1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-14 07:23:23 +00:00

Fixed UDP-LISTEN with bind to IPv4 address on option -0

This commit is contained in:
Gerhard Rieger 2025-01-11 08:09:40 +01:00
parent c4844692f3
commit 0f1c5dd85a
5 changed files with 131 additions and 26 deletions

View file

@ -277,8 +277,10 @@ int xioopen_ipdgram_listen(
int pf = addrdesc->arg1;
int ipproto = addrdesc->arg2;
union sockaddr_union us;
int bind_rc;
int socktype = SOCK_DGRAM;
socklen_t uslen;
int result;
if (argc != 2) {
xio_syntax(argv[0], 1, argc-1, addrdesc->syntax);
@ -295,12 +297,31 @@ int xioopen_ipdgram_listen(
applyopts(sfd, -1, opts, PH_INIT);
uslen = socket_init(pf, &us);
retropt_bind(opts, pf, socktype, ipproto,
bind_rc = retropt_bind(opts, pf, socktype, ipproto,
(struct sockaddr *)&us, &uslen, 1,
xfd->stream.para.socket.ip.ai_flags);
if (bind_rc == STAT_NORETRY)
return STAT_NORETRY;
if (pf == PF_UNSPEC && bind_rc == STAT_OK)
pf = us.soa.sa_family;
if (false) {
;
#if WITH_IP4 || WITH_IP6
} else if (pf == PF_UNSPEC && bind_rc == STAT_NOACTION) {
int ai_flags[2];
ai_flags[0] = sfd->para.socket.ip.ai_flags[0];
ai_flags[1] = sfd->para.socket.ip.ai_flags[1];
if (!(ai_flags[1] & AI_PASSIVE))
ai_flags[0] |= AI_PASSIVE;
result =
xioresolve(NULL, portname, pf, socktype, ipproto, &us, &uslen, ai_flags);
if (result != STAT_OK) {
Error("error resolving bind option");
return STAT_NORETRY;
}
pf = us.soa.sa_family;
#endif /* WITH_IP4 || WITH_IP6*/
#if WITH_IP4
} else if (pf == PF_INET) {
us.ip4.sin_port = parseport(portname, ipproto);