Reference #4 Reference #3 Gestion 2 serveurs UDP pour `vterm`/`cterm` reste à faire le UDP multicast + dispatch socket random udp fonctionne
This commit is contained in:
parent
8cc7dcf06c
commit
b751266152
|
@ -5,6 +5,7 @@
|
|||
"slist": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"utility": "cpp",
|
||||
"functional": "cpp"
|
||||
"functional": "cpp",
|
||||
"system_error": "cpp"
|
||||
}
|
||||
}
|
|
@ -14,26 +14,39 @@
|
|||
*/
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
printf("Execution tree structure\n");
|
||||
printf("[procedureName]\n");
|
||||
printf("{threadName}\n");
|
||||
printf("[parent]{child}[subchild] Description\n\n\n");
|
||||
|
||||
|
||||
/* [1] Lancement des THREADS d'écoute
|
||||
=========================================================*/
|
||||
/* (1) Ecoute TCP */
|
||||
pthread_create(&listenManagers[0], NULL, LISTEN_TCP, NULL);
|
||||
if( DEBUGMOD&THR ) printf("[main][TCP_LISTEN_THREAD] démarré\n");
|
||||
pthread_create(&listenManagers[0], NULL, LISTEN_TCP, (void*)(intptr_t) TCP_LIST);
|
||||
if( DEBUGMOD&THR ) printf("{tcp_listen} démarré\n");
|
||||
|
||||
/* (2) Ecoute UDP */
|
||||
pthread_create(&listenManagers[1], NULL, LISTEN_UDP, NULL);
|
||||
if( DEBUGMOD&THR ) printf("[main][UDP_LISTEN_THREAD] démarré\n");
|
||||
/* (2) Ecoute UDP multicast */
|
||||
// pthread_create(&listenManagers[1], NULL, LISTEN_UDP, (void*)(intptr_t) TCP_);
|
||||
// if( DEBUGMOD&THR ) printf("{udp_mcas émarré\n\n");
|
||||
|
||||
/* (3) Ecoute UDP viewTerm */
|
||||
pthread_create(&listenManagers[2], NULL, LISTEN_UDP, (void*)(intptr_t) UDP_VTER);
|
||||
if( DEBUGMOD&THR ) printf("{udp_vterm} démarré\n");
|
||||
|
||||
/* (4) Ecoute UDP ctrlTerm */
|
||||
pthread_create(&listenManagers[3], NULL, LISTEN_UDP, (void*)(intptr_t) UDP_CTER);
|
||||
if( DEBUGMOD&THR ) printf("{udp_cterm} démarré\n");
|
||||
|
||||
|
||||
/* [2] On attends la fin de tous les THREADS
|
||||
==========================================================*/
|
||||
pthread_join(listenManagers[0], NULL);
|
||||
pthread_join(listenManagers[1], NULL);
|
||||
for( char i = 0 ; i < 4 ; i++ )
|
||||
pthread_join(listenManagers[(int)i], NULL);
|
||||
|
||||
/* [3] On ferme la SOCKET d'écoute globale
|
||||
==========================================================*/
|
||||
printf("[main] FERMETURE DE TOUTES LES CONNECTIONS!\n");
|
||||
printf("FERMETURE DE TOUTES LES CONNECTIONS!\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,19 +78,19 @@ void* LISTEN_TCP(){
|
|||
|
||||
/* [1] On démarre le SERVEUR TCP d'écoute globale
|
||||
==========================================================*/
|
||||
if( DROP_TCP_SERVER(TCP_PORT, &LISTENSOCK) < 0 ){
|
||||
if( DROP_TCP_SERVER(TCP_LIST, &LISTENSOCK) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("\tErreur de mise en place de la socket d'écoute TCP\n");
|
||||
if( DEBUGMOD&SCK ) printf("{tcp_listen} Erreur création socket d'écoute\n");
|
||||
|
||||
// On ferme la SOCKET d'écoute globale
|
||||
printf("\tFERMETURE DE L'ECOUTE TCP!\n");
|
||||
printf("{tcp_listen} FERMETURE SOCKET D'ECOUTE TCP!\n");
|
||||
close(LISTENSOCK);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
printf("[main][TCP_LISTEN_THREAD] Listen Port: %d\n", TCP_PORT);
|
||||
printf("{tcp_listen} Port écoute: %d\n", TCP_LIST);
|
||||
|
||||
|
||||
|
||||
|
@ -94,7 +107,7 @@ void* LISTEN_TCP(){
|
|||
|
||||
/* 3. Si erreur, on attend une nouvelle connection */
|
||||
if( CLIENT_SOCKET < 0 ){
|
||||
if( DEBUGMOD&SCK ) printf("[main][TCP_LISTEN_THREAD] Erreur connection\n");
|
||||
if( DEBUGMOD&SCK ) printf("{tcp_listen} accept: Erreur connection\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -108,13 +121,13 @@ void* LISTEN_TCP(){
|
|||
/* 5. On lance un thread pour le traitement de ce client */
|
||||
pthread_create(&TCPManagers[index], NULL, managePlane, (void*)(intptr_t) CLIENT_SOCKET);
|
||||
|
||||
if( DEBUGMOD&THR ) printf("[main][TCP_LISTEN_THREAD][COM_THREAD][%d] démarré\n", index);
|
||||
if( DEBUGMOD&THR ) printf("{tcp_listen}{com}(%d) démarré\n", index);
|
||||
|
||||
/* 6. On signale que ce "manager" est maintenant actif */
|
||||
activeTCPManagers[index] = 1;
|
||||
|
||||
}else
|
||||
if( DEBUGMOD&THR ) printf("[main][TCP_LISTEN_THREAD] Aucun thread libre!\n");
|
||||
if( DEBUGMOD&THR ) printf("{tcp_listen} Aucun thread libre\n");
|
||||
|
||||
}
|
||||
|
||||
|
@ -124,9 +137,10 @@ void* LISTEN_TCP(){
|
|||
for( i = 0 ; i < MAX_TCP_THR ; i++ )
|
||||
pthread_join(TCPManagers[i], NULL);
|
||||
|
||||
|
||||
/* [4] On ferme la SOCKET d'écoute globale
|
||||
==========================================================*/
|
||||
printf("[main][TCP_LISTEN_THREAD] FERMETURE DE L'ECOUTE TCP!\n");
|
||||
printf("{tcp_listen} FERMETURE SOCKET D'ECOUTE TCP!\n");
|
||||
close(LISTENSOCK);
|
||||
|
||||
return NULL;
|
||||
|
@ -150,36 +164,39 @@ void* LISTEN_TCP(){
|
|||
* [6] On démarre un thread de gestion avec timeout (en attente du client redirigé)
|
||||
*
|
||||
*/
|
||||
void* LISTEN_UDP(){
|
||||
void* LISTEN_UDP(void* THREADABLE_PORT){
|
||||
/* [0] Initialisation des variables
|
||||
==========================================================*/
|
||||
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[INET_ADDRSTRLEN]; // IP (string) du client
|
||||
socklen_t len; // taille de la socket
|
||||
int read; // compteurs
|
||||
char buffer[MAX_BUF_LEN]; // buffer requête
|
||||
struct bind_header request; // requête parsée
|
||||
int i, index; // compteurs
|
||||
int CLIENT_SOCKET; // contiendra la socket UDP à envoyer sur un THREAD
|
||||
struct sockaddr_in listenInfo; // contiendra les infos de la socket LISTEN
|
||||
struct sockaddr_in comInfo; // contiendra les infos de la socket COM
|
||||
struct sockaddr_in clientInfo; // contiendra les infos 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
|
||||
struct bind_header request; // requête parsée
|
||||
int i, index; // compteurs
|
||||
int UDP_PORT = (intptr_t) THREADABLE_PORT; // Port serveur
|
||||
char xterm = (UDP_PORT==UDP_VTER) ? 'v' : 'c'; // terminal type identifier
|
||||
|
||||
// retour de @DROP_UDP_SERVER
|
||||
int SOCKET;
|
||||
|
||||
/* [1] On démarre le SERVEUR UDP d'écoute globale
|
||||
==========================================================*/
|
||||
if( DROP_UDP_SERVER(UDP_PORT, &SOCKET) < 0 ){
|
||||
if( DROP_UDP_SERVER(UDP_PORT, &SOCKET, &listenInfo) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] Erreur de mise en place de la socket d'écoute\n");
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de création socket d'écoute\n", xterm);
|
||||
|
||||
// On ferme la SOCKET d'écoute globale
|
||||
printf("[main][UDP_LISTEN_THREAD] FERMETURE DE LA SOCKET D'ECOUTE UDP!\n");
|
||||
printf("{udp_%cterm} FERMETURE SOCKET D'ECOUTE UDP!\n", xterm);
|
||||
close(SOCKET);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("[main][UDP_LISTEN_THREAD] Listen Port: %d\n", UDP_PORT);
|
||||
printf("{udp_%cterm} Listen Port: %d\n", xterm, UDP_PORT);
|
||||
|
||||
|
||||
|
||||
|
@ -192,31 +209,32 @@ void* LISTEN_UDP(){
|
|||
index = -1;
|
||||
|
||||
/* 1. On attends une connection UDP */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
read = recvfrom(SOCKET, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
||||
|
||||
/* 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)) );
|
||||
if( read < BINDHDR_LEN ){
|
||||
if( DEBUGMOD&BUF ) printf("{udp_%cterm} read('%s') = %d bytes (expected: %d)\n", xterm, buffer, read, (int) (BINDHDR_LEN) );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 3. On récupère l'adresse IP du client */
|
||||
inet_ntop(AF_INET, &clientInfo.sin_addr, client_ip, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &(clientInfo.sin_addr), client_ip, INET_ADDRSTRLEN);
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] '%s' connecté\n", client_ip);
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} '%s' connecté\n", xterm, client_ip);
|
||||
|
||||
/* 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);
|
||||
printf("{udp_%cterm} received: bind_header{flag = %d; port = %d}\n", xterm, (int) request.flags, request.port);
|
||||
|
||||
/* 5 Si on veut un port de communicatin */
|
||||
if( request.flags&BINDHEAD_PRT ){
|
||||
|
||||
/* 5.1 On bind une socket sur un port random */
|
||||
if( DROP_UDP_SERVER(0, &CLIENT_SOCKET) < 0 ){
|
||||
if( DROP_UDP_SERVER(0, &CLIENT_SOCKET, &comInfo) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] Erreur de création de la socket COM\n");
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de création de la socket COM\n", xterm);
|
||||
|
||||
// On ferme la SOCKET CLIENT
|
||||
close(CLIENT_SOCKET);
|
||||
|
@ -232,9 +250,9 @@ void* LISTEN_UDP(){
|
|||
|
||||
/* On récupère le port de la socket de communication */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( getsockname(CLIENT_SOCKET, (struct sockaddr*) &serverInfo, &len) < 0 ){
|
||||
if( getsockname(CLIENT_SOCKET, (struct sockaddr*) &comInfo, &len) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] Erreur de recherche du port COM ouvert\n");
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de recherche du port COM ouvert\n", xterm);
|
||||
|
||||
close(CLIENT_SOCKET);
|
||||
|
||||
|
@ -243,8 +261,8 @@ void* LISTEN_UDP(){
|
|||
|
||||
// Si on a le port -> on le met dans la reponse
|
||||
}else{
|
||||
request.port = htons(serverInfo.sin_port);
|
||||
if( DEBUGMOD&SCK ) printf("[main][UDP_LISTEN_THREAD] Comm. socket is on port %d\n", request.port);
|
||||
request.port = htons(comInfo.sin_port);
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm}{udp_com} Comm. socket is on port %d\n", xterm, request.port);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -255,34 +273,33 @@ void* LISTEN_UDP(){
|
|||
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");
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( sendto(SOCKET, buffer, BINDHDR_LEN/sizeof(char) + 1, 0, (struct sockaddr*) &clientInfo, len) < 0 ){
|
||||
printf("{udp_%cterm} Impossible de répondre au client!\n", xterm);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("[main][UDP_LISTEN_THREAD] sent: bind_header{flag = %d; port = %d}\n", (int) request.flags, request.port);
|
||||
printf("{udp_%cterm} sent: bind_header{flag = %d; port = %d}\n", xterm, (int) request.flags, request.port);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* 4. On cherche un "manager" libre (inactif) */
|
||||
/* 9. On cherche un "manager" libre (inactif) */
|
||||
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
||||
if( activeUDPManagers[i] == 0 ){ index = i; break; }
|
||||
|
||||
// si on a trouvé un "manager" libre
|
||||
if( index != -1 ){
|
||||
|
||||
/* 5. On lance un thread pour le traitement de ce client */
|
||||
/* 9.1. On lance un thread pour le traitement de ce client */
|
||||
pthread_create(&UDPManagers[index], NULL, manageTerminal, (void*)(intptr_t) CLIENT_SOCKET);
|
||||
|
||||
if( DEBUGMOD&THR ) printf("[main][UDP_LISTEN_THREAD][COM_THREAD][%d] démarré\n", index);
|
||||
if( DEBUGMOD&THR ) printf("{udp_%cterm}{udp_com}(%d) démarré\n", xterm, index);
|
||||
|
||||
/* 6. On signale que ce "manager" est maintenant actif */
|
||||
/* 9.2. On signale que ce "manager" est maintenant actif */
|
||||
activeUDPManagers[index] = 1;
|
||||
|
||||
}else
|
||||
if( DEBUGMOD&THR ) printf("[main][UDP_LISTEN_THREAD] Aucun thread UDP libre!\n");
|
||||
if( DEBUGMOD&THR ) printf("{udp_%cterm} Aucun thread UDP libre!\n", xterm);
|
||||
|
||||
}
|
||||
|
||||
|
@ -290,7 +307,7 @@ void* LISTEN_UDP(){
|
|||
|
||||
/* [n] On ferme la SOCKET d'écoute globale
|
||||
==========================================================*/
|
||||
printf("[main][UDP_LISTEN_THREAD] FERMETURE DE LA SOCKET UDP!\n");
|
||||
printf("{udp_%cterm} FERMETURE SOCKET D'ECOUTE UDP!\n", xterm);
|
||||
close(SOCKET);
|
||||
|
||||
return NULL;
|
||||
|
@ -407,7 +424,7 @@ void* manageTerminal(void* THREADABLE_SOCKET){
|
|||
|
||||
do{
|
||||
|
||||
printf("[main][UDP_LISTEN_THREAD][COM_THREAD] waiting for terminal request\n");
|
||||
printf("{udp_x-term}{udp_com} waiting for terminal request\n");
|
||||
/* [2] Récupération de la requête
|
||||
=========================================================*/
|
||||
/* 1. On lit sur la socket */
|
||||
|
@ -415,13 +432,13 @@ void* manageTerminal(void* THREADABLE_SOCKET){
|
|||
read = recvfrom(UDP_SOCKET, request, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
||||
|
||||
/* 2. Si erreur reception */
|
||||
if( DEBUGMOD&BUF ) printf("[main][UDP_LISTEN_THREAD][COM_THREAD] READ = %d\n", read);
|
||||
if( DEBUGMOD&BUF ) printf("{udp_x-term}{udp_com} READ = %d\n", read);
|
||||
|
||||
if( read < 0 )
|
||||
continue;
|
||||
|
||||
/* 3. On désérialise la requête*/
|
||||
printf("[main][UDP_LISTEN_THREAD][COM_THREAD] TERMINAL Request(%d bytes) : '%s'\n", read, request);
|
||||
printf("{udp_x-term}{udp_com} TERMINAL Request(%d bytes) : '%s'\n", read, request);
|
||||
|
||||
/* [3] Gestion de la requête
|
||||
=========================================================*/
|
||||
|
@ -439,14 +456,17 @@ void* manageTerminal(void* THREADABLE_SOCKET){
|
|||
============================================================================*/
|
||||
/* 1. On récupère le rang dans les "managers" */
|
||||
int i, index = -1;
|
||||
for( i = 0 ; i < MAX_TCP_THR ; i++ )
|
||||
if( TCPManagers[i] == pthread_self() ){ index = i; break; }
|
||||
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
||||
if( UDPManagers[i] == pthread_self() ){ index = i; break; }
|
||||
|
||||
/* 2. On met à jour "activeManagers" */
|
||||
if( index != -1 )
|
||||
activeTCPManagers[index] = 0;
|
||||
activeUDPManagers[index] = 0;
|
||||
|
||||
/* 3. On arrête le THREAD */
|
||||
if( DEBUGMOD&THR ) printf("[main][UDP_LISTEN_THREAD][COM_THREAD][%d] libéré\n", index);
|
||||
if( DEBUGMOD&THR ) printf("{udp_x-term}{udp_com}(%d) libéré\n", index);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,14 +9,20 @@
|
|||
|
||||
/* headers */
|
||||
void* LISTEN_TCP();
|
||||
void* LISTEN_UDP();
|
||||
void* LISTEN_UDP(void* THREADABLE_PORT);
|
||||
void* managePlane(void* THREADABLE_SOCKET);
|
||||
void* manageTerminal(void* THREADABLE_SOCKET);
|
||||
// void* manageViewTerm(void* THREADABLE_SOCKET);
|
||||
// void* manageCtrlTerm(void* THREADABLE_SOCKET);
|
||||
|
||||
|
||||
|
||||
// VARIABLES THREADS D'ECOUTE TCP/UDP
|
||||
static pthread_t listenManagers[2]; // contiendra les THREADS d'écoute
|
||||
static pthread_t listenManagers[4]; // contiendra les THREADS d'écoute
|
||||
// 1. Multicast UDP (plane)
|
||||
// 2. ListenSock TCP (plane)
|
||||
// 3. ListenSock UDP (vterm)
|
||||
// 4. ListenSock UDP (cterm)
|
||||
|
||||
// VARIABLES THREADS CONNECTION TCP
|
||||
static pthread_t TCPManagers[MAX_TCP_THR]; // contiendra les THREADS TCP
|
||||
|
|
|
@ -20,10 +20,17 @@
|
|||
struct plane udpate;
|
||||
};
|
||||
|
||||
struct term_res{
|
||||
char flags;
|
||||
char n;
|
||||
struct plane* data;
|
||||
};
|
||||
|
||||
|
||||
#define BINDHEAD_CTL 0x01
|
||||
#define BINDHEAD_PRT 0x02
|
||||
|
||||
#define BINDHDR_LEN sizeof(char)+sizeof(unsigned short)
|
||||
struct bind_header{
|
||||
char flags;
|
||||
unsigned short port;
|
||||
|
|
|
@ -24,9 +24,12 @@
|
|||
#include "data.h"
|
||||
|
||||
/* vars */
|
||||
#define SRV_HOST "localhost"
|
||||
#define TCP_PORT 4444
|
||||
#define UDP_PORT 4444
|
||||
#define SRV_HOST "127.0.0.1"
|
||||
#define UDP_MCST 4444 // multicast UDP port for PLANES
|
||||
#define TCP_LIST 0x504c // TCP plane command (PL = 8076)
|
||||
|
||||
#define UDP_VTER 4445 // viewTerm listener
|
||||
#define UDP_CTER 4446 // ctrlTerm listener
|
||||
|
||||
#define MAX_BUF_LEN 512
|
||||
#define MAX_TCP_THR 10
|
||||
|
|
|
@ -23,7 +23,7 @@ int DROP_TCP_SERVER(const int pPort, int* pListenSock){
|
|||
=======================================================*/
|
||||
*pListenSock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server SOCKET = %d\n", *pListenSock);
|
||||
if( DEBUGMOD&SCK ) printf(" * [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(" * /lib/tcp/server/drop_tcp_server BIND = %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK ) printf(" * [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(" * /lib/tcp/server/drop_tcp_server LISTEN = %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK ) printf(" * [drop_tcp_server] listen: %d\n", STATUS);
|
||||
|
||||
// si erreur
|
||||
if( STATUS < 0 ) return -1;
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
|
||||
|
||||
|
||||
int DROP_UDP_SERVER(const int pPort, int* pListenSock){
|
||||
int DROP_UDP_SERVER(const int pPort, int* pListenSock, struct sockaddr_in* pInfo){
|
||||
if( DEBUGMOD&HDR ) printf("====== DROP_UDP_SERVER(%d, %p) ======\n\n", pPort, (void*) pListenSock);
|
||||
|
||||
/* [0] Initialisation des variables
|
||||
=========================================================*/
|
||||
// CREATION
|
||||
struct sockaddr_in addr;
|
||||
int STATUS; // status
|
||||
|
||||
// INITIALISATION
|
||||
|
@ -23,7 +22,7 @@ int DROP_UDP_SERVER(const int pPort, int* pListenSock){
|
|||
=======================================================*/
|
||||
*pListenSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if( DEBUGMOD&SCK ) printf(" * /lib/udp/server/drop_udp_server SOCKET = %d\n", *pListenSock);
|
||||
if( DEBUGMOD&SCK ) printf(" * [drop_udp_server] socket: %d\n", *pListenSock);
|
||||
|
||||
// si erreur
|
||||
if( *pListenSock < 0 ) return -1;
|
||||
|
@ -32,19 +31,19 @@ int DROP_UDP_SERVER(const int pPort, int* pListenSock){
|
|||
/* [2] On définit les infos de la socket
|
||||
=========================================================*/
|
||||
/* (1) Reset des valeurs */
|
||||
bzero(&addr, sizeof(struct sockaddr_in));
|
||||
bzero(pInfo, sizeof(struct sockaddr_in));
|
||||
|
||||
/* (2) On définit les infos */
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(pPort);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
pInfo->sin_family = AF_INET;
|
||||
pInfo->sin_port = htons(pPort);
|
||||
pInfo->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
|
||||
/* [3] On publie la SOCKET
|
||||
=======================================================*/
|
||||
STATUS = bind(*pListenSock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in));
|
||||
STATUS = bind(*pListenSock, (struct sockaddr*) pInfo, sizeof(struct sockaddr_in));
|
||||
|
||||
if( DEBUGMOD&SCK ) printf(" * /lib/udp/server/drop_udp_server BIND = %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK ) printf(" * [drop_udp_server] bind: %d\n", STATUS);
|
||||
|
||||
// si erreur
|
||||
if( STATUS < 0 ) return -1;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* [n] On renvoie la socket par référence
|
||||
*
|
||||
*/
|
||||
int DROP_UDP_SERVER(const int pPort, int* pListenSock);
|
||||
int DROP_UDP_SERVER(const int pPort, int* pListenSock, struct sockaddr_in* pInfo);
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue