Windows SDK Support Team Blog

#define _WIN32_WINNT

How to programmatically inject a list of IP Addresses into the IP Options header in the IP Datagram [ Source Routing ]?

How to programmatically inject a list of IP Addresses into the IP Options header in the IP Datagram [ Source Routing ]?

  • Comments 2

   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:
============
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.

   1: \\Define a structure for LSR
   2: typedef struct
   3: {
   4: unsigned char Code;
   5: unsigned char Len;
   6: unsigned char Offset;
   7: unsigned long Addrs[2];
   8: }LSR; 
   9:  
  10: //Set the Loose Source Routing Option:
  11: LSR SourceRoute;
  12: ZeroMemory(&SourceRoute,sizeof(LSR)); 
  13:  
  14: SourceRoute.Code = 0x83; // Loose Source Routing.
  15: SourceRoute.Len = 11;
  16: SourceRoute.Offset = 4;
  17: SourceRoute.Addrs [0] = inet_addr("a.b.c.d");
  18: SourceRoute.Addrs [1] = inet_addr("x.y.z.q"); 
  19:  
  20: //Set the source routing on the socket handle.
  21: int iErr = setsockopt(SocketHandle,IPPROTO_IP,IP_OPTIONS,(char*)&SourceRoute,SourceRoute.oLen); 
  22:  

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.

 

-Balajee P

Windows SDK

Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post
  • So I tried the above example on a Windows XP Pro SP3 machine and captured the packets with Wireshark and there are no IP options in any of the packets.  I also tried this with the Record Route and a couple of other options with similar results.  setsockopt() completed successfully and getsockopt() returns the filled in options, but they are not being added to outgoing packets.  Am I missing something?  Is there something else that needs to be configured?  I would really like to see this working.

    Thanks.

  • Brandon,

         I also observed the same behavior with Windows XP while testing the above program in the past.There might be issues with LSR/SSR implementation in Windows XP. You should not see the problem in higher versions of OS like

    Vista. If you want to accomplish source routing in windows XP, you could try using raw sockets to craft your own IP packet, but I have to agree that this workaround is more painful to implement :(

    Thanks,

    Balajee

Page 1 of 1 (2 items)