#include /* for perror */ #include #include #include int main(int argc, char **argv) { const int s = socket(AF_INET, SOCK_DGRAM, 0); int ttl; /* time to live */ socklen_t length = sizeof ttl; if (s < 0) { perror(argv[0]); /* Print message starting with argv[0]. */ return 1; } if (getsockopt(s, IPPROTO_IP, IP_TTL, &ttl, &length) != 0) { perror(argv[0]); return 2; } printf("The time to live is %d.\n", ttl); return EXIT_SUCCESS; }