helper.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2012 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 ipv4
  5. import (
  6. "errors"
  7. "net"
  8. )
  9. var (
  10. errMissingAddress = errors.New("missing address")
  11. errMissingHeader = errors.New("missing header")
  12. errHeaderTooShort = errors.New("header too short")
  13. errBufferTooShort = errors.New("buffer too short")
  14. errInvalidConnType = errors.New("invalid conn type")
  15. errOpNoSupport = errors.New("operation not supported")
  16. errNoSuchInterface = errors.New("no such interface")
  17. errNoSuchMulticastInterface = errors.New("no such multicast interface")
  18. // See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
  19. freebsdVersion uint32
  20. )
  21. func boolint(b bool) int {
  22. if b {
  23. return 1
  24. }
  25. return 0
  26. }
  27. func netAddrToIP4(a net.Addr) net.IP {
  28. switch v := a.(type) {
  29. case *net.UDPAddr:
  30. if ip := v.IP.To4(); ip != nil {
  31. return ip
  32. }
  33. case *net.IPAddr:
  34. if ip := v.IP.To4(); ip != nil {
  35. return ip
  36. }
  37. }
  38. return nil
  39. }