From 3bc57064aae80baa6e2ef86fe5c7f2158e55e53a Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Fri, 7 Aug 2009 11:32:55 +0000 Subject: get the default ttl via sysctl instead of using IPDEFTTL --- usr.sbin/relayd/check_icmp.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/relayd/check_icmp.c b/usr.sbin/relayd/check_icmp.c index 4886e3ffb0a..df95a763bab 100644 --- a/usr.sbin/relayd/check_icmp.c +++ b/usr.sbin/relayd/check_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: check_icmp.c,v 1.27 2009/08/07 11:10:23 reyk Exp $ */ +/* $OpenBSD: check_icmp.c,v 1.28 2009/08/07 11:32:54 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -16,9 +16,11 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include #include +#include #include #include @@ -168,7 +170,8 @@ send_icmp(int s, short event, void *arg) ssize_t r; u_char packet[ICMP_BUF_SIZE]; socklen_t slen; - int i = 0, ttl; + int i = 0, ttl, mib[4]; + size_t len; if (event == EV_TIMEOUT) { icmp_checks_timeout(cie, HCE_ICMP_WRITE_TIMEOUT); @@ -222,13 +225,18 @@ send_icmp(int s, short event, void *arg) } if ((ttl = host->conf.ttl) > 0) - setsockopt(s, IPPROTO_IP, IP_TTL, + (void)setsockopt(s, IPPROTO_IP, IP_TTL, &host->conf.ttl, sizeof(int)); else { /* Revert to default TTL */ - ttl = IPDEFTTL; - (void)setsockopt(s, IPPROTO_IP, IP_TTL, - &ttl, sizeof(int)); + mib[0] = CTL_NET; + mib[1] = cie->af; + mib[2] = IPPROTO_IP; + mib[3] = IPCTL_DEFTTL; + len = sizeof(ttl); + if (sysctl(mib, 4, &ttl, &len, NULL, 0) == 0) + (void)setsockopt(s, IPPROTO_IP, IP_TTL, + &ttl, sizeof(int)); } r = sendto(s, packet, sizeof(packet), 0, to, slen); -- cgit v1.2.3