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.
This commit is contained in:
parent
0c540ad60e
commit
f8198c0428
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user