Support setting outgoing interface for multicast.
[cubemap] / config.cpp
index 57bf10a..f474f8c 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <net/if.h>
 #include <sys/socket.h>
 #include <map>
 #include <string>
@@ -298,6 +299,18 @@ bool parse_udpstream(const ConfigLine &line, Config *config)
                udpstream.ttl = atoi(ttl_it->second.c_str());
        }
 
+       // Parse the multicast interface index.
+       map<string, string>::const_iterator multicast_iface_it = line.parameters.find("multicast_output_interface");
+       if (multicast_iface_it == line.parameters.end()) {
+               udpstream.multicast_iface_index = -1;
+       } else {
+               udpstream.multicast_iface_index = if_nametoindex(multicast_iface_it->second.c_str());
+               if (udpstream.multicast_iface_index == 0) {
+                       log(ERROR, "Interface '%s' does not exist", multicast_iface_it->second.c_str());
+                       return false;
+               }
+       }
+
        config->udpstreams.push_back(udpstream);
        return true;
 }