From f8198c042810b2c512c610654272db845e32b75e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 25 Aug 2019 12:45:13 -0600 Subject: device: getsockname on linux to determine port It turns out Go isn't passing the pointer properly so we wound up with a zero port every time. --- device/conn_linux.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'device') diff --git a/device/conn_linux.go b/device/conn_linux.go index ebbbe11..f74ad51 100644 --- a/device/conn_linux.go +++ b/device/conn_linux.go @@ -391,6 +391,11 @@ func create4(port uint16) (int, uint16, error) { return FD_ERR, 0, err } + sa, err := unix.Getsockname(fd) + if err == nil { + addr.Port = sa.(*unix.SockaddrInet4).Port + } + return fd, uint16(addr.Port), err } @@ -450,6 +455,11 @@ func create6(port uint16) (int, uint16, error) { return FD_ERR, 0, err } + sa, err := unix.Getsockname(fd) + if err == nil { + addr.Port = sa.(*unix.SockaddrInet6).Port + } + return fd, uint16(addr.Port), err } -- cgit v1.2.3