Changeset 4c14b88 in mainline for uspace/app/nettest1/nettest1.c


Ignore:
Timestamp:
2013-12-31T07:57:14Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b973dc
Parents:
6297465 (diff), 208b5f5 (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.
Message:

mainline changes

File:
1 edited

Legend:

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

    r6297465 r4c14b88  
    3838#include "print_error.h"
    3939
     40#include <assert.h>
    4041#include <malloc.h>
    4142#include <stdio.h>
     
    5960#define NETTEST1_TEXT  "Networking test 1 - sockets"
    6061
    61 static uint16_t family = AF_INET;
     62static uint16_t family = AF_NONE;
    6263static sock_type_t type = SOCK_DGRAM;
    6364static size_t size = 27;
     
    326327        }
    327328       
    328         char *addr_s = argv[argc - 1];
     329        char *host = argv[argc - 1];
    329330       
    330331        /* 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);
    333334       
    334335        if (rc != EOK) {
    335336                /* Interpret as a host name */
    336337                dnsr_hostinfo_t *hinfo = NULL;
    337                 rc = dnsr_name2host(addr_s, &hinfo, family);
     338                rc = dnsr_name2host(host, &hinfo, ipver_from_af(family));
    338339               
    339340                if (rc != EOK) {
    340                         printf("Error resolving host '%s'.\n", addr_s);
     341                        printf("Error resolving host '%s'.\n", host);
    341342                        return EINVAL;
    342343                }
    343344               
    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) {
    352359                printf("Address family does not match explicitly set family.\n");
    353360                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;
    372361        }
    373362       
     
    434423            &time_before));
    435424       
     425        free(address);
     426       
    436427        if (verbose)
    437428                printf("Exiting\n");
Note: See TracChangeset for help on using the changeset viewer.