#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>.
Now when i try to compile using:
gcc -Wall -o dns dns.c
It spits it back in my face that the function inet_ntoa() is an unresolved
symbol. So my question is: which library do I link with to get it to link?
What command line do I use?
RedHat Linux 8.0 Kernel 2.4.18-26.8.0
Hi James,
please post the whole output of gcc
cu
Andreas
JYI> #include <stdio.h>
JYI> #include <stdlib.h>
JYI> #include <errno.h>
JYI> #include <netdb.h>
JYI> #include <sys/types.h>
JYI> #include <sys/socket.h>
JYI> #include <netinet/in.h>
JYI> #include <arpa/inet.h>.
JYI> Now when i try to compile using:
JYI> gcc -Wall -o dns dns.c
JYI> It spits it back in my face that the function inet_ntoa() is an unresolved
JYI> symbol. So my question is: which library do I link with to get it to link?
JYI> What command line do I use?
It is in libc. So standard linking should find and attach it.
As said here, please copy & paste compiler output from it, not your re-telling.
JYI> RedHat Linux 8.0 Kernel 2.4.18-26.8.0
Yes, I've just checked RH 8.0.
-netch-
Maybe -lresolve? I'm puzzled why you don't just *check*. The 'nm'
command will list the symbols in a library, and you can 'grep' the
output for 'inet_ntoa'. For example:
nm -o `find /lib -name \*so\*` | grep inet_ntoa | grep -v U
DS
Sorry about that:
gcc -Wall dns dns.c
> dns.c: In function 'main':
> dns.c:29: warning: implicit declaration of function 'inet_itoa'
> dns.c:29: warning: format argument is not a pointer (arg 2)
> /tmp/cc3yiCfw.o: In function 'main':
> /tmp/cc3yiCfw.o(.text+0x94): undefined reference to 'inet_itoa'
> collect2: ld returned 1 exit status
Maybe I missed a header file?
Here's the code I had:
/*
** dns.c - a hostname lookup demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
struct hostent *h;
if (argc != 2) { // error check the command line
fprintf(stderr,"usage: getip address\n");
exit(1);
}
if ((h=gethostbyname(argv[1])) == NULL) { // get the host info
herror("gethostbyname");
exit(1);
}
printf("Host name : %s\n", h->h_name);
printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));
return 0;
}
What's "inet_itoa"? The code you posted in another article used
inet_ntoa, but the compiler is seeing inet_itoa for some reason. Are
you sure the code you posted is the same code that's failing here?
Oops. It was inet_ntoa(). Sorry, guys.
What was inet_ntoa()? What you actually used in the code, or what gcc
complained about?
I'm just wondering how, if you copied and pasted the output of gcc,
it's complaining about something you didn't have in the code.
If you did have inet_ntoa in the code, how about posting the real
output of gcc?