-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (28 loc) · 722 Bytes
/
main.go
File metadata and controls
35 lines (28 loc) · 722 Bytes
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
package main
import (
"fmt"
"log"
"net"
"os"
"syscall"
"github.com/hankjacobs/sopeersec"
)
func main() {
l, err := net.Listen("unix", "/home/ubuntu/test/test1.socket")
if err != nil {
log.Fatal("listen error:", err)
}
defer l.Close()
defer os.Remove("/home/ubuntu/test/test.socket")
// Now do one of two things:
// 1) use netcat or socat or something to connect to the above socket or
// 2) bind mount the above directory into a docker container and do #1
for {
conn, _ := l.Accept()
unixConn := conn.(*net.UnixConn)
osFile, _ := unixConn.File()
label, errno := sopeersec.GetsockoptPeerSec(int(osFile.Fd()), syscall.SOL_SOCKET)
fmt.Println(errno, string(label))
fmt.Println("---")
}
}