Skip to content

Commit ba0db0b

Browse files
fix: UDP packet buffer initialization pointing all msg_name to same address (#245)
Fix bug in bsd_create_udp_packet_buffer() where all mmsghdr structures were pointing their msg_name field to the same address (&b->addr[0]) instead of their respective slots in the address array (&b->addr[n]). This caused all received UDP packets to appear as coming from the same peer address when using Linux recvmmsg(), making it impossible to distinguish between different clients in UDP server applications. Changes: - Line 251: Change .msg_name = &b->addr to .msg_name = &b->addr[n] Fixes issue where us_udp_packet_buffer_peer() would return identical pointers for different packet indices on Linux systems.
1 parent a80584e commit ba0db0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void *bsd_create_udp_packet_buffer() {
251251
b->iov[n].iov_len = LIBUS_UDP_MAX_SIZE;
252252

253253
b->msgvec[n].msg_hdr = (struct msghdr) {
254-
.msg_name = &b->addr,
254+
.msg_name = &b->addr[n],
255255
.msg_namelen = sizeof (struct sockaddr_storage),
256256

257257
.msg_iov = &b->iov[n],
@@ -764,4 +764,4 @@ LIBUS_SOCKET_DESCRIPTOR bsd_create_connect_socket_unix(const char *server_path,
764764
connect(fd, (struct sockaddr *)&server_address, size);
765765

766766
return fd;
767-
}
767+
}

0 commit comments

Comments
 (0)