[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inet_aton / inet_ntoa

Franz Bettag

3/15/2006 11:37:00 PM

Hi guys,

i have a big problem with ruby + inet_aton.
Since IPAddr has the to_i function it can convert IPAddrs to integers
(inet_aton). But i didn't find any function that reverses this
(inet_ntoa).. And without such a function, i can't work =)

Any ideas?

thanks!
--


Mit freundlichen Grüßen / best regards

Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-h...

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665
3 Answers

Ara.T.Howard

3/16/2006 12:39:00 AM

0

Claudio Jeker

3/16/2006 8:27:00 AM

0

On Thu, Mar 16, 2006 at 08:38:46AM +0900, Franz Bettag wrote:
> Hi guys,
>
> i have a big problem with ruby + inet_aton.
> Since IPAddr has the to_i function it can convert IPAddrs to integers
> (inet_aton). But i didn't find any function that reverses this
> (inet_ntoa).. And without such a function, i can't work =)
>
> Any ideas?
>

require "ipaddr"

IPAddr.new("192.168.42.21").to_i
=> 3232246293
IPAddr.new(3232246293, Socket::AF_INET).to_s
=> "192.168.42.21"

Same works for Socket::AF_INET6.

Additionally you can do:

IPAddr.new_ntoh([ 3232246293 ].pack("N"))
=> #<IPAddr: IPv4:192.168.42.21/255.255.255.255>

IPAddr::new_ntoh creates a new ipaddr containing the given network byte
ordered string form of an IP address.

--
:wq Claudio


Franz Bettag

3/16/2006 9:13:00 AM

0

Thanks to both of you! :)


Claudio Jeker schrieb:
> On Thu, Mar 16, 2006 at 08:38:46AM +0900, Franz Bettag wrote:
>
>>Hi guys,
>>
>>i have a big problem with ruby + inet_aton.
>>Since IPAddr has the to_i function it can convert IPAddrs to integers
>>(inet_aton). But i didn't find any function that reverses this
>>(inet_ntoa).. And without such a function, i can't work =)
>>
>>Any ideas?
>>
>
>
> require "ipaddr"
>
> IPAddr.new("192.168.42.21").to_i
> => 3232246293
> IPAddr.new(3232246293, Socket::AF_INET).to_s
> => "192.168.42.21"
>
> Same works for Socket::AF_INET6.
>
> Additionally you can do:
>
> IPAddr.new_ntoh([ 3232246293 ].pack("N"))
> => #<IPAddr: IPv4:192.168.42.21/255.255.255.255>
>
> IPAddr::new_ntoh creates a new ipaddr containing the given network byte
> ordered string form of an IP address.
>


--


Mit freundlichen Grüßen

Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-h...

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665