From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e2fe95e4fd8e27a8 X-Google-Attributes: gidfee84,public From: Gerard Gobillard Subject: Re: bind, socket, EADDRNOTAVAIL Date: 1999/11/18 Message-ID: <38341962.4EDFEDC3@ms.alcatel.fr>#1/1 X-Deja-AN: 550150462 Content-Transfer-Encoding: 7bit References: To: russell@ais.oberlin.edu Content-Type: text/plain; charset=us-ascii Organization: Alcatel CIT, Etablissement de Marcoussis, France Mime-Version: 1.0 Newsgroups: comp.unix.osf.osf1 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