Commit cdf12612 authored by Sam Hocevar's avatar Sam Hocevar

  * Fixed the vlcs communication issue by initializing WinSock at
    startup (thanks Meuuh for the tip).
parent 6389eac3
......@@ -133,6 +133,7 @@ C_OBJ += src/misc/darwin_specific.o
endif
ifneq (,$(findstring mingw32,$(SYS)))
C_OBJ += src/misc/win32_specific.o
RESOURCE_OBJ := share/vlc_win32_rc.o
endif
......
/*****************************************************************************
* win32_specific.h: Win32 specific features
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: win32_specific.h,v 1.1 2001/11/12 22:42:56 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*****************************************************************************/
/*****************************************************************************
* Prototypes
*****************************************************************************/
void system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] );
void system_End ( void );
......@@ -4,7 +4,7 @@
* decoders.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: input.c,v 1.153 2001/11/12 04:12:37 sam Exp $
* $Id: input.c,v 1.154 2001/11/12 22:42:56 sam Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -52,7 +52,9 @@
# include <netdb.h> /* hostent ... */
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
# endif
#endif
#ifdef HAVE_SYS_TIMES_H
......@@ -728,22 +730,6 @@ static void NetworkOpen( input_thread_t * p_input )
struct sockaddr_in sock;
unsigned int i_mc_group;
#ifdef WIN32
WSADATA Data;
int i_err;
#endif
#ifdef WIN32
/* WinSock Library Init. */
i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
if( i_err )
{
intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
return ;
}
#endif
/* Get the remote server */
if( p_input->p_source != NULL )
{
......@@ -993,10 +979,6 @@ static void NetworkClose( input_thread_t * p_input )
intf_WarnMsg( 2, "input: closing network target `%s'", p_input->p_source );
close( p_input->i_handle );
#ifdef WIN32
WSACleanup();
#endif
}
/*****************************************************************************
......@@ -1012,22 +994,6 @@ static void HTTPOpen( input_thread_t * p_input )
struct sockaddr_in sock;
char psz_buffer[256];
#ifdef WIN32
WSADATA Data;
int i_err;
#endif
#ifdef WIN32
/* WinSock Library Init. */
i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
if( i_err )
{
intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
return ;
}
#endif
/* Get the remote server */
if( p_input->p_source != NULL )
{
......
......@@ -4,7 +4,7 @@
* and spawn threads.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: main.c,v 1.123 2001/11/12 20:16:33 sam Exp $
* $Id: main.c,v 1.124 2001/11/12 22:42:56 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -92,6 +92,10 @@
# include "darwin_specific.h"
#endif
#ifdef WIN32
# include "win32_specific.h"
#endif
#include "netutils.h" /* network_ChannelJoin */
#include "main.h"
......@@ -288,7 +292,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
/*
* System specific initialization code
*/
#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
system_Init( &i_argc, ppsz_argv, ppsz_env );
#elif defined( WIN32 )
......@@ -440,7 +444,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
/*
* System specific cleaning code
*/
#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
system_End();
#endif
......
......@@ -2,7 +2,7 @@
* netutils.c: various network functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: netutils.c,v 1.42 2001/11/12 20:16:33 sam Exp $
* $Id: netutils.c,v 1.43 2001/11/12 22:42:56 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Benoit Steiner <benny@via.ecp.fr>
......@@ -38,23 +38,24 @@
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* gethostname() */
# include <unistd.h> /* gethostname() */
#elif defined( _MSC_VER ) && defined( _WIN32 )
#include <io.h>
# include <io.h>
#endif
#if !defined( _MSC_VER )
#include <sys/time.h> /* gettimeofday */
#endif
#if !defined( WIN32 )
#include <netdb.h> /* gethostbyname() */
#include <netinet/in.h> /* BSD: struct in_addr */
#include <sys/socket.h> /* BSD: struct sockaddr */
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
#ifdef WIN32
# include <winsock2.h>
#elif !defined( SYS_BEOS ) && !defined( SYS_NTO )
# include <netdb.h> /* hostent ... */
# include <sys/socket.h> /* BSD: struct sockaddr */
# include <netinet/in.h> /* BSD: struct in_addr */
# ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
# endif
#endif
#ifdef SYS_LINUX
......@@ -287,6 +288,12 @@ int network_ChannelJoin( int i_channel )
/* Initializing the socket */
i_fd = socket( AF_INET, SOCK_DGRAM, 0 );
if( i_fd < 0 )
{
intf_ErrMsg( "network error: unable to create vlcs socket (%s)",
strerror( errno ) );
return -1;
}
/* Getting information about the channel server */
psz_vlcs = main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
......@@ -294,7 +301,8 @@ int network_ChannelJoin( int i_channel )
i_port = main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
INPUT_CHANNEL_PORT_DEFAULT );
intf_WarnMsg( 6, "network: vlcs '%s', port %d", psz_vlcs, i_port );
intf_WarnMsg( 5, "network: socket %i, vlcs '%s', port %d",
i_fd, psz_vlcs, i_port );
memset( &sa_client, 0x00, sizeof(struct sockaddr_in) );
memset( &sa_server, 0x00, sizeof(struct sockaddr_in) );
......@@ -310,11 +318,11 @@ int network_ChannelJoin( int i_channel )
#endif
/* Bind the socket */
i_dummy = bind( i_fd, (struct sockaddr *)(&sa_client),
sizeof(struct sockaddr) );
if ( i_dummy )
if( bind( i_fd, (struct sockaddr*)(&sa_client), sizeof(sa_client) ) )
{
intf_ErrMsg( "network: unable to bind vlcs socket: %i", i_dummy );
intf_ErrMsg( "network: unable to bind vlcs socket (%s)",
strerror( errno ) );
close( i_fd );
return -1;
}
......@@ -322,6 +330,7 @@ int network_ChannelJoin( int i_channel )
if( GetMacAddress( i_fd, psz_mac ) )
{
intf_ErrMsg( "network error: failed getting MAC address" );
close( i_fd );
return -1;
}
......@@ -347,9 +356,8 @@ int network_ChannelJoin( int i_channel )
delay.tv_usec = 0;
FD_ZERO( &fds );
FD_SET( i_fd, &fds );
i_dummy = select( i_fd + 1, &fds, NULL, NULL, &delay );
switch( i_dummy )
switch( select( i_fd + 1, &fds, NULL, NULL, &delay ) )
{
case 0:
intf_ErrMsg( "network error: no answer from vlcs" );
......@@ -396,7 +404,7 @@ int network_ChannelJoin( int i_channel )
#else
intf_ErrMsg( "network error: channels not supported on this platform" );
return NULL;
return -1;
#endif
}
......
/*****************************************************************************
* win32_specific.c: Win32 specific features
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: win32_specific.c,v 1.1 2001/11/12 22:42:56 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*****************************************************************************/
#include "defs.h"
#include <string.h> /* strdup() */
#include <stdlib.h> /* free() */
#include <winsock2.h>
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "win32_specific.h"
/*****************************************************************************
* system_Init: initialize winsock.
*****************************************************************************/
void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
{
WSADATA Data;
int i_err;
/* WinSock Library Init. */
i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
if( i_err )
{
fprintf( stderr, "error: can't initiate WinSocks, error %i", i_err );
}
}
/*****************************************************************************
* system_End: terminate winsock.
*****************************************************************************/
void system_End( void )
{
WSACleanup();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment