#!/bin/perl
use Socket;

#macros in /usr/include/netinet/in.h
sub IPPROTO_IP {return 0;}   #IPv4
sub IP_TTL     {return 4;}   #IPv4 time to live

socket(S, AF_INET, SOCK_DGRAM, 0) or die "$0: $!";
$ttl = getsockopt(S, IPPROTO_IP, IP_TTL) or die "$0: $!";
$t = unpack('I', $ttl);
print "The time to live is $t.\n";
exit 0;
