Hello everybody, yesterday I was facing a problem. A system function gethostbyname() that expects one argument, a const char* causes a segmentation fault. The function call code is - probably not saying much - the following: char *http_send_recv(char *hostname, char *request) { struct hostent *hptr; ... if( hptr = gethostbyname( hostname )) memcpy(&sin.sin_addr, hptr->h_addr, hptr->h_length); else { /* error */ } ... } gdb output: (gdb) p hostname $1 = 0x804916b "www.oliver-block.eu" (gdb) s 5701: symbol=gethostbyname; lookup in file=/home/oblock/programming/c/tcp/ddnscli 5701: symbol=gethostbyname; lookup in file=/lib/tls/libc.so.6 lookup 0x08048000 0x00000284 -> 0x40034000 0x000c9ae0 /1 gethostbyname 5701: symbol=malloc; lookup in file=/home/oblock/programming/c/tcp/ddnscli 5701: symbol=malloc; lookup in file=/lib/tls/libc.so.6 Program received signal SIGSEGV, Segmentation fault. 0x40007b46 in do_lookup_x () from /lib/ld-linux.so.2 (gdb) bt #0 0x40007b46 in do_lookup_x () from /lib/ld-linux.so.2 #1 0x400084ae in _dl_lookup_symbol_x () from /lib/ld-linux.so.2 #2 0x4000cc26 in fixup () from /lib/ld-linux.so.2 #3 0x4000c9f0 in _dl_runtime_resolve () from /lib/ld-linux.so.2 #4 0x400fdb3f in gethostbyname () from /lib/tls/libc.so.6 #5 0x08048d1b in http_send_recv (hostname=0x804916b "www.oliver-block.eu", request=0x804914f "GET /checkip.php /HTTP1.1\r\n") at ddnscli.c:161 #6 0x08048e12 in get_ip () at ddnscli.c:191 #7 0x08048f01 in main (argc=6, argv=0xbffff174) at ddnscli.c:243 (gdb) Help is appreciated. Best regards, Oliver -- Leben ist mehr als ... <http://www.nak-nrw.de/index.php?id=71>
On Tuesday 07 November 2006 16:10, Oliver Block wrote:
Hello everybody,
yesterday I was facing a problem. A system function gethostbyname() that expects one argument, a const char* causes a segmentation fault.
The function call code is - probably not saying much - the following:
char *http_send_recv(char *hostname, char *request) { struct hostent *hptr; ... if( hptr = gethostbyname( hostname )) memcpy(&sin.sin_addr, hptr->h_addr, hptr->h_length);
What does the code look like that calls http_send_recv? I'll bet good money the hostname pointer isn't properly allocated
participants (2)
-
Anders Johansson
-
Oliver Block