Decimal to IP address
[1/3] from: ptretter::prodigy::net at: 9-Dec-2000 17:21
Anyone have an easy solution for converting a 32 bit decimal number to ip address. Paul Tretter We could really use a built in function for REBOL/Core I believe.
[2/3] from: kevin:sunshinecable at: 11-Dec-2000 11:59
On Sat, 9 Dec 2000, Paul E Tretter wrote:
> Anyone have an easy solution for converting a 32 bit decimal number to ip address. > > Paul Tretter
Hi Paul, How about: dectoip: make function! [netdec] [ d: netdec // 256 c: (to-integer netdec / 256) // 256 b: (to-integer netdec / 65536) // 256 a: (to-integer netdec / 16777216) ip: to-tuple rejoin [a "." b "." c "." d] ] print dectoip 3509897244 == 220.127.116.11 Regards, Kev
[3/3] from: holger:rebol at: 11-Dec-2000 14:17
On Mon, Dec 11, 2000 at 11:59:40AM -0800, Kevin McKinnon wrote:
> On Sat, 9 Dec 2000, Paul E Tretter wrote: > >
<<quoted lines omitted: 12>>> print dectoip 3509897244 > == 18.104.22.168
A problem is that you would need to know whether the integer is in host byte order or network byte order. For network byte order the above function looks correct. For host byte order it would depend on whether the number was created on a big endian or little endian machine. For big endian the function is still correct, but for little endian you need to use ip: to-tuple rejoin [d "." c "." b "." a] to form the IP address. -- Holger Kruse [holger--rebol--com]
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted