/* Fall through */
case STATE_ANNOUNCE:
- dns_reply_a(iface, announce_ttl);
+ dns_reply_a(iface, NULL, announce_ttl);
service_announce_services(iface, announce_ttl);
uloop_timeout_set(timeout, announce_ttl * 800);
break;
iov[1].iov_len = len;
DBG(1, "Q <- %s %s\n", dns_type_string(type), question);
- if (interface_send_packet(iface, iov, ARRAY_SIZE(iov)) < 0)
+ if (interface_send_packet(iface, NULL, iov, ARRAY_SIZE(iov)) < 0)
perror("failed to send question :");
}
}
void
-dns_send_answer(struct interface *iface, const char *answer)
+dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer)
{
uint8_t buffer[256];
struct blob_attr *attr;
DBG(1, "A <- %s %s\n", dns_type_string(be16_to_cpu(a->type)), answer);
}
- if (interface_send_packet(iface, iov, n_iov) < 0)
+ if (interface_send_packet(iface, to, iov, n_iov) < 0)
fprintf(stderr, "failed to send question\n");
}
void
-dns_reply_a(struct interface *iface, int ttl)
+dns_reply_a(struct interface *iface, struct sockaddr *to, int ttl)
{
struct ifaddrs *ifap, *ifa;
struct sockaddr_in *sa;
dns_add_answer(TYPE_AAAA, (uint8_t *) &sa6->sin6_addr, 16, ttl);
}
}
- dns_send_answer(iface, mdns_hostname_local);
+ dns_send_answer(iface, to, mdns_hostname_local);
freeifaddrs(ifap);
}
case TYPE_ANY:
if (!strcmp(name, mdns_hostname_local)) {
service_reply(iface, NULL, announce_ttl);
- dns_reply_a(iface, announce_ttl);
+ dns_reply_a(iface, NULL, announce_ttl);
}
break;
if (host)
*host = '\0';
if (!strcmp(mdns_hostname, name))
- dns_reply_a(iface, announce_ttl);
+ dns_reply_a(iface, NULL, announce_ttl);
break;
};
}
void dns_send_question(struct interface *iface, const char *question, int type, int multicast);
void dns_init_answer(void);
void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
-void dns_send_answer(struct interface *iface, const char *answer);
-void dns_reply_a(struct interface *iface, int ttl);
+void dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer);
+void dns_reply_a(struct interface *iface, struct sockaddr *to, int ttl);
const char* dns_type_string(uint16_t type);
void dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t port, uint8_t *buf, int len);
#include "service.h"
static int
-interface_send_packet4(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct iovec *iov, int iov_len)
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in a;
pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi_ifindex = iface->ifindex;
- a.sin_addr.s_addr = inet_addr(MCAST_ADDR);
+ if (iface->multicast || !to) {
+ a.sin_addr.s_addr = inet_addr(MCAST_ADDR);
+ if (to)
+ fprintf(stderr, "Ignoring IPv4 address for multicast interface\n");
+ } else {
+ a.sin_addr.s_addr = to->sin_addr.s_addr;
+ }
return sendmsg(fd, &m, 0);
}
static int
-interface_send_packet6(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct iovec *iov, int iov_len)
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in6_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in6 a;
pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi6_ifindex = iface->ifindex;
- inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr);
+ if (iface->multicast || !to) {
+ inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr);
+ if (to)
+ fprintf(stderr, "Ignoring IPv6 address for multicast interface\n");
+ } else {
+ a.sin6_addr = to->sin6_addr;
+ }
return sendmsg(fd, &m, 0);
}
int
-interface_send_packet(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet(struct interface *iface, struct sockaddr *to, struct iovec *iov, int iov_len)
{
if (debug > 1) {
fprintf(stderr, "TX ipv%d: %s\n", iface->v6 * 2 + 4, iface->name);
}
if (iface->v6)
- return interface_send_packet6(iface, iov, iov_len);
+ return interface_send_packet6(iface, (struct sockaddr_in6 *)to, iov, iov_len);
- return interface_send_packet4(iface, iov, iov_len);
+ return interface_send_packet4(iface, (struct sockaddr_in *)to, iov, iov_len);
}
static void interface_close(struct interface *iface)
vlist_for_each_element(&interfaces, iface, node)
if (iface->fd.fd > 0 && iface->multicast) {
- dns_reply_a(iface, 0);
+ dns_reply_a(iface, NULL, 0);
service_announce_services(iface, 0);
}
vlist_for_each_element(&interfaces, iface, node)
int interface_add(const char *name);
void interface_shutdown(void);
-int interface_send_packet(struct interface *iface, struct iovec *iov, int iov_len);
+int interface_send_packet(struct interface *iface, struct sockaddr *to, struct iovec *iov, int iov_len);
struct interface* interface_get(const char *name, int v6, int multicast);
#endif
dns_init_answer();
service_add_ptr(service_name(s->service), ttl);
- dns_send_answer(iface, service);
+ dns_send_answer(iface, NULL, service);
dns_init_answer();
service_add_srv(s, ttl);
if (s->txt && s->txt_len)
dns_add_answer(TYPE_TXT, (uint8_t *) s->txt, s->txt_len, ttl);
- dns_send_answer(iface, host);
+ dns_send_answer(iface, NULL, host);
}
void
if (ttl) {
dns_init_answer();
service_add_ptr(s->service, ttl);
- dns_send_answer(iface, sdudp);
+ dns_send_answer(iface, NULL, sdudp);
}
service_reply_single(iface, s, ttl, 0);
}