Blame SOURCES/cups-avahi-address.patch

3635cf
diff -up cups-2.2b2/cups/http-support.c.avahi-address cups-2.2b2/cups/http-support.c
3635cf
--- cups-2.2b2/cups/http-support.c.avahi-address	2016-06-24 17:43:35.000000000 +0200
3635cf
+++ cups-2.2b2/cups/http-support.c	2016-06-27 15:31:34.201361844 +0200
3635cf
@@ -2340,7 +2340,7 @@ http_resolve_cb(
3635cf
     const char             *type,	/* I - Registration type */
3635cf
     const char             *domain,	/* I - Domain (unused) */
3635cf
     const char             *hostTarget,	/* I - Hostname */
3635cf
-    const AvahiAddress     *address,	/* I - Address (unused) */
3635cf
+    const AvahiAddress     *address,	/* I - Address */
3635cf
     uint16_t               port,	/* I - Port number */
3635cf
     AvahiStringList        *txt,	/* I - TXT record */
3635cf
     AvahiLookupResultFlags flags,	/* I - Lookup flags (unused) */
3635cf
@@ -2493,39 +2493,62 @@ http_resolve_cb(
3635cf
     * getting the IP address of the .local name and then do reverse-lookups...
3635cf
     */
3635cf
 
3635cf
-    http_addrlist_t	*addrlist,	/* List of addresses */
3635cf
-			*addr;		/* Current address */
3635cf
+    http_addr_t addr;
3635cf
+    size_t addrlen;
3635cf
+    int error;
3635cf
 
3635cf
     DEBUG_printf(("5http_resolve_cb: Looking up \"%s\".", hostTarget));
3635cf
 
3635cf
-    snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
3635cf
-    if ((addrlist = httpAddrGetList(hostTarget, AF_UNSPEC, fqdn)) != NULL)
3635cf
+    switch (address->proto)
3635cf
     {
3635cf
-      for (addr = addrlist; addr; addr = addr->next)
3635cf
+    case AVAHI_PROTO_INET:
3635cf
+      addr.ipv4.sin_family = AF_INET;
3635cf
+      addrlen = sizeof (addr.ipv4.sin_addr);
3635cf
+      memcpy (&addr.ipv4.sin_addr, &address->data, addrlen);
3635cf
+      break;
3635cf
+    case AVAHI_PROTO_INET6:
3635cf
+      addr.ipv6.sin6_family = AF_INET6;
3635cf
+      addrlen = sizeof (addr.ipv6.sin6_addr);
3635cf
+      memcpy (&addr.ipv6.sin6_addr, &address->data, addrlen);
3635cf
+      break;
3635cf
+    default:
3635cf
+      DEBUG_printf(("8http_resolve_cb: unknown address family %d",
3635cf
+		    address->proto));
3635cf
+      addrlen = 0;
3635cf
+    }
3635cf
+
3635cf
+    if (addrlen > 0) {
3635cf
+      error = getnameinfo(&addr.addr, httpAddrLength (&addr),
3635cf
+			  fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
3635cf
+
3635cf
+      if (!error)
3635cf
       {
3635cf
-        int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
3635cf
+	DEBUG_printf(("8http_resolve_cb: Found \"%s\".", fqdn));
3635cf
 
3635cf
-        if (!error)
3635cf
-	{
3635cf
-	  DEBUG_printf(("5http_resolve_cb: Found \"%s\".", fqdn));
3635cf
+	if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
3635cf
+	    _cups_strcasecmp(hostptr, ".local"))
3635cf
 
3635cf
-	  if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
3635cf
-	      _cups_strcasecmp(hostptr, ".local"))
3635cf
-	  {
3635cf
-	    hostTarget = fqdn;
3635cf
-	    break;
3635cf
-	  }
3635cf
+	{
3635cf
+	  hostTarget = fqdn;
3635cf
 	}
3635cf
+      } else {
3635cf
+	avahi_address_snprint (fqdn, sizeof (fqdn), address);
3635cf
+	hostTarget = fqdn;
3635cf
+
3635cf
 #ifdef DEBUG
3635cf
-	else
3635cf
-	  DEBUG_printf(("5http_resolve_cb: \"%s\" did not resolve: %d",
3635cf
-	                httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)),
3635cf
-			error));
3635cf
+	DEBUG_printf(("8http_resolve_cb: \"%s\" did not resolve: %d",
3635cf
+		      fqdn, error));
3635cf
 #endif /* DEBUG */
3635cf
       }
3635cf
 
3635cf
-      httpAddrFreeList(addrlist);
3635cf
     }
3635cf
+  } else {
3635cf
+   /*
3635cf
+    * Use the IP address that responded...
3635cf
+    */
3635cf
+
3635cf
+   avahi_address_snprint (fqdn, sizeof (fqdn), address);
3635cf
+   hostTarget = fqdn;
3635cf
   }
3635cf
 
3635cf
  /*