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?
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).
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.
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.
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.
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 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)
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.