简体   繁体   English

我需要帮助来了解GetIpAddrTable和接口广播地址

[英]I need help understanding GetIpAddrTable and the interface broadcast address

I'm trying to use GetIpAddrTable ( https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getipaddrtable ) to gather the interface addresses but I'm struggling to understand the response for dwBCastAddr . 我正在尝试使用GetIpAddrTablehttps://docs.microsoft.com/zh-cn/windows/win32/api/iphlpapi/nf-iphlpapi-getipaddrtable )来收集接口地址,但是我在努力理解响应对于dwBCastAddr

For my network the broadcast address for the interface should be 192.168.1.255 but all that dwBCastAddr returns is 1 and I have no idea what I'm supposed to do with that. 对于我的网络,该接口的广播地址应为192.168.1.255dwBCastAddr返回的所有内容dwBCastAddr 1 ,我不知道该怎么办。

The documentation for the data structure ( https://docs.microsoft.com/en-us/windows/win32/api/ipmib/ns-ipmib-mib_ipaddrrow_w2k ) says the following: 数据结构的文档( https://docs.microsoft.com/zh-cn/windows/win32/api/ipmib/ns-ipmib-mib_ipaddrrow_w2k )表示以下内容:

dwBCastAddr dwBCastAddr

Type: DWORD 类型:DWORD

The broadcast address in network byte order. 网络字节顺序的广播地址。 A broadcast address is typically >the IPv4 address with the host portion set to either all zeros or all ones. 广播地址通常是>主机部分设置为全零或全1的IPv4地址。

The proper value for this member is not returned by the GetIpAddrTable function. GetIpAddrTable函数不会返回此成员的正确值。

What are they trying to say here? 他们想在这里说什么?

This is the line used to get the broadcast address: 这是用于获取广播地址的行:

IPAddr.S_un.S_addr = (u_long)pIPAddrTable->table[i].dwBCastAddr;

I'm just trying to figure out how to get 192.168.1.255 out of this. 我只是想弄清楚如何从中获取192.168.1.255。

Any help would be appreciated. 任何帮助,将不胜感激。

The proper value for this member is not returned by the GetIpAddrTable function. GetIpAddrTable函数不会返回此成员的正确值。

It's saying that if you are using GetIpAddrTable , the value of dwBCastAddr is wrong and useless. 它说,如果你正在使用GetIpAddrTable ,价值dwBCastAddr是错误的,无用的。 So don't use it. 所以不要使用它。

Instead you can calculate the broadcast address yourself from the IP address and subnet mask like so: 相反,您可以自己从IP地址和子网掩码中计算出广播地址,如下所示:

 IPAddr.S_un.S_addr=  pIPAddrTable->table[i].dwAddr | ~pIPAddrTable->table[i].dwMask;
 printf("\tBroadCast[%d]:    \t%s\n", i, inet_ntoa(IPAddr));

See How can I determine network and broadcast address from the IP address and subnet mask? 请参阅如何从IP地址和子网掩码确定网络和广播地址? for more details. 更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM