Index: /code/branches/ipv6/src/external/enet/CMakeLists.txt
===================================================================
--- /code/branches/ipv6/src/external/enet/CMakeLists.txt	(revision 7389)
+++ /code/branches/ipv6/src/external/enet/CMakeLists.txt	(revision 7390)
@@ -27,5 +27,5 @@
     include/enet/unix.h
     include/enet/utility.h
-    #include/enet/win32.h
+    include/enet/win32.h
 
 COMPILATION_BEGIN ENetCompilation.cpp
@@ -38,5 +38,5 @@
     protocol.c
     unix.c
-    #win32.c
+    win32.c
 COMPILATION_END
 )
Index: /code/branches/ipv6/src/external/enet/include/enet/enet.h
===================================================================
--- /code/branches/ipv6/src/external/enet/include/enet/enet.h	(revision 7389)
+++ /code/branches/ipv6/src/external/enet/include/enet/enet.h	(revision 7390)
@@ -78,5 +78,9 @@
 {
    ENetHostAddress host;
-   enet_uint32 scopeID; //FIXME: this is of different size on Windows
+#ifdef WIN32
+   u_long scopeID;
+#else
+   uint32_t scopeID;
+#endif
    enet_uint16 port;
 } ENetAddress;
Index: /code/branches/ipv6/src/external/enet/include/enet/win32.h
===================================================================
--- /code/branches/ipv6/src/external/enet/include/enet/win32.h	(revision 7389)
+++ /code/branches/ipv6/src/external/enet/include/enet/win32.h	(revision 7390)
@@ -15,4 +15,5 @@
 #include <stdlib.h>
 #include <winsock2.h>
+#include <ws2tcpip.h>
 
 typedef SOCKET ENetSocket;
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 7389)
+++ /code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch	(revision 7390)
@@ -2,5 +2,5 @@
 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
+Subject: [PATCH 1/5] use getaddrinfo for lookup in unix.c
 
 ---
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 7389)
+++ /code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch	(revision 7390)
@@ -2,5 +2,5 @@
 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
+Subject: [PATCH 2/5] basic IPv6 support on Linux systems
 
 this uses IPv4-mapped IPv6 addresses
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 7389)
+++ /code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch	(revision 7390)
@@ -1,6 +1,6 @@
-From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5 Mon Sep 17 00:00:00 2001
+From b26e4ef3fa9c0139fc2ec086d2243b809365d683 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
+Subject: [PATCH 3/5] using address family in functions
 
 ---
@@ -8,6 +8,6 @@
  include/enet/enet.h |   22 +++++++++---
  protocol.c          |    5 ++-
- unix.c              |   87 ++++++++++++++++++++++++++++++++------------------
- 4 files changed, 77 insertions(+), 41 deletions(-)
+ unix.c              |   86 ++++++++++++++++++++++++++++++++------------------
+ 4 files changed, 76 insertions(+), 41 deletions(-)
 
 diff --git a/host.c b/host.c
@@ -91,8 +91,8 @@
  
 diff --git a/unix.c b/unix.c
-index de032bb..13a24d8 100644
+index de032bb..475c6e3 100644
 --- a/unix.c
 +++ b/unix.c
-@@ -71,7 +71,28 @@ enet_time_set (enet_uint32 newTimeBase)
+@@ -71,7 +71,27 @@ enet_time_set (enet_uint32 newTimeBase)
      timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
  }
@@ -119,10 +119,9 @@
 +}
 +
-+
 +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)
+@@ -80,32 +100,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;
@@ -164,5 +163,5 @@
          ((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)
+@@ -132,7 +151,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
  
      for (res = result; res != NULL; res = res -> ai_next)
@@ -173,5 +172,5 @@
      }
  
-@@ -147,9 +167,9 @@ static int
+@@ -147,9 +166,9 @@ static int
  enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
  {
@@ -185,5 +184,5 @@
  
      return 0;
-@@ -168,21 +188,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
+@@ -168,21 +187,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
  }
  
@@ -211,5 +210,5 @@
  
  int
-@@ -192,13 +212,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
+@@ -192,13 +211,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
  }
  
@@ -232,5 +231,5 @@
  
      return sock;
-@@ -241,25 +264,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+@@ -241,25 +263,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
  }
  
@@ -264,5 +263,5 @@
        return ENET_SOCKET_NULL;
  
-@@ -281,7 +304,8 @@ int
+@@ -281,7 +303,8 @@ int
  enet_socket_send (ENetSocket socket,
                    const ENetAddress * address,
@@ -274,5 +273,5 @@
      struct msghdr msgHdr;
      struct sockaddr_storage sin;
-@@ -291,9 +315,9 @@ enet_socket_send (ENetSocket socket,
+@@ -291,9 +314,9 @@ enet_socket_send (ENetSocket socket,
  
      if (address != NULL)
@@ -286,5 +285,5 @@
  
      msgHdr.msg_iov = (struct iovec *) buffers;
-@@ -316,7 +340,8 @@ int
+@@ -316,7 +339,8 @@ int
  enet_socket_receive (ENetSocket socket,
                       ENetAddress * address,
@@ -296,5 +295,5 @@
      struct msghdr msgHdr;
      struct sockaddr_storage sin;
-@@ -327,7 +352,7 @@ enet_socket_receive (ENetSocket socket,
+@@ -327,7 +351,7 @@ enet_socket_receive (ENetSocket socket,
      if (address != NULL)
      {
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 7389)
+++ /code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch	(revision 7390)
@@ -1,13 +1,13 @@
-From 9801a6bcd072870248a6b07245fc09a9492f8f51 Mon Sep 17 00:00:00 2001
+From 73fa28a84ce456561d3912578121a30bc8263c50 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
+Subject: [PATCH 4/5] using two separate sockets for IPv4 and IPv6
 
 ---
- host.c              |   53 +++++++++++++++++++++++++++++++++++++-------------
- include/enet/enet.h |   11 ++++++++-
- protocol.c          |   47 +++++++++++++++++++++++++++++++++++++++-----
- unix.c              |   47 ++++++++++++++++++++++++++++++++------------
- 4 files changed, 123 insertions(+), 35 deletions(-)
+ host.c              |   53 +++++++++++++++++++++++++++---------
+ include/enet/enet.h |   11 ++++++-
+ protocol.c          |   47 ++++++++++++++++++++++++++++----
+ unix.c              |   74 +++++++++++++++++++++++++++++++++++++-------------
+ 4 files changed, 144 insertions(+), 41 deletions(-)
 
 diff --git a/host.c b/host.c
@@ -233,8 +233,8 @@
         host -> serviceTime = enet_time_get ();
 diff --git a/unix.c b/unix.c
-index 13a24d8..22ffb76 100644
+index 475c6e3..751cb6f 100644
 --- a/unix.c
 +++ b/unix.c
-@@ -117,7 +117,9 @@ static int
+@@ -116,7 +116,9 @@ static int
  enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
  {
@@ -247,5 +247,5 @@
          ((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)
+@@ -218,7 +220,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
  #ifdef IPV6_V6ONLY
      if (family == ENET_IPV6)
@@ -256,5 +256,5 @@
      }
  #endif // IPV6_V6ONLY
-@@ -393,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
+@@ -392,22 +394,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
  }
  
@@ -263,7 +263,6 @@
 +enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
  {
--#ifdef HAS_POLL
+ #ifdef HAS_POLL
 -    struct pollfd pollSocket;
-+//#ifdef HAS_POLL
 +    struct pollfd pollSocket[2];
      int pollCount;
@@ -304,5 +303,5 @@
      if (pollCount < 0)
        return -1;
-@@ -418,13 +436,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+@@ -417,10 +435,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
      if (pollCount == 0)
        return 0;
@@ -317,16 +316,53 @@
  
      return 0;
-+/*
-+FIXME: implement or remove this
- #else
-     fd_set readSet, writeSet;
-     struct timeval timeVal;
-@@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+@@ -436,12 +454,28 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+     FD_ZERO (& writeSet);
+ 
+     if (* condition & ENET_SOCKET_WAIT_SEND)
+-      FD_SET (socket, & writeSet);
++    {
++        if (socket4 != ENET_SOCKET_NULL)
++            FD_SET (socket4, & writeSet);
++        if (socket6 != ENET_SOCKET_NULL)
++            FD_SET (socket6, & writeSet);
++    }
+ 
+     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
+-      FD_SET (socket, & readSet);
++    {
++        if (socket4 != ENET_SOCKET_NULL)
++            FD_SET (socket4, & readSet);
++        if (socket6 != ENET_SOCKET_NULL)
++            FD_SET (socket6, & readSet);
++    }
++
++    ENetSocket maxSocket = 0;
++    if (socket4 != ENET_SOCKET_NULL)
++        maxSocket = socket4;
++    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
++        maxSocket = socket6;
+ 
+-    selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
++    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+ 
+     if (selectCount < 0)
+       return -1;
+@@ -451,11 +485,13 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+     if (selectCount == 0)
+       return 0;
+ 
+-    if (FD_ISSET (socket, & writeSet))
+-      * condition |= ENET_SOCKET_WAIT_SEND;
++    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
++        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
++        * condition |= ENET_SOCKET_WAIT_SEND;
+ 
+-    if (FD_ISSET (socket, & readSet))
+-      * condition |= ENET_SOCKET_WAIT_RECEIVE;
++    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
++        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
++        * condition |= ENET_SOCKET_WAIT_RECEIVE;
  
      return 0;
- #endif
-+*/
- }
- 
  #endif
 -- 
Index: /code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch
===================================================================
--- /code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch	(revision 7390)
+++ /code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch	(revision 7390)
@@ -0,0 +1,423 @@
+From 93248e1cd75da47980e0d69428747ff6471be1ed Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi@koalatux.ch>
+Date: Thu, 9 Sep 2010 16:02:21 +0200
+Subject: [PATCH 5/5] IPv6 for Windows
+
+---
+ include/enet/enet.h  |    6 +-
+ include/enet/win32.h |    1 +
+ win32.c              |  237 ++++++++++++++++++++++++++++++++------------------
+ 3 files changed, 160 insertions(+), 84 deletions(-)
+
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index 616fe7f..54e3b3b 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -77,7 +77,11 @@ extern const ENetHostAddress ENET_HOST_BROADCAST;    /**< specifies a IPv4 subne
+ typedef struct _ENetAddress
+ {
+    ENetHostAddress host;
+-   enet_uint32 scopeID; //FIXME: this is of different size on Windows
++#ifdef WIN32
++   u_long scopeID;
++#else
++   uint32_t scopeID;
++#endif
+    enet_uint16 port;
+ } ENetAddress;
+ 
+diff --git a/include/enet/win32.h b/include/enet/win32.h
+index 0e1cf0c..9f3f6e5 100644
+--- a/include/enet/win32.h
++++ b/include/enet/win32.h
+@@ -14,6 +14,7 @@
+ 
+ #include <stdlib.h>
+ #include <winsock2.h>
++#include <ws2tcpip.h>
+ 
+ typedef SOCKET ENetSocket;
+ 
+diff --git a/win32.c b/win32.c
+index e1fae23..dbbe85a 100644
+--- a/win32.c
++++ b/win32.c
+@@ -52,77 +52,139 @@ enet_time_set (enet_uint32 newTimeBase)
+     timeBase = (enet_uint32) timeGetTime () - newTimeBase;
+ }
+ 
+-int
+-enet_address_set_host (ENetAddress * address, const char * name)
++static enet_uint16
++enet_af (ENetAddressFamily family)
+ {
+-    struct hostent * hostEntry;
++    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 (SOCKADDR_IN);
++    if (family == ENET_IPV6)
++        return sizeof (SOCKADDR_IN6);
++    return 0;
++}
+ 
+-    hostEntry = gethostbyname (name);
+-    if (hostEntry == NULL ||
+-        hostEntry -> h_addrtype != AF_INET)
++static ENetAddressFamily
++enet_address_set_address (ENetAddress * address, const SOCKADDR * sin)
++{
++    memset (address, 0, sizeof (ENetAddress));
++    if (sin -> sa_family == AF_INET)
+     {
+-        unsigned long host = inet_addr (name);
+-        if (host == INADDR_NONE)
+-            return -1;
+-        address -> host = host;
+-        return 0;
++        address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr));
++        //address -> scopeID = 0;
++        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port);
++        return ENET_IPV4;
+     }
++    if (sin -> sa_family == AF_INET6)
++    {
++        address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr;
++        address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id;
++        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port);
++        return ENET_IPV6;
++    }
++    return ENET_NO_ADDRESS_FAMILY;
++}
+ 
+-    address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
+-
+-    return 0;
++static int
++enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family)
++{
++    memset (sin, 0, enet_sa_size(family));
++    if (family == ENET_IPV4 &&
++      (enet_get_address_family (address) == ENET_IPV4 ||
++      !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
++    {
++        ((SOCKADDR_IN *) sin) -> sin_family = AF_INET;
++        ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12];
++        ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
++        return 0;
++    }
++    else if (family == ENET_IPV6)
++    {
++        ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6;
++        ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host;
++        ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID;
++        ((SOCKADDR_IN6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++        return 0;
++    }
++    return -1;
+ }
+ 
+ int
+-enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
++enet_address_set_host (ENetAddress * address, const char * name)
+ {
+-    char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
+-    if (addr == NULL)
++    enet_uint16 port = address -> port;
++    ADDRINFO hints;
++    ADDRINFO * result;
++    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;
+-    strncpy (name, addr, nameLength);
++
++    for (res = result; res != NULL; res = res -> ai_next)
++    {
++        if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
++            break;
++    }
++
++    address -> port = port;
++    freeaddrinfo(result);
++    if (res == NULL) return -1;
++
+     return 0;
+ }
+ 
+-int
+-enet_address_get_host (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)
+ {
+-    struct in_addr in;
+-    struct hostent * hostEntry;
+-    
+-    in.s_addr = address -> host;
+-    
+-    hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
+-    if (hostEntry == NULL)
+-      return enet_address_get_host_ip (address, name, nameLength);
++    SOCKADDR_STORAGE sin;
++    enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6);
+ 
+-    strncpy (name, hostEntry -> h_name, nameLength);
++    if ( getnameinfo((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)
++{
++    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((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((SOCKADDR *) & sin, & address_, family);
+     }
+ 
+-    return bind (socket,
+-                 (struct sockaddr *) & sin,
+-                 sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
++    return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
+ }
+ 
+ int
+@@ -132,7 +194,7 @@ enet_socket_listen (ENetSocket socket, int 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);
+ }
+@@ -173,28 +235,23 @@ 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));
++    SOCKADDR_STORAGE sin;
++    enet_address_set_sin((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)) == SOCKET_ERROR ? -1 : 0;
++    return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
+ }
+ 
+ ENetSocket
+-enet_socket_accept (ENetSocket socket, ENetAddress * address)
++enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
+ {
+     SOCKET result;
+-    struct sockaddr_in sin;
+-    int sinLength = sizeof (struct sockaddr_in);
++    SOCKADDR_STORAGE sin;
++    int sinLength = enet_sa_size (family);
+ 
+     result = accept (socket, 
+-                     address != NULL ? (struct sockaddr *) & sin : NULL, 
++                     address != NULL ? (SOCKADDR *) & sin : NULL,
+                      address != NULL ? & sinLength : NULL);
+ 
+     if (result == INVALID_SOCKET)
+@@ -202,8 +259,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, (SOCKADDR *) & sin);
+     }
+ 
+     return result;
+@@ -219,18 +275,15 @@ int
+ enet_socket_send (ENetSocket socket,
+                   const ENetAddress * address,
+                   const ENetBuffer * buffers,
+-                  size_t bufferCount)
++                  size_t bufferCount,
++                  ENetAddressFamily family)
+ {
+-    struct sockaddr_in sin;
++    SOCKADDR_STORAGE sin;
+     DWORD sentLength;
+ 
+     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((SOCKADDR *) & sin, address, family);
+     }
+ 
+     if (WSASendTo (socket, 
+@@ -238,8 +291,8 @@ enet_socket_send (ENetSocket socket,
+                    (DWORD) bufferCount,
+                    & sentLength,
+                    0,
+-                   address != NULL ? (struct sockaddr *) & sin : 0,
+-                   address != NULL ? sizeof (struct sockaddr_in) : 0,
++                   address != NULL ? (SOCKADDR *) & sin : 0,
++                   address != NULL ? enet_sa_size (family) : 0,
+                    NULL,
+                    NULL) == SOCKET_ERROR)
+     {
+@@ -256,19 +309,20 @@ int
+ enet_socket_receive (ENetSocket socket,
+                      ENetAddress * address,
+                      ENetBuffer * buffers,
+-                     size_t bufferCount)
++                     size_t bufferCount,
++                     ENetAddressFamily family)
+ {
+-    INT sinLength = sizeof (struct sockaddr_in);
++    INT sinLength = enet_sa_size (family);
+     DWORD flags = 0,
+           recvLength;
+-    struct sockaddr_in sin;
++    SOCKADDR_STORAGE sin;
+ 
+     if (WSARecvFrom (socket,
+                      (LPWSABUF) buffers,
+                      (DWORD) bufferCount,
+                      & recvLength,
+                      & flags,
+-                     address != NULL ? (struct sockaddr *) & sin : NULL,
++                     address != NULL ? (SOCKADDR *) & sin : NULL,
+                      address != NULL ? & sinLength : NULL,
+                      NULL,
+                      NULL) == SOCKET_ERROR)
+@@ -288,8 +342,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, (SOCKADDR *) & sin);
+     }
+ 
+     return (int) recvLength;
+@@ -307,25 +360,41 @@ 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)
+ {
+     fd_set readSet, writeSet;
+     struct timeval timeVal;
+     int selectCount;
+-    
++
+     timeVal.tv_sec = timeout / 1000;
+     timeVal.tv_usec = (timeout % 1000) * 1000;
+-    
++
+     FD_ZERO (& readSet);
+     FD_ZERO (& writeSet);
+ 
+     if (* condition & ENET_SOCKET_WAIT_SEND)
+-      FD_SET (socket, & writeSet);
++    {
++        if (socket4 != ENET_SOCKET_NULL)
++            FD_SET (socket4, & writeSet);
++        if (socket6 != ENET_SOCKET_NULL)
++            FD_SET (socket6, & writeSet);
++    }
+ 
+     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
+-      FD_SET (socket, & readSet);
++    {
++        if (socket4 != ENET_SOCKET_NULL)
++            FD_SET (socket4, & readSet);
++        if (socket6 != ENET_SOCKET_NULL)
++            FD_SET (socket6, & readSet);
++    }
+ 
+-    selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
++    ENetSocket maxSocket = 0;
++    if (socket4 != ENET_SOCKET_NULL)
++        maxSocket = socket4;
++    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
++        maxSocket = socket6;
++
++    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+ 
+     if (selectCount < 0)
+       return -1;
+@@ -335,14 +404,16 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+     if (selectCount == 0)
+       return 0;
+ 
+-    if (FD_ISSET (socket, & writeSet))
+-      * condition |= ENET_SOCKET_WAIT_SEND;
+-    
+-    if (FD_ISSET (socket, & readSet))
+-      * condition |= ENET_SOCKET_WAIT_RECEIVE;
++    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
++        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
++        * condition |= ENET_SOCKET_WAIT_SEND;
++
++    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
++        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
++        * condition |= ENET_SOCKET_WAIT_RECEIVE;
+ 
+     return 0;
+-} 
++}
+ 
+ #endif
+ 
+-- 
+1.7.1
+
Index: /code/branches/ipv6/src/external/enet/unix.c
===================================================================
--- /code/branches/ipv6/src/external/enet/unix.c	(revision 7389)
+++ /code/branches/ipv6/src/external/enet/unix.c	(revision 7390)
@@ -92,5 +92,4 @@
 }
 
-
 static ENetAddressFamily
 enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
@@ -398,5 +397,5 @@
 enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
 {
-//#ifdef HAS_POLL
+#ifdef HAS_POLL
     struct pollfd pollSocket[2];
     int pollCount;
@@ -444,6 +443,4 @@
 
     return 0;
-/*
-FIXME: implement or remove this
 #else
     fd_set readSet, writeSet;
@@ -458,10 +455,26 @@
 
     if (* condition & ENET_SOCKET_WAIT_SEND)
-      FD_SET (socket, & writeSet);
+    {
+        if (socket4 != ENET_SOCKET_NULL)
+            FD_SET (socket4, & writeSet);
+        if (socket6 != ENET_SOCKET_NULL)
+            FD_SET (socket6, & writeSet);
+    }
 
     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
-      FD_SET (socket, & readSet);
-
-    selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
+    {
+        if (socket4 != ENET_SOCKET_NULL)
+            FD_SET (socket4, & readSet);
+        if (socket6 != ENET_SOCKET_NULL)
+            FD_SET (socket6, & readSet);
+    }
+
+    ENetSocket maxSocket = 0;
+    if (socket4 != ENET_SOCKET_NULL)
+        maxSocket = socket4;
+    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
+        maxSocket = socket6;
+
+    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
 
     if (selectCount < 0)
@@ -473,15 +486,16 @@
       return 0;
 
-    if (FD_ISSET (socket, & writeSet))
-      * condition |= ENET_SOCKET_WAIT_SEND;
-
-    if (FD_ISSET (socket, & readSet))
-      * condition |= ENET_SOCKET_WAIT_RECEIVE;
-
-    return 0;
-#endif
-*/
-}
-
-#endif
-
+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
+        * condition |= ENET_SOCKET_WAIT_SEND;
+
+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
+        * condition |= ENET_SOCKET_WAIT_RECEIVE;
+
+    return 0;
+#endif
+}
+
+#endif
+
Index: /code/branches/ipv6/src/external/enet/win32.c
===================================================================
--- /code/branches/ipv6/src/external/enet/win32.c	(revision 7389)
+++ /code/branches/ipv6/src/external/enet/win32.c	(revision 7390)
@@ -53,21 +53,105 @@
 }
 
+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 (SOCKADDR_IN);
+    if (family == ENET_IPV6)
+        return sizeof (SOCKADDR_IN6);
+    return 0;
+}
+
+static ENetAddressFamily
+enet_address_set_address (ENetAddress * address, const SOCKADDR * sin)
+{
+    memset (address, 0, sizeof (ENetAddress));
+    if (sin -> sa_family == AF_INET)
+    {
+        address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr));
+        //address -> scopeID = 0;
+        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port);
+        return ENET_IPV4;
+    }
+    if (sin -> sa_family == AF_INET6)
+    {
+        address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr;
+        address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id;
+        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port);
+        return ENET_IPV6;
+    }
+    return ENET_NO_ADDRESS_FAMILY;
+}
+
+static int
+enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family)
+{
+    memset (sin, 0, enet_sa_size(family));
+    if (family == ENET_IPV4 &&
+      (enet_get_address_family (address) == ENET_IPV4 ||
+      !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
+    {
+        ((SOCKADDR_IN *) sin) -> sin_family = AF_INET;
+        ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12];
+        ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
+        return 0;
+    }
+    else if (family == ENET_IPV6)
+    {
+        ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6;
+        ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host;
+        ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID;
+        ((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)
 {
-    struct hostent * hostEntry;
-
-    hostEntry = gethostbyname (name);
-    if (hostEntry == NULL ||
-        hostEntry -> h_addrtype != AF_INET)
-    {
-        unsigned long host = inet_addr (name);
-        if (host == INADDR_NONE)
-            return -1;
-        address -> host = host;
-        return 0;
-    }
-
-    address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
+    enet_uint16 port = address -> port;
+    ADDRINFO hints;
+    ADDRINFO * result;
+    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 ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
+            break;
+    }
+
+    address -> port = port;
+    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)
+{
+    SOCKADDR_STORAGE sin;
+    enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6);
+
+    if ( getnameinfo((SOCKADDR *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
+        return -1;
 
     return 0;
@@ -77,9 +161,5 @@
 enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
 {
-    char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
-    if (addr == NULL)
-        return -1;
-    strncpy (name, addr, nameLength);
-    return 0;
+    return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
 }
 
@@ -87,41 +167,23 @@
 enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
 {
-    struct in_addr in;
-    struct hostent * hostEntry;
-    
-    in.s_addr = address -> host;
-    
-    hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
-    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;
+    return enet_address_get_host_x(address, name, nameLength, 0);
+}
+
+int
+enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
+{
+    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((SOCKADDR *) & sin, address, family);
     }
     else
     {
-       sin.sin_port = 0;
-       sin.sin_addr.s_addr = INADDR_ANY;
-    }
-
-    return bind (socket,
-                 (struct sockaddr *) & sin,
-                 sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
+        ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
+        enet_address_set_sin((SOCKADDR *) & sin, & address_, family);
+    }
+
+    return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
 }
 
@@ -133,5 +195,5 @@
 
 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);
@@ -174,26 +236,21 @@
 
 int
-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)) == SOCKET_ERROR ? -1 : 0;
+enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
+{
+    SOCKADDR_STORAGE sin;
+    enet_address_set_sin((SOCKADDR *) & sin, address, family);
+
+    return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
 }
 
 ENetSocket
-enet_socket_accept (ENetSocket socket, ENetAddress * address)
+enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
 {
     SOCKET result;
-    struct sockaddr_in sin;
-    int sinLength = sizeof (struct sockaddr_in);
+    SOCKADDR_STORAGE sin;
+    int sinLength = enet_sa_size (family);
 
     result = accept (socket, 
-                     address != NULL ? (struct sockaddr *) & sin : NULL, 
+                     address != NULL ? (SOCKADDR *) & sin : NULL,
                      address != NULL ? & sinLength : NULL);
 
@@ -203,6 +260,5 @@
     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, (SOCKADDR *) & sin);
     }
 
@@ -220,16 +276,13 @@
                   const ENetAddress * address,
                   const ENetBuffer * buffers,
-                  size_t bufferCount)
-{
-    struct sockaddr_in sin;
+                  size_t bufferCount,
+                  ENetAddressFamily family)
+{
+    SOCKADDR_STORAGE sin;
     DWORD sentLength;
 
     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((SOCKADDR *) & sin, address, family);
     }
 
@@ -239,6 +292,6 @@
                    & sentLength,
                    0,
-                   address != NULL ? (struct sockaddr *) & sin : 0,
-                   address != NULL ? sizeof (struct sockaddr_in) : 0,
+                   address != NULL ? (SOCKADDR *) & sin : 0,
+                   address != NULL ? enet_sa_size (family) : 0,
                    NULL,
                    NULL) == SOCKET_ERROR)
@@ -257,10 +310,11 @@
                      ENetAddress * address,
                      ENetBuffer * buffers,
-                     size_t bufferCount)
-{
-    INT sinLength = sizeof (struct sockaddr_in);
+                     size_t bufferCount,
+                     ENetAddressFamily family)
+{
+    INT sinLength = enet_sa_size (family);
     DWORD flags = 0,
           recvLength;
-    struct sockaddr_in sin;
+    SOCKADDR_STORAGE sin;
 
     if (WSARecvFrom (socket,
@@ -269,5 +323,5 @@
                      & recvLength,
                      & flags,
-                     address != NULL ? (struct sockaddr *) & sin : NULL,
+                     address != NULL ? (SOCKADDR *) & sin : NULL,
                      address != NULL ? & sinLength : NULL,
                      NULL,
@@ -289,6 +343,5 @@
     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, (SOCKADDR *) & sin);
     }
 
@@ -308,23 +361,39 @@
 
 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)
 {
     fd_set readSet, writeSet;
     struct timeval timeVal;
     int selectCount;
-    
+
     timeVal.tv_sec = timeout / 1000;
     timeVal.tv_usec = (timeout % 1000) * 1000;
-    
+
     FD_ZERO (& readSet);
     FD_ZERO (& writeSet);
 
     if (* condition & ENET_SOCKET_WAIT_SEND)
-      FD_SET (socket, & writeSet);
+    {
+        if (socket4 != ENET_SOCKET_NULL)
+            FD_SET (socket4, & writeSet);
+        if (socket6 != ENET_SOCKET_NULL)
+            FD_SET (socket6, & writeSet);
+    }
 
     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
-      FD_SET (socket, & readSet);
-
-    selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
+    {
+        if (socket4 != ENET_SOCKET_NULL)
+            FD_SET (socket4, & readSet);
+        if (socket6 != ENET_SOCKET_NULL)
+            FD_SET (socket6, & readSet);
+    }
+
+    ENetSocket maxSocket = 0;
+    if (socket4 != ENET_SOCKET_NULL)
+        maxSocket = socket4;
+    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
+        maxSocket = socket6;
+
+    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
 
     if (selectCount < 0)
@@ -336,12 +405,14 @@
       return 0;
 
-    if (FD_ISSET (socket, & writeSet))
-      * condition |= ENET_SOCKET_WAIT_SEND;
-    
-    if (FD_ISSET (socket, & readSet))
-      * condition |= ENET_SOCKET_WAIT_RECEIVE;
-
-    return 0;
-} 
+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
+        * condition |= ENET_SOCKET_WAIT_SEND;
+
+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
+        * condition |= ENET_SOCKET_WAIT_RECEIVE;
+
+    return 0;
+}
 
 #endif
