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.

63 lines
1.3 KiB

  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. }
  40. func opAddr(a net.Addr) net.Addr {
  41. switch a.(type) {
  42. case *net.TCPAddr:
  43. if a == nil {
  44. return nil
  45. }
  46. case *net.UDPAddr:
  47. if a == nil {
  48. return nil
  49. }
  50. case *net.IPAddr:
  51. if a == nil {
  52. return nil
  53. }
  54. }
  55. return a
  56. }