Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > I'd like to conver long value to IP address, which fuction do I have to use?

Reply
Thread Tools

I'd like to conver long value to IP address, which fuction do I have to use?

 
 
somez72
Guest
Posts: n/a
 
      05-03-2004
hello.
I have a long value ,,, and
I'd like to conver it to IP address.
I can't find which function Should I use?

Could you someone help?


Have a day.


 
Reply With Quote
 
 
 
 
Karthik
Guest
Posts: n/a
 
      05-03-2004
somez72 wrote:
> hello.
> I have a long value ,,, and
> I'd like to conver it to IP address.
> I can't find which function Should I use?
>
> Could you someone help?
>
>
> Have a day.
>
>

Was wondering how would you represent an IP address as long ? Perhaps
String might do. Or better even a separate data structure for it as a
group of 'short's would do.

--
Karthik
Humans please 'removeme_' for my real email.
 
Reply With Quote
 
 
 
 
Thomas Schodt
Guest
Posts: n/a
 
      05-03-2004
somez72 wrote:

> hello.
> I have a long value ,,, and
> I'd like to conver it to IP address.
> I can't find which function Should I use?
>
> Could you someone help?


An IPv4 address is 4 octets, or 32 bits.
In most C flavours that could be represented in a long.

A long in Java is 64 bits.

You are probably translating some legacy application from C to Java?

You can split your 32-bit scalar in 4 octets
with simple bit shifts and casts.
Store the 4 octets in a byte[4] array,
you can ignore the fact that byte is signed.

You can then use InetAddress.getByAddress(byte[])
to obtain an InetAddress (actually an Inet4Address).
 
Reply With Quote
 
somez72
Guest
Posts: n/a
 
      05-03-2004
Thanks.
what I mean was ,
Someone insert ip address to mysql DB with long format.
( for example , ip address field in mysql DB has values something
like 23455543222. )
so I need to convert it to IP address format ( xxx.yyy.zzz.ccc ) in my JAVA
application.

I'd like to know is there that kind of API, to convert to IP4 Adress in
JAVA?

Have a day.




"Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
news:c75qbi$iqc$1$(E-Mail Removed)...
> somez72 wrote:
>
> > hello.
> > I have a long value ,,, and
> > I'd like to conver it to IP address.
> > I can't find which function Should I use?
> >
> > Could you someone help?

>
> An IPv4 address is 4 octets, or 32 bits.
> In most C flavours that could be represented in a long.
>
> A long in Java is 64 bits.
>
> You are probably translating some legacy application from C to Java?
>
> You can split your 32-bit scalar in 4 octets
> with simple bit shifts and casts.
> Store the 4 octets in a byte[4] array,
> you can ignore the fact that byte is signed.
>
> You can then use InetAddress.getByAddress(byte[])
> to obtain an InetAddress (actually an Inet4Address).



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-03-2004
On Tue, 4 May 2004 03:36:01 +0900, "somez72" <(E-Mail Removed)>
wrote or quoted :

>I need to convert it to IP address format ( xxx.yyy.zzz.ccc ) in my JAVA
>application.


I posted code for that yesterday. See
http://mindprod.com/jgloss/ip.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
[sun java] conver charset for string Rafal \(sxat\) Java 1 04-15-2007 07:03 PM
Conver Time to Seconds vunet.us@gmail.com Javascript 8 01-13-2007 12:26 AM
can '1' be conver to true ,and the '0' conver to false ? Kylin ASP .Net 2 06-02-2005 03:08 PM
how i conver a string to number with asp? John Muñoz ASP General 1 11-20-2003 08:35 PM



Advertisments