Discussion:
dhclient dhcpctl usage
Boaz Ben-David
2012-01-08 18:55:37 UTC
Permalink
Hi,

I need to control the dhcp daemon using c/c++.
Can I do this using dhcpctl? I saw a mention of this in the dhclient man page but I could not find any example of this.
Ed Ravin
2012-01-09 03:49:06 UTC
Permalink
Post by Boaz Ben-David
I need to control the dhcp daemon using c/c++.
Can I do this using dhcpctl? I saw a mention of this in the dhclient man page but I could not find any example of this.
Here's an example - the "omcmd" utility provides a command-line
interface to the API:

http://freecode.com/projects/omcmd

Attached is a patch for a problem with bad processing of dates
on Intel platforms that you'll probably want. Also, the docs
in the package are a bit out of date, they refer to a problem
(not able to free leases via the API) that has since been (somewhat
circuitously) fixed in the server.
Boaz Ben-David
2012-01-09 09:18:38 UTC
Permalink
Post by Ed Ravin
Post by Boaz Ben-David
I need to control the dhcp daemon using c/c++.
Can I do this using dhcpctl? I saw a mention of this in the dhclient man page but I could not find any example of this.
Here's an example - the "omcmd" utility provides a command-line
http://freecode.com/projects/omcmd
Attached is a patch for a problem with bad processing of dates
on Intel platforms that you'll probably want. Also, the docs
in the package are a bit out of date, they refer to a problem
(not able to free leases via the API) that has since been (somewhat
circuitously) fixed in the server.
Hi and thanks for the reply.

It seems this program provides functionality similiar to omshell, that
can only help in case of

a DHCP server configuration (as far as I understood). What I need is a
programmatic way to control a running

DHCP client daemon.

If I misunderstood and omshell and omcmd can also control the DHCP
client daemon I will be more than happy to

know.


Thanks,

Boaz.
Ed Ravin
2012-01-09 16:57:17 UTC
Permalink
On Mon, Jan 09, 2012 at 11:18:38AM +0200, Boaz Ben-David wrote:
... [regarding omcmd]
Post by Boaz Ben-David
It seems this program provides functionality similiar to omshell,
that can only help in case of
a DHCP server configuration (as far as I understood).
You seemed to be asking for examples of how to use the dhcpctl API, and
that's how omcmd implements the omshell-like functionality.
Post by Boaz Ben-David
What I need is
a programmatic way to control a running
DHCP client daemon.
What kinds of "control" are you looking for? Please be specific.
Boaz Ben-David
2012-01-09 19:26:14 UTC
Permalink
By control I mean requesting the dhcp client to renew a lease, release a lease, knowing that a lease was successfully squires etc...

Thanks,

Boaz.

Ed Ravin <***@panix.com> wrote:


On Mon, Jan 09, 2012 at 11:18:38AM +0200, Boaz Ben-David wrote:
... [regarding omcmd]
Post by Boaz Ben-David
It seems this program provides functionality similiar to omshell,
that can only help in case of
a DHCP server configuration (as far as I understood).
You seemed to be asking for examples of how to use the dhcpctl API, and
that's how omcmd implements the omshell-like functionality.
Post by Boaz Ben-David
What I need is
a programmatic way to control a running
DHCP client daemon.
What kinds of "control" are you looking for? Please be specific.
Ed Ravin
2012-01-09 20:21:37 UTC
Permalink
Post by Boaz Ben-David
By control I mean requesting the dhcp client to renew a lease,
release a lease, knowing that a lease was successfully squires
etc...
You can more or less do that with omcmd, omshell, or another dhcpctl-based
program, which will talk to the ISC DHCP server.

But the dhcpctl API is only for talking to the server, not the client. If
you want to mess with the ISC dhclient program, you can try killing the
running dhclient, edit its lease database (dhclient.leases) to change
what you want, and restart it.

---------

(excerpt from "man dhcpctl" below)

DESCRIPTION
The dhcpctl set of functions provide an API that can be used to
communicate with and manipulate a running ISC DHCP server.
Ed Ravin
2012-01-09 20:36:32 UTC
Permalink
Post by Ed Ravin
Post by Boaz Ben-David
By control I mean requesting the dhcp client to renew a lease,
release a lease, knowing that a lease was successfully squires
etc...
You can more or less do that with omcmd, omshell, or another dhcpctl-based
program, which will talk to the ISC DHCP server.
But the dhcpctl API is only for talking to the server, not the client. If
you want to mess with the ISC dhclient program, you can try killing the
running dhclient, edit its lease database (dhclient.leases) to change
what you want, and restart it.
Actually, you probably want to use "dhclient -r" on the client machine
to release the lease, and just restart dhclient to renew the lease.
Or hack your own dhclient code to do what you want. Just changing state
on the client side may get the client to do something but not necessarily
change the state on the server.
Boaz Ben-David
2012-01-10 07:01:40 UTC
Permalink
Post by Ed Ravin
Post by Ed Ravin
Post by Boaz Ben-David
By control I mean requesting the dhcp client to renew a lease,
release a lease, knowing that a lease was successfully squires
etc...
You can more or less do that with omcmd, omshell, or another dhcpctl-based
program, which will talk to the ISC DHCP server.
But the dhcpctl API is only for talking to the server, not the client. If
you want to mess with the ISC dhclient program, you can try killing the
running dhclient, edit its lease database (dhclient.leases) to change
what you want, and restart it.
Actually, you probably want to use "dhclient -r" on the client machine
to release the lease, and just restart dhclient to renew the lease.
Or hack your own dhclient code to do what you want. Just changing state
on the client side may get the client to do something but not necessarily
change the state on the server.
_______________________________________________
dhcp-users mailing list
https://lists.isc.org/mailman/listinfo/dhcp-users
The motivation is so I can control the dhcp client daemon from another
process written in C++.

For example, udhcpc (busybox's dhcp client) can be controlled using two
signals (one for renew and one for release).

My problem is that I can order udhcpc to renew, for example, but I don't
get any feedback as for the outcome of the

request. I want to be able to signal the client to renew and get a
result (success, fail, timeout...) in my C++ program.


If anyone has a better way of doing this I will be more than happy to hear.


Thanks,

Boaz.

Loading...