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:36:29 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:29 +0100
commit882fd010527b8d8823f09e19edbed3746265fa08 (patch)
treebe5c7cace6697afc753c152d13ad5145d0884a42 /backend/escl/escl_devices.c
parent527bedac30eb120915718eb7997e6dacd583512e (diff)
parente0d94cf4d39395df1e2c6bb4d967200298c13881 (diff)
Merge branch 'feature/upstream' into develop
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);
+ }
+ }
}
}