# Ipsocket ttl

**URL:** <https://www.ruby-forum.com/t/ipsocket-ttl/100549>\
**Category:** Ruby\
**Created:** [February 3, 2006, 4:50am UTC](https://www.ruby-forum.com/t/ipsocket-ttl/100549 "2006-02-03T04:50:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@davis](https://www.ruby-forum.com/u/davis)\
**Post date:** [February 3, 2006, 4:50am UTC](https://www.ruby-forum.com/t/ipsocket-ttl/100549/1 "2006-02-03T04:50:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@davis](https://www.ruby-forum.com/u/davis)\
**Post date:** [February 5, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/ipsocket-ttl/100549/2 "2006-02-05T15:07:45Z")

</div>

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.
