Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm writing a small application to emulate an "appliance" in order to run some testing without the physical device. This "appliance" starts off by broadcasting a "Hello I'm here" message, on UDP, every couple of seconds, waiting for a response. When I sniffed the network, I could see the broadcasts being sent to 192.168.0.255.
For my application, I didn't want to hardcode the address, so I tried to use 255.255.255.255, but this doesn't appear to go anywhere. A sniffer running on the same box doesn't even see the packets. To check my program, I hardcoded the address as "192.168.0.2555" and everything looks good.
So, two questions. Why doesn't broadcasting to "255.255.255.255" work. Or is there something else I need to set, in addition to SO_BROADCAST to get this to work.
And secondly, if I can't use 255's, then how can I determine, programatically, the address to use, as this my run on differently configured machines. And these will usually be Linux, but might also be WinBlows.
1. The reason that 255.255.255.255 doesn't work because it is not a valid broadcast address. Machines will only ever respond to requests directed at it or directed at it's broadcast address.
2. Two suggestions to determine the addresses. One is to use dhcp to configure your applicance. This is the most simple as your appliance will basically auto configure itself. Second would be to sniff the traffic and after getting a good enough sample of source and destination addresses you can determine the network.
2. Two suggestions to determine the addresses. One is to use dhcp to configure your applicance. This is the most simple as your appliance will basically auto configure itself. Second would be to sniff the traffic and after getting a good enough sample of source and destination addresses you can determine the network.
That's not quite was I was after. Neither of those are "programatic" ways that an application can determine what broadcast address to use.
I guess what you can do is use a dhcp library to go through the motions of dhcp and then release the address. This will give you all the information you would need.
The broadcast address shows up in ifconfig's output.. You could have the script execute that command, then with sed/awk you should be able to grab it out, and assign it to a variable for later use.
x.x.x.0 in a /24 network is the Network address it should NEVER be assigned to a host.
x.x.x.255 in a /24 network is the broadcast address, it should never be assigned to a host...
You would need to make the last portion of the IP address 255 ( eight 1's..) for it to be the broadcast..
so if the network is 192.168.1.0 /24 the broadcast address should be 192.168.1.255
if the network is 172.16.14.0 /24 the broadcast address would be 172.16.14.255
Draygo: It looks like the 255.255.255.255 broadcasts are being sent through my local network. My problem was, that my Linux box has 2 NICs, and I suspect that they were being routed down the "wrong" one. When I ran the application on Windows, the broadcasts were visible at the Linux box. So, the following 2 comments are kinda not needed, but I wanted to put the record straight.
farslayer: I already do understand how IPs, subnets, broadcast address, gateway, etc. My problem is, how to get that information in an application on a running system.
fur: Did you notice that I asked for a "portable" way of doing this. This needs to run on Windows as well. And also, I did say "application", not script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.