- if (interface_send_packet(iface, iov, n_iov) < 0)
- fprintf(stderr, "failed to send question\n");
+ if (interface_send_packet(iface, to, iov, n_iov) < 0)
+ perror("failed to send answer");
+}
+
+void
+dns_reply_a(struct interface *iface, struct sockaddr *to, int ttl)
+{
+ struct ifaddrs *ifap, *ifa;
+ struct sockaddr_in *sa;
+ struct sockaddr_in6 *sa6;
+
+ getifaddrs(&ifap);
+
+ dns_init_answer();
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if (strcmp(ifa->ifa_name, iface->name))
+ continue;
+ 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) {
+ sa6 = (struct sockaddr_in6 *) ifa->ifa_addr;
+ dns_add_answer(TYPE_AAAA, (uint8_t *) &sa6->sin6_addr, 16, ttl);
+ }
+ }
+ dns_send_answer(iface, to, mdns_hostname_local);
+
+ freeifaddrs(ifap);