Skip to content

Commit d73732e

Browse files
firearithewei
andauthored
fix: udp client localaddr (#580)
* getsockname after sendto --------- Co-authored-by: firear <firear> Co-authored-by: ithewei <[email protected]>
1 parent e2ee106 commit d73732e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

event/nio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,13 @@ static int __nio_write(hio_t* io, const void* buf, int len) {
287287
case HIO_TYPE_UDP:
288288
case HIO_TYPE_KCP:
289289
case HIO_TYPE_IP:
290+
{
290291
nwrite = sendto(io->fd, buf, len, 0, io->peeraddr, SOCKADDR_LEN(io->peeraddr));
292+
if (((sockaddr_u*)io->localaddr)->sin.sin_port == 0) {
293+
socklen_t addrlen = sizeof(sockaddr_u);
294+
getsockname(io->fd, io->localaddr, &addrlen);
295+
}
296+
}
291297
break;
292298
default:
293299
nwrite = write(io->fd, buf, len);

0 commit comments

Comments
 (0)