0

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.

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.

The documentation for the data structure (https://docs.microsoft.com/en-us/windows/win32/api/ipmib/ns-ipmib-mib_ipaddrrow_w2k) says the following:

dwBCastAddr

Type: 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.

The proper value for this member is not returned by the GetIpAddrTable function.

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.

Any help would be appreciated.

  • What you are looking for is the network broadcast address, but there is also the Limited Broadcast address (all ones: `255.255.255.255`), and the (obsolete) all zeroes broadcast address (`0.0.0.0`). Broadcast itself is really obsolete because it wastes network and host resources, and multicast is what should be used for modern networking. That is why IPv6 has eliminated broadcast in favor of multicast. Many companies will not use applications that use broadcast because of wasted resources and the security implications. – Ron Maupin Sep 11 '19 at 12:55

1 Answers1

1

The proper value for this member is not returned by the GetIpAddrTable function.

It's saying that if you are using GetIpAddrTable , the value of dwBCastAddr is wrong and useless. So don't use it.

Instead you can calculate the broadcast address yourself from the IP address and subnet mask like so:

 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? for more details.

nos
  • 207,058
  • 53
  • 381
  • 474
  • > It's saying that if you are using GetIpAddrTable , the value of dwBCastAddr is wrong and useless. So don't use it. Thanks! I was just making sure I wasn't going crazy as it just isn't super clear. The project I'm using uses boost and I can use those methods to determine the broadcast address then but just was confused why it was getting set like this in the first place. – DrJohnZoidberg Sep 11 '19 at 13:02