IP_ADAPTER_INFO
结构体信息
The IP_ADAPTER_INFO structure contains information about a particular network adapter on the local computer.
结构体IP_ADAPTER_INFO包含本地计算机某一个网络适配器的信息。
定义
typedef struct _IP_ADAPTER_INFO {
struct _IP_ADAPTER_INFO* Next;//指向链表中下一个适配器信息的指针
DWORD ComboIndex;//预留值
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];//使用ANSI字符串表示的适配器名称
char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];//使用ANSI字符串表示的适配器描述
UINT AddressLength;//适配器硬件地址以字节计算的长度
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];//硬件地址以BYTE数组所表示
DWORD Index;//适配器索引
UINT Type;//适配器类型
UINT DhcpEnabled;//指定这个适配器是否开启DHCP
PIP_ADDR_STRING CurrentIpAddress;//预留值
IP_ADDR_STRING IpAddressList;//该适配器的IPv4地址链表
IP_ADDR_STRING GatewayList;//该适配器的网关IPv4地址链表
IP_ADDR_STRING DhcpServer;//该适配器的DHCP服务器的IPv4 地址链表
BOOL HaveWins;
IP_ADDR_STRING PrimaryWinsServer;
IP_ADDR_STRING SecondaryWinsServer;
time_t LeaseObtained;
time_t LeaseExpires;
} IP_ADAPTER_INFO,
*PIP_ADAPTER_INFO;
使用
ADAPTER_INFO structure is limited to IPv4 information about a particular network adapter on the local computer. The IP_ADAPTER_INFO structure is retrieved by calling the GetAdaptersInfo function.
结构体ADAPTER_INFO只限制于获取本地计算机网络适配器的IPv4信息,该结构体通过调用GetAdaptersInfo函数获取值。
示例代码
// It is possible for an adapter to have multiple
// IPv4 addresses, gateways, and secondary WINS servers
// assigned to the adapter.
// Note that this sample code only prints out the
// first entry for the IP address/mask, gateway,
// and secondary WINS server for 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\", pAdapter->AdapterName);
printf("\\tAdapter Desc: \\t%s\", pAdapter->Description);
printf("\\tAdapter Addr: \\t");
for (UINT i = 0; i < pAdapter->AddressLength; i++)
printf("%x%c", pAdapter->Address[i],
i == pAdapter->AddressLength - 1 ? ''\'' : ''-'');
printf("\\tIP Address: \\t%s\", pAdapter->IpAddressList.IpAddress.String);
printf("\\tIP Mask: \\t%s\", pAdapter->IpAddressList.IpMask.String);
printf("\\tGateway: \\t%s\", pAdapter->GatewayList.IpAddress.String);
printf("\\t***\");
if (pAdapter->DhcpEnabled) {
printf("\\tDHCP Enabled: Yes\");
printf("\\t\\tDHCP Server: \\t%s\", pAdapter->DhcpServer.IpAddress.String);
printf("\\tLease Obtained: %ld\", pAdapter->LeaseObtained);
}
else
printf("\\tDHCP Enabled: No\");
if (pAdapter->HaveWins) {
printf("\\tHave Wins: Yes\");
printf("\\t\\tPrimary Wins Server: \\t%s\", pAdapter->PrimaryWinsServer.IpAddress.String);
printf("\\t\\tSecondary Wins Server: \\t%s\", pAdapter->SecondaryWinsServer.IpAddress.String);
}
else
printf("\\tHave Wins: No\");
pAdapter = pAdapter->Next;
}
}
else {
printf("Call to GetAdaptersInfo failed.\");
}