#include <resolv.h>
#include <glob.h>
+#include <inttypes.h>
#include <stdio.h>
#include <time.h>
#include "announce.h"
enum {
+ SERVICE_INSTANCE,
SERVICE_SERVICE,
SERVICE_PORT,
SERVICE_TXT,
};
static const struct blobmsg_policy service_policy[__SERVICE_MAX] = {
+ [SERVICE_INSTANCE] = { .name = "instance", .type = BLOBMSG_TYPE_STRING },
[SERVICE_SERVICE] = { .name = "service", .type = BLOBMSG_TYPE_STRING },
[SERVICE_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
[SERVICE_TXT] = { .name = "txt", .type = BLOBMSG_TYPE_ARRAY },
{
time_t t = monotonic_time();
- if (t - s->t <= TOUT_LOOKUP)
+ if (t - s->t <= TOUT_LOOKUP) {
+ DBG(2, "t=%" PRId64 ", s->t=%" PRId64 ", t - s->t = %" PRId64 "\n", (int64_t)t, (int64_t)s->t, (int64_t)(t - s->t));
return 0;
+ }
return t;
}
{
struct blob_attr *txt, *_tb[__SERVICE_MAX];
struct service *s;
- char *d_service, *d_id;
+ char *d_instance, *d_service, *d_id;
uint8_t *d_txt;
int rem2;
int txt_len = 0;
+ unsigned int n;
blobmsg_parse(service_policy, ARRAY_SIZE(service_policy),
_tb, blobmsg_data(b), blobmsg_data_len(b));
blobmsg_for_each_attr(txt, _tb[SERVICE_TXT], rem2)
txt_len += 1 + strlen(blobmsg_get_string(txt));
+ n = strlen(blobmsg_name(b));
s = calloc_a(sizeof(*s),
- &d_id, strlen(blobmsg_name(b)) + 1,
+ &d_id, n + 1,
+ &d_instance, _tb[SERVICE_INSTANCE] ? strlen(blobmsg_get_string(_tb[SERVICE_INSTANCE])) + 1 : 0,
&d_service, strlen(blobmsg_get_string(_tb[SERVICE_SERVICE])) + 1,
&d_txt, txt_len);
if (!s)
return;
s->port = blobmsg_get_u32(_tb[SERVICE_PORT]);
- s->id = strcpy(d_id, blobmsg_name(b));
- s->instance = umdns_host_label;
+ s->id = strncpy(d_id, blobmsg_name(b), n);
+ if (_tb[SERVICE_INSTANCE])
+ s->instance = strcpy(d_instance, blobmsg_get_string(_tb[SERVICE_INSTANCE]));
+ else
+ s->instance = umdns_host_label;
s->service = strcpy(d_service, blobmsg_get_string(_tb[SERVICE_SERVICE]));
s->active = 1;
s->t = 0;