mirror of
https://github.com/golang/go
synced 2024-11-21 21:04:41 -07:00
net: make LocalAddr on multicast return group address
Fixes #3067. R=golang-dev, rsc, rsc CC=golang-dev https://golang.org/cl/5656098
This commit is contained in:
parent
9a59aec1a1
commit
e91bf2e9d1
@ -81,6 +81,9 @@ func TestListenMulticastUDP(t *testing.T) {
|
||||
if !found {
|
||||
t.Fatalf("%q not found in RIB", tt.gaddr.String())
|
||||
}
|
||||
if c.LocalAddr().String() != tt.gaddr.String() {
|
||||
t.Fatalf("LocalAddr returns %q, expected %q", c.LocalAddr().String(), tt.gaddr.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +117,9 @@ func TestSimpleListenMulticastUDP(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("ListenMulticastUDP failed: %v", err)
|
||||
}
|
||||
if c.LocalAddr().String() != tt.gaddr.String() {
|
||||
t.Fatalf("LocalAddr returns %q, expected %q", c.LocalAddr().String(), tt.gaddr.String())
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,14 @@ func socket(net string, f, t, p int, la, ra syscall.Sockaddr, toAddr func(syscal
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var bla syscall.Sockaddr
|
||||
if la != nil {
|
||||
la, err = listenerSockaddr(s, f, la, toAddr)
|
||||
bla, err = listenerSockaddr(s, f, la, toAddr)
|
||||
if err != nil {
|
||||
closesocket(s)
|
||||
return nil, err
|
||||
}
|
||||
err = syscall.Bind(s, la)
|
||||
err = syscall.Bind(s, bla)
|
||||
if err != nil {
|
||||
closesocket(s)
|
||||
return nil, err
|
||||
@ -61,7 +62,12 @@ func socket(net string, f, t, p int, la, ra syscall.Sockaddr, toAddr func(syscal
|
||||
}
|
||||
|
||||
sa, _ := syscall.Getsockname(s)
|
||||
laddr := toAddr(sa)
|
||||
var laddr Addr
|
||||
if la != nil && bla != la {
|
||||
laddr = toAddr(la)
|
||||
} else {
|
||||
laddr = toAddr(sa)
|
||||
}
|
||||
sa, _ = syscall.Getpeername(s)
|
||||
raddr := toAddr(sa)
|
||||
|
||||
|
@ -262,7 +262,7 @@ func ListenMulticastUDP(net string, ifi *Interface, gaddr *UDPAddr) (*UDPConn, e
|
||||
return nil, UnknownNetworkError(net)
|
||||
}
|
||||
if gaddr == nil || gaddr.IP == nil {
|
||||
return nil, &OpError{"listenmulticastudp", "udp", nil, errMissingAddress}
|
||||
return nil, &OpError{"listenmulticast", net, nil, errMissingAddress}
|
||||
}
|
||||
fd, err := internetSocket(net, gaddr.toAddr(), nil, syscall.SOCK_DGRAM, 0, "listen", sockaddrToUDP)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user