public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Mysterious gethostbyname problem
@ 2004-01-20  2:36 Andre Kirchner
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Kirchner @ 2004-01-20  2:36 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Mysterious gethostbyname problem
@ 2004-01-21  1:00 Andre Kirchner
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Kirchner @ 2004-01-21  1:00 UTC (permalink / raw)
  To: gcc-help

Hi,

I found out that this program executes without any
problem if it's executed from the command line, and so
I guess there is something wrong with ide I'm using (
Kdevelop ). If I found out what was wrong I'll post
here.

Thanks for all the help,

Andre

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Mysterious gethostbyname problem
@ 2004-01-20 12:43 Assinovsky, Lev
  0 siblings, 0 replies; 3+ messages in thread
From: Assinovsky, Lev @ 2004-01-20 12:43 UTC (permalink / raw)
  To: Andre Kirchner, gcc-help

I believe you have DNS problems.
Try nslookup www.hotmail.com

----
Lev Assinovsky
Aelita Software Corporation


> -----Original Message-----
> From: Andre Kirchner [mailto:supercroc1974@yahoo.com]
> Sent: Tuesday, January 20, 2004 5:36 AM
> To: gcc-help@gcc.gnu.org
> Subject: Mysterious gethostbyname problem
> 
> 
> 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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-01-21  1:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-20  2:36 Mysterious gethostbyname problem Andre Kirchner
2004-01-20 12:43 Assinovsky, Lev
2004-01-21  1:00 Andre Kirchner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).