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.
 
 
 

67 lines
1.5 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. "runtime"
  9. )
  10. var (
  11. errInvalidConn = errors.New("invalid connection")
  12. errMissingAddress = errors.New("missing address")
  13. errMissingHeader = errors.New("missing header")
  14. errNilHeader = errors.New("nil header")
  15. errHeaderTooShort = errors.New("header too short")
  16. errExtHeaderTooShort = errors.New("extension header too short")
  17. errInvalidConnType = errors.New("invalid conn type")
  18. errNoSuchInterface = errors.New("no such interface")
  19. errNoSuchMulticastInterface = errors.New("no such multicast interface")
  20. errNotImplemented = errors.New("not implemented on " + runtime.GOOS + "/" + runtime.GOARCH)
  21. // See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html.
  22. freebsdVersion uint32
  23. )
  24. func boolint(b bool) int {
  25. if b {
  26. return 1
  27. }
  28. return 0
  29. }
  30. func netAddrToIP4(a net.Addr) net.IP {
  31. switch v := a.(type) {
  32. case *net.UDPAddr:
  33. if ip := v.IP.To4(); ip != nil {
  34. return ip
  35. }
  36. case *net.IPAddr:
  37. if ip := v.IP.To4(); ip != nil {
  38. return ip
  39. }
  40. }
  41. return nil
  42. }
  43. func opAddr(a net.Addr) net.Addr {
  44. switch a.(type) {
  45. case *net.TCPAddr:
  46. if a == nil {
  47. return nil
  48. }
  49. case *net.UDPAddr:
  50. if a == nil {
  51. return nil
  52. }
  53. case *net.IPAddr:
  54. if a == nil {
  55. return nil
  56. }
  57. }
  58. return a
  59. }