Changeset 0773396 in mainline for uspace/app/nettest2/nettest2.c


Ignore:
Timestamp:
2013-12-25T13:05:25Z (10 years ago)
Author:
Martin Decky <martin@…>
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.
Message:

merge mainline changes

File:
1 edited

Legend:

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

    rf4a47e52 r0773396  
    3838#include "print_error.h"
    3939
     40#include <assert.h>
    4041#include <malloc.h>
    4142#include <stdio.h>
     
    6061#define NETTEST2_TEXT  "Networking test 2 - transfer"
    6162
    62 static uint16_t family = PF_INET;
     63static uint16_t family = AF_NONE;
    6364static size_t size = 28;
    6465static bool verbose = false;
     
    271272                /* Interpret as a host name */
    272273                dnsr_hostinfo_t *hinfo = NULL;
    273                 rc = dnsr_name2host(addr_s, &hinfo, family);
     274                rc = dnsr_name2host(addr_s, &hinfo, ipver_from_af(family));
    274275               
    275276                if (rc != EOK) {
     
    281282        }
    282283       
    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) {
     284        struct sockaddr *address;
     285        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) {
    288297                printf("Address family does not match explicitly set family.\n");
    289298                return EINVAL;
    290         }
    291        
    292         /* Prepare the address buffer */
    293        
    294         struct sockaddr *address;
    295         socklen_t addrlen;
    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;
    311299        }
    312300       
     
    424412                return rc;
    425413       
     414        free(address);
     415       
    426416        if (verbose)
    427417                printf("\nExiting\n");
Note: See TracChangeset for help on using the changeset viewer.