|
|
|
@ -61,14 +61,12 @@ int cree_socket_stream (const char * nom_hote, const int num_port, const char *
|
|
|
|
|
else {
|
|
|
|
|
adresse.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pattacher un port a la socket sock
|
|
|
|
|
if (bind(sock, (struct sockaddr *) & adresse, sizeof(struct sockaddr_in)) < 0) {
|
|
|
|
|
close(sock);
|
|
|
|
|
printf("Erreur : bind\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -82,7 +80,6 @@ int affiche_adresse_socket (int sock) {
|
|
|
|
|
printf("Erreur : getsockname\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf ("IP = %s, Port = %u \n", inet_ntoa(adresse.sin_addr), ntohs(adresse.sin_port));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -159,20 +156,13 @@ void traite_connexion (int sock){
|
|
|
|
|
printf("J'ai lu %d bytes\n",longueur);
|
|
|
|
|
// Pour le client telnet :
|
|
|
|
|
//buffer[longueur-2] = '\0';
|
|
|
|
|
// Avec un client autre que telnet :
|
|
|
|
|
//buffer[longueur]='\0';
|
|
|
|
|
|
|
|
|
|
// printf("Je melange %s\n",buffer);
|
|
|
|
|
//strfry(buffer);
|
|
|
|
|
|
|
|
|
|
// Ecrire la variable buffer sur la socket
|
|
|
|
|
write(sock, buffer, longueur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(sock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char * argv[]) {
|
|
|
|
|
return serveur_tcp();
|
|
|
|
|
}
|
|
|
|
|