diff options
author | cepera <cepera@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
commit | 99e67b1db27953625d41d1f3eb45ff2517b4d697 (patch) | |
tree | e54d1799e55c6a3c58feb227f2a1f22aa07912c0 /util/network | |
parent | 28045de07753ee182fc8e5ca778469d7a7c5bb20 (diff) | |
download | ydb-99e67b1db27953625d41d1f3eb45ff2517b4d697.tar.gz |
Restoring authorship annotation for <cepera@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/address.h | 18 | ||||
-rw-r--r-- | util/network/interface.cpp | 50 | ||||
-rw-r--r-- | util/network/interface.h | 26 |
3 files changed, 47 insertions, 47 deletions
diff --git a/util/network/address.h b/util/network/address.h index 448fcac0c9..5b1cf10cd4 100644 --- a/util/network/address.h +++ b/util/network/address.h @@ -40,13 +40,13 @@ namespace NAddr { } inline TOpaqueAddr(const IRemoteAddr* addr) noexcept { - Assign(addr->Addr(), addr->Len()); + Assign(addr->Addr(), addr->Len()); } - inline TOpaqueAddr(const sockaddr* addr) { + inline TOpaqueAddr(const sockaddr* addr) { Assign(addr, SockAddrLength(addr)); - } - + } + const sockaddr* Addr() const override { return MutableAddr(); } @@ -65,11 +65,11 @@ namespace NAddr { private: inline void Assign(const sockaddr* addr, socklen_t len) noexcept { - L_ = len; - memcpy(MutableAddr(), addr, L_); - } - - private: + L_ = len; + memcpy(MutableAddr(), addr, L_); + } + + private: sockaddr_storage S_; socklen_t L_; }; diff --git a/util/network/interface.cpp b/util/network/interface.cpp index 256776c6d3..c207523181 100644 --- a/util/network/interface.cpp +++ b/util/network/interface.cpp @@ -1,28 +1,28 @@ -#include "interface.h" - +#include "interface.h" + #if defined(_unix_) #include <ifaddrs.h> -#endif - -#ifdef _win_ +#endif + +#ifdef _win_ #include <iphlpapi.h> #pragma comment(lib, "Iphlpapi.lib") -#endif - -namespace NAddr { +#endif + +namespace NAddr { static bool IsInetAddress(sockaddr* addr) { return (addr != nullptr) && ((addr->sa_family == AF_INET) || (addr->sa_family == AF_INET6)); } - + TNetworkInterfaceList GetNetworkInterfaces() { TNetworkInterfaceList result; - -#ifdef _win_ + +#ifdef _win_ TVector<char> buf; buf.resize(1000000); PIP_ADAPTER_ADDRESSES adapterBuf = (PIP_ADAPTER_ADDRESSES)&buf[0]; ULONG bufSize = buf.ysize(); - + if (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, adapterBuf, &bufSize) == ERROR_SUCCESS) { for (PIP_ADAPTER_ADDRESSES ptr = adapterBuf; ptr != 0; ptr = ptr->Next) { // The check below makes code working on Vista+ @@ -37,12 +37,12 @@ namespace NAddr { // ignore disable adapters continue; } - + for (IP_ADAPTER_UNICAST_ADDRESS* addr = ptr->FirstUnicastAddress; addr != 0; addr = addr->Next) { sockaddr* a = (sockaddr*)addr->Address.lpSockaddr; if (IsInetAddress(a)) { TNetworkInterface networkInterface; - + // Not very efficient but straightforward for (size_t i = 0; ptr->FriendlyName[i] != 0; i++) { CHAR w = ptr->FriendlyName[i]; @@ -52,11 +52,11 @@ namespace NAddr { networkInterface.Address = new TOpaqueAddr(a); result.push_back(networkInterface); - } - } - } - } -#else + } + } + } + } +#else ifaddrs* ifap; if (getifaddrs(&ifap) != -1) { for (ifaddrs* ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) { @@ -68,12 +68,12 @@ namespace NAddr { interface.Mask = new TOpaqueAddr(ifa->ifa_netmask); } result.push_back(interface); - } - } + } + } freeifaddrs(ifap); - } -#endif - + } +#endif + return result; } -} +} diff --git a/util/network/interface.h b/util/network/interface.h index dda4555021..7bee4f492b 100644 --- a/util/network/interface.h +++ b/util/network/interface.h @@ -1,17 +1,17 @@ -#pragma once - -#include "address.h" - -#include <util/generic/vector.h> - -namespace NAddr { - struct TNetworkInterface { +#pragma once + +#include "address.h" + +#include <util/generic/vector.h> + +namespace NAddr { + struct TNetworkInterface { TString Name; IRemoteAddrRef Address; IRemoteAddrRef Mask; - }; - + }; + using TNetworkInterfaceList = TVector<TNetworkInterface>; - - TNetworkInterfaceList GetNetworkInterfaces(); -} + + TNetworkInterfaceList GetNetworkInterfaces(); +} |