cups-avahi-address.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. diff -up cups-2.2b2/cups/http-support.c.avahi-address cups-2.2b2/cups/http-support.c
  2. --- cups-2.2b2/cups/http-support.c.avahi-address 2016-06-24 17:43:35.000000000 +0200
  3. +++ cups-2.2b2/cups/http-support.c 2016-06-27 15:31:34.201361844 +0200
  4. @@ -2340,7 +2340,7 @@ http_resolve_cb(
  5. const char *type, /* I - Registration type */
  6. const char *domain, /* I - Domain (unused) */
  7. const char *hostTarget, /* I - Hostname */
  8. - const AvahiAddress *address, /* I - Address (unused) */
  9. + const AvahiAddress *address, /* I - Address */
  10. uint16_t port, /* I - Port number */
  11. AvahiStringList *txt, /* I - TXT record */
  12. AvahiLookupResultFlags flags, /* I - Lookup flags (unused) */
  13. @@ -2493,39 +2493,62 @@ http_resolve_cb(
  14. * getting the IP address of the .local name and then do reverse-lookups...
  15. */
  16. - http_addrlist_t *addrlist, /* List of addresses */
  17. - *addr; /* Current address */
  18. + http_addr_t addr;
  19. + size_t addrlen;
  20. + int error;
  21. DEBUG_printf(("5http_resolve_cb: Looking up \"%s\".", hostTarget));
  22. - snprintf(fqdn, sizeof(fqdn), "%d", ntohs(port));
  23. - if ((addrlist = httpAddrGetList(hostTarget, AF_UNSPEC, fqdn)) != NULL)
  24. + switch (address->proto)
  25. {
  26. - for (addr = addrlist; addr; addr = addr->next)
  27. + case AVAHI_PROTO_INET:
  28. + addr.ipv4.sin_family = AF_INET;
  29. + addrlen = sizeof (addr.ipv4.sin_addr);
  30. + memcpy (&addr.ipv4.sin_addr, &address->data, addrlen);
  31. + break;
  32. + case AVAHI_PROTO_INET6:
  33. + addr.ipv6.sin6_family = AF_INET6;
  34. + addrlen = sizeof (addr.ipv6.sin6_addr);
  35. + memcpy (&addr.ipv6.sin6_addr, &address->data, addrlen);
  36. + break;
  37. + default:
  38. + DEBUG_printf(("8http_resolve_cb: unknown address family %d",
  39. + address->proto));
  40. + addrlen = 0;
  41. + }
  42. +
  43. + if (addrlen > 0) {
  44. + error = getnameinfo(&addr.addr, httpAddrLength (&addr),
  45. + fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
  46. +
  47. + if (!error)
  48. {
  49. - int error = getnameinfo(&(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr)), fqdn, sizeof(fqdn), NULL, 0, NI_NAMEREQD);
  50. + DEBUG_printf(("8http_resolve_cb: Found \"%s\".", fqdn));
  51. - if (!error)
  52. - {
  53. - DEBUG_printf(("5http_resolve_cb: Found \"%s\".", fqdn));
  54. + if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
  55. + _cups_strcasecmp(hostptr, ".local"))
  56. - if ((hostptr = fqdn + strlen(fqdn) - 6) <= fqdn ||
  57. - _cups_strcasecmp(hostptr, ".local"))
  58. - {
  59. - hostTarget = fqdn;
  60. - break;
  61. - }
  62. + {
  63. + hostTarget = fqdn;
  64. }
  65. + } else {
  66. + avahi_address_snprint (fqdn, sizeof (fqdn), address);
  67. + hostTarget = fqdn;
  68. +
  69. #ifdef DEBUG
  70. - else
  71. - DEBUG_printf(("5http_resolve_cb: \"%s\" did not resolve: %d",
  72. - httpAddrString(&(addr->addr), fqdn, sizeof(fqdn)),
  73. - error));
  74. + DEBUG_printf(("8http_resolve_cb: \"%s\" did not resolve: %d",
  75. + fqdn, error));
  76. #endif /* DEBUG */
  77. }
  78. - httpAddrFreeList(addrlist);
  79. }
  80. + } else {
  81. + /*
  82. + * Use the IP address that responded...
  83. + */
  84. +
  85. + avahi_address_snprint (fqdn, sizeof (fqdn), address);
  86. + hostTarget = fqdn;
  87. }
  88. /*