| 883 | |
| 884 | #ifdef _WIN32 |
| 885 | static std::vector<INTERFACE_INFO> GetNetworkInterfaces() |
| 886 | { |
| 887 | InitialiseWSA(); |
| 888 | |
| 889 | int sock = socket(AF_INET, SOCK_DGRAM, 0); |
| 890 | if (sock == -1) |
| 891 | { |
| 892 | return {}; |
| 893 | } |
| 894 | |
| 895 | // Get all the network interfaces, requires a trial and error approach |
| 896 | // until we find the capacity required to store all of them. |
| 897 | DWORD len = 0; |
| 898 | size_t capacity = 16; |
| 899 | std::vector<INTERFACE_INFO> interfaces; |
| 900 | for (;;) |
| 901 | { |
| 902 | interfaces.resize(capacity); |
| 903 | if (WSAIoctl( |
| 904 | sock, SIO_GET_INTERFACE_LIST, nullptr, 0, interfaces.data(), |
| 905 | static_cast<DWORD>(capacity * sizeof(INTERFACE_INFO)), &len, nullptr, nullptr) |
| 906 | == 0) |
| 907 | { |
| 908 | break; |
| 909 | } |
| 910 | if (WSAGetLastError() != WSAEFAULT) |
| 911 | { |
| 912 | closesocket(sock); |
| 913 | return {}; |
| 914 | } |
| 915 | capacity *= 2; |
| 916 | } |
| 917 | interfaces.resize(len / sizeof(INTERFACE_INFO)); |
| 918 | interfaces.shrink_to_fit(); |
| 919 | return interfaces; |
| 920 | } |
| 921 | #endif |
| 922 | |
| 923 | std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses() |
no test coverage detected