[vlc-commits] Obsolete confusing --miface-addr option and rework net_SetMcastOut()

Rémi Denis-Courmont git at videolan.org
Mon Aug 22 17:10:30 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 22 18:08:17 2011 +0300| [c0c8d4e2fea8e3af8d939040ca0ce90d0f63b63c] | committer: Rémi Denis-Courmont

Obsolete confusing --miface-addr option and rework net_SetMcastOut()

--miface-addr mostly did not work as --miface was supposed to be used
instead.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c0c8d4e2fea8e3af8d939040ca0ce90d0f63b63c
---

 modules/access_output/udp.c |    1 -
 src/libvlc-module.c         |    7 +---
 src/network/udp.c           |   87 +++++++++---------------------------------
 3 files changed, 20 insertions(+), 75 deletions(-)

diff --git a/modules/access_output/udp.c b/modules/access_output/udp.c
index 482c391..d996d74 100644
--- a/modules/access_output/udp.c
+++ b/modules/access_output/udp.c
@@ -102,7 +102,6 @@ static const char *const ppsz_core_options[] = {
     "dscp",
     "ttl",
     "miface",
-    "miface-addr",
     NULL
 };
 
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index f61280b..455c25f 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -669,11 +669,6 @@ static const char *const ppsz_clock_descriptions[] =
 #define MIFACE_LONGTEXT N_( \
     "Default multicast interface. This overrides the routing table.")
 
-#define MIFACE_ADDR_TEXT N_("IPv4 multicast output interface address")
-#define MIFACE_ADDR_LONGTEXT N_( \
-    "IPv4 address for the default multicast interface. This overrides " \
-    "the routing table.")
-
 #define DSCP_TEXT N_("DiffServ Code Point")
 #define DSCP_LONGTEXT N_("Differentiated Services Code Point " \
     "for outgoing UDP streams (or IPv4 Type Of Service, " \
@@ -1982,7 +1977,7 @@ vlc_module_begin ()
                 ACCESS_OUTPUT_TEXT, ACCESS_OUTPUT_LONGTEXT, true )
     add_integer( "ttl", -1, TTL_TEXT, TTL_LONGTEXT, true )
     add_string( "miface", NULL, MIFACE_TEXT, MIFACE_LONGTEXT, true )
-    add_string( "miface-addr", NULL, MIFACE_ADDR_TEXT, MIFACE_ADDR_LONGTEXT, true )
+    add_obsolete_string( "miface-addr" )
     add_integer( "dscp", 0, DSCP_TEXT, DSCP_LONGTEXT, true )
 
     set_subcategory( SUBCAT_SOUT_PACKETIZER )
diff --git a/src/network/udp.c b/src/network/udp.c
index f25842c..d58910d 100644
--- a/src/network/udp.c
+++ b/src/network/udp.c
@@ -244,80 +244,38 @@ static int net_SetMcastHopLimit( vlc_object_t *p_this,
 }
 
 
-static int net_SetMcastOutIface (int fd, int family, int scope)
+static int net_SetMcastOut (vlc_object_t *p_this, int fd, int family,
+                            const char *iface)
 {
+    int scope = if_nametoindex (iface);
+    if (scope == 0)
+    {
+        msg_Err (p_this, "invalid multicast interface: %s", iface);
+        return -1;
+    }
+
     switch (family)
     {
 #ifdef IPV6_MULTICAST_IF
         case AF_INET6:
-            return setsockopt (fd, SOL_IPV6, IPV6_MULTICAST_IF,
-                               &scope, sizeof (scope));
+            if (setsockopt (fd, SOL_IPV6, IPV6_MULTICAST_IF,
+                            &scope, sizeof (scope) == 0))
+                return 0;
 #endif
 
 #ifdef __linux__
         case AF_INET:
         {
             struct ip_mreqn req = { .imr_ifindex = scope };
-
-            return setsockopt (fd, SOL_IP, IP_MULTICAST_IF, &req,
-                               sizeof (req));
-        }
-#endif
-    }
-
-    errno = EAFNOSUPPORT;
-    return -1;
-}
-
-
-static inline int net_SetMcastOutIPv4 (int fd, struct in_addr ipv4)
-{
-#ifdef IP_MULTICAST_IF
-    return setsockopt( fd, SOL_IP, IP_MULTICAST_IF, &ipv4, sizeof (ipv4));
-#else
-    errno = EAFNOSUPPORT;
-    return -1;
-#endif
-}
-
-
-static int net_SetMcastOut (vlc_object_t *p_this, int fd, int family,
-                            const char *iface, const char *addr)
-{
-    if (iface != NULL)
-    {
-        int scope = if_nametoindex (iface);
-        if (scope == 0)
-        {
-            msg_Err (p_this, "invalid multicast interface: %s", iface);
-            return -1;
-        }
-
-        if (net_SetMcastOutIface (fd, family, scope) == 0)
-            return 0;
-
-        msg_Err (p_this, "%s: %m", iface);
-    }
-
-    if (addr != NULL)
-    {
-        if (family == AF_INET)
-        {
-            struct in_addr ipv4;
-            if (inet_pton (AF_INET, addr, &ipv4) <= 0)
-            {
-                msg_Err (p_this, "invalid IPv4 address for multicast: %s",
-                         addr);
-                return -1;
-            }
-
-            if (net_SetMcastOutIPv4 (fd, ipv4) == 0)
+            if (setsockopt (fd, SOL_IP, IP_MULTICAST_IF,
+                            &req, sizeof (req)) == 0)
                 return 0;
-
-            msg_Err (p_this, "%s: %m", addr);
         }
+#endif
+        default:
+            errno = EAFNOSUPPORT;
     }
-
+    msg_Err (p_this, "cannot force multicast interface %s: %m", iface);
     return -1;
 }
 
@@ -586,14 +544,7 @@ int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
         str = var_InheritString (p_this, "miface");
         if (str != NULL)
         {
-            net_SetMcastOut (p_this, fd, ptr->ai_family, str, NULL);
-            free (str);
-        }
-
-        str = var_InheritString (p_this, "miface-addr");
-        if (str != NULL)
-        {
-            net_SetMcastOut (p_this, fd, ptr->ai_family, NULL, str);
+            net_SetMcastOut (p_this, fd, ptr->ai_family, str);
             free (str);
         }
 



More information about the vlc-commits mailing list