]> git.sesse.net Git - vlc/blobdiff - src/misc/netutils.c
* DirectX plugin by Gildas Bazin <gbazin@netcourrier.com>.
[vlc] / src / misc / netutils.c
index dd3b27827cbf0d2a06ff1f9b0f9564bb3bfd37b4..b1bdcc18fb0d6dbf671a65b0db1e63ef998f26b7 100644 (file)
@@ -2,7 +2,7 @@
  * netutils.c: various network functions
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: netutils.c,v 1.32 2001/05/28 02:44:39 sam Exp $
+ * $Id: netutils.c,v 1.37 2001/06/02 01:09:03 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Benoit Steiner <benny@via.ecp.fr>
 #include <stdlib.h>                             /* free(), realloc(), atoi() */
 #include <errno.h>                                                /* errno() */
 #include <string.h>                                              /* memset() */
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>                                         /* gethostname() */
+#elif defined( _MSC_VER ) && defined( _WIN32 )
+#include <io.h>
+#endif
+
+#if !defined( _MSC_VER )
 #include <sys/time.h>                                        /* gettimeofday */
+#endif
 
-#ifndef WIN32
+#if !defined( WIN32 )
 #include <netdb.h>                                        /* gethostbyname() */
 #include <netinet/in.h>                               /* BSD: struct in_addr */
 #include <sys/socket.h>                              /* BSD: struct sockaddr */
@@ -49,7 +57,7 @@
 #include <sys/ioctl.h>                                            /* ioctl() */
 #endif
 
-#ifdef WIN32                            /* tools to get the MAC adress from  */
+#if defined( WIN32 )                    /* tools to get the MAC adress from  */
 #include <windows.h>                    /* the interface under Windows      */
 #include <stdio.h>
 #endif
@@ -254,10 +262,12 @@ int network_ChannelJoin( int i_channel )
     struct timeval      answer_delay;
     int                 i_nbanswer;
     char                i_answer;
-    fd_set              fd;
+    fd_set              fds;
     unsigned int        i_rc;
+    char *              psz_channel_server;
 
-    if( ! p_main->b_channels )
+    if( !main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
+                              INPUT_NETWORK_CHANNEL_DEFAULT  ) )
     {
         intf_ErrMsg( "network: channels disabled, to enable them, use the"
                      "--channels option" );
@@ -269,14 +279,14 @@ int network_ChannelJoin( int i_channel )
     /* If last change is too recent, wait a while */
     if( mdate() - p_main->p_channel->last_change < INPUT_CHANNEL_CHANGE_DELAY )
     {
-        intf_Msg( "network: waiting before changing channel" );
+        intf_WarnMsg( 2, "network: waiting before changing channel" );
         mwait( p_main->p_channel->last_change + INPUT_CHANNEL_CHANGE_DELAY );
     }
 
     p_main->p_channel->last_change = mdate();
     p_main->p_channel->i_channel   = i_channel;
 
-    intf_Msg( "network: joining channel %d", i_channel );
+    intf_WarnMsg( 2, "network: joining channel %d", i_channel );
 
     /*
      * Initializing the socket
@@ -286,14 +296,25 @@ int network_ChannelJoin( int i_channel )
     /*
      * Getting the server's information
      */
+    intf_WarnMsg( 6, "Channel server: %s port: %d",
+            main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
+                                 INPUT_CHANNEL_SERVER_DEFAULT ),
+            main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
+                                 INPUT_CHANNEL_PORT_DEFAULT ) );
+
     memset( &sa_server, 0x00, sizeof(struct sockaddr_in) );
     sa_server.sin_family = AF_INET;
-    sa_server.sin_port   = htons( INPUT_CHANNEL_PORT_DEFAULT );
+    sa_server.sin_port   = htons( main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
+                                  INPUT_CHANNEL_PORT_DEFAULT ) );
+
+    psz_channel_server = strdup( main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
+                                 INPUT_CHANNEL_SERVER_DEFAULT ) );
 #ifdef HAVE_ARPA_INET_H
-    if( !inet_aton( psz_server, &p_socket->sin_addr) )
+    inet_aton( psz_channel_server, &sa_server.sin_addr );
 #else
-    if( (sa_server.sin_addr.s_addr = inet_addr( INPUT_CHANNEL_SERVER_DEFAULT )) == -1 )
+    sa_server.sin_addr.s_addr = inet_addr( psz_channel_server );
 #endif
+    free( psz_channel_server );
 
     /*
      * Looking for the interface MAC address
@@ -348,9 +369,9 @@ int network_ChannelJoin( int i_channel )
      */
     answer_delay.tv_sec  = 5;
     answer_delay.tv_usec = 0;
-    FD_ZERO( &fd );
-    FD_SET( i_socket, &fd );
-    i_nbanswer = select( i_socket + 1, &fd, NULL, NULL, &answer_delay );
+    FD_ZERO( &fds );
+    FD_SET( i_socket, &fds );
+    i_nbanswer = select( i_socket + 1, &fds, NULL, NULL, &answer_delay );
 
     switch( i_nbanswer )
     {
@@ -458,7 +479,7 @@ static int GetMacAddress( int i_socket, char *psz_mac )
 
     return( i_ret );
 
-#elif
+#else
     return( -1);
 
 #endif