break;
case TYPE_PTR:
- service_announce_services(iface, name);
+ service_announce_services(iface, name, announce_ttl);
service_reply(iface, name, announce_ttl);
break;
if (host)
*host = '\0';
if (!strcmp(mdns_hostname, name))
- service_reply_a(iface, q->type, announce_ttl);
+ service_reply_a(iface, announce_ttl);
break;
};
}
#include "util.h"
#include "dns.h"
#include "announce.h"
+#include "service.h"
static int
interface_send_packet4(struct interface *iface, struct iovec *iov, int iov_len)
return !v4 && !v6;
}
+void interface_shutdown(void)
+{
+ struct interface *iface;
+
+ vlist_for_each_element(&interfaces, iface, node)
+ if (iface->fd.fd > 0 && iface->multicast) {
+ service_announce(iface, 0);
+ service_reply_a(iface, 0);
+ }
+ vlist_for_each_element(&interfaces, iface, node)
+ interface_free(iface);
+}
+
VLIST_TREE(interfaces, avl_strcmp, iface_update_cb, false, false);
}
void
-service_reply_a(struct interface *iface, int type, int ttl)
+service_reply_a(struct interface *iface, int ttl)
{
struct ifaddrs *ifap, *ifa;
struct sockaddr_in *sa;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (strcmp(ifa->ifa_name, iface->name))
continue;
- if (ifa->ifa_addr->sa_family==AF_INET) {
+ if (ifa->ifa_addr->sa_family == AF_INET) {
sa = (struct sockaddr_in *) ifa->ifa_addr;
dns_add_answer(TYPE_A, (uint8_t *) &sa->sin_addr, 4, ttl);
}
- if (ifa->ifa_addr->sa_family==AF_INET6) {
+ if (ifa->ifa_addr->sa_family == AF_INET6) {
uint8_t ll_prefix[] = {0xfe, 0x80 };
sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
if (!memcmp(&sa6->sin6_addr, &ll_prefix, 2))
if (match)
return;
- service_reply_a(iface, TYPE_A, ttl);
+ if (ttl)
+ service_reply_a(iface, ttl);
}
void
-service_announce_services(struct interface *iface, const char *service)
+service_announce_services(struct interface *iface, const char *service, int ttl)
{
struct service *s;
int tcp = 1;
if (!strstr(s->service, "._udp") && !tcp)
continue;
s->t = 0;
- dns_init_answer();
- service_add_ptr(s->service, announce_ttl);
- if (tcp)
- dns_send_answer(iface, sdtcp);
- else
- dns_send_answer(iface, sdudp);
- service_reply(iface, s->service, announce_ttl);
+ if (ttl) {
+ dns_init_answer();
+ service_add_ptr(s->service, ttl);
+ if (tcp)
+ dns_send_answer(iface, sdtcp);
+ else
+ dns_send_answer(iface, sdudp);
+ }
+ service_reply(iface, s->service, ttl);
}
}
void
-service_announce(struct interface *iface)
+service_announce(struct interface *iface, int ttl)
{
- service_announce_services(iface, sdudp);
- service_announce_services(iface, sdtcp);
+ service_announce_services(iface, sdudp, ttl);
+ service_announce_services(iface, sdtcp, ttl);
}
static void
extern void service_init(int announce);
extern void service_cleanup(void);
-extern void service_announce(struct interface *iface);
-extern void service_announce_services(struct interface *iface, const char *service);
+extern void service_announce(struct interface *iface, int ttl);
+extern void service_announce_services(struct interface *iface, const char *service, int ttl);
extern void service_reply(struct interface *iface, const char *match, int ttl);
-extern void service_reply_a(struct interface *iface, int type, int ttl);
+extern void service_reply_a(struct interface *iface, int ttl);
#endif