I was told that a DNS SRV record might contain a service name as the
port value. Though I haven't seen that, but if it's true, I'll need a
way to translate it to a real port number.
I don't want to store a map inside my code, nor do I intend to read
/etc/services directly, that's why I asked for a getportbyname() method.
Thanks
Max
On 11/14/2012 11:08 AM, 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: kurchi.subhra.ha...@oracle.com
To: weijun.w...@oracle.com
Cc: net-dev@openjdk.java.net
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