Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yet another Ipv6 patch #51

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions include/enet/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions include/enet/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdlib.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>

typedef SOCKET ENetSocket;

Expand Down
6 changes: 3 additions & 3 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
Loading