mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-11-03 04:17:20 -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/net/; revision=4342
This commit is contained in:
parent
ca71d4dea7
commit
38ab54d207
30
net/sock.c
30
net/sock.c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user