Only pass the peer's local address if the host was wildcard bound
This commit is contained in:
@@ -61,6 +61,8 @@ enet_host_create (int addressFamily, const ENetAddress * address, size_t peerCou
|
||||
return NULL;
|
||||
}
|
||||
|
||||
host -> wildcardBind = address && enet_address_wildcard (address);
|
||||
|
||||
enet_socket_set_option (host -> socket, ENET_SOCKOPT_NONBLOCK, 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);
|
||||
|
||||
@@ -364,6 +364,7 @@ typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, st
|
||||
typedef struct _ENetHost
|
||||
{
|
||||
ENetSocket socket;
|
||||
int wildcardBind;
|
||||
ENetAddress address; /**< Internet address of the host */
|
||||
enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
|
||||
enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
|
||||
@@ -527,6 +528,7 @@ ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSock
|
||||
ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);
|
||||
ENET_API int enet_address_set_address (ENetAddress * address, struct sockaddr * addr, socklen_t addrlen);
|
||||
ENET_API int enet_address_set_port (ENetAddress * address, enet_uint16 port);
|
||||
ENET_API int enet_address_wildcard (const ENetAddress * address);
|
||||
ENET_API int enet_address_equal (ENetAddress * address1, ENetAddress * address2);
|
||||
|
||||
/** @} */
|
||||
|
||||
+3
-1
@@ -1731,7 +1731,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
|
||||
enet_socket_set_option (host -> socket, ENET_SOCKOPT_QOS, 0);
|
||||
}
|
||||
|
||||
sentLength = enet_socket_send (host -> socket, & currentPeer -> address, & currentPeer -> localAddress, host -> buffers, host -> bufferCount);
|
||||
sentLength = enet_socket_send (host -> socket, & currentPeer -> address,
|
||||
host -> wildcardBind ? (& currentPeer -> localAddress) : NULL,
|
||||
host -> buffers, host -> bufferCount);
|
||||
|
||||
enet_protocol_remove_sent_unreliable_commands (currentPeer, & sentUnreliableCommands);
|
||||
|
||||
|
||||
@@ -269,6 +269,30 @@ enet_address_equal (ENetAddress * address1, ENetAddress * address2)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
enet_address_wildcard (const ENetAddress * address)
|
||||
{
|
||||
switch (address -> address.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
{
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *) & address -> address;
|
||||
return sin -> sin_addr.s_addr == INADDR_ANY;
|
||||
}
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
{
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) & address -> address;
|
||||
return ! memcmp (& sin6 -> sin6_addr, & in6addr_any, sizeof (in6addr_any));
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
enet_address_set_port (ENetAddress * address, enet_uint16 port)
|
||||
{
|
||||
|
||||
@@ -190,6 +190,28 @@ enet_address_equal (ENetAddress * address1, ENetAddress * address2)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
enet_address_wildcard (const ENetAddress * address)
|
||||
{
|
||||
switch (address -> address.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
{
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *) & address -> address;
|
||||
return sin -> sin_addr.S_un.S_addr == INADDR_ANY;
|
||||
}
|
||||
case AF_INET6:
|
||||
{
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) & address -> address;
|
||||
return ! memcmp (& sin6 -> sin6_addr, & in6addr_any, sizeof (in6addr_any));
|
||||
}
|
||||
default:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
enet_address_set_host (ENetAddress * address, const char * name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user