Changeset 02a09ed in mainline for uspace/app/nettest1/nettest1.c
- Timestamp:
- 2013-06-28T20:20:03Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d24ad3
- Parents:
- edf0d27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest1.c
redf0d27 r02a09ed 59 59 #define NETTEST1_TEXT "Networking test 1 - sockets" 60 60 61 static int family = PF_INET;61 static uint16_t family = AF_INET; 62 62 static sock_type_t type = SOCK_DGRAM; 63 static char *data;64 63 static size_t size = 27; 65 static int verbose = 0; 64 static bool verbose = false; 65 static int sockets = 10; 66 static int messages = 10; 67 static uint16_t port = 7; 66 68 67 69 static struct sockaddr *address; 68 70 static socklen_t addrlen; 69 71 70 static int sockets; 71 static int messages; 72 static uint16_t port; 72 static char *data; 73 73 74 74 static void nettest1_print_help(void) … … 299 299 int main(int argc, char *argv[]) 300 300 { 301 struct sockaddr_in address_in;302 struct sockaddr_in6 address_in6;303 dnsr_hostinfo_t *hinfo;304 uint8_t *address_start;305 306 int *socket_ids;307 int index;308 struct timeval time_before;309 struct timeval time_after;310 311 int rc;312 313 sockets = 10;314 messages = 10;315 port = 7;316 317 301 /* 318 302 * Parse the command line arguments. Stop before the last argument 319 303 * if it does not start with dash ('-') 320 304 */ 321 for (index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); index++) { 305 int index; 306 int rc; 307 308 for (index = 1; (index < argc - 1) || ((index == argc - 1) && 309 (argv[index][0] == '-')); index++) { 322 310 /* Options should start with dash ('-') */ 323 311 if (argv[index][0] == '-') { … … 331 319 } 332 320 333 /* If not before the last argument containing the host */321 /* The last argument containing the host */ 334 322 if (index >= argc) { 335 printf(" Command line error: missing host name\n");323 printf("Host name missing.\n"); 336 324 nettest1_print_help(); 337 325 return EINVAL; 338 326 } 339 327 328 char *addr_s = argv[argc - 1]; 329 330 /* Interpret as address */ 331 inet_addr_t addr_addr; 332 rc = inet_addr_parse(addr_s, &addr_addr); 333 334 if (rc != EOK) { 335 /* Interpret as a host name */ 336 dnsr_hostinfo_t *hinfo = NULL; 337 rc = dnsr_name2host(addr_s, &hinfo); 338 339 if (rc != EOK) { 340 printf("Error resolving host '%s'.\n", addr_s); 341 return EINVAL; 342 } 343 344 addr_addr = hinfo->addr; 345 } 346 347 struct sockaddr_in addr; 348 struct sockaddr_in6 addr6; 349 uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6); 350 351 if (af != family) { 352 printf("Address family does not match explicitly set family.\n"); 353 return EINVAL; 354 } 355 340 356 /* Prepare the address buffer */ 341 342 switch (family) { 343 case PF_INET: 344 address_in.sin_family = AF_INET; 345 address_in.sin_port = htons(port); 346 address = (struct sockaddr *) &address_in; 347 addrlen = sizeof(address_in); 348 address_start = (uint8_t *) &address_in.sin_addr.s_addr; 349 break; 350 case PF_INET6: 351 address_in6.sin6_family = AF_INET6; 352 address_in6.sin6_port = htons(port); 353 address = (struct sockaddr *) &address_in6; 354 addrlen = sizeof(address_in6); 355 address_start = (uint8_t *) &address_in6.sin6_addr.s6_addr; 357 358 switch (af) { 359 case AF_INET: 360 addr.sin_port = htons(port); 361 address = (struct sockaddr *) &addr; 362 addrlen = sizeof(addr); 363 break; 364 case AF_INET6: 365 addr6.sin6_port = htons(port); 366 address = (struct sockaddr *) &addr6; 367 addrlen = sizeof(addr6); 356 368 break; 357 369 default: 358 370 fprintf(stderr, "Address family is not supported\n"); 359 371 return EAFNOSUPPORT; 360 }361 362 /* Parse the last argument which should contain the host/address */363 rc = inet_pton(family, argv[argc - 1], address_start);364 if (rc != EOK) {365 /* Try interpreting as a host name */366 rc = dnsr_name2host(argv[argc - 1], &hinfo);367 if (rc != EOK) {368 printf("Error resolving host '%s'.\n", argv[argc - 1]);369 return rc;370 }371 372 rc = inet_addr_sockaddr_in(&hinfo->addr, &address_in);373 if (rc != EOK) {374 printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]);375 return rc;376 }377 372 } 378 373 … … 406 401 * null (\0). 407 402 */ 408 socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));403 int *socket_ids = (int *) malloc(sizeof(int) * (sockets + 1)); 409 404 if (!socket_ids) { 410 405 fprintf(stderr, "Failed to allocate receive buffer.\n"); … … 417 412 printf("Starting tests\n"); 418 413 414 struct timeval time_before; 419 415 rc = gettimeofday(&time_before, NULL); 420 416 if (rc != EOK) { … … 428 424 nettest1_test(socket_ids, sockets, messages); 429 425 426 struct timeval time_after; 430 427 rc = gettimeofday(&time_after, NULL); 431 428 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.