dhclient dhcpctl usage
Ed Ravin
eravin at panix.com
Mon Jan 9 03:49:06 UTC 2012
On Sun, Jan 08, 2012 at 08:55:37PM +0200, Boaz Ben-David wrote:
> 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.
-------------- next part --------------
--- omfuncs.c 2011/11/07 06:38:10 1.1
+++ omfuncs.c 2011/11/07 06:46:59
@@ -174,8 +174,9 @@
case op_cltt:
strptime(val, "%a %b %d %T %Y", ×truct);
timeval=mktime(×truct);
+ netint=htonl((unsigned long)timeval);
omapi_data_string_new(&value, 4, MDL);
- memcpy(value->value, &timeval, 4);
+ memcpy(value->value, &netint, 4);
break;
case op_name:
case op_client_hostname:
@@ -215,8 +216,9 @@
case op_tstp:
case op_tsfp:
case op_cltt:
- memcpy(&thetime, value->value, value->len);
- ctime_r(&thetime,buf);
+ memcpy(&netint, value->value, value->len);
+ hostint=ntohl(netint);
+ ctime_r((time_t *) &hostint,buf);
buf[strlen(buf)-1]='\0';
break;
case op_ipaddr:
More information about the dhcp-users
mailing list