helper.go 590 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2013 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. package ipv6
  5. import (
  6. "errors"
  7. "net"
  8. )
  9. var errOpNoSupport = errors.New("operation not supported")
  10. func boolint(b bool) int {
  11. if b {
  12. return 1
  13. }
  14. return 0
  15. }
  16. func netAddrToIP16(a net.Addr) net.IP {
  17. switch v := a.(type) {
  18. case *net.UDPAddr:
  19. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  20. return ip
  21. }
  22. case *net.IPAddr:
  23. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  24. return ip
  25. }
  26. }
  27. return nil
  28. }