Fixed option sourceport with UDP6-DATAGRAM

This commit is contained in:
Gerhard Rieger 2023-11-06 21:22:49 +01:00
parent f61a95585b
commit c00262b42d
2 changed files with 15 additions and 1 deletions

View file

@ -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.

View file

@ -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;