summaryrefslogtreecommitdiff
path: root/backend/escl/escl_devices.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-16 10:20:08 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-16 10:20:08 +0100
commit778ebf8ee9cb22ea5727844333bcd5a6ee6bc0de (patch)
treea754e785b286ed82b45fe4e50b980714ad80e0a7 /backend/escl/escl_devices.c
parent7d8aac1f3634dc58785bec7acf097dd6bac8c394 (diff)
parent32cb765f681299af226ca0520993cbe47ba5ecd0 (diff)
Merge branch 'release/debian/1.2.1-1'debian/1.2.1-1
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);
+ }
+ }
}
}