From mboxrd@z Thu Jan 1 00:00:00 1970
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fee84,10bf95f665757cee,start
X-Google-Attributes: gidfee84,public
X-Google-ArrivalTime: 1994-03-10 15:20:43 PST
Path: gmd.de!newsserver.jvnc.net!yale.edu!yale!gumby!wupost!howland.reston.ans.net!vixen.cso.uiuc.edu!hoohoo.ncsa.uiuc.edu!robm
From: robm@ncsa.uiuc.edu (Rob McCool)
Newsgroups: comp.unix.osf.osf1
Subject: sin_port weirdness in DEC OSF/1?
Date: 10 Mar 1994 23:20:43 GMT
Organization: NCSA
Message-ID: <2loa0b$sqk@vixen.cso.uiuc.edu>
NNTP-Posting-Host: hoohoo.ncsa.uiuc.edu
X-Newsreader: TIN [version 1.2 PL2]
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 must see.
From mboxrd@z Thu Jan 1 00:00:00 1970
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fee84,10bf95f665757cee
X-Google-Attributes: gidfee84,public
X-Google-ArrivalTime: 1994-03-10 20:16:48 PST
Path: gmd.de!newsserver.jvnc.net!yale.edu!yale!gumby!wupost!math.ohio-state.edu!howland.reston.ans.net!vixen.cso.uiuc.edu!hoohoo.ncsa.uiuc.edu!robm
From: robm@ncsa.uiuc.edu (Rob McCool)
Newsgroups: comp.unix.osf.osf1
Subject: Re: sin_port weirdness in DEC OSF/1?
Date: 11 Mar 1994 04:16:48 GMT
Organization: NCSA
Message-ID: <2lorbg$lh6@vixen.cso.uiuc.edu>
References: <2loa0b$sqk@vixen.cso.uiuc.edu>
NNTP-Posting-Host: hoohoo.ncsa.uiuc.edu
X-Newsreader: TIN [version 1.2 PL2]
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 must see.
From mboxrd@z Thu Jan 1 00:00:00 1970
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fee84,10bf95f665757cee
X-Google-Attributes: gidfee84,public
X-Google-ArrivalTime: 1994-03-10 23:42:42 PST
Path: gmd.de!newsserver.jvnc.net!darwin.sura.net!howland.reston.ans.net!pipex!uknet!EU.net!sun4nl!philapd!apdnews!atperf.idca.tds.philips.nl!pb
From: pb@idca.tds.philips.nl (Peter Brouwer)
Newsgroups: comp.unix.osf.osf1
Subject: Re: sin_port weirdness in DEC OSF/1?
Message-ID:
Date: 11 Mar 94 07:42:42 GMT
References: <2loa0b$sqk@vixen.cso.uiuc.edu>
Sender: news@idca.tds.philips.nl
Reply-To: pb@idca.tds.philips.nl (Peter Brouwer)
Organization: Digital Equipment Corporation Apeldoorn, The Netherlands.
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.
From mboxrd@z Thu Jan 1 00:00:00 1970
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fee84,10bf95f665757cee
X-Google-Attributes: gidfee84,public
X-Google-ArrivalTime: 1994-03-11 06:23:03 PST
Newsgroups: comp.unix.osf.osf1
Path: gmd.de!xlink.net!howland.reston.ans.net!agate!news.Brown.EDU!noc.near.net!atria.com!jtk
From: jtk@atria.com (John T. Kohl)
Subject: Re: sin_port weirdness in DEC OSF/1?
In-Reply-To: robm@ncsa.uiuc.edu's message of 10 Mar 1994 23:20:43 GMT
Message-ID:
Sender: news@atria.com
Nntp-Posting-Host: banana.atria.com
Organization: Atria Software, Inc.
References: <2loa0b$sqk@vixen.cso.uiuc.edu>
Date: Fri, 11 Mar 1994 14:23:03 GMT
>>>>> "Rob" == Rob McCool 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 or
working for but not representing: Atria Software
---------
Oh, just enjoy yourself!