| 147 | | return( ZeTrucMucheFunction( i_vlan_id ) ); /* FIXME: join vlan ?? */ |
|---|
| 148 | | #endif /* SYS_BEOS */ |
|---|
| | 178 | |
|---|
| | 179 | /* |
|---|
| | 180 | *Looking for informations about the eth0 interface |
|---|
| | 181 | */ |
|---|
| | 182 | interface.ifr_addr.sa_family = AF_INET; |
|---|
| | 183 | strcpy( interface.ifr_name, INTERFACE ); |
|---|
| | 184 | |
|---|
| | 185 | |
|---|
| | 186 | /* |
|---|
| | 187 | * Initialysing the socket |
|---|
| | 188 | */ |
|---|
| | 189 | socket_cl = socket( AF_INET, SOCK_DGRAM, 0 ); |
|---|
| | 190 | intf_DbgMsg( "socket %d\n", socket_cl ); |
|---|
| | 191 | |
|---|
| | 192 | |
|---|
| | 193 | /* |
|---|
| | 194 | * Getting the server's information |
|---|
| | 195 | */ |
|---|
| | 196 | bzero (&sa_server, sizeof (struct sockaddr_in)); |
|---|
| | 197 | sa_server.sin_family = AF_INET; |
|---|
| | 198 | sa_server.sin_port = htons (VLANSERVER_PORT); |
|---|
| | 199 | inet_aton (SERVER, &(sa_server.sin_addr)); |
|---|
| | 200 | |
|---|
| | 201 | /* |
|---|
| | 202 | * Looking for the interface MAC address |
|---|
| | 203 | */ |
|---|
| | 204 | ioctl( socket_cl, SIOCGIFHWADDR, &interface ); |
|---|
| | 205 | intf_DbgMsg( "macaddr == %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", |
|---|
| | 206 | interface.ifr_hwaddr.sa_data[0] & 0xff, |
|---|
| | 207 | interface.ifr_hwaddr.sa_data[1] & 0xff, |
|---|
| | 208 | interface.ifr_hwaddr.sa_data[2] & 0xff, |
|---|
| | 209 | interface.ifr_hwaddr.sa_data[3] & 0xff, |
|---|
| | 210 | interface.ifr_hwaddr.sa_data[4] & 0xff, |
|---|
| | 211 | interface.ifr_hwaddr.sa_data[5] & 0xff ); |
|---|
| | 212 | |
|---|
| | 213 | /* |
|---|
| | 214 | * Getting date of the client |
|---|
| | 215 | */ |
|---|
| | 216 | date_cl = malloc (sizeof (struct timeval)); |
|---|
| | 217 | if (gettimeofday (date_cl, 0) == -1) |
|---|
| | 218 | { |
|---|
| | 219 | return -1; |
|---|
| | 220 | } |
|---|
| | 221 | date = date_cl->tv_sec; |
|---|
| | 222 | intf_DbgMsg ("date %lu\n", date); |
|---|
| | 223 | |
|---|
| | 224 | |
|---|
| | 225 | /* |
|---|
| | 226 | * Build of the message |
|---|
| | 227 | */ |
|---|
| | 228 | sprintf (mess, "%d %u %lu %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n", |
|---|
| | 229 | i_vlan_id, version, date, |
|---|
| | 230 | interface.ifr_hwaddr.sa_data[0] & 0xff, |
|---|
| | 231 | interface.ifr_hwaddr.sa_data[1] & 0xff, |
|---|
| | 232 | interface.ifr_hwaddr.sa_data[2] & 0xff, |
|---|
| | 233 | interface.ifr_hwaddr.sa_data[3] & 0xff, |
|---|
| | 234 | interface.ifr_hwaddr.sa_data[4] & 0xff, |
|---|
| | 235 | interface.ifr_hwaddr.sa_data[5] & 0xff); |
|---|
| | 236 | intf_DbgMsg ("The message is %s\n", mess); |
|---|
| | 237 | |
|---|
| | 238 | |
|---|
| | 239 | /* |
|---|
| | 240 | * Open the socket 2 |
|---|
| | 241 | */ |
|---|
| | 242 | bzero (&sa_client, sizeof (struct sockaddr_in)); |
|---|
| | 243 | sa_client.sin_family = AF_INET; |
|---|
| | 244 | sa_client.sin_port = htons( 4312 ); |
|---|
| | 245 | sa_client.sin_addr.s_addr = INADDR_ANY; |
|---|
| | 246 | intf_DbgMsg ("socket %d\n", socket_cl = socket( AF_INET, SOCK_DGRAM, 0 )); |
|---|
| | 247 | fromlen = sizeof (struct sockaddr); |
|---|
| | 248 | intf_DbgMsg( "bind %i\n", bind( socket_cl, (struct sockaddr *)(&sa_client), sizeof( struct sockaddr ))); |
|---|
| | 249 | |
|---|
| | 250 | |
|---|
| | 251 | /* |
|---|
| | 252 | * Send the message |
|---|
| | 253 | */ |
|---|
| | 254 | sendto (socket_cl, mess, 80, 0, (struct sockaddr *)(&sa_server), sizeof (struct sockaddr )); |
|---|
| | 255 | { |
|---|
| | 256 | unsigned z; |
|---|
| | 257 | printf("BBP\n"); |
|---|
| | 258 | z=0; |
|---|
| | 259 | do {z++;} while (mess[z]!=':'); |
|---|
| | 260 | do {z++;} while (mess[z]!='e'); |
|---|
| | 261 | printf("meuuh %d %d\n",(unsigned)mess[z+3],(unsigned)mess[z+4]); |
|---|
| | 262 | } |
|---|
| | 263 | printf("BBP2\n"); |
|---|
| | 264 | |
|---|
| | 265 | |
|---|
| | 266 | /* |
|---|
| | 267 | * Waiting 5 sec for one answer from the server |
|---|
| | 268 | */ |
|---|
| | 269 | time.tv_sec = 5; |
|---|
| | 270 | time.tv_usec = 0; |
|---|
| | 271 | FD_ZERO( &rfds ); |
|---|
| | 272 | FD_SET( socket_cl, &rfds ); |
|---|
| | 273 | nbanswer = select( socket_cl + 1, &rfds, NULL, NULL, &time); |
|---|
| | 274 | if( nbanswer == 0 ) |
|---|
| | 275 | { |
|---|
| | 276 | intf_DbgMsg( "no answer\n" ); |
|---|
| | 277 | } |
|---|
| | 278 | else if( nbanswer == -1 ) |
|---|
| | 279 | { |
|---|
| | 280 | intf_DbgMsg( "I couldn't recieve the answer\n" ); |
|---|
| | 281 | } |
|---|
| | 282 | else |
|---|
| | 283 | { |
|---|
| | 284 | recvfrom (socket_cl, &answer, sizeof( char ), 0, (struct sockaddr *)(&sa_client), &fromlen); |
|---|
| | 285 | intf_DbgMsg( "the answer : %hhd\n", answer ); |
|---|
| | 286 | if( answer == -1 ) |
|---|
| | 287 | { |
|---|
| | 288 | intf_DbgMsg( "The server doesn't succed to create the thread\n" ); |
|---|
| | 289 | } |
|---|
| | 290 | else if( answer == 0 ) |
|---|
| | 291 | { |
|---|
| | 292 | intf_DbgMsg( "The server try to change the channel\n" ); |
|---|
| | 293 | } |
|---|
| | 294 | else |
|---|
| | 295 | { |
|---|
| | 296 | intf_DbgMsg( "I don't know what is this answer !\n" ); |
|---|
| | 297 | } |
|---|
| | 298 | } |
|---|
| | 299 | |
|---|
| | 300 | |
|---|
| | 301 | /* |
|---|
| | 302 | * Close the socket |
|---|
| | 303 | */ |
|---|
| | 304 | close( socket_cl); |
|---|
| | 305 | |
|---|
| | 306 | return 0; |
|---|
| | 307 | #endif |
|---|
| 150 | | |
|---|
| 151 | | /***************************************************************************** |
|---|
| 152 | | * input_VlanLeave: leave a vlan |
|---|
| 153 | | ***************************************************************************** |
|---|
| 154 | | * This function tells the vlan library that the designed interface is no more |
|---|
| 155 | | * locked and than vlan changes can occur. |
|---|
| 156 | | *****************************************************************************/ |
|---|
| 157 | | void input_VlanLeave( int i_vlan_id ) |
|---|
| 158 | | { |
|---|
| 159 | | /* XXX?? */ |
|---|
| 160 | | } |
|---|
| 161 | | |
|---|
| 162 | | /* following functions are local */ |
|---|
| 163 | | |
|---|
| 164 | | static int ZeTrucMucheFunction( int Channel) |
|---|
| 165 | | { |
|---|
| 166 | | #ifdef SYS_LINUX |
|---|
| 167 | | int i_socket; |
|---|
| 168 | | char * ipaddr; |
|---|
| 169 | | struct ifreq interface; |
|---|
| 170 | | struct sockaddr_in sa_server; |
|---|
| 171 | | struct sockaddr_in sa_client; |
|---|
| 172 | | char mess[80]; |
|---|
| 173 | | |
|---|
| 174 | | /* |
|---|
| 175 | | *Looking for informations about the eth0 interface |
|---|
| 176 | | */ |
|---|
| 177 | | |
|---|
| 178 | | interface.ifr_addr.sa_family = AF_INET; |
|---|
| 179 | | strcpy( interface.ifr_name, main_GetPszVariable( INPUT_IFACE_VAR, INPUT_IFACE_DEFAULT ) ); |
|---|
| 180 | | |
|---|
| 181 | | i_socket = socket( AF_INET, SOCK_DGRAM, 0 ); |
|---|
| 182 | | |
|---|
| 183 | | /* Looking for the interface IP address */ |
|---|
| 184 | | ioctl( i_socket, SIOCGIFDSTADDR, &interface ); |
|---|
| 185 | | ipaddr = inet_ntoa((*(struct sockaddr_in *)(&(interface.ifr_addr))).sin_addr ); |
|---|
| 186 | | |
|---|
| 187 | | /* Looking for the interface MAC address */ |
|---|
| 188 | | ioctl( i_socket, SIOCGIFHWADDR, &interface ); |
|---|
| 189 | | close( i_socket ); |
|---|
| 190 | | |
|---|
| 191 | | /* |
|---|
| 192 | | * Getting address, port, ... of the server |
|---|
| 193 | | */ |
|---|
| 194 | | |
|---|
| 195 | | /* Initialize */ |
|---|
| 196 | | bzero( &sa_server, sizeof(struct sockaddr_in) ); |
|---|
| 197 | | /* sin_family is ALWAYS set to AF_INET (see in man 7 ip)*/ |
|---|
| 198 | | sa_server.sin_family = AF_INET; |
|---|
| 199 | | /* Giving port on to connect after having convert it*/ |
|---|
| 200 | | sa_server.sin_port = htons ( main_GetIntVariable( INPUT_VLAN_PORT_VAR, INPUT_VLAN_PORT_DEFAULT )); |
|---|
| 201 | | /* Giving address after having convert it into binary data*/ |
|---|
| 202 | | inet_aton( main_GetPszVariable( INPUT_VLAN_SERVER_VAR, INPUT_VLAN_SERVER_DEFAULT ), &(sa_server.sin_addr) ); |
|---|
| 203 | | |
|---|
| 204 | | /* |
|---|
| 205 | | * Getting address, port, ... of the client |
|---|
| 206 | | */ |
|---|
| 207 | | |
|---|
| 208 | | /* Initialize */ |
|---|
| 209 | | bzero( &sa_client, sizeof(struct sockaddr_in) ); |
|---|
| 210 | | /* sin_family is ALWAYS set to AF_INET (see in man 7 ip)*/ |
|---|
| 211 | | sa_client.sin_family = AF_INET; |
|---|
| 212 | | /* Giving port on to connect after having convert it*/ |
|---|
| 213 | | sa_client.sin_port = htons( 0 ); |
|---|
| 214 | | /* Giving address after having convert it into binary data*/ |
|---|
| 215 | | inet_aton( ipaddr, &(sa_client.sin_addr) ); |
|---|
| 216 | | |
|---|
| 217 | | /* Initialization of the socket */ |
|---|
| 218 | | i_socket = socket(AF_INET, SOCK_DGRAM, 17 ); /* XXX?? UDP */ |
|---|
| 219 | | /* SOCK_DGRAM because here we use DATAGRAM |
|---|
| 220 | | * Sachant qu'il y a un #define AF_INET = PF_INET dans sys/socket.h et que PF_INET est le IP protocol family ... |
|---|
| 221 | | * Protocol is in #define, should be 17 for udp */ |
|---|
| 222 | | |
|---|
| 223 | | /* Elaborate the message to send */ |
|---|
| 224 | | 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", |
|---|
| 225 | | Channel, ipaddr, |
|---|
| 226 | | interface.ifr_hwaddr.sa_data[0] & 0xff, |
|---|
| 227 | | interface.ifr_hwaddr.sa_data[1] & 0xff, |
|---|
| 228 | | interface.ifr_hwaddr.sa_data[2] & 0xff, |
|---|
| 229 | | interface.ifr_hwaddr.sa_data[3] & 0xff, |
|---|
| 230 | | interface.ifr_hwaddr.sa_data[4] & 0xff, |
|---|
| 231 | | interface.ifr_hwaddr.sa_data[5] & 0xff, |
|---|
| 232 | | interface.ifr_hwaddr.sa_data[0] & 0xff, |
|---|
| 233 | | interface.ifr_hwaddr.sa_data[1] & 0xff, |
|---|
| 234 | | interface.ifr_hwaddr.sa_data[2] & 0xff, |
|---|
| 235 | | interface.ifr_hwaddr.sa_data[3] & 0xff, |
|---|
| 236 | | interface.ifr_hwaddr.sa_data[4] & 0xff, |
|---|
| 237 | | interface.ifr_hwaddr.sa_data[5] & 0xff |
|---|
| 238 | | ); |
|---|
| 239 | | |
|---|
| 240 | | /* Send the message */ |
|---|
| 241 | | intf_DbgMsg("%s\n", mess); |
|---|
| 242 | | sendto(i_socket,mess,80,0,(struct sockaddr *)&sa_server,sizeof(struct sockaddr)); |
|---|
| 243 | | |
|---|
| 244 | | /*Close the socket */ |
|---|
| 245 | | close( i_socket ); |
|---|
| 246 | | #endif |
|---|
| 247 | | |
|---|
| 248 | | return 0; |
|---|
| 249 | | } |
|---|