diff options
author | Till Kamppeter <till.kamppeter@gmail.com> | 2020-08-25 21:34:00 +0200 |
---|---|---|
committer | Didier Raboud <odyx@debian.org> | 2020-09-03 08:54:23 +0200 |
commit | 9f3961eee4da243dd5a4df2db058cd7b6a85a2a6 (patch) | |
tree | d58f99ca44deeb4cc51e910b99211bb4e978b4bb | |
parent | 522ab59581f69039504dbc58c5afc5cafdd16f93 (diff) |
Resolve DNS-SD-service-name-based URIs correctly also if they are from a service from localhost (like IPP-over-USB, Printer Application, ...)
-rw-r--r-- | cups/http-support.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/cups/http-support.c b/cups/http-support.c index 63175145e..8eabaee4c 100644 --- a/cups/http-support.c +++ b/cups/http-support.c @@ -2483,7 +2483,7 @@ http_poll_cb( static void http_resolve_cb( AvahiServiceResolver *resolver, /* I - Resolver (unused) */ - AvahiIfIndex interface, /* I - Interface index (unused) */ + AvahiIfIndex interface, /* I - Interface index */ AvahiProtocol protocol, /* I - Network protocol (unused) */ AvahiResolverEvent event, /* I - Event (found, etc.) */ const char *name, /* I - Service name */ @@ -2504,6 +2504,7 @@ http_resolve_cb( *resdefault; /* Default path */ char resource[257], /* Remote path */ fqdn[256]; /* FQDN of the .local name */ + char ifname[IF_NAMESIZE]; /* Interface name */ AvahiStringList *pair; /* Current TXT record key/value pair */ char *value; /* Value for "rp" key */ size_t valueLen = 0; /* Length of "rp" key */ @@ -2631,12 +2632,36 @@ http_resolve_cb( } /* + * Check whether the interface is the loopback interface ("lo"), in this + * case set "localhost" as the host name + */ + + if (!if_indextoname((unsigned int)interface, ifname)) + { + if (uribuf->options & _HTTP_RESOLVE_STDERR) + fprintf(stderr, + "DEBUG: Unable to find interface name for interface %d: %s\n", + interface, strerror(errno)); + DEBUG_printf(("Unable to find interface name for interface %d: %s\n", + interface, strerror(errno))); + ifname[0] = '\0'; + } + + if (!strcmp(ifname, "lo")) { + if (uribuf->options & _HTTP_RESOLVE_STDERR) + fputs("DEBUG: Service comes from loopback interface \"lo\", setting \"localhost\" as host name.\n", + stderr); + DEBUG_puts("Service comes from loopback interface \"lo\", setting \"localhost\" as host name."); + hostTarget = "localhost"; + } + + /* * Lookup the FQDN if needed... */ - if ((uribuf->options & _HTTP_RESOLVE_FQDN) && - (hostptr = hostTarget + strlen(hostTarget) - 6) > hostTarget && - !_cups_strcasecmp(hostptr, ".local")) + else if ((uribuf->options & _HTTP_RESOLVE_FQDN) && + (hostptr = hostTarget + strlen(hostTarget) - 6) > hostTarget && + !_cups_strcasecmp(hostptr, ".local")) { /* * OK, we got a .local name but the caller needs a real domain. Start by |