size_t avahi_address_get_size(const AvahiAddress *a) {
assert(a);
- if (a->family == AVAHI_PROTO_INET)
+ if (a->proto == AVAHI_PROTO_INET)
return 4;
- else if (a->family == AVAHI_PROTO_INET6)
+ else if (a->proto == AVAHI_PROTO_INET6)
return 16;
return 0;
assert(a);
assert(b);
- if (a->family != b->family)
+ if (a->proto != b->proto)
return -1;
return memcmp(a->data.data, b->data.data, avahi_address_get_size(a));
assert(length);
assert(a);
- return (char*) inet_ntop(a->family, a->data.data, s, length);
+ return (char*) inet_ntop(avahi_proto_to_af(a->proto), a->data.data, s, length);
}
char* avahi_reverse_lookup_name_ipv4(const AvahiIPv4Address *a) {
return reverse_lookup_name_ipv6(a, "ip6.int");
}
-AvahiAddress *avahi_address_parse(const char *s, AvahiProtocol family, AvahiAddress *ret_addr) {
+AvahiAddress *avahi_address_parse(const char *s, AvahiProtocol proto, AvahiAddress *ret_addr) {
assert(ret_addr);
assert(s);
- if (family == AVAHI_PROTO_UNSPEC) {
+ if (proto == AVAHI_PROTO_UNSPEC) {
if (inet_pton(AF_INET, s, ret_addr->data.data) <= 0) {
if (inet_pton(AF_INET6, s, ret_addr->data.data) <= 0)
return NULL;
else
- ret_addr->family = AVAHI_PROTO_INET6;
+ ret_addr->proto = AVAHI_PROTO_INET6;
} else
- ret_addr->family = AVAHI_PROTO_INET;
+ ret_addr->proto = AVAHI_PROTO_INET;
} else {
- if (inet_pton(family, s, ret_addr->data.data) <= 0)
+ if (inet_pton(avahi_proto_to_af(proto), s, ret_addr->data.data) <= 0)
return NULL;
- ret_addr->family = family;
+ ret_addr->proto = proto;
}
return ret_addr;
assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6);
- ret_addr->family = sa->sa_family;
+ ret_addr->proto = avahi_af_to_proto(sa->sa_family);
if (sa->sa_family == AF_INET)
memcpy(&ret_addr->data.ipv4, &((const struct sockaddr_in*) sa)->sin_addr, sizeof(ret_addr->data.ipv4));
assert(a);
- if (a->family != AVAHI_PROTO_INET6)
+ if (a->proto != AVAHI_PROTO_INET6)
return 0;
return memcmp(a->data.ipv6.address, ipv4_in_ipv6, sizeof(ipv4_in_ipv6)) == 0;
}
+int avahi_proto_to_af(AvahiProtocol proto) {
+ if (proto == AVAHI_PROTO_INET)
+ return AF_INET;
+ if (proto == AVAHI_PROTO_INET6)
+ return AF_INET6;
+
+ assert(proto == AVAHI_PROTO_UNSPEC);
+ return AF_UNSPEC;
+}
+
+AvahiProtocol avahi_af_to_proto(int af) {
+ if (af == AF_INET)
+ return AVAHI_PROTO_INET;
+ if (af == AF_INET6)
+ return AVAHI_PROTO_INET6;
+
+ assert(af == AF_UNSPEC);
+ return AVAHI_PROTO_UNSPEC;
+}
+
+const char* avahi_proto_to_string(AvahiProtocol proto) {
+ if (proto == AVAHI_PROTO_INET)
+ return "IPv4";
+ if (proto == AVAHI_PROTO_INET6)
+ return "IPv6";
+
+ assert(proto == AVAHI_PROTO_UNSPEC);
+ return "UNSPEC";
+}
AVAHI_C_DECL_BEGIN
/** Protocol family specification, takes the values AVAHI_INET, AVAHI_INET6, AVAHI_UNSPEC */
-typedef unsigned char AvahiProtocol;
+typedef char AvahiProtocol;
/** Numeric network interface index. Takes OS dependent values and the special constant AVAHI_IF_UNSPEC */
typedef int AvahiIfIndex;
/** Values for AvahiProtocol */
enum {
- AVAHI_PROTO_INET = AF_INET, /**< IPv4 */
- AVAHI_PROTO_INET6 = AF_INET6, /**< IPv6 */
- AVAHI_PROTO_UNSPEC = AF_UNSPEC /**< Unspecified/all protocol(s) */
+ AVAHI_PROTO_INET = 0, /**< IPv4 */
+ AVAHI_PROTO_INET6 = 1, /**< IPv6 */
+ AVAHI_PROTO_UNSPEC = -1 /**< Unspecified/all protocol(s) */
};
/** Special values for AvahiIfIndex */
/** Protocol (address family) independent address structure */
typedef struct {
- AvahiProtocol family; /**< Address family */
+ AvahiProtocol proto; /**< Address family */
union {
AvahiIPv6Address ipv6; /** Address when IPv6 */
* encapsulated IPv4 address, returns 1 if yes, 0 otherwise */
int avahi_address_is_ipv4_in_ipv6(const AvahiAddress *a);
+/** Map AVAHI_PROTO_xxx constants to Unix AF_xxx constants */
+int avahi_proto_to_af(AvahiProtocol proto);
+
+/** Map Unix AF_xxx constants to AVAHI_PROTO_xxx constants */
+AvahiProtocol avahi_af_to_proto(int af);
+
+/** Return a textual representation of the specified protocol number. i.e. "IPv4", "IPv6" or "UNSPEC" */
+const char* avahi_proto_to_string(AvahiProtocol proto);
+
AVAHI_C_DECL_END
#endif
n = (struct nlmsghdr*) req;
n->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
n->nlmsg_type = type;
- n->nlmsg_flags = NLM_F_ROOT/*|NLM_F_MATCH*/|NLM_F_REQUEST;
+ n->nlmsg_flags = NLM_F_ROOT|NLM_F_REQUEST;
n->nlmsg_pid = 0;
gen = NLMSG_DATA(n);
b = avahi_interface_relevant(i);
if (m->list == LIST_DONE && b && !i->announcing) {
- avahi_log_info("New relevant interface %s.%i.", i->hardware->name, i->protocol);
+ avahi_log_info("New relevant interface %s.%s.", i->hardware->name, avahi_proto_to_string(i->protocol));
if (i->protocol == AVAHI_PROTO_INET)
avahi_mdns_mcast_join_ipv4(m->server->fd_ipv4, i->hardware->index);
avahi_announce_interface(m->server, i);
avahi_browser_new_interface(m->server, i);
} else if (!b && i->announcing) {
- avahi_log_info("Interface %s.%i no longer relevant.", i->hardware->name, i->protocol);
+ avahi_log_info("Interface %s.%s no longer relevant.", i->hardware->name, avahi_proto_to_string(i->protocol));
if (i->protocol == AVAHI_PROTO_INET)
avahi_mdns_mcast_leave_ipv4(m->server->fd_ipv4, i->hardware->index);
AvahiAddress raddr;
int raddr_valid = 0;
- if (ifaddrmsg->ifa_family != AVAHI_PROTO_INET && ifaddrmsg->ifa_family != AVAHI_PROTO_INET6)
+ if (ifaddrmsg->ifa_family != AF_INET && ifaddrmsg->ifa_family != AF_INET6)
return;
- if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, (AvahiProtocol) ifaddrmsg->ifa_family)))
+ if (!(i = (AvahiInterface*) avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, avahi_af_to_proto(ifaddrmsg->ifa_family))))
return;
- raddr.family = (AvahiProtocol) ifaddrmsg->ifa_family;
+ raddr.proto = avahi_af_to_proto(ifaddrmsg->ifa_family);
l = NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg));
a = IFA_RTA(ifaddrmsg);
switch(a->rta_type) {
case IFA_ADDRESS:
- if ((raddr.family == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) ||
- (raddr.family == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4))
+ if ((raddr.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) ||
+ (raddr.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4))
return;
memcpy(raddr.data.data, RTA_DATA(a), RTA_PAYLOAD(a));
if (!avahi_interface_relevant(i))
return;
- assert(!a || a->family == i->protocol);
+ assert(!a || a->proto == i->protocol);
/* if (a) */
/* avahi_log_debug("unicast sending on '%s.%i' to %s:%u", i->hardware->name, i->protocol, avahi_address_snprint(t, sizeof(t), a), port); */
for (i = m->interfaces; i; i = i->interface_next) {
if (avahi_interface_relevant(i)) {
char ln[256];
- snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%i ;;;", i->hardware->name, i->protocol);
+ snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%s ;;;", i->hardware->name, avahi_proto_to_string(i->protocol));
callback(ln, userdata);
if (avahi_cache_dump(i->cache, callback, userdata) < 0)
return -1;
assert(i);
assert(a);
- if (a->family != i->protocol)
+ if (a->proto != i->protocol)
return 0;
for (ia = i->addresses; ia; ia = ia->address_next) {
- if (a->family == AVAHI_PROTO_INET) {
+ if (a->proto == AVAHI_PROTO_INET) {
uint32_t m;
m = ~(((uint32_t) -1) >> ia->prefix_len);
} else {
unsigned j;
unsigned char pl;
- assert(a->family == AVAHI_PROTO_INET6);
+ assert(a->proto == AVAHI_PROTO_INET6);
pl = ia->prefix_len;
assert(iface != AVAHI_IF_UNSPEC);
assert(a);
- if (!(i = avahi_interface_monitor_get_interface(m, iface, a->family)))
+ if (!(i = avahi_interface_monitor_get_interface(m, iface, a->proto)))
return 0;
for (j = i->addresses; j; j = j->address_next)
assert(address);
assert(callback);
- assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
+ assert(address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6);
- if (address->family == AVAHI_PROTO_INET)
+ if (address->proto == AVAHI_PROTO_INET)
n = avahi_reverse_lookup_name_ipv4(&address->data.ipv4);
else
n = avahi_reverse_lookup_name_ipv6_arpa(&address->data.ipv6);
switch (r->address_record->key->type) {
case AVAHI_DNS_TYPE_A:
- a.family = AVAHI_PROTO_INET;
+ a.proto = AVAHI_PROTO_INET;
a.data.ipv4 = r->address_record->data.a.address;
break;
case AVAHI_DNS_TYPE_AAAA:
- a.family = AVAHI_PROTO_INET6;
+ a.proto = AVAHI_PROTO_INET6;
a.data.ipv6 = r->address_record->data.aaaa.address;
break;
switch (r->address_record->key->type) {
case AVAHI_DNS_TYPE_A:
- a.family = AVAHI_PROTO_INET;
+ a.proto = AVAHI_PROTO_INET;
a.data.ipv4 = r->address_record->data.a.address;
break;
case AVAHI_DNS_TYPE_AAAA:
- a.family = AVAHI_PROTO_INET6;
+ a.proto = AVAHI_PROTO_INET6;
a.data.ipv6 = r->address_record->data.aaaa.address;
break;
assert(i);
assert(a);
assert(port > 0);
- assert(i->protocol == a->family);
+ assert(i->protocol == a->proto);
if (!s->config.enable_reflector)
return;
AvahiAddress b;
assert(a);
- avahi_address_parse(a->family == AVAHI_PROTO_INET ? AVAHI_IPV4_MCAST_GROUP : AVAHI_IPV6_MCAST_GROUP, a->family, &b);
+ avahi_address_parse(a->proto == AVAHI_PROTO_INET ? AVAHI_IPV4_MCAST_GROUP : AVAHI_IPV6_MCAST_GROUP, a->proto, &b);
return avahi_address_cmp(a, &b) == 0;
}
assert(dest);
assert(iface > 0);
- if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
+ if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, avahi_af_to_proto(sa->sa_family))) ||
!avahi_interface_relevant(i)) {
avahi_log_warn("Recieved packet from invalid interface.");
return;
assert(sa);
assert(iface > 0);
- if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
+ if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, avahi_af_to_proto(sa->sa_family))) ||
!avahi_interface_relevant(i)) {
avahi_log_warn("Recieved packet from invalid interface.");
return;
return;
}
- if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.family)) ||
+ if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.proto)) ||
!avahi_interface_relevant(j))
return;
if (events & AVAHI_WATCH_IN) {
if (fd == s->fd_ipv4) {
- dest.family = AVAHI_PROTO_INET;
+ dest.proto = AVAHI_PROTO_INET;
if ((p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &sa, &dest.data.ipv4, &iface, &ttl))) {
dispatch_packet(s, p, (struct sockaddr*) &sa, &dest, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_ipv6) {
- dest.family = AVAHI_PROTO_INET6;
+ dest.proto = AVAHI_PROTO_INET6;
if ((p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &sa6, &dest.data.ipv6, &iface, &ttl))) {
dispatch_packet(s, p, (struct sockaddr*) &sa6, &dest, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_legacy_unicast_ipv4) {
- dest.family = AVAHI_PROTO_INET;
+ dest.proto = AVAHI_PROTO_INET;
if ((p = avahi_recv_dns_packet_ipv4(s->fd_legacy_unicast_ipv4, &sa, &dest.data.ipv4, &iface, &ttl))) {
dispatch_legacy_unicast_packet(s, p, (struct sockaddr*) &sa, iface, ttl);
avahi_dns_packet_free(p);
}
} else if (fd == s->fd_legacy_unicast_ipv6) {
- dest.family = AVAHI_PROTO_INET6;
+ dest.proto = AVAHI_PROTO_INET6;
if ((p = avahi_recv_dns_packet_ipv6(s->fd_legacy_unicast_ipv6, &sa6, &dest.data.ipv6, &iface, &ttl))) {
dispatch_legacy_unicast_packet(s, p, (struct sockaddr*) &sa6, iface, ttl);
goto fail;
}
- if (a->family == AVAHI_PROTO_INET) {
+ if (a->proto == AVAHI_PROTO_INET) {
char *reverse;
AvahiRecord *r;
char *reverse;
AvahiRecord *r;
- assert(a->family == AVAHI_PROTO_INET6);
+ assert(a->proto == AVAHI_PROTO_INET6);
if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
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);
+ assert(address->proto == AVAHI_PROTO_INET || address->proto == 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) {
+ if (address->proto == 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;
msg.msg_controllen = sizeof(cmsg_data);
msg.msg_flags = 0;
- return sendmsg_loop(fd, &msg, 0 /*MSG_DONTROUTE*/);
+ return sendmsg_loop(fd, &msg, 0);
}
int avahi_send_dns_packet_ipv6(int fd, int interface, AvahiDnsPacket *p, const AvahiIPv6Address *a, uint16_t port) {
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) a->family;
+ i_aprotocol = (int32_t) a->proto;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) address->family;
+ i_aprotocol = (int32_t) address->proto;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) a->family;
+ i_aprotocol = (int32_t) a->proto;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) address->family;
+ i_aprotocol = (int32_t) address->proto;
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Found");
dbus_message_append_args(
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) a->family;
+ i_aprotocol = (int32_t) a->proto;
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Found");
dbus_message_append_args(
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) a->family;
+ i_aprotocol = (int32_t) a->proto;
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Found");
dbus_message_append_args(