Changeset 0773396 in mainline for uspace/app/nettest1/nettest1.c
- Timestamp:
- 2013-12-25T13:05:25Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bc54126c
- Parents:
- f4a47e52 (diff), 6946f23 (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
rf4a47e52 r0773396 38 38 #include "print_error.h" 39 39 40 #include <assert.h> 40 41 #include <malloc.h> 41 42 #include <stdio.h> … … 59 60 #define NETTEST1_TEXT "Networking test 1 - sockets" 60 61 61 static uint16_t family = AF_ INET;62 static uint16_t family = AF_NONE; 62 63 static sock_type_t type = SOCK_DGRAM; 63 64 static size_t size = 27; … … 326 327 } 327 328 328 char * addr_s= argv[argc - 1];329 char *host = argv[argc - 1]; 329 330 330 331 /* Interpret as address */ 331 inet_addr_t addr_addr;332 rc = inet_addr_parse( addr_s, &addr_addr);332 inet_addr_t iaddr; 333 rc = inet_addr_parse(host, &iaddr); 333 334 334 335 if (rc != EOK) { 335 336 /* Interpret as a host name */ 336 337 dnsr_hostinfo_t *hinfo = NULL; 337 rc = dnsr_name2host( addr_s, &hinfo, family);338 rc = dnsr_name2host(host, &hinfo, ipver_from_af(family)); 338 339 339 340 if (rc != EOK) { 340 printf("Error resolving host '%s'.\n", addr_s);341 printf("Error resolving host '%s'.\n", host); 341 342 return EINVAL; 342 343 } 343 344 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) { 345 iaddr = hinfo->addr; 346 } 347 348 rc = inet_addr_sockaddr(&iaddr, port, &address, &addrlen); 349 if (rc != EOK) { 350 assert(rc == ENOMEM); 351 printf("Out of memory.\n"); 352 return ENOMEM; 353 } 354 355 if (family == AF_NONE) 356 family = address->sa_family; 357 358 if (address->sa_family != family) { 352 359 printf("Address family does not match explicitly set family.\n"); 353 360 return EINVAL; 354 }355 356 /* Prepare the address buffer */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);368 break;369 default:370 fprintf(stderr, "Address family is not supported\n");371 return EAFNOSUPPORT;372 361 } 373 362 … … 434 423 &time_before)); 435 424 425 free(address); 426 436 427 if (verbose) 437 428 printf("Exiting\n");
Note:
See TracChangeset
for help on using the changeset viewer.