I was asked a question my one of my teachers. What is TCP port 0 reserved for? I did a bit of searching and research found 2 reasons:
For linux based system, to get the next available port from the OS that the program can use. Like asking for dynamically allocated ports.
Packets that don't need port numbers (like ICMP) use port number 0 in their packet.
But these seemed like something that has evolved to be used for, just because port 0 was not being used for anything else. I did not find any use of port 0 that was assigned by 'IANA' in the beginning. Is there anything that was officially assigned to port 0?
sockaddr_in
, orsockaddr_in6
structure, which require you to fill a port number even if in the end the socket type isSOCK_RAW
. So maybe this is where the confusion occurs.