LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2018, 12:28 AM   #1
ghhbak
LQ Newbie
 
Registered: May 2018
Posts: 9

Rep: Reputation: Disabled
Extract dhcp option from dhcp ack packet in udhcpc


Hi - I'm using udhcpc which comes with busybox 1.23.2 to support networking on my embedded board. I'm able to obtain dynamic IP address from a DHCP server.

The script /lib/netifd/dhcp.script is run and within it the setup_interface function. Can someone help me understand how to collect and access the TFTP server address value (by using a script variable) which comes in the DHCP ack packet as option 150?
 
Old 05-17-2018, 05:20 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,693

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
There were some recent changes to udhcpc that is supposed to automatically create environment variables for known simple options. I have not examined to see if would work for option 150. Otherwise as far as I know you need to add the option to the options.c file and recompile.

https://git.busybox.net/busybox/

https://git.busybox.net/busybox/plai...c?h=1_9_stable
https://udhcp.busybox.net/README.udhcpc
 
Old 05-17-2018, 09:03 PM   #3
ghhbak
LQ Newbie
 
Registered: May 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks for your response. I'm on version 1.23.2 as mentioned earlier, and there is no longer an options.c file. The documentation is outdated for a long time.
 
Old 05-18-2018, 02:28 AM   #4
ghhbak
LQ Newbie
 
Registered: May 2018
Posts: 9

Original Poster
Rep: Reputation: Disabled
SOLVED

I finally figured out what is to be done. First, need to add a new macro in the list of option codes in common.h. I added it as '#define DHCP_OPTION_150 0x96'. Next, in dhcpc.c, a small code block needs to be added in udhcpc_main() and under the code block for DHCPACK, to extract the IP address:
temp = udhcp_get_option(&packet, DHCP_OPTION_150);
if (!temp) {
bb_error_msg("error: couldn't get opt 150");
} else {
uint32_t tftp_ip;
move_from_unaligned32(tftp_ip, temp);
tftp_ip = ntohl(tftp_ip);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Packet parser to extract DHCP options from the DHCP ack packet ghhbak Linux - Newbie 4 05-17-2018 08:24 AM
udhcpc can’t pick hostname→ip table from DHCP server fargred Linux - Networking 2 01-10-2014 06:43 AM
[SOLVED] what DHCP SERVER do when receive a dhcp release packet from client arnold.king Linux - Networking 2 04-17-2013 11:39 AM
sometimes udhcpc cannot NEVER grab dhcp ip address unless reboot 5883 Linux - Embedded & Single-board computer 1 10-09-2012 01:41 PM
why DHCP client not sending own host name in DHCP request packet? sonika_singhi Linux - Networking 7 05-28-2005 05:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration