views:

7369

answers:

7

I've heard some people say the IPv4 broadcast address is 0.0.0.0 and others say it is 255.255.255.255... would someone explain the real-world difference?

+3  A: 

well, 0.0.0.0 isn't a broadcast address....

You can't target an IP packet to that address and expect someone to get it (though in some cases it's valid as a source if you don't want a response).

Jonathan
You are right but very old OS (SunOS...) used 0.0.0.0 as a broadcast address, by mistake.
bortzmeyer
+9  A: 

In IPv4, the lowest address on a given network is the "network address", and the highest address is the "broadcast address". If you considered the whole internet as your netwrok, then technically, 0.0.0.0 is your network address, where as 255.255.255.255 is your broadcast address.

I don't even know if these addresses are actually used, but I know that they are reserved in the IP protocal.

Charles Graham
I think you can ping the "broadcast address" to get a list of devices on your subnet (say you forgot the address of something and it is headless). I know the "network address" is sometimes used when you are configuring a server, so it probably has other practical uses
username
+13  A: 

0.0.0.0 represents "any address". If you bind a listening socket to 0.0.0.0, you're telling the OS to accept connections on any ip address that the host has network adapters bound to.

e.g. if your host had two network adapters with two different ip addresses. You can bind a socket to either one and it will accept connections only on that adapter. Or you can bind a socket to 0.0.0.0 (INADDR_ANY in WinSock) and it will bind to both adapters.

255.255.255.255 (INADDR_BROADCAST) is the broadcast address for your LAN segment.

Ferruccio
I can prove you wrong. I have a correctly set up host-switch combination that does NOT transport UDP broadcasts over 255.255.255.255. It's dangerous to rely on it.
Thorsten79
I'm surprised to hear that. Just to be clear, it's on a switch and broadcasts don't make it to other machines on that switch? It's not trying to broadcast across a router?
Ferruccio
Yes. I was completely surprised because on our development machines it worked just fine. On the test system it simply wouldn't work. I thought before that 255.255.255.255 would be a nice shortcut to avoid the system-dependent extraction of the broadcast address from the interface.See my EDIT please.
Thorsten79
Sorry, I was wrong. I double-checked.
Thorsten79
+2  A: 

You can see details of IP address space allocation at IANA, IANA IPv4 Address Space.

255.255.255.255 is "limited broadcast address" as stated in the link given by Johnatan, it does not cross routers and is a broadcast address for only the local network.

hayalci
+3  A: 

For a networking system we developed I have tried out all sorts of combinations of broadcast addresses between four different Linux IPv4 hosts and the hosts themselves (loopback device).

The reliable ways of sending UDP broadcasts that I have found:

  • SEND to subnet broadcast address, RECEIVE on subnet broadcast address
  • SEND to subnet broadcast address, RECEIVE on INADDR_ANY (0.0.0.0)
  • SEND to 255.255.255.255, RECEIVE on INADDR_ANY (0.0.0.0)

SEND to INADDR_ ANY + RECEIVE on INADDR_ANY only worked for the loopback device. INADDR_ANY is something you only want to use on the receiving side.

EDIT of EDIT: I double-checked my results on the servers where 255.255.255.255 did not work, and now I get the answers. Sorry.

Thorsten79
+2  A: 

Thorsten79 is correct about local network broadcasts - they should always be sent to the local network's specific broadcast address, not to 255.255.255.255. Unfortunately it's not trivial to work that address out programatically.

Note that until about a decade ago it was common for some systems to use the .0 address on a subnet as the broadcast address.

However some systems still incorrectly believe that any host addresses ending in .0 are not legal. Since the advent of Classless Inter-Domain Routing (CIDR) - i.e. variable length subnets, this no longer the case. It is perfectly legal to have a host address (i.e. /32) that ends in .0, but you may have problems reaching some of the rest of the internet (e.g. microsoft.com)

Alnitak
A: 

They're totally orthogonal concepts.

All of 0.0.0.0/8 is reserved for exclusive use in the source address field of the IPv4 header. It's the universal self-address, and it may not appear in the destination field. See RFC 1700. The 255.255.255.255 broadcast address is reserved by RFC 919 for link-local broadcast destinations. It must not appear in the source address field, and packets sent to that destination must not be forwarded by IPv4 routers.

james woodyatt