From c3942de84256e54255648953ec21028626f9178c Mon Sep 17 00:00:00 2001 From: Niklas Hofmann Date: Fri, 8 Aug 2014 16:08:23 +0200 Subject: [PATCH] TXT record bugfix --- src/discovery.c | 84 ++++++++++++++++++++++++++++--------------------- src/meshlink.c | 5 +++ 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/discovery.c b/src/discovery.c index 4d1209b8..7e3fca5b 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -258,53 +258,63 @@ static void discovery_resolve_callback(AvahiSServiceResolver *resolver, AvahiIfI if(node_name_li != NULL && node_fp_li != NULL) { - char *node_name = avahi_string_list_get_text(node_name_li) + strlen(MESHLINK_MDNS_NAME_KEY) + 1; - char *node_fp = avahi_string_list_get_text(node_fp_li) + strlen(MESHLINK_MDNS_FINGERPRINT_KEY) + 1; + char *node_name = (char*)avahi_string_list_get_text(node_name_li) + strlen(MESHLINK_MDNS_NAME_KEY); + char *node_fp = (char*)avahi_string_list_get_text(node_fp_li) + strlen(MESHLINK_MDNS_FINGERPRINT_KEY); - meshlink_node_t *node = meshlink_get_node(mesh, node_name); - - if(node != NULL) + if(node_name[0] == '=' && node_fp[0] == '=') { - fprintf(stderr, "Node %s is part of the mesh network.\n", node->name); - - sockaddr_t naddress; - memset(&naddress, 0, sizeof(naddress)); + node_name += 1; + node_fp += 1; - switch(address->proto) - { - case AVAHI_PROTO_INET: - { - naddress.in.sin_family = AF_INET; - naddress.in.sin_port = port; - naddress.in.sin_addr.s_addr = address->data.ipv4.address; - } - break; - - case AVAHI_PROTO_INET6: - { - naddress.in6.sin6_family = AF_INET6; - naddress.in6.sin6_port = port; - memcpy(naddress.in6.sin6_addr.s6_addr, address->data.ipv6.address, sizeof(naddress.in6.sin6_addr.s6_addr)); - } - break; - - default: - naddress.unknown.family = AF_UNKNOWN; - break; - } + meshlink_node_t *node = meshlink_get_node(mesh, node_name); - if(naddress.unknown.family != AF_UNKNOWN) + if(node != NULL) { - meshlink_hint_address(mesh, (meshlink_node_t *)node, (struct sockaddr*)&naddress); + fprintf(stderr, "Node %s is part of the mesh network.\n", node->name); + + sockaddr_t naddress; + memset(&naddress, 0, sizeof(naddress)); + + switch(address->proto) + { + case AVAHI_PROTO_INET: + { + naddress.in.sin_family = AF_INET; + naddress.in.sin_port = port; + naddress.in.sin_addr.s_addr = address->data.ipv4.address; + } + break; + + case AVAHI_PROTO_INET6: + { + naddress.in6.sin6_family = AF_INET6; + naddress.in6.sin6_port = port; + memcpy(naddress.in6.sin6_addr.s6_addr, address->data.ipv6.address, sizeof(naddress.in6.sin6_addr.s6_addr)); + } + break; + + default: + naddress.unknown.family = AF_UNKNOWN; + break; + } + + if(naddress.unknown.family != AF_UNKNOWN) + { + meshlink_hint_address(mesh, (meshlink_node_t *)node, (struct sockaddr*)&naddress); + } + else + { + fprintf(stderr, "Could not resolve node %s to a known address family type.\n", node->name); + } } else { - fprintf(stderr, "Could not resolve node %s to a known address family type.\n", node->name); + fprintf(stderr, "Node %s is not part of the mesh network.\n", node_name); } } else { - fprintf(stderr, "Node %s is not part of the mesh network.\n", node_name); + fprintf(stderr, "TXT records invalid.\n"); } } else @@ -391,6 +401,8 @@ static void *discovery_loop(void *userdata) bool discovery_start(meshlink_handle_t *mesh) { + fprintf(stderr, "discovery_start called\n"); + // asserts assert(mesh != NULL); assert(mesh->avahi_poll == NULL); @@ -498,6 +510,8 @@ fail: void discovery_stop(meshlink_handle_t *mesh) { + fprintf(stderr, "discovery_stop called\n"); + // asserts assert(mesh != NULL); diff --git a/src/meshlink.c b/src/meshlink.c index d5ea5418..7781c4b3 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -843,6 +843,9 @@ static void *meshlink_main_loop(void *arg) { } bool meshlink_start(meshlink_handle_t *mesh) { + + fprintf(stderr, "meshlink_start called\n"); + if(!mesh) { meshlink_errno = MESHLINK_EINVAL; return false; @@ -876,6 +879,8 @@ bool meshlink_start(meshlink_handle_t *mesh) { } void meshlink_stop(meshlink_handle_t *mesh) { + + fprintf(stderr, "meshlink_stop called\n"); if(!mesh) { meshlink_errno = MESHLINK_EINVAL; -- 2.39.5