mirror of
https://github.com/moonlight-stream/Internet-Hosting-Tool.git
synced 2026-06-18 14:41:04 +00:00
Several minor bugfixes from final pre-release testing
This commit is contained in:
+15
-5
@@ -711,9 +711,13 @@ void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* inte
|
|||||||
// Don't try with NAT-PMP if the UPnP attempt for the same gateway failed due to being
|
// Don't try with NAT-PMP if the UPnP attempt for the same gateway failed due to being
|
||||||
// disconnected or some other error. This will avoid overwriting UPnP rules on a disconnected IGD
|
// disconnected or some other error. This will avoid overwriting UPnP rules on a disconnected IGD
|
||||||
// with duplicate NAT-PMP rules. We want to allow deletion of NAT-PMP rules in any case though.
|
// with duplicate NAT-PMP rules. We want to allow deletion of NAT-PMP rules in any case though.
|
||||||
if (tryNatPmp && enable && !strcmp(upstreamAddrNatPmp, upstreamAddrUPnP)) {
|
if (enable && !strcmp(upstreamAddrNatPmp, upstreamAddrUPnP)) {
|
||||||
printf("Not attempting to use NAT-PMP to talk to the same UPnP gateway\n");
|
printf("Not attempting to use NAT-PMP/PCP to talk to the same UPnP gateway\n");
|
||||||
tryNatPmp = false;
|
tryNatPmp = false;
|
||||||
|
|
||||||
|
// We have both UPnP and NAT-PMP on the same upstream gateway, so let's
|
||||||
|
// assume PCP is on the same box too.
|
||||||
|
tryPcp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryNatPmp) {
|
if (tryNatPmp) {
|
||||||
@@ -737,9 +741,14 @@ void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* inte
|
|||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
printf("NAT-PMP IPv4 port mapping successful" NL);
|
printf("NAT-PMP IPv4 port mapping successful" NL);
|
||||||
|
|
||||||
|
// Always try all possibilities when disabling to ensure
|
||||||
|
// we completely clean up
|
||||||
|
if (enable) {
|
||||||
tryPcp = false;
|
tryPcp = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
closenatpmp(&natpmp);
|
closenatpmp(&natpmp);
|
||||||
}
|
}
|
||||||
@@ -835,8 +844,9 @@ void UpdatePortMappings(bool enable)
|
|||||||
printf("Found %d hops" NL, hopCount);
|
printf("Found %d hops" NL, hopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start at hop 1 since we don't want to count the default gateway
|
// getHopsIP4() already skips the default gateway, so 0
|
||||||
int nextHopIndex = 1;
|
// is actually the first hop after the default gateway
|
||||||
|
int nextHopIndex = 0;
|
||||||
|
|
||||||
// Start by probing for the default gateway
|
// Start by probing for the default gateway
|
||||||
UpdatePortMappingsForTarget(enable, nullptr, nullptr, upstreamAddrStr);
|
UpdatePortMappingsForTarget(enable, nullptr, nullptr, upstreamAddrStr);
|
||||||
@@ -990,7 +1000,7 @@ HandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpConte
|
|||||||
ServiceStatus.dwControlsAccepted = 0;
|
ServiceStatus.dwControlsAccepted = 0;
|
||||||
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
||||||
|
|
||||||
printf("Removing UPnP/NAT-PMP rules after service stop request\n");
|
printf("Removing UPnP/NAT-PMP/PCP rules after service stop request\n");
|
||||||
UpdatePortMappings(false);
|
UpdatePortMappings(false);
|
||||||
|
|
||||||
printf("The service is stopping\n");
|
printf("The service is stopping\n");
|
||||||
|
|||||||
+2
-2
@@ -188,7 +188,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
|
|||||||
// This must be done after the rest of the message is populated
|
// This must be done after the rest of the message is populated
|
||||||
populateMappingNonce(&reqMsg, pcpAddr, pcpAddrLen);
|
populateMappingNonce(&reqMsg, pcpAddr, pcpAddrLen);
|
||||||
|
|
||||||
bytesRead = SOCKET_ERROR;
|
bytesRead = 0;
|
||||||
for (i = 0; i < RECV_TIMEOUT_SEC; i++) {
|
for (i = 0; i < RECV_TIMEOUT_SEC; i++) {
|
||||||
// Retransmit the request every second until the timeout elapses
|
// Retransmit the request every second until the timeout elapses
|
||||||
if (send(sock, (char *)&reqMsg, reqMsgLen, 0) == SOCKET_ERROR) {
|
if (send(sock, (char *)&reqMsg, reqMsgLen, 0) == SOCKET_ERROR) {
|
||||||
@@ -222,7 +222,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
printf("No response from PCP server\n");
|
printf("NO RESPONSE\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else if (bytesRead == SOCKET_ERROR) {
|
else if (bytesRead == SOCKET_ERROR) {
|
||||||
|
|||||||
+9
-6
@@ -157,6 +157,9 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
|
|||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start at TTL 2 to skip contacting our default gateway
|
||||||
|
#define TTL_START 2
|
||||||
|
|
||||||
bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
|
bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
|
||||||
{
|
{
|
||||||
HANDLE icmpFile;
|
HANDLE icmpFile;
|
||||||
@@ -179,8 +182,8 @@ bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ttl = 1;
|
int ttl;
|
||||||
for (; ttl < *hopAddressCount; ttl++)
|
for (ttl = TTL_START; ttl - TTL_START < *hopAddressCount; ttl++)
|
||||||
{
|
{
|
||||||
IP_OPTION_INFORMATION ipOptions;
|
IP_OPTION_INFORMATION ipOptions;
|
||||||
|
|
||||||
@@ -206,19 +209,19 @@ bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
|
|||||||
|
|
||||||
if (replies[0].Status == IP_TTL_EXPIRED_TRANSIT) {
|
if (replies[0].Status == IP_TTL_EXPIRED_TRANSIT) {
|
||||||
// Get the IP address that responded to us
|
// Get the IP address that responded to us
|
||||||
printf("Hop %d: %s\n", ttl, inet_ntoa(*(IN_ADDR*)&replies[0].Address));
|
printf("Hop %d: %s\n", ttl - TTL_START, inet_ntoa(*(IN_ADDR*)&replies[0].Address));
|
||||||
hopAddress[ttl - 1] = *(IN_ADDR*)&replies[0].Address;
|
hopAddress[ttl - TTL_START] = *(IN_ADDR*)&replies[0].Address;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Bail on anything else
|
// Bail on anything else
|
||||||
printf("Hop %d: %s (error %d)\n", ttl, inet_ntoa(*(IN_ADDR*)&replies[0].Address), replies[0].Status);
|
printf("Hop %d: %s (error %d)\n", ttl - TTL_START, inet_ntoa(*(IN_ADDR*)&replies[0].Address), replies[0].Status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IcmpCloseHandle(icmpFile);
|
IcmpCloseHandle(icmpFile);
|
||||||
|
|
||||||
*hopAddressCount = ttl - 1;
|
*hopAddressCount = ttl - TTL_START;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user