X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Favahi-test.c;h=51a3a03371147ee335edf9a855875dee5e71c038;hb=c3575017e2137ef664e4735bd6f9ff1209653ef3;hp=cf8bd3b83c232aedb05913ff8b6bdced499acc12;hpb=41f2725b37437a585ce285051bdae06f4919dc3b;p=catta diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c index cf8bd3b..51a3a03 100644 --- a/avahi-core/avahi-test.c +++ b/avahi-core/avahi-test.c @@ -33,10 +33,13 @@ #include #include #include +#include + #include #include #include #include +#include static AvahiSEntryGroup *group = NULL; static AvahiServer *server = NULL; @@ -121,7 +124,8 @@ static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntry static void server_callback(AvahiServer *s, AvahiServerState state, void* userdata) { - avahi_log_debug("server state: %i", state); + server = s; + avahi_log_debug("server state: %i", state); if (state == AVAHI_SERVER_RUNNING) { avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s)); @@ -145,6 +149,7 @@ static void remove_entries(void) { static void create_entries(int new_name) { AvahiAddress a; + AvahiRecord *r; remove_entries(); @@ -181,6 +186,14 @@ static void create_entries(int new_name) { goto fail; } + r = avahi_record_new_full("cname.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL); + r->data.cname.name = avahi_strdup("cocaine.local"); + + if (avahi_server_add(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, r) < 0) { + avahi_log_error("Failed to add CNAME record"); + goto fail; + } + avahi_s_entry_group_commit(group); return; @@ -200,7 +213,7 @@ static void hnr_callback( const AvahiAddress *a, AvahiLookupResultFlags flags, void* userdata) { - char t[64]; + char t[AVAHI_ADDRESS_STR_MAX]; if (a) avahi_address_snprint(t, sizeof(t), a); @@ -217,7 +230,7 @@ static void ar_callback( const char *hostname, AvahiLookupResultFlags flags, void* userdata) { - char t[64]; + char t[AVAHI_ADDRESS_STR_MAX]; avahi_address_snprint(t, sizeof(t), a); @@ -280,7 +293,7 @@ static void sr_callback( if (event != AVAHI_RESOLVER_FOUND) avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event)); else { - char t[64], *s; + char t[AVAHI_ADDRESS_STR_MAX], *s; avahi_address_snprint(t, sizeof(t), a); @@ -301,7 +314,7 @@ static void dsb_callback( AvahiLookupResultFlags flags, void* userdata) { - char t[64] = "n/a"; + char t[AVAHI_ADDRESS_STR_MAX] = "n/a"; if (a) avahi_address_snprint(t, sizeof(t), a); @@ -341,7 +354,7 @@ int main(int argc, char *argv[]) { r = avahi_s_record_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, k, 0, record_browser_callback, NULL); avahi_key_unref(k); - hnr = avahi_s_host_name_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "cocaine.local", AVAHI_PROTO_UNSPEC, 0, hnr_callback, NULL); + hnr = avahi_s_host_name_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "cname.local", AVAHI_PROTO_UNSPEC, 0, hnr_callback, NULL); ar = avahi_s_address_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, avahi_address_parse("192.168.50.1", AVAHI_PROTO_INET, &a), 0, ar_callback, NULL);