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.
 
 
 

54 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. "encoding/binary"
  7. "errors"
  8. "net"
  9. "unsafe"
  10. )
  11. var (
  12. errMissingAddress = errors.New("missing address")
  13. errHeaderTooShort = errors.New("header too short")
  14. errInvalidConnType = errors.New("invalid conn type")
  15. errOpNoSupport = errors.New("operation not supported")
  16. errNoSuchInterface = errors.New("no such interface")
  17. nativeEndian binary.ByteOrder
  18. )
  19. func init() {
  20. i := uint32(1)
  21. b := (*[4]byte)(unsafe.Pointer(&i))
  22. if b[0] == 1 {
  23. nativeEndian = binary.LittleEndian
  24. } else {
  25. nativeEndian = binary.BigEndian
  26. }
  27. }
  28. func boolint(b bool) int {
  29. if b {
  30. return 1
  31. }
  32. return 0
  33. }
  34. func netAddrToIP16(a net.Addr) net.IP {
  35. switch v := a.(type) {
  36. case *net.UDPAddr:
  37. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  38. return ip
  39. }
  40. case *net.IPAddr:
  41. if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
  42. return ip
  43. }
  44. }
  45. return nil
  46. }