Skip to content

Commit

Permalink
Added pcap_get_servicename() function in wpcap.dll to return the Npca…
Browse files Browse the repository at this point in the history
…p service name, it returns "NPF" for WinPcap compatible mode and "NPCAP" for Non-WinPcap compatible mode.
  • Loading branch information
hsluoyz committed May 22, 2016
1 parent 4325bda commit 5d84de4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions Common/Packet32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packetWin7/Dll/Packet.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ EXPORTS
PacketLibraryVersion
PacketGetVersion
PacketGetDriverVersion
PacketGetDriverName
PacketOpenAdapter
PacketSendPacket
PacketSendPackets
Expand Down
23 changes: 20 additions & 3 deletions packetWin7/Dll/Packet32.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,20 @@ CHAR g_LogFileName[1024] = "winpcap_debug.txt";
#include <WpcapNames.h>

//
// 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
//
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions wpcap/PRJ/WPCAP.DEF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions wpcap/libpcap/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions wpcap/libpcap/pcap/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5d84de4

Please sign in to comment.