/usr/share/gocode/src/github.com/linuxkit/virtsock/cmd/sock_stress/vsock.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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | package main
import (
"log"
"net"
"runtime"
"strconv"
"strings"
"github.com/linuxkit/virtsock/pkg/vsock"
)
const (
vsockPort = 0x5653
)
type vsockAddr struct {
addr vsock.VsockAddr
}
// vsockParseSockStr extracts the cid and port from a string.
// The format is "CID:Port", "CID", or ":Port" as well as an empty string.
func vsockParseSockStr(sockStr string) vsockAddr {
a := vsock.VsockAddr{vsock.CIDAny, vsockPort}
// For listeners on the host the CID needs to be CIDHost
if runtime.GOOS == "darwin" {
a.CID = vsock.CIDHost
}
if sockStr == "" {
return vsockAddr{a}
}
var err error
cidStr := ""
portStr := ""
if strings.Contains(sockStr, ":") {
cidStr, portStr, err = net.SplitHostPort(sockStr)
if err != nil {
log.Fatalf("Error parsing socket string '%s': %v", sockStr, err)
}
} else {
cidStr = sockStr
}
if cidStr != "" {
cid, err := strconv.ParseUint(cidStr, 10, 32)
if err != nil {
log.Fatalf("Error parsing '%s': %v", cidStr, err)
}
a.CID = uint32(cid)
}
if portStr != "" {
port, err := strconv.ParseUint(portStr, 10, 32)
if err != nil {
log.Fatalf("Error parsing '%s': %v", portStr, err)
}
a.Port = uint32(port)
}
return vsockAddr{a}
}
func (s vsockAddr) String() string {
return s.addr.String()
}
// Dial connects on a virtio socket
func (s vsockAddr) Dial(conid int) (Conn, error) {
return vsock.Dial(s.addr.CID, s.addr.Port)
}
// Listen returns a net.Listener for a given virtio socket
func (s vsockAddr) Listen() net.Listener {
l, err := vsock.Listen(s.addr.CID, s.addr.Port)
if err != nil {
log.Fatalln("Listen():", err)
}
return l
}
// ListenPacket is not implemented for virtio sockets
func (s vsockAddr) ListenPacket() net.PacketConn {
log.Fatalln("ListenPacket(): not implemented for virtio sockets")
return nil
}
|