Re: Unsigned integer to IP address?

From: Ethel Aardvark <bigjobbies_at_hotmail.com>
Date: 9 Oct 2003 04:09:59 -0700
Message-ID: <1a8fec49.0310090309.13b57737_at_posting.google.com>


In no particular language (i.e., you may need FLOOR() instead of INT())...

To convert dotted (A.B.C.D) to a number:

         D
         + 256 * C
         + 256 * 256 * B
         + 256 * 256 * 256 * A

To convert number (X) back to dotted:
         temp = X / 256
         D = 256 * (temp - INT(temp))
         temp = (INT (temp)) / 256
         C = 256 * (temp - INT(temp))
         temp = (INT (temp)) / 256
         B = 256 * (temp - INT(temp))
         A = INT (temp)

(There is a chance I have the endian-ness wrong, in which case swap A<->D and B<->C in the calculations.)

Regards,

ETA "Ana C. Dent" <anacedent_at_hotmail.com> wrote in message news:<lGhgb.54981$Ms2.34316_at_fed1read03>...
> Monica Roman wrote:
> > Hello everyone,
> > My question is how to upload an unsigned integer so that it looks like
> > an IP address in Oracle?
> > A Perl program captures IP addresses from a log server and puts them
> > into a .csv file that I then sqload into Oracle. When I query the db
> > the numbers look very different e.g., (just an example) 2423598587
> > instead of 134.290.34.59 (this was made up, any similarity to real IP
> > is pure coincidence).
> > I need them to look like an IP address.
> >
> > Thank you much,
> >
> > Monica
>
> Inside the OS an IP# is just a 32-bit integer.
> It is typically represented in what is called "dottted-quad" notation.
> This means that each 8-bit byte (0-255) represents one of the 4 numbers
> displayed. So you need to "convert" the large decimal number into the
> appropriate ONE & ZERO, group them into four 8 bits bytes & the convert
> those four values back to decimal (Small Matter Of Programming [SMOP]).
Received on Thu Oct 09 2003 - 13:09:59 CEST

Original text of this message