/usr/share/gocode/src/github.com/linuxkit/virtsock/cmd/sock_stress/hvsock.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"
"strings"
"github.com/linuxkit/virtsock/pkg/hvsock"
)
var (
svcid, _ = hvsock.GUIDFromString("3049197C-FACB-11E6-BD58-64006A7986D3")
)
type hvsockAddr struct {
addr hvsock.HypervAddr
}
// hvsockParseSockStr extracts the vmid and svcid from a string.
// The format is "VMID:Service", "VMID", or ":Service" as well as an
// empty string. For VMID we also support "parent" and assume
// "loopback" if the string can't be parsed.
func hvsockParseSockStr(sockStr string) hvsockAddr {
a := hvsock.HypervAddr{hvsock.GUIDZero, svcid}
if sockStr == "" {
return hvsockAddr{a}
}
var err error
vmStr := ""
svcStr := ""
if strings.Contains(sockStr, ":") {
vmStr, svcStr, err = net.SplitHostPort(sockStr)
if err != nil {
log.Fatalf("Error parsing socket string '%s': %v", sockStr, err)
}
} else {
vmStr = sockStr
}
if vmStr != "" {
if strings.Contains(vmStr, "-") {
a.VMID, err = hvsock.GUIDFromString(vmStr)
if err != nil {
log.Fatalf("Error parsing VM '%s': %v", vmStr, err)
}
} else if clientStr == "parent" {
a.VMID = hvsock.GUIDParent
} else {
a.VMID = hvsock.GUIDLoopback
}
}
if svcStr != "" {
a.ServiceID, err = hvsock.GUIDFromString(svcStr)
if err != nil {
log.Fatalf("Error parsing SVC '%s': %v", svcStr, err)
}
}
return hvsockAddr{a}
}
func (s hvsockAddr) String() string {
return s.addr.String()
}
// Dial connects on a Hyper-V socket
func (s hvsockAddr) Dial(conid int) (Conn, error) {
return hvsock.Dial(s.addr)
}
// Listen returns a net.Listener for a given Hyper-V socket
func (s hvsockAddr) Listen() net.Listener {
l, err := hvsock.Listen(s.addr)
if err != nil {
log.Fatalln("Listen():", err)
}
return l
}
// ListenPacket is not implemented for Hyper-V sockets
func (s hvsockAddr) ListenPacket() net.PacketConn {
log.Fatalln("ListenPacket(): not implemented for Hyper-V sockets")
return nil
}
|