stack.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. ln, err := net.Listen("tcp6", "[::1]:0")
  21. if err != nil {
  22. return false
  23. }
  24. ln.Close()
  25. return true
  26. }
  27. // SupportsRawIPSocket reports whether the platform supports raw IP
  28. // sockets.
  29. func SupportsRawIPSocket() (string, bool) {
  30. return supportsRawIPSocket()
  31. }
  32. // SupportsIPv6MulticastDeliveryOnLoopback reports whether the
  33. // platform supports IPv6 multicast packet delivery on software
  34. // loopback interface.
  35. func SupportsIPv6MulticastDeliveryOnLoopback() bool {
  36. return supportsIPv6MulticastDeliveryOnLoopback()
  37. }
  38. // ProtocolNotSupported reports whether err is a protocol not
  39. // supported error.
  40. func ProtocolNotSupported(err error) bool {
  41. return protocolNotSupported(err)
  42. }