diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-25 12:45:13 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-08-25 12:45:13 -0600 |
commit | f8198c042810b2c512c610654272db845e32b75e (patch) | |
tree | 95aed58033343fb4c3714eb03c66de8273a8b2f6 /device/conn_linux.go | |
parent | 0c540ad60e6942f0c8458d8b9b5ceb2d76a0d29b (diff) |
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.
Diffstat (limited to 'device/conn_linux.go')
-rw-r--r-- | device/conn_linux.go | 10 |
1 files changed, 10 insertions, 0 deletions
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 } |