| Summary: | gethostbyname() funtion crashes programs | ||
|---|---|---|---|
| Product: | Gentoo Linux | Reporter: | Ioannis Aslanidis (RETIRED) <deathwing00> |
| Component: | [OLD] Development | Assignee: | Gentoo Linux bug wranglers <bug-wranglers> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | critical | ||
| Priority: | High | ||
| Version: | unspecified | ||
| Hardware: | x86 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Package list: | Runtime testing required: | --- | |
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"
|
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