Changeset b40bfac in mainline for uspace/app/nettest1/nettest1.c
- Timestamp:
- 2010-11-08T07:13:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63a1e60
- Parents:
- d70a463 (diff), 3da12d74 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest1.c
rd70a463 rb40bfac 28 28 29 29 /** @addtogroup nettest 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @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" 36 39 37 40 #include <malloc.h> … … 41 44 #include <time.h> 42 45 #include <arg_parse.h> 43 #include <err.h>44 46 45 47 #include <net/in.h> … … 49 51 #include <net/socket_parse.h> 50 52 51 #include "nettest.h" 52 #include "print_error.h" 53 54 /** Echo module name. 55 */ 53 /** Echo module name. */ 56 54 #define NAME "Nettest1" 57 55 58 /** Packet data pattern. 59 */ 56 /** Packet data pattern. */ 60 57 #define NETTEST1_TEXT "Networking test 1 - sockets" 61 58 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; 59 static int family = PF_INET; 60 static sock_type_t type = SOCK_DGRAM; 61 static char *data; 62 static size_t size = 27; 63 static int verbose = 0; 64 65 static struct sockaddr *address; 66 static socklen_t addrlen; 67 68 static int sockets; 69 static int messages; 70 static uint16_t port; 71 72 static void nettest1_print_help(void) 73 { 74 printf( 75 "Network Networking test 1 aplication - sockets\n" 76 "Usage: echo [options] numeric_address\n" 77 "Where options are:\n" 78 "-f protocol_family | --family=protocol_family\n" 79 "\tThe listenning socket protocol family. Only the PF_INET and " 80 "PF_INET6 are supported.\n" 81 "\n" 82 "-h | --help\n" 83 "\tShow this application help.\n" 84 "\n" 85 "-m count | --messages=count\n" 86 "\tThe number of messages to send and receive per socket. The " 87 "default is 10.\n" 88 "\n" 89 "-n sockets | --sockets=count\n" 90 "\tThe number of sockets to use. The default is 10.\n" 91 "\n" 92 "-p port_number | --port=port_number\n" 93 "\tThe port number the application should send messages to. The " 94 "default is 7.\n" 95 "\n" 96 "-s packet_size | --size=packet_size\n" 97 "\tThe packet data size the application sends. The default is " 98 "28 bytes.\n" 99 "\n" 100 "-v | --verbose\n" 101 "\tShow all output messages.\n"); 102 } 103 104 /** Parse one command-line option. 105 * 106 * @param argc Number of all command-line arguments. 107 * @param argv All command-line arguments. 108 * @param index Current argument index (in, out). 109 */ 110 static int nettest1_parse_opt(int argc, char *argv[], int *index) 111 { 103 112 int value; 113 int rc; 114 115 switch (argv[*index][1]) { 116 /* 117 * Short options with only one letter 118 */ 119 case 'f': 120 rc = arg_parse_name_int(argc, argv, index, &family, 0, socket_parse_protocol_family); 121 if (rc != EOK) 122 return rc; 123 break; 124 case 'h': 125 nettest1_print_help(); 126 return EOK; 127 case 'm': 128 rc = arg_parse_int(argc, argv, index, &messages, 0); 129 if (rc != EOK) 130 return rc; 131 break; 132 case 'n': 133 rc = arg_parse_int(argc, argv, index, &sockets, 0); 134 if (rc != EOK) 135 return rc; 136 break; 137 case 'p': 138 rc = arg_parse_int(argc, argv, index, &value, 0); 139 if (rc != EOK) 140 return rc; 141 port = (uint16_t) value; 142 break; 143 case 's': 144 rc = arg_parse_int(argc, argv, index, &value, 0); 145 if (rc != EOK) 146 return rc; 147 size = (value >= 0) ? (size_t) value : 0; 148 break; 149 case 't': 150 rc = arg_parse_name_int(argc, argv, index, &value, 0, socket_parse_socket_type); 151 if (rc != EOK) 152 return rc; 153 type = (sock_type_t) value; 154 break; 155 case 'v': 156 verbose = 1; 157 break; 158 /* 159 * Long options with double dash ('-') 160 */ 161 case '-': 162 if (str_lcmp(argv[*index] + 2, "family=", 7) == 0) { 163 rc = arg_parse_name_int(argc, argv, index, &family, 9, 164 socket_parse_protocol_family); 165 if (rc != EOK) 166 return rc; 167 } else if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 168 nettest1_print_help(); 169 return EOK; 170 } else if (str_lcmp(argv[*index] + 2, "messages=", 6) == 0) { 171 rc = arg_parse_int(argc, argv, index, &messages, 8); 172 if (rc != EOK) 173 return rc; 174 } else if (str_lcmp(argv[*index] + 2, "sockets=", 6) == 0) { 175 rc = arg_parse_int(argc, argv, index, &sockets, 8); 176 if (rc != EOK) 177 return rc; 178 } else if (str_lcmp(argv[*index] + 2, "port=", 5) == 0) { 179 rc = arg_parse_int(argc, argv, index, &value, 7); 180 if (rc != EOK) 181 return rc; 182 port = (uint16_t) value; 183 } else if (str_lcmp(argv[*index] + 2, "type=", 5) == 0) { 184 rc = arg_parse_name_int(argc, argv, index, &value, 7, 185 socket_parse_socket_type); 186 if (rc != EOK) 187 return rc; 188 type = (sock_type_t) value; 189 } else if (str_lcmp(argv[*index] + 2, "verbose", 8) == 0) { 190 verbose = 1; 191 } else { 192 nettest1_print_help(); 193 return EINVAL; 194 } 195 break; 196 default: 197 nettest1_print_help(); 198 return EINVAL; 199 } 200 201 return EOK; 202 } 203 204 /** Fill buffer with the NETTEST1_TEXT pattern. 205 * 206 * @param buffer Data buffer. 207 * @param size Buffer size in bytes. 208 */ 209 static void nettest1_fill_buffer(char *buffer, size_t size) 210 { 211 size_t length; 212 213 length = 0; 214 while (size > length + sizeof(NETTEST1_TEXT) - 1) { 215 memcpy(buffer + length, NETTEST1_TEXT, 216 sizeof(NETTEST1_TEXT) - 1); 217 length += sizeof(NETTEST1_TEXT) - 1; 218 } 219 220 memcpy(buffer + length, NETTEST1_TEXT, size - length); 221 buffer[size] = '\0'; 222 } 223 224 static int nettest1_test(int *socket_ids, int nsockets, int nmessages) 225 { 226 int rc; 227 228 if (verbose) 229 printf("%d sockets, %d messages\n", nsockets, nmessages); 230 231 rc = sockets_create(verbose, socket_ids, nsockets, family, type); 232 if (rc != EOK) 233 return rc; 234 235 if (type == SOCK_STREAM) { 236 rc = sockets_connect(verbose, socket_ids, nsockets, address, 237 addrlen); 238 if (rc != EOK) 239 return rc; 240 } 241 242 rc = sockets_sendto_recvfrom(verbose, socket_ids, nsockets, address, 243 &addrlen, data, size, nmessages); 244 if (rc != EOK) 245 return rc; 246 247 rc = sockets_close(verbose, socket_ids, nsockets); 248 if (rc != EOK) 249 return rc; 250 251 if (verbose) 252 printf("\tOK\n"); 253 254 /****/ 255 256 rc = sockets_create(verbose, socket_ids, nsockets, family, type); 257 if (rc != EOK) 258 return rc; 259 260 if (type == SOCK_STREAM) { 261 rc = sockets_connect(verbose, socket_ids, nsockets, address, 262 addrlen); 263 if (rc != EOK) 264 return rc; 265 } 266 267 rc = sockets_sendto(verbose, socket_ids, nsockets, address, addrlen, 268 data, size, nmessages); 269 if (rc != EOK) 270 return rc; 271 272 rc = sockets_recvfrom(verbose, socket_ids, nsockets, address, &addrlen, 273 data, size, nmessages); 274 if (rc != EOK) 275 return rc; 276 277 rc = sockets_close(verbose, socket_ids, nsockets); 278 if (rc != EOK) 279 return rc; 280 281 if (verbose) 282 printf("\tOK\n"); 283 284 return EOK; 285 } 286 287 int main(int argc, char *argv[]) 288 { 289 290 socklen_t max_length; 291 uint8_t *address_data[sizeof(struct sockaddr_in6)]; 292 struct sockaddr_in *address_in; 293 struct sockaddr_in6 *address_in6; 294 uint8_t *address_start; 295 296 int *socket_ids; 104 297 int index; 105 298 struct timeval time_before; 106 299 struct timeval time_after; 107 300 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{ 301 int rc; 302 303 max_length = sizeof(address_data); 304 address = (struct sockaddr *) address_data; 305 address_in = (struct sockaddr_in *) address; 306 address_in6 = (struct sockaddr_in6 *) address; 307 308 sockets = 10; 309 messages = 10; 310 port = 7; 311 312 /* 313 * Parse the command line arguments. Stop before the last argument 314 * if it does not start with dash ('-') 315 */ 316 for (index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); index++) { 317 /* Options should start with dash ('-') */ 318 if (argv[index][0] == '-') { 319 rc = nettest1_parse_opt(argc, argv, &index); 320 if (rc != EOK) 321 return rc; 322 } else { 172 323 nettest1_print_help(); 173 324 return EINVAL; … … 175 326 } 176 327 177 / / if not before the last argument containing the address178 if (index >= argc){328 /* If not before the last argument containing the address */ 329 if (index >= argc) { 179 330 printf("Command line error: missing address\n"); 180 331 nettest1_print_help(); … … 182 333 } 183 334 184 / / prepare the address buffer335 /* Prepare the address buffer */ 185 336 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); 337 338 switch (family) { 339 case PF_INET: 340 address_in->sin_family = AF_INET; 341 address_in->sin_port = htons(port); 342 address_start = (uint8_t *) &address_in->sin_addr.s_addr; 343 addrlen = sizeof(struct sockaddr_in); 344 break; 345 case PF_INET6: 346 address_in6->sin6_family = AF_INET6; 347 address_in6->sin6_port = htons(port); 348 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr; 349 addrlen = sizeof(struct sockaddr_in6); 350 break; 351 default: 352 fprintf(stderr, "Address family is not supported\n"); 353 return EAFNOSUPPORT; 354 } 355 356 /* Parse the last argument which should contain the address */ 357 rc = inet_pton(family, argv[argc - 1], address_start); 358 if (rc != EOK) { 359 fprintf(stderr, "Address parse error %d\n", rc); 360 return rc; 361 } 362 363 /* Check data buffer size */ 364 if (size <= 0) { 365 fprintf(stderr, "Data buffer size too small (%d). Using 1024 " 366 "bytes instead.\n", size); 213 367 size = 1024; 214 368 } 215 369 216 // prepare the buffer 217 // size plus the terminating null (\0) 370 /* 371 * Prepare data buffer. Allocate size bytes plus one for the 372 * trailing null character. 373 */ 218 374 data = (char *) malloc(size + 1); 219 if (! data){375 if (!data) { 220 376 fprintf(stderr, "Failed to allocate data buffer.\n"); 221 377 return ENOMEM; 222 378 } 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); 379 nettest1_fill_buffer(data, size); 380 381 /* Check socket count */ 382 if (sockets <= 0) { 383 fprintf(stderr, "Socket count too small (%d). Using " 384 "2 instead.\n", sockets); 228 385 sockets = 2; 229 386 } 230 387 231 // prepare the socket buffer 232 // count plus the terminating null (\0) 388 /* 389 * Prepare socket buffer. Allocate count fields plus the terminating 390 * null (\0). 391 */ 233 392 socket_ids = (int *) malloc(sizeof(int) * (sockets + 1)); 234 if (! socket_ids){393 if (!socket_ids) { 235 394 fprintf(stderr, "Failed to allocate receive buffer.\n"); 236 395 return ENOMEM; … … 238 397 socket_ids[sockets] = NULL; 239 398 240 if (verbose){399 if (verbose) 241 400 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){ 401 402 rc = gettimeofday(&time_before, NULL); 403 if (rc != EOK) { 404 fprintf(stderr, "Get time of day error %d\n", rc); 405 return rc; 406 } 407 408 nettest1_test(socket_ids, 1, 1); 409 nettest1_test(socket_ids, 1, messages); 410 nettest1_test(socket_ids, sockets, 1); 411 nettest1_test(socket_ids, sockets, messages); 412 413 rc = gettimeofday(&time_after, NULL); 414 if (rc != EOK) { 415 fprintf(stderr, "Get time of day error %d\n", rc); 416 return rc; 417 } 418 419 printf("Tested in %d microseconds\n", tv_sub(&time_after, 420 &time_before)); 421 422 if (verbose) 370 423 printf("Exiting\n"); 371 }372 424 373 425 return EOK; 374 426 } 375 427 376 void nettest1_print_help(void){377 printf(378 "Network Networking test 1 aplication - sockets\n" \379 "Usage: echo [options] numeric_address\n" \380 "Where options are:\n" \381 "-f protocol_family | --family=protocol_family\n" \382 "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"383 "\n" \384 "-h | --help\n" \385 "\tShow this application help.\n"386 "\n" \387 "-m count | --messages=count\n" \388 "\tThe number of messages to send and receive per socket. The default is 10.\n" \389 "\n" \390 "-n sockets | --sockets=count\n" \391 "\tThe number of sockets to use. The default is 10.\n" \392 "\n" \393 "-p port_number | --port=port_number\n" \394 "\tThe port number the application should send messages to. The default is 7.\n" \395 "\n" \396 "-s packet_size | --size=packet_size\n" \397 "\tThe packet data size the application sends. The default is 28 bytes.\n" \398 "\n" \399 "-v | --verbose\n" \400 "\tShow all output messages.\n"401 );402 }403 404 void nettest1_refresh_data(char * data, size_t size){405 size_t length;406 407 // fill the data408 length = 0;409 while(size > length + sizeof(NETTEST1_TEXT) - 1){410 memcpy(data + length, NETTEST1_TEXT, sizeof(NETTEST1_TEXT) - 1);411 length += sizeof(NETTEST1_TEXT) - 1;412 }413 memcpy(data + length, NETTEST1_TEXT, size - length);414 data[size] = '\0';415 }416 428 417 429 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.