In the previous code, the `*port` is assigned before `getsockname`, so the caller may be not able to get the actual port number assigned by system. Move the assigning of `*port` to be after `getsockname` to resolve the issue.
In the previous code, the `*port` is assigned before `getsockname`, so the caller may be not able to get the actual port number assigned by system. Move the assigning of `*port` to be after `getsockname` to resolve the issue.