IP_ADAPTER_INFO 的msdn说明

 IP_ADAPTER_INFO

The IP_ADAPTER_INFO structure contains information about a particular network adapter on the local computer.

 typedef struct _IP_ADAPTER_INFO

{ struct _IP_ADAPTER_INFO* Next;

DWORD ComboIndex;

char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];

char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];

 UINT AddressLength;

BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];

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; } IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;

Members

Next

Pointer to the next adapter in the list of adapters.

ComboIndex

Reserved.

AdapterName

Name of the adapter.

Description

Description for the adapter.

AddressLength

Length of the hardware address for the adapter.

Address

Hardware address for the adapter.

Index

Adapter index. The adapter index may change when an adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.

Type

Adapter type. The type must be of the following values:

MIB_IF_TYPE_OTHER

MIB_IF_TYPE_ETHERNET

MIB_IF_TYPE_TOKENRING

MIB_IF_TYPE_FDDI

MIB_IF_TYPE_PPP

MIB_IF_TYPE_LOOPBACK

MIB_IF_TYPE_SLIP

These values are defined in the header file IPIfCons.h.

DhcpEnabled

Specifies whether dynamic host configuration protocol (DHCP) is enabled for this adapter. CurrentIpAddress

Reserved.

IpAddressList

List of IP addresses associated with this adapter.

GatewayList

IP address of the default gateway for this adapter.

DhcpServer

IP address of the DHCP server for this adapter. A value of 255.255.255.255 indicates the DHCP server could not be reached, or is in the process of being reached.

HaveWins

Specifies whether this adapter uses Windows Internet Name Service (WINS).

PrimaryWinsServer

IP address of the primary WINS server.

SecondaryWinsServer IP address of the secondary WINS server.

LeaseObtained

Time when the current DHCP lease was obtained.

LeaseExpires

Time when the current DHCP lease expires.

Example Code

This example retrieves the adapter information and prints various properties of each adapter. PIP_ADAPTER_INFO pAdapterInfo;

PIP_ADAPTER_INFO pAdapter = NULL;

DWORD dwRetVal = 0;

pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );

ulOutBufLen = sizeof(IP_ADAPTER_INFO); // Make an initial call to GetAdaptersInfo to get

// the necessary size into the ulOutBufLen variable

if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS)

{

GlobalFree (pAdapterInfo);

pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);

}

if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)

{

pAdapter = pAdapterInfo;

while (pAdapter)

{

printf("/tAdapter Name: /t%s/n", pAdapter->AdapterName);

printf("/tAdapter Desc: /t%s/n", pAdapter->Description);

printf("/tAdapter Addr: /t%ld/n", pAdapter->Address);

printf("/tIP Address: /t%s/n", pAdapter->IpAddressList.IpAddress.String);

printf("/tIP Mask: /t%s/n", pAdapter->IpAddressList.IpMask.String);

printf("/tGateway: /t%s/n", pAdapter->GatewayList.IpAddress.String);

printf("/t***/n");

if (pAdapter->DhcpEnabled)

{

printf("/tDHCP Enabled: Yes/n");

printf("/t/tDHCP Server: /t%s/n", pAdapter->DhcpServer.IpAddress.String);

printf("/tLease Obtained: %ld/n", pAdapter->LeaseObtained);

}

else

printf("/tDHCP Enabled: No/n");

if (pAdapter->HaveWins)

{

printf("/tHave Wins: Yes/n");

printf("/t/tPrimary Wins Server: /t%s/n", pAdapter->PrimaryWinsServer.IpAddress.String);

printf("/t/tSecondary Wins Server: /t%s/n", pAdapter->SecondaryWinsServer.IpAddress.String);

}

else

printf("/tHave Wins: No/n");

pAdapter = pAdapter->Next;

}

}

else

{

printf("Call to GetAdaptersInfo failed./n");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值