summaryrefslogtreecommitdiff
path: root/backend/escl/escl_devices.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-12 17:35:53 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:35:53 +0100
commit84357741a6a6e6430f199b2c3f7498e0e97da9ad (patch)
tree23e8d66ede9506b94c76fb36910ca3c7dd15c74e /backend/escl/escl_devices.c
parent302276dc1b90cfc972fb726ca94a23b18f4b0088 (diff)
New upstream version 1.2.1upstream/1.2.1upstream
Diffstat (limited to 'backend/escl/escl_devices.c')
-rw-r--r--backend/escl/escl_devices.c77
1 files changed, 48 insertions, 29 deletions
diff --git a/backend/escl/escl_devices.c b/backend/escl/escl_devices.c
index 92e064b..a2fdb80 100644
--- a/backend/escl/escl_devices.c
+++ b/backend/escl/escl_devices.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <arpa/inet.h>
#include <avahi-client/lookup.h>
#include <avahi-common/error.h>
@@ -53,47 +54,65 @@ static int count_finish = 0;
*/
static void
resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface,
- AVAHI_GCC_UNUSED AvahiProtocol protocol,
- AvahiResolverEvent event, const char *name,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
const char __sane_unused__ *type,
const char __sane_unused__ *domain,
const char __sane_unused__ *host_name,
- const AvahiAddress *address, uint16_t port, AvahiStringList *txt,
+ const AvahiAddress *address,
+ uint16_t port,
+ AvahiStringList *txt,
AvahiLookupResultFlags __sane_unused__ flags,
void __sane_unused__ *userdata)
{
- char a[AVAHI_ADDRESS_STR_MAX], *t;
+ char a[(AVAHI_ADDRESS_STR_MAX + 10)] = { 0 };
+ char *t;
const char *is;
const char *uuid;
AvahiStringList *s;
assert(r);
switch (event) {
- case AVAHI_RESOLVER_FAILURE:
- break;
- case AVAHI_RESOLVER_FOUND:
- avahi_address_snprint(a, sizeof(a), address);
- t = avahi_string_list_to_string(txt);
- if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) {
- char ip_add[PATH_MAX] = {0};
- s = avahi_string_list_find(txt, "is");
- if (s && s->size > 3)
- is = (const char*)s->text + 3;
- else
- is = (const char*)NULL;
- s = avahi_string_list_find(txt, "uuid");
- if (s && s->size > 5)
- uuid = (const char*)s->text + 5;
- else
- uuid = (const char*)NULL;
- DBG (10, "resolve_callback [%s]\n", a);
- if (strstr(a, "127.0.0.1") != NULL) {
- snprintf(ip_add, sizeof(ip_add), "%s", "localhost");
- DBG (10,"resolve_callback fix redirect [localhost]\n");
- }
+ case AVAHI_RESOLVER_FAILURE:
+ break;
+ case AVAHI_RESOLVER_FOUND:
+ {
+ char *psz_addr = ((void*)0);
+ char b[128] = { 0 };
+ avahi_address_snprint(b, (sizeof(b)/sizeof(b[0]))-1, address);
+#ifdef ENABLE_IPV6
+ if (protocol == AVAHI_PROTO_INET6 && strchr(b, ':'))
+ {
+ if ( asprintf( &psz_addr, "[%s]", b ) == -1 )
+ break;
+ }
else
- snprintf(ip_add, sizeof(ip_add), "%s", a);
- escl_device_add(port, name, ip_add, is, uuid, (char*)type);
- }
+#endif
+ {
+ if ( asprintf( &psz_addr, "%s", b ) == -1 )
+ break;
+ }
+ t = avahi_string_list_to_string(txt);
+ if (strstr(t, "\"rs=eSCL\"") || strstr(t, "\"rs=/eSCL\"")) {
+ s = avahi_string_list_find(txt, "is");
+ if (s && s->size > 3)
+ is = (const char*)s->text + 3;
+ else
+ is = (const char*)NULL;
+ s = avahi_string_list_find(txt, "uuid");
+ if (s && s->size > 5)
+ uuid = (const char*)s->text + 5;
+ else
+ uuid = (const char*)NULL;
+ DBG (10, "resolve_callback [%s]\n", a);
+ if (strstr(psz_addr, "127.0.0.1") != NULL) {
+ escl_device_add(port, name, "localhost", is, uuid, (char*)type);
+ DBG (10,"resolve_callback fix redirect [localhost]\n");
+ }
+ else
+ escl_device_add(port, name, psz_addr, is, uuid, (char*)type);
+ }
+ }
}
}