[Kea-users] Reading and parsing sub-options

Ola Thoresen ola at nytt.no
Mon Feb 1 10:10:16 UTC 2016


Sorry to bother you with such a trivial (probably) question, but my C++ 
is not really good, and I need some help to get along with this project.

My goal is to take one of the values from suboption #2 in an Option 82 
and insert it into a suboption in Option 43 in the DHCP-reply.

So I receive a DHCP-reuqest with Option82-2 set to something like 
"customer-number-cpe-id" (IE "104523-01") and I need to add that string 
to the outgoing reply.
- That way, the CPE will be instructed to download its customzed config 
file on boot.

So far, I have managed to modify the example-hook, so I can actually 
read the Option 82 and 43-values with the following code added to the 
pkt4_send.cc:

         OptionPtr option82_ptr = response4_ptr->getOption(82);
         OptionPtr option82_1_ptr = option82_ptr->getOption(1);
         OptionPtr option82_2_ptr = option82_ptr->getOption(2);

         OptionPtr option43_ptr = response4_ptr->getOption(43);
         OptionPtr option43_1_ptr = option43_ptr->getOption(1);

And I can log the raw options to the "interesting" file by

         string option82_1_data = option82_1_ptr->toString();
         string option82_2_data = option82_2_ptr->toString();
         string option43_1_data = option43_1_ptr->toString();

         // Write the information to the log file.
         interesting << hwaddr << " " << ipaddr << " " << 
option82_1_data << " " << option82_2_data << " " << option43_1_data << "\n";


However, I just can't figure out how to get the actual value of the 
options, not the complete binary data, including length and type.
So the string in the log looks like:

type=001, len=017: 41:43:58:2d:30:32:3a:67:65:2d:30:2f:30:2f:34:2e:30

I could ofcourse strip the first 19 bytes from the string, and then do a 
manual character-conversion of each of the numeric values, but I guess 
(hope?) there is an easier way to get the textual value of an option.

I have tried to understand how getValue() and the other functions should 
be applied, but so far I have had no luck.

So if someone could point me in the right direction, I will hopefully be 
able to get this hook working.



Rgds.

Ola Thoresen



More information about the Kea-users mailing list