Conn4 connects to the server listener at the specified named port using one of 127.0.0.0/8 addresses as a source.
(sourceIP, portName string)
| 424 | // Conn4 connects to the server listener at the specified named port using one |
| 425 | // of 127.0.0.0/8 addresses as a source. |
| 426 | func (t *T) Conn4(sourceIP, portName string) Conn { |
| 427 | port := t.ports[portName] |
| 428 | if port == 0 { |
| 429 | panic("tests: connection for the unused port name is requested") |
| 430 | } |
| 431 | |
| 432 | localIP := net.ParseIP(sourceIP) |
| 433 | if localIP == nil { |
| 434 | panic("tests: invalid localIP argument") |
| 435 | } |
| 436 | if localIP.To4() == nil { |
| 437 | panic("tests: only IPv4 addresses are allowed") |
| 438 | } |
| 439 | |
| 440 | conn, err := net.DialTCP("tcp4", &net.TCPAddr{ |
| 441 | IP: localIP, |
| 442 | Port: 0, |
| 443 | }, &net.TCPAddr{ |
| 444 | IP: net.IPv4(127, 0, 0, 1), |
| 445 | Port: int(port), |
| 446 | }) |
| 447 | if err != nil { |
| 448 | t.Fatal("Could not connect, is server listening?", err) |
| 449 | } |
| 450 | |
| 451 | return Conn{ |
| 452 | T: t, |
| 453 | WriteTimeout: 1 * time.Second, |
| 454 | ReadTimeout: 15 * time.Second, |
| 455 | Conn: conn, |
| 456 | Scanner: bufio.NewScanner(conn), |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | var ( |
| 461 | DefaultSourceIP = net.IPv4(127, 109, 97, 100) |
no outgoing calls