From 55138ca9b501bd32c870bb468d6736a42d026cfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 14 Feb 2017 12:18:06 +0100 Subject: [PATCH] Don't try sending unicast responses with multicast address MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit So far we were doing that when destination IP address wasn't specified. Now we have all places in code cleaned up, stop accepting this and print an error if needed. Signed-off-by: Rafał Miłecki --- interface.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/interface.c b/interface.c index 1cc9499..ada8acb 100644 --- a/interface.c +++ b/interface.c @@ -69,7 +69,7 @@ interface_send_packet4(struct interface *iface, struct sockaddr_in *to, struct i pkti = (struct in_pktinfo*) CMSG_DATA(cmsg); pkti->ipi_ifindex = iface->ifindex; - if (iface->multicast || !to) { + if (iface->multicast) { a.sin_addr.s_addr = inet_addr(MCAST_ADDR); if (to) fprintf(stderr, "Ignoring IPv4 address for multicast interface\n"); @@ -109,7 +109,7 @@ interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg); pkti->ipi6_ifindex = iface->ifindex; - if (iface->multicast || !to) { + if (iface->multicast) { inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr); if (to) fprintf(stderr, "Ignoring IPv6 address for multicast interface\n"); @@ -123,6 +123,11 @@ interface_send_packet6(struct interface *iface, struct sockaddr_in6 *to, struct int interface_send_packet(struct interface *iface, struct sockaddr *to, struct iovec *iov, int iov_len) { + if (!iface->multicast && !to) { + fprintf(stderr, "No IP address specified for unicast interface\n"); + return -1; + } + if (debug > 1) { fprintf(stderr, "TX ipv%d: %s\n", iface->v6 * 2 + 4, iface->name); fprintf(stderr, " multicast: %d\n", iface->multicast); -- 2.11.0