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

Discussion in 'Java' started by somez72, May 3, 2004.

  1. somez72

    somez72 Guest

    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.
     
    somez72, May 3, 2004
    #1
    1. Advertising

  2. somez72

    Karthik Guest

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

    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.
     
    Karthik, May 3, 2004
    #2
    1. Advertising

  3. Re: I'd like to conver long value to IP address, which fuction doI have to use?

    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).
     
    Thomas Schodt, May 3, 2004
    #3
  4. somez72

    somez72 Guest

    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$...
    > 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).
     
    somez72, May 3, 2004
    #4
  5. somez72

    Roedy Green Guest

    On Tue, 4 May 2004 03:36:01 +0900, "somez72" <>
    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.
     
    Roedy Green, May 3, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kylin
    Replies:
    2
    Views:
    423
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Jun 2, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    444
    Stylus Studio
    Sep 26, 2006
  3. Rafal \(sxat\)

    [sun java] conver charset for string

    Rafal \(sxat\), Apr 14, 2007, in forum: Java
    Replies:
    1
    Views:
    2,832
    Joshua Cranmer
    Apr 15, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    828
    Peter Nilsson
    Jan 15, 2008
  5. John Muñoz

    how i conver a string to number with asp?

    John Muñoz, Nov 20, 2003, in forum: ASP General
    Replies:
    1
    Views:
    140
    Aaron Bertrand - MVP
    Nov 20, 2003
Loading...

Share This Page