2

Of course we need to specify source port and destination port but besides that, why do we need UDP when we could just send IP packets with the same payload?

I'm not asking why I can't do it. I want to know what the need for the UDP protocol was.

gotthecodes
  • 273
  • 3
  • 12
  • here is similar a question ["UDP vs IP- difference?"](https://stackoverflow.com/questions/7463808/udp-vs-ip-difference). Maybe you find it interesting. – Neyroman Nov 09 '17 at 15:06

2 Answers2

4

why do we need UDP when we could just send IP packets with the same payload?

  1. IP packets have no end-to-end error detection mechanism. IPv4 has a checksum that covers only its header, so the data is protected only by the layer 2 error detection, which isn't end-to-end. Both UDP and TCP use a checksum to check the data for errors end-to-end.

  2. Once the destination machine receives such an IP packet, which application should it pass it to? We need a way of identifying the destination app (socket actually, but never mind) of a specific message. UDP and TCP do that with port numbers. Having no port number is similar to sending a postal package to an apartment building without specifying which apartment it should be given to.

Malt
  • 28,965
  • 9
  • 65
  • 105
  • ha, nice! I didn't take integrity into consideration. – Marcus Müller Nov 07 '17 at 21:35
  • 2
    @MarcusMüller, IPv6 has even done away with any integrity checking, leaving that up to the lower and upper layers, and it makes the UDP CRC, which is optional for IPv4, a requirement for IPv6. – Ron Maupin Nov 07 '17 at 22:04
3

With raw IP packets, there could only be one dedicated listening socket per IP address. IP addresses identify hosts on the network layer, enabling traffic to reach some physical device, a "host".

As soon as you want to have different "destinations" (i.e. applications) on the same host, you need something like the ports concept that TCP and UDP have.

For this reason we need a protocol atop of IP; this aligns well with the layered network stack model. UDP is pretty much a minimal protocol to support ports.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94