-int avahi_server_add_dns_server_address(
- AvahiServer *s,
- AvahiSEntryGroup *g,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- const char *domain,
- AvahiDNSServerType type,
- const AvahiAddress *address,
- uint16_t port /** should be 53 */) {
-
- AvahiRecord *r;
- int ret;
- char n[64] = "ip-";
-
- assert(s);
- assert(address);
- assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
- assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
-
- if (port == 0)
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
-
- if (domain && !avahi_is_valid_domain_name(domain))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
-
- if (address->family == AVAHI_PROTO_INET) {
- hexstring(n+3, sizeof(n)-3, &address->data, 4);
- r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME);
- r->data.a.address = address->data.ipv4;
- } else {
- hexstring(n+3, sizeof(n)-3, &address->data, 6);
- r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME);
- r->data.aaaa.address = address->data.ipv6;
- }
-
- if (!r)
- return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
-
- ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r);
- avahi_record_unref(r);
-
- if (ret < 0)
- return ret;
-
- return avahi_server_add_dns_server_name(s, g, interface, protocol, domain, type, n, port);
-}
-
-int avahi_server_add_dns_server_name(
- AvahiServer *s,
- AvahiSEntryGroup *g,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- const char *domain,
- AvahiDNSServerType type,
- const char *name,
- uint16_t port /** should be 53 */) {
-
- int ret = -1;
- char t[256], *d = NULL, *n = NULL;
- AvahiRecord *r;
-
- assert(s);
- assert(name);
- assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
-
- if (port == 0)
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT);
-
- if (!avahi_is_valid_domain_name(name))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
-
- if (domain && !avahi_is_valid_domain_name(domain))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
-
-
- if (!domain)
- domain = s->domain_name;
-
- if (!(n = avahi_normalize_name(name)) ||
- !(d = avahi_normalize_name(domain))) {
- avahi_free(n);
- avahi_free(d);
- return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
- }
-
- snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", d);
- avahi_free(d);
-
- if (!(r = avahi_record_new_full(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) {
- avahi_free(n);
- return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
- }
-
- r->data.srv.priority = 0;
- r->data.srv.weight = 0;
- r->data.srv.port = port;
- r->data.srv.name = n;
- ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_NULL, r);
- avahi_record_unref(r);
-
- return ret;
-}
-
-static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) {
- AvahiKey *k = userdata;
-
- assert(m);
- assert(i);
- assert(k);
-
- avahi_interface_post_query(i, k, 0);
-}