I want to calculate the broadcast address for:
IP: 192.168.3.1
Subnet: 255.255.255.0
= 192.168.3.255
in C.
I know the way (doing fancy bitwise OR's between the inversed IP and subnet), but my problem is I come from the green fields of MacOSX Cocoa programing.
I looked into the source of ipcal, but wasn't able to integrate it into my code base. There must be a simple ten lines of code somewhere on the internet, I just can't find it. Could someone point me to a short code example of how to do it in C?
ok whom will look for this code in the future. I have spend sometimes today as I needed this, here is the full code and it works :) simply copy and paste it and then import the required dlls.
Then just call it like :
Happy coding :)
I understand that the OP had at least a vague understanding of the bit-level arithmetic but was lost on converting the strings to numbers and its inverse. here's a working (with minimal testing anyway) example, using froh42's calculation.
Just calculate:
(Broadcast = ip-addr or the inverted subnet-mask)
The broadcast address has a
1
bit where the subnet mask has a0
bit.Could it be?
Edit: I considered that both ip and subnet are without "."
Here is how to do it in C#. for example using ip 10.28.40.149 with netmask 255.255.252.0 returns 10.28.43.255 which is the correct broadcast address. thanks to some code from here