[done] Passed all UDP terminal dispatchers to MULTICAST (224.0.0.2:4445 and 224.0.0.3:4446) to remove broadcast needs.[todo]{ udp multicast for plane + plane comm }
This commit is contained in:
parent
ab0fea9a14
commit
0c641726a8
|
@ -28,22 +28,28 @@ int main(int argc, char* argv[]){
|
|||
sgca_index.data = 0;
|
||||
sgca_index.update = 0;
|
||||
|
||||
/* Variables locales */
|
||||
struct listn_thrd_arg tcp_listn_arg = { SERV_HOST, TCP_LIST };
|
||||
struct listn_thrd_arg udp_vterm_arg = { MCST_VTER, UDP_VTER };
|
||||
struct listn_thrd_arg udp_cterm_arg = { MCST_CTER, UDP_CTER };
|
||||
|
||||
|
||||
/* [1] Lancement des THREADS d'écoute
|
||||
=========================================================*/
|
||||
/* (1) Ecoute TCP */
|
||||
pthread_create(&listenManagers[0], NULL, LISTEN_TCP, (void*)(intptr_t) TCP_LIST);
|
||||
pthread_create(&listenManagers[0], NULL, LISTEN_TCP, (void*) &tcp_listn_arg);
|
||||
if( DEBUGMOD&THR ) printf("{tcp_listn} 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");
|
||||
// pthread_create(&listenManagers[1], NULL, LISTEN_UDP, (void*)(intptr_t) UDP_MCST);
|
||||
// if( DEBUGMOD&THR ) printf("{udp_mcast} émarré\n\n");
|
||||
|
||||
/* (3) Ecoute UDP viewTerm */
|
||||
pthread_create(&listenManagers[2], NULL, LISTEN_UDP, (void*)(intptr_t) UDP_VTER);
|
||||
pthread_create(&listenManagers[2], NULL, LISTEN_UDP, (void*) &udp_vterm_arg);
|
||||
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);
|
||||
pthread_create(&listenManagers[3], NULL, LISTEN_UDP, (void*) &udp_cterm_arg);
|
||||
if( DEBUGMOD&THR ) printf("{udp_cterm} démarré\n");
|
||||
|
||||
|
||||
|
@ -74,14 +80,14 @@ int main(int argc, char* argv[]){
|
|||
* [4] On ferme la SOCKET d'écoute TCP globale
|
||||
*
|
||||
*/
|
||||
void* LISTEN_TCP(void* THREADABLE_PORT){
|
||||
void* LISTEN_TCP(void* THREADABLE_ARG){
|
||||
/* [0] Initialisation des variables
|
||||
==========================================================*/
|
||||
int CLIENT_SOCKET; // contiendra la socket TCP à envoyer sur un THREAD
|
||||
struct sockaddr_in clientInfo; // contiendra les infos client
|
||||
socklen_t len; // taille de la socket
|
||||
int index, i; // compteurs
|
||||
int TCP_PORT = (intptr_t) THREADABLE_PORT; // Port serveur
|
||||
int CLIENT_SOCKET; // contiendra la socket TCP à envoyer sur un THREAD
|
||||
struct sockaddr_in clientInfo; // contiendra les infos client
|
||||
socklen_t len; // taille de la socket
|
||||
int index, i; // compteurs
|
||||
struct listn_thrd_arg* arg = THREADABLE_ARG; // Addr + Port serveur
|
||||
|
||||
|
||||
// retour de @DROP_TCP_SERVER
|
||||
|
@ -90,7 +96,7 @@ void* LISTEN_TCP(void* THREADABLE_PORT){
|
|||
|
||||
/* [1] On démarre le SERVEUR TCP d'écoute globale
|
||||
==========================================================*/
|
||||
if( DROP_TCP_SERVER(TCP_PORT, &LISTENSOCK) < 0 ){
|
||||
if( DROP_TCP_SERVER(arg->port, &LISTENSOCK) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{tcp_listn} Erreur création socket d'écoute\n");
|
||||
|
||||
|
@ -102,7 +108,8 @@ void* LISTEN_TCP(void* THREADABLE_PORT){
|
|||
}
|
||||
|
||||
|
||||
printf("{tcp_listn} port: %d\n", TCP_PORT);
|
||||
|
||||
printf("{tcp_listn} listen on %s:%d\n", arg->addr, arg->port);
|
||||
|
||||
|
||||
|
||||
|
@ -181,21 +188,23 @@ void* LISTEN_TCP(void* THREADABLE_PORT){
|
|||
* [N] On ferme la SOCKET d'écoute globale
|
||||
*
|
||||
*/
|
||||
void* LISTEN_UDP(void* THREADABLE_PORT){
|
||||
void* LISTEN_UDP(void* THREADABLE_ARG){
|
||||
/* [0] Initialisation des variables
|
||||
==========================================================*/
|
||||
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
|
||||
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
|
||||
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
|
||||
struct listn_thrd_arg* arg = THREADABLE_ARG; // Addr + Port serveur
|
||||
char entity[9+1];
|
||||
|
||||
if( strcmp(arg->addr, MCST_VTER) == 0 && arg->port == UDP_VTER ) strcpy(entity, "udp_vterm");
|
||||
else strcpy(entity, "udp_cterm");
|
||||
|
||||
// retour de @DROP_UDP_SERVER
|
||||
int SOCKET;
|
||||
|
@ -203,18 +212,18 @@ void* LISTEN_UDP(void* THREADABLE_PORT){
|
|||
|
||||
/* [1] On démarre le SERVEUR UDP d'écoute globale
|
||||
==========================================================*/
|
||||
if( DROP_UDP_SERVER(UDP_PORT, &SOCKET, &listenInfo) < 0 ){
|
||||
if( DROP_UDP_SERVER(arg->addr, arg->port, &SOCKET, &listenInfo, strcmp(arg->addr, SERV_HOST) != 0) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de création socket d'écoute\n", xterm);
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de création socket d'écoute\n", entity);
|
||||
|
||||
// On ferme la SOCKET d'écoute globale
|
||||
printf("{udp_%cterm} FERMETURE SOCKET D'ECOUTE UDP!\n", xterm);
|
||||
printf("{%s} FERMETURE SOCKET D'ECOUTE UDP!\n", entity);
|
||||
close(SOCKET);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("{udp_%cterm} port: %d\n", xterm, UDP_PORT);
|
||||
printf("{%s} listen on %s:%d\n", entity, arg->addr, arg->port);
|
||||
|
||||
|
||||
|
||||
|
@ -232,60 +241,60 @@ void* LISTEN_UDP(void* THREADABLE_PORT){
|
|||
|
||||
/* 2. Si erreur reception ou taille incorrecte -> retour à l'écoute */
|
||||
if( read < BINDHDR_LEN ){
|
||||
if( DEBUGMOD&BUF ) printf("{udp_%cterm} read('%s') = %d bytes (expected: %d)\n", xterm, buffer, read, (int) (BINDHDR_LEN) );
|
||||
if( DEBUGMOD&BUF ) printf("{%s} read('%s') = %d bytes (expected: %d)\n", entity, 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);
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} '%s' connecté\n", xterm, client_ip);
|
||||
if( DEBUGMOD&SCK ) printf("{%s} '%s' connecté\n", entity, inet_ntoa(clientInfo.sin_addr));
|
||||
|
||||
|
||||
|
||||
/* [3] Gestion de la requête
|
||||
=========================================================*/
|
||||
/* 1. On parse la requête */
|
||||
memcpy(&request.flags, buffer, sizeof(char));
|
||||
memcpy(&request.port, buffer+sizeof(char), sizeof(unsigned short));
|
||||
printf("{udp_%cterm} received: bind_header{flag = %d; port = %d}\n", xterm, (int) request.flags, request.port);
|
||||
memcpy(&request.flags, buffer, sizeof(char));
|
||||
memcpy(&request.addr, buffer+sizeof(char), sizeof(char)*15);
|
||||
memcpy(&request.port, buffer+sizeof(char)*16, sizeof(unsigned short));
|
||||
printf("{%s} received: bind_header{flag = %d; addr = '%s'; port = %d}\n", entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
/* 2. Si on veut un port de communicatin */
|
||||
if( request.flags&BINDHEAD_PRT ){
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* 2.1 On bind une socket sur un port random */
|
||||
if( DROP_UDP_SERVER(0, &CLIENT_SOCKET, &comInfo) < 0 ){
|
||||
if( DROP_UDP_SERVER(SERV_HOST, 0, &CLIENT_SOCKET, &comInfo, 0) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de création de la socket COM\n", xterm);
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de création de la socket COM\n", entity);
|
||||
|
||||
// On ferme la SOCKET CLIENT
|
||||
close(CLIENT_SOCKET);
|
||||
|
||||
// On retire le flags PORT pour dire qu'on a pas pu ouvrir une socket de comm.
|
||||
request.flags -= BINDHEAD_PRT;
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* 2.2 Si on veut on port de communication */
|
||||
if( request.flags&BINDHEAD_PRT ){
|
||||
if( request.flags&BINDHEAD_SCK ){
|
||||
|
||||
/* On récupère le port de la socket de communication */
|
||||
len = sizeof(struct sockaddr_in);
|
||||
if( getsockname(CLIENT_SOCKET, (struct sockaddr*) &comInfo, &len) < 0 ){
|
||||
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm} Erreur de recherche du port COM ouvert\n", xterm);
|
||||
if( DEBUGMOD&SCK ) printf("{%s} Erreur de recherche du port COM ouvert\n", entity);
|
||||
|
||||
close(CLIENT_SOCKET);
|
||||
|
||||
// On retire le flags PORT pour dire qu'on a pas pu ouvrir une socket de comm.
|
||||
request.flags -= BINDHEAD_PRT;
|
||||
request.flags -= BINDHEAD_SCK;
|
||||
|
||||
// Si on a le port -> on le met dans la reponse
|
||||
}else{
|
||||
strcpy(request.addr, SERV_HOST);
|
||||
request.port = htons(comInfo.sin_port);
|
||||
if( DEBUGMOD&SCK ) printf("{udp_%cterm}{udp_com} Comm. socket is on port %d\n", xterm, request.port);
|
||||
if( DEBUGMOD&SCK ) printf("{%s}{udp_com} socket opened on %s:%d\n", entity, request.addr, request.port);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -294,16 +303,17 @@ void* LISTEN_UDP(void* THREADABLE_PORT){
|
|||
/* [4] Envoi de la réponse
|
||||
=========================================================*/
|
||||
bzero(buffer, MAX_BUF_LEN);
|
||||
memcpy(buffer, &request.flags, sizeof(char));
|
||||
memcpy(buffer+sizeof(char), &request.port, sizeof(unsigned short));
|
||||
memcpy(buffer, &request.flags, sizeof(char));
|
||||
memcpy(buffer+sizeof(char), &request.addr, sizeof(char)*15);
|
||||
memcpy(buffer+sizeof(char)*16, &request.port, sizeof(unsigned short));
|
||||
|
||||
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);
|
||||
printf("{%s} Impossible de répondre au client!\n", entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("{udp_%cterm} sent: bind_header{flag = %d; port = %d}\n", xterm, (int) request.flags, request.port);
|
||||
printf("{%s} sent: bind_header{flag = %d; addr = '%s'; port = %d}\n", entity, (int) request.flags, request.addr, request.port);
|
||||
|
||||
|
||||
|
||||
|
@ -319,13 +329,13 @@ void* LISTEN_UDP(void* THREADABLE_PORT){
|
|||
/* 2.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("{udp_%cterm}{udp_com}(%d) démarré\n", xterm, index);
|
||||
if( DEBUGMOD&THR ) printf("{%s}{udp_com}(%d) démarré\n", entity, index);
|
||||
|
||||
/* 2.2. On signale que ce "manager" est maintenant actif */
|
||||
activeUDPManagers[index] = 1;
|
||||
|
||||
}else
|
||||
if( DEBUGMOD&THR ) printf("{udp_%cterm} Aucun thread UDP libre!\n", xterm);
|
||||
if( DEBUGMOD&THR ) printf("{%s} Aucun thread UDP libre!\n", entity);
|
||||
|
||||
}
|
||||
|
||||
|
@ -333,7 +343,7 @@ void* LISTEN_UDP(void* THREADABLE_PORT){
|
|||
|
||||
/* [n] On ferme la SOCKET d'écoute globale
|
||||
==========================================================*/
|
||||
printf("{udp_%cterm} FERMETURE SOCKET D'ECOUTE UDP!\n", xterm);
|
||||
printf("{%s} FERMETURE SOCKET D'ECOUTE UDP!\n", entity);
|
||||
close(SOCKET);
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
|
||||
/* headers */
|
||||
void* LISTEN_TCP(void* THREADABLE_PORT);
|
||||
void* LISTEN_UDP(void* THREADABLE_PORT);
|
||||
void* LISTEN_TCP(void* THREADABLE_ARG);
|
||||
void* LISTEN_UDP(void* THREADABLE_ARG);
|
||||
void* managePlane(void* THREADABLE_SOCKET);
|
||||
void* manageTerminal(void* THREADABLE_SOCKET);
|
||||
// void* manageViewTerm(void* THREADABLE_SOCKET);
|
||||
|
@ -32,8 +32,15 @@ static int activeTCPManagers[MAX_TCP_THR] = {0}; // contiendra les THREADS TCP a
|
|||
static pthread_t UDPManagers[MAX_UDP_THR]; // contiendra les THREADS UDP
|
||||
static int activeUDPManagers[MAX_UDP_THR] = {0}; // contiendra les THREADS UDP actifs
|
||||
|
||||
|
||||
struct listn_thrd_arg{
|
||||
const char addr[16];
|
||||
const unsigned short port;
|
||||
};
|
||||
|
||||
|
||||
// ENREGISTREMENT DES DONNEES AVIONS
|
||||
struct {
|
||||
struct{
|
||||
unsigned int data;
|
||||
unsigned int update;
|
||||
} sgca_index;
|
||||
|
|
|
@ -28,12 +28,14 @@
|
|||
};
|
||||
|
||||
|
||||
#define BINDHDR_LEN ( sizeof(char)+sizeof(unsigned short) )
|
||||
#define BINDHEAD_CTL 0x01
|
||||
#define BINDHEAD_PRT 0x02
|
||||
#define BINDHDR_LEN ( sizeof(char)*16+sizeof(unsigned short) )
|
||||
#define BINDHEAD_CTL 0x01 // is command terminal (else: view terminal)
|
||||
#define BINDHEAD_SCK 0x02 // ask for com socket
|
||||
#define BINDHEAD_TCP 0x04 // ask TCP instead of UDP
|
||||
|
||||
struct bind_header{
|
||||
char flags;
|
||||
char flags;
|
||||
char addr[15];
|
||||
unsigned short port;
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
|
||||
/* vars */
|
||||
#define SERV_HOST "127.0.0.1" // adresse serveur
|
||||
#define MCST_HOST "225.0.0.37" // adresse groupe multicast UDP
|
||||
#define MCST_HOST "224.0.0.1" // adresse groupe multicast UDP -> plane
|
||||
#define MCST_VTER "224.0.0.2" // adresse groupe multicast UDP -> viewTerm
|
||||
#define MCST_CTER "224.0.0.3" // adresse groupe multicast UDP -> ctrlTerm
|
||||
#define UDP_MCST 4444 // multicast UDP port for PLANES
|
||||
#define TCP_LIST 0x504c // TCP plane command (PL = 8076)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ int DROP_TCP_SERVER(const int pPort, int* pListenSock){
|
|||
=======================================================*/
|
||||
*pListenSock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if( DEBUGMOD&SCK&HDR ) printf(" * [drop_tcp_server] socket: %d\n", *pListenSock);
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) 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&HDR ) printf(" * [drop_tcp_server] bind: %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) 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&HDR ) printf(" * [drop_tcp_server] listen: %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_tcp_server] listen: %d\n", STATUS);
|
||||
|
||||
// si erreur
|
||||
if( STATUS < 0 ) return -1;
|
||||
|
|
|
@ -3,30 +3,39 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
int DROP_UDP_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct sockaddr_in* pInfo, const char pMcast){
|
||||
if( DEBUGMOD&HDR ) printf("====== DROP_UDP_MCAST(%s, %d, %p, %p, %d) ======\n\n", pAddr, pPort, (void*) pListenSock, (void*) pInfo, (int) pMcast);
|
||||
|
||||
/* [0] Initialisation des variables
|
||||
=========================================================*/
|
||||
// CREATION
|
||||
int STATUS; // status
|
||||
|
||||
// INITIALISATION
|
||||
int STATUS; // status
|
||||
uint yes = 1;
|
||||
struct ip_mreq mcastReq;
|
||||
*pListenSock = -1;
|
||||
|
||||
|
||||
/* [1] Création de la socket
|
||||
=======================================================*/
|
||||
/* 1. Création socket */
|
||||
*pListenSock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
if( DEBUGMOD&SCK&HDR ) printf(" * [drop_udp_server] socket: %d\n", *pListenSock);
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_udp_server] socket: %d\n", *pListenSock);
|
||||
|
||||
// si erreur
|
||||
/* 2. Gestion erreur */
|
||||
if( *pListenSock < 0 ) return -1;
|
||||
|
||||
/* 3. MULTICAST -> Autorisation plusieurs sockets sur port */
|
||||
if( pMcast ){
|
||||
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_udp_server] set port to be reused\n");
|
||||
|
||||
if( setsockopt(*pListenSock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(uint) ) < 0 ){
|
||||
close(*pListenSock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* [2] On définit les infos de la socket
|
||||
=========================================================*/
|
||||
|
@ -41,13 +50,27 @@ int DROP_UDP_SERVER(const int pPort, int* pListenSock, struct sockaddr_in* pInfo
|
|||
|
||||
/* [3] On publie la SOCKET
|
||||
=======================================================*/
|
||||
/* 1. Publication socket */
|
||||
STATUS = bind(*pListenSock, (struct sockaddr*) pInfo, sizeof(struct sockaddr_in));
|
||||
|
||||
if( DEBUGMOD&SCK&HDR ) printf(" * [drop_udp_server] bind: %d\n", STATUS);
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_udp_server] bind: %d\n", STATUS);
|
||||
|
||||
// si erreur
|
||||
/* 2. Gestion erreur */
|
||||
if( STATUS < 0 ) return -1;
|
||||
|
||||
/* 3. Demande groupe multicast (si demandé) */
|
||||
if( pMcast ){
|
||||
|
||||
if( DEBUGMOD&SCK && DEBUGMOD&HDR ) printf(" * [drop_udp_server] join mcast group: %s\n", pAddr);
|
||||
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
|
||||
|
|
|
@ -6,13 +6,15 @@
|
|||
#include "../../header.h"
|
||||
|
||||
|
||||
/* Créé et met un serveur UDP d'écoute
|
||||
/* Créé et met un serveur UDP d'écoute MULTICAST ou CLASSIQUE
|
||||
*
|
||||
* ==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
|
||||
* @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==
|
||||
|
@ -25,7 +27,7 @@
|
|||
* [n] On renvoie la socket par référence
|
||||
*
|
||||
*/
|
||||
int DROP_UDP_SERVER(const int pPort, int* pListenSock, struct sockaddr_in* pInfo);
|
||||
int DROP_UDP_SERVER(const char* pAddr, const int pPort, int* pListenSock, struct sockaddr_in* pInfo, const char pMcast);
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue