--- rpl/src/instructions_o1.c 2015/02/19 11:01:25 1.81 +++ rpl/src/instructions_o1.c 2015/06/08 07:15:31 1.82 @@ -869,6 +869,203 @@ instruction_or(struct_processus *s_etat_ ================================================================================ */ + +#define d_BIND_TO_DEVICE 0 +#define d_BROADCAST 1 +#define d_DONT_ROUTE 2 +#define d_KEEP_ALIVE 3 +#define d_PRIORITY 4 +#define d_RECEIVE_BUFFER 5 +#define d_FORCE_RECEIVE_BUFFER 6 +#define d_SEND_BUFFER 7 +#define d_FORCE_SEND_BUFFER 8 +#define d_RECEIVING_TIMEOUT 9 +#define d_SENDING_TIMEOUT 10 +#define d_REUSE_ADDRESS 11 + +static inline logical1 +options_socket(struct_processus *s_etat_processus, + struct_objet *s_objet_resultat, unsigned char *options, + unsigned char *peripherique, int *priorite, + int *buffer_emission, int *buffer_reception, + int *timeout_emission, int *timeout_reception) +{ + int drapeau; + + /* + * Options des sockets + */ + + drapeau = -1; + +# define WARNING(message) { \ + if ((*s_etat_processus).langue != 'F') \ + printf("+++Warning : %s unavailable on host system\n", message); \ + else \ + printf("+++Attention : %s non disponible sur le système hôte\n", \ + message); } while(0) + + if (options[d_BIND_TO_DEVICE] == 'Y') + { +# ifdef SO_BINDTODEVICE + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)) + .socket, SOL_SOCKET, SO_BINDTODEVICE, peripherique, + (socklen_t) strlen(peripherique)) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } +# else + WARNING("BIND TO DEVICE"); +# endif + } + + if (options[d_BROADCAST] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_BROADCAST, &drapeau, sizeof(drapeau)) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_DONT_ROUTE] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_DONTROUTE, &drapeau, sizeof(drapeau)) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_KEEP_ALIVE] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_KEEPALIVE, &drapeau, sizeof(drapeau)) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_PRIORITY] == 'Y') + { +# ifdef SO_PRIORITY + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)) + .socket, SOL_SOCKET, SO_PRIORITY, priorite, + sizeof((*priorite))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } +# else + WARNING("PRIORITY"); +# endif + } + + if (options[d_RECEIVE_BUFFER] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_RCVBUF, buffer_reception, + sizeof((*buffer_reception))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_FORCE_RECEIVE_BUFFER] == 'Y') + { +# ifdef SO_RCVBUFFORCE + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)) + .socket, SOL_SOCKET, SO_RCVBUFFORCE, + buffer_reception, sizeof((*buffer_reception))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } +# else + WARNING("FORCE_RECEIVE_BUFFER"); +# endif + } + + if (options[d_SEND_BUFFER] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_SNDBUF, buffer_emission, + sizeof((*buffer_emission))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_FORCE_SEND_BUFFER] == 'Y') + { +# ifdef SO_SNDBUFFORCE + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)) + .socket, SOL_SOCKET, SO_SNDBUFFORCE, buffer_emission, + sizeof((*buffer_emission))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } +# else + WARNING("FORCE_SEND_BUFFER"); +# endif + } + + if (options[d_RECEIVING_TIMEOUT] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_RCVTIMEO, + timeout_reception, sizeof((*timeout_reception))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_SENDING_TIMEOUT] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_SNDTIMEO, + timeout_emission, sizeof((*timeout_emission))) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + if (options[d_REUSE_ADDRESS] == 'Y') + { + if (setsockopt((*((struct_socket *) (*s_objet_resultat).objet)).socket, + SOL_SOCKET, SO_REUSEADDR, &drapeau, sizeof(drapeau)) != 0) + { + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return(d_erreur); + } + } + + return(d_absence_erreur); +# undef WARNING +} + + void instruction_open(struct_processus *s_etat_processus) { @@ -905,7 +1102,6 @@ instruction_open(struct_processus *s_eta int buffer_emission; int buffer_reception; - int drapeau; int priorite; int prochain_descripteur; int protocole_numerique; @@ -976,19 +1172,6 @@ instruction_open(struct_processus *s_eta unsigned long nombre_elements; unsigned long unite; -# define d_BIND_TO_DEVICE 0 -# define d_BROADCAST 1 -# define d_DONT_ROUTE 2 -# define d_KEEP_ALIVE 3 -# define d_PRIORITY 4 -# define d_RECEIVE_BUFFER 5 -# define d_FORCE_RECEIVE_BUFFER 6 -# define d_SEND_BUFFER 7 -# define d_FORCE_SEND_BUFFER 8 -# define d_RECEIVING_TIMEOUT 9 -# define d_SENDING_TIMEOUT 10 -# define d_REUSE_ADDRESS 11 - /* * Argument : { "ouverture" "accès" "format" [ { "nom" } 'protection' ] } */ @@ -1140,7 +1323,6 @@ instruction_open(struct_processus *s_eta buffer_reception = 0; timeout_emission = 0; timeout_reception = 0; - drapeau = -1; s_parametres_tty = NULL; for(i = 0; i < 12; options[i++] = 'N'); @@ -4382,223 +4564,6 @@ instruction_open(struct_processus *s_eta * Traitement des sockets */ - - inline logical1 options_socket() - { - /* - * Options des sockets - */ - -# define WARNING(message) \ - if ((*s_etat_processus).langue != 'F') \ - printf("+++Warning : %s unavailable on host system\n", \ - message); \ - else \ - printf("+++Attention : %s non disponible sur le système " \ - "hôte\n", message) - - if (options[d_BIND_TO_DEVICE] == 'Y') - { -# ifdef SO_BINDTODEVICE - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_BINDTODEVICE, - peripherique, (socklen_t) strlen(peripherique)) - != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } -# else - WARNING("BIND TO DEVICE"); -# endif - } - - if (options[d_BROADCAST] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_BROADCAST, - &drapeau, sizeof(drapeau)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_DONT_ROUTE] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_DONTROUTE, - &drapeau, sizeof(drapeau)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_KEEP_ALIVE] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_KEEPALIVE, - &drapeau, sizeof(drapeau)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_PRIORITY] == 'Y') - { -# ifdef SO_PRIORITY - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_PRIORITY, - &priorite, sizeof(priorite)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } -# else - WARNING("PRIORITY"); -# endif - } - - if (options[d_RECEIVE_BUFFER] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_RCVBUF, - &buffer_reception, sizeof(buffer_reception)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_FORCE_RECEIVE_BUFFER] == 'Y') - { -# ifdef SO_RCVBUFFORCE - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_RCVBUFFORCE, - &buffer_reception, sizeof(buffer_reception)) - != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } -# else - WARNING("FORCE_RECEIVE_BUFFER"); -# endif - } - - if (options[d_SEND_BUFFER] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_SNDBUF, - &buffer_emission, sizeof(buffer_emission)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_FORCE_SEND_BUFFER] == 'Y') - { -# ifdef SO_SNDBUFFORCE - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_SNDBUFFORCE, - &buffer_emission, sizeof(buffer_emission)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } -# else - WARNING("FORCE_SEND_BUFFER"); -# endif - } - - if (options[d_RECEIVING_TIMEOUT] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_RCVTIMEO, - &timeout_reception, sizeof(timeout_reception)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_SENDING_TIMEOUT] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_SNDTIMEO, - &timeout_emission, sizeof(timeout_emission)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - if (options[d_REUSE_ADDRESS] == 'Y') - { - if (setsockopt((*((struct_socket *) (*s_objet_resultat) - .objet)).socket, SOL_SOCKET, SO_REUSEADDR, - &drapeau, sizeof(drapeau)) != 0) - { - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_resultat); - - (*s_etat_processus).erreur_execution = - d_ex_erreur_parametre_fichier; - return(d_erreur); - } - } - - return(d_absence_erreur); -#undef WARNING - } - /* * Vérification de la cohérence des arguments et traitement * des valeurs par défaut. @@ -4915,7 +4880,10 @@ instruction_open(struct_processus *s_eta strncpy(socket_unix.sun_path, pointeur, UNIX_PATH_MAX); socket_unix.sun_path[UNIX_PATH_MAX - 1] = d_code_fin_chaine; - if (options_socket() == d_erreur) + if (options_socket(s_etat_processus, s_objet_resultat, + options, peripherique, &priorite, + &buffer_emission, &buffer_reception, + &timeout_emission, &timeout_reception) == d_erreur) { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); @@ -5019,7 +4987,12 @@ instruction_open(struct_processus *s_eta (*resolution_courante).ai_addr)) .sin_addr.s_addr; - if (options_socket() == d_erreur) + if (options_socket(s_etat_processus, + s_objet_resultat, + options, peripherique, &priorite, + &buffer_emission, &buffer_reception, + &timeout_emission, &timeout_reception) + == d_erreur) { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); @@ -5126,7 +5099,12 @@ instruction_open(struct_processus *s_eta (*resolution_courante).ai_addr)) .sin6_addr.s6_addr[i], i++); - if (options_socket() == d_erreur) + if (options_socket(s_etat_processus, + s_objet_resultat, + options, peripherique, &priorite, + &buffer_emission, &buffer_reception, + &timeout_emission, &timeout_reception) + == d_erreur) { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); @@ -5262,7 +5240,12 @@ instruction_open(struct_processus *s_eta socket_ipv4.sin_addr.s_addr = htonl(adresse_ipv4); - if (options_socket() == d_erreur) + if (options_socket(s_etat_processus, + s_objet_resultat, + options, peripherique, &priorite, + &buffer_emission, &buffer_reception, + &timeout_emission, &timeout_reception) + == d_erreur) { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat); @@ -5339,7 +5322,12 @@ instruction_open(struct_processus *s_eta socket_ipv6.sin6_addr.s6_addr[i] = (unsigned char) (adresse[i]), i++); - if (options_socket() == d_erreur) + if (options_socket(s_etat_processus, + s_objet_resultat, + options, peripherique, &priorite, + &buffer_emission, &buffer_reception, + &timeout_emission, &timeout_reception) + == d_erreur) { liberation(s_etat_processus, s_objet_argument); liberation(s_etat_processus, s_objet_resultat);