/usr/share/gocode/src/github.com/linuxkit/virtsock/cmd/sock_stress/tcp.go is in golang-github-linuxkit-virtsock-dev 0.0~git20170720.0.0416e3d-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | package main
import (
"log"
"net"
)
type tcpAddr struct {
addr *net.TCPAddr
net string
}
// tcpParseSockStr extracts the host and port from a string.
// The format is "Host:Port", "Host", or ":Port" as well as an empty string.
func tcpParseSockStr(netStr, sockStr string) tcpAddr {
var s tcpAddr
s.net = netStr
sockStr = parseNetStr(s.net == "tcp6", sockStr)
a, err := net.ResolveTCPAddr(netStr, sockStr)
if err != nil {
log.Fatalf("Error parsing socket string '%s': %v", sockStr, err)
}
s.addr = a
return s
}
func (s tcpAddr) String() string {
return s.net + "://" + s.addr.String()
}
// Dial connects on a TCP socket
func (s tcpAddr) Dial(conid int) (Conn, error) {
c, err := net.Dial(s.net, s.addr.String())
if err != nil {
return nil, err
}
return c.(*net.TCPConn), err
}
// Listen returns a net.Listener for a given TCP socket
func (s tcpAddr) Listen() net.Listener {
l, err := net.Listen(s.net, s.addr.String())
if err != nil {
log.Fatalln("Listen():", err)
}
return l
}
// ListenPacket is not implemented for TCP
func (s tcpAddr) ListenPacket() net.PacketConn {
log.Fatalln("ListenPacket(): not implemented for TCP")
return nil
}
|