LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build !plan9 | 5 // +build !plan9 |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 b[6] = uint8(seqnum >> 8) // sequence number | 199 b[6] = uint8(seqnum >> 8) // sequence number |
200 b[7] = uint8(seqnum & 0xff) // sequence number | 200 b[7] = uint8(seqnum & 0xff) // sequence number |
201 return b | 201 return b |
202 } | 202 } |
203 | 203 |
204 func parseICMPEchoReply(b []byte) (id, seqnum int) { | 204 func parseICMPEchoReply(b []byte) (id, seqnum int) { |
205 id = int(b[4])<<8 | int(b[5]) | 205 id = int(b[4])<<8 | int(b[5]) |
206 seqnum = int(b[6])<<8 | int(b[7]) | 206 seqnum = int(b[6])<<8 | int(b[7]) |
207 return | 207 return |
208 } | 208 } |
| 209 |
| 210 var ipConnLocalNameTests = []struct { |
| 211 net string |
| 212 laddr *IPAddr |
| 213 }{ |
| 214 {"ip4:icmp", &IPAddr{IP: IPv4(127, 0, 0, 1)}}, |
| 215 {"ip4:icmp", &IPAddr{}}, |
| 216 {"ip4:icmp", nil}, |
| 217 } |
| 218 |
| 219 func TestIPConnLocalName(t *testing.T) { |
| 220 if os.Getuid() != 0 { |
| 221 t.Logf("skipping test; must be root") |
| 222 return |
| 223 } |
| 224 |
| 225 for _, tt := range ipConnLocalNameTests { |
| 226 c, err := ListenIP(tt.net, tt.laddr) |
| 227 if err != nil { |
| 228 t.Errorf("ListenIP failed: %v", err) |
| 229 return |
| 230 } |
| 231 defer c.Close() |
| 232 la := c.LocalAddr() |
| 233 if la == nil { |
| 234 t.Error("IPConn.LocalAddr failed") |
| 235 return |
| 236 } |
| 237 } |
| 238 } |
LEFT | RIGHT |