From c00262b42d8e36054f1b3a6cc4819d1045c60f33 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Mon, 6 Nov 2023 21:22:49 +0100 Subject: [PATCH] Fixed option sourceport with UDP6-DATAGRAM --- CHANGES | 2 ++ xio-udp.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 6677f7a..1f3f346 100644 --- a/CHANGES +++ b/CHANGES @@ -204,6 +204,8 @@ Corrections: Thanks to Hiroshi Sakurai for reporting the problem and suggesting this solution. + Fixed option sourceport with UDP6-DATAGRAM. + Coding: Introduced groups_t instead of uint32_t, for more flexibility. diff --git a/xio-udp.c b/xio-udp.c index eb3db58..9925218 100644 --- a/xio-udp.c +++ b/xio-udp.c @@ -465,10 +465,10 @@ static int xioopen_udp_datagram( if (retropt_ushort(opts, OPT_SOURCEPORT, &sfd->para.socket.ip.sourceport) >= 0) { sfd->para.socket.ip.dosourceport = true; - sfd->para.socket.ip.sourceport = ntohs(sfd->peersa.ip4.sin_port); } retropt_socket_pf(opts, &pf); + result = _xioopen_udp_sendto(hostname, argv[2], opts, xioflags, xxfd, addrdesc->groups, pf, socktype, ipproto); @@ -477,6 +477,18 @@ static int xioopen_udp_datagram( return result; } + if (sfd->para.socket.ip.dosourceport) { + switch (sfd->peersa.soa.sa_family) { + case PF_INET: + default: + sfd->para.socket.ip.sourceport = ntohs(sfd->peersa.ip4.sin_port); + break; + case PF_INET6: + sfd->para.socket.ip.sourceport = ntohs(sfd->peersa.ip6.sin6_port); + break; + } + } + sfd->dtype = XIOREAD_RECV|XIOWRITE_SENDTO; sfd->para.socket.la.soa.sa_family = sfd->peersa.soa.sa_family;