結構體信息
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\n", pAdapter->AdapterName);
printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
printf("\tAdapter Addr: \t");
for (UINT i = 0; i < pAdapter->AddressLength; i++)
printf("%x%c", pAdapter->Address[i],
i == pAdapter->AddressLength - 1 ? '\n' : '-');
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");
}