Ipsocket ttl

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

Le 2 févr. 06, à 22:48, Dave K. 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs