Changeset 287d729 in mainline for uspace/app/nettest1/nettest1.c


Ignore:
Timestamp:
2013-04-25T06:45:04Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fff7ef4
Parents:
c55cbbf
Message:

Hostname resolution in nterm and nettest1-3.

File:
1 edited

Legend:

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

    rc55cbbf r287d729  
    4646#include <arg_parse.h>
    4747
     48#include <inet/dnsr.h>
    4849#include <net/in.h>
    4950#include <net/in6.h>
     
    7576        printf(
    7677            "Network Networking test 1 aplication - sockets\n"
    77             "Usage: echo [options] numeric_address\n"
     78            "Usage: nettest1 [options] host\n"
    7879            "Where options are:\n"
    7980            "-f protocol_family | --family=protocol_family\n"
     
    290291        struct sockaddr_in address_in;
    291292        struct sockaddr_in6 address_in6;
     293        dnsr_hostinfo_t *hinfo;
    292294        uint8_t *address_start;
    293295
     
    319321        }
    320322
    321         /* If not before the last argument containing the address */
     323        /* If not before the last argument containing the host */
    322324        if (index >= argc) {
    323                 printf("Command line error: missing address\n");
     325                printf("Command line error: missing host name\n");
    324326                nettest1_print_help();
    325327                return EINVAL;
     
    348350        }
    349351
    350         /* Parse the last argument which should contain the address */
     352        /* Parse the last argument which should contain the host/address */
    351353        rc = inet_pton(family, argv[argc - 1], address_start);
    352354        if (rc != EOK) {
    353                 fprintf(stderr, "Address parse error %d\n", rc);
    354                 return rc;
     355                /* Try interpreting as a host name */
     356                rc = dnsr_init();
     357                if (rc != EOK) {
     358                        printf("Failed connecting DNS resolution "
     359                            "service (%d).\n", rc);
     360                        return rc;
     361                }
     362
     363                rc = dnsr_name2host(argv[argc - 1], &hinfo);
     364                if (rc != EOK) {
     365                        printf("Error resolving host '%s'.\n", argv[argc - 1]);
     366                        return rc;
     367                }
     368
     369                address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    355370        }
    356371
Note: See TracChangeset for help on using the changeset viewer.