Dont understand the main in the code of dhclient.c

DÔ Phan-Cam-Thach dophancamthach at yahoo.co.uk
Tue Jul 15 10:25:55 UTC 2008


Thank you very much for your help.
I havent payed attention to the figure "State-transition diagram for DHCP clients" in rfc 2131 so that i didnt understand that. Your answer helped me much in reading the code. There are still some things that i haven't understood in the code. I'll try myself. If i will not be able, i'll ask for your helps.
Best regards.
Cam Thach.

 
DO Phan Cam Thach
email: dophancamthach at yahoo.co.uk



----- Original Message ----
From: Ted Lemon <Ted.Lemon at nominum.com>
To: "dhcp-users at isc.org" <dhcp-users at isc.org>
Sent: Tuesday, 8 July, 2008 12:48:42 AM
Subject: RE: Dont understand the main in the code of dhclient.c

> I have read the file dhclient.c, but i haven't found out where
> and how the main calls the majors functions for making, sending
> the messages DHCP like make_discover, send_discover,... or for
> treating the messages received from server like dhcpoffer,..

The thing you need to understand is that the code is not linear - it's event-driven.  So the DHCP client sets up all the state that's required to run, and then it sets up a timer that sends the first DHCPDISCOVER or DHCPREQUEST.  When the timer expires, typically in about a second, the timer expiry function calls the appropriate state_* function to send off a request.  When a packet comes in, the appropriate packet handling function is called.  If no packet comes in, another timer expires and triggers a retransmission, or else triggers a call to a different state_* function.

So you have to read the code with that idea in mind, not with the idea that you're following a single thread step by step from start to end.

One way to see how this happens is to run gdb on the DHCP client and watch what happens.  You will find that after all the main functions run, you wind up in select().  When select() returns, that means an event has happened.  If you continue to trace with gdb, you will see which event happened, and how it was processed.


      __________________________________________________________
Not happy with your email address?.
Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-users/attachments/20080715/416ae623/attachment.html>


More information about the dhcp-users mailing list