Ignore:
File:
1 edited

Legend:

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

    r9d58539 r0aa70f4  
    3939#include <str.h>
    4040
     41#include <inet/dnsr.h>
    4142#include <net/in.h>
    4243#include <net/in6.h>
     
    6061        int fd;
    6162        char *endptr;
     63        dnsr_hostinfo_t *hinfo;
    6264
    6365        port = 7;
    6466
    65         data = (char *)"Hello World!";
     67        data = (char *) "Hello World!";
    6668        size = str_size(data);
    6769
     
    7577                rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
    7678                if (rc != EOK) {
    77                         fprintf(stderr, "Error parsing address\n");
    78                         return 1;
     79                        /* Try interpreting as a host name */
     80                        rc = dnsr_name2host(argv[1], &hinfo, AF_INET);
     81                        if (rc != EOK) {
     82                                printf("Error resolving host '%s'.\n", argv[1]);
     83                                return rc;
     84                        }
     85                       
     86                        uint16_t af = inet_addr_sockaddr_in(&hinfo->addr, &addr, NULL);
     87                        if (af != AF_INET) {
     88                                printf("Host '%s' not resolved as IPv4 address.\n", argv[1]);
     89                                return rc;
     90                        }
    7991                }
    8092                printf("result: rc=%d, family=%d, addr=%x\n", rc,
     
    98110
    99111        printf("connect()\n");
    100         rc = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
     112        rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr));
    101113        printf(" -> %d\n", rc);
    102114        if (rc != 0)
     
    115127        } while (rc > 0);
    116128
    117         async_usleep(1000*1000);
     129        async_usleep(1000 * 1000);
    118130
    119131        printf("closesocket()\n");
     
    124136}
    125137
    126 
    127138/** @}
    128139 */
Note: See TracChangeset for help on using the changeset viewer.