Review of the Network Adapters Parameters

Environment: VC6 + Microsoft SDK, VC7, Windows 98/ME/NT/2000/XP

This article describes the program that shows the information about different network interfaces operating at the current moment.

The basis of this utility is the use of such API functions as GetAdaptersInfo(), inet_addr(), and gethostbyaddr(). The program displays the adapters' names in the system, protocol type (PPP, Ethernet, and so forth), IP addresses of the given computer and gateway, and their NetBIOS names.

You need to include in the program the following header files besides the standard: Iphlpapi.h, IPIfCons.h, and Winsock2.h. And it is also necessary to include in the project such libraries as Iphlpapi.lib and Ws2_32.lib.

Let's examine the function prototype GetAdaptersInfo():

DWORD GetAdaptersInfo(
  PIP_ADAPTER_INFO pAdapterInfo,
  PULONG pOutBufLen

The first argument is a pointer to a buffer, where the connected list of structures IP_ADAPTER_INFO is stored; every one of these structures carries the information about one of the system network adapters. The second argument is a pointer to the variable of the unsigned long type that stores the buffer size.

Let's examine the structure IP_ADAPTER_INFO:

  struct _IP_ADAPTER_INFO* Next;
  DWORD ComboIndex;
  char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
  UINT AddressLength;
  DWORD Index;
  UINT Type;
  UINT DhcpEnabled;
  PIP_ADDR_STRING CurrentIpAddress;
  IP_ADDR_STRING IpAddressList;
  IP_ADDR_STRING GatewayList;
  IP_ADDR_STRING DhcpServer;
  BOOL HaveWins;
  IP_ADDR_STRING PrimaryWinsServer;
  IP_ADDR_STRING SecondaryWinsServer;
  time_t LeaseObtained;
  time_t LeaseExpires;

The fields' names are clear for understanding. The structure contains a lot of useful information.

After we have the connected list of these structures, we have to go through it and get the needed information. It can be done this way, for example:

PIP_ADAPTER_INFO pCurAdapt = &buffer[0];

do {

  //getting the needed information from the structure.

} while ((pCurAdapt = pCurAdapt->Next) != NULL);

We will get the type of the network protocol from the structure Type member IP_ADAPTER_INFO the following way:

char* GetType(UINT type) {
  switch (type) {
    return "Unknown";
    return "Ethernet";
    return "Token ring";
    return "FDDI";
    return "PPP";
    return "Loop Back";
    return "SLIP";

  return "Unknown";

At last, we have to examine the process of receiving the computer name through its IP address. We will get the IP address through the IP_ADDR_STRING structure.

  struct _IP_ADDR_STRING* Next;
  DWORD Context;

The function that receives the host name through IP address is below.

bool GetDN(char* ip, char* host, unsigned int len) {
  unsigned long res;
  WSADATA wsaData;
  HOSTENT* pHost;

  res = inet_addr(ip);

  if ((res == INADDR_NONE) || (res   == 0)) {
       strcpy(host, "unable to resolve");
       return false;

  if (WSAStartup(MAKEWORD(1, 1), &wsaData)) {
      strcpy(host, "unable to resolve");
      return false;

  pHost = gethostbyaddr((char*)&res, sizeof(res), AF_INET);
  if (pHost == NULL) {
      strcpy(host, "unable to resolve");
      return false;

  if (strlen(pHost->h_name)>len) {

    strcpy(host, "buffer too small");
    return false;

  strcpy(host, pHost->h_name);

  return true;

It is called the following way:

// ...
  char host[1024];

GetDN(pCurIP->IpAddress.String, host, sizeof(host));


Our home site (for software, IT related links, sources, and articles) is


Download demo - 4 Kb


  • About your demo

    Posted by Legacy on 05/15/2003 12:00am

    Originally posted by: X

    Your demo displays only local IP address and its adaptor.
    "At last, we have to examine the process of receiving the computer name through its IP address."...

  • Change IP ?

    Posted by Legacy on 05/13/2003 12:00am

    Originally posted by: Sonu Kapoor


    Any Idea how to change the current IP ?

    Thanks, Sonu

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date