LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2018, 06:00 PM   #1
eztoril
LQ Newbie
 
Registered: Jan 2018
Posts: 2

Rep: Reputation: Disabled
How to build and use dhcpctl?


Hi,

My name is Martin. I have a Linux system where I have started the standard ISC DHCP client ('dhclient'). This client aims to contact a DHCP server on my network to get leases/addresses etc. I.e. plain DHCP usage.

Now, I want to monitor and retrieve information/addresses from the DHCP client ('dhclient'), add/remove interfaces of the DHCP client etc., from a C program that I have written myself.

Reading the man pages, I read about 'dhcpctl' as a static lib (dhcpctl.a) that should function as an API towards my 'dhclient'. Thus, the idea is to link the 'dhcpctl' lib into my own C program and then use the API functions described in:

https://linux.die.net/man/3/dhcpctl

...in order to get addresses, lease times, create new interfaces, delete interfaces etc. I.e. fully manage the 'dhclient', according to my needs (I don't exactly know whether the API functions listed are sufficient, but I assume so).

However, when reading the man-text in the link, it says:

"The dhcpctl set of functions provide an API that can be used to communicate with and manipulate a running ISC DHCP server."

...i.e. they mention 'ISC DHCP Server', not DHCP client. Do they actually mean DHCP Server only or is this also applicable to 'dhclient'? If both, any difference in API/usage?

Somewhat contradictory, the man pages of 'dhclient' mentions:

"The DHCP client provides some ability to control it while it is running, without stopping it. This capability is provided using OMAPI, an API for manipulating remote objects. OMAPI clients connect to the client using TCP/IP, authenticate, and can then examine the client's current status and make changes to it.
Rather than implementing the underlying OMAPI protocol directly, user programs should use the dhcpctl API or OMAPI itself. Dhcpctl is a wrapper that handles some of the housekeeping chores that OMAPI does not do automatically."


...which talks in favor of what I want to do here - use 'dhcpctl' lib to communicate with the 'dhclient' (which 'under the hood' seems to use omapi).

Could anyone explain the confusion above?

Do you think 'dhcpctl' lib will work as the suitable API lib fulfilling my communication needs to/from my own program towards the 'dhclient'?

------------------------

Second part:

When building the 'dev' package of dhcp, I get these three static libs:

* dhcpctl.a
* omapi.a
* dst.a

However, when I'm linking all these into my own C program, it still lacks some functions, some 'dst_*' functions, some 'dns_*' functions etc.

Indications gives by hand that I need to also link some BIND lib into my C program as well! Is that true? If yes, howcome the 'dev' package does not produce all the libs needed for my purpose? It sounds very suspicious and makes me feel it is something wrong here?

I am very greatful if someone could please enlight me here?

Thanks in advance!

BR Martin
 
Old 01-09-2018, 01:31 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Welcome to LQ!

I am not sure I fully understand your question, but you seem to be interested in interacting with a dhclient, not the DHCP server.

From man dhclient:

Code:
OMAPI
       The DHCP client provides some ability to control it while it is  running,  without  stopping  it.   This
       capability  is  provided  using OMAPI, an API for manipulating remote objects.  OMAPI clients connect to
       the client using TCP/IP, authenticate, and can then examine the client's current status and make changes
       to it.

       Rather  than  implementing  the underlying OMAPI protocol directly, user programs should use the dhcpctl
       API or OMAPI itself.  Dhcpctl is a wrapper that handles some of the housekeeping chores that OMAPI  does
       not  do  automatically.  Dhcpctl and OMAPI are documented in dhcpctl(3) and omapi(3).  Most things you'd
       want to do with the client can be done directly using the omshell(1)  command,  rather  than  having  to
       write a special program.
Perhaps smeone more familiar with use of DHCP libs than myself will jump in here, but it would be helpful if you could provide a more specific example of the interaction you want to provide, noting in particular the code objects interacting and the hosts on which they reside.
 
Old 01-09-2018, 04:42 PM   #3
eztoril
LQ Newbie
 
Registered: Jan 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi,

Yes, I want to interact with the 'dhclient' from within my own C program, retrieve information from it and control it.

To be more specific, I give typical use cases:

The 'dhclient' interacts using DHCP protocol with the external DHCP server for a specific external interface. From that interaction, the 'dhclient' retrieves address to be assigned to the external interface. However, I want my C program to also learn this leased address that was set on the interfaces by the client. Thus my plan is to use the 'dhcpctl' lib/API to interact with the 'dhclient', asking for the address of the specific external interface.

Of course I can write my program to e.g. use 'omshell' to do the same thing and parse its result or e.g. let my program to parse the output of 'ifconfig' command to learn the address in that way instead, but in my opinion a much nicer way would be to use the 'dhcpctl' lib to extract the address from the client.

In addition, the dhclient could perhaps (through the API) inform my C program when a new address is learned and to which interface it belongs. That would be great as an alternative to polling each interface from my program.

Some other use cases would e.g. be to let my C program to retrieve run-time info from the 'dhclient' (while it is running), for statistical purposes.
Or signal to the dhclient that its config file(s) have been updated and it should therefore re-read them. (of course this can also be fulfilled by just kill the client and re-spawn it again, but again, it would be nicer to use the API).

Hope this explains better my ideas.

Will 'dhcpctl' lib allow me to fulfill the use cases described above?

Thanks in advance.

BR Martin
 
  


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
Call for Testers: Comparison of MATE 1.14 (mix build vs fully GTK+3 build) willysr Slackware 33 05-10-2016 03:40 PM
[SOLVED] Linux 4.4 seems to refuse to build IPv6 for the 64-bit build - 32-bit build works fine GameCodingNinja Linux From Scratch 2 02-07-2016 06:40 PM
SBOPKG(8) not list/show/build dependencies of SlackBuild scripts to build Slackware p xavi_slacky Slackware 3 06-13-2013 07:53 PM
[SOLVED] DHCPCTL : how to use it zelycorn Programming 7 08-02-2011 09:10 AM
LXer: Build 'em Right, Build 'em Strong, Build 'em Linux LXer Syndicated Linux News 0 10-01-2007 09:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

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