Skip to content

Commit 5de4a5b

Browse files
committed
Bind the control stream socket to the local address used for other UDP traffic
1 parent bbf15af commit 5de4a5b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/ControlStream.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -1592,16 +1592,21 @@ int startControlStream(void) {
15921592
int err;
15931593

15941594
if (AppVersionQuad[0] >= 5) {
1595-
ENetAddress address;
1595+
ENetAddress remoteAddress, localAddress;
15961596
ENetEvent event;
15971597

15981598
LC_ASSERT(ControlPortNumber != 0);
15991599

1600-
enet_address_set_address(&address, (struct sockaddr *)&RemoteAddr, AddrLen);
1601-
enet_address_set_port(&address, ControlPortNumber);
1600+
enet_address_set_address(&localAddress, (struct sockaddr *)&LocalAddr, AddrLen);
1601+
enet_address_set_port(&localAddress, 0); // Wildcard port
1602+
1603+
enet_address_set_address(&remoteAddress, (struct sockaddr *)&RemoteAddr, AddrLen);
1604+
enet_address_set_port(&remoteAddress, ControlPortNumber);
16021605

16031606
// Create a client
1604-
client = enet_host_create(address.address.ss_family, NULL, 1, CTRL_CHANNEL_COUNT, 0, 0);
1607+
client = enet_host_create(RemoteAddr.ss_family,
1608+
LocalAddr.ss_family != 0 ? &localAddress : NULL,
1609+
1, CTRL_CHANNEL_COUNT, 0, 0);
16051610
if (client == NULL) {
16061611
stopping = true;
16071612
return -1;
@@ -1616,7 +1621,7 @@ int startControlStream(void) {
16161621
enet_socket_set_option (client->socket, ENET_SOCKOPT_QOS, 1);
16171622

16181623
// Connect to the host
1619-
peer = enet_host_connect(client, &address, CTRL_CHANNEL_COUNT, 0);
1624+
peer = enet_host_connect(client, &remoteAddress, CTRL_CHANNEL_COUNT, 0);
16201625
if (peer == NULL) {
16211626
stopping = true;
16221627
enet_host_destroy(client);

0 commit comments

Comments
 (0)