Ernesto81 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I would like to set IPOPT_LSRR with one hop (code sample with one hop) :

my $_hop = inet_aton $hop; my $_end = inet_aton $end; my $_header = pack "C4", &NOP, &LSRR, $length, $ptr; my $ipOpt = $_header . $_hop . $_end; setsockopt S, IPPROTO_IP, IP_OPTIONS, $ipOpt;

This is not working properly. The connection is successfully established, but cannot see the IP options with wireshark (and it is not performing LSRR).

Do you have any suggestion, please?

Since inet_aton return a "32 bits" in_addr C like opaque string (or at least, this is what I am supposing), pack is not being used, instead hops are just appended, so, how could I invoke getsockopt and, using unpack, print out the different hops back?

Thanks in advance and kind regards,

Ernesto

Replies are listed 'Best First'.
Re: loose source and route record
by Ernesto81 (Novice) on Feb 01, 2011 at 02:52 UTC

    Hi again,

    Issue is solved and now LSRR works fine (solution posted here, maybe it could help) :

    For the first question, why setsockopt fails (solution for 1 hop) :

    my $_hop = inet_aton $hop ; my $_end = inet_aton $end ; my $_length = "11"; my $_pointer = "4"; my $_header = pack "C3", &LSRR, $_length, $_pointer; my $_ipOpt = $_header . $_hop . $_end; setsockopt S, IPPROTO_IP, IP_OPTIONS, $ipOpt;

    Problem was NOP (used for four-byte boundary alignment). Perl is helping us doing the alignment by itself, BUT, pay attention to length and pointer. Now lenght is 11 bytes, but pointer is 4, otherwise it fails.

    If you want to use it, just put it in between socket and connect in a TCP client.

    For the second question, how to do the inverse, using getsockopt and unpack, here is one possible solution :

    $_ipOpt = getsockopt S, IPPROTO_IP, IP_OPTIONS; ( my $_lsrr, my $_length, my $_ptr, my $_hop1, my $_hop2 ) = unpack "C +3 a4 a4", $_ipOpt; my $hop1 = inet_ntoa $_hop1; my $hop2 = inet_ntoa $_hop2; print STDOUT "### hop1 : $hop1 ; hop2 : $hop2 \n";

    Kind regards

    Ernesto

Re: loose source and route record
by Anonymous Monk on Jan 31, 2011 at 13:02 UTC
    Please post complete code

      Hi Anonymous Monk,

      Attached below there is a script that reproduces the situation (tested and working (the script, no LSRR option ... ) ) :

      #!/usr/bin/perl use strict;

      Kind regards,

      Ernesto

        Um, how is it complete without dataStruct? Your question is about setsockopt , but the data you give setsockopt is undefined