problem with omapi
劲草
brilliant_er at yahoo.cn
Tue Dec 22 06:58:22 UTC 2009
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 */
status = dhcpctl_connect (&connection, "211.87.239.28",7911, 0);
/* create a lease object */
status = 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*/
status = omapi_data_string_new (&ipaddrstring,4, MDL);
memcpy(ipaddrstring->value, &convaddr.s_addr, 4);
status = dhcpctl_set_value (lease, ipaddrstring,"ip-address");
status = dhcpctl_open_object (lease, connection, 0);
/* wait for response from server */
status = 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()
status = dhcpctl_data_string_dereference(&ipaddrstring,MDL);
// extracts a value of an attribute from the handle
status = 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
___________________________________________________________
好玩贺卡等你发,邮箱贺卡全新上线!
http://card.mail.cn.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.isc.org/pipermail/dhcp-users/attachments/20091222/526ee48e/attachment.html>
More information about the dhcp-users
mailing list