#include <winsock2.h>
#include <wspiapi.h>
+#include <iphlpapi.h>
#include <windows.h>
#include <io.h>
#include <assert.h>
} /* }}} int lcc_server_set_ttl */
#if WIN32
-int lcc_server_set_interface (lcc_server_t *srv, char const *ifname) /* {{{ */
+static unsigned if_nametoindex (LPCSTR pszIfName) /* {{{ */
{
- return (-1);
-} /* }}} int lcc_server_set_interface */
-#else
+ IP_ADAPTER_ADDRESSES *pAddrList;
+ IP_ADAPTER_ADDRESSES *pAddrPtr;
+ BYTE bBuffer[8192];
+ ULONG dwSize;
+ ULONG dwStatus;
+ unsigned dwIndex = 0;
+
+ dwSize = (ULONG) sizeof (bBuffer);
+ pAddrList = (IP_ADAPTER_ADDRESSES *) &bBuffer[0];
+
+ dwStatus = GetAdaptersAddresses (
+ /* Family = */ AF_UNSPEC,
+ /* Flags = */ GAA_FLAG_SKIP_ANYCAST,
+ /* Reserved = */ NULL,
+ /* AdapterAddresses = */ pAddrList,
+ /* SizePointer = */ &dwSize);
+ if (dwStatus != ERROR_SUCCESS)
+ return (0);
+
+ for (pAddrPtr = pAddrList;
+ pAddrPtr != NULL;
+ pAddrPtr = pAddrPtr->Next)
+ {
+ if (strcmp (pszIfName, pAddrPtr->AdapterName) != 0)
+ continue;
+
+ dwIndex = (unsigned) pAddrPtr->IfIndex;
+ break;
+ }
+
+ return (dwIndex);
+} /* }}} unsigned if_nametoindex */
+#endif /* WIN32 */
+
int lcc_server_set_interface (lcc_server_t *srv, char const *ifname) /* {{{ */
{
int if_index;
return (0);
} /* }}} int lcc_server_set_interface */
-#endif /* !WIN32 */
int lcc_server_set_security_level (lcc_server_t *srv, /* {{{ */
lcc_security_level_t level,