mirror of
https://github.com/moonlight-stream/Internet-Hosting-Tool.git
synced 2025-07-03 00:06:11 +00:00
Wait for the NAT-PMP response when deleting a conflicting entry
This commit is contained in:
parent
d379a4ee74
commit
1b8f15e259
@ -417,9 +417,42 @@ bool NATPMPMapPort(natpmp_t* natpmp, int proto, int port, bool enable)
|
|||||||
|
|
||||||
// It couldn't assign us the external port we requested and gave us an alternate external port.
|
// It couldn't assign us the external port we requested and gave us an alternate external port.
|
||||||
// We can't use this alternate mapping, so immediately release it.
|
// We can't use this alternate mapping, so immediately release it.
|
||||||
sendnewportmappingrequest(natpmp, natPmpProto, response.pnu.newportmapping.privateport, 0, 0);
|
printf("Deleting unwanted NAT-PMP mapping %s %d...", proto == IPPROTO_TCP ? "TCP" : "UDP", response.pnu.newportmapping.mappedpublicport);
|
||||||
|
err = sendnewportmappingrequest(natpmp, natPmpProto, response.pnu.newportmapping.privateport, 0, 0);
|
||||||
|
if (err < 0) {
|
||||||
|
printf("ERROR %d" NL, err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
do {
|
||||||
|
fd_set fds;
|
||||||
|
struct timeval timeout;
|
||||||
|
|
||||||
|
FD_ZERO(&fds);
|
||||||
|
FD_SET(natpmp->s, &fds);
|
||||||
|
|
||||||
|
err = getnatpmprequesttimeout(natpmp, &timeout);
|
||||||
|
if (err != 0) {
|
||||||
|
assert(err == 0);
|
||||||
|
printf("WAIT FAILED: %d" NL, err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
select(0, &fds, nullptr, nullptr, &timeout);
|
||||||
|
|
||||||
|
err = readnatpmpresponseorretry(natpmp, &response);
|
||||||
|
} while (err == NATPMP_TRYAGAIN);
|
||||||
|
|
||||||
|
if (err == 0) {
|
||||||
|
printf("DONE" NL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("FAILED %d" NL, err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
printf("OK (%d seconds remaining)" NL, response.pnu.newportmapping.lifetime);
|
printf("OK (%d seconds remaining)" NL, response.pnu.newportmapping.lifetime);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user