From 5d84de40271d08c173563c3c53d1484132a13478 Mon Sep 17 00:00:00 2001 From: hsluoyz Date: Sun, 22 May 2016 11:06:03 +0800 Subject: [PATCH] Added pcap_get_servicename() function in wpcap.dll to return the Npcap service name, it returns "NPF" for WinPcap compatible mode and "NPCAP" for Non-WinPcap compatible mode. --- Common/Packet32.h | 1 + packetWin7/Dll/Packet.def | 1 + packetWin7/Dll/Packet32.c | 23 ++++++++++++++++++++--- wpcap/PRJ/WPCAP.DEF | 1 + wpcap/libpcap/pcap.c | 11 +++++++++++ wpcap/libpcap/pcap/pcap.h | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Common/Packet32.h b/Common/Packet32.h index 2bd819dc..e338966d 100644 --- a/Common/Packet32.h +++ b/Common/Packet32.h @@ -320,6 +320,7 @@ extern "C" PCHAR PacketGetVersion(); PCHAR PacketGetDriverVersion(); + PCHAR PacketGetDriverName(); BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject, int nbytes); BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject, int nwrites); BOOLEAN PacketSetMode(LPADAPTER AdapterObject, int mode); diff --git a/packetWin7/Dll/Packet.def b/packetWin7/Dll/Packet.def index ca397a74..ed2b3e9f 100644 --- a/packetWin7/Dll/Packet.def +++ b/packetWin7/Dll/Packet.def @@ -4,6 +4,7 @@ EXPORTS PacketLibraryVersion PacketGetVersion PacketGetDriverVersion + PacketGetDriverName PacketOpenAdapter PacketSendPacket PacketSendPackets diff --git a/packetWin7/Dll/Packet32.c b/packetWin7/Dll/Packet32.c index e157eeff..bb65887c 100644 --- a/packetWin7/Dll/Packet32.c +++ b/packetWin7/Dll/Packet32.c @@ -120,15 +120,20 @@ CHAR g_LogFileName[1024] = "winpcap_debug.txt"; #include // -// Current packet.dll Version. It can be retrieved directly or through the PacketGetVersion() function. +// Current packet.dll version. It can be retrieved directly or through the PacketGetVersion() function. // char PacketLibraryVersion[64]; // -// Current NPF.sys Version. It can be retrieved directly or through the PacketGetVersion() function. +// Current driver version. It can be retrieved directly or through the PacketGetVersion() function. // char PacketDriverVersion[64]; +// +// Current driver name ("NPF" or "NPCAP"). It can be retrieved directly or through the PacketGetVersion() function. +// +char PacketDriverName[64]; + // // WinPcap global registry key // @@ -881,6 +886,7 @@ BOOL APIENTRY DllMain(HANDLE DllHandle,DWORD Reason,LPVOID lpReserved) // XXX We want to replace this with a constant. We leave it out for the moment // TODO fixme. Those hardcoded strings are terrible... PacketGetFileVersion(TEXT("drivers\\") TEXT(NPF_DRIVER_NAME) TEXT(".sys"), PacketDriverVersion, sizeof(PacketDriverVersion)); + strcpy_s(PacketDriverName, 64, NPF_DRIVER_NAME); // Get the name for "Npcap Loopback Adapter" NPcapGetLoopbackInterfaceName(); @@ -2338,7 +2344,7 @@ PCHAR PacketGetVersion() } /*! - \brief Return a string with the version of the NPF.sys device driver. + \brief Return a string with the version of the device driver. \return A char pointer to the version of the driver. */ PCHAR PacketGetDriverVersion() @@ -2348,6 +2354,17 @@ PCHAR PacketGetDriverVersion() return PacketDriverVersion; } +/*! +\brief Return a string with the name of the device driver. +\return A char pointer to the version of the driver. +*/ +PCHAR PacketGetDriverName() +{ + TRACE_ENTER("PacketGetDriverName"); + TRACE_EXIT("PacketGetDriverName"); + return PacketDriverName; +} + /*! \brief Stops and unloads the WinPcap device driver. \return If the function succeeds, the return value is nonzero, otherwise it is zero. diff --git a/wpcap/PRJ/WPCAP.DEF b/wpcap/PRJ/WPCAP.DEF index b6d285a4..7d07f2b7 100644 --- a/wpcap/PRJ/WPCAP.DEF +++ b/wpcap/PRJ/WPCAP.DEF @@ -79,6 +79,7 @@ EXPORTS pcap_datalink_val_to_name pcap_datalink_val_to_description pcap_lib_version + pcap_get_servicename pcap_dump_file pcap_dump_ftell pcap_get_airpcap_handle diff --git a/wpcap/libpcap/pcap.c b/wpcap/libpcap/pcap.c index 279c84ab..45eef4f0 100644 --- a/wpcap/libpcap/pcap.c +++ b/wpcap/libpcap/pcap.c @@ -1381,6 +1381,17 @@ pcap_lib_version(void) return (full_pcap_version_string); } +const char * +pcap_get_servicename(void) +{ + /* + * Generate the service name string, can be "NPF" (WinPcap compatible mode) or "NPCAP" (Non-WinPcap compatible mode) + */ + char *service_name_string; + service_name_string = PacketGetDriverName(); + return (service_name_string); +} + #elif defined(MSDOS) static char *full_pcap_version_string; diff --git a/wpcap/libpcap/pcap/pcap.h b/wpcap/libpcap/pcap/pcap.h index 84d80cb9..6adbbcd6 100644 --- a/wpcap/libpcap/pcap/pcap.h +++ b/wpcap/libpcap/pcap/pcap.h @@ -353,6 +353,7 @@ int pcap_findalldevs(pcap_if_t **, char *); void pcap_freealldevs(pcap_if_t *); const char *pcap_lib_version(void); +const char *pcap_get_servicename(void); /* XXX this guy lives in the bpf tree */ u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);