os, net, crypto/x509: add hurd support

Patch by Svante Signell.

Change-Id: I774b4437028287a1952c0a95ef024b56233abadb
Reviewed-on: https://go-review.googlesource.com/c/161519
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/libgo/go/crypto/x509/root_hurd.go b/libgo/go/crypto/x509/root_hurd.go
new file mode 100644
index 0000000..59e9ff0
--- /dev/null
+++ b/libgo/go/crypto/x509/root_hurd.go
@@ -0,0 +1,11 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// This file is derived from root_linux.go
+
+package x509
+
+// Possible certificate files; stop after finding one.
+var certFiles = []string{
+	"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
+}
diff --git a/libgo/go/internal/poll/sendfile_linux.go b/libgo/go/internal/poll/sendfile_glibc.go
similarity index 97%
rename from libgo/go/internal/poll/sendfile_linux.go
rename to libgo/go/internal/poll/sendfile_glibc.go
index 8e93806..6652e3f 100644
--- a/libgo/go/internal/poll/sendfile_linux.go
+++ b/libgo/go/internal/poll/sendfile_glibc.go
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build hurd linux
+
 package poll
 
 import "syscall"
diff --git a/libgo/go/net/cgo_hurd.go b/libgo/go/net/cgo_hurd.go
new file mode 100644
index 0000000..98e4cfa
--- /dev/null
+++ b/libgo/go/net/cgo_hurd.go
@@ -0,0 +1,17 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// This file is derived from cgo_bsd.go
+
+// +build cgo,!netgo
+// +build hurd
+
+package net
+
+/*
+#include <netdb.h>
+*/
+
+import "syscall"
+
+const cgoAddrInfoFlags = syscall.AI_CANONNAME | syscall.AI_V4MAPPED | syscall.AI_ALL
diff --git a/libgo/go/net/sendfile_linux.go b/libgo/go/net/sendfile_glibc.go
similarity index 97%
rename from libgo/go/net/sendfile_linux.go
rename to libgo/go/net/sendfile_glibc.go
index 297e625..a71cfc9 100644
--- a/libgo/go/net/sendfile_linux.go
+++ b/libgo/go/net/sendfile_glibc.go
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build hurd linux
+
 package net
 
 import (
diff --git a/libgo/go/net/sockopt_hurd.go b/libgo/go/net/sockopt_hurd.go
new file mode 100644
index 0000000..c6de7a9
--- /dev/null
+++ b/libgo/go/net/sockopt_hurd.go
@@ -0,0 +1,41 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package net
+
+import (
+	"os"
+	"syscall"
+)
+
+func setDefaultSockopts(s, family, sotype int, ipv6only bool) error {
+	if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW {
+		// Allow both IP versions even if the OS default
+		// is otherwise. Note that some operating systems
+		// never admit this option.
+		syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only))
+	}
+	// Allow broadcast.
+	if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil {
+		return os.NewSyscallError("setsockopt", err)
+	}
+	return nil
+}
+
+func setDefaultListenerSockopts(s int) error {
+	// Allow reuse of recently-used addresses.
+	if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
+		return os.NewSyscallError("setsockopt", err)
+	}
+	return nil
+}
+
+func setDefaultMulticastSockopts(s int) error {
+	// Allow multicast UDP and raw IP datagram sockets to listen
+	// concurrently across multiple listeners.
+	if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
+		return os.NewSyscallError("setsockopt", err)
+	}
+	return nil
+}
diff --git a/libgo/go/os/executable_procfs.go b/libgo/go/os/executable_procfs.go
index d6ac270..e690103 100644
--- a/libgo/go/os/executable_procfs.go
+++ b/libgo/go/os/executable_procfs.go
@@ -19,7 +19,7 @@
 	switch runtime.GOOS {
 	default:
 		return "", errors.New("Executable not implemented for " + runtime.GOOS)
-	case "linux", "android":
+	case "hurd", "linux", "android":
 		procfn = "/proc/self/exe"
 	case "netbsd":
 		procfn = "/proc/curproc/exe"
diff --git a/libgo/go/os/pipe_linux.go b/libgo/go/os/pipe_glibc.go
similarity index 97%
rename from libgo/go/os/pipe_linux.go
rename to libgo/go/os/pipe_glibc.go
index acd7b88..31b144e 100644
--- a/libgo/go/os/pipe_linux.go
+++ b/libgo/go/os/pipe_glibc.go
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build hurd linux
+
 package os
 
 import "syscall"