diff --git a/host.c b/host.c index 3be6c092..6418f270 100644 --- a/host.c +++ b/host.c @@ -49,6 +49,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL memset (host -> peers, 0, peerCount * sizeof (ENetPeer)); host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM); + if (host -> socket != ENET_SOCKET_NULL) + enet_socket_set_option (host -> socket, ENET_SOCKOPT_IPV6_V6ONLY, 0); if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0)) { if (host -> socket != ENET_SOCKET_NULL) @@ -64,6 +66,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL 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 -> socket, ENET_SOCKOPT_IPV6_V6ONLY, 0); + if (address != NULL && enet_socket_get_address (host -> socket, & host -> address) < 0) host -> address = * address; @@ -87,7 +91,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL host -> commandCount = 0; host -> bufferCount = 0; host -> checksum = NULL; - host -> receivedAddress.host = ENET_HOST_ANY; + host -> receivedAddress.host = in6addr_any; host -> receivedAddress.port = 0; host -> receivedData = NULL; host -> receivedDataLength = 0; diff --git a/include/enet/enet.h b/include/enet/enet.h index 650b199e..433e0205 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -62,7 +62,8 @@ typedef enum _ENetSocketOption ENET_SOCKOPT_RCVTIMEO = 6, ENET_SOCKOPT_SNDTIMEO = 7, ENET_SOCKOPT_ERROR = 8, - ENET_SOCKOPT_NODELAY = 9 + ENET_SOCKOPT_NODELAY = 9, + ENET_SOCKOPT_IPV6_V6ONLY = 10 } ENetSocketOption; typedef enum _ENetSocketShutdown @@ -72,6 +73,7 @@ typedef enum _ENetSocketShutdown ENET_SOCKET_SHUTDOWN_READ_WRITE = 2 } ENetSocketShutdown; +#define ENET_IPV6 1 #define ENET_HOST_ANY 0 #define ENET_HOST_BROADCAST 0xFFFFFFFFU #define ENET_PORT_ANY 0 @@ -88,10 +90,13 @@ typedef enum _ENetSocketShutdown */ typedef struct _ENetAddress { - enet_uint32 host; + struct in6_addr host; enet_uint16 port; + enet_uint16 sin6_scope_id; } ENetAddress; +#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0) + /** * Packet flag bit constants. * diff --git a/include/enet/win32.h b/include/enet/win32.h index 063111c7..f90db46f 100644 --- a/include/enet/win32.h +++ b/include/enet/win32.h @@ -14,9 +14,20 @@ #endif #endif + +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif +#ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 +#endif +#ifndef NOMINMAX + #define NOMINMAX +#endif #include #include #include +#include typedef SOCKET ENetSocket; diff --git a/protocol.c b/protocol.c index 29d64873..8e7bd3b3 100644 --- a/protocol.c +++ b/protocol.c @@ -298,7 +298,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet } else if (currentPeer -> state != ENET_PEER_STATE_CONNECTING && - currentPeer -> address.host == host -> receivedAddress.host) + in6_equal(currentPeer -> address.host , host -> receivedAddress.host)) { if (currentPeer -> address.port == host -> receivedAddress.port && currentPeer -> connectID == command -> connect.connectID) @@ -1010,9 +1010,9 @@ 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 || + ((!in6_equal(host -> receivedAddress.host , peer -> address.host) || host -> receivedAddress.port != peer -> address.port) && - peer -> address.host != ENET_HOST_BROADCAST) || + 1 /* no broadcast in ipv6 !in6_equal(peer -> address.host , ENET_HOST_BROADCAST)*/) || (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID && sessionID != peer -> incomingSessionID)) return 0; diff --git a/unix.c b/unix.c index b3cadd0d..12b26a26 100644 --- a/unix.c +++ b/unix.c @@ -108,28 +108,46 @@ enet_address_set_host (ENetAddress * address, const char * name) struct addrinfo hints, * resultList = NULL, * result = NULL; memset (& hints, 0, sizeof (hints)); - hints.ai_family = AF_INET; + hints.ai_family = AF_UNSPEC; - if (getaddrinfo (name, NULL, NULL, & resultList) != 0) + if (getaddrinfo (name, NULL, & hints, & resultList) != 0) return -1; for (result = resultList; result != NULL; result = result -> ai_next) { - if (result -> ai_family == AF_INET && result -> ai_addr != NULL && result -> ai_addrlen >= sizeof (struct sockaddr_in)) + if (result -> ai_addr != NULL && result -> ai_addrlen >= sizeof (struct sockaddr_in)) { - struct sockaddr_in * sin = (struct sockaddr_in *) result -> ai_addr; + if (result -> ai_family == AF_INET) + { + struct sockaddr_in * sin = (struct sockaddr_in *) result -> ai_addr; - address -> host = sin -> sin_addr.s_addr; + ((uint32_t *) & address -> host.s6_addr)[0] = 0; + ((uint32_t *) & address -> host.s6_addr)[1] = 0; + ((uint32_t *) & address -> host.s6_addr)[2] = htonl(0xffff); + ((uint32_t *) & address -> host.s6_addr)[3] = sin->sin_addr.s_addr; - freeaddrinfo (resultList); + freeaddrinfo (resultList); - return 0; + return 0; + } + else if(result -> ai_family == AF_INET6) + { + struct sockaddr_in6 * sin = (struct sockaddr_in6 *) result -> ai_addr; + + address -> host = sin -> sin6_addr; + address -> sin6_scope_id = sin -> sin6_scope_id; + + freeaddrinfo (resultList); + + return 0; + } } } if (resultList != NULL) freeaddrinfo (resultList); #else +#warning "Really use gethostbyname() with IPv6? Not all platforms support it." struct hostent * hostEntry = NULL; #ifdef HAS_GETHOSTBYNAME_R struct hostent hostData; @@ -145,17 +163,18 @@ enet_address_set_host (ENetAddress * address, const char * name) hostEntry = gethostbyname (name); #endif - if (hostEntry != NULL && hostEntry -> h_addrtype == AF_INET) + if (hostEntry != NULL && hostEntry -> h_addrtype == AF_INET6) { - address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; + address -> host = *(struct in6_addr *) hostEntry -> h_addr_list [0]; return 0; } #endif #ifdef HAS_INET_PTON - if (! inet_pton (AF_INET, name, & address -> host)) + if (! inet_pton (AF_INET6, name, & address -> host)) #else +#error "inet_pton() is needed for IPv6 support" if (! inet_aton (name, (struct in_addr *) & address -> host)) #endif return -1; @@ -167,8 +186,9 @@ int enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) { #ifdef HAS_INET_NTOP - if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL) + if (inet_ntop (AF_INET6, & address -> host, name, nameLength) == NULL) #else +#error "inet_ntop() is needed for IPv6 support" char * addr = inet_ntoa (* (struct in_addr *) & address -> host); if (addr != NULL) { @@ -186,15 +206,17 @@ enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameL int enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) { + #ifdef HAS_GETNAMEINFO - struct sockaddr_in sin; + struct sockaddr_in6 sin; int err; 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; + sin.sin6_family = AF_INET6; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; err = getnameinfo ((struct sockaddr *) & sin, sizeof (sin), name, nameLength, NULL, 0, NI_NAMEREQD); if (! err) @@ -206,24 +228,25 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng if (err != EAI_NONAME) return -1; #else - struct in_addr in; +#warning "Really use gethostbyaddr() with IPv6? Not all platforms support it." + struct in6_addr in; struct hostent * hostEntry = NULL; #ifdef HAS_GETHOSTBYADDR_R struct hostent hostData; char buffer [2048]; int errnum; - in.s_addr = address -> host; + in = address -> host; #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); + gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); #else - hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum); + hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & errnum); #endif #else - in.s_addr = address -> host; + in = address -> host; - hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); + hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in6_addr), AF_INET6); #endif if (hostEntry != NULL) @@ -242,39 +265,42 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng int enet_socket_bind (ENetSocket socket, const ENetAddress * address) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; + sin.sin6_family = AF_INET6; if (address != NULL) { - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; } else { - sin.sin_port = 0; - sin.sin_addr.s_addr = INADDR_ANY; + sin.sin6_port = 0; + sin.sin6_addr = in6addr_any; + sin.sin6_scope_id = 0; } return bind (socket, (struct sockaddr *) & sin, - sizeof (struct sockaddr_in)); + sizeof (struct sockaddr_in6)); } int enet_socket_get_address (ENetSocket socket, ENetAddress * address) { - struct sockaddr_in sin; - socklen_t sinLength = sizeof (struct sockaddr_in); + struct sockaddr_in6 sin; + socklen_t sinLength = sizeof (struct sockaddr_in6); if (getsockname (socket, (struct sockaddr *) & sin, & sinLength) == -1) return -1; - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; return 0; } @@ -288,7 +314,7 @@ enet_socket_listen (ENetSocket socket, int backlog) ENetSocket enet_socket_create (ENetSocketType type) { - return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); + return socket (PF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); } int @@ -343,6 +369,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); break; + case ENET_SOCKOPT_IPV6_V6ONLY: + result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int)); + break; + default: break; } @@ -370,16 +400,17 @@ enet_socket_get_option (ENetSocket socket, ENetSocketOption option, int * value) int enet_socket_connect (ENetSocket socket, const ENetAddress * address) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; int result; - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_family = AF_INET6; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; - result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)); + result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6)); if (result == -1 && errno == EINPROGRESS) return 0; @@ -390,8 +421,8 @@ ENetSocket enet_socket_accept (ENetSocket socket, ENetAddress * address) { int result; - struct sockaddr_in sin; - socklen_t sinLength = sizeof (struct sockaddr_in); + struct sockaddr_in6 sin; + socklen_t sinLength = sizeof (struct sockaddr_in6); result = accept (socket, address != NULL ? (struct sockaddr *) & sin : NULL, @@ -402,8 +433,9 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address) if (address != NULL) { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; } return result; @@ -429,21 +461,22 @@ enet_socket_send (ENetSocket socket, size_t bufferCount) { struct msghdr msgHdr; - struct sockaddr_in sin; + struct sockaddr_in6 sin; int sentLength; memset (& msgHdr, 0, sizeof (struct msghdr)); if (address != NULL) { - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_family = AF_INET6; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; msgHdr.msg_name = & sin; - msgHdr.msg_namelen = sizeof (struct sockaddr_in); + msgHdr.msg_namelen = sizeof (struct sockaddr_in6); } msgHdr.msg_iov = (struct iovec *) buffers; @@ -469,7 +502,7 @@ enet_socket_receive (ENetSocket socket, size_t bufferCount) { struct msghdr msgHdr; - struct sockaddr_in sin; + struct sockaddr_in6 sin; int recvLength; memset (& msgHdr, 0, sizeof (struct msghdr)); @@ -477,7 +510,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; @@ -500,8 +533,9 @@ enet_socket_receive (ENetSocket socket, if (address != NULL) { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; } return recvLength; diff --git a/win32.c b/win32.c index 5cc16799..58b33c69 100644 --- a/win32.c +++ b/win32.c @@ -62,20 +62,36 @@ enet_time_set (enet_uint32 newTimeBase) int enet_address_set_host (ENetAddress * address, const char * name) { - struct hostent * hostEntry; - + struct hostent * hostEntry = NULL; +#ifdef HAS_GETHOSTBYNAME_R + struct hostent hostData; + char buffer [2048]; + int errnum; + +#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); +#else + hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum); +#endif +#else hostEntry = gethostbyname (name); +#endif + if (hostEntry == NULL || hostEntry -> h_addrtype != AF_INET) { - unsigned long host = inet_addr (name); - if (host == INADDR_NONE) +#ifdef HAS_INET_PTON + if (! inet_pton (AF_INET6, name, & address -> host)) +#elif _MSC_VER + // TODO FIXME +#else + if (! inet_aton (name, (struct in_addr *) & address -> host)) +#endif return -1; - address -> host = host; return 0; } - address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; +// address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; return 0; } @@ -83,28 +99,46 @@ enet_address_set_host (ENetAddress * address, const char * name) int enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) { +#ifdef HAS_INET_NTOP + if (inet_ntop (AF_INET6, & address -> host, name, nameLength) == NULL) +#else char * addr = inet_ntoa (* (struct in_addr *) & address -> host); - if (addr == NULL) - return -1; - else + if (addr != NULL) { size_t addrLen = strlen(addr); if (addrLen >= nameLength) return -1; memcpy (name, addr, addrLen + 1); - } + } + else +#endif + return -1; return 0; } int enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) { - struct in_addr in; - struct hostent * hostEntry; - - in.s_addr = address -> host; - - hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); + struct in6_addr in; + struct hostent * hostEntry = NULL; +#ifdef HAS_GETHOSTBYADDR_R + struct hostent hostData; + char buffer [2048]; + int errnum; + + in = address -> host; + +#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); +#else + hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & errnum); +#endif +#else + in = address -> host; + + hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in6_addr), AF_INET6); +#endif + if (hostEntry == NULL) return enet_address_get_host_ip (address, name, nameLength); else @@ -121,39 +155,42 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng int enet_socket_bind (ENetSocket socket, const ENetAddress * address) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; + sin.sin6_family = AF_INET6; if (address != NULL) { - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; } else { - sin.sin_port = 0; - sin.sin_addr.s_addr = INADDR_ANY; + sin.sin6_port = 0; + sin.sin6_addr = in6addr_any; + sin.sin6_scope_id = 0; } return bind (socket, (struct sockaddr *) & sin, - sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0; + sizeof (struct sockaddr_in6)) == SOCKET_ERROR ? -1 : 0; } int enet_socket_get_address (ENetSocket socket, ENetAddress * address) { - struct sockaddr_in sin; - int sinLength = sizeof (struct sockaddr_in); + struct sockaddr_in6 sin; + int sinLength = sizeof (struct sockaddr_in6); if (getsockname (socket, (struct sockaddr *) & sin, & sinLength) == -1) return -1; - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; return 0; } @@ -167,7 +204,7 @@ enet_socket_listen (ENetSocket socket, int backlog) ENetSocket enet_socket_create (ENetSocketType type) { - return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); + return socket (PF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); } int @@ -211,6 +248,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); break; + case ENET_SOCKOPT_IPV6_V6ONLY: + result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int)); + break; + default: break; } @@ -237,16 +278,17 @@ enet_socket_get_option (ENetSocket socket, ENetSocketOption option, int * value) int enet_socket_connect (ENetSocket socket, const ENetAddress * address) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; int result; - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_family = AF_INET6; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; - result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)); + result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6)); if (result == SOCKET_ERROR && WSAGetLastError () != WSAEWOULDBLOCK) return -1; @@ -257,8 +299,8 @@ ENetSocket enet_socket_accept (ENetSocket socket, ENetAddress * address) { SOCKET result; - struct sockaddr_in sin; - int sinLength = sizeof (struct sockaddr_in); + struct sockaddr_in6 sin; + int sinLength = sizeof (struct sockaddr_in6); result = accept (socket, address != NULL ? (struct sockaddr *) & sin : NULL, @@ -269,8 +311,9 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address) if (address != NULL) { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; } return result; @@ -295,16 +338,17 @@ enet_socket_send (ENetSocket socket, const ENetBuffer * buffers, size_t bufferCount) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; DWORD sentLength; if (address != NULL) { - memset (& sin, 0, sizeof (struct sockaddr_in)); + memset (& sin, 0, sizeof (struct sockaddr_in6)); - sin.sin_family = AF_INET; - sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); - sin.sin_addr.s_addr = address -> host; + sin.sin6_family = AF_INET6; + sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); + sin.sin6_addr = address -> host; + sin.sin6_scope_id = address -> sin6_scope_id; } if (WSASendTo (socket, @@ -313,7 +357,7 @@ enet_socket_send (ENetSocket socket, & sentLength, 0, address != NULL ? (struct sockaddr *) & sin : NULL, - address != NULL ? sizeof (struct sockaddr_in) : 0, + address != NULL ? sizeof (struct sockaddr_in6) : 0, NULL, NULL) == SOCKET_ERROR) { @@ -332,10 +376,10 @@ enet_socket_receive (ENetSocket socket, ENetBuffer * buffers, size_t bufferCount) { - INT sinLength = sizeof (struct sockaddr_in); + INT sinLength = sizeof (struct sockaddr_in6); DWORD flags = 0, recvLength; - struct sockaddr_in sin; + struct sockaddr_in6 sin; if (WSARecvFrom (socket, (LPWSABUF) buffers, @@ -362,8 +406,9 @@ enet_socket_receive (ENetSocket socket, if (address != NULL) { - address -> host = (enet_uint32) sin.sin_addr.s_addr; - address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); + address -> host = sin.sin6_addr; + address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); + address -> sin6_scope_id = sin.sin6_scope_id; } return (int) recvLength;