summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--socket.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/socket.c b/socket.c
index 0b0be78..872796d 100644
--- a/socket.c
+++ b/socket.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2014-2016 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of llmnrd.
*
@@ -34,6 +34,7 @@
#include "socket.h"
static const int YES = 1;
+static const int TTL = 255;
int socket_open_ipv4(uint16_t port)
{
@@ -52,6 +53,17 @@ int socket_open_ipv4(uint16_t port)
goto err;
}
+ /* 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;
+ }
+
/* bind the socket */
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
@@ -91,6 +103,17 @@ int socket_open_ipv6(uint16_t port)
goto err;
}
+ /* 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;
+ }
+
/* IPv6 only socket */
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &YES, sizeof(YES)) < 0) {
log_err("Failed to set IPv6 only socket option: %s\n", strerror(errno));