From a2ba56ac2dcf2b8f42bff9c047eb8e1daa3dfda7 Mon Sep 17 00:00:00 2001 From: octo Date: Mon, 30 Jan 2006 17:15:39 +0000 Subject: [PATCH] Added the `MulticastTTL' option so users can set a TTL different to `1'. --- src/configfile.c | 7 ++----- src/network.c | 26 ++++++++++++++++++++++++++ src/network.h | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index c217724a..52978b39 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -69,15 +69,12 @@ typedef struct cf_mode_item */ static cf_mode_item_t cf_mode_list[] = { - /* - {"Server", NULL, MODE_CLIENT }, - {"Port", NULL, MODE_CLIENT | MODE_SERVER }, - */ + {"MulticastTTL",NULL, MODE_CLIENT }, {"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}, {"DataDir", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}, {"LogFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL} }; -static int cf_mode_num = 3; +static int cf_mode_num = 4; static int nesting_depth = 0; static char *current_module = NULL; diff --git a/src/network.c b/src/network.c index 3fe25fd4..cecf0bad 100644 --- a/src/network.c +++ b/src/network.c @@ -33,6 +33,7 @@ #include "network.h" #include "common.h" +#include "configfile.h" #include "utils_debug.h" /* 1500 - 40 - 8 = Ethernet packet - IPv6 header - UDP header */ @@ -61,6 +62,16 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) { int loop = 1; + char *ttl_str; + int ttl_int; + + ttl_str = cf_get_option ("MulticastTTL", NULL); + ttl_int = 0; + if (ttl_str != NULL) + ttl_int = atoi (ttl_str); + if ((ttl_int < 1) || (ttl_int > 255)) + ttl_int = NET_DEFAULT_MC_TTL; + DBG ("fd = %i; calling `bind'", se->fd); if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1) @@ -88,6 +99,14 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) return (-1); } + /* IP_MULTICAST_TTL */ + if (setsockopt (se->fd, IPPROTO_IP, IP_MULTICAST_TTL, + &ttl_int, sizeof (ttl_int)) == -1) + { + syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + return (-1); + } + if (setsockopt (se->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) == -1) { @@ -128,6 +147,13 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) return (-1); } + if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + &ttl_int, sizeof (ttl_int)) == -1) + { + syslog (LOG_ERR, "setsockopt: %s", strerror (errno)); + return (-1); + } + if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) == -1) { diff --git a/src/network.h b/src/network.h index 374448cc..aa3d3fcd 100644 --- a/src/network.h +++ b/src/network.h @@ -54,6 +54,7 @@ #define NET_DEFAULT_V4_ADDR "239.192.74.66" #define NET_DEFAULT_V6_ADDR "ff18::efc0:4a42" #define NET_DEFAULT_PORT "25826" +#define NET_DEFAULT_MC_TTL 1 int network_create_socket (const char *node, const char *service); int network_receive (char **host, char **type, char **instance, char **value); -- 2.30.2