| 60 | } |
| 61 | |
| 62 | static bool NatpmpDiscover(natpmp_t* natpmp, struct in_addr& external_ipv4_addr) |
| 63 | { |
| 64 | const int r_send = sendpublicaddressrequest(natpmp); |
| 65 | if (r_send == 2 /* OK */) { |
| 66 | int r_read; |
| 67 | natpmpresp_t response; |
| 68 | do { |
| 69 | r_read = readnatpmpresponseorretry(natpmp, &response); |
| 70 | } while (r_read == NATPMP_TRYAGAIN); |
| 71 | |
| 72 | if (r_read == 0) { |
| 73 | external_ipv4_addr = response.pnu.publicaddress.addr; |
| 74 | return true; |
| 75 | } else if (r_read == NATPMP_ERR_NOGATEWAYSUPPORT) { |
| 76 | LogPrintf("natpmp: The gateway does not support NAT-PMP.\n"); |
| 77 | } else { |
| 78 | LogPrintf("natpmp: readnatpmpresponseorretry() for public address failed with %d error.\n", r_read); |
| 79 | } |
| 80 | } else { |
| 81 | LogPrintf("natpmp: sendpublicaddressrequest() failed with %d error.\n", r_send); |
| 82 | } |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | static bool NatpmpMapping(natpmp_t* natpmp, const struct in_addr& external_ipv4_addr, uint16_t private_port, bool& external_ip_discovered) |
| 88 | { |