diff --git a/include/network_interface.h b/include/network_interface.h index ac824df..7ed5ba1 100644 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -106,7 +106,11 @@ public: /** * \brief Retrieves this interface's name. - * + * + * This name can be used as the interface name provided to the + * Sniffer class when starting a sniffing session. + * + * \sa Sniffer * \return std::string containing this interface's name. */ std::string name() const; diff --git a/src/network_interface.cpp b/src/network_interface.cpp index c919a3e..5e34620 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -43,6 +43,7 @@ #include #else #include + #include #endif #include "network_interface.h" #include "utils.h" @@ -169,7 +170,19 @@ std::string NetworkInterface::name() const { throw std::runtime_error("Error fetching this interface's name"); return iface_name; #else // WIN32 - return "Not implemented"; + ULONG size; + ::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size); + std::vector buffer(size); + if (::GetAdaptersAddresses(AF_INET, 0, 0, (IP_ADAPTER_ADDRESSES *)&buffer[0], &size) == ERROR_SUCCESS) { + PIP_ADAPTER_ADDRESSES iface = (IP_ADAPTER_ADDRESSES *)&buffer[0]; + while (iface) { + if (iface->IfIndex == iface_id) { + return std::string("\\Device\\NPF_") + iface->AdapterName; + } + iface = iface->Next; + } + } + throw std::runtime_error("Failed to find interface name"); #endif // WIN32 }