2017-04-01 15:01:36 +00:00
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-07 16:14:21 +00:00
|
|
|
int DROP_UDP_SERVER(const int pPort, int* pListenSock, struct sockaddr_in* pInfo){
|
2017-04-01 15:01:36 +00:00
|
|
|
if( DEBUGMOD&HDR ) printf("====== DROP_UDP_SERVER(%d, %p) ======\n\n", pPort, (void*) pListenSock);
|
|
|
|
|
|
|
|
/* [0] Initialisation des variables
|
|
|
|
=========================================================*/
|
|
|
|
// CREATION
|
2017-04-06 15:41:34 +00:00
|
|
|
int STATUS; // status
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
// INITIALISATION
|
|
|
|
*pListenSock = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Création de la socket
|
|
|
|
=======================================================*/
|
|
|
|
*pListenSock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
|
2017-04-07 16:14:21 +00:00
|
|
|
if( DEBUGMOD&SCK ) printf(" * [drop_udp_server] socket: %d\n", *pListenSock);
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
// si erreur
|
|
|
|
if( *pListenSock < 0 ) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On définit les infos de la socket
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Reset des valeurs */
|
2017-04-07 16:14:21 +00:00
|
|
|
bzero(pInfo, sizeof(struct sockaddr_in));
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
/* (2) On définit les infos */
|
2017-04-07 16:14:21 +00:00
|
|
|
pInfo->sin_family = AF_INET;
|
|
|
|
pInfo->sin_port = htons(pPort);
|
|
|
|
pInfo->sin_addr.s_addr = htonl(INADDR_ANY);
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] On publie la SOCKET
|
|
|
|
=======================================================*/
|
2017-04-07 16:14:21 +00:00
|
|
|
STATUS = bind(*pListenSock, (struct sockaddr*) pInfo, sizeof(struct sockaddr_in));
|
2017-04-01 15:01:36 +00:00
|
|
|
|
2017-04-07 16:14:21 +00:00
|
|
|
if( DEBUGMOD&SCK ) printf(" * [drop_udp_server] bind: %d\n", STATUS);
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
// si erreur
|
|
|
|
if( STATUS < 0 ) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n] Code succès
|
|
|
|
=========================================================*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|