diff options
| author | Anton <anton@picapica> | 2019-03-09 19:46:44 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2019-03-09 19:46:44 +0400 |
| commit | b2adb74b429e279e76ce380cbb406d4089658d71 (patch) | |
| tree | 9759f6dc4e79730ab278a67b00739ce17382c3f9 /PICA_netconf.c | |
| parent | fa0b28ae592d4c70dff39a65833995c6cb182b95 (diff) | |
| download | pica-pica-b2adb74b429e279e76ce380cbb406d4089658d71.tar.gz pica-pica-b2adb74b429e279e76ce380cbb406d4089658d71.zip | |
implementation of PICA_guess_listening_addr_ipv4() for Winodws
Diffstat (limited to 'PICA_netconf.c')
| -rw-r--r-- | PICA_netconf.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/PICA_netconf.c b/PICA_netconf.c index 9c6f96b..d1dbb30 100644 --- a/PICA_netconf.c +++ b/PICA_netconf.c @@ -93,6 +93,31 @@ in_addr_t PICA_guess_listening_addr_ipv4() freeifaddrs(ifaddr); #else + char databuf[16384]; + ULONG size = sizeof databuf; + ULONG ret; + PIP_ADAPTER_ADDRESSES addrs = (PIP_ADAPTER_ADDRESSES)databuf; + PIP_ADAPTER_ADDRESSES ap; + + ret = GetAdaptersAddresses(AF_INET, + GAA_FLAG_SKIP_ANYCAST + | GAA_FLAG_SKIP_MULTICAST + | GAA_FLAG_SKIP_DNS_SERVER + | GAA_FLAG_SKIP_FRIENDLY_NAME, + NULL, + addrs, &size); + + if (ret != NO_ERROR) + return INADDR_ANY; + + ap = addrs; + while(ap) + { + retaddr = ((struct sockaddr_in*)ap->FirstUnicastAddress->Address.lpSockaddr)->sin_addr.s_addr; + if (!PICA_is_reserved_addr_ipv4(retaddr)) + break; + ap = ap->Next; + } #endif return retaddr; |
