John,
The goal of getportbyname() is transfer responsibility of finding right
ports for running service from software developer to system
administrator, and especially useful if we have one /etc/services for
whole network (e.g. distributed by NIS)
e.g instead of constantly fixing port numbers in jdk tests we can
a) require QA to have a name "test_program_port" defined on
all machines
b) Use getportbyname() to get appropriate port.
or
if we have kerberos running on non-standard port, in ideal world we can
just change /etc/services:kerberos entry out from 88 instead of fixing
zillion client configs.
So I'm surprised we don't have this API in java.
-Dmitry
On 2012-11-14 07:08, John Zavgren wrote:
> Max:
> I've never seen a procedure that binds a protocol to a port number. (The http
> protocol you mention usually uses TCP port number 80, but the port choice for
> this protocol is up to the discretion of the programmer. The file
> /etc/services binds names to numbers so that tools like tcpdump and netstat
> can convert port numbers to names and that can be useful sometimes. But, you
> can violate these conventions without any consequences. If you use TCP port
> number 79 to carry http traffic, my netstat program will think it's the
> finger protocol. You can event set the port number that an http server uses
> for receiving connections if you want. It's completely legal to run a WWW
> server on, say, TCP port 666.)
>
> On the other hand, there are procedures for getting an IP protocol by name...
> they will convert the character string "UDP" into a structure called a
> protoent i.e., getprotobyname("UDP"); The protoent structure in this example
> will contain the number 17 in host byte order as the member p_proto. But,
> that's a different kind of protocol than what you are considering. The
> bindings between IP protocol names and numbers are "written in stone",
> because every OS (windows, Mac, Linux, etc.) needs to know which protocol
> handler to invoke whenever an IP datagram arrives. If this wasn't true then
> interoperability would suffer. Maybe this is why getprotobyname() exists in
> the C runtime libraries? I've never used it. And it doesn't seem necessary.
>
> Have you considered using an Enum? That could bind the string "http" to the
> port number 80.
> John
>
> ----- Original Message -----
> From: [email protected]
> To: [email protected]
> Cc: [email protected]
> Sent: Tuesday, November 13, 2012 9:16:28 PM GMT -05:00 US/Canada Eastern
> Subject: Re: getportbyname in Java?
>
> I don't think so...
>
> Thanks,
> - Kurchi
>
> On 13.11.2012 16:40, Weijun Wang wrote:
>> Is there a Java API I can translate "http" to 80?
>>
>> Thanks
>> Max
>
--
Dmitry Samersoff
Oracle Java development team, Saint Petersburg, Russia
* Give Rabbit time, and he'll always get the answer