Commit 25c83d44 authored by Christophe Massiot's avatar Christophe Massiot

(Hopefully) fixed the network connect() bug under UNIX. I need

confirmation that I didn't break the Win32 port, please.
parent 8b949d08
......@@ -4,7 +4,7 @@
* decoders.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: input.c,v 1.156 2001/11/15 18:50:49 sam Exp $
* $Id: input.c,v 1.157 2001/11/21 16:47:46 massiot Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -731,7 +731,6 @@ static void NetworkOpen( input_thread_t * p_input )
int i_opt;
int i_opt_size;
struct sockaddr_in sock;
unsigned int i_mc_group;
/* Get the remote server */
if( p_input->p_source != NULL )
......@@ -895,15 +894,6 @@ static void NetworkOpen( input_thread_t * p_input )
return;
}
/* Required for IP_ADD_MEMBERSHIP */
i_mc_group = sock.sin_addr.s_addr;
#if defined( WIN32 )
sock.sin_addr.s_addr = INADDR_ANY;
#define IN_MULTICAST(a) IN_CLASSD(a)
#endif
/* Bind it */
if( bind( p_input->i_handle, (struct sockaddr *)&sock,
sizeof( sock ) ) < 0 )
......@@ -916,13 +906,18 @@ static void NetworkOpen( input_thread_t * p_input )
/* Join the multicast group if the socket is a multicast address */
#if defined( WIN32 )
# define IN_MULTICAST(a) IN_CLASSD(a)
#endif
/* TODO : make this compile under Win32 */
#ifndef WIN32
if( IN_MULTICAST( ntohl(i_mc_group) ) )
if( IN_MULTICAST( ntohl(sock.sin_addr.s_addr) ) )
{
struct ip_mreq imr;
imr.imr_interface.s_addr = htonl(INADDR_ANY);
imr.imr_multiaddr.s_addr = i_mc_group;
imr.imr_interface.s_addr = INADDR_ANY;
imr.imr_multiaddr.s_addr = sock.sin_addr.s_addr;
if( setsockopt( p_input->i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char*)&imr, sizeof(struct ip_mreq) ) == -1 )
{
......
......@@ -2,7 +2,7 @@
* netutils.c: various network functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: netutils.c,v 1.46 2001/11/16 00:29:52 stef Exp $
* $Id: netutils.c,v 1.47 2001/11/21 16:47:46 massiot Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Benoit Steiner <benny@via.ecp.fr>
......@@ -115,48 +115,34 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
char * psz_broadcast )
{
#if defined( SYS_BEOS )
intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
intf_ErrMsg( "error: networking is not yet supported under BeOS" );
return( 1 );
#else
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 );
if( psz_broadcast == NULL )
{
/* 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 );
}
p_socket->sin_addr.s_addr = INADDR_ANY;
}
else
{
/* I didn't manage to make INADDR_ANYT work, even with setsockopt
* so, as it's kludgy to try and determine the broadcast addr
* it is passed as an argument in the command line */
strncpy( psz_hostname, psz_broadcast, INPUT_MAX_SOURCE_LENGTH );
}
struct hostent * p_hostent;
/* Try to convert address directly from in_addr - this will work if
* psz_in_addr is dotted decimal. */
* psz_broadcast is dotted decimal. */
#ifdef HAVE_ARPA_INET_H
if( !inet_aton( psz_hostname, &p_socket->sin_addr) )
if( !inet_aton( psz_broadcast, &p_socket->sin_addr) )
#else
if( (p_socket->sin_addr.s_addr = inet_addr( psz_hostname )) == -1 )
if( (p_socket->sin_addr.s_addr = inet_addr( psz_broadcast )) == -1 )
#endif
{
/* We have a fqdn, try to find its address */
if ( (p_hostent = gethostbyname( psz_hostname )) == NULL )
if ( (p_hostent = gethostbyname( psz_broadcast )) == NULL )
{
intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_hostname );
intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_broadcast );
return( -1 );
}
......@@ -164,6 +150,7 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
memcpy( &p_socket->sin_addr, p_hostent->h_addr_list[0],
p_hostent->h_length );
}
}
return( 0 );
#endif
}
......@@ -174,7 +161,7 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
int network_BuildRemoteAddr( struct sockaddr_in * p_socket, char * psz_server )
{
#if defined( SYS_BEOS )
intf_ErrMsg( "error: channel changing is not yet supported under BeOS" );
intf_ErrMsg( "error: networking is not yet supported under BeOS" );
return( 1 );
#else
......
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