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 7378)
+++ /code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch	(revision 7378)
@@ -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/4] 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 7378)
+++ /code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch	(revision 7378)
@@ -0,0 +1,381 @@
+From fc72c66f6b8a6b1d924ffa86861ce00a1c591839 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/4] basic IPv6 support on Linux systems
+
+this uses IPv4-mapped IPv6 addresses
+---
+ include/enet/enet.h |   22 ++++++--
+ protocol.c          |   26 +++++++---
+ unix.c              |  134 ++++++++++++++++++++++++++++++---------------------
+ 3 files changed, 114 insertions(+), 68 deletions(-)
+
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index 2f656d6..d3ca971 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -53,13 +53,16 @@ typedef enum _ENetSocketOption
+    ENET_SOCKOPT_REUSEADDR = 5
+ } 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_IPV4MAPPED_PREFIX; /**< specifies the IPv4-mapped IPv6 prefix */
++extern const ENetHostAddress ENET_HOST_BROADCAST;    /**< specifies a IPv4 subnet-wide broadcast */
++#define ENET_IPV4MAPPED_PREFIX_LEN 12                /**< specifies the length of the IPv4-mapped IPv6 prefix */
++#define ENET_PORT_ANY 0                              /**< specifies that a port should be automatically chosen */
+ 
+ /**
+  * Portable internet address structure. 
+@@ -73,7 +76,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 +492,12 @@ 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
++*/
++ENET_API ENetHostAddress enet_address_map4 (enet_uint32 address);
++
+ /** @} */
+ 
+ ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
+diff --git a/protocol.c b/protocol.c
+index 8e26dfb..930835e 100644
+--- a/protocol.c
++++ b/protocol.c
+@@ -9,6 +9,10 @@
+ #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_IPV4MAPPED_PREFIX = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 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,
+@@ -25,6 +29,14 @@ static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] =
+     sizeof (ENetProtocolThrottleConfigure),
+ };
+ 
++ENetHostAddress
++enet_address_map4 (enet_uint32 address)
++{
++    ENetHostAddress addr = ENET_IPV4MAPPED_PREFIX;
++    ((enet_uint32 *)addr.addr)[3] = address;
++    return addr;
++}
++
+ size_t
+ enet_protocol_command_size (enet_uint8 commandNumber)
+ {
+@@ -262,9 +274,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 +860,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 +904,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..de032bb 100644
+--- a/unix.c
++++ b/unix.c
+@@ -71,30 +71,72 @@ enet_time_set (enet_uint32 newTimeBase)
+     timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
+ }
+ 
++static int
++enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
++{
++    memset (address, 0, sizeof (ENetAddress));
++    if (sin -> sa_family == AF_INET)
++    {
++        address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
++        //address -> scopeID = 0;
++        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in *) sin) -> sin_port);
++        return 0;
++    }
++    if (sin -> sa_family == AF_INET6)
++    {
++        address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) sin) -> sin6_addr;
++        address -> scopeID = ((struct sockaddr_in6 *) sin) -> sin6_scope_id;
++        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in6 *) sin) -> sin6_port);
++        return 0;
++    }
++    return -1;
++}
++
++static int
++enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, sa_family_t family)
++{
++    if (family == AF_INET)
++    {
++        memset (sin, 0, sizeof (struct sockaddr_in));
++        ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
++        ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
++        ((struct sockaddr_in *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
++        return 0;
++    }
++    else if (family == AF_INET6)
++    {
++        memset (sin, 0, sizeof (struct sockaddr_in6));
++        ((struct sockaddr_in6 *) sin) -> sin6_family = AF_INET6;
++        ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
++        ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
++        ((struct sockaddr_in6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++        return 0;
++    }
++    return -1;
++}
++
+ int
+ enet_address_set_host (ENetAddress * address, const char * name)
+ {
++    enet_uint16 port = address -> port;
+     struct addrinfo hints;
+     struct addrinfo * result;
+     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) )
+-    {
+         return -1;
+-    }
+ 
+     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;
++        if ( !enet_address_set_address(address, res -> ai_addr) )
+             break;
+-        }
+     }
++
++    address -> port = port;
+     freeaddrinfo(result);
+     if (res == NULL) return -1;
+ 
+@@ -104,17 +146,11 @@ 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;
+-
+-    memset (& sin, 0, sizeof (struct sockaddr_in));
++    struct sockaddr_storage sin;
++    enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
+ 
+-    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))
+-    {
++    if ( getnameinfo((struct sockaddr *) & sin, sizeof(struct sockaddr_in6), name, nameLength, NULL, 0, flags))
+         return -1;
+-    }
+ 
+     return 0;
+ }
+@@ -134,29 +170,22 @@ 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;
+-
+-    memset (& sin, 0, sizeof (struct sockaddr_in));
+-
+-    sin.sin_family = AF_INET;
++    struct sockaddr_storage sin;
+ 
+     if (address != NULL)
+     {
+-       sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+-       sin.sin_addr.s_addr = address -> host;
++        enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
+     }
+     else
+     {
+-       sin.sin_port = 0;
+-       sin.sin_addr.s_addr = INADDR_ANY;
++        ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
++        enet_address_set_sin((struct sockaddr *) & sin, & address_, AF_INET6);
+     }
+ 
+-    return bind (socket,
+-                 (struct sockaddr *) & sin,
+-                 sizeof (struct sockaddr_in)); 
++    return bind (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
+ }
+ 
+-int 
++int
+ enet_socket_listen (ENetSocket socket, int backlog)
+ {
+     return listen (socket, backlog < 0 ? SOMAXCONN : backlog);
+@@ -165,7 +194,14 @@ 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);
++    ENetSocket sock = socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
++
++#ifdef IPV6_V6ONLY
++    int value = 0;
++    setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
++#endif // IPV6_V6ONLY
++
++    return sock;
+ }
+ 
+ int
+@@ -207,23 +243,18 @@ 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_storage sin;
++    enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
+ 
+-    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));
++    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_storage sin;
++    socklen_t sinLength = sizeof (struct sockaddr_in6);
+ 
+     result = accept (socket, 
+                      address != NULL ? (struct sockaddr *) & sin : NULL, 
+@@ -234,8 +265,7 @@ 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);
++        enet_address_set_address(address, (struct sockaddr *) & sin);
+     }
+ 
+     return result;
+@@ -254,21 +284,16 @@ enet_socket_send (ENetSocket socket,
+                   size_t bufferCount)
+ {
+     struct msghdr msgHdr;
+-    struct sockaddr_in sin;
++    struct sockaddr_storage sin;
+     int sentLength;
+ 
+     memset (& msgHdr, 0, sizeof (struct msghdr));
+ 
+     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;
+-
++        enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
+         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 +319,7 @@ enet_socket_receive (ENetSocket socket,
+                      size_t bufferCount)
+ {
+     struct msghdr msgHdr;
+-    struct sockaddr_in sin;
++    struct sockaddr_storage sin;
+     int recvLength;
+ 
+     memset (& msgHdr, 0, sizeof (struct msghdr));
+@@ -302,7 +327,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 +350,7 @@ 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);
++        enet_address_set_address(address, (struct sockaddr *) & sin);
+     }
+ 
+     return recvLength;
+-- 
+1.7.1
+
Index: /code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch
===================================================================
--- /code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch	(revision 7378)
+++ /code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch	(revision 7378)
@@ -0,0 +1,309 @@
+From 130babc6f69e07830f73f7757222597117eb1cba Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi@koalatux.ch>
+Date: Mon, 6 Sep 2010 14:58:50 +0200
+Subject: [PATCH 3/4] using address family in functions
+
+---
+ host.c              |    4 +-
+ include/enet/enet.h |   22 +++++++++---
+ protocol.c          |    5 ++-
+ unix.c              |   87 ++++++++++++++++++++++++++++++++------------------
+ 4 files changed, 77 insertions(+), 41 deletions(-)
+
+diff --git a/host.c b/host.c
+index 8bb2433..9ccf894 100644
+--- a/host.c
++++ b/host.c
+@@ -48,8 +48,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);
+-    if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
++    host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6);
++    if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address, ENET_IPV6) < 0))
+     {
+        if (host -> socket != ENET_SOCKET_NULL)
+          enet_socket_destroy (host -> socket);
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index d3ca971..97f0556 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -82,6 +82,16 @@ typedef struct _ENetAddress
+ } ENetAddress;
+ 
+ /**
++ * The address family type.
++ */
++typedef enum _ENetAddressFamily
++{
++    ENET_NO_ADDRESS_FAMILY = 0,
++    ENET_IPV4 = 1,
++    ENET_IPV6 = 2
++} ENetAddressFamily;
++
++/**
+  * Packet flag bit constants.
+  *
+  * The host must be specified in network byte-order, and the port must be in
+@@ -445,13 +455,13 @@ ENET_API void enet_time_set (enet_uint32);
+ /** @defgroup socket ENet socket functions
+     @{
+ */
+-ENET_API ENetSocket enet_socket_create (ENetSocketType);
+-ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *);
++ENET_API ENetSocket enet_socket_create (ENetSocketType, ENetAddressFamily);
++ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *, ENetAddressFamily);
+ ENET_API int        enet_socket_listen (ENetSocket, int);
+-ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
+-ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *);
+-ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
+-ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
++ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *, ENetAddressFamily);
++ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *, ENetAddressFamily);
++ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, ENetAddressFamily);
++ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddressFamily);
+ ENET_API int        enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
+ ENET_API int        enet_socket_set_option (ENetSocket, ENetSocketOption, int);
+ ENET_API void       enet_socket_destroy (ENetSocket);
+diff --git a/protocol.c b/protocol.c
+index 930835e..4c4850a 100644
+--- a/protocol.c
++++ b/protocol.c
+@@ -1046,7 +1046,8 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
+        receivedLength = enet_socket_receive (host -> socket,
+                                              & host -> receivedAddress,
+                                              & buffer,
+-                                             1);
++                                             1,
++                                             ENET_IPV6);
+ 
+        if (receivedLength < 0)
+          return -1;
+@@ -1509,7 +1510,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
+ 
+         currentPeer -> lastSendTime = host -> serviceTime;
+ 
+-        sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount);
++        sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount, ENET_IPV6);
+ 
+         enet_protocol_remove_sent_unreliable_commands (currentPeer);
+ 
+diff --git a/unix.c b/unix.c
+index de032bb..13a24d8 100644
+--- a/unix.c
++++ b/unix.c
+@@ -71,7 +71,28 @@ enet_time_set (enet_uint32 newTimeBase)
+     timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
+ }
+ 
+-static int
++static enet_uint16
++enet_af (ENetAddressFamily family)
++{
++    if (family == ENET_IPV4)
++        return AF_INET;
++    if (family == ENET_IPV6)
++        return AF_INET6;
++    return 0;
++}
++
++static socklen_t
++enet_sa_size (ENetAddressFamily family)
++{
++    if (family == ENET_IPV4)
++        return sizeof (struct sockaddr_in);
++    if (family == ENET_IPV6)
++        return sizeof (struct sockaddr_in6);
++    return 0;
++}
++
++
++static ENetAddressFamily
+ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
+ {
+     memset (address, 0, sizeof (ENetAddress));
+@@ -80,32 +101,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
+         address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
+         //address -> scopeID = 0;
+         address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in *) sin) -> sin_port);
+-        return 0;
++        return ENET_IPV4;
+     }
+     if (sin -> sa_family == AF_INET6)
+     {
+         address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) sin) -> sin6_addr;
+         address -> scopeID = ((struct sockaddr_in6 *) sin) -> sin6_scope_id;
+         address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in6 *) sin) -> sin6_port);
+-        return 0;
++        return ENET_IPV6;
+     }
+-    return -1;
++    return ENET_NO_ADDRESS_FAMILY;
+ }
+ 
+ static int
+-enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, sa_family_t family)
++enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
+ {
+-    if (family == AF_INET)
++    memset (sin, 0, enet_sa_size(family));
++    if (family == ENET_IPV4)
+     {
+-        memset (sin, 0, sizeof (struct sockaddr_in));
+         ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
+         ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
+         ((struct sockaddr_in *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
+         return 0;
+     }
+-    else if (family == AF_INET6)
++    else if (family == ENET_IPV6)
+     {
+-        memset (sin, 0, sizeof (struct sockaddr_in6));
+         ((struct sockaddr_in6 *) sin) -> sin6_family = AF_INET6;
+         ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
+         ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
+@@ -132,7 +152,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
+ 
+     for (res = result; res != NULL; res = res -> ai_next)
+     {
+-        if ( !enet_address_set_address(address, res -> ai_addr) )
++        if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
+             break;
+     }
+ 
+@@ -147,9 +167,9 @@ static int
+ enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
+ {
+     struct sockaddr_storage sin;
+-    enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
++    enet_address_set_sin((struct sockaddr *) & sin, address, ENET_IPV6);
+ 
+-    if ( getnameinfo((struct sockaddr *) & sin, sizeof(struct sockaddr_in6), name, nameLength, NULL, 0, flags))
++    if ( getnameinfo((struct sockaddr *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
+         return -1;
+ 
+     return 0;
+@@ -168,21 +188,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
+ }
+ 
+ int
+-enet_socket_bind (ENetSocket socket, const ENetAddress * address)
++enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
+ {
+     struct sockaddr_storage sin;
+ 
+     if (address != NULL)
+     {
+-        enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
++        enet_address_set_sin((struct sockaddr *) & sin, address, family);
+     }
+     else
+     {
+         ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
+-        enet_address_set_sin((struct sockaddr *) & sin, & address_, AF_INET6);
++        enet_address_set_sin((struct sockaddr *) & sin, & address_, family);
+     }
+ 
+-    return bind (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
++    return bind (socket, (struct sockaddr *) & sin, enet_sa_size(family));
+ }
+ 
+ int
+@@ -192,13 +212,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
+ }
+ 
+ ENetSocket
+-enet_socket_create (ENetSocketType type)
++enet_socket_create (ENetSocketType type, ENetAddressFamily family)
+ {
+-    ENetSocket sock = socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
++    ENetSocket sock = socket (enet_af (family), type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
+ 
+ #ifdef IPV6_V6ONLY
+-    int value = 0;
+-    setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
++    if (family == ENET_IPV6)
++    {
++        int value = 0;
++        setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
++    }
+ #endif // IPV6_V6ONLY
+ 
+     return sock;
+@@ -241,25 +264,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+ }
+ 
+ int
+-enet_socket_connect (ENetSocket socket, const ENetAddress * address)
++enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
+ {
+     struct sockaddr_storage sin;
+-    enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
++    enet_address_set_sin((struct sockaddr *) & sin, address, family);
+ 
+-    return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
++    return connect (socket, (struct sockaddr *) & sin, enet_sa_size (family));
+ }
+ 
+ ENetSocket
+-enet_socket_accept (ENetSocket socket, ENetAddress * address)
++enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
+ {
+     int result;
+     struct sockaddr_storage sin;
+-    socklen_t sinLength = sizeof (struct sockaddr_in6);
++    socklen_t sinLength = enet_sa_size (family);
+ 
+     result = accept (socket, 
+                      address != NULL ? (struct sockaddr *) & sin : NULL, 
+                      address != NULL ? & sinLength : NULL);
+-    
++
+     if (result == -1)
+       return ENET_SOCKET_NULL;
+ 
+@@ -281,7 +304,8 @@ int
+ enet_socket_send (ENetSocket socket,
+                   const ENetAddress * address,
+                   const ENetBuffer * buffers,
+-                  size_t bufferCount)
++                  size_t bufferCount,
++                  ENetAddressFamily family)
+ {
+     struct msghdr msgHdr;
+     struct sockaddr_storage sin;
+@@ -291,9 +315,9 @@ enet_socket_send (ENetSocket socket,
+ 
+     if (address != NULL)
+     {
+-        enet_address_set_sin((struct sockaddr *) & sin, address, AF_INET6);
++        enet_address_set_sin((struct sockaddr *) & sin, address, family);
+         msgHdr.msg_name = & sin;
+-        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
++        msgHdr.msg_namelen = enet_sa_size (family);
+     }
+ 
+     msgHdr.msg_iov = (struct iovec *) buffers;
+@@ -316,7 +340,8 @@ int
+ enet_socket_receive (ENetSocket socket,
+                      ENetAddress * address,
+                      ENetBuffer * buffers,
+-                     size_t bufferCount)
++                     size_t bufferCount,
++                     ENetAddressFamily family)
+ {
+     struct msghdr msgHdr;
+     struct sockaddr_storage sin;
+@@ -327,7 +352,7 @@ enet_socket_receive (ENetSocket socket,
+     if (address != NULL)
+     {
+         msgHdr.msg_name = & sin;
+-        msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
++        msgHdr.msg_namelen = enet_sa_size (family);
+     }
+ 
+     msgHdr.msg_iov = (struct iovec *) buffers;
+-- 
+1.7.1
+
Index: /code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch
===================================================================
--- /code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch	(revision 7378)
+++ /code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch	(revision 7378)
@@ -0,0 +1,310 @@
+From d61448922c08e6801f07c38077623d3bcc513ad4 Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi@koalatux.ch>
+Date: Wed, 8 Sep 2010 12:50:04 +0200
+Subject: [PATCH 4/4] using two separate sockets for IPv4 and IPv6
+
+---
+ host.c              |   45 ++++++++++++++++++++++++++++++++++++---------
+ include/enet/enet.h |   11 +++++++++--
+ protocol.c          |   42 ++++++++++++++++++++++++++++++++++++------
+ unix.c              |   38 ++++++++++++++++++++++++++------------
+ 4 files changed, 107 insertions(+), 29 deletions(-)
+
+diff --git a/host.c b/host.c
+index 9ccf894..85dfa3c 100644
+--- a/host.c
++++ b/host.c
+@@ -48,11 +48,15 @@ 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_IPV6);
+-    if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address, ENET_IPV6) < 0))
++
++    // FIXME: check address for ANY_ADRESS if not only bind to specific protocol
++    // FIXME: allow to fail one of the two protocols
++    /* IPv4 */
++    host -> socket4 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV4);
++    if (host -> socket4 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket4, address, ENET_IPV4) < 0))
+     {
+-       if (host -> socket != ENET_SOCKET_NULL)
+-         enet_socket_destroy (host -> socket);
++       if (host -> socket4 != ENET_SOCKET_NULL)
++         enet_socket_destroy (host -> socket4);
+ 
+        enet_free (host -> peers);
+        enet_free (host);
+@@ -60,10 +64,32 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
+        return NULL;
+     }
+ 
+-    enet_socket_set_option (host -> socket, ENET_SOCKOPT_NONBLOCK, 1);
+-    enet_socket_set_option (host -> socket, ENET_SOCKOPT_BROADCAST, 1);
+-    enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
+-    enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
++    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_NONBLOCK, 1);
++    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_BROADCAST, 1);
++    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
++    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
++
++    /* IPv6 */
++    host -> socket6 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6);
++    if (host -> socket6 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket6, address, ENET_IPV6) < 0))
++    {
++       if (host -> socket6 != ENET_SOCKET_NULL)
++       {
++           enet_socket_destroy (host -> socket4);
++           enet_socket_destroy (host -> socket6);
++       }
++
++       enet_free (host -> peers);
++       enet_free (host);
++
++       return NULL;
++    }
++
++    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_NONBLOCK, 1);
++    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_BROADCAST, 1);
++    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
++    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
++
+ 
+     if (address != NULL)
+       host -> address = * address;
+@@ -133,7 +159,8 @@ enet_host_destroy (ENetHost * host)
+ {
+     ENetPeer * currentPeer;
+ 
+-    enet_socket_destroy (host -> socket);
++    enet_socket_destroy (host -> socket4);
++    enet_socket_destroy (host -> socket6);
+ 
+     for (currentPeer = host -> peers;
+          currentPeer < & host -> peers [host -> peerCount];
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index 97f0556..39cf93e 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -335,7 +335,8 @@ typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * b
+   */
+ typedef struct _ENetHost
+ {
+-   ENetSocket           socket;
++   ENetSocket           socket4;
++   ENetSocket           socket6;
+    ENetAddress          address;                     /**< Internet address of the host */
+    enet_uint32          incomingBandwidth;           /**< downstream bandwidth of the host */
+    enet_uint32          outgoingBandwidth;           /**< upstream bandwidth of the host */
+@@ -462,7 +463,7 @@ ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *, ENetAddressFa
+ ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *, ENetAddressFamily);
+ ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, ENetAddressFamily);
+ ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddressFamily);
+-ENET_API int        enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
++ENET_API int        enet_socket_wait (ENetSocket, ENetSocket, enet_uint32 *, enet_uint32);
+ ENET_API int        enet_socket_set_option (ENetSocket, ENetSocketOption, int);
+ ENET_API void       enet_socket_destroy (ENetSocket);
+ ENET_API int        enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
+@@ -508,6 +509,12 @@ ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName
+ */
+ ENET_API ENetHostAddress enet_address_map4 (enet_uint32 address);
+ 
++/** Returns the Address family of an (IPv4-mapped) IPv6 address.
++    @param address IPv6 address
++    @returns address family
++*/
++ENET_API ENetAddressFamily enet_get_address_family (const ENetAddress * address);
++
+ /** @} */
+ 
+ ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
+diff --git a/protocol.c b/protocol.c
+index 4c4850a..37f6387 100644
+--- a/protocol.c
++++ b/protocol.c
+@@ -37,6 +37,14 @@ enet_address_map4 (enet_uint32 address)
+     return addr;
+ }
+ 
++ENetAddressFamily
++enet_get_address_family (const ENetAddress * address)
++{
++    if (!memcmp(& address->host, & ENET_IPV4MAPPED_PREFIX, ENET_IPV4MAPPED_PREFIX_LEN))
++        return ENET_IPV4;
++    return ENET_IPV6;
++}
++
+ size_t
+ enet_protocol_command_size (enet_uint8 commandNumber)
+ {
+@@ -1033,7 +1041,7 @@ commandError:
+ }
+  
+ static int
+-enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
++enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event, ENetAddressFamily family)
+ {
+     for (;;)
+     {
+@@ -1043,11 +1051,11 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
+        buffer.data = host -> packetData [0];
+        buffer.dataLength = sizeof (host -> packetData [0]);
+ 
+-       receivedLength = enet_socket_receive (host -> socket,
++       receivedLength = enet_socket_receive (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
+                                              & host -> receivedAddress,
+                                              & buffer,
+                                              1,
+-                                             ENET_IPV6);
++                                             family);
+ 
+        if (receivedLength < 0)
+          return -1;
+@@ -1055,6 +1063,9 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
+        if (receivedLength == 0)
+          return 0;
+ 
++       if (enet_get_address_family (& host -> receivedAddress) != family)
++         return -1;
++
+        host -> receivedData = host -> packetData [0];
+        host -> receivedDataLength = receivedLength;
+       
+@@ -1510,7 +1521,12 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
+ 
+         currentPeer -> lastSendTime = host -> serviceTime;
+ 
+-        sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount, ENET_IPV6);
++        ENetAddressFamily family = enet_get_address_family (& currentPeer -> address);
++        sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
++                                           & currentPeer -> address,
++                                           host -> buffers,
++                                           host -> bufferCount,
++                                           family);
+ 
+         enet_protocol_remove_sent_unreliable_commands (currentPeer);
+ 
+@@ -1621,7 +1637,21 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
+           break;
+        }
+ 
+-       switch (enet_protocol_receive_incoming_commands (host, event))
++       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4))
++       {
++       case 1:
++          return 1;
++
++       case -1:
++          perror ("Error receiving incoming packets");
++
++          return -1;
++
++       default:
++          break;
++       }
++
++       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6))
+        {
+        case 1:
+           return 1;
+@@ -1673,7 +1703,7 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
+ 
+        waitCondition = ENET_SOCKET_WAIT_RECEIVE;
+ 
+-       if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
++       if (enet_socket_wait (host -> socket4, host -> socket6, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
+          return -1;
+        
+        host -> serviceTime = enet_time_get ();
+diff --git a/unix.c b/unix.c
+index 13a24d8..96d17f8 100644
+--- a/unix.c
++++ b/unix.c
+@@ -117,7 +117,9 @@ static int
+ enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
+ {
+     memset (sin, 0, enet_sa_size(family));
+-    if (family == ENET_IPV4)
++    if (family == ENET_IPV4 &&
++      (enet_get_address_family (address) == ENET_IPV4 ||
++      !memcmp (address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
+     {
+         ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
+         ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
+@@ -219,7 +221,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
+ #ifdef IPV6_V6ONLY
+     if (family == ENET_IPV6)
+     {
+-        int value = 0;
++        int value = 1;
+         setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
+     }
+ #endif // IPV6_V6ONLY
+@@ -393,22 +395,31 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
+ }
+ 
+ int
+-enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
++enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
+ {
+-#ifdef HAS_POLL
+-    struct pollfd pollSocket;
++    //FIXME allow only one of the sockets being available
++//#ifdef HAS_POLL
++    struct pollfd pollSocket[2];
+     int pollCount;
+     
+-    pollSocket.fd = socket;
+-    pollSocket.events = 0;
++    pollSocket[0].fd = socket4;
++    pollSocket[1].fd = socket6;
++    pollSocket[0].events = 0;
++    pollSocket[1].events = 0;
+ 
+     if (* condition & ENET_SOCKET_WAIT_SEND)
+-      pollSocket.events |= POLLOUT;
++    {
++        pollSocket[0].events |= POLLOUT;
++        pollSocket[1].events |= POLLOUT;
++    }
+ 
+     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
+-      pollSocket.events |= POLLIN;
++    {
++        pollSocket[0].events |= POLLIN;
++        pollSocket[1].events |= POLLIN;
++    }
+ 
+-    pollCount = poll (& pollSocket, 1, timeout);
++    pollCount = poll (pollSocket, 2, timeout);
+ 
+     if (pollCount < 0)
+       return -1;
+@@ -418,13 +429,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+     if (pollCount == 0)
+       return 0;
+ 
+-    if (pollSocket.revents & POLLOUT)
++    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLOUT)
+       * condition |= ENET_SOCKET_WAIT_SEND;
+     
+-    if (pollSocket.revents & POLLIN)
++    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLIN)
+       * condition |= ENET_SOCKET_WAIT_RECEIVE;
+ 
+     return 0;
++/*
++FIXME: implement this
+ #else
+     fd_set readSet, writeSet;
+     struct timeval timeVal;
+@@ -460,6 +473,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+ 
+     return 0;
+ #endif
++*/
+ }
+ 
+ #endif
+-- 
+1.7.1
+
Index: de/branches/ipv6/src/external/enet/patches/patch
===================================================================
--- /code/branches/ipv6/src/external/enet/patches/patch	(revision 7377)
+++ 	(revision )
@@ -1,744 +1,0 @@
-diff --git a/host.c b/host.c
-index 8bb2433..85dfa3c 100644
---- a/host.c
-+++ b/host.c
-@@ -48,11 +48,15 @@ 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);
--    if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
-+
-+    // FIXME: check address for ANY_ADRESS if not only bind to specific protocol
-+    // FIXME: allow to fail one of the two protocols
-+    /* IPv4 */
-+    host -> socket4 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV4);
-+    if (host -> socket4 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket4, address, ENET_IPV4) < 0))
-     {
--       if (host -> socket != ENET_SOCKET_NULL)
--         enet_socket_destroy (host -> socket);
-+       if (host -> socket4 != ENET_SOCKET_NULL)
-+         enet_socket_destroy (host -> socket4);
- 
-        enet_free (host -> peers);
-        enet_free (host);
-@@ -60,10 +64,32 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
-        return NULL;
-     }
- 
--    enet_socket_set_option (host -> socket, ENET_SOCKOPT_NONBLOCK, 1);
--    enet_socket_set_option (host -> socket, ENET_SOCKOPT_BROADCAST, 1);
--    enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
--    enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
-+    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_NONBLOCK, 1);
-+    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_BROADCAST, 1);
-+    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
-+    enet_socket_set_option (host -> socket4, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
-+
-+    /* IPv6 */
-+    host -> socket6 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6);
-+    if (host -> socket6 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket6, address, ENET_IPV6) < 0))
-+    {
-+       if (host -> socket6 != ENET_SOCKET_NULL)
-+       {
-+           enet_socket_destroy (host -> socket4);
-+           enet_socket_destroy (host -> socket6);
-+       }
-+
-+       enet_free (host -> peers);
-+       enet_free (host);
-+
-+       return NULL;
-+    }
-+
-+    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_NONBLOCK, 1);
-+    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_BROADCAST, 1);
-+    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
-+    enet_socket_set_option (host -> socket6, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
-+
- 
-     if (address != NULL)
-       host -> address = * address;
-@@ -133,7 +159,8 @@ enet_host_destroy (ENetHost * host)
- {
-     ENetPeer * currentPeer;
- 
--    enet_socket_destroy (host -> socket);
-+    enet_socket_destroy (host -> socket4);
-+    enet_socket_destroy (host -> socket6);
- 
-     for (currentPeer = host -> peers;
-          currentPeer < & host -> peers [host -> peerCount];
-diff --git a/include/enet/enet.h b/include/enet/enet.h
-index 2f656d6..39cf93e 100644
---- a/include/enet/enet.h
-+++ b/include/enet/enet.h
-@@ -53,13 +53,16 @@ typedef enum _ENetSocketOption
-    ENET_SOCKOPT_REUSEADDR = 5
- } 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_IPV4MAPPED_PREFIX; /**< specifies the IPv4-mapped IPv6 prefix */
-+extern const ENetHostAddress ENET_HOST_BROADCAST;    /**< specifies a IPv4 subnet-wide broadcast */
-+#define ENET_IPV4MAPPED_PREFIX_LEN 12                /**< specifies the length of the IPv4-mapped IPv6 prefix */
-+#define ENET_PORT_ANY 0                              /**< specifies that a port should be automatically chosen */
- 
- /**
-  * Portable internet address structure. 
-@@ -73,11 +76,22 @@ enum
-  */
- typedef struct _ENetAddress
- {
--   enet_uint32 host;
-+   ENetHostAddress host;
-+   enet_uint32 scopeID; //FIXME: this is of different size on Windows
-    enet_uint16 port;
- } ENetAddress;
- 
- /**
-+ * The address family type.
-+ */
-+typedef enum _ENetAddressFamily
-+{
-+    ENET_NO_ADDRESS_FAMILY = 0,
-+    ENET_IPV4 = 1,
-+    ENET_IPV6 = 2
-+} ENetAddressFamily;
-+
-+/**
-  * Packet flag bit constants.
-  *
-  * The host must be specified in network byte-order, and the port must be in
-@@ -321,7 +335,8 @@ typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * b
-   */
- typedef struct _ENetHost
- {
--   ENetSocket           socket;
-+   ENetSocket           socket4;
-+   ENetSocket           socket6;
-    ENetAddress          address;                     /**< Internet address of the host */
-    enet_uint32          incomingBandwidth;           /**< downstream bandwidth of the host */
-    enet_uint32          outgoingBandwidth;           /**< upstream bandwidth of the host */
-@@ -441,14 +456,14 @@ ENET_API void enet_time_set (enet_uint32);
- /** @defgroup socket ENet socket functions
-     @{
- */
--ENET_API ENetSocket enet_socket_create (ENetSocketType);
--ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *);
-+ENET_API ENetSocket enet_socket_create (ENetSocketType, ENetAddressFamily);
-+ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *, ENetAddressFamily);
- ENET_API int        enet_socket_listen (ENetSocket, int);
--ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
--ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *);
--ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
--ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
--ENET_API int        enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
-+ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *, ENetAddressFamily);
-+ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *, ENetAddressFamily);
-+ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, ENetAddressFamily);
-+ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddressFamily);
-+ENET_API int        enet_socket_wait (ENetSocket, ENetSocket, enet_uint32 *, enet_uint32);
- ENET_API int        enet_socket_set_option (ENetSocket, ENetSocketOption, int);
- ENET_API void       enet_socket_destroy (ENetSocket);
- ENET_API int        enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
-@@ -488,6 +503,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
-+*/
-+ENET_API ENetHostAddress enet_address_map4 (enet_uint32 address);
-+
-+/** Returns the Address family of an (IPv4-mapped) IPv6 address.
-+    @param address IPv6 address
-+    @returns address family
-+*/
-+ENET_API ENetAddressFamily enet_get_address_family (const ENetAddress * address);
-+
- /** @} */
- 
- ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
-diff --git a/protocol.c b/protocol.c
-index 8e26dfb..37f6387 100644
---- a/protocol.c
-+++ b/protocol.c
-@@ -9,6 +9,10 @@
- #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_IPV4MAPPED_PREFIX = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 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,
-@@ -25,6 +29,22 @@ static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] =
-     sizeof (ENetProtocolThrottleConfigure),
- };
- 
-+ENetHostAddress
-+enet_address_map4 (enet_uint32 address)
-+{
-+    ENetHostAddress addr = ENET_IPV4MAPPED_PREFIX;
-+    ((enet_uint32 *)addr.addr)[3] = address;
-+    return addr;
-+}
-+
-+ENetAddressFamily
-+enet_get_address_family (const ENetAddress * address)
-+{
-+    if (!memcmp(& address->host, & ENET_IPV4MAPPED_PREFIX, ENET_IPV4MAPPED_PREFIX_LEN))
-+        return ENET_IPV4;
-+    return ENET_IPV6;
-+}
-+
- size_t
- enet_protocol_command_size (enet_uint8 commandNumber)
- {
-@@ -262,9 +282,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 +868,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 +912,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;
-     }
-     
-@@ -1021,7 +1041,7 @@ commandError:
- }
-  
- static int
--enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
-+enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event, ENetAddressFamily family)
- {
-     for (;;)
-     {
-@@ -1031,10 +1051,11 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
-        buffer.data = host -> packetData [0];
-        buffer.dataLength = sizeof (host -> packetData [0]);
- 
--       receivedLength = enet_socket_receive (host -> socket,
-+       receivedLength = enet_socket_receive (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
-                                              & host -> receivedAddress,
-                                              & buffer,
--                                             1);
-+                                             1,
-+                                             family);
- 
-        if (receivedLength < 0)
-          return -1;
-@@ -1042,6 +1063,9 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
-        if (receivedLength == 0)
-          return 0;
- 
-+       if (enet_get_address_family (& host -> receivedAddress) != family)
-+         return -1;
-+
-        host -> receivedData = host -> packetData [0];
-        host -> receivedDataLength = receivedLength;
-       
-@@ -1497,7 +1521,12 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
- 
-         currentPeer -> lastSendTime = host -> serviceTime;
- 
--        sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount);
-+        ENetAddressFamily family = enet_get_address_family (& currentPeer -> address);
-+        sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
-+                                           & currentPeer -> address,
-+                                           host -> buffers,
-+                                           host -> bufferCount,
-+                                           family);
- 
-         enet_protocol_remove_sent_unreliable_commands (currentPeer);
- 
-@@ -1608,7 +1637,21 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
-           break;
-        }
- 
--       switch (enet_protocol_receive_incoming_commands (host, event))
-+       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4))
-+       {
-+       case 1:
-+          return 1;
-+
-+       case -1:
-+          perror ("Error receiving incoming packets");
-+
-+          return -1;
-+
-+       default:
-+          break;
-+       }
-+
-+       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6))
-        {
-        case 1:
-           return 1;
-@@ -1660,7 +1703,7 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
- 
-        waitCondition = ENET_SOCKET_WAIT_RECEIVE;
- 
--       if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
-+       if (enet_socket_wait (host -> socket4, host -> socket6, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
-          return -1;
-        
-        host -> serviceTime = enet_time_get ();
-diff --git a/unix.c b/unix.c
-index 6971541..96d17f8 100644
---- a/unix.c
-+++ b/unix.c
-@@ -71,122 +71,162 @@ enet_time_set (enet_uint32 newTimeBase)
-     timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
- }
- 
--int
--enet_address_set_host (ENetAddress * address, const char * name)
-+static enet_uint16
-+enet_af (ENetAddressFamily family)
- {
--    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 (family == ENET_IPV4)
-+        return AF_INET;
-+    if (family == ENET_IPV6)
-+        return AF_INET6;
-+    return 0;
-+}
- 
--    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;
--    }
-+static socklen_t
-+enet_sa_size (ENetAddressFamily family)
-+{
-+    if (family == ENET_IPV4)
-+        return sizeof (struct sockaddr_in);
-+    if (family == ENET_IPV6)
-+        return sizeof (struct sockaddr_in6);
-+    return 0;
-+}
- 
--    address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
- 
--    return 0;
-+static ENetAddressFamily
-+enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
-+{
-+    memset (address, 0, sizeof (ENetAddress));
-+    if (sin -> sa_family == AF_INET)
-+    {
-+        address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
-+        //address -> scopeID = 0;
-+        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in *) sin) -> sin_port);
-+        return ENET_IPV4;
-+    }
-+    if (sin -> sa_family == AF_INET6)
-+    {
-+        address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) sin) -> sin6_addr;
-+        address -> scopeID = ((struct sockaddr_in6 *) sin) -> sin6_scope_id;
-+        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in6 *) sin) -> sin6_port);
-+        return ENET_IPV6;
-+    }
-+    return ENET_NO_ADDRESS_FAMILY;
- }
- 
--int
--enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
-+static int
-+enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
- {
--#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
--        return -1;
--    return 0;
-+    memset (sin, 0, enet_sa_size(family));
-+    if (family == ENET_IPV4 &&
-+      (enet_get_address_family (address) == ENET_IPV4 ||
-+      !memcmp (address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
-+    {
-+        ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
-+        ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
-+        ((struct sockaddr_in *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
-+        return 0;
-+    }
-+    else if (family == ENET_IPV6)
-+    {
-+        ((struct sockaddr_in6 *) sin) -> sin6_family = AF_INET6;
-+        ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
-+        ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
-+        ((struct sockaddr_in6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
-+        return 0;
-+    }
-+    return -1;
- }
- 
- int
--enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
-+enet_address_set_host (ENetAddress * address, const char * name)
- {
--    struct in_addr in;
--    struct hostent * hostEntry = NULL;
--#ifdef HAS_GETHOSTBYADDR_R
--    struct hostent hostData;
--    char buffer [2048];
--    int errnum;
-+    enet_uint16 port = address -> port;
-+    struct addrinfo hints;
-+    struct addrinfo * result;
-+    struct addrinfo * res;
- 
--    in.s_addr = address -> host;
-+    memset(& hints, 0, sizeof (hints));
-+    hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
-+    hints.ai_family = AF_UNSPEC;
- 
--#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;
-+    if ( getaddrinfo(name, NULL, &hints, &result) )
-+        return -1;
- 
--    hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
--#endif
-+    for (res = result; res != NULL; res = res -> ai_next)
-+    {
-+        if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
-+            break;
-+    }
- 
--    if (hostEntry == NULL)
--      return enet_address_get_host_ip (address, name, nameLength);
-+    address -> port = port;
-+    freeaddrinfo(result);
-+    if (res == NULL) return -1;
- 
--    strncpy (name, hostEntry -> h_name, nameLength);
-+    return 0;
-+}
-+
-+static int
-+enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
-+{
-+    struct sockaddr_storage sin;
-+    enet_address_set_sin((struct sockaddr *) & sin, address, ENET_IPV6);
-+
-+    if ( getnameinfo((struct sockaddr *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
-+        return -1;
- 
-     return 0;
- }
- 
- int
--enet_socket_bind (ENetSocket socket, const ENetAddress * address)
-+enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
- {
--    struct sockaddr_in sin;
-+    return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
-+}
- 
--    memset (& sin, 0, sizeof (struct sockaddr_in));
-+int
-+enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
-+{
-+    return enet_address_get_host_x(address, name, nameLength, 0);
-+}
- 
--    sin.sin_family = AF_INET;
-+int
-+enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
-+{
-+    struct sockaddr_storage sin;
- 
-     if (address != NULL)
-     {
--       sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
--       sin.sin_addr.s_addr = address -> host;
-+        enet_address_set_sin((struct sockaddr *) & sin, address, family);
-     }
-     else
-     {
--       sin.sin_port = 0;
--       sin.sin_addr.s_addr = INADDR_ANY;
-+        ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
-+        enet_address_set_sin((struct sockaddr *) & sin, & address_, family);
-     }
- 
--    return bind (socket,
--                 (struct sockaddr *) & sin,
--                 sizeof (struct sockaddr_in)); 
-+    return bind (socket, (struct sockaddr *) & sin, enet_sa_size(family));
- }
- 
--int 
-+int
- enet_socket_listen (ENetSocket socket, int backlog)
- {
-     return listen (socket, backlog < 0 ? SOMAXCONN : backlog);
- }
- 
- ENetSocket
--enet_socket_create (ENetSocketType type)
-+enet_socket_create (ENetSocketType type, ENetAddressFamily family)
- {
--    return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
-+    ENetSocket sock = socket (enet_af (family), type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
-+
-+#ifdef IPV6_V6ONLY
-+    if (family == ENET_IPV6)
-+    {
-+        int value = 1;
-+        setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
-+    }
-+#endif // IPV6_V6ONLY
-+
-+    return sock;
- }
- 
- int
-@@ -226,37 +266,31 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
- }
- 
- int
--enet_socket_connect (ENetSocket socket, const ENetAddress * address)
-+enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
- {
--    struct sockaddr_in sin;
--
--    memset (& sin, 0, sizeof (struct sockaddr_in));
-+    struct sockaddr_storage sin;
-+    enet_address_set_sin((struct sockaddr *) & sin, address, family);
- 
--    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));
-+    return connect (socket, (struct sockaddr *) & sin, enet_sa_size (family));
- }
- 
- ENetSocket
--enet_socket_accept (ENetSocket socket, ENetAddress * address)
-+enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
- {
-     int result;
--    struct sockaddr_in sin;
--    socklen_t sinLength = sizeof (struct sockaddr_in);
-+    struct sockaddr_storage sin;
-+    socklen_t sinLength = enet_sa_size (family);
- 
-     result = accept (socket, 
-                      address != NULL ? (struct sockaddr *) & sin : NULL, 
-                      address != NULL ? & sinLength : NULL);
--    
-+
-     if (result == -1)
-       return ENET_SOCKET_NULL;
- 
-     if (address != NULL)
-     {
--        address -> host = (enet_uint32) sin.sin_addr.s_addr;
--        address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
-+        enet_address_set_address(address, (struct sockaddr *) & sin);
-     }
- 
-     return result;
-@@ -272,24 +306,20 @@ int
- enet_socket_send (ENetSocket socket,
-                   const ENetAddress * address,
-                   const ENetBuffer * buffers,
--                  size_t bufferCount)
-+                  size_t bufferCount,
-+                  ENetAddressFamily family)
- {
-     struct msghdr msgHdr;
--    struct sockaddr_in sin;
-+    struct sockaddr_storage sin;
-     int sentLength;
- 
-     memset (& msgHdr, 0, sizeof (struct msghdr));
- 
-     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;
--
-+        enet_address_set_sin((struct sockaddr *) & sin, address, family);
-         msgHdr.msg_name = & sin;
--        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
-+        msgHdr.msg_namelen = enet_sa_size (family);
-     }
- 
-     msgHdr.msg_iov = (struct iovec *) buffers;
-@@ -312,10 +342,11 @@ int
- enet_socket_receive (ENetSocket socket,
-                      ENetAddress * address,
-                      ENetBuffer * buffers,
--                     size_t bufferCount)
-+                     size_t bufferCount,
-+                     ENetAddressFamily family)
- {
-     struct msghdr msgHdr;
--    struct sockaddr_in sin;
-+    struct sockaddr_storage sin;
-     int recvLength;
- 
-     memset (& msgHdr, 0, sizeof (struct msghdr));
-@@ -323,7 +354,7 @@ enet_socket_receive (ENetSocket socket,
-     if (address != NULL)
-     {
-         msgHdr.msg_name = & sin;
--        msgHdr.msg_namelen = sizeof (struct sockaddr_in);
-+        msgHdr.msg_namelen = enet_sa_size (family);
-     }
- 
-     msgHdr.msg_iov = (struct iovec *) buffers;
-@@ -346,8 +377,7 @@ 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);
-+        enet_address_set_address(address, (struct sockaddr *) & sin);
-     }
- 
-     return recvLength;
-@@ -365,22 +395,31 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
- }
- 
- int
--enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
-+enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
- {
--#ifdef HAS_POLL
--    struct pollfd pollSocket;
-+    //FIXME allow only one of the sockets being available
-+//#ifdef HAS_POLL
-+    struct pollfd pollSocket[2];
-     int pollCount;
-     
--    pollSocket.fd = socket;
--    pollSocket.events = 0;
-+    pollSocket[0].fd = socket4;
-+    pollSocket[1].fd = socket6;
-+    pollSocket[0].events = 0;
-+    pollSocket[1].events = 0;
- 
-     if (* condition & ENET_SOCKET_WAIT_SEND)
--      pollSocket.events |= POLLOUT;
-+    {
-+        pollSocket[0].events |= POLLOUT;
-+        pollSocket[1].events |= POLLOUT;
-+    }
- 
-     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
--      pollSocket.events |= POLLIN;
-+    {
-+        pollSocket[0].events |= POLLIN;
-+        pollSocket[1].events |= POLLIN;
-+    }
- 
--    pollCount = poll (& pollSocket, 1, timeout);
-+    pollCount = poll (pollSocket, 2, timeout);
- 
-     if (pollCount < 0)
-       return -1;
-@@ -390,13 +429,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
-     if (pollCount == 0)
-       return 0;
- 
--    if (pollSocket.revents & POLLOUT)
-+    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLOUT)
-       * condition |= ENET_SOCKET_WAIT_SEND;
-     
--    if (pollSocket.revents & POLLIN)
-+    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLIN)
-       * condition |= ENET_SOCKET_WAIT_RECEIVE;
- 
-     return 0;
-+/*
-+FIXME: implement this
- #else
-     fd_set readSet, writeSet;
-     struct timeval timeVal;
-@@ -432,6 +473,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
- 
-     return 0;
- #endif
-+*/
- }
- 
- #endif
