Forum: Ruby ipsocket ttl

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
48cab1f4522b7efc4d02e497303171a5?d=identicon&s=25 Dave King (Guest)
on 2006-02-03 04:50
(Received via mailing list)
I was wondering if there is any way to specify the time-to-live value of
an IP socket in ruby?
D8831c4665a164c6ce484003deb1afd6?d=identicon&s=25 Guillaume Marcais (Guest)
on 2006-02-05 15:07
(Received via mailing list)
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.
This topic is locked and can not be replied to.