Packet Sniffer SDK DLL Edition

2: Retrieve information about network devices

 Previous Next

The next step is to clarify which network devices have been found out in your system.

In the Packet Sniffer SDK library information about each network device is stored in HNAdapterConfig object. To gain access to all HNAdapterConfig objects, you should gain access to the first HNAdapterConfig object by MgrGetFirstAdapterCfg function, and then enumerate HNAdapterConfig objects by MgrGetNextAdapterCfg function.

[C++]
HANDLE hCfg = MgrGetFirstAdapterCfg(hMgr); 
do
{
   DWORD Type = AdpCfgGetAdapterType(hCfg);
   if (Type == atEthernet) 
    MessageBox(NULL,"Ethernet adapter was found","Information",MB_OK);
   ...
}while((hCfg = MgrGetNextAdapterCfg(hMgr,hCfg)) != NULL);
[Delphi]
hCfg   : Pointer; 
Type   : DWORD;

hCfg   := MgrGetFirstAdapterCfg(hMgr);
repeat
  Type := AdpCfgGetAdapterType(hCfg);
  if (Type = atEthernet) then 
   MessageBox(0,'Ethernet adapter was found','Information',MB_OK);
  ...
  hCfg := MgrGetNextAdapterCfg(hMgr,hCfg);
until(hCfg = nil);

To get the whole amount of the network adapters installed on the system, please use HNPSManager.AdaptersCfgCount property.

To collect the information about the network devices, you may take an easier way. You should define HNPSManger.OnConfigChange event handler for HNPSManager component before calling the MgrInitialize function.

In this case while HNPSManager component initialization (MgrInitialize function call), is called for each HNAdapterConfig object created. In HNPSManger.OnConfigChange event handler you can also get information about corresponding network device.

[C++]
void __stdcall OnConfigChange(DWORD_PTR Param, HANDLE hCfg, DWORD ChangeType)
{
   DWORD Type = AdpCfgGetAdapterType(hCfg);
   if (Type == atEthernet) 
    MessageBox(NULL,"Ethernet adapter was found","Information",MB_OK);
   ...
}

MgrInitialize();
[Delphi]
procedure OnConfigChange(Param: Pointer; hConfig: Pointer; ChangeType: Cardinal); stdcall;
var
  Type : DWORD;
begin
  Type := AdpCfgGetAdapterType(hCfg);
  if (Type = atEthernet) then
   MessageBox(0,'Ethernet adapter was found','Information',MB_OK);
  ...	
end;
 
MgrInitialize();

After the information about network devices has been collected, you can start working with any network device except for the devices which were determined as atUnknown. (Please see HNNetAdapterType).

Next step:

3: Open network device