[xiph-cvs] cvs commit: net sock.c sock.h
Michael Smith
msmith at xiph.org
Thu Feb 13 03:29:07 PST 2003
msmith 03/02/13 06:29:07
Modified: src connection.c
. sock.c sock.h
Log:
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.
Revision Changes Path
1.49 +2 -2 icecast/src/connection.c
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- connection.c 12 Feb 2003 22:50:59 -0000 1.48
+++ connection.c 13 Feb 2003 11:29:07 -0000 1.49
@@ -126,9 +126,9 @@
}
/* 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);
<p><p>1.15 +22 -8 net/sock.c
Index: sock.c
===================================================================
RCS file: /usr/local/cvsroot/net/sock.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- sock.c 12 Feb 2003 10:58:17 -0000 1.14
+++ sock.c 13 Feb 2003 11:29:07 -0000 1.15
@@ -486,11 +486,11 @@
#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 @@
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 @@
#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_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;
}
+
<p><p>1.11 +6 -0 net/sock.h
Index: sock.h
===================================================================
RCS file: /usr/local/cvsroot/net/sock.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- sock.h 6 Feb 2003 13:10:48 -0000 1.10
+++ sock.h 13 Feb 2003 11:29:07 -0000 1.11
@@ -46,6 +46,12 @@
#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 */
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list