Index: bitlbee.c
===================================================================
--- bitlbee.c	(revision 238f828cb3524a2a09337d7502cc6db9556fc67a)
+++ bitlbee.c	(revision e4d62711995840def3a2d51f62923d95cb368cee)
@@ -68,5 +68,9 @@
 int bitlbee_daemon_init()
 {
+#ifdef IPV6
+	struct sockaddr_in6 listen_addr;
+#else
 	struct sockaddr_in listen_addr;
+#endif
 	int i;
 	GIOChannel *ch;
@@ -75,5 +79,5 @@
 	log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG );
 	
-	global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 );
+	global.listen_socket = socket( AF_INETx, SOCK_STREAM, 0 );
 	if( global.listen_socket == -1 )
 	{
@@ -81,9 +85,22 @@
 		return( -1 );
 	}
-	listen_addr.sin_family = AF_INET;
+	
+#ifdef IPV6
+	listen_addr.sin6_family = AF_INETx;
+	listen_addr.sin6_port = htons( global.conf->port );
+	i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin6_addr );
+#else
+	listen_addr.sin_family = AF_INETx;
 	listen_addr.sin_port = htons( global.conf->port );
-	listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface );
-	
-	i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) );
+	i = inet_pton( AF_INETx, global.conf->iface, &listen_addr.sin_addr );
+#endif
+	
+	if( i != 1 )
+	{
+		log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface );
+		return( -1 );
+	}
+	
+	i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) );
 	if( i == -1 )
 	{
Index: irc.c
===================================================================
--- irc.c	(revision 238f828cb3524a2a09337d7502cc6db9556fc67a)
+++ irc.c	(revision e4d62711995840def3a2d51f62923d95cb368cee)
@@ -40,12 +40,15 @@
 irc_t *irc_new( int fd )
 {
-	irc_t *irc = g_new0( irc_t, 1 );
-	
+	irc_t *irc;
+	struct hostent *peer;
+	unsigned int i;
+	char buf[128];
+#ifdef IPV6
+	struct sockaddr_in6 sock[1];
+#else
 	struct sockaddr_in sock[1];
-#ifdef IPV6
-	struct sockaddr_in6 sock6[1];
 #endif
-	struct hostent *peer;
-	unsigned int i, j;
+	
+	irc = g_new0( irc_t, 1 );
 	
 	irc->fd = fd;
@@ -71,19 +74,22 @@
 	
 	i = sizeof( *sock );
-#ifdef IPV6
-	j = sizeof( *sock6 );
-#endif
+	
 	if( global.conf->hostname )
 		irc->myhost = g_strdup( global.conf->hostname );
-	else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
-	{
-		if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
+#ifdef IPV6
+	else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
+	{
+		if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
 			irc->myhost = g_strdup( peer->h_name );
-	}
-#ifdef IPV6
-	else if( getsockname( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
-	{
-		if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
+		else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
+			irc->myhost = g_strdup( buf );
+	}
+#else
+	else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
+	{
+		if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
 			irc->myhost = g_strdup( peer->h_name );
+		else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
+			irc->myhost = g_strdup( buf );
 	}
 #endif
@@ -91,16 +97,18 @@
 	i = sizeof( *sock );
 #ifdef IPV6
-	j = sizeof( *sock6 );
-#endif
-	if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET )
-	{
-		if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) )
+	if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin6_family == AF_INETx )
+	{
+		if( ( peer = gethostbyaddr( (char*) &sock->sin6_addr, sizeof( sock->sin6_addr ), AF_INETx ) ) )
 			irc->host = g_strdup( peer->h_name );
-	}
-#ifdef IPV6
-	else if( getpeername( irc->fd, (struct sockaddr*) sock6, &j ) == 0 && sock6->sin6_family == AF_INET6 )
-	{
-		if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) )
+		else if( inet_ntop( AF_INETx, &sock->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL )
+			irc->host = g_strdup( buf );
+	}
+#else
+	if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INETx )
+	{
+		if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INETx ) ) )
 			irc->host = g_strdup( peer->h_name );
+		else if( inet_ntop( AF_INETx, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL )
+			irc->host = g_strdup( buf );
 	}
 #endif
Index: protocols/http_client.c
===================================================================
--- protocols/http_client.c	(revision 238f828cb3524a2a09337d7502cc6db9556fc67a)
+++ protocols/http_client.c	(revision e4d62711995840def3a2d51f62923d95cb368cee)
@@ -27,7 +27,7 @@
 #include <stdio.h>
 
-#include "sock.h"
 #include "http_client.h"
 #include "url.h"
+#include "sock.h"
 
 
Index: protocols/oscar/oscar.c
===================================================================
--- protocols/oscar/oscar.c	(revision 238f828cb3524a2a09337d7502cc6db9556fc67a)
+++ protocols/oscar/oscar.c	(revision e4d62711995840def3a2d51f62923d95cb368cee)
@@ -21,5 +21,4 @@
  */
 
-#include "sock.h"
 #include <errno.h>
 #include <ctype.h>
@@ -33,4 +32,5 @@
 #include "bitlbee.h"
 #include "proxy.h"
+#include "sock.h"
 
 #include "aim.h"
Index: sock.h
===================================================================
--- sock.h	(revision 238f828cb3524a2a09337d7502cc6db9556fc67a)
+++ sock.h	(revision e4d62711995840def3a2d51f62923d95cb368cee)
@@ -1,4 +1,11 @@
 #include <errno.h>
 #include <fcntl.h>
+
+/* To cut down on the ifdef stuff a little bit in other places */
+#ifdef IPV6
+#define AF_INETx AF_INET6
+#else
+#define AF_INETx AF_INET
+#endif
 
 #ifndef _WIN32
