Changes in / [49d819b4:7ae3d6f] in mainline


Ignore:
Location:
uspace/app
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/netecho/netecho.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup netecho
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Network echo application.
    35  *  Answers received packets.
     34 * Network echo application.
     35 * Answers received packets.
    3636 */
    3737
     
    5151#include "print_error.h"
    5252
    53 /** Network echo module name.
    54  */
     53/** Network echo module name. */
    5554#define NAME    "Network Echo"
    5655
    57 /** Prints the application help.
    58  */
    59 void echo_print_help(void);
    60 
    61 /** Module entry point.
    62  *  Reads command line parameters and starts listenning.
    63  *  @param[in] argc The number of command line parameters.
    64  *  @param[in] argv The command line parameters.
    65  *  @returns EOK on success.
    66  */
    67 int main(int argc, char * argv[]);
    68 
    69 void echo_print_help(void){
     56static void echo_print_help(void)
     57{
    7058        printf(
    7159                "Network Echo aplication\n" \
     
    10189}
    10290
    103 int main(int argc, char * argv[]){
     91int main(int argc, char *argv[])
     92{
    10493        ERROR_DECLARE;
    10594
    106         size_t size                     = 1024;
    107         int verbose                     = 0;
    108         char * reply            = NULL;
    109         sock_type_t type        = SOCK_DGRAM;
    110         int count                       = -1;
    111         int family                      = PF_INET;
    112         uint16_t port           = 7;
    113         int backlog                     = 3;
    114 
    115         socklen_t max_length                            = sizeof(struct sockaddr_in6);
     95        size_t size = 1024;
     96        int verbose = 0;
     97        char *reply = NULL;
     98        sock_type_t type = SOCK_DGRAM;
     99        int count = -1;
     100        int family = PF_INET;
     101        uint16_t port = 7;
     102        int backlog = 3;
     103
     104        socklen_t max_length = sizeof(struct sockaddr_in6);
    116105        uint8_t address_data[max_length];
    117         struct sockaddr * address                       = (struct sockaddr *) address_data;
    118         struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    119         struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
     106        struct sockaddr *address = (struct sockaddr *) address_data;
     107        struct sockaddr_in *address_in = (struct sockaddr_in *) address;
     108        struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address;
    120109        socklen_t addrlen;
    121110        char address_string[INET6_ADDRSTRLEN];
    122         uint8_t * address_start;
     111        uint8_t *address_start;
    123112        int socket_id;
    124113        int listening_id;
    125         char * data;
     114        char *data;
    126115        size_t length;
    127116        int index;
     
    130119
    131120        // parse the command line arguments
    132         for(index = 1; index < argc; ++ index){
    133                 if(argv[index][0] == '-'){
    134                         switch(argv[index][1]){
    135                                 case 'b':
    136                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0));
    137                                         break;
    138                                 case 'c':
    139                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0));
    140                                         break;
    141                                 case 'f':
    142                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
    143                                         break;
    144                                 case 'h':
     121        for (index = 1; index < argc; ++ index) {
     122                if (argv[index][0] == '-') {
     123                        switch (argv[index][1]) {
     124                        case 'b':
     125                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0));
     126                                break;
     127                        case 'c':
     128                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0));
     129                                break;
     130                        case 'f':
     131                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
     132                                break;
     133                        case 'h':
     134                                echo_print_help();
     135                                return EOK;
     136                                break;
     137                        case 'p':
     138                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     139                                port = (uint16_t) value;
     140                                break;
     141                        case 'r':
     142                                ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0));
     143                                break;
     144                        case 's':
     145                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     146                                size = (value >= 0) ? (size_t) value : 0;
     147                                break;
     148                        case 't':
     149                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
     150                                type = (sock_type_t) value;
     151                                break;
     152                        case 'v':
     153                                verbose = 1;
     154                                break;
     155                        // long options with the double minus sign ('-')
     156                        case '-':
     157                                if (str_lcmp(argv[index] + 2, "backlog=", 6) == 0) {
     158                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8));
     159                                } else if (str_lcmp(argv[index] + 2, "count=", 6) == 0) {
     160                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8));
     161                                } else if (str_lcmp(argv[index] + 2, "family=", 7) == 0) {
     162                                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
     163                                } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) {
    145164                                        echo_print_help();
    146165                                        return EOK;
    147                                         break;
    148                                 case 'p':
    149                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     166                                } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) {
     167                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    150168                                        port = (uint16_t) value;
    151                                         break;
    152                                 case 'r':
    153                                         ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0));
    154                                         break;
    155                                 case 's':
    156                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     169                                } else if (str_lcmp(argv[index] + 2, "reply=", 6) == 0) {
     170                                        ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8));
     171                                } else if (str_lcmp(argv[index] + 2, "size=", 5) == 0) {
     172                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    157173                                        size = (value >= 0) ? (size_t) value : 0;
    158                                         break;
    159                                 case 't':
    160                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
     174                                } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) {
     175                                        ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
    161176                                        type = (sock_type_t) value;
    162                                         break;
    163                                 case 'v':
     177                                } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) {
    164178                                        verbose = 1;
    165                                         break;
    166                                 // long options with the double minus sign ('-')
    167                                 case '-':
    168                                         if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
    169                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8));
    170                                         }else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
    171                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8));
    172                                         }else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    173                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
    174                                         }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    175                                                 echo_print_help();
    176                                                 return EOK;
    177                                         }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
    178                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    179                                                 port = (uint16_t) value;
    180                                         }else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){
    181                                                 ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8));
    182                                         }else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
    183                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    184                                                 size = (value >= 0) ? (size_t) value : 0;
    185                                         }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    186                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
    187                                                 type = (sock_type_t) value;
    188                                         }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
    189                                                 verbose = 1;
    190                                         }else{
    191                                                 echo_print_help();
    192                                                 return EINVAL;
    193                                         }
    194                                         break;
    195                                 default:
     179                                } else {
    196180                                        echo_print_help();
    197181                                        return EINVAL;
     182                                }
     183                                break;
     184                        default:
     185                                echo_print_help();
     186                                return EINVAL;
    198187                        }
    199                 }else{
     188                } else {
    200189                        echo_print_help();
    201190                        return EINVAL;
     
    204193
    205194        // check the buffer size
    206         if(size <= 0){
     195        if (size <= 0) {
    207196                fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size);
    208197                size = 1024;
     
    210199        // size plus the terminating null (\0)
    211200        data = (char *) malloc(size + 1);
    212         if(! data){
     201        if (!data) {
    213202                fprintf(stderr, "Failed to allocate receive buffer.\n");
    214203                return ENOMEM;
     
    220209        // prepare the address buffer
    221210        bzero(address_data, max_length);
    222         switch(family){
    223                 case PF_INET:
    224                         address_in->sin_family = AF_INET;
    225                         address_in->sin_port = htons(port);
    226                         addrlen = sizeof(struct sockaddr_in);
    227                         break;
    228                 case PF_INET6:
    229                         address_in6->sin6_family = AF_INET6;
    230                         address_in6->sin6_port = htons(port);
    231                         addrlen = sizeof(struct sockaddr_in6);
    232                         break;
    233                 default:
    234                         fprintf(stderr, "Protocol family is not supported\n");
    235                         return EAFNOSUPPORT;
     211        switch (family) {
     212        case PF_INET:
     213                address_in->sin_family = AF_INET;
     214                address_in->sin_port = htons(port);
     215                addrlen = sizeof(struct sockaddr_in);
     216                break;
     217        case PF_INET6:
     218                address_in6->sin6_family = AF_INET6;
     219                address_in6->sin6_port = htons(port);
     220                addrlen = sizeof(struct sockaddr_in6);
     221                break;
     222        default:
     223                fprintf(stderr, "Protocol family is not supported\n");
     224                return EAFNOSUPPORT;
    236225        }
    237226
    238227        // get a listening socket
    239228        listening_id = socket(family, type, 0);
    240         if(listening_id < 0){
     229        if (listening_id < 0) {
    241230                socket_print_error(stderr, listening_id, "Socket create: ", "\n");
    242231                return listening_id;
     
    244233
    245234        // if the stream socket is used
    246         if(type == SOCK_STREAM){
     235        if (type == SOCK_STREAM) {
    247236                // check the backlog
    248                 if(backlog <= 0){
     237                if (backlog <= 0) {
    249238                        fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size);
    250239                        backlog = 3;
    251240                }
    252241                // set the backlog
    253                 if(ERROR_OCCURRED(listen(listening_id, backlog))){
     242                if (ERROR_OCCURRED(listen(listening_id, backlog))) {
    254243                        socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n");
    255244                        return ERROR_CODE;
     
    258247
    259248        // bind the listenning socket
    260         if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){
     249        if (ERROR_OCCURRED(bind(listening_id, address, addrlen))) {
    261250                socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n");
    262251                return ERROR_CODE;
    263252        }
    264253
    265         if(verbose){
     254        if (verbose)
    266255                printf("Socket %d listenning at %d\n", listening_id, port);
    267         }
    268256
    269257        socket_id = listening_id;
     
    271259        // do count times
    272260        // or indefinitely if set to a negative value
    273         while(count){
     261        while (count) {
    274262
    275263                addrlen = max_length;
    276                 if(type == SOCK_STREAM){
     264                if (type == SOCK_STREAM) {
    277265                        // acceept a socket if the stream socket is used
    278266                        socket_id = accept(listening_id, address, &addrlen);
    279                         if(socket_id <= 0){
     267                        if (socket_id <= 0) {
    280268                                socket_print_error(stderr, socket_id, "Socket accept: ", "\n");
    281                         }else{
    282                                 if(verbose){
     269                        } else {
     270                                if (verbose)
    283271                                        printf("Socket %d accepted\n", socket_id);
    284                                 }
    285272                        }
    286273                }
    287274
    288275                // if the datagram socket is used or the stream socked was accepted
    289                 if(socket_id > 0){
     276                if (socket_id > 0) {
    290277
    291278                        // receive an echo request
    292279                        value = recvfrom(socket_id, data, size, 0, address, &addrlen);
    293                         if(value < 0){
     280                        if (value < 0) {
    294281                                socket_print_error(stderr, value, "Socket receive: ", "\n");
    295                         }else{
     282                        } else {
    296283                                length = (size_t) value;
    297                                 if(verbose){
     284                                if (verbose) {
    298285                                        // print the header
    299286
    300287                                        // get the source port and prepare the address buffer
    301288                                        address_start = NULL;
    302                                         switch(address->sa_family){
    303                                                 case AF_INET:
    304                                                         port = ntohs(address_in->sin_port);
    305                                                         address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    306                                                         break;
    307                                                 case AF_INET6:
    308                                                         port = ntohs(address_in6->sin6_port);
    309                                                         address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    310                                                         break;
    311                                                 default:
    312                                                         fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
     289                                        switch (address->sa_family) {
     290                                        case AF_INET:
     291                                                port = ntohs(address_in->sin_port);
     292                                                address_start = (uint8_t *) &address_in->sin_addr.s_addr;
     293                                                break;
     294                                        case AF_INET6:
     295                                                port = ntohs(address_in6->sin6_port);
     296                                                address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
     297                                                break;
     298                                        default:
     299                                                fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
    313300                                        }
    314301                                        // parse the source address
    315                                         if(address_start){
    316                                                 if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
     302                                        if (address_start) {
     303                                                if (ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))) {
    317304                                                        fprintf(stderr, "Received address error %d\n", ERROR_CODE);
    318                                                 }else{
     305                                                } else {
    319306                                                        data[length] = '\0';
    320307                                                        printf("Socket %d received %d bytes from %s:%d\n%s\n", socket_id, length, address_string, port, data);
     
    324311
    325312                                // answer the request either with the static reply or the original data
    326                                 if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){
     313                                if (ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen)))
    327314                                        socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
    328                                 }
    329 
    330315                        }
    331316
    332317                        // close the accepted stream socket
    333                         if(type == SOCK_STREAM){
    334                                 if(ERROR_OCCURRED(closesocket(socket_id))){
     318                        if (type == SOCK_STREAM) {
     319                                if (ERROR_OCCURRED(closesocket(socket_id)))
    335320                                        socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
    336                                 }
    337321                        }
    338322
     
    340324
    341325                // decrease the count if positive
    342                 if(count > 0){
    343                         -- count;
    344                         if(verbose){
     326                if (count > 0) {
     327                        count--;
     328                        if (verbose)
    345329                                printf("Waiting for next %d packet(s)\n", count);
    346                         }
    347                 }
    348         }
    349 
    350         if(verbose){
     330                }
     331        }
     332
     333        if (verbose)
    351334                printf("Closing the socket\n");
    352         }
    353335
    354336        // close the listenning socket
    355         if(ERROR_OCCURRED(closesocket(listening_id))){
     337        if (ERROR_OCCURRED(closesocket(listening_id))) {
    356338                socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
    357339                return ERROR_CODE;
    358340        }
    359341
    360         if(verbose){
     342        if (verbose)
    361343                printf("Exiting\n");
    362         }
    363344
    364345        return EOK;
  • uspace/app/netecho/print_error.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup net_app
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Generic application error printing functions implementation.
     34 * Generic application error printing functions implementation.
    3535 */
     36
     37#include "print_error.h"
    3638
    3739#include <stdio.h>
     
    4042#include <net/icmp_codes.h>
    4143
    42 #include "print_error.h"
     44/** Prints the specific ICMP error description.
     45 *
     46 * @param[in] output The description output stream. May be NULL.
     47 * @param[in] error_code The ICMP error code.
     48 * @param[in] prefix The error description prefix. May be NULL.
     49 * @param[in] suffix The error description suffix. May be NULL.
     50 */
     51void icmp_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
     52{
     53        if (!output)
     54                return;
     55       
     56        if (prefix)
     57                fprintf(output, "%s", prefix);
     58               
     59        switch (error_code) {
     60        case ICMP_DEST_UNREACH:
     61                fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
     62                break;
     63        case ICMP_SOURCE_QUENCH:
     64                fprintf(output, "ICMP Source Quench (%d) error", error_code);
     65                break;
     66        case ICMP_REDIRECT:
     67                fprintf(output, "ICMP Redirect (%d) error", error_code);
     68                break;
     69        case ICMP_ALTERNATE_ADDR:
     70                fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
     71                break;
     72        case ICMP_ROUTER_ADV:
     73                fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
     74                break;
     75        case ICMP_ROUTER_SOL:
     76                fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
     77                break;
     78        case ICMP_TIME_EXCEEDED:
     79                fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
     80                break;
     81        case ICMP_PARAMETERPROB:
     82                fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
     83                break;
     84        case ICMP_CONVERSION_ERROR:
     85                fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
     86                break;
     87        case ICMP_REDIRECT_MOBILE:
     88                fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
     89                break;
     90        case ICMP_SKIP:
     91                fprintf(output, "ICMP SKIP (%d) error", error_code);
     92                break;
     93        case ICMP_PHOTURIS:
     94                fprintf(output, "ICMP Photuris (%d) error", error_code);
     95                break;
     96        default:
     97                fprintf(output, "Other (%d) error", error_code);
     98        }
    4399
    44 void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    45         if(output){
    46                 if(prefix){
    47                         fprintf(output, "%s", prefix);
    48                 }
    49                 switch(error_code){
    50                         case ICMP_DEST_UNREACH:
    51                                 fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
    52                                 break;
    53                         case ICMP_SOURCE_QUENCH:
    54                                 fprintf(output, "ICMP Source Quench (%d) error", error_code);
    55                                 break;
    56                         case ICMP_REDIRECT:
    57                                 fprintf(output, "ICMP Redirect (%d) error", error_code);
    58                                 break;
    59                         case ICMP_ALTERNATE_ADDR:
    60                                 fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
    61                                 break;
    62                         case ICMP_ROUTER_ADV:
    63                                 fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
    64                                 break;
    65                         case ICMP_ROUTER_SOL:
    66                                 fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
    67                                 break;
    68                         case ICMP_TIME_EXCEEDED:
    69                                 fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
    70                                 break;
    71                         case ICMP_PARAMETERPROB:
    72                                 fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
    73                                 break;
    74                         case ICMP_CONVERSION_ERROR:
    75                                 fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
    76                                 break;
    77                         case ICMP_REDIRECT_MOBILE:
    78                                 fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
    79                                 break;
    80                         case ICMP_SKIP:
    81                                 fprintf(output, "ICMP SKIP (%d) error", error_code);
    82                                 break;
    83                         case ICMP_PHOTURIS:
    84                                 fprintf(output, "ICMP Photuris (%d) error", error_code);
    85                                 break;
    86                         default:
    87                                 fprintf(output, "Other (%d) error", error_code);
    88                 }
    89                 if(suffix){
    90                         fprintf(output, "%s", suffix);
    91                 }
    92         }
     100        if (suffix)
     101                fprintf(output, "%s", suffix);
    93102}
    94103
    95 void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    96         if(IS_ICMP_ERROR(error_code)){
     104/** Prints the error description.
     105 *
     106 * Supports ICMP and socket error codes.
     107 *
     108 * @param[in] output The description output stream. May be NULL.
     109 * @param[in] error_code The error code.
     110 * @param[in] prefix The error description prefix. May be NULL.
     111 * @param[in] suffix The error description suffix. May be NULL.
     112 */
     113void print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
     114{
     115        if (IS_ICMP_ERROR(error_code))
    97116                icmp_print_error(output, error_code, prefix, suffix);
    98         }else if(IS_SOCKET_ERROR(error_code)){
     117        else if(IS_SOCKET_ERROR(error_code))
    99118                socket_print_error(output, error_code, prefix, suffix);
    100         }
    101119}
    102120
    103 void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
    104         if(output){
    105                 if(prefix){
    106                         fprintf(output, "%s", prefix);
    107                 }
    108                 switch(error_code){
    109                         case ENOTSOCK:
    110                                 fprintf(output, "Not a socket (%d) error", error_code);
    111                                 break;
    112                         case EPROTONOSUPPORT:
    113                                 fprintf(output, "Protocol not supported (%d) error", error_code);
    114                                 break;
    115                         case ESOCKTNOSUPPORT:
    116                                 fprintf(output, "Socket type not supported (%d) error", error_code);
    117                                 break;
    118                         case EPFNOSUPPORT:
    119                                 fprintf(output, "Protocol family not supported (%d) error", error_code);
    120                                 break;
    121                         case EAFNOSUPPORT:
    122                                 fprintf(output, "Address family not supported (%d) error", error_code);
    123                                 break;
    124                         case EADDRINUSE:
    125                                 fprintf(output, "Address already in use (%d) error", error_code);
    126                                 break;
    127                         case ENOTCONN:
    128                                 fprintf(output, "Socket not connected (%d) error", error_code);
    129                                 break;
    130                         case NO_DATA:
    131                                 fprintf(output, "No data (%d) error", error_code);
    132                                 break;
    133                         case EINPROGRESS:
    134                                 fprintf(output, "Another operation in progress (%d) error", error_code);
    135                                 break;
    136                         case EDESTADDRREQ:
    137                                 fprintf(output, "Destination address required (%d) error", error_code);
    138                         case TRY_AGAIN:
    139                                 fprintf(output, "Try again (%d) error", error_code);
    140                         default:
    141                                 fprintf(output, "Other (%d) error", error_code);
    142                 }
    143                 if(suffix){
    144                         fprintf(output, "%s", suffix);
    145                 }
     121/** Prints the specific socket error description.
     122 *
     123 * @param[in] output The description output stream. May be NULL.
     124 * @param[in] error_code The socket error code.
     125 * @param[in] prefix The error description prefix. May be NULL.
     126 * @param[in] suffix The error description suffix. May be NULL.
     127 */
     128void socket_print_error(FILE *output, int error_code, const char *prefix, const char *suffix)
     129{
     130        if (!output)
     131                return;
     132
     133        if (prefix)
     134                fprintf(output, "%s", prefix);
     135
     136        switch (error_code) {
     137        case ENOTSOCK:
     138                fprintf(output, "Not a socket (%d) error", error_code);
     139                break;
     140        case EPROTONOSUPPORT:
     141                fprintf(output, "Protocol not supported (%d) error", error_code);
     142                break;
     143        case ESOCKTNOSUPPORT:
     144                fprintf(output, "Socket type not supported (%d) error", error_code);
     145                break;
     146        case EPFNOSUPPORT:
     147                fprintf(output, "Protocol family not supported (%d) error", error_code);
     148                break;
     149        case EAFNOSUPPORT:
     150                fprintf(output, "Address family not supported (%d) error", error_code);
     151                break;
     152        case EADDRINUSE:
     153                fprintf(output, "Address already in use (%d) error", error_code);
     154                break;
     155        case ENOTCONN:
     156                fprintf(output, "Socket not connected (%d) error", error_code);
     157                break;
     158        case NO_DATA:
     159                fprintf(output, "No data (%d) error", error_code);
     160                break;
     161        case EINPROGRESS:
     162                fprintf(output, "Another operation in progress (%d) error", error_code);
     163                break;
     164        case EDESTADDRREQ:
     165                fprintf(output, "Destination address required (%d) error", error_code);
     166        case TRY_AGAIN:
     167                fprintf(output, "Try again (%d) error", error_code);
     168        default:
     169                fprintf(output, "Other (%d) error", error_code);
    146170        }
     171
     172        if (suffix)
     173                fprintf(output, "%s", suffix);
    147174}
    148175
    149176/** @}
    150177 */
     178
  • uspace/app/netecho/print_error.h

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup net_app
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Generic application error printing functions.
     34 * Generic application error printing functions.
    3535 */
    3636
    37 #ifndef __NET_APP_PRINT__
    38 #define __NET_APP_PRINT__
     37#ifndef NET_APP_PRINT_
     38#define NET_APP_PRINT_
     39
     40#include <stdio.h>
    3941
    4042/** Returns whether the error code may be an ICMP error code.
    41  *  @param[in] error_code The error code.
    42  *  @returns A value indicating whether the error code may be an ICMP error code.
     43 *
     44 * @param[in] error_code The error code.
     45 * @returns A value indicating whether the error code may be an ICMP error code.
    4346 */
    44 #define IS_ICMP_ERROR(error_code)               ((error_code) > 0)
     47#define IS_ICMP_ERROR(error_code)       ((error_code) > 0)
    4548
    4649/** Returns whether the error code may be socket error code.
    47  *  @param[in] error_code The error code.
    48  *  @returns A value indicating whether the error code may be a socket error code.
     50 *
     51 * @param[in] error_code The error code.
     52 * @returns A value indicating whether the error code may be a socket error code.
    4953 */
    5054#define IS_SOCKET_ERROR(error_code)     ((error_code) < 0)
    5155
    52 /** Prints the specific ICMP error description.
    53  *  @param[in] output The description output stream. May be NULL.
    54  *  @param[in] error_code The ICMP error code.
    55  *  @param[in] prefix The error description prefix. May be NULL.
    56  *  @param[in] suffix The error description suffix. May be NULL.
    57  */
    58 extern void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
    59 
    60 /** Prints the error description.
    61  *  Supports ICMP and socket error codes.
    62  *  @param[in] output The description output stream. May be NULL.
    63  *  @param[in] error_code The error code.
    64  *  @param[in] prefix The error description prefix. May be NULL.
    65  *  @param[in] suffix The error description suffix. May be NULL.
    66  */
    67 extern void print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
    68 
    69 /** Prints the specific socket error description.
    70  *  @param[in] output The description output stream. May be NULL.
    71  *  @param[in] error_code The socket error code.
    72  *  @param[in] prefix The error description prefix. May be NULL.
    73  *  @param[in] suffix The error description suffix. May be NULL.
    74  */
    75 extern void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
     56extern void icmp_print_error(FILE *, int, const char *, const char *);
     57extern void print_error(FILE *, int, const char *, const char *);
     58extern void socket_print_error(FILE *, int, const char *, const char *);
    7659
    7760#endif
  • uspace/app/nettest1/nettest.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup nettest
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking test support functions implementation.
     34 * Networking test support functions implementation.
    3535 */
    3636
     
    4343#include "print_error.h"
    4444
    45 int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
    46         int index;
    47 
    48         if(verbose){
     45
     46/** Creates new sockets.
     47 *
     48 * @param[in] verbose A value indicating whether to print out verbose information.
     49 * @param[out] socket_ids A field to store the socket identifiers.
     50 * @param[in] sockets The number of sockets to create. Should be at most the size of the field.
     51 * @param[in] family The socket address family.
     52 * @param[in] type The socket type.
     53 * @returns EOK on success.
     54 * @returns Other error codes as defined for the socket() function.
     55 */
     56int sockets_create(int verbose, int *socket_ids, int sockets, int family, sock_type_t type)
     57{
     58        int index;
     59
     60        if (verbose)
    4961                printf("Create\t");
    50         }
    51         fflush(stdout);
    52         for(index = 0; index < sockets; ++ index){
     62               
     63        fflush(stdout);
     64       
     65        for (index = 0; index < sockets; index++) {
    5366                socket_ids[index] = socket(family, type, 0);
    54                 if(socket_ids[index] < 0){
     67                if (socket_ids[index] < 0) {
    5568                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
    5669                        socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
    5770                        return socket_ids[index];
    5871                }
    59                 if(verbose){
    60                         print_mark(index);
    61                 }
    62         }
    63         return EOK;
    64 }
    65 
    66 int sockets_close(int verbose, int * socket_ids, int sockets){
    67         ERROR_DECLARE;
    68 
    69         int index;
    70 
    71         if(verbose){
     72                if (verbose)
     73                        print_mark(index);
     74        }
     75       
     76        return EOK;
     77}
     78
     79/** Closes sockets.
     80 *
     81 * @param[in] verbose A value indicating whether to print out verbose information.
     82 * @param[in] socket_ids A field of stored socket identifiers.
     83 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     84 * @returns EOK on success.
     85 * @returns Other error codes as defined for the closesocket() function.
     86 */
     87int sockets_close(int verbose, int *socket_ids, int sockets)
     88{
     89        ERROR_DECLARE;
     90
     91        int index;
     92
     93        if (verbose)
    7294                printf("\tClose\t");
    73         }
    74         fflush(stdout);
    75         for(index = 0; index < sockets; ++ index){
    76                 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
     95
     96        fflush(stdout);
     97       
     98        for (index = 0; index < sockets; index++) {
     99                if (ERROR_OCCURRED(closesocket(socket_ids[index]))) {
    77100                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
    78101                        socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
    79102                        return ERROR_CODE;
    80103                }
    81                 if(verbose){
    82                         print_mark(index);
    83                 }
    84         }
    85         return EOK;
    86 }
    87 
    88 int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){
    89         ERROR_DECLARE;
    90 
    91         int index;
    92 
    93         if(verbose){
     104                if (verbose)
     105                        print_mark(index);
     106        }
     107       
     108        return EOK;
     109}
     110
     111/** Connects sockets.
     112 *
     113 * @param[in] verbose A value indicating whether to print out verbose information.
     114 * @param[in] socket_ids A field of stored socket identifiers.
     115 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     116 * @param[in] address The destination host address to connect to.
     117 * @param[in] addrlen The length of the destination address in bytes.
     118 * @returns EOK on success.
     119 * @returns Other error codes as defined for the connect() function.
     120 */
     121int sockets_connect(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen)
     122{
     123        ERROR_DECLARE;
     124
     125        int index;
     126
     127        if (verbose)
    94128                printf("\tConnect\t");
    95         }
    96         fflush(stdout);
    97         for(index = 0; index < sockets; ++ index){
    98                 if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
     129       
     130        fflush(stdout);
     131       
     132        for (index = 0; index < sockets; index++) {
     133                if (ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))) {
    99134                        socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
    100135                        return ERROR_CODE;
    101136                }
    102                 if(verbose){
    103                         print_mark(index);
    104                 }
    105         }
    106         return EOK;
    107 }
    108 
    109 int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){
     137                if (verbose)
     138                        print_mark(index);
     139        }
     140       
     141        return EOK;
     142}
     143
     144/** Sends data via sockets.
     145 *
     146 * @param[in] verbose A value indicating whether to print out verbose information.
     147 * @param[in] socket_ids A field of stored socket identifiers.
     148 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     149 * @param[in] address The destination host address to send data to.
     150 * @param[in] addrlen The length of the destination address in bytes.
     151 * @param[in] data The data to be sent.
     152 * @param[in] size The data size in bytes.
     153 * @param[in] messages The number of datagrams per socket to be sent.
     154 * @returns EOK on success.
     155 * @returns Other error codes as defined for the sendto() function.
     156 */
     157int sockets_sendto(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen, char *data, int size, int messages)
     158{
    110159        ERROR_DECLARE;
    111160
     
    113162        int message;
    114163
    115         if(verbose){
     164        if (verbose)
    116165                printf("\tSendto\t");
    117         }
    118         fflush(stdout);
    119         for(index = 0; index < sockets; ++ index){
    120                 for(message = 0; message < messages; ++ message){
    121                         if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){
     166
     167        fflush(stdout);
     168       
     169        for (index = 0; index < sockets; index++) {
     170                for (message = 0; message < messages; message++) {
     171                        if (ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))) {
    122172                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    123173                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     
    125175                        }
    126176                }
    127                 if(verbose){
    128                         print_mark(index);
    129                 }
    130         }
    131         return EOK;
    132 }
    133 
    134 int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     177                if (verbose)
     178                        print_mark(index);
     179        }
     180       
     181        return EOK;
     182}
     183
     184/** Receives data via sockets.
     185 *
     186 * @param[in] verbose A value indicating whether to print out verbose information.
     187 * @param[in] socket_ids A field of stored socket identifiers.
     188 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     189 * @param[in] address The source host address of received datagrams.
     190 * @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
     191 * @param[out] data The received data.
     192 * @param[in] size The maximum data size in bytes.
     193 * @param[in] messages The number of datagrams per socket to be received.
     194 * @returns EOK on success.
     195 * @returns Other error codes as defined for the recvfrom() function.
     196 */
     197int sockets_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
     198{
    135199        int value;
    136200        int index;
    137201        int message;
    138202
    139         if(verbose){
     203        if (verbose)
    140204                printf("\tRecvfrom\t");
    141         }
    142         fflush(stdout);
    143         for(index = 0; index < sockets; ++ index){
    144                 for(message = 0; message < messages; ++ message){
     205       
     206        fflush(stdout);
     207       
     208        for (index = 0; index < sockets; index++) {
     209                for (message = 0; message < messages; message++) {
    145210                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
    146                         if(value < 0){
     211                        if (value < 0) {
    147212                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    148213                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     
    150215                        }
    151216                }
    152                 if(verbose){
    153                         print_mark(index);
    154                 }
    155         }
    156         return EOK;
    157 }
    158 
    159 int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
     217                if (verbose)
     218                        print_mark(index);
     219        }
     220        return EOK;
     221}
     222
     223/** Sends and receives data via sockets.
     224 *
     225 * Each datagram is sent and a reply read consequently.
     226 * The next datagram is sent after the reply is received.
     227 *
     228 * @param[in] verbose A value indicating whether to print out verbose information.
     229 * @param[in] socket_ids A field of stored socket identifiers.
     230 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
     231 * @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
     232 * @param[in] addrlen The length of the destination address in bytes.
     233 * @param[in,out] data The data to be sent. The received data are set instead.
     234 * @param[in] size The data size in bytes.
     235 * @param[in] messages The number of datagrams per socket to be received.
     236 * @returns EOK on success.
     237 * @returns Other error codes as defined for the recvfrom() function.
     238 */
     239int sockets_sendto_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
     240{
    160241        ERROR_DECLARE;
    161242
     
    164245        int message;
    165246
    166         if(verbose){
     247        if (verbose)
    167248                printf("\tSendto and recvfrom\t");
    168         }
    169         fflush(stdout);
    170         for(index = 0; index < sockets; ++ index){
    171                 for(message = 0; message < messages; ++ message){
    172                         if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){
     249
     250        fflush(stdout);
     251       
     252        for (index = 0; index < sockets; index++) {
     253                for (message = 0; message < messages; message++) {
     254                        if (ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, *addrlen))) {
    173255                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    174256                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     
    176258                        }
    177259                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
    178                         if(value < 0){
     260                        if (value < 0) {
    179261                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    180262                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     
    182264                        }
    183265                }
    184                 if(verbose){
    185                         print_mark(index);
    186                 }
    187         }
    188         return EOK;
    189 }
    190 
    191 void print_mark(int index){
    192         if((index + 1) % 10){
     266                if (verbose)
     267                        print_mark(index);
     268        }
     269       
     270        return EOK;
     271}
     272
     273/** Prints a mark.
     274 *
     275 * If the index is a multiple of ten, a different mark is printed.
     276 *
     277 * @param[in] index The index of the mark to be printed.
     278 */
     279void print_mark(int index)
     280{
     281        if ((index + 1) % 10)
    193282                printf("*");
    194         }else{
     283        else
    195284                printf("|");
    196         }
    197285        fflush(stdout);
    198286}
  • uspace/app/nettest1/nettest.h

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup nettest
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking test support functions.
     34 * Networking test support functions.
    3535 */
    3636
    37 #ifndef __NET_TEST__
    38 #define __NET_TEST__
     37#ifndef NET_TEST_
     38#define NET_TEST_
    3939
    4040#include <net/socket.h>
    4141
    42 /** Prints a mark.
    43  *  If the index is a multiple of ten, a different mark is printed.
    44  *  @param[in] index The index of the mark to be printed.
    45  */
    46 extern void print_mark(int index);
    47 
    48 /** Creates new sockets.
    49  *  @param[in] verbose A value indicating whether to print out verbose information.
    50  *  @param[out] socket_ids A field to store the socket identifiers.
    51  *  @param[in] sockets The number of sockets to create. Should be at most the size of the field.
    52  *  @param[in] family The socket address family.
    53  *  @param[in] type The socket type.
    54  *  @returns EOK on success.
    55  *  @returns Other error codes as defined for the socket() function.
    56  */
    57 extern int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type);
    58 
    59 /** Closes sockets.
    60  *  @param[in] verbose A value indicating whether to print out verbose information.
    61  *  @param[in] socket_ids A field of stored socket identifiers.
    62  *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
    63  *  @returns EOK on success.
    64  *  @returns Other error codes as defined for the closesocket() function.
    65  */
    66 extern int sockets_close(int verbose, int * socket_ids, int sockets);
    67 
    68 /** Connects sockets.
    69  *  @param[in] verbose A value indicating whether to print out verbose information.
    70  *  @param[in] socket_ids A field of stored socket identifiers.
    71  *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
    72  *  @param[in] address The destination host address to connect to.
    73  *  @param[in] addrlen The length of the destination address in bytes.
    74  *  @returns EOK on success.
    75  *  @returns Other error codes as defined for the connect() function.
    76  */
    77 extern int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen);
    78 
    79 /** Sends data via sockets.
    80  *  @param[in] verbose A value indicating whether to print out verbose information.
    81  *  @param[in] socket_ids A field of stored socket identifiers.
    82  *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
    83  *  @param[in] address The destination host address to send data to.
    84  *  @param[in] addrlen The length of the destination address in bytes.
    85  *  @param[in] data The data to be sent.
    86  *  @param[in] size The data size in bytes.
    87  *  @param[in] messages The number of datagrams per socket to be sent.
    88  *  @returns EOK on success.
    89  *  @returns Other error codes as defined for the sendto() function.
    90  */
    91 extern int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages);
    92 
    93 /** Receives data via sockets.
    94  *  @param[in] verbose A value indicating whether to print out verbose information.
    95  *  @param[in] socket_ids A field of stored socket identifiers.
    96  *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
    97  *  @param[in] address The source host address of received datagrams.
    98  *  @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
    99  *  @param[out] data The received data.
    100  *  @param[in] size The maximum data size in bytes.
    101  *  @param[in] messages The number of datagrams per socket to be received.
    102  *  @returns EOK on success.
    103  *  @returns Other error codes as defined for the recvfrom() function.
    104  */
    105 extern int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
    106 
    107 /** Sends and receives data via sockets.
    108  *  Each datagram is sent and a reply read consequently.
    109  *  The next datagram is sent after the reply is received.
    110  *  @param[in] verbose A value indicating whether to print out verbose information.
    111  *  @param[in] socket_ids A field of stored socket identifiers.
    112  *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
    113  *  @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
    114  *  @param[in] addrlen The length of the destination address in bytes.
    115  *  @param[in,out] data The data to be sent. The received data are set instead.
    116  *  @param[in] size The data size in bytes.
    117  *  @param[in] messages The number of datagrams per socket to be received.
    118  *  @returns EOK on success.
    119  *  @returns Other error codes as defined for the recvfrom() function.
    120  */
    121 extern int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
     42extern void print_mark(int);
     43extern int sockets_create(int, int *, int, int, sock_type_t);
     44extern int sockets_close(int, int *, int);
     45extern int sockets_connect(int, int *, int, struct sockaddr *, socklen_t);
     46extern int sockets_sendto(int, int *, int, struct sockaddr *, socklen_t, char *, int, int);
     47extern int sockets_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int);
     48extern int sockets_sendto_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int);
    12249
    12350#endif
     
    12552/** @}
    12653 */
     54
  • uspace/app/nettest1/nettest1.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup nettest
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking test 1 application - sockets.
    35  */
     34 * Networking test 1 application - sockets.
     35 */
     36
     37#include "nettest.h"
     38#include "print_error.h"
    3639
    3740#include <malloc.h>
     
    4952#include <net/socket_parse.h>
    5053
    51 #include "nettest.h"
    52 #include "print_error.h"
    53 
    54 /** Echo module name.
    55  */
     54/** Echo module name. */
    5655#define NAME    "Nettest1"
    5756
    58 /** Packet data pattern.
    59  */
     57/** Packet data pattern. */
    6058#define NETTEST1_TEXT   "Networking test 1 - sockets"
    6159
    62 /** Module entry point.
    63  *  Starts testing.
    64  *  @param[in] argc The number of command line parameters.
    65  *  @param[in] argv The command line parameters.
    66  *  @returns EOK on success.
    67  */
    68 int main(int argc, char * argv[]);
    69 
    70 /** Prints the application help.
    71  */
    72 void nettest1_print_help(void);
    73 
    74 /** Refreshes the data.
    75  *  Fills the data block with the NETTEST1_TEXT pattern.
    76  *  @param[out] data The data block.
    77  *  @param[in] size The data block size in bytes.
    78  */
    79 void nettest1_refresh_data(char * data, size_t size);
    80 
    81 int main(int argc, char * argv[]){
    82         ERROR_DECLARE;
    83 
    84         size_t size                     = 27;
    85         int verbose                     = 0;
    86         sock_type_t type        = SOCK_DGRAM;
    87         int sockets                     = 10;
    88         int messages            = 10;
    89         int family                      = PF_INET;
    90         uint16_t port           = 7;
    91 
    92         socklen_t max_length                            = sizeof(struct sockaddr_in6);
    93         uint8_t address_data[max_length];
    94         struct sockaddr * address                       = (struct sockaddr *) address_data;
    95         struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    96         struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
    97         socklen_t addrlen;
    98 //      char address_string[INET6_ADDRSTRLEN];
    99         uint8_t * address_start;
    100 
    101         int * socket_ids;
    102         char * data;
    103         int value;
    104         int index;
    105         struct timeval time_before;
    106         struct timeval time_after;
    107 
    108         // parse the command line arguments
    109         // stop before the last argument if it does not start with the minus sign ('-')
    110         for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
    111                 // options should start with the minus sign ('-')
    112                 if(argv[index][0] == '-'){
    113                         switch(argv[index][1]){
    114                                 // short options with only one letter
    115                                 case 'f':
    116                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
    117                                         break;
    118                                 case 'h':
    119                                         nettest1_print_help();
    120                                         return EOK;
    121                                         break;
    122                                 case 'm':
    123                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
    124                                         break;
    125                                 case 'n':
    126                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
    127                                         break;
    128                                 case 'p':
    129                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
    130                                         port = (uint16_t) value;
    131                                         break;
    132                                 case 's':
    133                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
    134                                         size = (value >= 0) ? (size_t) value : 0;
    135                                         break;
    136                                 case 't':
    137                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
    138                                         type = (sock_type_t) value;
    139                                         break;
    140                                 case 'v':
    141                                         verbose = 1;
    142                                         break;
    143                                 // long options with the double minus sign ('-')
    144                                 case '-':
    145                                         if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    146                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
    147                                         }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    148                                                 nettest1_print_help();
    149                                                 return EOK;
    150                                         }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
    151                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
    152                                         }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
    153                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
    154                                         }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
    155                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    156                                                 port = (uint16_t) value;
    157                                         }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    158                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
    159                                                 type = (sock_type_t) value;
    160                                         }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
    161                                                 verbose = 1;
    162                                         }else{
    163                                                 nettest1_print_help();
    164                                                 return EINVAL;
    165                                         }
    166                                         break;
    167                                 default:
    168                                         nettest1_print_help();
    169                                         return EINVAL;
    170                         }
    171                 }else{
    172                         nettest1_print_help();
    173                         return EINVAL;
    174                 }
    175         }
    176 
    177         // if not before the last argument containing the address
    178         if(index >= argc){
    179                 printf("Command line error: missing address\n");
    180                 nettest1_print_help();
    181                 return EINVAL;
    182         }
    183 
    184         // prepare the address buffer
    185         bzero(address_data, max_length);
    186         switch(family){
    187                 case PF_INET:
    188                         address_in->sin_family = AF_INET;
    189                         address_in->sin_port = htons(port);
    190                         address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    191                         addrlen = sizeof(struct sockaddr_in);
    192                         break;
    193                 case PF_INET6:
    194                         address_in6->sin6_family = AF_INET6;
    195                         address_in6->sin6_port = htons(port);
    196                         address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    197                         addrlen = sizeof(struct sockaddr_in6);
    198                         break;
    199                 default:
    200                         fprintf(stderr, "Address family is not supported\n");
    201                         return EAFNOSUPPORT;
    202         }
    203 
    204         // parse the last argument which should contain the address
    205         if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
    206                 fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
    207                 return ERROR_CODE;
    208         }
    209 
    210         // check the buffer size
    211         if(size <= 0){
    212                 fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
    213                 size = 1024;
    214         }
    215 
    216         // prepare the buffer
    217         // size plus the terminating null (\0)
    218         data = (char *) malloc(size + 1);
    219         if(! data){
    220                 fprintf(stderr, "Failed to allocate data buffer.\n");
    221                 return ENOMEM;
    222         }
    223         nettest1_refresh_data(data, size);
    224 
    225         // check the socket count
    226         if(sockets <= 0){
    227                 fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
    228                 sockets = 2;
    229         }
    230 
    231         // prepare the socket buffer
    232         // count plus the terminating null (\0)
    233         socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
    234         if(! socket_ids){
    235                 fprintf(stderr, "Failed to allocate receive buffer.\n");
    236                 return ENOMEM;
    237         }
    238         socket_ids[sockets] = NULL;
    239 
    240         if(verbose){
    241                 printf("Starting tests\n");
    242         }
    243 
    244         if(verbose){
    245                 printf("1 socket, 1 message\n");
    246         }
    247 
    248         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    249                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    250                 return ERROR_CODE;
    251         }
    252 
    253         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    254         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    255         if(verbose){
    256                 printf("\tOK\n");
    257         }
    258 
    259         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    260         if(type == SOCK_STREAM){
    261                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    262         }
    263         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
    264         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    265         if(verbose){
    266                 printf("\tOK\n");
    267         }
    268 
    269         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    270         if(type == SOCK_STREAM){
    271                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    272         }
    273         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
    274         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
    275         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    276         if(verbose){
    277                 printf("\tOK\n");
    278         }
    279 
    280         if(verbose){
    281                 printf("1 socket, %d messages\n", messages);
    282         }
    283 
    284         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    285         if(type == SOCK_STREAM){
    286                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    287         }
    288         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
    289         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    290         if(verbose){
    291                 printf("\tOK\n");
    292         }
    293 
    294         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
    295         if(type == SOCK_STREAM){
    296                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
    297         }
    298         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
    299         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
    300         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
    301         if(verbose){
    302                 printf("\tOK\n");
    303         }
    304 
    305         if(verbose){
    306                 printf("%d sockets, 1 message\n", sockets);
    307         }
    308 
    309         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    310         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    311         if(verbose){
    312                 printf("\tOK\n");
    313         }
    314 
    315         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    316         if(type == SOCK_STREAM){
    317                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    318         }
    319         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
    320         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    321         if(verbose){
    322                 printf("\tOK\n");
    323         }
    324 
    325         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    326         if(type == SOCK_STREAM){
    327                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    328         }
    329         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
    330         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
    331         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    332         if(verbose){
    333                 printf("\tOK\n");
    334         }
    335 
    336         if(verbose){
    337                 printf("%d sockets, %d messages\n", sockets, messages);
    338         }
    339 
    340         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    341         if(type == SOCK_STREAM){
    342                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    343         }
    344         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    345         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    346         if(verbose){
    347                 printf("\tOK\n");
    348         }
    349 
    350         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    351         if(type == SOCK_STREAM){
    352                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    353         }
    354         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
    355         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    356         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    357 
    358         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    359                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    360                 return ERROR_CODE;
    361         }
    362 
    363         if(verbose){
    364                 printf("\tOK\n");
    365         }
    366 
    367         printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    368 
    369         if(verbose){
    370                 printf("Exiting\n");
    371         }
    372 
    373         return EOK;
    374 }
    375 
    376 void nettest1_print_help(void){
     60static void nettest1_print_help(void)
     61{
    37762        printf(
    37863                "Network Networking test 1 aplication - sockets\n" \
     
    40287}
    40388
    404 void nettest1_refresh_data(char * data, size_t size){
     89/** Refreshes the data.
     90 *
     91 * Fills the data block with the NETTEST1_TEXT pattern.
     92 *
     93 * @param[out] data The data block.
     94 * @param[in] size The data block size in bytes.
     95 */
     96static void nettest1_refresh_data(char *data, size_t size)
     97{
    40598        size_t length;
    40699
    407100        // fill the data
    408101        length = 0;
    409         while(size > length + sizeof(NETTEST1_TEXT) - 1){
     102        while (size > length + sizeof(NETTEST1_TEXT) - 1) {
    410103                memcpy(data + length, NETTEST1_TEXT, sizeof(NETTEST1_TEXT) - 1);
    411104                length += sizeof(NETTEST1_TEXT) - 1;
     
    415108}
    416109
     110
     111int main(int argc, char *argv[])
     112{
     113        ERROR_DECLARE;
     114
     115        size_t size = 27;
     116        int verbose = 0;
     117        sock_type_t type = SOCK_DGRAM;
     118        int sockets = 10;
     119        int messages = 10;
     120        int family = PF_INET;
     121        uint16_t port = 7;
     122
     123        socklen_t max_length = sizeof(struct sockaddr_in6);
     124        uint8_t address_data[max_length];
     125        struct sockaddr *address = (struct sockaddr *) address_data;
     126        struct sockaddr_in *address_in = (struct sockaddr_in *) address;
     127        struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address;
     128        socklen_t addrlen;
     129        uint8_t *address_start;
     130
     131        int *socket_ids;
     132        char *data;
     133        int value;
     134        int index;
     135        struct timeval time_before;
     136        struct timeval time_after;
     137
     138        // parse the command line arguments
     139        // stop before the last argument if it does not start with the minus sign ('-')
     140        for (index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); index++) {
     141                // options should start with the minus sign ('-')
     142                if (argv[index][0] == '-') {
     143                        switch (argv[index][1]) {
     144                        // short options with only one letter
     145                        case 'f':
     146                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
     147                                break;
     148                        case 'h':
     149                                nettest1_print_help();
     150                                return EOK;
     151                                break;
     152                        case 'm':
     153                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
     154                                break;
     155                        case 'n':
     156                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
     157                                break;
     158                        case 'p':
     159                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     160                                port = (uint16_t) value;
     161                                break;
     162                        case 's':
     163                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     164                                size = (value >= 0) ? (size_t) value : 0;
     165                                break;
     166                        case 't':
     167                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
     168                                type = (sock_type_t) value;
     169                                break;
     170                        case 'v':
     171                                verbose = 1;
     172                                break;
     173                        // long options with the double minus sign ('-')
     174                        case '-':
     175                                if (str_lcmp(argv[index] + 2, "family=", 7) == 0) {
     176                                        ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
     177                                } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) {
     178                                        nettest1_print_help();
     179                                        return EOK;
     180                                } else if (str_lcmp(argv[index] + 2, "messages=", 6) == 0) {
     181                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
     182                                } else if (str_lcmp(argv[index] + 2, "sockets=", 6) == 0) {
     183                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
     184                                } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) {
     185                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
     186                                        port = (uint16_t) value;
     187                                } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) {
     188                                        ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
     189                                        type = (sock_type_t) value;
     190                                } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) {
     191                                        verbose = 1;
     192                                } else {
     193                                        nettest1_print_help();
     194                                        return EINVAL;
     195                                }
     196                                break;
     197                        default:
     198                                nettest1_print_help();
     199                                return EINVAL;
     200                        }
     201                } else {
     202                        nettest1_print_help();
     203                        return EINVAL;
     204                }
     205        }
     206
     207        // if not before the last argument containing the address
     208        if (index >= argc) {
     209                printf("Command line error: missing address\n");
     210                nettest1_print_help();
     211                return EINVAL;
     212        }
     213
     214        // prepare the address buffer
     215        bzero(address_data, max_length);
     216        switch (family) {
     217        case PF_INET:
     218                address_in->sin_family = AF_INET;
     219                address_in->sin_port = htons(port);
     220                address_start = (uint8_t *) &address_in->sin_addr.s_addr;
     221                addrlen = sizeof(struct sockaddr_in);
     222                break;
     223        case PF_INET6:
     224                address_in6->sin6_family = AF_INET6;
     225                address_in6->sin6_port = htons(port);
     226                address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
     227                addrlen = sizeof(struct sockaddr_in6);
     228                break;
     229        default:
     230                fprintf(stderr, "Address family is not supported\n");
     231                return EAFNOSUPPORT;
     232        }
     233
     234        // parse the last argument which should contain the address
     235        if (ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))) {
     236                fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
     237                return ERROR_CODE;
     238        }
     239
     240        // check the buffer size
     241        if (size <= 0) {
     242                fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
     243                size = 1024;
     244        }
     245
     246        // prepare the buffer
     247        // size plus the terminating null (\0)
     248        data = (char *) malloc(size + 1);
     249        if (!data) {
     250                fprintf(stderr, "Failed to allocate data buffer.\n");
     251                return ENOMEM;
     252        }
     253        nettest1_refresh_data(data, size);
     254
     255        // check the socket count
     256        if (sockets <= 0) {
     257                fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
     258                sockets = 2;
     259        }
     260
     261        // prepare the socket buffer
     262        // count plus the terminating null (\0)
     263        socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
     264        if (!socket_ids) {
     265                fprintf(stderr, "Failed to allocate receive buffer.\n");
     266                return ENOMEM;
     267        }
     268        socket_ids[sockets] = NULL;
     269
     270        if (verbose)
     271                printf("Starting tests\n");
     272
     273        if (verbose)
     274                printf("1 socket, 1 message\n");
     275
     276        if (ERROR_OCCURRED(gettimeofday(&time_before, NULL))) {
     277                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     278                return ERROR_CODE;
     279        }
     280
     281        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     282        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     283        if (verbose)
     284                printf("\tOK\n");
     285
     286        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     287        if (type == SOCK_STREAM)
     288                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     289        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
     290        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     291        if (verbose)
     292                printf("\tOK\n");
     293
     294        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     295        if (type == SOCK_STREAM)
     296                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     297        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
     298        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
     299        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     300        if (verbose)
     301                printf("\tOK\n");
     302
     303        if (verbose)
     304                printf("1 socket, %d messages\n", messages);
     305
     306        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     307        if (type == SOCK_STREAM)
     308                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     309        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
     310        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     311        if (verbose)
     312                printf("\tOK\n");
     313
     314        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
     315        if (type == SOCK_STREAM)
     316                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
     317        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
     318        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
     319        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
     320        if (verbose)
     321                printf("\tOK\n");
     322
     323        if (verbose)
     324                printf("%d sockets, 1 message\n", sockets);
     325
     326        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     327        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     328        if (verbose)
     329                printf("\tOK\n");
     330
     331        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     332        if (type == SOCK_STREAM)
     333                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     334        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
     335        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     336        if (verbose)
     337                printf("\tOK\n");
     338
     339        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     340        if (type == SOCK_STREAM)
     341                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     342        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
     343        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
     344        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     345        if (verbose)
     346                printf("\tOK\n");
     347
     348        if (verbose)
     349                printf("%d sockets, %d messages\n", sockets, messages);
     350
     351        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     352        if (type == SOCK_STREAM)
     353                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     354        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     355        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     356        if (verbose)
     357                printf("\tOK\n");
     358
     359        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     360        if (type == SOCK_STREAM)
     361                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     362        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
     363        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     364        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     365
     366        if (ERROR_OCCURRED(gettimeofday(&time_after, NULL))) {
     367                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     368                return ERROR_CODE;
     369        }
     370
     371        if (verbose)
     372                printf("\tOK\n");
     373
     374        printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     375
     376        if (verbose)
     377                printf("Exiting\n");
     378
     379        return EOK;
     380}
     381
     382
    417383/** @}
    418384 */
  • uspace/app/nettest2/nettest2.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup nettest
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking test 2 application - transfer.
    35  */
     34 * Networking test 2 application - transfer.
     35 */
     36
     37#include "nettest.h"
     38#include "print_error.h"
    3639
    3740#include <malloc.h>
     
    4952#include <net/socket_parse.h>
    5053
    51 #include "nettest.h"
    52 #include "print_error.h"
    53 
    54 /** Echo module name.
    55  */
     54/** Echo module name. */
    5655#define NAME    "Nettest2"
    5756
    58 /** Packet data pattern.
    59  */
     57/** Packet data pattern. */
    6058#define NETTEST2_TEXT   "Networking test 2 - transfer"
    6159
    62 /** Module entry point.
    63  *  Starts testing.
    64  *  @param[in] argc The number of command line parameters.
    65  *  @param[in] argv The command line parameters.
    66  *  @returns EOK on success.
    67  */
    68 int main(int argc, char * argv[]);
    69 
    70 /** Prints the application help.
    71  */
    72 void nettest2_print_help(void);
    73 
    74 /** Refreshes the data.
    75  *  Fills the data block with the NETTEST1_TEXT pattern.
    76  *  @param[out] data The data block.
    77  *  @param[in] size The data block size in bytes.
    78  */
    79 void nettest2_refresh_data(char * data, size_t size);
    80 
    81 int main(int argc, char * argv[]){
    82         ERROR_DECLARE;
    83 
    84         size_t size                     = 28;
    85         int verbose                     = 0;
    86         sock_type_t type        = SOCK_DGRAM;
    87         int sockets                     = 10;
    88         int messages            = 10;
    89         int family                      = PF_INET;
    90         uint16_t port           = 7;
    91 
    92         socklen_t max_length                            = sizeof(struct sockaddr_in6);
    93         uint8_t address_data[max_length];
    94         struct sockaddr * address                       = (struct sockaddr *) address_data;
    95         struct sockaddr_in * address_in         = (struct sockaddr_in *) address;
    96         struct sockaddr_in6 * address_in6       = (struct sockaddr_in6 *) address;
    97         socklen_t addrlen;
    98 //      char address_string[INET6_ADDRSTRLEN];
    99         uint8_t * address_start;
    100 
    101         int * socket_ids;
    102         char * data;
    103         int value;
    104         int index;
    105         struct timeval time_before;
    106         struct timeval time_after;
    107 
    108         // parse the command line arguments
    109         // stop before the last argument if it does not start with the minus sign ('-')
    110         for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
    111                 // options should start with the minus sign ('-')
    112                 if(argv[index][0] == '-'){
    113                         switch(argv[index][1]){
    114                                 // short options with only one letter
    115                                 case 'f':
    116                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
    117                                         break;
    118                                 case 'h':
    119                                         nettest2_print_help();
    120                                         return EOK;
    121                                         break;
    122                                 case 'm':
    123                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
    124                                         break;
    125                                 case 'n':
    126                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
    127                                         break;
    128                                 case 'p':
    129                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
    130                                         port = (uint16_t) value;
    131                                         break;
    132                                 case 's':
    133                                         ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
    134                                         size = (value >= 0) ? (size_t) value : 0;
    135                                         break;
    136                                 case 't':
    137                                         ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
    138                                         type = (sock_type_t) value;
    139                                         break;
    140                                 case 'v':
    141                                         verbose = 1;
    142                                         break;
    143                                 // long options with the double minus sign ('-')
    144                                 case '-':
    145                                         if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
    146                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
    147                                         }else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
    148                                                 nettest2_print_help();
    149                                                 return EOK;
    150                                         }else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
    151                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
    152                                         }else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
    153                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
    154                                         }else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
    155                                                 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
    156                                                 port = (uint16_t) value;
    157                                         }else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
    158                                                 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
    159                                                 type = (sock_type_t) value;
    160                                         }else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
    161                                                 verbose = 1;
    162                                         }else{
    163                                                 nettest2_print_help();
    164                                                 return EINVAL;
    165                                         }
    166                                         break;
    167                                 default:
    168                                         nettest2_print_help();
    169                                         return EINVAL;
    170                         }
    171                 }else{
    172                         nettest2_print_help();
    173                         return EINVAL;
    174                 }
    175         }
    176 
    177         // if not before the last argument containing the address
    178         if(index >= argc){
    179                 printf("Command line error: missing address\n");
    180                 nettest2_print_help();
    181                 return EINVAL;
    182         }
    183 
    184         // prepare the address buffer
    185         bzero(address_data, max_length);
    186         switch(family){
    187                 case PF_INET:
    188                         address_in->sin_family = AF_INET;
    189                         address_in->sin_port = htons(port);
    190                         address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    191                         addrlen = sizeof(struct sockaddr_in);
    192                         break;
    193                 case PF_INET6:
    194                         address_in6->sin6_family = AF_INET6;
    195                         address_in6->sin6_port = htons(port);
    196                         address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    197                         addrlen = sizeof(struct sockaddr_in6);
    198                         break;
    199                 default:
    200                         fprintf(stderr, "Address family is not supported\n");
    201                         return EAFNOSUPPORT;
    202         }
    203 
    204         // parse the last argument which should contain the address
    205         if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
    206                 fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
    207                 return ERROR_CODE;
    208         }
    209 
    210         // check the buffer size
    211         if(size <= 0){
    212                 fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
    213                 size = 1024;
    214         }
    215 
    216         // prepare the buffer
    217         // size plus terminating null (\0)
    218         data = (char *) malloc(size + 1);
    219         if(! data){
    220                 fprintf(stderr, "Failed to allocate data buffer.\n");
    221                 return ENOMEM;
    222         }
    223         nettest2_refresh_data(data, size);
    224 
    225         // check the socket count
    226         if(sockets <= 0){
    227                 fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
    228                 sockets = 2;
    229         }
    230 
    231         // prepare the socket buffer
    232         // count plus the terminating null (\0)
    233         socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
    234         if(! socket_ids){
    235                 fprintf(stderr, "Failed to allocate receive buffer.\n");
    236                 return ENOMEM;
    237         }
    238         socket_ids[sockets] = NULL;
    239 
    240         if(verbose){
    241                 printf("Starting tests\n");
    242         }
    243 
    244         ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
    245 
    246         if(type == SOCK_STREAM){
    247                 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
    248         }
    249 
    250         if(verbose){
    251                 printf("\n");
    252         }
    253 
    254         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    255                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    256                 return ERROR_CODE;
    257         }
    258 
    259         ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    260 
    261         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    262                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    263                 return ERROR_CODE;
    264         }
    265 
    266         if(verbose){
    267                 printf("\tOK\n");
    268         }
    269 
    270         printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    271 
    272         if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
    273                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    274                 return ERROR_CODE;
    275         }
    276 
    277         ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
    278         ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
    279 
    280         if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
    281                 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
    282                 return ERROR_CODE;
    283         }
    284 
    285         if(verbose){
    286                 printf("\tOK\n");
    287         }
    288 
    289         printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
    290 
    291         ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
    292 
    293         if(verbose){
    294                 printf("\nExiting\n");
    295         }
    296 
    297         return EOK;
    298 }
    299 
    300 void nettest2_print_help(void){
     60static void nettest2_print_help(void)
     61{
    30162        printf(
    30263                "Network Networking test 2 aplication - UDP transfer\n" \
     
    32687}
    32788
    328 void nettest2_refresh_data(char * data, size_t size){
     89/** Refreshes the data.
     90 *
     91 * Fills the data block with the NETTEST1_TEXT pattern.
     92 *
     93 * @param[out] data The data block.
     94 * @param[in] size The data block size in bytes.
     95 */
     96static void nettest2_refresh_data(char *data, size_t size)
     97{
    32998        size_t length;
    33099
    331100        // fill the data
    332101        length = 0;
    333         while(size > length + sizeof(NETTEST2_TEXT) - 1){
     102        while (size > length + sizeof(NETTEST2_TEXT) - 1) {
    334103                memcpy(data + length, NETTEST2_TEXT, sizeof(NETTEST2_TEXT) - 1);
    335104                length += sizeof(NETTEST2_TEXT) - 1;
     
    339108}
    340109
     110
     111int main(int argc, char *argv[])
     112{
     113        ERROR_DECLARE;
     114
     115        size_t size = 28;
     116        int verbose = 0;
     117        sock_type_t type = SOCK_DGRAM;
     118        int sockets = 10;
     119        int messages = 10;
     120        int family = PF_INET;
     121        uint16_t port = 7;
     122
     123        socklen_t max_length = sizeof(struct sockaddr_in6);
     124        uint8_t address_data[max_length];
     125        struct sockaddr *address = (struct sockaddr *) address_data;
     126        struct sockaddr_in *address_in = (struct sockaddr_in *) address;
     127        struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address;
     128        socklen_t addrlen;
     129        uint8_t *address_start;
     130
     131        int *socket_ids;
     132        char *data;
     133        int value;
     134        int index;
     135        struct timeval time_before;
     136        struct timeval time_after;
     137
     138        // parse the command line arguments
     139        // stop before the last argument if it does not start with the minus sign ('-')
     140        for (index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index) {
     141                // options should start with the minus sign ('-')
     142                if (argv[index][0] == '-') {
     143                        switch(argv[index][1]){
     144                        // short options with only one letter
     145                        case 'f':
     146                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
     147                                break;
     148                        case 'h':
     149                                nettest2_print_help();
     150                                return EOK;
     151                                break;
     152                        case 'm':
     153                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
     154                                break;
     155                        case 'n':
     156                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
     157                                break;
     158                        case 'p':
     159                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     160                                port = (uint16_t) value;
     161                                break;
     162                        case 's':
     163                                ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
     164                                size = (value >= 0) ? (size_t) value : 0;
     165                                break;
     166                        case 't':
     167                                ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
     168                                type = (sock_type_t) value;
     169                                break;
     170                        case 'v':
     171                                verbose = 1;
     172                                break;
     173                        // long options with the double minus sign ('-')
     174                        case '-':
     175                                if (str_lcmp(argv[index] + 2, "family=", 7) == 0) {
     176                                        ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
     177                                } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) {
     178                                        nettest2_print_help();
     179                                        return EOK;
     180                                } else if (str_lcmp(argv[index] + 2, "messages=", 6) == 0) {
     181                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
     182                                } else if (str_lcmp(argv[index] + 2, "sockets=", 6) == 0) {
     183                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
     184                                } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) {
     185                                        ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
     186                                        port = (uint16_t) value;
     187                                } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) {
     188                                        ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
     189                                        type = (sock_type_t) value;
     190                                } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) {
     191                                        verbose = 1;
     192                                } else {
     193                                        nettest2_print_help();
     194                                        return EINVAL;
     195                                }
     196                                break;
     197                        default:
     198                                nettest2_print_help();
     199                                return EINVAL;
     200                        }
     201                } else {
     202                        nettest2_print_help();
     203                        return EINVAL;
     204                }
     205        }
     206
     207        // if not before the last argument containing the address
     208        if (index >= argc) {
     209                printf("Command line error: missing address\n");
     210                nettest2_print_help();
     211                return EINVAL;
     212        }
     213
     214        // prepare the address buffer
     215        bzero(address_data, max_length);
     216        switch (family) {
     217        case PF_INET:
     218                address_in->sin_family = AF_INET;
     219                address_in->sin_port = htons(port);
     220                address_start = (uint8_t *) &address_in->sin_addr.s_addr;
     221                addrlen = sizeof(struct sockaddr_in);
     222                break;
     223        case PF_INET6:
     224                address_in6->sin6_family = AF_INET6;
     225                address_in6->sin6_port = htons(port);
     226                address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
     227                addrlen = sizeof(struct sockaddr_in6);
     228                break;
     229        default:
     230                fprintf(stderr, "Address family is not supported\n");
     231                return EAFNOSUPPORT;
     232        }
     233
     234        // parse the last argument which should contain the address
     235        if (ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))) {
     236                fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
     237                return ERROR_CODE;
     238        }
     239
     240        // check the buffer size
     241        if (size <= 0) {
     242                fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
     243                size = 1024;
     244        }
     245
     246        // prepare the buffer
     247        // size plus terminating null (\0)
     248        data = (char *) malloc(size + 1);
     249        if (!data) {
     250                fprintf(stderr, "Failed to allocate data buffer.\n");
     251                return ENOMEM;
     252        }
     253        nettest2_refresh_data(data, size);
     254
     255        // check the socket count
     256        if (sockets <= 0) {
     257                fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
     258                sockets = 2;
     259        }
     260
     261        // prepare the socket buffer
     262        // count plus the terminating null (\0)
     263        socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
     264        if (!socket_ids) {
     265                fprintf(stderr, "Failed to allocate receive buffer.\n");
     266                return ENOMEM;
     267        }
     268        socket_ids[sockets] = NULL;
     269
     270        if (verbose)
     271                printf("Starting tests\n");
     272
     273        ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
     274
     275        if (type == SOCK_STREAM)
     276                ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
     277
     278        if (verbose)
     279                printf("\n");
     280
     281        if (ERROR_OCCURRED(gettimeofday(&time_before, NULL))) {
     282                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     283                return ERROR_CODE;
     284        }
     285
     286        ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     287
     288        if (ERROR_OCCURRED(gettimeofday(&time_after, NULL))) {
     289                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     290                return ERROR_CODE;
     291        }
     292
     293        if (verbose)
     294                printf("\tOK\n");
     295
     296        printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     297
     298        if (ERROR_OCCURRED(gettimeofday(&time_before, NULL))) {
     299                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     300                return ERROR_CODE;
     301        }
     302
     303        ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
     304        ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
     305
     306        if (ERROR_OCCURRED(gettimeofday(&time_after, NULL))) {
     307                fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
     308                return ERROR_CODE;
     309        }
     310
     311        if (verbose)
     312                printf("\tOK\n");
     313
     314        printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
     315
     316        ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
     317
     318        if (verbose)
     319                printf("\nExiting\n");
     320
     321        return EOK;
     322}
     323
    341324/** @}
    342325 */
Note: See TracChangeset for help on using the changeset viewer.