started multicast for planes
This commit is contained in:
parent
070d0dd19d
commit
edad9a8f8f
|
@ -9,13 +9,13 @@ default: all
|
||||||
lib/network/tcp/client.o: lib/header.h lib/network/tcp/client.h lib/network/tcp/client.c
|
lib/network/tcp/client.o: lib/header.h lib/network/tcp/client.h lib/network/tcp/client.c
|
||||||
gcc $(CFLAGS) -c -o lib/network/tcp/client.o lib/network/tcp/client.c
|
gcc $(CFLAGS) -c -o lib/network/tcp/client.o lib/network/tcp/client.c
|
||||||
|
|
||||||
lib/network/udp/client.o: lib/header.h lib/network/udp/client.h lib/network/udp/client.c
|
lib/network/udp/server.o: lib/header.h lib/network/udp/server.h lib/network/udp/server.c
|
||||||
gcc $(CFLAGS) -c -o lib/network/udp/client.o lib/network/udp/client.c
|
gcc $(CFLAGS) -c -o lib/network/udp/server.o lib/network/udp/server.c
|
||||||
|
|
||||||
# Compiles the Plane
|
# Compiles the Plane
|
||||||
# -lm flag for math lib
|
# -lm flag for math lib
|
||||||
boot: lib/network/tcp/client.o lib/network/udp/client.o plane.h plane.c
|
boot: lib/network/tcp/client.o lib/network/udp/server.o plane.h plane.c
|
||||||
gcc $(CFLAGS) -o boot lib/network/tcp/client.o lib/network/udp/client.o plane.c -lm
|
gcc $(CFLAGS) -o boot lib/network/tcp/client.o lib/network/udp/server.o plane.c -lm
|
||||||
|
|
||||||
|
|
||||||
# Run full compilation
|
# Run full compilation
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**************************int DROP_MULTICAST_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct sockaddr_in* pInfo){
|
||||||
|
* UDP Server Dependency *
|
||||||
|
***************************
|
||||||
|
* Designed & Developed by *
|
||||||
|
* Adrien Marquès *
|
||||||
|
* <xdrm-brackets> *
|
||||||
|
***************************
|
||||||
|
* doowap31@gmail.com *
|
||||||
|
**************************/
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int DROP_MULTICAST_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct sockaddr_in* pInfo){
|
||||||
|
|
||||||
|
/* [0] Initialisation des variables
|
||||||
|
=========================================================*/
|
||||||
|
int STATUS; // status
|
||||||
|
struct ip_mreq mcastReq;
|
||||||
|
*pListenSock = -1;
|
||||||
|
struct timeval timeout;
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] Création de la socket
|
||||||
|
=======================================================*/
|
||||||
|
/* 1. Création socket */
|
||||||
|
*pListenSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
|
/* 2. Gestion erreur */
|
||||||
|
if( *pListenSock < 0 ) return -1;
|
||||||
|
|
||||||
|
/* 3. Timeout */
|
||||||
|
timeout.tv_sec = SOCK_TIMEOUT;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
|
if( setsockopt(*pListenSock, SOL_SOCKET, SO_RCVTIMEO|SO_SNDTIMEO, (char*) &timeout, sizeof(struct timeval) ) < 0 ){
|
||||||
|
close(*pListenSock);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] On définit les infos de la socket
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) Reset des valeurs */
|
||||||
|
bzero(pInfo, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
|
/* (2) On définit les infos */
|
||||||
|
pInfo->sin_family = AF_INET;
|
||||||
|
pInfo->sin_port = htons(pPort);
|
||||||
|
pInfo->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
|
|
||||||
|
/* [3] On publie la SOCKET
|
||||||
|
=======================================================*/
|
||||||
|
/* 1. Publication socket */
|
||||||
|
STATUS = bind(*pListenSock, (struct sockaddr*) pInfo, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
|
/* 2. Gestion erreur */
|
||||||
|
if( STATUS < 0 ) return -1;
|
||||||
|
|
||||||
|
/* 3. Demande groupe multicast */
|
||||||
|
mcastReq.imr_multiaddr.s_addr = inet_addr(pAddr);
|
||||||
|
mcastReq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
|
if( setsockopt(*pListenSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcastReq, sizeof(mcastReq)) < 0 ){
|
||||||
|
close(*pListenSock);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [n] Code succès
|
||||||
|
=========================================================*/
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**************************
|
||||||
|
* UDP Server Dependency *
|
||||||
|
***************************
|
||||||
|
* Designed & Developed by *
|
||||||
|
* Adrien Marquès *
|
||||||
|
* <xdrm-brackets> *
|
||||||
|
***************************
|
||||||
|
* doowap31@gmail.com *
|
||||||
|
**************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _LIB_NETWORK_UDP_SERVER_H_
|
||||||
|
#define _LIB_NETWORK_UDP_SERVER_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "../../header.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Créé et met un serveur UDP d'écoute MULTICAST
|
||||||
|
*
|
||||||
|
* ==IN==
|
||||||
|
* @pAddr<const char*> Adresse du groupe multicast UDP
|
||||||
|
* @pPort<const int> Port d'écoute UDP
|
||||||
|
* @pMcast<const char> Si multicast ou non
|
||||||
|
*
|
||||||
|
* ==OUT==
|
||||||
|
* @pListenSocket<int*> Pointeur sur le <int> à remplir => contiendra un pointeur sur la socket d'écoute
|
||||||
|
* @pInfo<sockaddr_in*> Pointeur sur le <sockaddr_n> à remplir => contiendra un pointeur sur les infos server
|
||||||
|
*
|
||||||
|
* ==RETURN==
|
||||||
|
* @status<int> -1 si erreur, sinon 0
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Création de la socket d'écoute
|
||||||
|
* [2] On définit les infos de la socket
|
||||||
|
* [3] On publie la SOCKET (bind)
|
||||||
|
* [n] On renvoie la socket par référence
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int DROP_MULTICAST_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct sockaddr_in* pInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -38,7 +38,7 @@ int open_communication(){
|
||||||
|
|
||||||
/* (1) Création socket multicast
|
/* (1) Création socket multicast
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
if( UDP_SOCKET(&mcast_socket, MCST_HOST, MCST_PORT, &udp) < 0 )
|
if( DROP_MULTICAST_SERVER(MCST_HOST, MCST_PORT, &mcast_socket, &udp) < 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,17 +48,18 @@ int open_communication(){
|
||||||
// memcpy(buffer, numero_vol, sizeof(char)*6);
|
// memcpy(buffer, numero_vol, sizeof(char)*6);
|
||||||
request.flags = BINDHEAD_TCP;
|
request.flags = BINDHEAD_TCP;
|
||||||
strcpy(request.addr, "000.000.000.000");
|
strcpy(request.addr, "000.000.000.000");
|
||||||
request.port = 0;
|
request.port = htons(0);
|
||||||
memcpy(buffer+sizeof(char)*0, &request.flags, sizeof(char));
|
memcpy(buffer+sizeof(char)*0, &request.flags, sizeof(char));
|
||||||
memcpy(buffer+sizeof(char)*1, &request.addr, sizeof(char)*INET_ADDRSTRLEN);
|
memcpy(buffer+sizeof(char)*1, &request.addr, sizeof(char)*INET_ADDRSTRLEN);
|
||||||
memcpy(buffer+sizeof(char)*(1+INET_ADDRSTRLEN), &request.port, sizeof(unsigned short));
|
memcpy(buffer+sizeof(char)*(1+INET_ADDRSTRLEN), &request.port, sizeof(unsigned short));
|
||||||
|
|
||||||
/* 2. Envoi séquence */
|
/* 2. Envoi séquence */
|
||||||
if( sendto(mcast_socket, buffer, BINDHDR_LEN/sizeof(char) +1, 0, (struct sockaddr*) &udp, sizeof(struct sockaddr_in)) < 0 ){
|
// if( sendto(mcast_socket, buffer, BINDHDR_LEN/sizeof(char) +1, 0, (struct sockaddr*) &udp, sizeof(struct sockaddr_in)) < 0 ){
|
||||||
close(mcast_socket);
|
// close(mcast_socket);
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// printf("* sent bind_header{flags = %d; addr = %s; port = %d;}\n", request.flags, request.addr, htons(request.port));
|
||||||
|
|
||||||
/* (3) Attente réponse SGCA -> adresse+port TCP
|
/* (3) Attente réponse SGCA -> adresse+port TCP
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
|
@ -73,6 +74,7 @@ int open_communication(){
|
||||||
|
|
||||||
/* 3. Vérification taille */
|
/* 3. Vérification taille */
|
||||||
if( status < BINDHDR_LEN ){
|
if( status < BINDHDR_LEN ){
|
||||||
|
printf("%d / %d\n", status, (int) BINDHDR_LEN);
|
||||||
close(mcast_socket);
|
close(mcast_socket);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +86,7 @@ int open_communication(){
|
||||||
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*INET_ADDRSTRLEN );
|
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*INET_ADDRSTRLEN );
|
||||||
memcpy(&request.port, buffer+sizeof(char)*(1+INET_ADDRSTRLEN), sizeof(unsigned short) );
|
memcpy(&request.port, buffer+sizeof(char)*(1+INET_ADDRSTRLEN), sizeof(unsigned short) );
|
||||||
|
|
||||||
printf("bind_header{flags = %d; addr = %s; port = %d;}\n\n", request.flags, request.addr, request.port);
|
printf("* received bind_header{flags = %d; addr = %s; port = %d;}\n\n", request.flags, request.addr, request.port);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "lib/header.h"
|
#include "lib/header.h"
|
||||||
#include "lib/network/udp/client.h"
|
#include "lib/network/udp/server.h"
|
||||||
#include "lib/network/tcp/client.h"
|
#include "lib/network/tcp/client.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue