mirror of
https://github.com/moonlight-stream/Internet-Hosting-Tool.git
synced 2025-07-01 23:35:27 +00:00
Ignore ICMP Port Unreachable messages during STUN
This commit is contained in:
parent
cdbaa0aff3
commit
83360d775b
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user