monstigule  | Bonjour à tous!     je me suis mis à la création d'un mini serveur, non pas pour héberger un site mais pour voir "comment ça fonctionne".
 j'ai suivi un code dans un bouquin:
  
  Code :
 - #include "includes.h"
 - //defines
 - #define PORT 80
 - #define WEBROOT "./web-serverX_ROOT/"
 - int main(void){
 - int sockfd, new_sockfd, yes=1;
 - struct sockaddr_in host_addr, client_addr;
 - socklen_t sin_size;
 - printf("Accepting web requests on port %d\n", PORT);
 - if((sockfd == socket(PF_INET, SOCK_STREAM, 0)) == -1)
 - 	fatal("in socket" );
 - if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
 - 	fatal("setting socket option SO_REUSEADDR" );
 - host_addr.sin_family = AF_INET;  // Ordre des octets de l'hôte.
 - host_addr.sin_port = htons(PORT);	// Ordre des octets du réseau (entier court).
 - host_addr.sin_addr.s_addr = 0;  // Remplir automatiquement l'IP.
 - memset(&(host_addr.sin_zero), '\0', 8);	// Reste de la structure à 0.
 - if(bind(sockfd, (struct sockaddr *)&host_addr, sizeof(struct sockaddr)) == -1)
 - 	fatal("binding to socket" );
 - if(listen(sockfd, 20) == -1)
 - 	fatal("listenning on socket" );
 - while(1) {  // Boucle d'acceptation des connexions entrantes.
 - 	sin_size = sizeof(struct sockaddr_in);
 - 	new_sockfd = accept(sockfd, (struct sockaddr *)&client_addr, &sin_size);
 - 	if(new_sockfd == -1)
 -   fatal("accepting connection" );
 - 	handle_connection(new_sockfd, &client_addr);
 - }
 - return 0;
 - }
 
  |  
 
   mais lors de l'éxécution, voici ce que me donne le terminal Linux:
  Code :
 - monstigule@monstigule-PC:~/Server$ gcc main.c
 - monstigule@monstigule-PC:~/Server$ ./a.out
 - Accepting web requests on port 80
 - Error: setting socket option SO_REUSEADDR
 - monstigule@monstigule-PC:~/Server$
 
  |  
 
   j'en conclus donc que   Code :
 - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))
 
  |  
  retourne la valeur -1.
 mais pourquoi? je n'arrive pas à trouver la solution...       merci d'avance        |