From: Russ Cox Date: Mon, 18 Jan 2010 23:59:32 +0000 (-0800) Subject: net: enable UDP broadcast before it is needed (instead of after) X-Git-Tag: weekly.2010-01-27~86 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7c1bb0037427ca5317e03d61e39478362bfb7755;p=gostls13.git net: enable UDP broadcast before it is needed (instead of after) Fixes #526. R=r CC=golang-dev https://golang.org/cl/186211 --- diff --git a/src/pkg/net/sock.go b/src/pkg/net/sock.go index dbb87d36f6..be92095a66 100644 --- a/src/pkg/net/sock.go +++ b/src/pkg/net/sock.go @@ -35,6 +35,9 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal // Allow reuse of recently-used addresses. syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + // Allow broadcast. + syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) + if la != nil { e = syscall.Bind(s, la) if e != 0 { diff --git a/src/pkg/net/udpsock.go b/src/pkg/net/udpsock.go index 1891f2f8c2..f5ad3c88f8 100644 --- a/src/pkg/net/udpsock.go +++ b/src/pkg/net/udpsock.go @@ -71,11 +71,7 @@ type UDPConn struct { fd *netFD } -func newUDPConn(fd *netFD) *UDPConn { - c := &UDPConn{fd} - setsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) - return c -} +func newUDPConn(fd *netFD) *UDPConn { return &UDPConn{fd} } func (c *UDPConn) ok() bool { return c != nil && c.fd != nil }