helper.go 1011 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. )
  19. func boolint(b bool) int {
  20. if b {
  21. return 1
  22. }
  23. return 0
  24. }
  25. func netAddrToIP4(a net.Addr) net.IP {
  26. switch v := a.(type) {
  27. case *net.UDPAddr:
  28. if ip := v.IP.To4(); ip != nil {
  29. return ip
  30. }
  31. case *net.IPAddr:
  32. if ip := v.IP.To4(); ip != nil {
  33. return ip
  34. }
  35. }
  36. return nil
  37. }