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 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN * 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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -731,7 +731,6 @@ static void NetworkOpen( input_thread_t * p_input ) ...@@ -731,7 +731,6 @@ static void NetworkOpen( input_thread_t * p_input )
int i_opt; int i_opt;
int i_opt_size; int i_opt_size;
struct sockaddr_in sock; struct sockaddr_in sock;
unsigned int i_mc_group;
/* Get the remote server */ /* Get the remote server */
if( p_input->p_source != NULL ) if( p_input->p_source != NULL )
...@@ -895,15 +894,6 @@ static void NetworkOpen( input_thread_t * p_input ) ...@@ -895,15 +894,6 @@ static void NetworkOpen( input_thread_t * p_input )
return; 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 */ /* Bind it */
if( bind( p_input->i_handle, (struct sockaddr *)&sock, if( bind( p_input->i_handle, (struct sockaddr *)&sock,
sizeof( sock ) ) < 0 ) sizeof( sock ) ) < 0 )
...@@ -916,13 +906,18 @@ static void NetworkOpen( input_thread_t * p_input ) ...@@ -916,13 +906,18 @@ static void NetworkOpen( input_thread_t * p_input )
/* Join the multicast group if the socket is a multicast address */ /* 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 #ifndef WIN32
if( IN_MULTICAST( ntohl(i_mc_group) ) ) if( IN_MULTICAST( ntohl(sock.sin_addr.s_addr) ) )
{ {
struct ip_mreq imr; struct ip_mreq imr;
imr.imr_interface.s_addr = htonl(INADDR_ANY); imr.imr_interface.s_addr = INADDR_ANY;
imr.imr_multiaddr.s_addr = i_mc_group; imr.imr_multiaddr.s_addr = sock.sin_addr.s_addr;
if( setsockopt( p_input->i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP, if( setsockopt( p_input->i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char*)&imr, sizeof(struct ip_mreq) ) == -1 ) (char*)&imr, sizeof(struct ip_mreq) ) == -1 )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* netutils.c: various network functions * netutils.c: various network functions
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * 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> * Authors: Vincent Seguin <seguin@via.ecp.fr>
* Benoit Steiner <benny@via.ecp.fr> * Benoit Steiner <benny@via.ecp.fr>
...@@ -115,54 +115,41 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port, ...@@ -115,54 +115,41 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port,
char * psz_broadcast ) char * psz_broadcast )
{ {
#if defined( SYS_BEOS ) #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 ); return( 1 );
#else #else
char psz_hostname[INPUT_MAX_SOURCE_LENGTH];
struct hostent * p_hostent;
/* Reset struct */ /* Reset struct */
memset( p_socket, 0, sizeof( struct sockaddr_in ) ); memset( p_socket, 0, sizeof( struct sockaddr_in ) );
p_socket->sin_family = AF_INET; /* family */ p_socket->sin_family = AF_INET; /* family */
p_socket->sin_port = htons( i_port ); p_socket->sin_port = htons( i_port );
if( psz_broadcast == NULL ) if( psz_broadcast == NULL )
{ {
/* Try to get our own IP */ p_socket->sin_addr.s_addr = INADDR_ANY;
if( gethostname( psz_hostname, sizeof(psz_hostname) ) )
{
intf_ErrMsg( "BuildLocalAddr : unable to resolve local name : %s",
strerror( errno ) );
return( -1 );
}
} }
else else
{ {
/* I didn't manage to make INADDR_ANYT work, even with setsockopt struct hostent * p_hostent;
* 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 );
}
/* Try to convert address directly from in_addr - this will work if /* 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 #ifdef HAVE_ARPA_INET_H
if( !inet_aton( psz_hostname, &p_socket->sin_addr) ) if( !inet_aton( psz_broadcast, &p_socket->sin_addr) )
#else #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 #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 ); /* We have a fqdn, try to find its address */
return( -1 ); if ( (p_hostent = gethostbyname( psz_broadcast )) == NULL )
{
intf_ErrMsg( "BuildLocalAddr: unknown host %s", psz_broadcast );
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 );
} }
/* 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 ); return( 0 );
#endif #endif
...@@ -174,7 +161,7 @@ int network_BuildLocalAddr( struct sockaddr_in * p_socket, int i_port, ...@@ -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 ) int network_BuildRemoteAddr( struct sockaddr_in * p_socket, char * psz_server )
{ {
#if defined( SYS_BEOS ) #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 ); return( 1 );
#else #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