24 void GetDefaultAdapters(
int family, ifaddrs* pList, ifaddrs** ppAddrPrimary, ifaddrs** ppAddrAlternate)
26 ifaddrs* pAdapter = NULL;
28 *ppAddrPrimary = NULL;
29 *ppAddrAlternate = NULL;
34 if ( (pAdapter->ifa_addr != NULL) && (pAdapter->ifa_addr->sa_family == family) && (pAdapter->ifa_flags & IFF_UP) && !(pAdapter->ifa_flags & IFF_LOOPBACK))
36 if (*ppAddrPrimary == NULL)
38 *ppAddrPrimary = pAdapter;
42 *ppAddrAlternate = pAdapter;
46 pAdapter = pAdapter->ifa_next;
58 ifaddrs* pList = NULL;
59 ifaddrs* pAdapter1 = NULL;
60 ifaddrs* pAdapter2 = NULL;
67 fRet = (pAdapter1 && pAdapter2);
86 ifaddrs* pList = NULL;
87 ifaddrs* pAdapter = NULL;
88 ifaddrs* pAdapter1 = NULL;
89 ifaddrs* pAdapter2 = NULL;
97 pAdapter = fPrimary ? pAdapter1 : pAdapter2;
114 ifaddrs* pList = NULL;
115 ifaddrs* pAdapter = NULL;
116 ifaddrs* pAdapterFound = NULL;
130 if ((pAdapter->ifa_addr != NULL) && (pAdapter->ifa_name != NULL) && (family == pAdapter->ifa_addr->sa_family))
132 if (strcmp(pAdapter->ifa_name, pszAdapterName) == 0)
134 pAdapterFound = pAdapter;
138 pAdapter = pAdapter->ifa_next;
145 if ((pAdapterFound == NULL) && ((family == AF_INET) || (family == AF_INET6)) )
147 uint8_t addrbytes[
sizeof(in6_addr)] = {};
148 int comparesize = (family == AF_INET) ?
sizeof(in_addr) :
sizeof(in6_addr);
152 if (inet_pton(family, pszAdapterName, addrbytes) == 1)
157 if ((pAdapter->ifa_addr != NULL) && (family == pAdapter->ifa_addr->sa_family))
162 if (family == AF_INET)
164 sockaddr_in *pAddr4 = (sockaddr_in*)(pAdapter->ifa_addr);
165 pCmp = &(pAddr4->sin_addr);
169 sockaddr_in6 *pAddr6 = (sockaddr_in6*)(pAdapter->ifa_addr);
170 pCmp = &(pAddr6->sin6_addr);
173 if (memcmp(pCmp, addrbytes, comparesize) == 0)
176 pAdapterFound = pAdapter;
180 pAdapter = pAdapter->ifa_next;
void GetDefaultAdapters(int family, ifaddrs *pList, ifaddrs **ppAddrPrimary, ifaddrs **ppAddrAlternate)
#define ChkIf(expr, hrerror)
HRESULT GetSocketAddressForAdapter(int family, const char *pszAdapterName, uint16_t port, CSocketAddress *pSocketAddr)
HRESULT GetBestAddressForSocketBind(bool fPrimary, int family, uint16_t port, CSocketAddress *pSocketAddr)
bool HasAtLeastTwoAdapters(int family)
#define ChkIfA(expr, hrerror)