stack.go 688 B

123456789101112131415161718192021222324252627282930
  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
  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. }