stack.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 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 nettest provides utilities for IP testing.
  5. package nettest // import "golang.org/x/net/internal/nettest"
  6. import "net"
  7. // SupportsIPv4 reports whether the platform supports IPv4 networking
  8. // functionality.
  9. func SupportsIPv4() bool {
  10. ln, err := net.Listen("tcp4", "127.0.0.1:0")
  11. if err != nil {
  12. return false
  13. }
  14. ln.Close()
  15. return true
  16. }
  17. // SupportsIPv6 reports whether the platform supports IPv6 networking
  18. // functionality.
  19. func SupportsIPv6() bool {
  20. if causesIPv6Crash() {
  21. return false
  22. }
  23. ln, err := net.Listen("tcp6", "[::1]:0")
  24. if err != nil {
  25. return false
  26. }
  27. ln.Close()
  28. return true
  29. }
  30. // SupportsRawIPSocket reports whether the platform supports raw IP
  31. // sockets.
  32. func SupportsRawIPSocket() (string, bool) {
  33. return supportsRawIPSocket()
  34. }
  35. // SupportsIPv6MulticastDeliveryOnLoopback reports whether the
  36. // platform supports IPv6 multicast packet delivery on software
  37. // loopback interface.
  38. func SupportsIPv6MulticastDeliveryOnLoopback() bool {
  39. return supportsIPv6MulticastDeliveryOnLoopback()
  40. }
  41. // ProtocolNotSupported reports whether err is a protocol not
  42. // supported error.
  43. func ProtocolNotSupported(err error) bool {
  44. return protocolNotSupported(err)
  45. }