Reputation: 77
What is the use of source address in IP header? Isn't network layer only concerned with forwarding packets to the destination address using the routing table?
Upvotes: 1
Views: 1397
Reputation: 16338
How would you send a confirmation if you don't know where you should send it to?
Protocols like TCP and ICMP need that.
Those protocols don't need to transmit the source address if it is stored in the IP header.
For example, TCP does not explizitly store the source address but the source (and destination) port. It is also easier to read if the source and destination address are transmitted one after another and not in different headers.
Nearly every protocol needs the source address in any case.
Lots of high-level protocols like HTTP need to send content back to the user who originally sent the packet(s).
Those protocols would have to send the senders IP too.
The source address is also needed if the packet can't be transmitted and an error response is sent back.
Upvotes: 2
Reputation: 41
Indeed the packet would be sent to the destination and routed correctly even without its original source address. You would not be able to leave the source address field empty as it will change the length of the header, at least you need to have some IP address. This field must be exactly 32 bits long for IPv4 (RFC791) and 128 bits for IPv6 (RFC8200) so no zero-length fields are allowed.
Whether the packet reaches its destination depends on the infrastructure in between. It is absolutely possible that the destination receives the packet, provided that there is no some firewall or other filter to drop the packet if it sees it as illegal, which some firewalls do.
To answer why it is needed, usually in two way communication you need to mention where the receiver should send the response.
In case you don't want to get a response then you might not care if the receiver knows the source address of the packet or not. In that case you can spoof the true source address and send the packet with any address you want, as long as you don't divert from the protocol specification.
However this would be an exception rather than the rule. Thus most protocols are designed to be used for (or at least to support) two way communication and the source address field is built into their specification.
Upvotes: 2