MCPcopy Create free account
hub / github.com/foxcpp/maddy / Conn4

Method Conn4

tests/t.go:426–458  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
426func (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
460var (
461 DefaultSourceIP = net.IPv4(127, 109, 97, 100)

Calls

no outgoing calls