mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-12-21 10:20:42 +00:00
Fix address structure handling in UDP_Bind
Fixed instances of copying only sizeof (struct sockaddr) bytes (not enough for struct sockaddr_in6), as well as trying to getsockname into an insufficient buffer.
This commit is contained in:
parent
32ad1f2067
commit
c9631565d6
1 changed files with 13 additions and 9 deletions
22
src/i_tcp.c
22
src/i_tcp.c
|
@ -748,8 +748,7 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen
|
||||||
unsigned long trueval = true;
|
unsigned long trueval = true;
|
||||||
#endif
|
#endif
|
||||||
mysockaddr_t straddr;
|
mysockaddr_t straddr;
|
||||||
struct sockaddr_in sin;
|
socklen_t len = sizeof(straddr);
|
||||||
socklen_t len = sizeof(sin);
|
|
||||||
|
|
||||||
if (s == (SOCKET_TYPE)ERRSOCKET)
|
if (s == (SOCKET_TYPE)ERRSOCKET)
|
||||||
return (SOCKET_TYPE)ERRSOCKET;
|
return (SOCKET_TYPE)ERRSOCKET;
|
||||||
|
@ -767,14 +766,12 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
straddr.any = *addr;
|
memcpy(&straddr, addr, addrlen);
|
||||||
I_OutputMsg("Binding to %s\n", SOCK_AddrToStr(&straddr));
|
I_OutputMsg("Binding to %s\n", SOCK_AddrToStr(&straddr));
|
||||||
|
|
||||||
if (family == AF_INET)
|
if (family == AF_INET)
|
||||||
{
|
{
|
||||||
mysockaddr_t tmpaddr;
|
if (straddr.ip4.sin_addr.s_addr == htonl(INADDR_ANY))
|
||||||
tmpaddr.any = *addr ;
|
|
||||||
if (tmpaddr.ip4.sin_addr.s_addr == htonl(INADDR_ANY))
|
|
||||||
{
|
{
|
||||||
opt = true;
|
opt = true;
|
||||||
opts = (socklen_t)sizeof(opt);
|
opts = (socklen_t)sizeof(opt);
|
||||||
|
@ -791,7 +788,7 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
else if (family == AF_INET6)
|
else if (family == AF_INET6)
|
||||||
{
|
{
|
||||||
if (memcmp(addr, &in6addr_any, sizeof(in6addr_any)) == 0) //IN6_ARE_ADDR_EQUAL
|
if (memcmp(&straddr.ip6.sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0) //IN6_ARE_ADDR_EQUAL
|
||||||
{
|
{
|
||||||
opt = true;
|
opt = true;
|
||||||
opts = (socklen_t)sizeof(opt);
|
opts = (socklen_t)sizeof(opt);
|
||||||
|
@ -843,10 +840,17 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen
|
||||||
CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10);
|
CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getsockname(s, (struct sockaddr *)&sin, &len) == -1)
|
if (getsockname(s, &straddr.any, &len) == -1)
|
||||||
CONS_Alert(CONS_WARNING, M_GetText("Failed to get port number\n"));
|
CONS_Alert(CONS_WARNING, M_GetText("Failed to get port number\n"));
|
||||||
else
|
else
|
||||||
current_port = (UINT16)ntohs(sin.sin_port);
|
{
|
||||||
|
if (family == AF_INET)
|
||||||
|
current_port = (UINT16)ntohs(straddr.ip4.sin_port);
|
||||||
|
#ifdef HAVE_IPV6
|
||||||
|
else if (family == AF_INET6)
|
||||||
|
current_port = (UINT16)ntohs(straddr.ip6.sin6_port);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue