mirror of
https://github.com/golang/go
synced 2024-11-12 09:50:21 -07:00
net: make it possible to use FilePacketConn with IPConn
Fixes #6803. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/57560043
This commit is contained in:
parent
5be96aad00
commit
c88a671925
@ -174,6 +174,8 @@ var filePacketConnTests = []struct {
|
|||||||
|
|
||||||
{net: "udp6", addr: "[::1]", ipv6: true},
|
{net: "udp6", addr: "[::1]", ipv6: true},
|
||||||
|
|
||||||
|
{net: "ip4:icmp", addr: "127.0.0.1"},
|
||||||
|
|
||||||
{net: "unixgram", addr: "@gotest3/net", linux: true},
|
{net: "unixgram", addr: "@gotest3/net", linux: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +189,10 @@ func TestFilePacketConn(t *testing.T) {
|
|||||||
if skipServerTest(tt.net, "unixgram", tt.addr, tt.ipv6, false, tt.linux) {
|
if skipServerTest(tt.net, "unixgram", tt.addr, tt.ipv6, false, tt.linux) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if os.Getuid() != 0 && tt.net == "ip4:icmp" {
|
||||||
|
t.Log("skipping test; must be root")
|
||||||
|
continue
|
||||||
|
}
|
||||||
testFilePacketConnListen(t, tt.net, tt.addr)
|
testFilePacketConnListen(t, tt.net, tt.addr)
|
||||||
switch tt.addr {
|
switch tt.addr {
|
||||||
case "", "0.0.0.0", "[::ffff:0.0.0.0]", "[::]":
|
case "", "0.0.0.0", "[::ffff:0.0.0.0]", "[::]":
|
||||||
|
@ -129,6 +129,8 @@ func FilePacketConn(f *os.File) (c PacketConn, err error) {
|
|||||||
switch fd.laddr.(type) {
|
switch fd.laddr.(type) {
|
||||||
case *UDPAddr:
|
case *UDPAddr:
|
||||||
return newUDPConn(fd), nil
|
return newUDPConn(fd), nil
|
||||||
|
case *IPAddr:
|
||||||
|
return newIPConn(fd), nil
|
||||||
case *UnixAddr:
|
case *UnixAddr:
|
||||||
return newUnixConn(fd), nil
|
return newUnixConn(fd), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user