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 | |
| parent | fa0b28ae592d4c70dff39a65833995c6cb182b95 (diff) | |
| download | pica-pica-b2adb74b429e279e76ce380cbb406d4089658d71.tar.gz pica-pica-b2adb74b429e279e76ce380cbb406d4089658d71.zip | |
implementation of PICA_guess_listening_addr_ipv4() for Winodws
| -rw-r--r-- | PICA_netconf.c | 25 | ||||
| -rw-r--r-- | configure.ac | 1 |
2 files changed, 26 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; diff --git a/configure.ac b/configure.ac index 622c701..b16e19c 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,7 @@ AS_CASE([$host], [*-w64-mingw*], [ AC_CHECK_LIB([ws2_32], [main], [LIBS="$LIBS -lws2_32"], []) AC_CHECK_LIB([winmm], [main], [LIBS="$LIBS -lwinmm"], []) + AC_CHECK_LIB([iphlpapi], [main], [LIBS="$LIBS -liphlpapi"]) ], [] ) |
