diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-08-02 11:05:52 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-08-02 11:05:52 +0200 |
commit | 00093ae71662ad597ac7db916ff08fe2f18e901d (patch) | |
tree | 7fac408c96d39a251f863fec77694ae76f9e005c | |
parent | 64644ddece9e6f5f08469ab4ad1277ab31983dad (diff) |
llmnr-query: Set TTL values as suggested in RFC 4795, section 2.5
Follow commit 64644dde ("socket: Set TTL values as suggested in RFC
4795, section 2.5") and set the TTL of the IP header to 255 for UDP
unicast and multicast packets, as recommended in RFC 4795, section 2.5.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | llmnr-query.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/llmnr-query.c b/llmnr-query.c index 303961d..de3df26 100644 --- a/llmnr-query.c +++ b/llmnr-query.c @@ -1,7 +1,7 @@ /* * Simple LLMNR query command. * - * Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch> + * Copyright (C) 2015-2016 Tobias Klauser <tklauser@distanz.ch> * * This file is part of llmnrd. * @@ -67,7 +67,7 @@ static void __noreturn usage_and_exit(int status) static void __noreturn version_and_exit(void) { fprintf(stdout, "llmnr-query %s %s\n" - "Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch>\n" + "Copyright (C) 2015-2016 Tobias Klauser <tklauser@distanz.ch>\n" "Licensed under the GNU General Public License, version 2\n", VERSION_STRING, GIT_VERSION); exit(EXIT_SUCCESS); @@ -96,6 +96,7 @@ int main(int argc, char **argv) uint16_t qtype = LLMNR_QTYPE_A; bool ipv6 = false; struct pkt *p; + static const int TTL = 255; while ((c = getopt_long(argc, argv, short_ops, long_opts, NULL)) != -1) { switch (c) { @@ -151,6 +152,30 @@ int main(int argc, char **argv) return -1; } + if (ipv6) { + /* RFC 4795, section 2.5 recommends to set TTL to 255 for UDP */ + if (setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &TTL, sizeof(TTL)) < 0) { + log_err("Failed to set IPv6 unicast hops socket option: %s\n", strerror(errno)); + goto err; + } + + if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &TTL, sizeof(TTL)) < 0) { + log_err("Failed to set IPv6 multicast hops socket option: %s\n", strerror(errno)); + goto err; + } + } else { + /* RFC 4795, section 2.5 recommends to set TTL to 255 for UDP */ + if (setsockopt(sock, IPPROTO_IP, IP_TTL, &TTL, sizeof(TTL)) < 0) { + log_err("Failed to set IPv4 unicast TTL socket option: %s\n", strerror(errno)); + goto err; + } + + if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &TTL, sizeof(TTL)) < 0) { + log_err("Failed to set IPv4 multicast TTL socket option: %s\n", strerror(errno)); + goto err; + } + } + if (iface != NULL) { unsigned int ifindex = if_nametoindex(iface); |