getportbyname in Java?

John Zavgren john.zavgren at oracle.com
Wed Nov 14 04:47:37 PST 2012


I see after reading the correspondence that DNS would be used to bind the names to the numbers, as in RFC 2728 :http://www.dns-sd.org/ServiceTypes.html. 
(There is a convenient description here: http://en.wikipedia.org/wiki/SRV_record.)

I wasn't aware of this effort. It's very cool and useful, especially for SIP and MXPP.
-----
Here's an example C program that I wrote:
#include<stdio.h>
#include<netdb.h>
#include<stdlib.h>
int main(int argc, char** argv)
{
        struct servent * serveEntPtr;
        serveEntPtr = getservbyname("http", "tcp");
        fprintf(stdout, "The port number for \"http\" is %d\n", ntohs(serveEntPtr->s_port));
        return EXIT_SUCCESS;
}
It returns:
The port number for "http" is 80

So, to implement the Java API one would could just look at the C source code for getservbyname() that's in the glibc library, and then Plagiarize.


John



----- Original Message -----
From: Alan.Bateman at oracle.com
To: weijun.wang at oracle.com
Cc: net-dev at openjdk.java.net
Sent: Wednesday, November 14, 2012 4:22:49 AM GMT -05:00 US/Canada Eastern
Subject: Re: getportbyname in Java?

On 14/11/2012 09:00, Weijun Wang wrote:
> I guess there were quite some public votes?
>
> -Max
I don't remember but with the JNDI DNS provider then you could look for 
SRV records, I recall we had a few prototypes of that too.

-Alan



More information about the net-dev mailing list