ae12454
From 9283ba29b23dd6dc7faaf138188fd02ab38b30e8 Mon Sep 17 00:00:00 2001
ae12454
From: Till Kamppeter <till.kamppeter@gmail.com>
ae12454
Date: Fri, 15 Dec 2017 10:16:28 -0200
ae12454
Subject: [PATCH] Add support to advertise local services ("localhost") on the
ae12454
 local machine only
ae12454
ae12454
This is the patch attached to Issue #125 (on Dec 6, 2017) and also
ae12454
shown in the readme.md of ippusbxd
ae12454
(https://github.com/OpenPrinting/ippusbxd).
ae12454
ae12454
It makes also services on the loopback ("lo") interface being
ae12454
advertised and these records use "localhost" instead of the network
ae12454
host name of the machine as server host name. This way clients, like
ae12454
for example CUPS or cups-browsed will find these local services and be
ae12454
able to work with them as they were network services.
ae12454
---
ae12454
 avahi-core/iface-linux.c     | 4 ++--
ae12454
 avahi-core/iface-pfroute.c   | 8 ++++----
ae12454
 avahi-core/resolve-service.c | 3 ++-
ae12454
 3 files changed, 8 insertions(+), 7 deletions(-)
ae12454
ae12454
diff --git a/avahi-core/iface-linux.c b/avahi-core/iface-linux.c
ae12454
index c6c5f77..e116c7b 100644
ae12454
--- a/avahi-core/iface-linux.c
ae12454
+++ b/avahi-core/iface-linux.c
ae12454
@@ -104,8 +104,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
ae12454
         hw->flags_ok =
ae12454
             (ifinfomsg->ifi_flags & IFF_UP) &&
ae12454
             (!m->server->config.use_iff_running || (ifinfomsg->ifi_flags & IFF_RUNNING)) &&
ae12454
-            !(ifinfomsg->ifi_flags & IFF_LOOPBACK) &&
ae12454
-            (ifinfomsg->ifi_flags & IFF_MULTICAST) &&
ae12454
+            ((ifinfomsg->ifi_flags & IFF_LOOPBACK) ||
ae12454
+             (ifinfomsg->ifi_flags & IFF_MULTICAST)) &&
ae12454
             (m->server->config.allow_point_to_point || !(ifinfomsg->ifi_flags & IFF_POINTOPOINT));
ae12454
 
ae12454
         /* Handle interface attributes */
ae12454
diff --git a/avahi-core/iface-pfroute.c b/avahi-core/iface-pfroute.c
ae12454
index 9a2e953..27c3443 100644
ae12454
--- a/avahi-core/iface-pfroute.c
ae12454
+++ b/avahi-core/iface-pfroute.c
ae12454
@@ -80,8 +80,8 @@ static void rtm_info(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m)
ae12454
   hw->flags_ok =
ae12454
     (ifm->ifm_flags & IFF_UP) &&
ae12454
     (!m->server->config.use_iff_running || (ifm->ifm_flags & IFF_RUNNING)) &&
ae12454
-    !(ifm->ifm_flags & IFF_LOOPBACK) &&
ae12454
-    (ifm->ifm_flags & IFF_MULTICAST) &&
ae12454
+    ((ifm->ifm_flags & IFF_LOOPBACK) ||
ae12454
+     (ifm->ifm_flags & IFF_MULTICAST)) &&
ae12454
     (m->server->config.allow_point_to_point || !(ifm->ifm_flags & IFF_POINTOPOINT));
ae12454
 
ae12454
   avahi_free(hw->name);
ae12454
@@ -427,8 +427,8 @@ static void if_add_interface(struct lifreq *lifreq, AvahiInterfaceMonitor *m, in
ae12454
         hw->flags_ok =
ae12454
             (flags & IFF_UP) &&
ae12454
             (!m->server->config.use_iff_running || (flags & IFF_RUNNING)) &&
ae12454
-            !(flags & IFF_LOOPBACK) &&
ae12454
-            (flags & IFF_MULTICAST) &&
ae12454
+            ((flags & IFF_LOOPBACK) ||
ae12454
+             (flags & IFF_MULTICAST)) &&
ae12454
             (m->server->config.allow_point_to_point || !(flags & IFF_POINTOPOINT));
ae12454
         hw->name = avahi_strdup(lifreq->lifr_name);
ae12454
         hw->mtu = mtu;
ae12454
diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c
ae12454
index 3377a50..3311b6b 100644
ae12454
--- a/avahi-core/resolve-service.c
ae12454
+++ b/avahi-core/resolve-service.c
ae12454
@@ -24,6 +24,7 @@
ae12454
 #include <string.h>
ae12454
 #include <stdio.h>
ae12454
 #include <stdlib.h>
ae12454
+#include <net/if.h>
ae12454
 
ae12454
 #include <avahi-common/domain.h>
ae12454
 #include <avahi-common/timeval.h>
ae12454
@@ -129,7 +130,7 @@ static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
ae12454
                 r->service_name,
ae12454
                 r->service_type,
ae12454
                 r->domain_name,
ae12454
-                r->srv_record->data.srv.name,
ae12454
+                (r->interface == if_nametoindex("lo")) ? "localhost" : r->srv_record->data.srv.name,
ae12454
                 r->address_record ? &a : NULL,
ae12454
                 r->srv_record->data.srv.port,
ae12454
                 r->txt_record ? r->txt_record->data.txt.string_list : NULL,
ae12454
-- 
ae12454
2.17.2
ae12454