]> git.sesse.net Git - vlc/blobdiff - src/stream_output/sap.c
Fail when trying to advertise a stream with an out-of-scope address
[vlc] / src / stream_output / sap.c
index 688cb3ce59191920bdb3f8e94d1071ab2e3ef85c..7a354f1b540dc5511946e6e2acca0d2565135294 100644 (file)
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -57,7 +57,6 @@ struct sap_address_t
 {
     char *psz_address;
     char psz_machine[NI_MAXNUMERICHOST];
-    int i_port;
     int i_rfd; /* Read socket */
     int i_wfd; /* Write socket */
 
@@ -318,9 +317,21 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
             if ((ipv4 & 0xfffc0000) == 0xefc00000)
                 ipv4 =  0xefc3ffff;
             else
+            if ((ipv4 & 0xff000000) == 0xef000000)
+                ipv4 = 0;
+            else
             /* other addresses => 224.2.127.254 */
                 ipv4 = 0xe0027ffe;
 
+            if( ipv4 == 0 )
+            {
+                msg_Err( p_sap, "Out-of-scope multicast address "
+                        "not supported by SAP: %s", p_session->psz_uri );
+                vlc_mutex_unlock( &p_sap->object_lock );
+                vlc_freeaddrinfo( res );
+                return VLC_EGENERIC;
+            }
+
             ((struct sockaddr_in *)&addr)->sin_addr.s_addr = htonl( ipv4 );
             break;
         }
@@ -370,9 +381,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
             return VLC_ENOMEM;
         }
         p_address->psz_address = strdup( psz_addr );
-        p_address->i_port  =  9875;
-        p_address->i_wfd = net_OpenUDP( p_sap, "", 0, psz_addr,
-                                        p_address->i_port );
+        p_address->i_wfd = net_ConnectUDP( p_sap, psz_addr, SAP_PORT, 255 );
         if( p_address->i_wfd != -1 )
         {
             char *ptr;
@@ -389,8 +398,7 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
 
         if( p_sap->b_control == VLC_TRUE )
         {
-            p_address->i_rfd = net_OpenUDP( p_sap, psz_addr,
-                                            p_address->i_port, "", 0 );
+            p_address->i_rfd = net_OpenUDP( p_sap, psz_addr, SAP_PORT, "", 0 );
             if( p_address->i_rfd != -1 )
                 net_StopSend( p_address->i_rfd );
             p_address->i_buff = 0;
@@ -447,13 +455,12 @@ static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
                    psz_head + 4 );
     }
     else
-#else
+#endif
     {
         inet_pton( AF_INET, /* can't fail */
                    p_sap_session->p_address->psz_machine,
                    psz_head + 4 );
     }
-#endif
 
     memcpy( psz_head + (b_ipv6 ? 20 : 8), "application/sdp", 15 );
 
@@ -558,7 +565,7 @@ static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
         i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
                            p_session->psz_data,
                            p_session->i_length );
-        if( i_ret != p_session->i_length )
+        if( i_ret != (int)p_session->i_length )
         {
             msg_Warn( p_sap, "SAP send failed on address %s (%i %i)",
                       p_session->p_address->psz_address,
@@ -621,14 +628,16 @@ static char *SDPGenerate( sap_handler_t *p_sap,
                             "%s%s%s",
                             i_sdp_id, i_sdp_version,
                             ipv, p_addr->psz_machine,
-                            psz_name, ipv, psz_uri, p_session->i_ttl,
+                            psz_name, ipv, psz_uri,
+                            /* FIXME: 1 is IPv4 default TTL, not that of IPv6 */
+                            p_session->i_ttl ?: (config_GetInt( p_sap, "ttl" ) ?: 1),
                             p_session->i_port, 
                             p_session->b_rtp ? "RTP/AVP" : "udp",
                             p_session->i_payload,
                             psz_group ? "a=x-plgroup:" : "",
                             psz_group ? psz_group : "", psz_group ? "\r\n" : "" ) == -1 )
         return NULL;
-    
+
     msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp),
              psz_sdp );
     return psz_sdp;
@@ -679,9 +688,7 @@ static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
     }
 #ifdef EXTRA_DEBUG
     msg_Dbg( p_sap,"%s:%i : Rate=%i, Interval = %i s",
-                    p_address->psz_address,p_address->i_port,
-                    i_rate,
-                    p_address->i_interval );
+             p_address->psz_address,SAP_PORT, i_rate, p_address->i_interval );
 #endif
 
     p_address->b_ready = VLC_TRUE;