gethostname warning


 
Thread Tools Search this Thread
Top Forums Programming gethostname warning
# 1  
Old 05-20-2009
gethostname warning

Hi, does anyone knows how to get rid of this annoying warning? Thank you!

Code:
#include <netdb.h>
main()
{
    gethostbyname("test");
}

$ gcc -static test.c
/tmp/ccW9HG18.o: In function `main':
test.cSmilie.text+0x19): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

$ nm a.out | grep gethostbyname
0804f660 T __gethostbyname_r
0804f660 T __new_gethostbyname_r
080500b0 T __nscd_gethostbyname2_r
08050110 T __nscd_gethostbyname_r
0804f4a0 T gethostbyname
0804f660 W gethostbyname_r


-----

$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
# 2  
Old 05-21-2009
Code:
gcc test.c

will stop the warning, but you will get others, your code is not correct - gethostbyname() returns a pointer to a hostent structure, for example.
# 3  
Old 05-21-2009
I need a static link.
# 4  
Old 05-21-2009
You have to redesign your code somehow.

gethostbyname() is not guaranteed to work internally the same way on different architectures. If you know the architecure ahead of time, then get the source for gethostbyname for that destination system, and embed it in your code. Otherwise, you will have to figure out what version of gethostbyname you have to run for the box your code is running on, then jump to that routine. ie., include all of your possible versions of the code.

gethostbyname is part of libc, so, for example, for a red hat box try:
libc/inet/
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Programming

regarding gethostname()

i used stuct hosent h; h=gethostname("google.com"); if(h==NULL) printf("net down"); else printf("net down"); my question hoe this gethostname will verify whether net ia active or inactive i eman whether by usin ping or sending socket . if it is socket which type of socket it is... (5 Replies)
Discussion started by: phani_sree
5 Replies
Login or Register to Ask a Question