problem with omapi
syhshanda
syhshanda at 126.com
Mon Jan 4 01:25:44 UTC 2010
Hi,
I tried this question several times, but nobody there seems interested.
The question was get the wrong time!The detail info was showed as following.
Thanks for your time!
Regards,
Bob
在2009-12-30 09:52:08,syhshanda <syhshanda at 126.com> 写道:
Greetings to the community!
Recently, I came cross the same problem, can anyone give some advice to me?
I'd really appreciate your help. Thanks for your time!!
Best Regards,
Bob
在2009-12-22 14:58:22,"劲草 " <brilliant_er at yahoo.cn> 写道:
Hi,
My version of dhcpd is 4.0.2b3.The OS is fedora-10 and environment of programming is
NetBeans-6.5.1. I use the following code to link dhcpd:
?#include <stdarg.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <isc-dhcp/result.h>
#include <dhcpctl/dhcpctl.h>
int main (int argc, char **argv) {
dhcpctl_data_string ipaddrstring = NULL;
dhcpctl_data_string value = NULL;
dhcpctl_handle connection = NULL;
dhcpctl_handle lease = NULL;
isc_result_t waitstatus;
struct in_addr convaddr;
time_t thetime;
dhcpctl_initialize ();
/* get connection with server */
dhcpctl_connect (&connection,
"211.87.239.28",7911, 0);
/* create a lease object */
dhcpctl_new_object (&lease, connection,"lease");
memset (&ipaddrstring, 0, sizeof ipaddrstring);
inet_pton(AF_INET, "211.87.239.238",&convaddr);
/* allocates a new dhcpctl_data_string object*/
omapi_data_string_new (&ipaddrstring,4, MDL);
memcpy(ipaddrstring->value, &convaddr.s_addr, 4);
dhcpctl_set_value (lease, ipaddrstring,"ip-address");
dhcpctl_open_object (lease, connection, 0);
/* wait for response from server */
dhcpctl_wait_for_completion (lease,&waitstatus);
if (waitstatus != ISC_R_SUCCESS) {
/* server not authoritative */
printf ( "Not successful ! \n");
//exit (0);
}
// deallocates a data string created by omapi_data_string_new()
dhcpctl_data_string_dereference(&ipaddrstring,MDL);
// extracts a value of an attribute from the handle
dhcpctl_get_value (&value, lease, "ends");
memcpy(&thetime, value->value, value->len);
dhcpctl_data_string_dereference(&value, MDL);
fprintf (stdout, "ending time is %s",ctime(&thetime));
}
In the dhcpd.leases file,the IP 211.87.239.238 detail info is following:
lease 211.87.239.238 {
starts 2 2009/12/08 07:23:44;
ends 3 2009/12/09 07:23:44;
tstp 3 2009/12/09 07:23:44;
cltt 2 2009/12/08 07:23:44;
binding state free;
hardware ethernet 00:01:6c:cb:93:e6;
}
Finally, when I run the code,but I get the error end time of lease:
?ending time is Wed Feb 12 23:26:35 1902
Thanks for you help!
Best Regards,
John
好玩贺卡等你发,邮箱贺卡全新上线!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-users/attachments/20100104/b7648ea8/attachment.html>
More information about the dhcp-users
mailing list