Skip to content

Commit c559551

Browse files
committed
Everything converted to ipv6.
You still can connect to ipv4 via IPv4-Mapped IPv6 Addresses. Incompatible lib ABI. Squashed commit of the following: commit d643eb3 Merge: c3fec7a 9ce6c59 Author: proller <proller@github.com> Date: Mon Oct 31 23:06:18 2016 +0300 Merge branch 'master' into ipv6 commit c3fec7a Merge: 1f8eb62 f46fee0 Author: proller <proller@github.com> Date: Fri Sep 16 13:16:45 2016 +0300 Merge remote-tracking branch 'upstream/master' into ipv6 commit 1f8eb62 Author: proller <proller@github.com> Date: Sat Mar 12 02:11:52 2016 +0300 support sin6_scope_id in address commit f499bc5 Merge: 720e7c4 4d10671 Author: proller <proller@github.com> Date: Sat Mar 12 01:14:00 2016 +0300 Merge remote-tracking branch 'upstream/master' into ipv6 commit 720e7c4 Author: proller <proller@github.com> Date: Thu Dec 17 01:17:38 2015 +0300 return setting ENET_SOCKOPT_IPV6_V6ONLY=>0 after bind commit b048473 Author: proller <proller@github.com> Date: Sat Sep 26 11:40:41 2015 +0400 fix win32 compiler warning commit 5a9492d Merge: 09018e4 2a567b0 Author: proller <proller@users.noreply.github.com> Date: Tue Aug 25 18:12:34 2015 +0300 Merge pull request #1 from K-os/ipv6 Allow connecting to IPv4 addresses commit 2a567b0 Author: Gabriel Hege <g+github@hege.cc> Date: Mon Aug 24 12:07:09 2015 +0200 Set socket option IPV6_V6ONLY before bind() commit 2b52599 Author: Gabriel Hege <g+github@hege.cc> Date: Mon Aug 24 12:11:09 2015 +0200 Handle IPv4/v6 addresses returend from getaddrinfo commit a91524f Author: Gabriel Hege <g+github@hege.cc> Date: Thu Aug 13 19:25:17 2015 +0200 gethostbyname(): Use correct address family AF_INET6 for result from gethostbyname() commit 90620b2 Author: Gabriel Hege <g+github@hege.cc> Date: Thu Aug 13 19:26:41 2015 +0200 Fail or Warn, when getaddrinfo(), inet_pton() and friends are missing commit 09018e4 Author: proller <proller@github.com> Date: Mon May 11 22:03:48 2015 +0300 fix commit a2651c6 Merge: 2c1bac4 62755b1 Author: proller <proller@github.com> Date: Mon May 11 20:28:46 2015 +0300 Merge branch 'master' into ipv6 Conflicts: unix.c commit 2c1bac4 Author: proller <proller@github.com> Date: Mon May 11 17:53:49 2015 +0300 add IPV6_V6ONLY socket option = 0 commit 52b0da7 Author: proller <proller@github.com> Date: Tue May 5 22:37:06 2015 +0400 very ugly win32 fix commit 1394392 Merge: e236d01 b1758c4 Author: proller <proller@github.com> Date: Mon May 4 22:45:36 2015 +0300 Merge branch 'master' into ipv6 commit e236d01 Author: proller <proller@github.com> Date: Mon May 4 19:41:47 2015 +0400 fix aton types commit 0ff6534 Merge: cf46ab3 c10af34 Author: proller <proller@github.com> Date: Fri Apr 10 23:40:21 2015 +0300 Merge remote-tracking branch 'origin/master' into ipv6 Conflicts: include/enet/win32.h commit cf46ab3 Author: proller <proller@github.com> Date: Mon Apr 6 03:20:12 2015 +0300 win32: fix include order commit b9de5d2 Merge: 3f5bab2 a2eb357 Author: proller <proller@github.com> Date: Sun Apr 5 03:38:19 2015 +0300 Merge branch 'master' into ipv6 Conflicts: unix.c commit 3f5bab2 Author: proller <proller@github.com> Date: Fri Jan 9 21:05:50 2015 +0300 fix inet_ntoa commit 7d9fa2b Author: proller <proller@github.com> Date: Tue Dec 16 23:53:47 2014 +0300 fix win32 build errors commit 04394e6 Author: proller <proller@github.com> Date: Wed Dec 3 01:07:18 2014 +0300 apple fix commit 9122c46 Merge: b3f2bf9 b8ae4a1 Author: proller <proller@github.com> Date: Wed Dec 3 01:01:51 2014 +0300 Merge branch 'master' into ipv6 commit b3f2bf9 Merge: 512a43b 8096edb Author: proller <proller@github.com> Date: Wed Oct 8 17:07:54 2014 +0400 Merge branch 'master' into ipv6 commit 512a43b Author: proller <proller@github.com> Date: Thu Jul 3 18:46:25 2014 +0400 Copypaste resolving functions from unix.c to win32.c commit dce98b9 Author: proller <proller@github.com> Date: Wed May 21 01:21:39 2014 +0400 ENET_IPV6 flag commit db8fb8c Author: proller <proller@github.com> Date: Wed May 21 00:25:51 2014 +0400 Try to add windows tcpip headers commit 28c5f1e Merge: 3963c69 06b535c Author: proller <proller@github.com> Date: Mon May 12 01:00:21 2014 +0400 Merge branch 'master' into ipv6 commit 3963c69 Merge: 3586b8a 47c8379 Author: proller <proller@github.com> Date: Mon May 12 00:56:06 2014 +0400 Merge remote-tracking branch 'origin/master' into ipv6 commit 3586b8a Author: proller <proller@github.com> Date: Thu Apr 10 23:50:10 2014 +0400 win32 convert, unfinished commit 3d27904 Author: proller <proller@github.com> Date: Thu Apr 10 23:20:32 2014 +0400 ipv6 support commit 54d2681 Author: proller <proller@github.com> Date: Thu Apr 10 22:56:28 2014 +0400 add CMakeLists.txt
1 parent 9ce6c59 commit c559551

File tree

6 files changed

+208
-109
lines changed

6 files changed

+208
-109
lines changed

host.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
4949
memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
5050

5151
host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
52+
if (host -> socket != ENET_SOCKET_NULL)
53+
enet_socket_set_option (host -> socket, ENET_SOCKOPT_IPV6_V6ONLY, 0);
5254
if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
5355
{
5456
if (host -> socket != ENET_SOCKET_NULL)
@@ -64,6 +66,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
6466
enet_socket_set_option (host -> socket, ENET_SOCKOPT_BROADCAST, 1);
6567
enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
6668
enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
69+
enet_socket_set_option (host -> socket, ENET_SOCKOPT_IPV6_V6ONLY, 0);
70+
6771

6872
if (address != NULL && enet_socket_get_address (host -> socket, & host -> address) < 0)
6973
host -> address = * address;
@@ -87,7 +91,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
8791
host -> commandCount = 0;
8892
host -> bufferCount = 0;
8993
host -> checksum = NULL;
90-
host -> receivedAddress.host = ENET_HOST_ANY;
94+
host -> receivedAddress.host = in6addr_any;
9195
host -> receivedAddress.port = 0;
9296
host -> receivedData = NULL;
9397
host -> receivedDataLength = 0;

include/enet/enet.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ typedef enum _ENetSocketOption
6262
ENET_SOCKOPT_RCVTIMEO = 6,
6363
ENET_SOCKOPT_SNDTIMEO = 7,
6464
ENET_SOCKOPT_ERROR = 8,
65-
ENET_SOCKOPT_NODELAY = 9
65+
ENET_SOCKOPT_NODELAY = 9,
66+
ENET_SOCKOPT_IPV6_V6ONLY = 10
6667
} ENetSocketOption;
6768

6869
typedef enum _ENetSocketShutdown
@@ -72,6 +73,7 @@ typedef enum _ENetSocketShutdown
7273
ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
7374
} ENetSocketShutdown;
7475

76+
#define ENET_IPV6 1
7577
#define ENET_HOST_ANY 0
7678
#define ENET_HOST_BROADCAST 0xFFFFFFFFU
7779
#define ENET_PORT_ANY 0
@@ -88,10 +90,13 @@ typedef enum _ENetSocketShutdown
8890
*/
8991
typedef struct _ENetAddress
9092
{
91-
enet_uint32 host;
93+
struct in6_addr host;
9294
enet_uint16 port;
95+
enet_uint16 sin6_scope_id;
9396
} ENetAddress;
9497

98+
#define in6_equal(in6_addr_a, in6_addr_b) (memcmp(&in6_addr_a, &in6_addr_b, sizeof(struct in6_addr)) == 0)
99+
95100
/**
96101
* Packet flag bit constants.
97102
*

include/enet/win32.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@
1414
#endif
1515
#endif
1616

17+
18+
#ifndef WIN32_LEAN_AND_MEAN
19+
#define WIN32_LEAN_AND_MEAN
20+
#endif
21+
#ifndef _WIN32_WINNT
22+
#define _WIN32_WINNT 0x0501
23+
#endif
24+
#ifndef NOMINMAX
25+
#define NOMINMAX
26+
#endif
1727
#include <stdlib.h>
1828
#include <winsock2.h>
1929
#include <windows.h>
30+
#include <ws2tcpip.h>
2031

2132
typedef SOCKET ENetSocket;
2233

protocol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
298298
}
299299
else
300300
if (currentPeer -> state != ENET_PEER_STATE_CONNECTING &&
301-
currentPeer -> address.host == host -> receivedAddress.host)
301+
in6_equal(currentPeer -> address.host , host -> receivedAddress.host))
302302
{
303303
if (currentPeer -> address.port == host -> receivedAddress.port &&
304304
currentPeer -> connectID == command -> connect.connectID)
@@ -1010,9 +1010,9 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
10101010

10111011
if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
10121012
peer -> state == ENET_PEER_STATE_ZOMBIE ||
1013-
((host -> receivedAddress.host != peer -> address.host ||
1013+
((!in6_equal(host -> receivedAddress.host , peer -> address.host) ||
10141014
host -> receivedAddress.port != peer -> address.port) &&
1015-
peer -> address.host != ENET_HOST_BROADCAST) ||
1015+
1 /* no broadcast in ipv6 !in6_equal(peer -> address.host , ENET_HOST_BROADCAST)*/) ||
10161016
(peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
10171017
sessionID != peer -> incomingSessionID))
10181018
return 0;

0 commit comments

Comments
 (0)