![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Motor Vehicle Crashes and Complex Event Processing | iBot | Complex Event Processing RSS News | 0 | 12-30-2007 07:20 PM |
| AIX 5.3 64-bit program crashes with AIX 5.1 | jeet_xp | High Level Programming | 3 | 08-24-2007 05:41 AM |
| Program crashes with optimization level O2 | Yuriy07 | HP-UX | 3 | 08-17-2007 10:11 AM |
| Samba crashes on Solaris with Veritas Cluster | rhfrommn | UNIX for Advanced & Expert Users | 1 | 10-28-2004 05:24 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
gethostnameby_r crashes
Hello all,
I'm trying to use gethostbyname_r function with 6 arguments in one of my functions. But the call to this crashes the program. Kindly help me in resolving this... Compiler Info: Linux target: i686-hardhat-linux version: 3.3.1 The following is the piece of code I'm trying to compile: Code:
#include <iostream.h>
#include <netdb.h>
#include <arpa/inet.h>
int main()
{
hostent *host, **host1;
in_addr **addr_ptr;
char hostname[255];
char buff[1024];
int err;
gethostname(hostname,255);
cout<<"hostname="<<hostname<<"\n";
gethostbyname_r(hostname,host,buff,sizeof(buff),host1,&err);
cout<<"err="<<err<<"\n";
addr_ptr=(struct in_addr**)host->h_addr_list;
char* mgcip=new char[16];
mgcip=inet_ntoa(**addr_ptr);
cout<<"mgcip="<<mgcip<<"\n";
}
$a.out hostname=oamce-1 Segmentation fault (core dumped) The following is the result of running gdb over the core file: Code:
$gdb a.out core
GNU gdb 6.0 (MontaVista 6.0-11.0.15.0500398 2005-03-19)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-hardhat-linux"...
Core was generated by `a.out'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libstdc++.so.5...done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2...done.
Loaded symbols for /lib/libnss_files.so.2
#0 0x40251345 in internal_getent (result=0x804895c, buffer=0xbfffcb50 "\177", buflen=8192,
errnop=0x40243be0, herrnop=0xbfffcb4c, af=2, flags=0) at nss_files/files-hosts.c:77
77 nss_files/files-hosts.c: No such file or directory.
in nss_files/files-hosts.c
(gdb) bt
#0 0x40251345 in internal_getent (result=0x804895c, buffer=0xbfffcb50 "\177", buflen=8192,
errnop=0x40243be0, herrnop=0xbfffcb4c, af=2, flags=0) at nss_files/files-hosts.c:77
#1 0x402517d5 in _nss_files_gethostbyname_r (name=0xbfffeb50 "oamce-1", result=0x804895c,
buffer=0xbfffcb50 "\177", buflen=8192, errnop=0x40243be0, herrnop=0xbfffcb4c)
at nss_files/files-hosts.c:268
#2 0x402066c8 in __gethostbyname_r (name=0xbfffeb50 "oamce-1", resbuf=0x804895c,
buffer=0xbfffcb50 "\177", buflen=8192, result=0xbfffec58, h_errnop=0xbfffcb4c)
at getXXbyYY_r.c:219
#3 0x0804882d in main () at 1.cc:13
Current language: auto; currently c
(gdb)
Thank you in advance for the kind help. Regards, Rajangam Last edited by vino; 06-23-2008 at 12:03 AM. Reason: added code tags |
| Forum Sponsor | ||
|
|