From a7cf22d3ec6bc1e6cc34878dbc211b726d143285 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 2 May 2017 21:54:15 +0200 Subject: add configuration option for protocol (IPv4 vs. IPv6) --- pacredir.c | 22 ++++++++++++++++++++-- pacredir.conf | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pacredir.c b/pacredir.c index 9fc08fd..6453bcf 100644 --- a/pacredir.c +++ b/pacredir.c @@ -609,6 +609,7 @@ int main(int argc, char ** argv) { dictionary * ini; const char * inistring; char * values, * value; + int8_t use_proto = AVAHI_PROTO_UNSPEC; uint16_t port; struct ignore_interfaces * tmp_ignore_interfaces; AvahiClient *client = NULL; @@ -670,6 +671,7 @@ int main(int argc, char ** argv) { /* continue anyway, there is nothing essential in the config file */ } else { int ini_verbose; + const char * tmp; /* extra verbosity from config */ ini_verbose = iniparser_getint(ini, "general:verbose", 0); @@ -699,6 +701,22 @@ int main(int argc, char ** argv) { free(values); } + /* configure protocols to use */ + if ((tmp = iniparser_getstring(ini, "general:protocol", NULL)) != NULL) { + switch(tmp[strlen(tmp) - 1]) { + case '4': + if (verbose > 0) + write_log(stdout, "Using IPv4 only\n"); + use_proto = AVAHI_PROTO_INET; + break; + case '6': + if (verbose > 0) + write_log(stdout, "Using IPv6 only\n"); + use_proto = AVAHI_PROTO_INET6; + break; + } + } + /* add static pacserve hosts */ if ((inistring = iniparser_getstring(ini, "general:pacserve hosts", NULL)) != NULL) { values = strdup(inistring); @@ -755,14 +773,14 @@ int main(int argc, char ** argv) { /* create the service browser for PACSERVE */ if ((pacserve = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, - AVAHI_PROTO_UNSPEC, PACSERVE, NULL, 0, browse_callback, client)) == NULL) { + use_proto, PACSERVE, NULL, 0, browse_callback, client)) == NULL) { write_log(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); goto fail; } /* create the service browser for PACDBSERVE */ if ((pacdbserve = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, - AVAHI_PROTO_UNSPEC, PACDBSERVE, NULL, 0, browse_callback, client)) == NULL) { + use_proto, PACDBSERVE, NULL, 0, browse_callback, client)) == NULL) { write_log(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); goto fail; } diff --git a/pacredir.conf b/pacredir.conf index c9a03cd..1f14bf3 100644 --- a/pacredir.conf +++ b/pacredir.conf @@ -19,6 +19,11 @@ max threads = 0 #ignore interfaces = openvpn #ignore interfaces = tap0 tun0 openvpn +# Specify to use IPv4, IPv6 or both. +protocol = IPv4 +#protocol = IPv6 +#protocol = both + # You may want to add hosts that do not announce their services via avahi or # are connected to a different network segment. Add them here. # Please note that pacdbserve hosts depend on the servers architecture! -- cgit v1.2.3-54-g00ecf