1
0
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:
Mikio Hara 2012-02-19 10:50:03 +09:00
parent 9a59aec1a1
commit e91bf2e9d1
3 changed files with 16 additions and 4 deletions

View File

@ -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()
}
}

View File

@ -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)

View File

@ -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 {