* sin_port weirdness in DEC OSF/1?
@ 1994-03-10 23:20 Rob McCool
1994-03-11 4:16 ` Rob McCool
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rob McCool @ 1994-03-10 23:20 UTC (permalink / raw)
Hi, in the source for my information server, I need to find out what port a
given socket is attached to while running under inetd. I'm finding that
while my code to do this works elsewhere, it fails miserably under OSF/1,
returning a very large integer (usually 20480 or 36895). Here is the code:
int get_portnum(int sd,FILE *out) {
struct sockaddr addr;
int len;
len = sizeof(struct sockaddr);
if(getsockname(sd,&addr,&len) < 0)
die(SERVER_ERROR,"could not get port number",out);
return(((struct sockaddr_in *)&addr)->sin_port);
}
Does anyone see anything wrong with this? Is this a bug in OSF/1, or a
mistake on my part which just happens to work on other systems? If it's an
OS bug, does anyone have a workaround?
This seems to happen with both OSF/1 1.2 and 1.3.
--
Rob McCool, robm@ncsa.uiuc.edu
Software Development Group, National Center for Supercomputing Applications
It was working ten minutes ago, I swear...
<A HREF="http://hoohoo.ncsa.uiuc.edu/~robm/sg.html">A must see.</A>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: sin_port weirdness in DEC OSF/1?
1994-03-10 23:20 sin_port weirdness in DEC OSF/1? Rob McCool
@ 1994-03-11 4:16 ` Rob McCool
1994-03-11 7:42 ` Peter Brouwer
1994-03-11 14:23 ` John T. Kohl
2 siblings, 0 replies; 4+ messages in thread
From: Rob McCool @ 1994-03-11 4:16 UTC (permalink / raw)
Thanks to those who responded and pointed out my hopelessly stupid mistake.
The problem is that I had to convert the port number from network order to
the host's order, and the Alpha, being little endian, was the only machine
that needed to swap.
--
Rob McCool, robm@ncsa.uiuc.edu
Software Development Group, National Center for Supercomputing Applications
It was working ten minutes ago, I swear...
<A HREF="http://hoohoo.ncsa.uiuc.edu/~robm/sg.html">A must see.</A>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: sin_port weirdness in DEC OSF/1?
1994-03-10 23:20 sin_port weirdness in DEC OSF/1? Rob McCool
1994-03-11 4:16 ` Rob McCool
@ 1994-03-11 7:42 ` Peter Brouwer
1994-03-11 14:23 ` John T. Kohl
2 siblings, 0 replies; 4+ messages in thread
From: Peter Brouwer @ 1994-03-11 7:42 UTC (permalink / raw)
In <2loa0b$sqk@vixen.cso.uiuc.edu> robm@ncsa.uiuc.edu (Rob McCool) writes:
>int get_portnum(int sd,FILE *out) {
> struct sockaddr addr;
> int len;
>
> len = sizeof(struct sockaddr);
> if(getsockname(sd,&addr,&len) < 0)
> die(SERVER_ERROR,"could not get port number",out);
> return(((struct sockaddr_in *)&addr)->sin_port);
>}
>Does anyone see anything wrong with this? Is this a bug in OSF/1, or a
>mistake on my part which just happens to work on other systems? If it's an
>OS bug, does anyone have a workaround?
Might the fact that sin_port is a u_short and your function returns an int give
problems?
--
Regards, Peter Brouwer /\_/\
pb@idca.tds.philips.nl (0 0)
-----------------------------------oOO--(_)--OOo----------------------------
# Digital Equipment Enterprise, / WorkGroup Systems, Office Product Set
# DIGITAL : HLDEO1::BROUWER_P,829-4218 \ Dep Office Product Sets, P.O.Box 245,
# PHONE:[+31][0]55 43 ext 4218,fax 9133 7300AE Apeldoorn, The Netherlands.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: sin_port weirdness in DEC OSF/1?
1994-03-10 23:20 sin_port weirdness in DEC OSF/1? Rob McCool
1994-03-11 4:16 ` Rob McCool
1994-03-11 7:42 ` Peter Brouwer
@ 1994-03-11 14:23 ` John T. Kohl
2 siblings, 0 replies; 4+ messages in thread
From: John T. Kohl @ 1994-03-11 14:23 UTC (permalink / raw)
>>>>> "Rob" == Rob McCool <robm@ncsa.uiuc.edu> writes:
In article <2loa0b$sqk@vixen.cso.uiuc.edu> robm@ncsa.uiuc.edu (Rob McCool) writes:
Rob> Hi, in the source for my information server, I need to find out what port a
Rob> given socket is attached to while running under inetd. I'm finding that
Rob> while my code to do this works elsewhere, it fails miserably under OSF/1,
Rob> returning a very large integer (usually 20480 or 36895). Here is the code:
DEC OSF/1 on Alpha AXP uses a different byte order from network byte
order; getsockname() reports the address and port number in network byte
order.
You should use ntohs() (network to host short) to convert the value. On
machines which have matching network and host byte order, the function
is a null macro; on machines like the DEC Alpha AXP, it's a
byte-swapping function.
--
John Kohl <jtk@atria.com> or <jtkohl@mit.edu>
working for but not representing: Atria Software
---------
Oh, just enjoy yourself!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1994-03-11 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-03-10 23:20 sin_port weirdness in DEC OSF/1? Rob McCool
1994-03-11 4:16 ` Rob McCool
1994-03-11 7:42 ` Peter Brouwer
1994-03-11 14:23 ` John T. Kohl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox