On Mon, Apr 29, 2002 at 03:31:59PM +0530, Wilson wrote:
>
> struct sockaddr_in addr;
> addr.sin_family = AF_INET;
> addr.sin_addr.s_addr = inet_addr( "134.15.15.39" );
> addr.sin_port = 10000;
>
> if( connectStatus = connect( fd, ( const sockaddr *)&addr,
> sizeof( addr ) ) < 0 )
> {
> cout << "connect() failed" << endl;
> close( fd );
> // return -1;
> }
Please use getaddrinfo() to create struct sockaddrs for you.
1) It's much easier.
2) No more hassles with htons()/ntohs().
3) Supports hostnames with multiple addresses.
4) Gives you IPv6 support for free.
Also look at http://www.kame.net/newsletter/19980604/.
--
Met vriendelijke groet / with kind regards,
Guus Sliepen <guus@sliepen.warande.net>
Attachment:
pgpO4qsntty14.pgp
Description: PGP signature