Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Gerard Gobillard <Gerard.Gobillard@ms.alcatel.fr>
To: russell@ais.oberlin.edu
Subject: Re: bind, socket, EADDRNOTAVAIL
Date: 1999/11/18	[thread overview]
Message-ID: <38341962.4EDFEDC3@ms.alcatel.fr> (raw)
In-Reply-To: Pine.OSF.3.96.991115194304.30871B-100000@ais.alumdev.oberlin.edu

Note that inet_addr("127.0.0.1") returns a integer ALREADY
in network order so you should not touch it before assigning
it to addr_in.sin_addr. Thus I suggest:

	(no numeric_addr variable)
	addr_in.sin_addr.s_addr = inet_addr("127.0.0.1");

gg
ps: inet_addr() is deprecated, it is better to use inet_aton().

kr wrote:
> ......
> 
>   in_addr numeric_addr; struct sockaddr_in addr_in;
> ......
> 
>   if ((in_port=socket(AF_INET,SOCK_STREAM,0)) < 0) {
>      perror("socket"); exit(EXIT_FAILURE);
>   }
> 
>   numeric_addr.s_addr=htonl(inet_addr("127.0.0.1"));
> 
>   addr_in.sin_port = 1039;  /* for example */
>   addr_in.sin_family = PF_INET;
>   addr_in.sin_addr = numeric_addr;
> 
>   if ( bind(in_port,(struct sockaddr *) & addr_in,sizeof(addr_in)) < 0) {
>      perror("bind"); exit(EXIT_FAILURE);  /* and voila! failure occurs. */
>   }
> ......
> 

-- 
Gerard Gobillard -- ALCATEL CIT
Branche CRC - UPE (Unite Plate-formes et Equipements)
Route de Nozay     Phone : + 33 0(1) 69 63 10 50
91460 Marcoussis   Fax   : + 33 0(1) 69 63 17 89
FRANCE             Email : mailto: Gerard.Gobillard@ms.alcatel.fr



      parent reply	other threads:[~1999-11-18  5:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-15  5:00 bind, socket, EADDRNOTAVAIL kr
1999-11-15  5:00 ` kr
1999-11-18  5:00 ` Gerard Gobillard [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox