]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* Bug fixes and enhancements in the Gtk+/Gnome interfaces.
[vlc] / src / input / input.c
index 64de1caee858827981f26e0bf7ef07ec35e10f44..802b19c2454b0da759e0bd68aa212eba1aa2bcd8 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.91 2001/03/07 10:31:10 stef Exp $
+ * $Id: input.c,v 1.93 2001/03/15 01:42:20 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
+#include "netutils.h"
 #include "modules.h"
 
 #include "intf_msg.h"
-#include "intf_plst.h"
+#include "intf_playlist.h"
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
@@ -69,6 +70,9 @@
 
 #include "main.h"
 
+ /* #include <netutils.h> */
+
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -309,7 +313,8 @@ static int InitThread( input_thread_t * p_input )
 
     if( p_input->p_input_module == NULL )
     {
-        intf_ErrMsg( "input error: no suitable input module" );
+        intf_ErrMsg( "input error: no suitable input module for `%s'",
+                     p_input->p_source );
         return( -1 );
     }
 
@@ -508,76 +513,19 @@ void input_FileClose( input_thread_t * p_input )
     return;
 }
 
+
 #ifndef SYS_BEOS
 /*****************************************************************************
- * input_BuildLocalAddr : fill a sockaddr_in structure for local binding
+ * input_NetworkOpen : open a network socket 
  *****************************************************************************/
-int input_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port, 
-                      boolean_t b_broadcast )
+void input_NetworkOpen( input_thread_t * p_input )
 {
-    char                psz_hostname[INPUT_MAX_SOURCE_LENGTH];
-    struct hostent    * p_hostent;
-    
-    /* Reset struct */
-    memset( p_socket, 0, sizeof( struct sockaddr_in ) );
-    p_socket->sin_family = AF_INET;                                 /* family */
-    p_socket->sin_port = htons( i_port );
+    int                 i_option_value, i_port;
+    struct sockaddr_in  s_socket;
+    boolean_t           b_broadcast;
     
-    if( !b_broadcast )
-    {
-        /* Try to get our own IP */
-        if( gethostname( psz_hostname, sizeof(psz_hostname) ) )
-        {
-            intf_ErrMsg( "BuildLocalAddr : unable to resolve local name : %s",
-                         strerror( errno ) );
-            return( -1 );
-        }
-
-    }
-    else
-    {
-        /* Using broadcast address. There are many ways of doing it, one of
-         * the simpliest being a #define ...
-         * FIXME : this is ugly */ 
-        strncpy( psz_hostname, INPUT_BCAST_ADDR,INPUT_MAX_SOURCE_LENGTH );
-    }
-
-    /* Try to convert address directly from in_addr - this will work if
-     * psz_in_addr is dotted decimal. */
-
-#ifdef HAVE_ARPA_INET_H
-    if( !inet_aton( psz_hostname, &p_socket->sin_addr) )
-#else
-    if( (p_socket->sin_addr.s_addr = inet_addr( psz_hostname )) == -1 )
-#endif
-    {
-        /* We have a fqdn, try to find its address */
-        if ( (p_hostent = gethostbyname( psz_hostname )) == NULL )
-        {
-            intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_hostname );
-            return( -1 );
-        }
-        
-        /* Copy the first address of the host in the socket address */
-        memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0], 
-                 p_hostent->h_length );
-    }
-
-    return( 0 );
-}
-
-/*****************************************************************************
- * input_BuildRemoteAddr : fill a sockaddr_in structure for remote host
- *****************************************************************************/
-int input_BuildRemoteAddr( input_thread_t * p_input, 
-                           struct sockaddr_in * p_socket )
-{
-    struct hostent            * p_hostent;
-
-    /* Reset structure */
-    memset( p_socket, 0, sizeof( struct sockaddr_in ) );
-    p_socket->sin_family = AF_INET;                                 /* family */
-    p_socket->sin_port = htons( 0 );                /* This is for remote end */
+    /* FIXME : we don't handle channels for the moment */
     
     /* Get the remote server */
     if( p_input->p_source == NULL )
@@ -585,43 +533,7 @@ int input_BuildRemoteAddr( input_thread_t * p_input,
         p_input->p_source = main_GetPszVariable( INPUT_SERVER_VAR, 
                                                  INPUT_SERVER_DEFAULT );
     }
-
-     /* Try to convert address directly from in_addr - this will work if
-      * psz_in_addr is dotted decimal. */
-#ifdef HAVE_ARPA_INET_H
-    if( !inet_aton( p_input->p_source, &p_socket->sin_addr) )
-#else
-    if( (p_socket->sin_addr.s_addr = inet_addr( p_input->p_source )) == -1 )
-#endif
-    {
-        /* We have a fqdn, try to find its address */
-        if ( (p_hostent = gethostbyname(p_input->p_source)) == NULL )
-        {
-            intf_ErrMsg( "BuildRemoteAddr: unknown host %s", 
-                         p_input->p_source );
-            return( -1 );
-        }
-        
-        /* Copy the first address of the host in the socket address */
-        memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0], 
-                 p_hostent->h_length );
-    }
-
-    return( 0 );
-}
-
-/*****************************************************************************
- * input_NetworkOpen : open a network socket 
- *****************************************************************************/
-void input_NetworkOpen( input_thread_t * p_input )
-{
-    int                 i_option_value, i_port;
-    struct sockaddr_in  s_socket;
-    boolean_t           b_broadcast;
     
-    /* FIXME : we don't handle channels for the moment */
-
     /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
      * protocol */
     p_input->i_handle = socket( AF_INET, SOCK_DGRAM, 0 );
@@ -644,7 +556,6 @@ void input_NetworkOpen( input_thread_t * p_input )
         return;
     }
 
-#ifndef SYS_BEOS
     /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
      * packet loss caused by scheduling problems */
     i_option_value = 524288;
@@ -657,16 +568,15 @@ void input_NetworkOpen( input_thread_t * p_input )
         p_input->b_error = 1;
         return;
     }
-#endif /* SYS_BEOS */
 
     /* Get details about what we are supposed to do */
     b_broadcast = (boolean_t)main_GetIntVariable( INPUT_BROADCAST_VAR, 0 );
     i_port = main_GetIntVariable( INPUT_PORT_VAR, INPUT_PORT_DEFAULT );
 
     /* TODO : here deal with channel stufs */
-
+    
     /* Build the local socket */
-    if ( input_BuildLocalAddr( &s_socket, i_port, b_broadcast ) 
+    if ( network_BuildLocalAddr( &s_socket, i_port, b_broadcast ) 
          == -1 )
     {
         close( p_input->i_handle );
@@ -685,7 +595,7 @@ void input_NetworkOpen( input_thread_t * p_input )
     }
 
     /* Build socket for remote connection */
-    if ( input_BuildRemoteAddr( p_input, &s_socket ) 
+    if ( network_BuildRemoteAddr( &s_socket, p_input->p_source ) 
          == -1 )
     {
         close( p_input->i_handle );