开发者

Equivalent information from GetAdaptersAddresses() in Windows 2000 (WIN2KSP4)?

I have a C++ (VS2005) application that makes use of GetAdaptersAddresses() on Windows XP and I need to provide most of the same information from IP_ADAPTER_ADDRESSES with regards to IPv4 (I don't need IPv6) in Windows 2000 (WIN2KSP4).

(The IPv6 Technology Preview for Windows 2000 is not an option)

Please remember when looking at MSDN, that under "Requirements" it should be "Minimum supported client : Windows 2000 Professional" (although, I do realize that MSDN isn't always correct*)

The call to GetAdaptersAddresses looks like:

// flags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME
GetAdaptersAddresses(AF_INET, flags, NULL, reinterpret_cast<IP_ADAPTER_ADDRESSES*>(info), &actualSize)

The version of IP_ADAPTER_ADDRESSES that I have looks like:

(fields that are struck-through开发者_StackOverflow社区 are not needed)

typedef struct _IP_ADAPTER_ADDRESSES {
  union {
    ULONGLONG Alignment;
    struct {
      ULONG Length;
      DWORD IfIndex;
    } ;
  } ;
  struct _IP_ADAPTER_ADDRESSES *Next;
  PCHAR                              AdapterName;
  PIP_ADAPTER_UNICAST_ADDRESS        FirstUnicastAddress;
  PIP_ADAPTER_ANYCAST_ADDRESS        FirstAnycastAddress;
  PIP_ADAPTER_MULTICAST_ADDRESS      FirstMulticastAddress;
  PIP_ADAPTER_DNS_SERVER_ADDRESS     FirstDnsServerAddress;
  PWCHAR                             DnsSuffix;
  PWCHAR                             Description;
  PWCHAR                             FriendlyName;
  BYTE                               PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
  DWORD                              PhysicalAddressLength;
  DWORD                              Flags;
  DWORD                              Mtu;
  DWORD                              IfType;
  IF_OPER_STATUS                     OperStatus;
  DWORD                              Ipv6IfIndex;
  DWORD                              ZoneIndices[16];
  PIP_ADAPTER_PREFIX                 FirstPrefix;
} IP_ADAPTER_ADDRESSES, *PIP_ADAPTER_ADDRESSES;

Through a combination of calls to:

  GetIpAddrTable       (MIB_IPADDRTABLE, MIB_IPADDRROW)  
  GetAdaptersInfo      (IP_ADAPTER_INFO)  
  GetIfTable           (MIB_IFTABLE, MIB_IFROW)  
  GetIfEntry           (MIB_IFROW)  

I can get some of the information I need:

  AdapterName
  FirstUnicastAddress   // I think I have this
  PhysicalAddress          // MAC address
  PhysicalAddressLength
  Flags
  Mtu                      // only available from MIB_IFROW
  IfType

That leaves me my problem, and 3 questions:

1) IF_OPER_STATUS OperStatus != dwOperStatus from MIB_IFROW

Anyone have thoughts on how to get the equivelent information or something close to it?

2) I believe that I have found the equivelent to FirstUnicastAddress with IP_ADDR_STRING IpAddressList from IP_ADAPTER_INFO. Assuming that I am correct (am I?), how might I determine that the addresses are in the same order; that the first address from FirstUnicastAddress is the same as the the first address in IpAddressList? And yes, it would be usefult to transverse the list if there is more than one address in the list.

3) FirstMulticastAddress : Getting this information has been made harder by my limited knowledge of multicasting. I had thought that using WSAIoctl with SIO_GET_INTERFACE_LIST would lead me to an answer, but no. Lately I've been trying to use getsockopt with IP_MULTICAST_IF. So far, I'm only managing to get 4 bytes returned with ip_mreq.imr_multiaddr set to 0.0.0.0. I'm hoping it's user error on my part since GetAdaptersAddresses returns 2 addresses for my network card and 1 address for loopback. So, how do I get all the multicast addresses associated with each interface? And if I do get the getsockopt call working, how do I get more than 1 multicast address from it?

Thanks,

Bill

  • Regarding the MSDN doc for ip_mreq at http://msdn.microsoft.com/en-us/library/ms738695%28VS.85%29.aspx, it lists Minimum supported client as Windows XP. Yet I found this nice little KB article support.microsoft.com/kb/131978


You are probably looking for GetAdaptersInfo, documented at: http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜