Commit 9f8fcf88 authored by Marc Ariberti's avatar Marc Ariberti

*** empty log message ***

parent a1c76679
...@@ -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.24 2001/04/12 01:52:45 sam Exp $ * $Id: netutils.c,v 1.25 2001/04/17 20:43:41 marcari 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>
...@@ -220,122 +220,122 @@ int network_ChannelCreate( void ) ...@@ -220,122 +220,122 @@ int network_ChannelCreate( void )
*****************************************************************************/ *****************************************************************************/
int network_ChannelJoin( int i_channel_id ) int network_ChannelJoin( int i_channel_id )
{ {
intf_ErrMsg("Changing to channel %d",i_channel_id);
return(0);
/* Courtesy of Nitrox. He'll update it soon */
#if 0
/* I still prefer to put BeOS a bit apart */ /* I still prefer to put BeOS a bit apart */
#ifdef SYS_BEOS #ifdef SYS_BEOS
intf_ErrMsg( "Channels are not yet supported uunder BeOS" ); intf_ErrMsg( "Channels are not yet supported under BeOS" );
return( -1 ); return( -1 );
#else #else
#ifdef SYS_LINUX #ifdef SYS_LINUX
int socket_cl; int i_socket_cl;
int fromlen; int i_fromlen;
struct ifreq interface; struct ifreq s_interface;
struct sockaddr_in sa_server; struct sockaddr_in sa_server;
struct sockaddr_in sa_client; struct sockaddr_in sa_client;
unsigned int version = 12; unsigned int i_version = 12;
char mess[80]; char psz_mess[80];
char mess_length = 80; char i_mess_length = 80;
struct timeval *date_cl; struct timeval * p_date_cl;
struct timeval time; struct timeval s_time;
long unsigned int date; long unsigned int i_date;
int nbanswer; int i_nbanswer;
char answer; char i_answer;
fd_set rfds; fd_set s_rfds;
unsigned int rc; unsigned int i_rc;
/* debug */ intf_ErrMsg("ChannelJoin : %d",i_channel_id);
/* debug */
intf_DbgMsg( "ChannelJoin : %d", i_channel_id );
/* If last change is too recent, wait a while */ /* If last change is too recent, wait a while */
if( mdate() - p_main->p_channel->last_change < INPUT_CHANNEL_CHANGE_DELAY ) if( mdate() - p_main->p_channel->last_change < INPUT_CHANNEL_CHANGE_DELAY )
{ {
intf_Msg("Waiting before changing channel...\n"); intf_Msg( "Waiting before changing channel...\n" );
mwait( p_main->p_channel->last_change + INPUT_CHANNEL_CHANGE_DELAY ); mwait( p_main->p_channel->last_change + INPUT_CHANNEL_CHANGE_DELAY );
} }
p_main->p_channel->last_change = mdate(); p_main->p_channel->last_change = mdate();
p_main->p_channel->i_channel_id = i_channel_id; p_main->p_channel->i_channel_id = i_channel_id;
intf_Msg("Joining channel %d\n", i_channel_id ); intf_Msg( "Joining channel %d\n", i_channel_id );
/* /*
* Looking for information about the eth0 interface * Looking for information about the eth0 interface
*/ */
interface.ifr_addr.sa_family=AF_INET; s_interface.ifr_addr.sa_family = AF_INET;
strcpy(interface.ifr_name,INPUT_IFACE_DEFAULT); strcpy( s_interface.ifr_name, INPUT_IFACE_DEFAULT );
/* /*
* Initialysing the socket * Initialysing the socket
*/ */
socket_cl=socket(AF_INET,SOCK_DGRAM,0); i_socket_cl=socket( AF_INET, SOCK_DGRAM, 0 );
/* /*
* Getting the server's information * Getting the server's information
*/ */
bzero(&sa_server,sizeof(struct sockaddr_in)); bzero( &sa_server, sizeof(struct sockaddr_in) );
sa_server.sin_family=AF_INET; sa_server.sin_family = AF_INET;
sa_server.sin_port=htons(INPUT_CHANNEL_PORT_DEFAULT); sa_server.sin_port = htons( INPUT_CHANNEL_PORT_DEFAULT );
inet_aton(INPUT_CHANNEL_SERVER_DEFAULT,&(sa_server.sin_addr)); inet_aton( INPUT_CHANNEL_SERVER_DEFAULT, &(sa_server.sin_addr) );
/* /*
* Looking for the interface MAC address * Looking for the interface MAC address
*/ */
ioctl(socket_cl,SIOCGIFHWADDR,&interface); ioctl( i_socket_cl, SIOCGIFHWADDR, &s_interface );
intf_DbgMsg( intf_DbgMsg(
"CHANNELSERVER: macaddr == %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", "CHANNELSERVER: macaddr == %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
interface.ifr_hwaddr.sa_data[0] & 0xff, s_interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff, s_interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff, s_interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff, s_interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff, s_interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff); s_interface.ifr_hwaddr.sa_data[5] & 0xff );
/* /*
* Getting date of the client * Getting date of the client
*/ */
date_cl=malloc(sizeof(struct timeval)); p_date_cl=malloc( sizeof(struct timeval) );
if(date_cl==NULL) if( p_date_cl == NULL )
{ {
intf_ErrMsg("CHANNELSERVER: unable to allocate memory\n"); intf_ErrMsg( "CHANNELSERVER: unable to allocate memory\n" );
/* return VS_R_MEMORY;*/ /* return VS_R_MEMORY;*/
return -1; return( -1);
} }
if (gettimeofday(date_cl,0)==-1) if ( gettimeofday( p_date_cl, 0 ) == -1 )
return -1; {
date=date_cl->tv_sec; return( -1);
free(date_cl); }
intf_DbgMsg("CHANNELSERVER: date %lu\n",date); i_date = p_date_cl->tv_sec;
free( p_date_cl );
intf_DbgMsg( "CHANNELSERVER: date %lu\n", i_date );
/* /*
* Build of the message * Build of the message
*/ */
sprintf(mess,"%d %u %lu %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n", sprintf( psz_mess, "%d %u %lu %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n",
i_channel_id, version, date, i_channel_id, i_version, i_date,
interface.ifr_hwaddr.sa_data[0] & 0xff, s_interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff, s_interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff, s_interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff, s_interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff, s_interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff); s_interface.ifr_hwaddr.sa_data[5] & 0xff );
intf_DbgMsg("CHANNELSERVER: The message is %s\n",mess);
intf_DbgMsg( "CHANNELSERVER: The message is %s\n", psz_mess );
/* /*
* Open the socket 2 * Open the socket 2
*/ */
bzero(&sa_client,sizeof(struct sockaddr_in)); bzero( &sa_client, sizeof(struct sockaddr_in) );
sa_client.sin_family=AF_INET; sa_client.sin_family = AF_INET;
sa_client.sin_port=htons(4312); sa_client.sin_port = htons(4312);
sa_client.sin_addr.s_addr=INADDR_ANY; sa_client.sin_addr.s_addr = INADDR_ANY;
fromlen=sizeof(struct sockaddr); i_fromlen = sizeof( struct sockaddr );
rc=bind(socket_cl,(struct sockaddr *)(&sa_client),sizeof(struct sockaddr)); i_rc = bind( i_socket_cl, (struct sockaddr *)(&sa_client),\
if (rc) sizeof(struct sockaddr) );
if ( i_rc )
{ {
intf_ErrMsg("CHANNELSERVER: Unable to bind socket:%u\n",rc); intf_ErrMsg( "CHANNELSERVER: Unable to bind socket:%u\n", i_rc );
/* TODO put CS_R_BIND in types.h*/ /* TODO put CS_R_BIND in types.h*/
/* return CS_R_SOCKET;*/ /* return CS_R_SOCKET;*/
return -1; return -1;
...@@ -345,47 +345,56 @@ int network_ChannelJoin( int i_channel_id ) ...@@ -345,47 +345,56 @@ int network_ChannelJoin( int i_channel_id )
/* /*
* Send the message * Send the message
*/ */
sendto(socket_cl,mess,mess_length,0,(struct sockaddr *)(&sa_server),\ sendto( i_socket_cl, psz_mess, i_mess_length, 0, \
sizeof(struct sockaddr)); (struct sockaddr *)(&sa_server), \
sizeof(struct sockaddr) );
/* /*
* Waiting 5 sec for one answer from the server * Waiting 5 sec for one answer from the server
*/ */
time.tv_sec=5; s_time.tv_sec = 5;
time.tv_usec=0; s_time.tv_usec = 0;
FD_ZERO(&rfds); FD_ZERO( &s_rfds );
FD_SET(socket_cl,&rfds); FD_SET( i_socket_cl, &s_rfds );
nbanswer=select(socket_cl+1,&rfds,NULL,NULL,&time); i_nbanswer = select( i_socket_cl+1, &s_rfds, NULL, NULL, &s_time );
if(nbanswer==0) if( i_nbanswer == 0 )
intf_DbgMsg("CHANNELSERVER: no answer\n"); {
else if(nbanswer==-1) intf_DbgMsg( "CHANNELSERVER: no answer\n" );
intf_DbgMsg("CHANNELSERVER: Unable to receive the answer\n"); }
else if( i_nbanswer == -1 )
{
intf_DbgMsg( "CHANNELSERVER: Unable to receive the answer\n ");
}
else else
{ {
recvfrom(socket_cl,&answer,sizeof(char),0,\ recvfrom( i_socket_cl, &i_answer, sizeof(char), 0,\
(struct sockaddr *)(&sa_client),&fromlen); (struct sockaddr *)(&sa_client), &i_fromlen);
intf_DbgMsg("CHANNELSERVER: the answer : %hhd\n",answer); intf_DbgMsg( "CHANNELSERVER: the answer : %hhd\n", i_answer );
if(answer==-1) if( i_answer == -1 )
{
intf_DbgMsg( intf_DbgMsg(
"CHANNELSERVER: The server failed to create the thread\n"); "CHANNELSERVER: The server failed to create the thread\n" );
else if(answer==0) }
else if( i_answer == 0 )
{
intf_DbgMsg( intf_DbgMsg(
"CHANNELSERVER: The server tries to change the channel\n"); "CHANNELSERVER: The server tries to change the channel\n" );
}
else else
intf_DbgMsg("CHANNELSERVER: Unknown answer !\n"); {
intf_DbgMsg( "CHANNELSERVER: Unknown answer !\n" );
}
} }
/* /*
* Close the socket * Close the socket
*/ */
close(socket_cl); close( i_socket_cl );
return 0; return( 0 );
#else /* SYS_LINUX */ #else /* SYS_LINUX */
intf_ErrMsg( "Channel only work under linux yet" ); intf_ErrMsg( "Channel only work under linux yet" );
#endif /* SYS_LINUX */ #endif /* SYS_LINUX */
}
#endif /* SYS_BEOS */ #endif /* SYS_BEOS */
#endif /* if 0 */
} }
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