4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include "subscribe.h"
29 struct AvahiHostNameResolver {
33 AvahiRecordResolver *record_resolver_a;
34 AvahiRecordResolver *record_resolver_aaaa;
36 AvahiHostNameResolverCallback callback;
39 AVAHI_LLIST_FIELDS(AvahiHostNameResolver, resolver);
42 static void record_resolver_callback(AvahiRecordResolver*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
43 AvahiHostNameResolver *r = userdata;
50 switch (record->key->type) {
51 case AVAHI_DNS_TYPE_A:
53 a.data.ipv4 = record->data.a.address;
56 case AVAHI_DNS_TYPE_AAAA:
58 a.data.ipv6 = record->data.aaaa.address;
65 r->callback(r, interface, protocol, event, record->key->name, &a, r->userdata);
68 AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *s, gint interface, guchar protocol, const gchar *host_name, AvahiHostNameResolverCallback callback, gpointer userdata) {
69 AvahiHostNameResolver *r;
76 r = g_new(AvahiHostNameResolver, 1);
78 r->host_name = avahi_normalize_name(host_name);
79 r->callback = callback;
80 r->userdata = userdata;
82 k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
83 r->record_resolver_a = avahi_record_resolver_new(s, interface, protocol, k, record_resolver_callback, r);
86 k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
87 r->record_resolver_aaaa = avahi_record_resolver_new(s, interface, protocol, k, record_resolver_callback, r);
90 AVAHI_LLIST_PREPEND(AvahiHostNameResolver, resolver, s->host_name_resolvers, r);
95 void avahi_host_name_resolver_free(AvahiHostNameResolver *r) {
98 AVAHI_LLIST_REMOVE(AvahiHostNameResolver, resolver, r->server->host_name_resolvers, r);
100 avahi_record_resolver_free(r->record_resolver_a);
101 avahi_record_resolver_free(r->record_resolver_aaaa);
102 g_free(r->host_name);