golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/lif/lif.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build solaris 6 7 // Package lif provides basic functions for the manipulation of 8 // logical network interfaces and interface addresses on Solaris. 9 // 10 // The package supports Solaris 11 or above. 11 package lif 12 13 import ( 14 "syscall" 15 ) 16 17 type endpoint struct { 18 af int 19 s uintptr 20 } 21 22 func (ep *endpoint) close() error { 23 return syscall.Close(int(ep.s)) 24 } 25 26 func newEndpoints(af int) ([]endpoint, error) { 27 var lastErr error 28 var eps []endpoint 29 afs := []int{syscall.AF_INET, syscall.AF_INET6} 30 if af != syscall.AF_UNSPEC { 31 afs = []int{af} 32 } 33 for _, af := range afs { 34 s, err := syscall.Socket(af, syscall.SOCK_DGRAM, 0) 35 if err != nil { 36 lastErr = err 37 continue 38 } 39 eps = append(eps, endpoint{af: af, s: uintptr(s)}) 40 } 41 if len(eps) == 0 { 42 return nil, lastErr 43 } 44 return eps, nil 45 }