Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 31060 - gethostbyname() funtion crashes programs
Summary: gethostbyname() funtion crashes programs
Status: RESOLVED DUPLICATE of bug 30865
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: High critical (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-13 12:50 UTC by Ioannis Aslanidis (RETIRED)
Modified: 2005-07-17 13:06 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ioannis Aslanidis (RETIRED) gentoo-dev 2003-10-13 12:50:22 UTC
I have been creating a simple socket client program and everything seems to go 
well until it calls the function gethostbyname(). I have compiled and executed 
the same program under Debian and RedHat and it DOES work while it does NOT 
under Gentoo. I have tried it in 3 different (different users, different 
configuration) Gentoo systems and no way.

I include a small code that shows up what I told you.

Reproducible: Always
Steps to Reproduce:
]#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>        

#define MAXDATASIZE 100   
#define MAXHOSTLEN 64

int main(int argc, char **argv)
{
   int error;
   int fd, numbytes;       
   char buf[MAXDATASIZE];  
   struct hostent *he;         
   struct sockaddr_in server;  
   char * anfitrion;
   int puerto;

   anfitrion = (char *) malloc (sizeof(char)*63);

   if (argc !=3) { 
      printf("Uso: %s <Direcci
Comment 1 Ioannis Aslanidis (RETIRED) gentoo-dev 2003-10-13 12:50:22 UTC
I have been creating a simple socket client program and everything seems to go 
well until it calls the function gethostbyname(). I have compiled and executed 
the same program under Debian and RedHat and it DOES work while it does NOT 
under Gentoo. I have tried it in 3 different (different users, different 
configuration) Gentoo systems and no way.

I include a small code that shows up what I told you.

Reproducible: Always
Steps to Reproduce:
]#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>        

#define MAXDATASIZE 100   
#define MAXHOSTLEN 64

int main(int argc, char **argv)
{
   int error;
   int fd, numbytes;       
   char buf[MAXDATASIZE];  
   struct hostent *he;         
   struct sockaddr_in server;  
   char * anfitrion;
   int puerto;

   anfitrion = (char *) malloc (sizeof(char)*63);

   if (argc !=3) { 
      printf("Uso: %s <Dirección IP> <Puerto>\n",argv[0]);
      exit(-1);
   }

   anfitrion=argv[1];
   puerto=atoi(argv[2]);

   printf("GET HOST BY NAME...\n");

[color=red]   if ((he=gethostbyname((char *)anfitrion))==NULL){       
      printf("gethostbyname() error\n");
      exit(-1);
   }
 [/color]  
   printf(" OK");
   printf("  --  IP: %s",he -> h_addr);

   if ((fd=socket(AF_INET, SOCK_STREAM, 0))==-1){  
      printf("socket() error\n");
      exit(-1);
   }

   server.sin_family = AF_INET;
   server.sin_port = htons(puerto); 
   server.sin_addr = *((struct in_addr *)he->h_addr);  
   bzero(&(server.sin_zero),8);

   if(connect(fd, (struct sockaddr *)&server,
      sizeof(struct sockaddr))==-1){ 
      printf("connect() error\n");
      exit(-1);
   }

   if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1){  
      printf("Error en recv() \n");
      exit(-1);
   }

   buf[numbytes]='\0';

   printf("Mensaje del Servidor: %s\n",buf); 

   close(fd);  

}
Actual Results:  
The program crashed when called gethostbyname().

Expected Results:  
gethostbyname() should have resolved the DNS-name correctly.

Gentoo Base System version 1.4.3.10p1
Portage 2.0.49-r9 (default-x86-1.4, gcc-3.3.1, glibc-2.3.2-r1, 2.4.20-xfs-r3)
=================================================================
System uname: 2.4.20-xfs-r3 i686 Intel(R) Pentium(R) 4 CPU 2.40GHz
ACCEPT_KEYWORDS="x86 ~x86"
AUTOCLEAN="yes"
CFLAGS="-mcpu=i686 -O2 -pipe"
CHOST="i686-pc-linux-gnu"
COMPILER="gcc3"
CONFIG_PROTECT="/etc /var/qmail/control /usr/kde/2/share/config /usr/kde/3/shar
e/config /usr/X11R6/lib/X11/xkb /usr/kde/3.1/share/config /usr/share/texmf/tex/
generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/config"
CONFIG_PROTECT_MASK="/etc/gconf /etc/env.d"
CXXFLAGS="-mcpu=i686 -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="sandbox ccache autoaddcvs"
GENTOO_MIRRORS="http://ftp.belnet.be/mirror/rsync.gentoo.org/gentoo 
http://gentoo.oregonstate.edu/ 
http://www.ibiblio.org/pub/Linux/distributions/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="apm crypt cups foomaticdb gif libg++ mad mikmod mmx mpeg ncurses nls 
pdflib xv gdbm berkdb slang readline tetex aalib tcltk java guile sdl tcpd pam 
libwww ssl esd imlib gnome motif X kde avi xmms acpi arts cdr dvd directfb 
emacs encode ethereal flash gpm gtk gtk2 ipv6 jpeg mozilla mule oggvorbis 
opengl oss perl png pnp prebuilt python qt quicktime ruby samba spell svga 
truetype xml xml2 zlib x86 alsa"
Comment 2 SpanKY gentoo-dev 2003-10-13 12:59:39 UTC

*** This bug has been marked as a duplicate of 30865 ***