diff --git a/host.c b/host.c index fff946a3..60ebc96c 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 dfa2c703..68be76cd 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -58,7 +58,8 @@ typedef enum _ENetSocketOption ENET_SOCKOPT_SNDTIMEO = 7, ENET_SOCKOPT_ERROR = 8, ENET_SOCKOPT_NODELAY = 9, - ENET_SOCKOPT_TTL = 10 + ENET_SOCKOPT_TTL = 10, + ENET_SOCKOPT_IPV6_V6ONLY = 11 } ENetSocketOption; typedef enum _ENetSocketShutdown @@ -68,6 +69,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 @@ -84,10 +86,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 1ba57909..43a41075 100644 --- a/include/enet/win32.h +++ b/include/enet/win32.h @@ -20,8 +20,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 1206b58c..9e6e0a35 100644 --- a/protocol.c +++ b/protocol.c @@ -318,7 +318,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) @@ -1043,9 +1043,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 a66bc33d..7ed634c1 100644 --- a/unix.c +++ b/unix.c @@ -104,11 +104,10 @@ int enet_address_set_host_ip (ENetAddress * address, const char * name) { #ifdef HAS_INET_PTON - if (! inet_pton (AF_INET, name, & address -> host)) + if (! inet_pton (AF_INET6, name, & address -> host)) #else if (! inet_aton (name, (struct in_addr *) & address -> host)) #endif - return -1; return 0; } @@ -120,28 +119,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; @@ -157,9 +174,9 @@ 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; } @@ -172,8 +189,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) { @@ -191,15 +209,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) @@ -211,24 +231,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__) || defined(__GNU__) - 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) @@ -247,39 +268,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; } @@ -293,7 +317,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 @@ -348,6 +372,9 @@ 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)); + case ENET_SOCKOPT_TTL: result = setsockopt (socket, IPPROTO_IP, IP_TTL, (char *) & value, sizeof (int)); break; @@ -384,16 +411,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; @@ -404,8 +432,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, @@ -416,8 +444,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; @@ -443,21 +472,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; @@ -483,7 +513,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)); @@ -491,7 +521,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; @@ -520,8 +550,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 578a3227..77d0d50d 100644 --- a/win32.c +++ b/win32.c @@ -63,6 +63,10 @@ enet_time_set (enet_uint32 newTimeBase) int enet_address_set_host_ip (ENetAddress * address, const char * name) { +#ifdef HAS_INET_PTON + if (! inet_pton (AF_INET6, name, & address -> host)) + return -1; +#else enet_uint8 vals [4] = { 0, 0, 0, 0 }; int i; @@ -83,20 +87,34 @@ enet_address_set_host_ip (ENetAddress * address, const char * name) } memcpy (& address -> host, vals, sizeof (enet_uint32)); +#endif + return 0; } 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) return enet_address_set_host_ip (address, name); - address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; +// address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; return 0; } @@ -104,28 +122,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 @@ -142,39 +178,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; } @@ -188,7 +227,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 @@ -232,6 +271,9 @@ 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)); + case ENET_SOCKOPT_TTL: result = setsockopt (socket, IPPROTO_IP, IP_TTL, (char *) & value, sizeof (int)); break; @@ -267,16 +309,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; @@ -287,8 +330,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, @@ -299,8 +342,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; @@ -325,16 +369,17 @@ enet_socket_send (ENetSocket socket, const ENetBuffer * buffers, size_t bufferCount) { - struct sockaddr_in sin; + struct sockaddr_in6 sin; DWORD sentLength = 0; 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, @@ -343,7 +388,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) { @@ -362,10 +407,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 = 0; - struct sockaddr_in sin; + struct sockaddr_in6 sin; if (WSARecvFrom (socket, (LPWSABUF) buffers, @@ -395,8 +440,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;