Index: code/branches/ipv6/src/external/enet/host.c
===================================================================
--- code/branches/ipv6/src/external/enet/host.c	(revision 7329)
+++ code/branches/ipv6/src/external/enet/host.c	(revision 7330)
@@ -50,4 +50,6 @@
 
     host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
+    enet_socket_set_option (host -> socket, ENET_SOCKOPT_V6ONLY, 0); // Needs to be set before bind.
+
     if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
     {
Index: code/branches/ipv6/src/external/enet/include/enet/enet.h
===================================================================
--- code/branches/ipv6/src/external/enet/include/enet/enet.h	(revision 7329)
+++ code/branches/ipv6/src/external/enet/include/enet/enet.h	(revision 7330)
@@ -51,14 +51,16 @@
    ENET_SOCKOPT_RCVBUF    = 3,
    ENET_SOCKOPT_SNDBUF    = 4,
-   ENET_SOCKOPT_REUSEADDR = 5
+   ENET_SOCKOPT_REUSEADDR = 5,
+   ENET_SOCKOPT_V6ONLY = 6
 } ENetSocketOption;
 
-enum
-{
-   ENET_HOST_ANY       = 0,            /**< specifies the default server host */
-   ENET_HOST_BROADCAST = 0xFFFFFFFF,   /**< specifies a subnet-wide broadcast */
-
-   ENET_PORT_ANY       = 0             /**< specifies that a port should be automatically chosen */
-};
+typedef struct _ENetHostAddress
+{
+   enet_uint8 addr[16];
+} ENetHostAddress;
+
+extern const ENetHostAddress ENET_HOST_ANY;       /**< specifies the default server host */
+extern const ENetHostAddress ENET_HOST_BROADCAST; /**< specifies a IPv4 subnet-wide broadcast */
+#define ENET_PORT_ANY 0                           /**< specifies that a port should be automatically chosen */
 
 /**
@@ -74,5 +76,6 @@
 typedef struct _ENetAddress
 {
-   enet_uint32 host;
+   ENetHostAddress host;
+   enet_uint32 scopeID; //FIXME: this is of different size on Windows
    enet_uint16 port;
 } ENetAddress;
@@ -489,4 +492,16 @@
 ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
 
+/** Maps an IPv4 Address to an IPv6 address.
+    @param address IPv4 address in network byte order
+    @returns the IPv4-mapped IPv6 address in network byte order
+*/
+static inline ENetHostAddress enet_address_map4 (enet_uint32 address)
+{
+   ENetHostAddress addr = ENET_HOST_ANY;
+   ((enet_uint16 *)addr.addr)[5] = 0xffff;
+   ((enet_uint32 *)addr.addr)[3] = address;
+   return addr;
+}
+
 /** @} */
 
Index: code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch	(revision 7330)
+++ code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch	(revision 7330)
@@ -0,0 +1,138 @@
+From e4638515a1ade5a23f3b8eb9ca7dad249a3d6903 Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi@koalatux.ch>
+Date: Thu, 2 Sep 2010 14:26:42 +0200
+Subject: [PATCH 1/2] use getaddrinfo for lookup in unix.c
+
+---
+ unix.c |   99 +++++++++++++++++++++++++--------------------------------------
+ 1 files changed, 39 insertions(+), 60 deletions(-)
+
+diff --git a/unix.c b/unix.c
+index 6971541..7329e8d 100644
+--- a/unix.c
++++ b/unix.c
+@@ -74,82 +74,61 @@ enet_time_set (enet_uint32 newTimeBase)
+ int
+ enet_address_set_host (ENetAddress * address, const char * name)
+ {
+-    struct hostent * hostEntry = NULL;
+-#ifdef HAS_GETHOSTBYNAME_R
+-    struct hostent hostData;
+-    char buffer [2048];
+-    int errnum;
+-
+-#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+-    gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
+-#else
+-    hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
+-#endif
+-#else
+-    hostEntry = gethostbyname (name);
+-#endif
++    struct addrinfo hints;
++    struct addrinfo * result;
++    struct addrinfo * res;
++
++    memset(& hints, 0, sizeof (hints));
++    hints.ai_flags = AI_NUMERICSERV;
++    hints.ai_family = AF_INET;
+ 
+-    if (hostEntry == NULL ||
+-        hostEntry -> h_addrtype != AF_INET)
++    if ( getaddrinfo(name, NULL, &hints, &result) )
+     {
+-#ifdef HAS_INET_PTON
+-        if (! inet_pton (AF_INET, name, & address -> host))
+-#else
+-        if (! inet_aton (name, (struct in_addr *) & address -> host))
+-#endif
+-            return -1;
+-        return 0;
++        return -1;
+     }
+ 
+-    address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
++    for (res = result; res != NULL; res = res -> ai_next)
++    {
++        if (res -> ai_family == AF_INET)
++        {
++            address -> host = ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr;
++            break;
++        }
++    }
++    freeaddrinfo(result);
++    if (res == NULL) return -1;
+ 
+     return 0;
+ }
+ 
+-int
+-enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
++static int
++enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
+ {
+-#ifdef HAS_INET_NTOP
+-    if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL)
+-#else
+-    char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
+-    if (addr != NULL)
+-        strncpy (name, addr, nameLength);
+-    else
+-#endif
++    struct sockaddr_in sin;
++
++    memset (& sin, 0, sizeof (struct sockaddr_in));
++
++    sin.sin_family = AF_INET;
++    sin.sin_addr = * (struct in_addr *) & address -> host;
++
++    if ( getnameinfo((struct sockaddr *) & sin, sizeof(sin), name, nameLength, NULL, 0, flags))
++    {
+         return -1;
++    }
++
+     return 0;
+ }
+ 
+ int
+-enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
++enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
+ {
+-    struct in_addr in;
+-    struct hostent * hostEntry = NULL;
+-#ifdef HAS_GETHOSTBYADDR_R
+-    struct hostent hostData;
+-    char buffer [2048];
+-    int errnum;
+-
+-    in.s_addr = address -> host;
+-
+-#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+-    gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
+-#else
+-    hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum);
+-#endif
+-#else
+-    in.s_addr = address -> host;
+-
+-    hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
+-#endif
+-
+-    if (hostEntry == NULL)
+-      return enet_address_get_host_ip (address, name, nameLength);
+-
+-    strncpy (name, hostEntry -> h_name, nameLength);
++    return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
++}
+ 
+-    return 0;
++int
++enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
++{
++    return enet_address_get_host_x(address, name, nameLength, 0);
+ }
+ 
+ int
+-- 
+1.7.1
+
Index: code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch	(revision 7330)
+++ code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch	(revision 7330)
@@ -0,0 +1,347 @@
+From 85c3be6ab21fd875baa57ea119ed58d5c54f0115 Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi@koalatux.ch>
+Date: Thu, 2 Sep 2010 14:27:07 +0200
+Subject: [PATCH 2/2] basic IPv6 support on Linux systems
+
+---
+ host.c              |    2 +
+ include/enet/enet.h |   29 ++++++++++++----
+ protocol.c          |   17 ++++++----
+ unix.c              |   90 ++++++++++++++++++++++++++++++--------------------
+ 4 files changed, 88 insertions(+), 50 deletions(-)
+
+diff --git a/host.c b/host.c
+index 8bb2433..5a18a59 100644
+--- a/host.c
++++ b/host.c
+@@ -49,6 +49,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
+     memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
+ 
+     host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
++    enet_socket_set_option (host -> socket, ENET_SOCKOPT_V6ONLY, 0); // Needs to be set before bind.
++
+     if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
+     {
+        if (host -> socket != ENET_SOCKET_NULL)
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index 2f656d6..a9f0759 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -50,16 +50,18 @@ typedef enum _ENetSocketOption
+    ENET_SOCKOPT_BROADCAST = 2,
+    ENET_SOCKOPT_RCVBUF    = 3,
+    ENET_SOCKOPT_SNDBUF    = 4,
+-   ENET_SOCKOPT_REUSEADDR = 5
++   ENET_SOCKOPT_REUSEADDR = 5,
++   ENET_SOCKOPT_V6ONLY = 6
+ } ENetSocketOption;
+ 
+-enum
++typedef struct _ENetHostAddress
+ {
+-   ENET_HOST_ANY       = 0,            /**< specifies the default server host */
+-   ENET_HOST_BROADCAST = 0xFFFFFFFF,   /**< specifies a subnet-wide broadcast */
++   enet_uint8 addr[16];
++} ENetHostAddress;
+ 
+-   ENET_PORT_ANY       = 0             /**< specifies that a port should be automatically chosen */
+-};
++extern const ENetHostAddress ENET_HOST_ANY;       /**< specifies the default server host */
++extern const ENetHostAddress ENET_HOST_BROADCAST; /**< specifies a IPv4 subnet-wide broadcast */
++#define ENET_PORT_ANY 0                           /**< specifies that a port should be automatically chosen */
+ 
+ /**
+  * Portable internet address structure. 
+@@ -73,7 +75,8 @@ enum
+  */
+ typedef struct _ENetAddress
+ {
+-   enet_uint32 host;
++   ENetHostAddress host;
++   enet_uint32 scopeID; //FIXME: this is of different size on Windows
+    enet_uint16 port;
+ } ENetAddress;
+ 
+@@ -488,6 +491,18 @@ ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostN
+ */
+ ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
+ 
++/** Maps an IPv4 Address to an IPv6 address.
++    @param address IPv4 address in network byte order
++    @returns the IPv4-mapped IPv6 address in network byte order
++*/
++static inline ENetHostAddress enet_address_map4 (enet_uint32 address)
++{
++   ENetHostAddress addr = ENET_HOST_ANY;
++   ((enet_uint16 *)addr.addr)[5] = 0xffff;
++   ((enet_uint32 *)addr.addr)[3] = address;
++   return addr;
++}
++
+ /** @} */
+ 
+ ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
+diff --git a/protocol.c b/protocol.c
+index 8e26dfb..318a2c7 100644
+--- a/protocol.c
++++ b/protocol.c
+@@ -9,6 +9,9 @@
+ #include "enet/time.h"
+ #include "enet/enet.h"
+ 
++const ENetHostAddress ENET_HOST_ANY = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
++const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
++
+ static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] =
+ {
+     0,
+@@ -262,9 +265,9 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
+          ++ currentPeer)
+     {
+         if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&
+-            currentPeer -> address.host == host -> receivedAddress.host &&
+             currentPeer -> address.port == host -> receivedAddress.port &&
+-            currentPeer -> connectID == command -> connect.connectID)
++            currentPeer -> connectID == command -> connect.connectID &&
++            !memcmp(& currentPeer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress)))
+           return NULL;
+     }
+ 
+@@ -848,10 +851,11 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
+ 
+        if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
+            peer -> state == ENET_PEER_STATE_ZOMBIE ||
+-           (host -> receivedAddress.host != peer -> address.host &&
+-             peer -> address.host != ENET_HOST_BROADCAST) ||
+            (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
+-            sessionID != peer -> incomingSessionID))
++            sessionID != peer -> incomingSessionID) ||
++           ( memcmp(& peer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress)) &&
++             memcmp(& peer -> address.host, & ENET_HOST_BROADCAST, sizeof (ENetHostAddress)) &&
++             peer -> address.host.addr[0] != 0xff ) )
+          return 0;
+     }
+  
+@@ -891,8 +895,7 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
+        
+     if (peer != NULL)
+     {
+-       peer -> address.host = host -> receivedAddress.host;
+-       peer -> address.port = host -> receivedAddress.port;
++       peer -> address = host -> receivedAddress;
+        peer -> incomingDataTotal += host -> receivedDataLength;
+     }
+     
+diff --git a/unix.c b/unix.c
+index 7329e8d..49fbace 100644
+--- a/unix.c
++++ b/unix.c
+@@ -79,8 +79,8 @@ enet_address_set_host (ENetAddress * address, const char * name)
+     struct addrinfo * res;
+ 
+     memset(& hints, 0, sizeof (hints));
+-    hints.ai_flags = AI_NUMERICSERV;
+-    hints.ai_family = AF_INET;
++    hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
++    hints.ai_family = AF_UNSPEC;
+ 
+     if ( getaddrinfo(name, NULL, &hints, &result) )
+     {
+@@ -91,7 +91,14 @@ enet_address_set_host (ENetAddress * address, const char * name)
+     {
+         if (res -> ai_family == AF_INET)
+         {
+-            address -> host = ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr;
++            address -> host = enet_address_map4( ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr );
++            address -> scopeID = 0;
++            break;
++        }
++        if (res -> ai_family == AF_INET6)
++        {
++            address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_addr;
++            address -> scopeID = ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_scope_id;
+             break;
+         }
+     }
+@@ -104,12 +111,13 @@ enet_address_set_host (ENetAddress * address, const char * name)
+ static int
+ enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
+ {
+-    struct sockaddr_in sin;
++    struct sockaddr_in6 sin;
+ 
+-    memset (& sin, 0, sizeof (struct sockaddr_in));
++    memset (& sin, 0, sizeof (struct sockaddr_in6));
+ 
+-    sin.sin_family = AF_INET;
+-    sin.sin_addr = * (struct in_addr *) & address -> host;
++    sin.sin6_family = AF_INET6;
++    sin.sin6_addr = * (struct in6_addr *) & address -> host;
++    sin.sin6_scope_id = address -> scopeID;
+ 
+     if ( getnameinfo((struct sockaddr *) & sin, sizeof(sin), name, nameLength, NULL, 0, flags))
+     {
+@@ -134,26 +142,28 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
+ int
+ enet_socket_bind (ENetSocket socket, const ENetAddress * address)
+ {
+-    struct sockaddr_in sin;
++    struct sockaddr_in6 sin;
+ 
+-    memset (& sin, 0, sizeof (struct sockaddr_in));
++    memset (& sin, 0, sizeof (struct sockaddr_in6));
+ 
+-    sin.sin_family = AF_INET;
++    sin.sin6_family = AF_INET6;
+ 
+     if (address != NULL)
+     {
+-       sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+-       sin.sin_addr.s_addr = address -> host;
++       sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++       sin.sin6_addr = * (struct in6_addr *) & address -> host;
++       sin.sin6_scope_id = address -> scopeID;
+     }
+     else
+     {
+-       sin.sin_port = 0;
+-       sin.sin_addr.s_addr = INADDR_ANY;
++       sin.sin6_port = 0;
++       sin.sin6_addr = in6addr_any;
++       sin.sin6_scope_id = 0;
+     }
+ 
+     return bind (socket,
+                  (struct sockaddr *) & sin,
+-                 sizeof (struct sockaddr_in)); 
++                 sizeof (struct sockaddr_in6));
+ }
+ 
+ int 
+@@ -165,7 +175,7 @@ enet_socket_listen (ENetSocket socket, int backlog)
+ ENetSocket
+ enet_socket_create (ENetSocketType type)
+ {
+-    return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
++    return socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
+ }
+ 
+ int
+@@ -198,6 +208,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+             result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int));
+             break;
+ 
++        case ENET_SOCKOPT_V6ONLY:
++            result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int));
++            break;
++
+         default:
+             break;
+     }
+@@ -207,23 +221,24 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+ int
+ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
+ {
+-    struct sockaddr_in sin;
++    struct sockaddr_in6 sin;
+ 
+-    memset (& sin, 0, sizeof (struct sockaddr_in));
++    memset (& sin, 0, sizeof (struct sockaddr_in6));
+ 
+-    sin.sin_family = AF_INET;
+-    sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+-    sin.sin_addr.s_addr = address -> host;
++    sin.sin6_family = AF_INET6;
++    sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++    sin.sin6_addr = * (struct in6_addr *) & address -> host;
++    sin.sin6_scope_id = address -> scopeID;
+ 
+-    return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
++    return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
+ }
+ 
+ ENetSocket
+ enet_socket_accept (ENetSocket socket, ENetAddress * address)
+ {
+     int result;
+-    struct sockaddr_in sin;
+-    socklen_t sinLength = sizeof (struct sockaddr_in);
++    struct sockaddr_in6 sin;
++    socklen_t sinLength = sizeof (struct sockaddr_in6);
+ 
+     result = accept (socket, 
+                      address != NULL ? (struct sockaddr *) & sin : NULL, 
+@@ -234,8 +249,9 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
+ 
+     if (address != NULL)
+     {
+-        address -> host = (enet_uint32) sin.sin_addr.s_addr;
+-        address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
++        address -> host = * (ENetHostAddress *) & sin.sin6_addr;
++        address -> scopeID = sin.sin6_scope_id;
++        address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
+     }
+ 
+     return result;
+@@ -254,21 +270,22 @@ enet_socket_send (ENetSocket socket,
+                   size_t bufferCount)
+ {
+     struct msghdr msgHdr;
+-    struct sockaddr_in sin;
++    struct sockaddr_in6 sin;
+     int sentLength;
+ 
+     memset (& msgHdr, 0, sizeof (struct msghdr));
+ 
+     if (address != NULL)
+     {
+-        memset (& sin, 0, sizeof (struct sockaddr_in));
++        memset (& sin, 0, sizeof (struct sockaddr_in6));
+ 
+-        sin.sin_family = AF_INET;
+-        sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+-        sin.sin_addr.s_addr = address -> host;
++        sin.sin6_family = AF_INET6;
++        sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++        sin.sin6_addr = * (struct in6_addr *) & address -> host;
++        sin.sin6_scope_id = address -> scopeID;
+ 
+         msgHdr.msg_name = & sin;
+-        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
++        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
+     }
+ 
+     msgHdr.msg_iov = (struct iovec *) buffers;
+@@ -294,7 +311,7 @@ enet_socket_receive (ENetSocket socket,
+                      size_t bufferCount)
+ {
+     struct msghdr msgHdr;
+-    struct sockaddr_in sin;
++    struct sockaddr_in6 sin;
+     int recvLength;
+ 
+     memset (& msgHdr, 0, sizeof (struct msghdr));
+@@ -302,7 +319,7 @@ enet_socket_receive (ENetSocket socket,
+     if (address != NULL)
+     {
+         msgHdr.msg_name = & sin;
+-        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
++        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
+     }
+ 
+     msgHdr.msg_iov = (struct iovec *) buffers;
+@@ -325,8 +342,9 @@ enet_socket_receive (ENetSocket socket,
+ 
+     if (address != NULL)
+     {
+-        address -> host = (enet_uint32) sin.sin_addr.s_addr;
+-        address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
++        address -> host = * (ENetHostAddress *) & sin.sin6_addr;
++        address -> scopeID = sin.sin6_scope_id;
++        address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
+     }
+ 
+     return recvLength;
+-- 
+1.7.1
+
Index: code/branches/ipv6/src/external/enet/protocol.c
===================================================================
--- code/branches/ipv6/src/external/enet/protocol.c	(revision 7329)
+++ code/branches/ipv6/src/external/enet/protocol.c	(revision 7330)
@@ -9,4 +9,7 @@
 #include "enet/time.h"
 #include "enet/enet.h"
+
+const ENetHostAddress ENET_HOST_ANY = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
+const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
 
 static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] =
@@ -263,7 +266,7 @@
     {
         if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&
-            currentPeer -> address.host == host -> receivedAddress.host &&
             currentPeer -> address.port == host -> receivedAddress.port &&
-            currentPeer -> connectID == command -> connect.connectID)
+            currentPeer -> connectID == command -> connect.connectID &&
+            !memcmp(& currentPeer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress)))
           return NULL;
     }
@@ -849,8 +852,9 @@
        if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
            peer -> state == ENET_PEER_STATE_ZOMBIE ||
-           (host -> receivedAddress.host != peer -> address.host &&
-             peer -> address.host != ENET_HOST_BROADCAST) ||
            (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
-            sessionID != peer -> incomingSessionID))
+            sessionID != peer -> incomingSessionID) ||
+           ( memcmp(& peer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress)) &&
+             memcmp(& peer -> address.host, & ENET_HOST_BROADCAST, sizeof (ENetHostAddress)) &&
+             peer -> address.host.addr[0] != 0xff ) )
          return 0;
     }
@@ -892,6 +896,5 @@
     if (peer != NULL)
     {
-       peer -> address.host = host -> receivedAddress.host;
-       peer -> address.port = host -> receivedAddress.port;
+       peer -> address = host -> receivedAddress;
        peer -> incomingDataTotal += host -> receivedDataLength;
     }
Index: code/branches/ipv6/src/external/enet/unix.c
===================================================================
--- code/branches/ipv6/src/external/enet/unix.c	(revision 7329)
+++ code/branches/ipv6/src/external/enet/unix.c	(revision 7330)
@@ -75,105 +75,94 @@
 enet_address_set_host (ENetAddress * address, const char * name)
 {
-    struct hostent * hostEntry = NULL;
-#ifdef HAS_GETHOSTBYNAME_R
-    struct hostent hostData;
-    char buffer [2048];
-    int errnum;
-
-#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-    gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
-#else
-    hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
-#endif
-#else
-    hostEntry = gethostbyname (name);
-#endif
-
-    if (hostEntry == NULL ||
-        hostEntry -> h_addrtype != AF_INET)
-    {
-#ifdef HAS_INET_PTON
-        if (! inet_pton (AF_INET, name, & address -> host))
-#else
-        if (! inet_aton (name, (struct in_addr *) & address -> host))
-#endif
-            return -1;
-        return 0;
-    }
-
-    address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
+    struct addrinfo hints;
+    struct addrinfo * result;
+    struct addrinfo * res;
+
+    memset(& hints, 0, sizeof (hints));
+    hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
+    hints.ai_family = AF_UNSPEC;
+
+    if ( getaddrinfo(name, NULL, &hints, &result) )
+    {
+        return -1;
+    }
+
+    for (res = result; res != NULL; res = res -> ai_next)
+    {
+        if (res -> ai_family == AF_INET)
+        {
+            address -> host = enet_address_map4( ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr );
+            address -> scopeID = 0;
+            break;
+        }
+        if (res -> ai_family == AF_INET6)
+        {
+            address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_addr;
+            address -> scopeID = ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_scope_id;
+            break;
+        }
+    }
+    freeaddrinfo(result);
+    if (res == NULL) return -1;
 
     return 0;
 }
 
+static int
+enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
+{
+    struct sockaddr_in6 sin;
+
+    memset (& sin, 0, sizeof (struct sockaddr_in6));
+
+    sin.sin6_family = AF_INET6;
+    sin.sin6_addr = * (struct in6_addr *) & address -> host;
+    sin.sin6_scope_id = address -> scopeID;
+
+    if ( getnameinfo((struct sockaddr *) & sin, sizeof(sin), name, nameLength, NULL, 0, flags))
+    {
+        return -1;
+    }
+
+    return 0;
+}
+
 int
 enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
 {
-#ifdef HAS_INET_NTOP
-    if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL)
-#else
-    char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
-    if (addr != NULL)
-        strncpy (name, addr, nameLength);
+    return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
+}
+
+int
+enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
+{
+    return enet_address_get_host_x(address, name, nameLength, 0);
+}
+
+int
+enet_socket_bind (ENetSocket socket, const ENetAddress * address)
+{
+    struct sockaddr_in6 sin;
+
+    memset (& sin, 0, sizeof (struct sockaddr_in6));
+
+    sin.sin6_family = AF_INET6;
+
+    if (address != NULL)
+    {
+       sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
+       sin.sin6_addr = * (struct in6_addr *) & address -> host;
+       sin.sin6_scope_id = address -> scopeID;
+    }
     else
-#endif
-        return -1;
-    return 0;
-}
-
-int
-enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
-{
-    struct in_addr in;
-    struct hostent * hostEntry = NULL;
-#ifdef HAS_GETHOSTBYADDR_R
-    struct hostent hostData;
-    char buffer [2048];
-    int errnum;
-
-    in.s_addr = address -> host;
-
-#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-    gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
-#else
-    hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum);
-#endif
-#else
-    in.s_addr = address -> host;
-
-    hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
-#endif
-
-    if (hostEntry == NULL)
-      return enet_address_get_host_ip (address, name, nameLength);
-
-    strncpy (name, hostEntry -> h_name, nameLength);
-
-    return 0;
-}
-
-int
-enet_socket_bind (ENetSocket socket, const ENetAddress * address)
-{
-    struct sockaddr_in sin;
-
-    memset (& sin, 0, sizeof (struct sockaddr_in));
-
-    sin.sin_family = AF_INET;
-
-    if (address != NULL)
-    {
-       sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
-       sin.sin_addr.s_addr = address -> host;
-    }
-    else
-    {
-       sin.sin_port = 0;
-       sin.sin_addr.s_addr = INADDR_ANY;
+    {
+       sin.sin6_port = 0;
+       sin.sin6_addr = in6addr_any;
+       sin.sin6_scope_id = 0;
     }
 
     return bind (socket,
                  (struct sockaddr *) & sin,
-                 sizeof (struct sockaddr_in)); 
+                 sizeof (struct sockaddr_in6));
 }
 
@@ -187,5 +176,5 @@
 enet_socket_create (ENetSocketType type)
 {
-    return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
+    return socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
 }
 
@@ -220,4 +209,8 @@
             break;
 
+        case ENET_SOCKOPT_V6ONLY:
+            result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int));
+            break;
+
         default:
             break;
@@ -229,13 +222,14 @@
 enet_socket_connect (ENetSocket socket, const ENetAddress * address)
 {
-    struct sockaddr_in sin;
-
-    memset (& sin, 0, sizeof (struct sockaddr_in));
-
-    sin.sin_family = AF_INET;
-    sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
-    sin.sin_addr.s_addr = address -> host;
-
-    return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
+    struct sockaddr_in6 sin;
+
+    memset (& sin, 0, sizeof (struct sockaddr_in6));
+
+    sin.sin6_family = AF_INET6;
+    sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
+    sin.sin6_addr = * (struct in6_addr *) & address -> host;
+    sin.sin6_scope_id = address -> scopeID;
+
+    return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
 }
 
@@ -244,6 +238,6 @@
 {
     int result;
-    struct sockaddr_in sin;
-    socklen_t sinLength = sizeof (struct sockaddr_in);
+    struct sockaddr_in6 sin;
+    socklen_t sinLength = sizeof (struct sockaddr_in6);
 
     result = accept (socket, 
@@ -256,6 +250,7 @@
     if (address != NULL)
     {
-        address -> host = (enet_uint32) sin.sin_addr.s_addr;
-        address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
+        address -> host = * (ENetHostAddress *) & sin.sin6_addr;
+        address -> scopeID = sin.sin6_scope_id;
+        address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
     }
 
@@ -276,5 +271,5 @@
 {
     struct msghdr msgHdr;
-    struct sockaddr_in sin;
+    struct sockaddr_in6 sin;
     int sentLength;
 
@@ -283,12 +278,13 @@
     if (address != NULL)
     {
-        memset (& sin, 0, sizeof (struct sockaddr_in));
-
-        sin.sin_family = AF_INET;
-        sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
-        sin.sin_addr.s_addr = address -> host;
+        memset (& sin, 0, sizeof (struct sockaddr_in6));
+
+        sin.sin6_family = AF_INET6;
+        sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
+        sin.sin6_addr = * (struct in6_addr *) & address -> host;
+        sin.sin6_scope_id = address -> scopeID;
 
         msgHdr.msg_name = & sin;
-        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
+        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
     }
 
@@ -316,5 +312,5 @@
 {
     struct msghdr msgHdr;
-    struct sockaddr_in sin;
+    struct sockaddr_in6 sin;
     int recvLength;
 
@@ -324,5 +320,5 @@
     {
         msgHdr.msg_name = & sin;
-        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
+        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
     }
 
@@ -347,6 +343,7 @@
     if (address != NULL)
     {
-        address -> host = (enet_uint32) sin.sin_addr.s_addr;
-        address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
+        address -> host = * (ENetHostAddress *) & sin.sin6_addr;
+        address -> scopeID = sin.sin6_scope_id;
+        address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
     }
 
