helper.go 703 B

12345678910111213141516171819202122232425262728293031323334353637
  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. errOpNoSupport = errors.New("operation not supported")
  11. errNoSuchInterface = errors.New("no such interface")
  12. errNoSuchMulticastInterface = errors.New("no such multicast interface")
  13. )
  14. func boolint(b bool) int {
  15. if b {
  16. return 1
  17. }
  18. return 0
  19. }
  20. func netAddrToIP4(a net.Addr) net.IP {
  21. switch v := a.(type) {
  22. case *net.UDPAddr:
  23. if ip := v.IP.To4(); ip != nil {
  24. return ip
  25. }
  26. case *net.IPAddr:
  27. if ip := v.IP.To4(); ip != nil {
  28. return ip
  29. }
  30. }
  31. return nil
  32. }