Ignore:
File:
1 edited

Legend:

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

    r26de91a rc442f63  
    3838#include "print_error.h"
    3939
    40 #include <assert.h>
    4140#include <malloc.h>
    4241#include <stdio.h>
     
    6160#define NETTEST2_TEXT  "Networking test 2 - transfer"
    6261
    63 static uint16_t family = AF_NONE;
     62static uint16_t family = PF_INET;
    6463static size_t size = 28;
    6564static bool verbose = false;
     
    272271                /* Interpret as a host name */
    273272                dnsr_hostinfo_t *hinfo = NULL;
    274                 rc = dnsr_name2host(addr_s, &hinfo, ipver_from_af(family));
     273                rc = dnsr_name2host(addr_s, &hinfo, family);
    275274               
    276275                if (rc != EOK) {
     
    282281        }
    283282       
     283        struct sockaddr_in addr;
     284        struct sockaddr_in6 addr6;
     285        uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
     286       
     287        if (af != family) {
     288                printf("Address family does not match explicitly set family.\n");
     289                return EINVAL;
     290        }
     291       
     292        /* Prepare the address buffer */
     293       
    284294        struct sockaddr *address;
    285295        socklen_t addrlen;
    286         rc = inet_addr_sockaddr(&addr_addr, port, &address, &addrlen);
    287         if (rc != EOK) {
    288                 assert(rc == ENOMEM);
    289                 printf("Out of memory.\n");
    290                 return ENOMEM;
    291         }
    292        
    293         if (family == AF_NONE)
    294                 family = address->sa_family;
    295        
    296         if (address->sa_family != family) {
    297                 printf("Address family does not match explicitly set family.\n");
    298                 return EINVAL;
     296       
     297        switch (af) {
     298        case AF_INET:
     299                addr.sin_port = htons(port);
     300                address = (struct sockaddr *) &addr;
     301                addrlen = sizeof(addr);
     302                break;
     303        case AF_INET6:
     304                addr6.sin6_port = htons(port);
     305                address = (struct sockaddr *) &addr6;
     306                addrlen = sizeof(addr6);
     307                break;
     308        default:
     309                fprintf(stderr, "Address family is not supported\n");
     310                return EAFNOSUPPORT;
    299311        }
    300312       
     
    412424                return rc;
    413425       
    414         free(address);
    415        
    416426        if (verbose)
    417427                printf("\nExiting\n");
Note: See TracChangeset for help on using the changeset viewer.