[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ipsocket ttl

Dave King

2/3/2006 3:49:00 AM

I was wondering if there is any way to specify the time-to-live value of
an IP socket in ruby?



1 Answer

Guillaume Marcais

2/5/2006 2:05:00 PM

0

Le 2 févr. 06, à 22:48, Dave King a écrit :

> I was wondering if there is any way to specify the time-to-live value
> of
> an IP socket in ruby?
>

This might be platform dependent. On Linux, look at 'man 7 ip' and
IP_TTL. In Ruby, you would do the same thing, call the #setsockopt
method on your socket.

In Ruby:

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> s = UDPSocket.new
=> #<UDPSocket:0xb7b86a54>
irb(main):004:0> s.getsockopt(Socket::SOL_IP, Socket::IP_TTL)
=> "@\000\000\000"
irb(main):005:0> s.getsockopt(Socket::SOL_IP,
Socket::IP_TTL).unpack("L")
=> [64]
irb(main):006:0> s.setsockopt(Socket::SOL_IP, Socket::IP_TTL,
[128].pack("L"))
=> 0
irb(main):007:0> s.getsockopt(Socket::SOL_IP,
Socket::IP_TTL).unpack("L")
=> [128]

To check if a given argument to #getsockopt is supported on your
platform, you can look at the constants defined with Socket.constants.

Hope this help,
Guillaume.