You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.0 KiB

  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 (
  10. errMissingAddress = errors.New("missing address")
  11. errHeaderTooShort = errors.New("header too short")
  12. errInvalidConnType = errors.New("invalid conn type")
  13. errOpNoSupport = errors.New("operation not supported")
  14. errNoSuchInterface = errors.New("no such interface")
  15. )
  16. func boolint(b bool) int {
  17. if b {
  18. return 1
  19. }
  20. return 0
  21. }
  22. func netAddrToIP16(a net.Addr) net.IP {
  23. switch v := a.(type) {
  24. case *net.UDPAddr:
  25. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  26. return ip
  27. }
  28. case *net.IPAddr:
  29. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  30. return ip
  31. }
  32. }
  33. return nil
  34. }
  35. func opAddr(a net.Addr) net.Addr {
  36. switch a.(type) {
  37. case *net.TCPAddr:
  38. if a == nil {
  39. return nil
  40. }
  41. case *net.UDPAddr:
  42. if a == nil {
  43. return nil
  44. }
  45. case *net.IPAddr:
  46. if a == nil {
  47. return nil
  48. }
  49. }
  50. return a
  51. }