2017-04-01 15:01:36 +00:00
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int DROP_TCP_SERVER(const int pPort, int* pListenSock){
|
|
|
|
if( DEBUGMOD&HDR ) printf("====== DROP_TCP_SERVER(%d, %p) ======\n\n", pPort, (void*) pListenSock);
|
|
|
|
|
|
|
|
/* [0] Initialisation des variables
|
|
|
|
=========================================================*/
|
|
|
|
// CREATION
|
|
|
|
static struct sockaddr_in addr; // contiendra les infos du serveur
|
|
|
|
int STATUS; // status
|
|
|
|
|
|
|
|
// INITIALISATION
|
|
|
|
*pListenSock = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Création de la socket
|
|
|
|
=======================================================*/
|
|
|
|
*pListenSock = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
|
2017-04-06 18:08:45 +00:00
|
|
|
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_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 */
|
|
|
|
bzero(&addr, 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);
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On publie la SOCKET
|
|
|
|
=======================================================*/
|
|
|
|
STATUS = bind(*pListenSock, (struct sockaddr*) &addr, sizeof(addr));
|
|
|
|
|
2017-04-06 18:08:45 +00:00
|
|
|
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server BIND = %d\n", STATUS);
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
// si erreur
|
|
|
|
if( STATUS < 0 ) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] On met la socket sur écoute
|
|
|
|
=======================================================*/
|
|
|
|
STATUS = listen(*pListenSock, MAX_TCP_THR);
|
|
|
|
|
2017-04-06 18:08:45 +00:00
|
|
|
if( DEBUGMOD&SCK ) printf(" * /lib/tcp/server/drop_tcp_server LISTEN = %d\n", STATUS);
|
2017-04-01 15:01:36 +00:00
|
|
|
|
|
|
|
// si erreur
|
|
|
|
if( STATUS < 0 ) return -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* [n] Code succès
|
|
|
|
=========================================================*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|