Commit fbb3c3d6 authored by Sam Hocevar's avatar Sam Hocevar

. le code des VLAN devrait refonctionner

parent e1e77d20
......@@ -30,6 +30,7 @@
#include <unistd.h> /* close() */
#include <string.h> /* strerror(), bzero() */
#include <stdlib.h> /* free() */
#include <sys/time.h> /* timeval */
#if defined(SYS_BSD) || defined(SYS_BEOS)
#include <netinet/in.h> /* struct in_addr */
......@@ -68,7 +69,6 @@ typedef struct input_vlan_s
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int ZeTrucMucheFunction( int Channel );
/*****************************************************************************
* input_VlanCreate: initialize global vlan method data
......@@ -118,6 +118,17 @@ void input_VlanDestroy( void )
free( p_main->p_vlan );
}
/*****************************************************************************
* input_VlanLeave: leave a vlan
*****************************************************************************
* This function tells the vlan library that the designed interface is no more
* locked and than vlan changes can occur.
*****************************************************************************/
void input_VlanLeave( int i_vlan_id )
{
/* XXX?? */
}
/*****************************************************************************
* input_VlanJoin: join a vlan
*****************************************************************************
......@@ -134,6 +145,26 @@ int input_VlanJoin( int i_vlan_id )
#ifdef SYS_BEOS
return( -1 );
#else
#define SERVER "138.195.130.90"
#define INTERFACE "eth0"
/* default server port */
#define VLANSERVER_PORT 6010
int socket_cl;
int fromlen;
struct ifreq interface;
struct sockaddr_in sa_server;
struct sockaddr_in sa_client;
unsigned int version = 12;
char mess[80];
struct timeval *date_cl;
struct timeval time;
long unsigned int date;
int nbanswer;
char answer;
fd_set rfds;
/* If last change is too recent, wait a while */
if( mdate() - p_main->p_vlan->last_change < INPUT_VLAN_CHANGE_DELAY )
{
......@@ -144,106 +175,134 @@ int input_VlanJoin( int i_vlan_id )
p_main->p_vlan->i_vlan_id = i_vlan_id;
intf_Msg("Joining VLAN %d (channel %d)\n", i_vlan_id + 2, i_vlan_id );
return( ZeTrucMucheFunction( i_vlan_id ) ); /* FIXME: join vlan ?? */
#endif /* SYS_BEOS */
}
/*****************************************************************************
* input_VlanLeave: leave a vlan
*****************************************************************************
* This function tells the vlan library that the designed interface is no more
* locked and than vlan changes can occur.
*****************************************************************************/
void input_VlanLeave( int i_vlan_id )
{
/* XXX?? */
}
/* following functions are local */
static int ZeTrucMucheFunction( int Channel)
{
#ifdef SYS_LINUX
int i_socket;
char * ipaddr;
struct ifreq interface;
struct sockaddr_in sa_server;
struct sockaddr_in sa_client;
char mess[80];
/*
/*
*Looking for informations about the eth0 interface
*/
interface.ifr_addr.sa_family = AF_INET;
strcpy( interface.ifr_name, main_GetPszVariable( INPUT_IFACE_VAR, INPUT_IFACE_DEFAULT ) );
strcpy( interface.ifr_name, INTERFACE );
/*
* Initialysing the socket
*/
socket_cl = socket( AF_INET, SOCK_DGRAM, 0 );
intf_DbgMsg( "socket %d\n", socket_cl );
i_socket = socket( AF_INET, SOCK_DGRAM, 0 );
/*
* Getting the server's information
*/
bzero (&sa_server, sizeof (struct sockaddr_in));
sa_server.sin_family = AF_INET;
sa_server.sin_port = htons (VLANSERVER_PORT);
inet_aton (SERVER, &(sa_server.sin_addr));
/*
* Looking for the interface MAC address
*/
ioctl( socket_cl, SIOCGIFHWADDR, &interface );
intf_DbgMsg( "macaddr == %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff );
/*
* Getting date of the client
*/
date_cl = malloc (sizeof (struct timeval));
if (gettimeofday (date_cl, 0) == -1)
{
return -1;
}
date = date_cl->tv_sec;
intf_DbgMsg ("date %lu\n", date);
/* Looking for the interface IP address */
ioctl( i_socket, SIOCGIFDSTADDR, &interface );
ipaddr = inet_ntoa((*(struct sockaddr_in *)(&(interface.ifr_addr))).sin_addr );
/* Looking for the interface MAC address */
ioctl( i_socket, SIOCGIFHWADDR, &interface );
close( i_socket );
/*
* Build of the message
*/
sprintf (mess, "%d %u %lu %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n",
i_vlan_id, version, date,
interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff);
intf_DbgMsg ("The message is %s\n", mess);
/*
* Getting address, port, ... of the server
* Open the socket 2
*/
bzero (&sa_client, sizeof (struct sockaddr_in));
sa_client.sin_family = AF_INET;
sa_client.sin_port = htons( 4312 );
sa_client.sin_addr.s_addr = INADDR_ANY;
intf_DbgMsg ("socket %d\n", socket_cl = socket( AF_INET, SOCK_DGRAM, 0 ));
fromlen = sizeof (struct sockaddr);
intf_DbgMsg( "bind %i\n", bind( socket_cl, (struct sockaddr *)(&sa_client), sizeof( struct sockaddr )));
/* Initialize */
bzero( &sa_server, sizeof(struct sockaddr_in) );
/* sin_family is ALWAYS set to AF_INET (see in man 7 ip)*/
sa_server.sin_family = AF_INET;
/* Giving port on to connect after having convert it*/
sa_server.sin_port = htons ( main_GetIntVariable( INPUT_VLAN_PORT_VAR, INPUT_VLAN_PORT_DEFAULT ));
/* Giving address after having convert it into binary data*/
inet_aton( main_GetPszVariable( INPUT_VLAN_SERVER_VAR, INPUT_VLAN_SERVER_DEFAULT ), &(sa_server.sin_addr) );
/*
* Getting address, port, ... of the client
* Send the message
*/
sendto (socket_cl, mess, 80, 0, (struct sockaddr *)(&sa_server), sizeof (struct sockaddr ));
{
unsigned z;
printf("BBP\n");
z=0;
do {z++;} while (mess[z]!=':');
do {z++;} while (mess[z]!='e');
printf("meuuh %d %d\n",(unsigned)mess[z+3],(unsigned)mess[z+4]);
}
printf("BBP2\n");
/* Initialize */
bzero( &sa_client, sizeof(struct sockaddr_in) );
/* sin_family is ALWAYS set to AF_INET (see in man 7 ip)*/
sa_client.sin_family = AF_INET;
/* Giving port on to connect after having convert it*/
sa_client.sin_port = htons( 0 );
/* Giving address after having convert it into binary data*/
inet_aton( ipaddr, &(sa_client.sin_addr) );
/* Initialization of the socket */
i_socket = socket(AF_INET, SOCK_DGRAM, 17 ); /* XXX?? UDP */
/* SOCK_DGRAM because here we use DATAGRAM
* Sachant qu'il y a un #define AF_INET = PF_INET dans sys/socket.h et que PF_INET est le IP protocol family ...
* Protocol is in #define, should be 17 for udp */
/* Elaborate the message to send */
sprintf( mess , "%d %s %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n",
Channel, ipaddr,
interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff,
interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff
);
/* Send the message */
intf_DbgMsg("%s\n", mess);
sendto(i_socket,mess,80,0,(struct sockaddr *)&sa_server,sizeof(struct sockaddr));
/*Close the socket */
close( i_socket );
#endif
/*
* Waiting 5 sec for one answer from the server
*/
time.tv_sec = 5;
time.tv_usec = 0;
FD_ZERO( &rfds );
FD_SET( socket_cl, &rfds );
nbanswer = select( socket_cl + 1, &rfds, NULL, NULL, &time);
if( nbanswer == 0 )
{
intf_DbgMsg( "no answer\n" );
}
else if( nbanswer == -1 )
{
intf_DbgMsg( "I couldn't recieve the answer\n" );
}
else
{
recvfrom (socket_cl, &answer, sizeof( char ), 0, (struct sockaddr *)(&sa_client), &fromlen);
intf_DbgMsg( "the answer : %hhd\n", answer );
if( answer == -1 )
{
intf_DbgMsg( "The server doesn't succed to create the thread\n" );
}
else if( answer == 0 )
{
intf_DbgMsg( "The server try to change the channel\n" );
}
else
{
intf_DbgMsg( "I don't know what is this answer !\n" );
}
}
/*
* Close the socket
*/
close( socket_cl);
return 0;
#endif
}
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