lif.go 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. //go:build solaris
  5. // +build solaris
  6. // Package lif provides basic functions for the manipulation of
  7. // logical network interfaces and interface addresses on Solaris.
  8. //
  9. // The package supports Solaris 11 or above.
  10. package lif
  11. import "syscall"
  12. type endpoint struct {
  13. af int
  14. s uintptr
  15. }
  16. func (ep *endpoint) close() error {
  17. return syscall.Close(int(ep.s))
  18. }
  19. func newEndpoints(af int) ([]endpoint, error) {
  20. var lastErr error
  21. var eps []endpoint
  22. afs := []int{sysAF_INET, sysAF_INET6}
  23. if af != sysAF_UNSPEC {
  24. afs = []int{af}
  25. }
  26. for _, af := range afs {
  27. s, err := syscall.Socket(af, sysSOCK_DGRAM, 0)
  28. if err != nil {
  29. lastErr = err
  30. continue
  31. }
  32. eps = append(eps, endpoint{af: af, s: uintptr(s)})
  33. }
  34. if len(eps) == 0 {
  35. return nil, lastErr
  36. }
  37. return eps, nil
  38. }