Add support for PCP on the first hop

This commit is contained in:
Cameron Gutman
2018-11-20 18:09:28 -08:00
parent 5840e39e94
commit c7565256b5
2 changed files with 31 additions and 5 deletions

View File

@@ -160,6 +160,17 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
return false;
}
// If we didn't get a local address, use the address of the interface we bound to.
// NB: We can't do this in all cases because we may be impersonating an upstream
// device if we're behind multiple NATs.
if (localAddr->ss_family == AF_INET && ((PSOCKADDR_IN)localAddr)->sin_addr.S_un.S_addr == 0) {
if (getsockname(sock, (struct sockaddr*)localAddr, &localAddrLen) == SOCKET_ERROR) {
printf("getsockname() failed: %d\n", WSAGetLastError());
closesocket(sock);
return false;
}
}
reqMsg = {};
reqMsg.hdr.version = PCP_VERSION;
reqMsg.hdr.opcode = OPCODE_MAP_REQUEST;