Windows API Documentation

Network Management API

This section details the functions, structures, and concepts related to managing network resources and configurations within the Windows operating system using the Win32 API.

Core Concepts

Understanding network management involves several key areas:

Key Functions

The following functions are central to network management tasks:

Related Structures

These structures are often used in conjunction with the network management functions:

Function: GetAdaptersInfo

Prototype:

ULONG GetAdaptersInfo(
  PIP_ADAPTER_INFO pAdapterInfo,
  PULONG pOutBufLen
);

Description: Retrieves detailed information about network adapters installed on the local computer.

Parameters:

Return Value: If the function succeeds, the return value is NO_ERROR. If the buffer is not large enough, the return value is ERROR_BUFFER_OVERFLOW. Otherwise, the return value is one of the system error codes.

Function: GetIpAddrProperties

Prototype:

DWORD GetIpAddrProperties(
  NET_IFINDEX           InterfaceIndex,
  PIP_ADAPTER_ADDRESSES *AdapterAddresses
);

Description: Retrieves IP address properties for a specified network interface.

Parameters:

Return Value: Returns NO_ERROR if successful, otherwise an error code.

Structure: IP_ADAPTER_INFO

Definition:

typedef struct _IP_ADAPTER_INFO {
    struct _IP_ADAPTER_INFO *Next;
    CHAR                    AdapterName[NDIS_MAX_ADAPTER_NAME_LENGTH + 4];
    CHAR                    Description[NDIS_MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
    UINT                    AddressLength;
    BYTE                    Address[NDIS_MAX_ADDRESS_LENGTH];
    UINT                    Index;
    UINT                    Type;
    UINT                    DhcpEnabled;
    IP_ADDR_STRING          IpAddress;
    IP_MASK                 SubnetMask;
    IP_ADDR_STRING          BroadcastAddress;
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;

Members: Contains details like adapter name, description, MAC address, IP address, subnet mask, and DHCP status.

Function: GetHostByName

Prototype:

struct hostent FAR * gethostbyname(
  const char FAR * name
);

Description: Retrieves the host information corresponding to the host name specified.

Parameters:

Return Value: If successful, returns a pointer to a hostent structure. If not successful, it returns NULL. The h_errno variable can be checked for specific error codes.

Structure: HOSTENT

Definition:

struct hostent {
    char FAR *  h_name;      /* Official name of the host. */
    char FAR ** h_aliases;   /* A NULL-terminated array of alternate names, if any. */
    short       h_addrtype;  /* The type of the address. */
    short       h_length;    /* The length, in bytes, of the address. */
    char FAR ** h_addr_list; /* A NULL-terminated array of network addresses for the host. */
};

Members: Stores the canonical hostname, aliases, address type (e.g., AF_INET for IPv4), address length, and a list of IP addresses.

Function: SendARP

Prototype:

ULONG SendARP(
  IPAddr   DestIP,
  IPAddr   srcIP,
  PIP_ADDR_LONG pMacAddr,
  PIP_ADDR_LONG pIpAddr
);

Description: Resolves an IP address to its corresponding physical address (MAC address) using ARP.

Parameters:

Return Value: Returns NO_ERROR if successful, or an appropriate error code.