Download the sample code
Network Driver Interface Specification (NDIS) is an API to communicate with Network Interface Cards (NIC) developed by Microsoft and 3Com Corporation. It is library of functions (wrapper) to hide the complexity of the network cards. Using NDIS developers can create device drivers that communicate with the NICs and enables the developer to create protocol stacks that send and receive data packets. These packets are usually called frame.
The sample program presented here lists the adapters present and the protocol names that are associated with each adapters. The application first opens the NDIS device driver. This is done by using the API CreateFile. The first parameter is the device name which will be NDS0: most of the time. The following snippet opens the “NDS0:” device:
m_hDevice = CreateFile(TEXT("NDS0:"),GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
After opening the device, the application retrieves all the adapters present and lists the names in a combobox. This is done using the API DeviceIoControl with IOCTL_NDIS_GET_ADAPTER_NAMES control code. Following code shows the operation:
When completed successfully the szBuffer will have the names of the adapters separated by NULL. The end of the buffer is represented by two NULLs.
When an adapter is selected the protocol names that are associated with it are displayed in a listbox. To retrieve the protocol names, first we have to bind the selected adapter, this is done by using the DeviceIoControl API with IOCTL_NDIS_BIND_ADAPTER control code:
The pszAdapter parameter is the name of the adapter to bind. After binding the adapter we can retrieve the protocol list by using the IOCTL_NDIS_GET_PROTOCOL_NAMES control code:
Again the szBuffer will be multi-string that contains all the protocol names associated with the adapter. This a very simple application and I hope this will give you an introduction to NIDS. I am working on more samples and will post here whenever it is completed.