Muhammad Salman
Muhammad Salman

Reputation: 35

Port Numbers in IPv4 & IPv6 is 16bits unsigned binary number so, each one is in range of 1 to 65535 (0 is reserved)

We all know that Port numbers in IPv4 and IPv6 are 16 bits wide so the range should be 0 to 65535, But I have heard that 0 is excluded and reserved for something else, This range is now 1 to 65535.

I want to know for what purpose it is reserved and for what purpose?

Upvotes: 1

Views: 460

Answers (2)

ice05
ice05

Reputation: 529

Port 0 is used as a "wildcard" port, meaning that when an application tries to create a socket and bind() it to an IP address, and supplies 0 as the port, the OS automatically binds the socket to a random available ephemeral port.

This is useful when applications need to send data and do not care which port it is sent from. This ensures that applications do not need to constantly try to find a suitable port manually.

The OS is powerful, so let it do (some of) the work for you.

Upvotes: 4

Sam Cross
Sam Cross

Reputation: 278

According to this article:

Port 0 is a wildcard port that tells the system to find a suitable port number.

Upvotes: 0

Related Questions