ipsocket ttl

D

Dave King

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

Guillaume Marcais

Le 2 f=E9vr. 06, =E0 22:48, Dave King a =E9crit :
I was wondering if there is any way to specify the time-to-live value=20=
of
an IP socket in ruby?

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

In Ruby:

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

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

Hope this help,
Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top