AvahiDnsPacket *reply;
AvahiRecord *r;
- if (!(reply = avahi_dns_packet_new_reply(p, 512 /* unicast DNS maximum packet size is 512 */ , 1, 1)))
+ if (!(reply = avahi_dns_packet_new_reply(p, 512 + AVAHI_DNS_PACKET_EXTRA_SIZE /* unicast DNS maximum packet size is 512 */ , 1, 1)))
return; /* OOM */
while ((r = avahi_record_list_next(s->record_list, NULL, NULL, NULL))) {
* the specific header field, and return to the caller */
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
-
break;
}
avahi_dns_packet_free(reply);
size = avahi_record_get_estimate_size(r) + AVAHI_DNS_PACKET_HEADER_SIZE;
- if (size > AVAHI_DNS_PACKET_SIZE_MAX)
- size = AVAHI_DNS_PACKET_SIZE_MAX;
- if (!(reply = avahi_dns_packet_new_reply(p, size, 0, 1)))
+ if (!(reply = avahi_dns_packet_new_reply(p, size + AVAHI_DNS_PACKET_EXTRA_SIZE, 0, 1)))
break; /* OOM */
- if (!avahi_dns_packet_append_record(reply, r, flush_cache, 0)) {
+ if (avahi_dns_packet_append_record(reply, r, flush_cache, 0)) {
+
+ /* Appending this record succeeded, so incremeant
+ * the specific header field, and return to the caller */
+
+ avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
+ break;
+
+ } else {
+
+ /* We completely fucked up, there's
+ * nothing we can do. The RR just doesn't
+ * fit in. Let's ignore it. */
+
char *t;
avahi_dns_packet_free(reply);
+ reply = NULL;
t = avahi_record_to_string(r);
avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t);
avahi_free(t);
break;
- } else
- avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
+ }
}
/* Appending the record didn't succeeed, so let's send this packet, and create a new one */
avahi_record_list_flush(s->record_list);
}
-
static void reflect_response(AvahiServer *s, AvahiInterface *i, AvahiRecord *r, int flush_cache) {
AvahiInterface *j;
int unicast_response = 0;
if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) {
- avahi_log_warn("Packet too short (1)");
+ avahi_log_warn(__FILE__": Packet too short or invalid while reading question key. (Maybe an UTF8 problem?)");
goto fail;
}
int unique = 0;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- avahi_log_warn("Packet too short (2)");
+ avahi_log_warn(__FILE__": Packet too short or invalid while reading known answer record. (Maybe an UTF8 problem?)");
goto fail;
}
int unique = 0;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- avahi_log_warn("Packet too short (3)");
+ avahi_log_warn(__FILE__": Packet too short or invalid while reading probe record. (Maybe an UTF8 problem?)");
goto fail;
}
/* char *txt; */
if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) {
- avahi_log_warn("Packet too short (4)");
+ avahi_log_warn(__FILE__": Packet too short or invalid while reading response record. (Maybe an UTF8 problem?)");
break;
}
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id);
for (j = s->monitor->interfaces; j; j = j->interface_next)
- if (avahi_interface_is_relevant(j) &&
+ if (j->announcing &&
j != i &&
(s->config.reflect_ipv || j->protocol == i->protocol)) {
assert(src_address->proto == dst_address->proto);
if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, src_address->proto)) ||
- !avahi_interface_is_relevant(i)) {
+ !i->announcing) {
avahi_log_warn("Recieved packet from invalid interface.");
return;
}
}
if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.proto)) ||
- !avahi_interface_is_relevant(j))
+ !j->announcing)
return;
/* Patch the original ID into this response */
if (!s->config.publish_domain)
return;
+ if (avahi_domain_equal(s->domain_name, "local"))
+ return;
+
if (s->browse_domain_entry_group)
assert(avahi_s_entry_group_is_empty(s->browse_domain_entry_group));
else
}
int avahi_server_set_host_name(AvahiServer *s, const char *host_name) {
+ char *hn = NULL;
assert(s);
- assert(host_name);
+
+ AVAHI_CHECK_VALIDITY(s, !host_name || avahi_is_valid_host_name(host_name), AVAHI_ERR_INVALID_HOST_NAME);
- if (host_name && !avahi_is_valid_host_name(host_name))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
+ if (!host_name) {
+ hn = avahi_get_host_name_strdup();
+ hn[strcspn(hn, ".")] = 0;
+ host_name = hn;
+ }
+ if (avahi_domain_equal(s->host_name, host_name) && s->state != AVAHI_SERVER_COLLISION) {
+ avahi_free(hn);
+ return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE);
+ }
+
withdraw_host_rrs(s);
avahi_free(s->host_name);
- s->host_name = host_name ? avahi_normalize_name_strdup(host_name) : avahi_get_host_name_strdup();
- s->host_name[strcspn(s->host_name, ".")] = 0;
+ s->host_name = hn ? hn : avahi_strdup(host_name);
+
update_fqdn(s);
register_stuff(s);
}
int avahi_server_set_domain_name(AvahiServer *s, const char *domain_name) {
+ char *dn = NULL;
assert(s);
- assert(domain_name);
- if (domain_name && !avahi_is_valid_domain_name(domain_name))
- return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+ AVAHI_CHECK_VALIDITY(s, !domain_name || avahi_is_valid_domain_name(domain_name), AVAHI_ERR_INVALID_DOMAIN_NAME);
+
+ if (!domain_name) {
+ dn = avahi_strdup("local");
+ domain_name = dn;
+ }
+
+ if (avahi_domain_equal(s->domain_name, domain_name)) {
+ avahi_free(dn);
+ return avahi_server_set_errno(s, AVAHI_ERR_NO_CHANGE);
+ }
withdraw_host_rrs(s);
avahi_free(s->domain_name);
- s->domain_name = domain_name ? avahi_normalize_name_strdup(domain_name) : avahi_strdup("local");
+ s->domain_name = avahi_normalize_name_strdup(domain_name);
update_fqdn(s);
register_stuff(s);
+
+ avahi_free(dn);
return AVAHI_OK;
}
c->disallow_other_stacks = 0;
c->browse_domains = NULL;
c->disable_publishing = 0;
+ c->allow_point_to_point = 0;
+ c->publish_aaaa_on_ipv4 = 1;
+ c->publish_a_on_ipv6 = 0;
return c;
}
avahi_wide_area_set_servers(s->wide_area_lookup_engine, a, n);
return AVAHI_OK;
}
+
+const AvahiServerConfig* avahi_server_get_config(AvahiServer *s) {
+ assert(s);
+
+ return &s->config;
+}