Windows 2000 (WIN2KSP4) 中 GetAdaptersAddresses() 的等效信息?
我有一个在 Windows XP 上使用 GetAdaptersAddresses() 的 C++ (VS2005) 应用程序,我需要提供来自 IP_ADAPTER_ADDRESSES 的有关 IPv4 的大部分相同信息(我不需要 IPv6) Windows 2000 (WIN2KSP4)。
(Windows 2000 的 IPv6 技术预览不是一个选项)
请记住,在查看 MSDN 时,“要求”下应该是 “最低支持的客户端:Windows 2000 Professional”(尽管,我确实意识到 MSDN 并不总是正确的*)
对 GetAdaptersAddresses 的调用如下所示:
// 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)
IP_ADAPTER_ADDRESSES 的版本我看起来像:
(不需要删除划线的字段)
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;
通过组合调用:
GetIpAddrTable (MIB_IPADDRTABLE, MIB_IPADDRROW)
GetAdaptersInfo (IP_ADAPTER_INFO)
GetIfTable (MIB_IFTABLE, MIB_IFROW)
GetIfEntry (MIB_IFROW)
我可以获得我需要的一些信息:
AdapterName
FirstUnicastAddress // I think I have this
PhysicalAddress // MAC address
PhysicalAddressLength
Flags
Mtu // only available from MIB_IFROW
IfType
这给我留下了我的问题,以及 3 个问题:
1) IF_OPER_STATUS OperStatus != dwOperStatus from MIB_IFROW
有人对如何获得等效信息或接近信息有想法吗?
2) 我相信我已经从 IP_ADAPTER_INFO 中找到了与 IP_ADDR_STRING IpAddressList 等效的 FirstUnicastAddress。假设我是正确的(是吗?),我如何确定地址的顺序相同? FirstUnicastAddress 中的第一个地址与 IpAddressList 中的第一个地址相同吗?是的,如果列表中有多个地址,那么遍历列表会很有用。
3) FirstMulticastAddress:由于我对多播的了解有限,获取此信息变得更加困难。 我原以为将 WSAIoctl 与 SIO_GET_INTERFACE_LIST 一起使用会引导我找到答案,但没有。最近我有 一直在尝试将 getsockopt 与 IP_MULTICAST_IF 一起使用。到目前为止,我只设法在 ip_mreq.imr_multiaddr 设置为 0.0.0.0 的情况下返回 4 个字节。我希望这是我的用户错误,因为 GetAdaptersAddresses 返回 我的网卡有 2 个地址,环回地址有 1 个。那么,如何获取所有多播地址 与每个接口相关联?如果我确实让 getsockopt 调用正常工作,我如何获得超过 1 个多播 地址来自它吗?
谢谢,
Bill
- 关于 ip_mreq 的 MSDN 文档,位于 http: //msdn.microsoft.com/en-us/library/ms738695%28VS.85%29.aspx,它列出了最低支持的客户端为 Windows XP。但我发现了这篇不错的小知识库文章 support.microsoft.com/kb/131978
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在寻找 GetAdaptersInfo,记录于:http:// /msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx
You are probably looking for GetAdaptersInfo, documented at: http://msdn.microsoft.com/en-us/library/aa365917%28VS.85%29.aspx