Search code examples
networkingporticmp

How can ICMP not use a port, but TCP/IP does?


For a protocol such as ICMP, it doesn't need a port. Why then, do various TCP and UDP applications need a port assigned to it? What would be the downside of having just a single port and then something like an application name to route to the correct place -- for example, instead of "3306" it would go to one port and have the application="mysql" tag?


Solution

  • A port is an address for some transport-layer protocols, specifically, TCP and UDP use port numbers. Both TCP and UDP use the same range of port numbers (0 to 65535) because they each use a 16-bit unsigned integer for the port number, but they are not the same ports; TCP port 12345 is not the same port as UDP port 12345. Other transport protocols use other addressing, or no addressing at all.

    For example, this is how RFC 793, Transmission Control Protocol defines a port:

    To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host.

    ICMP is not a transport protocol, it is an integral part of IP. This is how RFC 792, Internet Message Control Protocol states it:

    ICMP, uses the basic support of IP as if it were a higher level protocol, however, ICMP is actually an integral part of IP, and must be implemented by every IP module.

    It goes back to the network layers and how each layer chooses where to send the payload of the layer datagram. For example, an ethernet header has the Ether Type field that tells ethernet where to send the payload of the ethernet frame. Different protocols will register with the ethernet module. IPv4 uses the Ether Type 0x800 and IPv6 uses Ether Type 0x86DD. Here is the list of registered Ether Types.

    IPv4 has the Protocol field (IPv6 uses the Next Header field for the same thing) that tells it where to send the packet payload. ICMP is protocol number 1, UDP is protocol number 17, and TCP is protocol number 6. A protocol will register with the IP module to tell it where to send the payload of the packet. Here is the list of registered protocol numbers.

    In the same way, some transport protocols allow applications to register with the transport protocol so that the transport protocol knows where to send the payload of the transport datagram. For example, an HTTP server will, by default, register with TCP for its port 80, but that can be modified.