diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-04-05 15:53:19 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-04-05 15:53:19 -0700 |
commit | 504738b1839ca7f38ea4421dbe142a6192f6c2d4 (patch) | |
tree | 69f1e162fae8dda5b3c0bcc98adc1b7624880b43 /service | |
parent | 32cd2a02c90fdc90470d0fe30cca1e9a3facd855 (diff) | |
download | infinitytier-504738b1839ca7f38ea4421dbe142a6192f6c2d4.tar.gz infinitytier-504738b1839ca7f38ea4421dbe142a6192f6c2d4.zip |
Binder for Windows, and use Binder to get local interface addresses to advertise.
Diffstat (limited to 'service')
-rw-r--r-- | service/OneService.cpp | 79 |
1 files changed, 10 insertions, 69 deletions
diff --git a/service/OneService.cpp b/service/OneService.cpp index 4acf007b..3a1a1628 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -877,78 +877,19 @@ public: if ((now - lastLocalInterfaceAddressCheck) >= ZT_LOCAL_INTERFACE_CHECK_INTERVAL) { lastLocalInterfaceAddressCheck = now; - _node->clearLocalInterfaceAddresses(); -#ifdef ZT_USE_MINIUPNPC - if (_portMapper) { - std::vector<InetAddress> mappedAddresses(_portMapper->get()); - for(std::vector<InetAddress>::const_iterator ext(mappedAddresses.begin());ext!=mappedAddresses.end();++ext) - _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*ext))); - } -#endif + _node->clearLocalInterfaceAddresses(); -#ifdef __UNIX_LIKE__ - std::vector<std::string> ztDevices; - { - Mutex::Lock _l(_taps_m); - for(std::map< uint64_t,EthernetTap *>::const_iterator t(_taps.begin());t!=_taps.end();++t) - ztDevices.push_back(t->second->deviceName()); - } - struct ifaddrs *ifatbl = (struct ifaddrs *)0; - if ((getifaddrs(&ifatbl) == 0)&&(ifatbl)) { - struct ifaddrs *ifa = ifatbl; - while (ifa) { - if ((ifa->ifa_name)&&(ifa->ifa_addr)&&(!isBlacklistedLocalInterfaceForZeroTierTraffic(ifa->ifa_name))) { - bool isZT = false; - for(std::vector<std::string>::const_iterator d(ztDevices.begin());d!=ztDevices.end();++d) { - if (*d == ifa->ifa_name) { - isZT = true; - break; - } - } - if (!isZT) { - InetAddress ip(ifa->ifa_addr); - ip.setPort(_ports[0]); - _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&ip)); - } - } - ifa = ifa->ifa_next; - } - freeifaddrs(ifatbl); +#ifdef ZT_USE_MINIUPNPC + if (_portMapper) { + std::vector<InetAddress> mappedAddresses(_portMapper->get()); + for(std::vector<InetAddress>::const_iterator ext(mappedAddresses.begin());ext!=mappedAddresses.end();++ext) + _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*ext))); } -#endif // __UNIX_LIKE__ +#endif -#ifdef __WINDOWS__ - std::vector<NET_LUID> ztDevices; - { - Mutex::Lock _l(_taps_m); - for(std::map< uint64_t,EthernetTap *>::const_iterator t(_taps.begin());t!=_taps.end();++t) - ztDevices.push_back(t->second->luid()); - } - char aabuf[16384]; - ULONG aalen = sizeof(aabuf); - if (GetAdaptersAddresses(AF_UNSPEC,GAA_FLAG_SKIP_ANYCAST|GAA_FLAG_SKIP_MULTICAST|GAA_FLAG_SKIP_DNS_SERVER,(void *)0,reinterpret_cast<PIP_ADAPTER_ADDRESSES>(aabuf),&aalen) == NO_ERROR) { - PIP_ADAPTER_ADDRESSES a = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(aabuf); - while (a) { - bool isZT = false; - for(std::vector<NET_LUID>::const_iterator d(ztDevices.begin());d!=ztDevices.end();++d) { - if (a->Luid.Value == d->Value) { - isZT = true; - break; - } - } - if (!isZT) { - PIP_ADAPTER_UNICAST_ADDRESS ua = a->FirstUnicastAddress; - while (ua) { - InetAddress ip(ua->Address.lpSockaddr); - ip.setPort(_port); - _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&ip)); - ua = ua->Next; - } - } - a = a->Next; - } - } -#endif // __WINDOWS__ + std::vector<InetAddress> boundAddrs(_bindings[0].allBoundLocalInterfaceAddresses()); + for(std::vector<InetAddress>::const_iterator i(boundAddrs.begin());i!=boundAddrs.end();++i) + _node->addLocalInterfaceAddress(reinterpret_cast<const struct sockaddr_storage *>(&(*i))); } const unsigned long delay = (dl > now) ? (unsigned long)(dl - now) : 100; |