1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Fix formatting of ip addresses so that v6 sockets are logged correctly.

svn path=/trunk/net/; revision=4345
This commit is contained in:
Michael Smith 2003-02-14 11:14:55 +00:00
parent 66757da884
commit de873ff693

View File

@ -668,15 +668,19 @@ int sock_accept(sock_t serversock, char *ip, int len)
ret = accept(serversock, (struct sockaddr *)&sa, &slen); ret = accept(serversock, (struct sockaddr *)&sa, &slen);
if (ret >= 0 && ip != NULL) { if (ret >= 0 && ip != NULL) {
/* inet_ntoa is not reentrant, we should protect this */
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
if(inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr, if(((struct sockaddr_in *)&sa)->sin_family == AF_INET)
ip, len) <= 0) inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr,
{
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr,
ip, len); ip, len);
else if(((struct sockaddr_in6 *)&sa)->sin6_family == AF_INET6)
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr,
ip, len);
else {
strncpy(ip, "ERROR", len-1);
ip[len-1] = 0;
} }
#else #else
/* inet_ntoa is not reentrant, we should protect this */
strncpy(ip, inet_ntoa(sa.sin_addr), len); strncpy(ip, inet_ntoa(sa.sin_addr), len);
#endif #endif
sock_set_nolinger(ret); sock_set_nolinger(ret);