IP Datagrams gets routed dynamically in the sense, we cannot precisely predict which path every IP Datagram will take to reach the destination. Some times you may need to
fix the path[ a set of routers] through which the IP Datagram must travel to reach the destination. IP Source Routing helps you to accomplish this.
Source Routing is a technique, through which you set a list of Router’s IP addresses [Pre Configured Path], so that the IP datagram which gets sent out follows the path
which you are providing and reaches the destination.
Loose Source Routing:
Here you provide a list of IP addresses, but the datagram may take an alternative path to reach the destination.
Strict Source Routing:
Here you provide a list of IP addresses and the IP Datagram MUST pass through the provided IP Address list.
The above code injects the two IP addresses "a.b.c.d" and "x.y.z.q" into every IP Datagrams IP options header which are sent out using the socket . Now the IP Datagram
has the following things:
a) Source IP address
b) Destination IP address
c) IP options field in the IP header containing "a.b.c.d" and "x.y.z.q"
Here is how it works:
1) The actual Destination Address is replaced with "a.b.c.d" and the IP Datagram is pushed out to "a.b.c.d"
2) "a.b.c.d" will receive the datagram and replaces the destination address again with "x.y.z.q" and pushes the IP datagram to "x.y.z.q"
3) "x.y.z.q" will receive the datagram and replaces the destination address with the actual destination address and pushes the IP datagram to the intended destination.