4

I didn't find any information about this on the Internet, because every website was just stating that it is in there, but never why.

One thought I had is that the router can identify in which network segment the sender is, so it can redirect the packet faster, but I don't know if that's true...

18

So the destination node knows which address to specify in the destination field when responding to the sender.

11

Primarily, so nodes along the path know where to send any error messages.

For the most part, IP is a bidirectional protocol. As such, there must be a sender and receiver.

  • Indeed, even when a reply is not required or even desired at higher levels (e.g., udp; think of snmp traps or syslog) the underlying ip level needs the sender for potential icmp messages triggered – Hagen von Eitzen Jun 30 '15 at 17:26
9

In addition to what Ron and Ricky have mentioned (the recipient needing to know who to respond to and nodes along the way needing to know where to send any ICMP messages,) TCP connections are identified by the unique 4-tuple of source IP address, destination IP address, source port number, and destination port number. Without the source IP address, the receiver's TCP stack wouldn't know which stream a particular incoming packet belonged to. The same is true, of course, for UDP or any other transport-layer protocol that supports having multiple remote hosts sending packets to the same transport-layer protocol and transport-layer protocol stream identifier (e.g. port number.)

Consider, for example, a web server. It listens for incoming packets on the server's TCP port 80. However, all of the clients connected to that server will be sending their packets to port 80 on the IP address of the web server. Additionally, there's no guarantee that the source port number will be different between clients on different computers. As such, without the source IP address being in the packet, the TCP stack doesn't know which of the connections to port 80 any given incoming packet belongs to and, thus, doesn't know which stream (socket) its payload should be delivered to. Additionally, it wouldn't know which receive window, etc. to use, since it wouldn't be able to uniquely identify which connection the packet belongs to.

Also, while this is not the reason for the design, an additional place where this becomes useful is in NATs. NATs use a 5-tuple to uniquely identify which connection incoming packets belong to, source IP address, source port, destination IP address, destination port, and transport-layer protocol (e.g. TCP or UDP.) Again, without all of that information, the NAT would be unable to uniquely identify the stream and, thus, wouldn't know which internal address/port it should forward the packet to.

  • IP is a step above TCP (and UDP). If a protocol needs more than IP provides (eg. port, sequence number, connection id), it's up to the protocol to add it. IP has a src and dst address to do what it needs to do. – Ricky Beam Jul 1 '15 at 5:03
  • @RickyBeam Well, below in the normal way of looking at the protocol stack. Anyway, I was using TCP as an example and, as I mentioned, this applies equally to any transport-level protocol that would need to demux packets from different sources arriving at the same port number, not just TCP. I'm sure IP was designed with that need in mind (in addition to its own internal needs which you and Ron already covered.) From a conceptual point of view, while the transport-layer needs to know the sender's network address, that data still decidedly belongs in the network-layer protocol (IP in this case.) – reirab Jul 1 '15 at 9:53
  • 1
    @RickyBeam In this particular instance, it's probably worth noting that much of the original design for TCP actually predates IP and the TCPv4 standard was developed in parallel with the IPv4 standard by the same group (USC for DARPA, both RFCs released in Sept 1981.) Each protocol is explicitly referenced throughout the RFC of the other. – reirab Jul 1 '15 at 10:16
6

Both Ricky and Ron are correct. IP packets have a source and a destination. The device at the destination uses the source address to determine where to send replies to, and if there is an error along the way the routers will use the source address of the packet to send error messages to.

  • 3
    Or to use an analogy: the two exact same reasons why you'd put a sender's address on an envelope you send through the post office. – jpa Jul 1 '15 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.