Don't try sending unicast responses with multicast address
authorRafał Miłecki <rafal@milecki.pl>
Tue, 14 Feb 2017 11:18:06 +0000 (12:18 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Wed, 15 Feb 2017 10:11:53 +0000 (11:11 +0100)
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 <rafal@milecki.pl>
interface.c

index 1cc9499..ada8acb 100644 (file)
@@ -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);