A question about ip_options's option type

Rami Rosen roszenrami at gmail.com
Sat Dec 14 12:52:51 EST 2013


Hi, Guibin,

Your example with SO_LINGER is not relevant as this is the SO_LINGER
option and not the generic IP_OPTION.

Please take a look at the ping implementation:
http://www.linux-ipv6.org/gitweb/gitweb.cgi?p=gitroot/iputils.git;a=blob;f=ping.c;h=c0366cdacd626dde1669bf2d97588eb7c6ece3fd;hb=HEAD


You have there:

       if (options & F_TIMESTAMP) {
492                 memset(rspace, 0, sizeof(rspace));
493                 rspace[0] = IPOPT_TIMESTAMP;
494                 rspace[1] = (ts_type==IPOPT_TS_TSONLY ? 40 : 36);
495                 rspace[2] = 5;

So for the type, byte 0, you have  IPOPT_TIMESTAMP
and for the length, you have 40 or 36 (It depends on ts_type)

Best Regards,

Rami Rosen
http://ramirose.wix.com/ramirosen



On Sat, Dec 14, 2013 at 3:00 AM, Guibin(Bill) Tian <gbtian at gmail.com> wrote:
> Hi, maybe it's a naive question. But I am confused here.
>
> For the options field of an IP header, as for the data in this field,
> according to document and the code in the method of "ip_options_compile",
> the first byte is  the options type data and the second byte is the length
> of the option. But I traced back the method of "ip_options_get_from_user",
> there is no place that assign these two values to the __data field.
>
> I checked some example of socket API "setsockopt", it also just converts the
> target options data pointer into a char * pointer and passes down to
> "ip_options_get_from_user", still it doesn't set these two values.
>
> Can anyone help me on this? Because I am trying to add my own options to IP
> header at the IP layer for some experiment purposes.
>
>
> struct linger linger = { 0 };
> linger.l_onoff = 1;
> linger.l_linger = 30;
> status = setsockopt(serverSocket,
> SOL_SOCKET, SO_LINGER,
> (const char *) &linger,
> sizeof(linger));
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



More information about the Kernelnewbies mailing list