getportbyname in Java?

Vitaly Davidovich vitalyd at gmail.com
Wed Nov 14 05:09:40 PST 2012


I think jdk can simply use getservbyname() in the impl - windows has the
same function.  I think both just look at their respective services file.
Googling "java getservbyname" returns some hits so it looks like people
would find this useful and it seems like it would be pretty straightforward
to implement.

Sent from my phone
On Nov 14, 2012 7:48 AM, "John Zavgren" <john.zavgren at oracle.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20121114/35953413/attachment.html 


More information about the net-dev mailing list