views:

86

answers:

2

When using ping on virtually every UNIX system available, pinging the broadcast address is simple:

$ ping 192.168.11.255

However, when this is done on Linux, a non-standard (and continually annoying!) response occurs:

$ ping 192.168.11.255
Do you want to ping broadcast? Then -b

This has annoyed me to no end ever since I saw it for the first time - Linux ping didn't used to be this way. I searched for the source of this switch, and can't find when it went in or any discussion as to why it was necessary.

It seems like this switch wasn't even deemed enough:

$ ping -b 192.168.11.255
WARNING: pinging broadcast address
PING 192.168.11.255 (192.168.11.255) 56(84) bytes of data.
64 bytes from 192.168.11.22: icmp_seq=1 ttl=64 time=0.225 ms

Is this really necessary? It's sorely tempting to write a patch that will fix Linux ping so it works like it should...

I can't believe no one else has complained about this, but I can't find it on Google if they did.

A: 

You could put

alias ping='ping -b'

in your .bashrc file :-)

Richard Fearn
I think this question was more like about why the switch exists in the first place.
Matti Virkkunen
Matti is right. Besides, the -b switch only works if the address is a broadcast address; otherwise, a usage display results instead.
David
@Matti: Yes, I understand that the question was about the reason for the `-b` switch being added, as opposed to a workaround for it! @David: Works here. As I understand things from the ping source code (http://www.linux-ipv6.org/gitweb/gitweb.cgi?p=gitroot/iputils.git;a=blob;f=ping.c;h=4472d777f7e098525b57c09c8f748ec877e6d518;hb=HEAD) it just allows broadcasting by setting a socket option. I guess it might not work on some systems, though.
Richard Fearn
A: 

I can conceivably think of one scenario where this might be useful. If you're on a network with a configured broadcast address that is not the address where all host bits are one. Thus you could conceivably accidentally ping the broadcast address if there wasn't such a prompt. And I guess that's bad.

jdizzle