Reference #7 + minmod

This commit is contained in:
xdrm-brackets 2017-04-06 20:08:45 +02:00
parent 0009aa269a
commit 8cc7dcf06c
8 changed files with 66 additions and 27 deletions

View File

@ -156,7 +156,7 @@ void* LISTEN_UDP(){
int CLIENT_SOCKET; // contiendra la socket UDP à envoyer sur un THREAD
struct sockaddr_in serverInfo; // contiendra les infos serveur
struct sockaddr_in clientInfo; // contiendra les infos client
char client_ip[20]; // IP du client
char client_ip[INET_ADDRSTRLEN]; // IP (string) du client
socklen_t len; // taille de la socket
int read; // compteurs
char buffer[MAX_BUF_LEN]; // buffer requête
@ -187,28 +187,28 @@ void* LISTEN_UDP(){
============================================================================*/
while( 1 ){
/* 0. On initialise les SOCKET en attendant la connexion et le rang du "manager" inactif */
/* 0. On initialise les SOCKET en attendant la connexion d'un client */
CLIENT_SOCKET = -1;
index = -1;
/* 1. On attends une connection UDP */
read = recvfrom(SOCKET, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
/* 2. Si erreur reception ou taille incorrecte */
/* 2. Si erreur reception ou taille incorrecte -> retour à l'écoute */
if( read != sizeof(char)+sizeof(unsigned short) ){
if( DEBUGMOD&BUF ) printf("[main][UDP_LISTEN_THREAD] read('%s') = %d bytes (expected: %d)\n", buffer, read, (int) (sizeof(char)+sizeof(unsigned short)) );
continue;
}
/* 3. On récupère l'adresse IP du client */
inet_ntop(AF_INET, &(clientInfo.sin_addr), client_ip, 20);
inet_ntop(AF_INET, &clientInfo.sin_addr, client_ip, INET_ADDRSTRLEN);
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] '%s' connecté\n", client_ip);
/* 4. On parse la requête*/
memcpy(&request, buffer, sizeof(struct bind_header));
printf("[main][UDP_LISTEN_THREAD] received: {flag = %d; port = %d}\n", (int) request.flags, request.port);
/* 4. On parse la requête */
memcpy(&request.flags, buffer, sizeof(char));
memcpy(&request.port, buffer+sizeof(char), sizeof(unsigned short));
printf("[main][UDP_LISTEN_THREAD] received: bind_header{flag = %d; port = %d}\n", (int) request.flags, request.port);
/* 5 Si on veut un port de communicatin */
if( request.flags&BINDHEAD_PRT ){
@ -242,20 +242,26 @@ void* LISTEN_UDP(){
request.flags -= BINDHEAD_PRT;
// Si on a le port -> on le met dans la reponse
}else
request.port = serverInfo.sin_port;
}else{
request.port = htons(serverInfo.sin_port);
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] Comm. socket is on port %d\n", request.port);
}
}
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] { port: %d }\n", serverInfo.sin_port);
/* 8. On envoie la réponse */
memcpy(buffer, &request, sizeof(struct bind_header));
if( send(SOCKET, buffer, strlen(buffer), 0) < 0 ){
bzero(buffer, MAX_BUF_LEN);
memcpy(buffer, &request.flags, sizeof(char));
memcpy(buffer+sizeof(char), &request.port, sizeof(unsigned short));
if( send(SOCKET, buffer, sizeof(char)+sizeof(unsigned short), 0) < 0 ){
printf("[main][UDP_LISTEN_THREAD] Impossible de répondre au client!\n");
continue;
}
printf("[main][UDP_LISTEN_THREAD] sent: bind_header{flag = %d; port = %d}\n", (int) request.flags, request.port);

View File

@ -0,0 +1,10 @@
#!/bin/bash
# [1] Create service target (boot)
sudo ln -s $(pwd)/sgca /usr/sbin/sgca;
# [2] Create service unit
sudo ln -s $(pwd)/sgca.service /lib/systemd/system/sgca.service;
# [3] Enable service (optional if no [Install])
sudo systemctl enable sgca.service;

3
central-manager/install/sgca Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
/home/xdrm-brackets/Desktop/git.xdrm.io/sysdis-project/central-manager/boot >> $1 2>&1;

View File

@ -0,0 +1,10 @@
[Unit]
Description=Systeme de Gestion du Controle Aerien
Requires=network.target
[Service]
Type=simple
User=xdrm-brackets
Group=xdrm-brackets
ExecStart=/usr/sbin/sgca /var/log/sgca

View File

@ -0,0 +1,11 @@
#!/bin/bash
# [1] Remove service target (boot)
sudo rm /usr/sbin/sgca;
# [2] Disable service
sudo systemctl disable sgca.service;
# [3] Remove service unit
sudo rm /lib/systemd/system/sgca.service;

View File

@ -23,7 +23,7 @@ int DROP_TCP_SERVER(const int pPort, int* pListenSock){
=======================================================*/
*pListenSock = socket(AF_INET, SOCK_STREAM, 0);
if( DEBUGMOD&SCK ) printf("\t\tTCP SOCKET = %d\n", *pListenSock);
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server SOCKET = %d\n", *pListenSock);
// si erreur
if( *pListenSock < 0 ) return -1;
@ -44,7 +44,7 @@ int DROP_TCP_SERVER(const int pPort, int* pListenSock){
=======================================================*/
STATUS = bind(*pListenSock, (struct sockaddr*) &addr, sizeof(addr));
if( DEBUGMOD&SCK ) printf("\t\tTCP BIND = %d\n", STATUS);
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server BIND = %d\n", STATUS);
// si erreur
if( STATUS < 0 ) return -1;
@ -54,7 +54,7 @@ int DROP_TCP_SERVER(const int pPort, int* pListenSock){
=======================================================*/
STATUS = listen(*pListenSock, MAX_TCP_THR);
if( DEBUGMOD&SCK ) printf("\t\tTCP LISTEN = %d\n", STATUS);
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server LISTEN = %d\n", STATUS);
// si erreur
if( STATUS < 0 ) return -1;

View File

@ -23,7 +23,7 @@ int DROP_UDP_SERVER(const int pPort, int* pListenSock){
=======================================================*/
*pListenSock = socket(AF_INET, SOCK_DGRAM, 0);
if( DEBUGMOD&SCK ) printf("\t\tUDP SOCKET = %d\n", *pListenSock);
if( DEBUGMOD&SCK ) printf(" * /lib/udp/server/drop_udp_server SOCKET = %d\n", *pListenSock);
// si erreur
if( *pListenSock < 0 ) return -1;
@ -44,7 +44,7 @@ int DROP_UDP_SERVER(const int pPort, int* pListenSock){
=======================================================*/
STATUS = bind(*pListenSock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
if( DEBUGMOD&SCK ) printf("\t\tUDP BIND = %d\n", STATUS);
if( DEBUGMOD&SCK ) printf(" * /lib/udp/server/drop_udp_server BIND = %d\n", STATUS);
// si erreur
if( STATUS < 0 ) return -1;

View File

@ -1 +0,0 @@
../../../plane/plane.h