* bind, socket, EADDRNOTAVAIL
@ 1999-11-15 5:00 kr
1999-11-15 5:00 ` kr
1999-11-18 5:00 ` Gerard Gobillard
0 siblings, 2 replies; 3+ messages in thread
From: kr @ 1999-11-15 5:00 UTC (permalink / raw)
I've run into an obstacle of sorts trying to port a program to Tru64 /
Digital Unix... where the program uses an internet socket to set up
a listening connection on an unpriveleged port, or where it is supposed
to, the bind operation is failing with errno "EADDRNOTAVAIL".
Any idea as to why? (i.e. does this platform have some socket-related
idiosyncrasies I'm unaware of?) Code fragment follows.
......
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. */
}
......
Very normal, vanilla stuff. ...I've tried running the program on two
different machines, with and without root privelege; I've even tried
varying the ports used, and whether or not the local host's network
address is named explicitly.
So I must be missing something obvious. Or perhaps there is an unknown
(and unwanted) DEC security feature enabled by default on both machines,
which is preventing the socket from binding as expected. Or I am the
unwitting victim of a subtle, *godawful* coding gaffe.
This is more-or-less textbook socket programming. So if you have
an inkling what's going on, give a buzz...
TIA.
Katherine Russell
Programmer/ Analyst, Oberlin College Development Resources
russell@ais.oberlin.edu
. ignore, override, become
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: bind, socket, EADDRNOTAVAIL
1999-11-15 5:00 bind, socket, EADDRNOTAVAIL kr
@ 1999-11-15 5:00 ` kr
1999-11-18 5:00 ` Gerard Gobillard
1 sibling, 0 replies; 3+ messages in thread
From: kr @ 1999-11-15 5:00 UTC (permalink / raw)
PS. (And if this isn't a mark of desperation...)
I also tried alternating whether or not I used htonl...
The only reason you see it in the sample code is as the
result of a last, desperate attempt to jiggle parameters around
in vain hopes something would click. Of course, it did not.
So if you tell me that part of the sample is bad, yes, I know,
I've tried it without as well |<
Katherine Russell
Programmer/ Analyst, Oberlin College Development Resources
russell@ais.oberlin.edu
. ignore, override, become
On Mon, 15 Nov 1999, kr wrote:
> I've run into an obstacle of sorts trying to port a program to Tru64 /
> etc:
> ......
>
> 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"));
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: bind, socket, EADDRNOTAVAIL
1999-11-15 5:00 bind, socket, EADDRNOTAVAIL kr
1999-11-15 5:00 ` kr
@ 1999-11-18 5:00 ` Gerard Gobillard
1 sibling, 0 replies; 3+ messages in thread
From: Gerard Gobillard @ 1999-11-18 5:00 UTC (permalink / raw)
To: russell
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-11-18 5:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-11-15 5:00 bind, socket, EADDRNOTAVAIL kr
1999-11-15 5:00 ` kr
1999-11-18 5:00 ` Gerard Gobillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox