Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
021474cdd2 | ||
|
|
308cd0dd00 | ||
|
|
83360d775b |
+1
-1
Submodule GS-IPv6-Forwarder updated: 6fc14fa95e...665958b759
+27
-15
@@ -39,6 +39,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
|
|||||||
#define POLLING_DELAY_SEC 120
|
#define POLLING_DELAY_SEC 120
|
||||||
#define PORT_MAPPING_DURATION_SEC 3600
|
#define PORT_MAPPING_DURATION_SEC 3600
|
||||||
#define UPNP_DISCOVERY_DELAY_MS 5000
|
#define UPNP_DISCOVERY_DELAY_MS 5000
|
||||||
|
#define GAA_INITIAL_SIZE 8192
|
||||||
|
|
||||||
static struct port_entry {
|
static struct port_entry {
|
||||||
int proto;
|
int proto;
|
||||||
@@ -233,10 +234,7 @@ bool UPnPMapPort(struct UPNPUrls* urls, struct IGDdatas* data, int proto, const
|
|||||||
|
|
||||||
bool GetIP4OnLinkPrefixLength(char* lanAddressString, int* prefixLength)
|
bool GetIP4OnLinkPrefixLength(char* lanAddressString, int* prefixLength)
|
||||||
{
|
{
|
||||||
union {
|
PIP_ADAPTER_ADDRESSES addresses;
|
||||||
IP_ADAPTER_ADDRESSES addresses;
|
|
||||||
char buffer[8192];
|
|
||||||
};
|
|
||||||
ULONG error;
|
ULONG error;
|
||||||
ULONG length;
|
ULONG length;
|
||||||
PIP_ADAPTER_ADDRESSES currentAdapter;
|
PIP_ADAPTER_ADDRESSES currentAdapter;
|
||||||
@@ -245,22 +243,34 @@ bool GetIP4OnLinkPrefixLength(char* lanAddressString, int* prefixLength)
|
|||||||
|
|
||||||
inet_pton(AF_INET, lanAddressString, &targetAddress);
|
inet_pton(AF_INET, lanAddressString, &targetAddress);
|
||||||
|
|
||||||
// Get a list of all interfaces with IPv4 addresses on the system
|
addresses = NULL;
|
||||||
length = sizeof(buffer);
|
length = GAA_INITIAL_SIZE;
|
||||||
error = GetAdaptersAddresses(AF_INET,
|
do {
|
||||||
GAA_FLAG_SKIP_ANYCAST |
|
free(addresses);
|
||||||
GAA_FLAG_SKIP_MULTICAST |
|
addresses = (PIP_ADAPTER_ADDRESSES)malloc(length);
|
||||||
GAA_FLAG_SKIP_DNS_SERVER |
|
if (addresses == NULL) {
|
||||||
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
printf("malloc(%u) failed" NL, length);
|
||||||
NULL,
|
return false;
|
||||||
&addresses,
|
}
|
||||||
&length);
|
|
||||||
|
// Get a list of all interfaces with IPv4 addresses on the system
|
||||||
|
error = GetAdaptersAddresses(AF_INET,
|
||||||
|
GAA_FLAG_SKIP_ANYCAST |
|
||||||
|
GAA_FLAG_SKIP_MULTICAST |
|
||||||
|
GAA_FLAG_SKIP_DNS_SERVER |
|
||||||
|
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
||||||
|
NULL,
|
||||||
|
addresses,
|
||||||
|
&length);
|
||||||
|
} while (error == ERROR_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
if (error != ERROR_SUCCESS) {
|
if (error != ERROR_SUCCESS) {
|
||||||
printf("GetAdaptersAddresses() failed: %d" NL, error);
|
printf("GetAdaptersAddresses() failed: %d" NL, error);
|
||||||
|
free(addresses);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentAdapter = &addresses;
|
currentAdapter = addresses;
|
||||||
currentAddress = nullptr;
|
currentAddress = nullptr;
|
||||||
while (currentAdapter != nullptr) {
|
while (currentAdapter != nullptr) {
|
||||||
currentAddress = currentAdapter->FirstUnicastAddress;
|
currentAddress = currentAdapter->FirstUnicastAddress;
|
||||||
@@ -271,6 +281,7 @@ bool GetIP4OnLinkPrefixLength(char* lanAddressString, int* prefixLength)
|
|||||||
|
|
||||||
if (RtlEqualMemory(¤tAddrV4->sin_addr, &targetAddress, sizeof(targetAddress))) {
|
if (RtlEqualMemory(¤tAddrV4->sin_addr, &targetAddress, sizeof(targetAddress))) {
|
||||||
*prefixLength = currentAddress->OnLinkPrefixLength;
|
*prefixLength = currentAddress->OnLinkPrefixLength;
|
||||||
|
free(addresses);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +292,7 @@ bool GetIP4OnLinkPrefixLength(char* lanAddressString, int* prefixLength)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("No adapter found with IPv4 address: %s" NL, lanAddressString);
|
printf("No adapter found with IPv4 address: %s" NL, lanAddressString);
|
||||||
|
free(addresses);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+55
-32
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#define LOOPBACK_SERVER_PORT_OFFSET -10000
|
#define LOOPBACK_SERVER_PORT_OFFSET -10000
|
||||||
|
|
||||||
|
#define GAA_INITIAL_SIZE 8192
|
||||||
|
|
||||||
static struct port_entry {
|
static struct port_entry {
|
||||||
int proto;
|
int proto;
|
||||||
int port;
|
int port;
|
||||||
@@ -864,31 +866,40 @@ bool FindLocalInterfaceIPAddress(int family, PSOCKADDR_STORAGE addr)
|
|||||||
|
|
||||||
bool FindZeroTierInterfaceAddress(PSOCKADDR_STORAGE addr)
|
bool FindZeroTierInterfaceAddress(PSOCKADDR_STORAGE addr)
|
||||||
{
|
{
|
||||||
union {
|
PIP_ADAPTER_ADDRESSES addresses;
|
||||||
IP_ADAPTER_ADDRESSES addresses;
|
|
||||||
char buffer[8192];
|
|
||||||
};
|
|
||||||
ULONG error;
|
ULONG error;
|
||||||
ULONG length;
|
ULONG length;
|
||||||
PIP_ADAPTER_ADDRESSES currentAdapter;
|
PIP_ADAPTER_ADDRESSES currentAdapter;
|
||||||
PIP_ADAPTER_UNICAST_ADDRESS currentAddress;
|
PIP_ADAPTER_UNICAST_ADDRESS currentAddress;
|
||||||
|
|
||||||
// Get all IPv4 interfaces
|
addresses = NULL;
|
||||||
length = sizeof(buffer);
|
length = GAA_INITIAL_SIZE;
|
||||||
error = GetAdaptersAddresses(AF_INET,
|
do {
|
||||||
GAA_FLAG_SKIP_ANYCAST |
|
free(addresses);
|
||||||
GAA_FLAG_SKIP_MULTICAST |
|
addresses = (PIP_ADAPTER_ADDRESSES)malloc(length);
|
||||||
GAA_FLAG_SKIP_DNS_SERVER |
|
if (addresses == NULL) {
|
||||||
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
fprintf(LOG_OUT, "malloc(%u) failed\n", length);
|
||||||
NULL,
|
return false;
|
||||||
&addresses,
|
}
|
||||||
&length);
|
|
||||||
|
// Get all IPv4 interfaces
|
||||||
|
error = GetAdaptersAddresses(AF_INET,
|
||||||
|
GAA_FLAG_SKIP_ANYCAST |
|
||||||
|
GAA_FLAG_SKIP_MULTICAST |
|
||||||
|
GAA_FLAG_SKIP_DNS_SERVER |
|
||||||
|
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
||||||
|
NULL,
|
||||||
|
addresses,
|
||||||
|
&length);
|
||||||
|
} while (error == ERROR_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
if (error != ERROR_SUCCESS) {
|
if (error != ERROR_SUCCESS) {
|
||||||
fprintf(LOG_OUT, "GetAdaptersAddresses() failed: %d\n", error);
|
fprintf(LOG_OUT, "GetAdaptersAddresses() failed: %d\n", error);
|
||||||
|
free(addresses);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentAdapter = &addresses;
|
currentAdapter = addresses;
|
||||||
while (currentAdapter != NULL) {
|
while (currentAdapter != NULL) {
|
||||||
// Look for ones that correspond to a ZeroTier device
|
// Look for ones that correspond to a ZeroTier device
|
||||||
if (wcsstr(currentAdapter->Description, L"ZeroTier")) {
|
if (wcsstr(currentAdapter->Description, L"ZeroTier")) {
|
||||||
@@ -897,6 +908,7 @@ bool FindZeroTierInterfaceAddress(PSOCKADDR_STORAGE addr)
|
|||||||
while (currentAddress != NULL) {
|
while (currentAddress != NULL) {
|
||||||
if (currentAddress->Address.lpSockaddr->sa_family == AF_INET) {
|
if (currentAddress->Address.lpSockaddr->sa_family == AF_INET) {
|
||||||
RtlCopyMemory(addr, currentAddress->Address.lpSockaddr, currentAddress->Address.iSockaddrLength);
|
RtlCopyMemory(addr, currentAddress->Address.lpSockaddr, currentAddress->Address.iSockaddrLength);
|
||||||
|
free(addresses);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,15 +919,13 @@ bool FindZeroTierInterfaceAddress(PSOCKADDR_STORAGE addr)
|
|||||||
currentAdapter = currentAdapter->Next;
|
currentAdapter = currentAdapter->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(addresses);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FindDuplicateDefaultInterfaces(void)
|
bool FindDuplicateDefaultInterfaces(void)
|
||||||
{
|
{
|
||||||
union {
|
PIP_ADAPTER_ADDRESSES addresses;
|
||||||
IP_ADAPTER_ADDRESSES addresses;
|
|
||||||
char buffer[8192];
|
|
||||||
};
|
|
||||||
ULONG error;
|
ULONG error;
|
||||||
ULONG length;
|
ULONG length;
|
||||||
MIB_IPFORWARDROW defaultRoute;
|
MIB_IPFORWARDROW defaultRoute;
|
||||||
@@ -928,24 +938,36 @@ bool FindDuplicateDefaultInterfaces(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all IPv4 interfaces
|
addresses = NULL;
|
||||||
length = sizeof(buffer);
|
length = GAA_INITIAL_SIZE;
|
||||||
error = GetAdaptersAddresses(AF_INET,
|
do {
|
||||||
GAA_FLAG_SKIP_UNICAST |
|
free(addresses);
|
||||||
GAA_FLAG_SKIP_ANYCAST |
|
addresses = (PIP_ADAPTER_ADDRESSES)malloc(length);
|
||||||
GAA_FLAG_SKIP_MULTICAST |
|
if (addresses == NULL) {
|
||||||
GAA_FLAG_SKIP_DNS_SERVER |
|
fprintf(LOG_OUT, "malloc(%u) failed\n", length);
|
||||||
GAA_FLAG_INCLUDE_GATEWAYS |
|
return false;
|
||||||
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
}
|
||||||
NULL,
|
|
||||||
&addresses,
|
// Get all IPv4 interfaces
|
||||||
&length);
|
error = GetAdaptersAddresses(AF_INET,
|
||||||
|
GAA_FLAG_SKIP_UNICAST |
|
||||||
|
GAA_FLAG_SKIP_ANYCAST |
|
||||||
|
GAA_FLAG_SKIP_MULTICAST |
|
||||||
|
GAA_FLAG_SKIP_DNS_SERVER |
|
||||||
|
GAA_FLAG_INCLUDE_GATEWAYS |
|
||||||
|
GAA_FLAG_SKIP_FRIENDLY_NAME,
|
||||||
|
NULL,
|
||||||
|
addresses,
|
||||||
|
&length);
|
||||||
|
} while (error == ERROR_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
if (error != ERROR_SUCCESS) {
|
if (error != ERROR_SUCCESS) {
|
||||||
fprintf(LOG_OUT, "GetAdaptersAddresses() failed: %d\n", error);
|
fprintf(LOG_OUT, "GetAdaptersAddresses() failed: %d\n", error);
|
||||||
|
free(addresses);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentAdapter = &addresses;
|
currentAdapter = addresses;
|
||||||
while (currentAdapter != NULL) {
|
while (currentAdapter != NULL) {
|
||||||
if (currentAdapter->OperStatus == IfOperStatusUp &&
|
if (currentAdapter->OperStatus == IfOperStatusUp &&
|
||||||
currentAdapter->FirstGatewayAddress != NULL &&
|
currentAdapter->FirstGatewayAddress != NULL &&
|
||||||
@@ -958,6 +980,7 @@ bool FindDuplicateDefaultInterfaces(void)
|
|||||||
currentAdapter = currentAdapter->Next;
|
currentAdapter = currentAdapter->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(addresses);
|
||||||
return matchingInterfaces > 1;
|
return matchingInterfaces > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+26
-18
@@ -100,29 +100,37 @@ bool getExternalAddressPortIP4(unsigned short localPort, PSOCKADDR_IN wanAddr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_set fds;
|
for (;;) {
|
||||||
FD_ZERO(&fds);
|
fd_set fds;
|
||||||
FD_SET(sock, &fds);
|
FD_ZERO(&fds);
|
||||||
|
FD_SET(sock, &fds);
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
int selectRes = select(0, &fds, nullptr, nullptr, &tv);
|
int selectRes = select(0, &fds, nullptr, nullptr, &tv);
|
||||||
if (selectRes == 0) {
|
if (selectRes == 0) {
|
||||||
// Timeout - continue looping
|
// Timeout - break to the enclosing loop
|
||||||
continue;
|
break;
|
||||||
|
}
|
||||||
|
else if (selectRes == SOCKET_ERROR) {
|
||||||
|
fprintf(LOG_OUT, "select() failed: %d\n", WSAGetLastError());
|
||||||
|
goto Exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// recvfrom() will return WSAECONNRESET if the socket has received an ICMP Port Unreachable
|
||||||
|
// message from one of the IP addresses we've attempted communication with. The socket is still
|
||||||
|
// operable (and may even contain queued messages to receive). We should ignore that error and
|
||||||
|
// continue reading, otherwise exit the loop.
|
||||||
|
bytesRead = recvfrom(sock, resp.buf, sizeof(resp.buf), 0, NULL, NULL);
|
||||||
|
if (bytesRead != SOCKET_ERROR || WSAGetLastError() != WSAECONNRESET) {
|
||||||
|
goto RecvDone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (selectRes == SOCKET_ERROR) {
|
|
||||||
fprintf(LOG_OUT, "select() failed: %d\n", WSAGetLastError());
|
|
||||||
goto Exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error handling is below
|
|
||||||
bytesRead = recvfrom(sock, resp.buf, sizeof(resp.buf), 0, NULL, NULL);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RecvDone:
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
fprintf(LOG_OUT, "No response from STUN server\n");
|
fprintf(LOG_OUT, "No response from STUN server\n");
|
||||||
goto Exit;
|
goto Exit;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VER_VERSION 5,3,1,0
|
#define VER_VERSION 5,4,0,0
|
||||||
#define VER_VERSION_STR "5.3.1.0"
|
#define VER_VERSION_STR "5.4.0.0"
|
||||||
|
|
||||||
#define VER_COMPANYNAME_STR "Moonlight Game Streaming Project"
|
#define VER_COMPANYNAME_STR "Moonlight Game Streaming Project"
|
||||||
#define VER_PRODUCTNAME_STR "Moonlight Internet Hosting Tool"
|
#define VER_PRODUCTNAME_STR "Moonlight Internet Hosting Tool"
|
||||||
|
|||||||
Reference in New Issue
Block a user