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

Better IPv6 support. Hopefully logging will work correctly now.

However, some things still won't work, notably relaying (the relay can be
ipv6, the server being relayed _from_ may not be).
I'll fix that some time soon.

svn path=/trunk/icecast/; revision=4342
This commit is contained in:
Michael Smith 2003-02-13 11:29:07 +00:00
parent 38e3bfb88f
commit b6c18398cd
3 changed files with 30 additions and 10 deletions

View File

@ -126,9 +126,9 @@ static connection_t *_accept_connection(void)
}
/* malloc enough room for a full IP address (including ipv6) */
ip = (char *)malloc(40);
ip = (char *)malloc(MAX_ADDR_LEN);
sock = sock_accept(global.serversock, ip, 40);
sock = sock_accept(global.serversock, ip, MAX_ADDR_LEN);
if (sock >= 0) {
con = create_connection(sock, ip);

View File

@ -486,11 +486,11 @@ sock_t sock_connect_wto(const char *hostname, const int port, const int timeout)
#else
/* TODO: This doesn't do ipv6 connections */
int sock_try_connection (int sock, const char *hostname, const unsigned port)
{
struct sockaddr_in sin, server;
char ip[40];
char ip[MAX_ADDR_LEN];
if (!hostname || !hostname[0] || port == 0)
return -1;
@ -498,7 +498,7 @@ int sock_try_connection (int sock, const char *hostname, const unsigned port)
memset(&sin, 0, sizeof(struct sockaddr_in));
memset(&server, 0, sizeof(struct sockaddr_in));
if (!resolver_getip(hostname, ip, 40))
if (!resolver_getip(hostname, ip, MAX_ADDR_LEN))
{
sock_close (sock);
return -1;
@ -582,7 +582,7 @@ sock_t sock_get_server_socket(const int port, char *sinterface)
#endif
int sa_family, sa_len, error, opt;
sock_t sock;
char ip[40];
char ip[MAX_ADDR_LEN];
if (port < 0)
return SOCK_ERROR;
@ -654,22 +654,36 @@ int sock_listen(sock_t serversock, int backlog)
int sock_accept(sock_t serversock, char *ip, int len)
{
struct sockaddr_in sin;
#ifdef HAVE_IPV6
struct sockaddr_storage sa;
#else
struct sockaddr_in sa;
#endif
int ret;
socklen_t slen;
if (!sock_valid_socket(serversock))
return SOCK_ERROR;
slen = sizeof(struct sockaddr_in);
ret = accept(serversock, (struct sockaddr *)&sin, &slen);
slen = sizeof(sa);
ret = accept(serversock, (struct sockaddr *)&sa, &slen);
if (ret >= 0 && ip != NULL) {
/* inet_ntoa is not reentrant, we should protect this */
strncpy(ip, inet_ntoa(sin.sin_addr), len);
#ifdef HAVE_IPV6
if(inet_ntop(AF_INET, &((struct sockaddr_in *)&sa)->sin_addr,
ip, len) <= 0)
{
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&sa)->sin6_addr,
ip, len);
}
#else
strncpy(ip, inet_ntoa(sa.sin_addr), len);
#endif
sock_set_nolinger(ret);
sock_set_keepalive(ret);
}
return ret;
}

View File

@ -46,6 +46,12 @@ struct iovec
#define inet_aton(a,b) inet_pton(AF_INET, (a), (b))
#endif
#ifdef INET6_ADDRSTRLEN
#define MAX_ADDR_LEN INET6_ADDRSTRLEN
#else
#define MAX_ADDR_LEN 46
#endif
typedef int sock_t;
/* The following values are based on unix avoiding errno value clashes */