2020-09-04 10:27:13 +02:00

63 lines
2.0 KiB
C

/******************************************************/
/* S3T - M311 - CHIGNOLI */
/* Client 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;
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);
}
/* 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 ("CLIENT sur machine %s (%u) - port %d\n",
inet_ntoa (socket_name.sin_addr),
socket_name.sin_addr, socket_name.sin_port);
/**************************************************/
/* A FAIRE : */
/* - demande de connexion */
/* - envoi de 80 caracteres au serveur */
/* - recuperation de 80 caracteres du serveur */
/* - affichage des 80 caractères retournés */
/**************************************************/
}
}