Mysterious gethostbyname problem
Andre Kirchner
supercroc1974@yahoo.com
Tue Jan 20 02:36:00 GMT 2004
Hi,
I have made this program, but I can't figure out what
is wrong with it. Somehow it always freezes at the
gethostbyname command.
Does anyone have anyidea about what could be wrong?
I'm using gcc 3.2.2 on a RedHat 9 system.
Thanks,
Andre
int main()
{
printf( "%d\n", connectSocket( "www.hotmail.com", 80 )
);
return( 0 );
}
int connectSocket( const char * hostName, const int
portno )
{
int sockfd;
struct hostent *server = 0;
struct sockaddr_in serv_addr;
// create the socket
sockfd = socket( AF_INET, SOCK_STREAM, 0 );
if ( sockfd < 0 )
return( -1 );
// determine the host
if( ( server = gethostbyname( hostName ) ) == NULL )
{
printf( "Error number: %d\n", errno );
return( -1 );
}
// connect to the host
bzero( ( char * ) &serv_addr, sizeof( serv_addr ) );
serv_addr.sin_family = AF_INET;
bcopy( ( char * ) server -> h_addr, ( char * )
&serv_addr.sin_addr.s_addr, server -> h_length );
serv_addr.sin_port = htons( portno );
if ( connect( sockfd, ( struct sockaddr* )
&serv_addr, sizeof( serv_addr ) ) < 0 )
return( -1 );
return( sockfd );
}
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
More information about the Gcc-help
mailing list