LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-01-2011, 08:05 AM   #1
zelycorn
Member
 
Registered: May 2011
Posts: 48

Rep: Reputation: 0
DHCPCTL : how to use it


Hello,

i would like to implement dhcpctl in a program to manipulate dhcp leases.

It doesn't work and there are errors at compilation :

/tmp/ccYPRIt5.o: In function `LeaseCleaning(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
pxe.cpp.text+0x133a): undefined reference to `dhcpctl_initialize()'
pxe.cpp.text+0x1352): undefined reference to `dhcpctl_connect(__omapi_object**, char const*, int, __omapi_object*)'
collect2: ld returned 1 exit status

Code:
#include <stdarg.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <isc-dhcp/result.h> 
#include <dhcpctl.h>
#include <omapip/omapip.h>

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 (); 
	dhcpctl_connect (&connection, "127.0.0.1", 9991, 0); 
	//hcpctl_new_object (&lease, connection, "lease");
g++ -o /home/ff/pxe /home/ff/pxe.cpp -I/usr/include/libxml2 -ldhcpctl -lomapi -ldst

Last edited by zelycorn; 08-02-2011 at 09:11 AM.
 
Old 08-01-2011, 10:34 PM   #2
gregvp
LQ Newbie
 
Registered: Dec 2006
Distribution: ARCH Linux
Posts: 15

Rep: Reputation: 2
The compiler is not finding dhcpctl.h. As the code is written it expects to find it in /usr/include/.
 
Old 08-02-2011, 01:48 AM   #3
zelycorn
Member
 
Registered: May 2011
Posts: 48

Original Poster
Rep: Reputation: 0
It is not so easy :
locate dhcpctl.h
/usr/include/dhcpctl.h

I'have already checked this.
 
Old 08-02-2011, 01:58 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Quote:
The compiler is not finding dhcpctl.h.
No, actually the error says that the LINKER isn't finding dhcpctl_initialize() or dhcpctl_connect().

The OP seems to be linking the correct library, "-ldhcpctl".

It's entirely possible the library is somehow invalid, or missing these symbols. It wouldn't hurt to run "nm libdhcpctl*|less" to see if these symbols are defined in the library.

It also might not hurt to try re-installing the package (library and headers).

One final test would be to write a standalone "C" program (instead of C++), invoke dhcpctl_initialize() and dhcpctl_connect(), build it with "gcc" (instead of g++) and see if it fails the same way.
 
Old 08-02-2011, 02:12 AM   #5
zelycorn
Member
 
Registered: May 2011
Posts: 48

Original Poster
Rep: Reputation: 0
I will try to compile a c program with only dhcpctl includes and functions.
 
Old 08-02-2011, 02:57 AM   #6
zelycorn
Member
 
Registered: May 2011
Posts: 48

Original Poster
Rep: Reputation: 0
A test in c :

gcc -o test -L/usr/lib64/ -ldst -lomapi -ldhcpctl -I/usr/include/ test.c
/tmp/ccW17ihL.o: In function `main':
test.c.text+0x29): undefined reference to `dhcpctl_initialize'
test.c.text+0x41): undefined reference to `dhcpctl_connect'
collect2: ld returned 1 exit status

Code:
#include <stdio.h>
#include <stdlib.h>

#include <stdarg.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <isc-dhcp/result.h>
#include <dhcpctl.h>
#include <omapip/omapip.h>


main () {

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 ();
  dhcpctl_connect (&connection, "10.47.35.5", 9991, 0);
  //hcpctl_new_object (&lease, connection, "lease");
fflush(stdout);
}
 
Old 08-02-2011, 03:27 AM   #7
zelycorn
Member
 
Registered: May 2011
Posts: 48

Original Poster
Rep: Reputation: 0
I also copied libdhcpctl.a and libdest.a from /usr/lib64 to /usr/lib.
 
Old 08-02-2011, 09:10 AM   #8
zelycorn
Member
 
Registered: May 2011
Posts: 48

Original Poster
Rep: Reputation: 0
So i know how to deal with dhcpctl by now :

only use c and not c++ thanks to paulsm4 !

gcc /root/test.c -o test -ldhcpctl -lomapi -ldst

cp /root/test.c /root/test.cpp
g++ /root/test.cpp -o test -ldhcpctl -lomapi -ldst
/tmp/ccuTsGfJ.o: In function `main':
test.cpp.text+0x9): undefined reference to `dhcpctl_initialize()'
test.cpp.text+0x21): undefined reference to `dhcpctl_connect(__omapi_object**, char const*, int, __omapi_object*)'
collect2: ld returned 1 exit status
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



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

All times are GMT -5. The time now is 09:35 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