76 lines
2.3 KiB
C
76 lines
2.3 KiB
C
/******************************************************/
|
|
/* S3T - M311 - CHIGNOLI */
|
|
/* Serveur IPC/BERKELEY -- DOMAINE INET -- MODE TCP */
|
|
/* A FINIR - A FINIR -A FINIR - A FINIR - A FINIR */
|
|
/******************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <strings.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <netdb.h>
|
|
#include <signal.h>
|
|
#include <arpa/inet.h>
|
|
|
|
#define BUFSIZE 80
|
|
int sd;
|
|
|
|
void arret_service()
|
|
{
|
|
printf("\n SERVEUR : SIGINT recu => Arret du SERVICE\n\n");
|
|
close(sd);
|
|
exit (0);
|
|
}
|
|
|
|
int main (int argc, char* argv [])
|
|
{
|
|
char buffer [BUFSIZE];
|
|
struct hostent *host_name;
|
|
struct sockaddr_in socket_name;
|
|
|
|
if (argc != 2)
|
|
{
|
|
printf ("\nSYNTAXE : %s <machine>\n\n", argv[0]); exit (1);
|
|
}
|
|
/* Armement du signal SIGINT pour arret "propre" du serveur */
|
|
signal(SIGINT,arret_service);
|
|
|
|
/* Obtention d'un descripteur de "socket" */
|
|
if ((sd = socket (PF_INET, SOCK_DGRAM, 0)) == -1)
|
|
{ perror ("*** Echec socket ***"); exit (2); }
|
|
|
|
/* Recherche de l'adresse INTERNET de la machine du serveur */
|
|
host_name = gethostbyname (argv[1]);
|
|
if (host_name == 0)
|
|
{ fprintf (stderr, "\n*** Echec gethostbyname ***\n\n"); exit(1); }
|
|
|
|
/* Paramétrage de la "socket" */
|
|
bzero ( (char *) &socket_name, sizeof (socket_name) ); // mise à zero
|
|
socket_name.sin_family = AF_INET;
|
|
socket_name.sin_port = 6200;
|
|
bcopy (host_name -> h_addr, &socket_name.sin_addr, host_name -> h_length);
|
|
|
|
/* Affichage infos socket */
|
|
printf ("SERVEUR sur machine %s (%u) - port %d\n",
|
|
inet_ntoa (socket_name.sin_addr),
|
|
socket_name.sin_addr, socket_name.sin_port);
|
|
|
|
/**************************************************/
|
|
/* A FAIRE : Suite du parametrage du "serveur" */
|
|
/**************************************************/
|
|
|
|
/* Boucle de traitement des demandes de connexion */
|
|
while (1)
|
|
{
|
|
/**************************************************/
|
|
/* A FAIRE : Attente des demandes de connexion */
|
|
/* d'un client et traitement. */
|
|
/**************************************************/
|
|
}
|
|
}
|
|
|
|
|