Packet Sniffer SDK VCL Edition

2: Retrieve information about network devices

 Previous Next

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 Get_FirstAdapterCfg method, and then enumerate HNAdapterConfig objects by Get_NextAdapterCfg method.

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

hCfg   : Pointer; 
AdpCfg : THNAdapterConfig;

AdpCfg := THNAdapterConfig.Create;
hCfg   := hMgr.Get_FirstAdapterCfg();
repeat
  AdpCfg.Handle := hCfg;
  if (AdpCfg.AdapterType = atEthernet) then 
   MessageBox(0,'Ethernet adapter was found','Information',MB_OK);
  ...
  hCfg := hMgr.Get_NextAdapterCfg(hCfg);
until(hCfg = nil);

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

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

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

procedure TForm.OnConfigChange(Sender: TObject; hConfig: Pointer; ChangeType: Integer);
begin
  AdpCfg.Handle := hConfig;
  if (AdpCfg.AdapterType = atEthernet) then
   MessageBox(0,'Ethernet adapter was found','Information',MB_OK);
  ...	
end;
 
hMgr.Initialize();

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