* netutils.c: various network functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: netutils.c,v 1.31 2001/05/28 02:38:48 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 */
#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
intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
return( 1 );
-#elif defined( SYS_LINUX )
+#elif defined( SYS_LINUX ) || defined( WIN32 )
/* FIXME : channels handling only work for linux */
/* Allocate structure */
p_main->p_channel = malloc( sizeof( input_channel_t ) );
intf_ErrMsg( "network error: channels are not yet supported under BeOS" );
return( -1 );
-#elif defined( WIN32 ) || defined( SYS_LINUX )
+#elif defined( SYS_LINUX ) || defined( WIN32 )
int i_socket;
int i_fromlen;
struct sockaddr_in sa_server;
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" );
/* 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
/*
* 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
*/
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 )
{
return( i_ret );
-#elif
+#else
return( -1);
#endif