nettest: fix Unix socket test on macOS

The macOS temp directory name is so long that it makes for
socket names that are far too long.

Fixes golang/go#54416.

Change-Id: Id09cb5af6122227132a9be1e8101ce3450af09e5
Reviewed-on: https://go-review.googlesource.com/c/net/+/423039
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
diff --git a/nettest/nettest.go b/nettest/nettest.go
index ae5413b..6918f2c 100644
--- a/nettest/nettest.go
+++ b/nettest/nettest.go
@@ -218,7 +218,11 @@
 // LocalPath returns a local path that can be used for Unix-domain
 // protocol testing.
 func LocalPath() (string, error) {
-	f, err := ioutil.TempFile("", "go-nettest")
+	dir := ""
+	if runtime.GOOS == "darwin" {
+		dir = "/tmp"
+	}
+	f, err := ioutil.TempFile(dir, "go-nettest")
 	if err != nil {
 		return "", err
 	}