|
5 | 5 | package ipv6_test
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "fmt" |
9 | 8 | "net"
|
10 | 9 | "runtime"
|
11 | 10 | "testing"
|
@@ -70,13 +69,16 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
|
70 | 69 | }
|
71 | 70 |
|
72 | 71 | for _, gaddr := range udpMultipleGroupListenerTests {
|
73 |
| - c1, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port |
| 72 | + c1, err := net.ListenPacket("udp6", "[ff02::]:0") // wildcard address with reusable port |
74 | 73 | if err != nil {
|
75 | 74 | t.Fatal(err)
|
76 | 75 | }
|
77 | 76 | defer c1.Close()
|
78 |
| - |
79 |
| - c2, err := net.ListenPacket("udp6", "[ff02::]:1024") // wildcard address with reusable port |
| 77 | + _, port, err := net.SplitHostPort(c1.LocalAddr().String()) |
| 78 | + if err != nil { |
| 79 | + t.Fatal(err) |
| 80 | + } |
| 81 | + c2, err := net.ListenPacket("udp6", net.JoinHostPort("ff02::", port)) // wildcard address with reusable port |
80 | 82 | if err != nil {
|
81 | 83 | t.Fatal(err)
|
82 | 84 | }
|
@@ -132,16 +134,29 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
132 | 134 | if err != nil {
|
133 | 135 | t.Fatal(err)
|
134 | 136 | }
|
| 137 | + port := "0" |
135 | 138 | for i, ifi := range ift {
|
136 | 139 | ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
|
137 | 140 | if !ok {
|
138 | 141 | continue
|
139 | 142 | }
|
140 |
| - c, err := net.ListenPacket("udp6", fmt.Sprintf("[%s%%%s]:1024", ip.String(), ifi.Name)) // unicast address with non-reusable port |
| 143 | + c, err := net.ListenPacket("udp6", net.JoinHostPort(ip.String()+"%"+ifi.Name, port)) // unicast address with non-reusable port |
141 | 144 | if err != nil {
|
142 |
| - t.Fatal(err) |
| 145 | + // The listen may fail when the serivce is |
| 146 | + // already in use, but it's fine because the |
| 147 | + // purpose of this is not to test the |
| 148 | + // bookkeeping of IP control block inside the |
| 149 | + // kernel. |
| 150 | + t.Log(err) |
| 151 | + continue |
143 | 152 | }
|
144 | 153 | defer c.Close()
|
| 154 | + if port == "0" { |
| 155 | + _, port, err = net.SplitHostPort(c.LocalAddr().String()) |
| 156 | + if err != nil { |
| 157 | + t.Fatal(err) |
| 158 | + } |
| 159 | + } |
145 | 160 | p := ipv6.NewPacketConn(c)
|
146 | 161 | if err := p.JoinGroup(&ifi, &gaddr); err != nil {
|
147 | 162 | t.Fatal(err)
|
@@ -227,7 +242,7 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
|
227 | 242 | if !ok {
|
228 | 243 | continue
|
229 | 244 | }
|
230 |
| - c, err := net.ListenPacket("ip6:ipv6-icmp", fmt.Sprintf("%s%%%s", ip.String(), ifi.Name)) // unicast address |
| 245 | + c, err := net.ListenPacket("ip6:ipv6-icmp", ip.String()+"%"+ifi.Name) // unicast address |
231 | 246 | if err != nil {
|
232 | 247 | t.Fatal(err)
|
233 | 248 | }
|
|
0 commit comments