Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2010, 4:30:50 PM (14 years ago)
Author:
adrfried
Message:

IPv6 for Windows

I have not tested this, please test this and report issues to me.

Location:
code/branches/ipv6/src/external/enet
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ipv6/src/external/enet/CMakeLists.txt

    r7385 r7390  
    2727    include/enet/unix.h
    2828    include/enet/utility.h
    29     #include/enet/win32.h
     29    include/enet/win32.h
    3030
    3131COMPILATION_BEGIN ENetCompilation.cpp
     
    3838    protocol.c
    3939    unix.c
    40     #win32.c
     40    win32.c
    4141COMPILATION_END
    4242)
  • code/branches/ipv6/src/external/enet/include/enet/enet.h

    r7389 r7390  
    7878{
    7979   ENetHostAddress host;
    80    enet_uint32 scopeID; //FIXME: this is of different size on Windows
     80#ifdef WIN32
     81   u_long scopeID;
     82#else
     83   uint32_t scopeID;
     84#endif
    8185   enet_uint16 port;
    8286} ENetAddress;
  • code/branches/ipv6/src/external/enet/include/enet/win32.h

    r7328 r7390  
    1515#include <stdlib.h>
    1616#include <winsock2.h>
     17#include <ws2tcpip.h>
    1718
    1819typedef SOCKET ENetSocket;
  • code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch

    r7378 r7390  
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Thu, 2 Sep 2010 14:26:42 +0200
    4 Subject: [PATCH 1/4] use getaddrinfo for lookup in unix.c
     4Subject: [PATCH 1/5] use getaddrinfo for lookup in unix.c
    55
    66---
  • code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch

    r7378 r7390  
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Thu, 2 Sep 2010 14:27:07 +0200
    4 Subject: [PATCH 2/4] basic IPv6 support on Linux systems
     4Subject: [PATCH 2/5] basic IPv6 support on Linux systems
    55
    66this uses IPv4-mapped IPv6 addresses
  • code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch

    r7389 r7390  
    1 From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5 Mon Sep 17 00:00:00 2001
     1From b26e4ef3fa9c0139fc2ec086d2243b809365d683 Mon Sep 17 00:00:00 2001
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Mon, 6 Sep 2010 14:58:50 +0200
    4 Subject: [PATCH 3/4] using address family in functions
     4Subject: [PATCH 3/5] using address family in functions
    55
    66---
     
    88 include/enet/enet.h |   22 +++++++++---
    99 protocol.c          |    5 ++-
    10  unix.c              |   87 ++++++++++++++++++++++++++++++++------------------
    11  4 files changed, 77 insertions(+), 41 deletions(-)
     10 unix.c              |   86 ++++++++++++++++++++++++++++++++------------------
     11 4 files changed, 76 insertions(+), 41 deletions(-)
    1212
    1313diff --git a/host.c b/host.c
     
    9191 
    9292diff --git a/unix.c b/unix.c
    93 index de032bb..13a24d8 100644
     93index de032bb..475c6e3 100644
    9494--- a/unix.c
    9595+++ b/unix.c
    96 @@ -71,7 +71,28 @@ enet_time_set (enet_uint32 newTimeBase)
     96@@ -71,7 +71,27 @@ enet_time_set (enet_uint32 newTimeBase)
    9797     timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
    9898 }
     
    119119+}
    120120+
    121 +
    122121+static ENetAddressFamily
    123122 enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
    124123 {
    125124     memset (address, 0, sizeof (ENetAddress));
    126 @@ -80,32 +101,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
     125@@ -80,32 +100,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
    127126         address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
    128127         //address -> scopeID = 0;
     
    164163         ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
    165164         ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
    166 @@ -132,7 +152,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
     165@@ -132,7 +151,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
    167166 
    168167     for (res = result; res != NULL; res = res -> ai_next)
     
    173172     }
    174173 
    175 @@ -147,9 +167,9 @@ static int
     174@@ -147,9 +166,9 @@ static int
    176175 enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
    177176 {
     
    185184 
    186185     return 0;
    187 @@ -168,21 +188,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
     186@@ -168,21 +187,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
    188187 }
    189188 
     
    211210 
    212211 int
    213 @@ -192,13 +212,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
     212@@ -192,13 +211,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
    214213 }
    215214 
     
    232231 
    233232     return sock;
    234 @@ -241,25 +264,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
     233@@ -241,25 +263,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
    235234 }
    236235 
     
    264263       return ENET_SOCKET_NULL;
    265264 
    266 @@ -281,7 +304,8 @@ int
     265@@ -281,7 +303,8 @@ int
    267266 enet_socket_send (ENetSocket socket,
    268267                   const ENetAddress * address,
     
    274273     struct msghdr msgHdr;
    275274     struct sockaddr_storage sin;
    276 @@ -291,9 +315,9 @@ enet_socket_send (ENetSocket socket,
     275@@ -291,9 +314,9 @@ enet_socket_send (ENetSocket socket,
    277276 
    278277     if (address != NULL)
     
    286285 
    287286     msgHdr.msg_iov = (struct iovec *) buffers;
    288 @@ -316,7 +340,8 @@ int
     287@@ -316,7 +339,8 @@ int
    289288 enet_socket_receive (ENetSocket socket,
    290289                      ENetAddress * address,
     
    296295     struct msghdr msgHdr;
    297296     struct sockaddr_storage sin;
    298 @@ -327,7 +352,7 @@ enet_socket_receive (ENetSocket socket,
     297@@ -327,7 +351,7 @@ enet_socket_receive (ENetSocket socket,
    299298     if (address != NULL)
    300299     {
  • code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch

    r7389 r7390  
    1 From 9801a6bcd072870248a6b07245fc09a9492f8f51 Mon Sep 17 00:00:00 2001
     1From 73fa28a84ce456561d3912578121a30bc8263c50 Mon Sep 17 00:00:00 2001
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Wed, 8 Sep 2010 12:50:04 +0200
    4 Subject: [PATCH 4/4] using two separate sockets for IPv4 and IPv6
     4Subject: [PATCH 4/5] using two separate sockets for IPv4 and IPv6
    55
    66---
    7  host.c              |   53 +++++++++++++++++++++++++++++++++++++-------------
    8  include/enet/enet.h |   11 ++++++++-
    9  protocol.c          |   47 +++++++++++++++++++++++++++++++++++++++-----
    10  unix.c              |   47 ++++++++++++++++++++++++++++++++------------
    11  4 files changed, 123 insertions(+), 35 deletions(-)
     7 host.c              |   53 +++++++++++++++++++++++++++---------
     8 include/enet/enet.h |   11 ++++++-
     9 protocol.c          |   47 ++++++++++++++++++++++++++++----
     10 unix.c              |   74 +++++++++++++++++++++++++++++++++++++-------------
     11 4 files changed, 144 insertions(+), 41 deletions(-)
    1212
    1313diff --git a/host.c b/host.c
     
    233233        host -> serviceTime = enet_time_get ();
    234234diff --git a/unix.c b/unix.c
    235 index 13a24d8..22ffb76 100644
     235index 475c6e3..751cb6f 100644
    236236--- a/unix.c
    237237+++ b/unix.c
    238 @@ -117,7 +117,9 @@ static int
     238@@ -116,7 +116,9 @@ static int
    239239 enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
    240240 {
     
    247247         ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
    248248         ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
    249 @@ -219,7 +221,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
     249@@ -218,7 +220,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
    250250 #ifdef IPV6_V6ONLY
    251251     if (family == ENET_IPV6)
     
    256256     }
    257257 #endif // IPV6_V6ONLY
    258 @@ -393,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
     258@@ -392,22 +394,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
    259259 }
    260260 
     
    263263+enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
    264264 {
    265 -#ifdef HAS_POLL
     265 #ifdef HAS_POLL
    266266-    struct pollfd pollSocket;
    267 +//#ifdef HAS_POLL
    268267+    struct pollfd pollSocket[2];
    269268     int pollCount;
     
    304303     if (pollCount < 0)
    305304       return -1;
    306 @@ -418,13 +436,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     305@@ -417,10 +435,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
    307306     if (pollCount == 0)
    308307       return 0;
     
    317316 
    318317     return 0;
    319 +/*
    320 +FIXME: implement or remove this
    321  #else
    322      fd_set readSet, writeSet;
    323      struct timeval timeVal;
    324 @@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     318@@ -436,12 +454,28 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     319     FD_ZERO (& writeSet);
     320 
     321     if (* condition & ENET_SOCKET_WAIT_SEND)
     322-      FD_SET (socket, & writeSet);
     323+    {
     324+        if (socket4 != ENET_SOCKET_NULL)
     325+            FD_SET (socket4, & writeSet);
     326+        if (socket6 != ENET_SOCKET_NULL)
     327+            FD_SET (socket6, & writeSet);
     328+    }
     329 
     330     if (* condition & ENET_SOCKET_WAIT_RECEIVE)
     331-      FD_SET (socket, & readSet);
     332+    {
     333+        if (socket4 != ENET_SOCKET_NULL)
     334+            FD_SET (socket4, & readSet);
     335+        if (socket6 != ENET_SOCKET_NULL)
     336+            FD_SET (socket6, & readSet);
     337+    }
     338+
     339+    ENetSocket maxSocket = 0;
     340+    if (socket4 != ENET_SOCKET_NULL)
     341+        maxSocket = socket4;
     342+    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
     343+        maxSocket = socket6;
     344 
     345-    selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
     346+    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
     347 
     348     if (selectCount < 0)
     349       return -1;
     350@@ -451,11 +485,13 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     351     if (selectCount == 0)
     352       return 0;
     353 
     354-    if (FD_ISSET (socket, & writeSet))
     355-      * condition |= ENET_SOCKET_WAIT_SEND;
     356+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
     357+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
     358+        * condition |= ENET_SOCKET_WAIT_SEND;
     359 
     360-    if (FD_ISSET (socket, & readSet))
     361-      * condition |= ENET_SOCKET_WAIT_RECEIVE;
     362+    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
     363+        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
     364+        * condition |= ENET_SOCKET_WAIT_RECEIVE;
    325365 
    326366     return 0;
    327  #endif
    328 +*/
    329  }
    330  
    331367 #endif
    332368--
  • code/branches/ipv6/src/external/enet/unix.c

    r7389 r7390  
    9292}
    9393
    94 
    9594static ENetAddressFamily
    9695enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
     
    398397enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
    399398{
    400 //#ifdef HAS_POLL
     399#ifdef HAS_POLL
    401400    struct pollfd pollSocket[2];
    402401    int pollCount;
     
    444443
    445444    return 0;
    446 /*
    447 FIXME: implement or remove this
    448445#else
    449446    fd_set readSet, writeSet;
     
    458455
    459456    if (* condition & ENET_SOCKET_WAIT_SEND)
    460       FD_SET (socket, & writeSet);
     457    {
     458        if (socket4 != ENET_SOCKET_NULL)
     459            FD_SET (socket4, & writeSet);
     460        if (socket6 != ENET_SOCKET_NULL)
     461            FD_SET (socket6, & writeSet);
     462    }
    461463
    462464    if (* condition & ENET_SOCKET_WAIT_RECEIVE)
    463       FD_SET (socket, & readSet);
    464 
    465     selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
     465    {
     466        if (socket4 != ENET_SOCKET_NULL)
     467            FD_SET (socket4, & readSet);
     468        if (socket6 != ENET_SOCKET_NULL)
     469            FD_SET (socket6, & readSet);
     470    }
     471
     472    ENetSocket maxSocket = 0;
     473    if (socket4 != ENET_SOCKET_NULL)
     474        maxSocket = socket4;
     475    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
     476        maxSocket = socket6;
     477
     478    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
    466479
    467480    if (selectCount < 0)
     
    473486      return 0;
    474487
    475     if (FD_ISSET (socket, & writeSet))
    476       * condition |= ENET_SOCKET_WAIT_SEND;
    477 
    478     if (FD_ISSET (socket, & readSet))
    479       * condition |= ENET_SOCKET_WAIT_RECEIVE;
    480 
    481     return 0;
    482 #endif
    483 */
    484 }
    485 
    486 #endif
    487 
     488    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
     489        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
     490        * condition |= ENET_SOCKET_WAIT_SEND;
     491
     492    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
     493        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
     494        * condition |= ENET_SOCKET_WAIT_RECEIVE;
     495
     496    return 0;
     497#endif
     498}
     499
     500#endif
     501
  • code/branches/ipv6/src/external/enet/win32.c

    r7328 r7390  
    5353}
    5454
     55static enet_uint16
     56enet_af (ENetAddressFamily family)
     57{
     58    if (family == ENET_IPV4)
     59        return AF_INET;
     60    if (family == ENET_IPV6)
     61        return AF_INET6;
     62    return 0;
     63}
     64
     65static socklen_t
     66enet_sa_size (ENetAddressFamily family)
     67{
     68    if (family == ENET_IPV4)
     69        return sizeof (SOCKADDR_IN);
     70    if (family == ENET_IPV6)
     71        return sizeof (SOCKADDR_IN6);
     72    return 0;
     73}
     74
     75static ENetAddressFamily
     76enet_address_set_address (ENetAddress * address, const SOCKADDR * sin)
     77{
     78    memset (address, 0, sizeof (ENetAddress));
     79    if (sin -> sa_family == AF_INET)
     80    {
     81        address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr));
     82        //address -> scopeID = 0;
     83        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port);
     84        return ENET_IPV4;
     85    }
     86    if (sin -> sa_family == AF_INET6)
     87    {
     88        address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr;
     89        address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id;
     90        address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port);
     91        return ENET_IPV6;
     92    }
     93    return ENET_NO_ADDRESS_FAMILY;
     94}
     95
     96static int
     97enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family)
     98{
     99    memset (sin, 0, enet_sa_size(family));
     100    if (family == ENET_IPV4 &&
     101      (enet_get_address_family (address) == ENET_IPV4 ||
     102      !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
     103    {
     104        ((SOCKADDR_IN *) sin) -> sin_family = AF_INET;
     105        ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12];
     106        ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
     107        return 0;
     108    }
     109    else if (family == ENET_IPV6)
     110    {
     111        ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6;
     112        ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host;
     113        ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID;
     114        ((SOCKADDR_IN6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
     115        return 0;
     116    }
     117    return -1;
     118}
     119
    55120int
    56121enet_address_set_host (ENetAddress * address, const char * name)
    57122{
    58     struct hostent * hostEntry;
    59 
    60     hostEntry = gethostbyname (name);
    61     if (hostEntry == NULL ||
    62         hostEntry -> h_addrtype != AF_INET)
    63     {
    64         unsigned long host = inet_addr (name);
    65         if (host == INADDR_NONE)
    66             return -1;
    67         address -> host = host;
    68         return 0;
    69     }
    70 
    71     address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
     123    enet_uint16 port = address -> port;
     124    ADDRINFO hints;
     125    ADDRINFO * result;
     126    ADDRINFO * res;
     127
     128    memset(& hints, 0, sizeof (hints));
     129    hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
     130    hints.ai_family = AF_UNSPEC;
     131
     132    if ( getaddrinfo(name, NULL, &hints, &result) )
     133        return -1;
     134
     135    for (res = result; res != NULL; res = res -> ai_next)
     136    {
     137        if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
     138            break;
     139    }
     140
     141    address -> port = port;
     142    freeaddrinfo(result);
     143    if (res == NULL) return -1;
     144
     145    return 0;
     146}
     147
     148static int
     149enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
     150{
     151    SOCKADDR_STORAGE sin;
     152    enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6);
     153
     154    if ( getnameinfo((SOCKADDR *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
     155        return -1;
    72156
    73157    return 0;
     
    77161enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
    78162{
    79     char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
    80     if (addr == NULL)
    81         return -1;
    82     strncpy (name, addr, nameLength);
    83     return 0;
     163    return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
    84164}
    85165
     
    87167enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
    88168{
    89     struct in_addr in;
    90     struct hostent * hostEntry;
    91    
    92     in.s_addr = address -> host;
    93    
    94     hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
    95     if (hostEntry == NULL)
    96       return enet_address_get_host_ip (address, name, nameLength);
    97 
    98     strncpy (name, hostEntry -> h_name, nameLength);
    99 
    100     return 0;
    101 }
    102 
    103 int
    104 enet_socket_bind (ENetSocket socket, const ENetAddress * address)
    105 {
    106     struct sockaddr_in sin;
    107 
    108     memset (& sin, 0, sizeof (struct sockaddr_in));
    109 
    110     sin.sin_family = AF_INET;
     169    return enet_address_get_host_x(address, name, nameLength, 0);
     170}
     171
     172int
     173enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
     174{
     175    SOCKADDR_STORAGE sin;
    111176
    112177    if (address != NULL)
    113178    {
    114        sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
    115        sin.sin_addr.s_addr = address -> host;
     179        enet_address_set_sin((SOCKADDR *) & sin, address, family);
    116180    }
    117181    else
    118182    {
    119        sin.sin_port = 0;
    120        sin.sin_addr.s_addr = INADDR_ANY;
    121     }
    122 
    123     return bind (socket,
    124                  (struct sockaddr *) & sin,
    125                  sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
     183        ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
     184        enet_address_set_sin((SOCKADDR *) & sin, & address_, family);
     185    }
     186
     187    return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
    126188}
    127189
     
    133195
    134196ENetSocket
    135 enet_socket_create (ENetSocketType type)
     197enet_socket_create (ENetSocketType type, ENetAddressFamily family)
    136198{
    137199    return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
     
    174236
    175237int
    176 enet_socket_connect (ENetSocket socket, const ENetAddress * address)
    177 {
    178     struct sockaddr_in sin;
    179 
    180     memset (& sin, 0, sizeof (struct sockaddr_in));
    181 
    182     sin.sin_family = AF_INET;
    183     sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
    184     sin.sin_addr.s_addr = address -> host;
    185 
    186     return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
     238enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
     239{
     240    SOCKADDR_STORAGE sin;
     241    enet_address_set_sin((SOCKADDR *) & sin, address, family);
     242
     243    return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
    187244}
    188245
    189246ENetSocket
    190 enet_socket_accept (ENetSocket socket, ENetAddress * address)
     247enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
    191248{
    192249    SOCKET result;
    193     struct sockaddr_in sin;
    194     int sinLength = sizeof (struct sockaddr_in);
     250    SOCKADDR_STORAGE sin;
     251    int sinLength = enet_sa_size (family);
    195252
    196253    result = accept (socket,
    197                      address != NULL ? (struct sockaddr *) & sin : NULL,
     254                     address != NULL ? (SOCKADDR *) & sin : NULL,
    198255                     address != NULL ? & sinLength : NULL);
    199256
     
    203260    if (address != NULL)
    204261    {
    205         address -> host = (enet_uint32) sin.sin_addr.s_addr;
    206         address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
     262        enet_address_set_address(address, (SOCKADDR *) & sin);
    207263    }
    208264
     
    220276                  const ENetAddress * address,
    221277                  const ENetBuffer * buffers,
    222                   size_t bufferCount)
    223 {
    224     struct sockaddr_in sin;
     278                  size_t bufferCount,
     279                  ENetAddressFamily family)
     280{
     281    SOCKADDR_STORAGE sin;
    225282    DWORD sentLength;
    226283
    227284    if (address != NULL)
    228285    {
    229         memset (& sin, 0, sizeof (struct sockaddr_in));
    230 
    231         sin.sin_family = AF_INET;
    232         sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
    233         sin.sin_addr.s_addr = address -> host;
     286        enet_address_set_sin((SOCKADDR *) & sin, address, family);
    234287    }
    235288
     
    239292                   & sentLength,
    240293                   0,
    241                    address != NULL ? (struct sockaddr *) & sin : 0,
    242                    address != NULL ? sizeof (struct sockaddr_in) : 0,
     294                   address != NULL ? (SOCKADDR *) & sin : 0,
     295                   address != NULL ? enet_sa_size (family) : 0,
    243296                   NULL,
    244297                   NULL) == SOCKET_ERROR)
     
    257310                     ENetAddress * address,
    258311                     ENetBuffer * buffers,
    259                      size_t bufferCount)
    260 {
    261     INT sinLength = sizeof (struct sockaddr_in);
     312                     size_t bufferCount,
     313                     ENetAddressFamily family)
     314{
     315    INT sinLength = enet_sa_size (family);
    262316    DWORD flags = 0,
    263317          recvLength;
    264     struct sockaddr_in sin;
     318    SOCKADDR_STORAGE sin;
    265319
    266320    if (WSARecvFrom (socket,
     
    269323                     & recvLength,
    270324                     & flags,
    271                      address != NULL ? (struct sockaddr *) & sin : NULL,
     325                     address != NULL ? (SOCKADDR *) & sin : NULL,
    272326                     address != NULL ? & sinLength : NULL,
    273327                     NULL,
     
    289343    if (address != NULL)
    290344    {
    291         address -> host = (enet_uint32) sin.sin_addr.s_addr;
    292         address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
     345        enet_address_set_address(address, (SOCKADDR *) & sin);
    293346    }
    294347
     
    308361
    309362int
    310 enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
     363enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
    311364{
    312365    fd_set readSet, writeSet;
    313366    struct timeval timeVal;
    314367    int selectCount;
    315    
     368
    316369    timeVal.tv_sec = timeout / 1000;
    317370    timeVal.tv_usec = (timeout % 1000) * 1000;
    318    
     371
    319372    FD_ZERO (& readSet);
    320373    FD_ZERO (& writeSet);
    321374
    322375    if (* condition & ENET_SOCKET_WAIT_SEND)
    323       FD_SET (socket, & writeSet);
     376    {
     377        if (socket4 != ENET_SOCKET_NULL)
     378            FD_SET (socket4, & writeSet);
     379        if (socket6 != ENET_SOCKET_NULL)
     380            FD_SET (socket6, & writeSet);
     381    }
    324382
    325383    if (* condition & ENET_SOCKET_WAIT_RECEIVE)
    326       FD_SET (socket, & readSet);
    327 
    328     selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
     384    {
     385        if (socket4 != ENET_SOCKET_NULL)
     386            FD_SET (socket4, & readSet);
     387        if (socket6 != ENET_SOCKET_NULL)
     388            FD_SET (socket6, & readSet);
     389    }
     390
     391    ENetSocket maxSocket = 0;
     392    if (socket4 != ENET_SOCKET_NULL)
     393        maxSocket = socket4;
     394    if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
     395        maxSocket = socket6;
     396
     397    selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
    329398
    330399    if (selectCount < 0)
     
    336405      return 0;
    337406
    338     if (FD_ISSET (socket, & writeSet))
    339       * condition |= ENET_SOCKET_WAIT_SEND;
    340    
    341     if (FD_ISSET (socket, & readSet))
    342       * condition |= ENET_SOCKET_WAIT_RECEIVE;
    343 
    344     return 0;
    345 }
     407    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
     408        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
     409        * condition |= ENET_SOCKET_WAIT_SEND;
     410
     411    if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
     412        (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
     413        * condition |= ENET_SOCKET_WAIT_RECEIVE;
     414
     415    return 0;
     416}
    346417
    347418#endif
Note: See TracChangeset for help on using the changeset viewer.