Article View: comp.lang.java.programmer
Article #589Re: InetAddress - no solution
From: Paul Tomblin
Date: Thu, 17 Sep 1998 00:00
Date: Thu, 17 Sep 1998 00:00
27 lines
1633 bytes
1633 bytes
In a previous article, "Martin Ry๏ฟฝ๏ฟฝnek" <rysanek@telecom.cz> said:
>I have just byte[] array of 4 bytes and need to create regular InetAddress
>class.
Sorry, but you have to convert it to a string:
private static String IPToString(byte[] addr)
{
String dottedquad = "";
for (int i = 0; i < addr.length;)
{
short sh = (short)(addr[i] & 0xff);
dottedquad += Integer.toString(sh);
i++;
if (i < addr.length)
dottedquad += ".";
}
return dottedquad;
}
Note that while I call it dotted*quad*, it will work in that time in the
future when the byte array is longer than 4 bytes. (IPv6, whose time has come)
--
Paul Tomblin, ptomblin@xcski.com.
"Only a NAZI would try to invoke Godwin's [law] deliberately"
- Jeff Gostin in a.s.r
Technical Details
Message-ID:
<6tr7gj$nvo$1@canoe.xcski.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<360105eb.0@news.cvut.cz>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: fb99b,e06616101d23416f X-Google-Attributes: gidfb99b,public X-Google-Thread: f5e83,e06616101d23416f X-Google-Attributes: gidf5e83,public X-Google-Thread: 10a146,e06616101d23416f X-Google-Attributes: gid10a146,public From: ptomblin@canoe.xcski.com (Paul Tomblin) Subject: Re: InetAddress - no solution Date: 1998/09/17 Message-ID: <6tr7gj$nvo$1@canoe.xcski.com> X-Deja-AN: 392065760 Distribution: cz Sender: ptomblin@xcski.com References: <360105eb.0@news.cvut.cz> Organization: Tomblin Computer Consulting, Rochester, New York and Ottawa, Ontario Reply-To: ptomblin@xcski.com (Paul Tomblin) Newsgroups: comp.lang.java.programmer,comp.lang.java.softwaretools,cz.comp.lang.java