GetAdaptersInfo函数问题
先看一下MSDN-------->
IP_ADAPTER_INFO Structure
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
A pointer to the next adapter in the list of adapters.
ComboIndex
Reserved.
AdapterName
An ANSI character string of the name of the adapter.
Description
An ANSI character string of the description for the adapter.
AddressLength
The length, in bytes, of the hardware address for the adapter.
Address
The hardware address for the adapter represented as a BYTE array.
Index
The 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
The adapter type. The type must be one 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
An option value that specifies whether the dynamic host configuration protocol (DHCP) is enabled for this adapter.
CurrentIpAddress
Reserved.
IpAddressList
The list of IPv4 addresses associated with this adapter represented as a linked list of IP_ADDR_STRING structures. An adapter can have multiple IPv4 addresses assigned to it.
GatewayList
The IPv4 address of the gateway for this adapter represented as a linked list of IP_ADDR_STRING structures. An adapter can have multiple IPv4 gateway addresses assigned to it. This list usually contains a single entry for IPv4 address of the default gateway for this adapter.
DhcpServer
The IPv4 address of the DHCP server for this adapter represented as a linked list of IP_ADDR_STRING structures. This list contains a single entry for IPv4 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. This member is only valid when the DhcpEnabled member is non-zero.
HaveWins
An option value that specifies whether this adapter uses the Windows Internet Name Service (WINS).
PrimaryWinsServer
The IPv4 address of the primary WINS server represented as a linked list of IP_ADDR_STRING structures. This list contains a single entry for IPv4 address of the primary WINS server for this adapter. This member is only valid when the HaveWins member is TRUE.
SecondaryWinsServer
The IPv4 address of the secondary WINS server represented as a linked list of IP_ADDR_STRING structures. An adapter can have multiple secondary WINS server addresses assigned to it. This member is only valid when the HaveWins member is TRUE.
LeaseObtained
The time when the current DHCP lease was obtained. This member is only valid when the DhcpEnabled member is non-zero.
LeaseExpires
The time when the current DHCP lease expires. This member is only valid when the DhcpEnabled member is non-zero.
Remarks
The IP_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.
When using Visual Studio 2005 and later, the time_t datatype defaults to an 8-byte datatype, not the 4-byte datatype used for the LeaseObtained and LeaseExpires members on a 32-bit platform. To properly use the IP_ADAPTER_INFO structure on a 32-bit platform, define _USE_32BIT_TIME_T (use -D _USE_32BIT_TIME_T as an option, for example) when compiling the application to force the time_t datatype to a 4-byte datatype.
For use on Windows XP and later, the IP_ADAPTER_ADDRESSES structure contains both IPv4 and IPv6 information. The GetAdaptersAddresses function retrieves IPv4 and IPv6 adapter information.
我的问题就是Index,怎么做才能在改变也是就MSDN所说的在关闭打开后得到一个正确的值,请高手指点~