* 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.
+ * 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-1307, USA.
+ * 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.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
+#include "defs.h"
+
#include <errno.h> /* ENOMEM */
#include <stdio.h> /* sprintf() */
#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 */
#include <net/if.h> /* interface (arch-dependent) */
#endif
-#include "threads.h"
#include "config.h"
#include "common.h"
+#include "threads.h"
#include "mtime.h"
+#include "plugins.h"
#include "netutils.h"
#include "input_vlan.h"
#include "intf_msg.h"
+
#include "main.h"
/*****************************************************************************
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int ZeTrucMucheFunction( int Channel );
/*****************************************************************************
* input_VlanCreate: initialize global vlan method data
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
*****************************************************************************
#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 )
{
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 );
+
+
+ /*
+ * 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);
- i_socket = socket( AF_INET, SOCK_DGRAM, 0 );
- /* Looking for the interface IP address */
- ioctl( i_socket, SIOCGIFDSTADDR, &interface );
- ipaddr = inet_ntoa((*(struct sockaddr_in *)(&(interface.ifr_addr))).sin_addr );
+ /*
+ * 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);
- /* Looking for the interface MAC address */
- ioctl( i_socket, SIOCGIFHWADDR, &interface );
- close( i_socket );
/*
- * 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
}