Changeset 287d729 in mainline


Ignore:
Timestamp:
2013-04-25T06:45:04Z (11 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.

Location:
uspace
Files:
8 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
  • uspace/app/nettest2/nettest2.c

    rc55cbbf r287d729  
    4747#include <stdbool.h>
    4848
     49#include <inet/dnsr.h>
    4950#include <net/in.h>
    5051#include <net/in6.h>
     
    7172        printf(
    7273            "Network Networking test 2 aplication - UDP transfer\n"
    73             "Usage: echo [options] address\n"
     74            "Usage: nettest2 [options] host\n"
    7475            "Where options are:\n"
    7576            "-f protocol_family | --family=protocol_family\n"
     
    227228        struct sockaddr_in address_in;
    228229        struct sockaddr_in6 address_in6;
     230        dnsr_hostinfo_t *hinfo;
    229231        socklen_t addrlen;
    230232        uint8_t *address_start;
     
    265267        }
    266268
    267         /* If not before the last argument containing the address */
     269        /* If not before the last argument containing the host */
    268270        if (index >= argc) {
    269                 printf("Command line error: missing address\n");
     271                printf("Command line error: missing host name\n");
    270272                nettest2_print_help();
    271273                return EINVAL;
     
    294296        }
    295297
    296         /* Parse the last argument which should contain the address. */
     298        /* Parse the last argument which should contain the host/address */
    297299        rc = inet_pton(family, argv[argc - 1], address_start);
    298300        if (rc != EOK) {
    299                 fprintf(stderr, "Address parse error %d\n", rc);
    300                 return rc;
     301                /* Try interpreting as a host name */
     302                rc = dnsr_init();
     303                if (rc != EOK) {
     304                        printf("Failed connecting DNS resolution "
     305                            "service (%d).\n", rc);
     306                        return rc;
     307                }
     308
     309                rc = dnsr_name2host(argv[argc - 1], &hinfo);
     310                if (rc != EOK) {
     311                        printf("Error resolving host '%s'.\n", argv[argc - 1]);
     312                        return rc;
     313                }
     314
     315                address_in.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    301316        }
    302317
  • uspace/app/nettest3/nettest3.c

    rc55cbbf r287d729  
    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;
     
    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_init();
     81                        if (rc != EOK) {
     82                                printf("Failed connecting DNS resolution "
     83                                    "service (%d).\n", rc);
     84                                return rc;
     85                        }
     86
     87                        rc = dnsr_name2host(argv[1], &hinfo);
     88                        if (rc != EOK) {
     89                                printf("Error resolving host '%s'.\n", argv[1]);
     90                                return rc;
     91                        }
     92
     93                        addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
     94                        addr.sin_family = AF_INET;
    7995                }
    8096                printf("result: rc=%d, family=%d, addr=%x\n", rc,
  • uspace/app/nterm/conn.c

    rc55cbbf r287d729  
    3333 */
    3434
     35#include <byteorder.h>
    3536#include <stdbool.h>
    3637#include <errno.h>
    3738#include <fibril.h>
     39#include <inet/dnsr.h>
    3840#include <net/socket.h>
    3941#include <stdio.h>
     
    7476{
    7577        struct sockaddr_in addr;
     78        dnsr_hostinfo_t *hinfo = NULL;
    7679        int rc;
    7780        char *endptr;
     
    8184        rc = inet_pton(addr.sin_family, addr_s, (uint8_t *)&addr.sin_addr);
    8285        if (rc != EOK) {
    83                 printf("Invalid addres %s\n", addr_s);
    84                 return EINVAL;
     86                /* Try interpreting as a host name */
     87                rc = dnsr_init();
     88                if (rc != EOK) {
     89                        printf("Failed connecting DNS resolution "
     90                            "service (%d).\n", rc);
     91                        goto error;
     92                }
     93
     94                rc = dnsr_name2host(addr_s, &hinfo);
     95                if (rc != EOK) {
     96                        printf("Error resolving host '%s'.\n", addr_s);
     97                        goto error;
     98                }
     99
     100                addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4);
    85101        }
    86102
     
    88104        if (*endptr != '\0') {
    89105                printf("Invalid port number %s\n", port_s);
    90                 return EINVAL;
     106                goto error;
    91107        }
    92108
     
    95111                goto error;
    96112
    97         printf("Connecting to address %s port %u\n", addr_s, ntohs(addr.sin_port));
     113        printf("Connecting to host %s port %u\n", addr_s, ntohs(addr.sin_port));
    98114
    99115        rc = connect(conn_fd, (struct sockaddr *)&addr, sizeof(addr));
  • uspace/app/nterm/nterm.c

    rc55cbbf r287d729  
    104104static void print_syntax(void)
    105105{
    106         printf("syntax: nterm <ip-address> <port>\n");
     106        printf("syntax: nterm <host> <port>\n");
    107107}
    108108
  • uspace/app/ping/ping.c

    rc55cbbf r287d729  
    6969static void print_syntax(void)
    7070{
    71         printf("syntax: " NAME " [-r] <addr>\n");
     71        printf("syntax: " NAME " [-r] <host>\n");
    7272}
    7373
  • uspace/lib/c/generic/dnsr.c

    rc55cbbf r287d729  
    5959}
    6060
    61 int dnsr_name2host(char *name, dnsr_hostinfo_t **rinfo)
     61int dnsr_name2host(const char *name, dnsr_hostinfo_t **rinfo)
    6262{
    6363        async_exch_t *exch = async_exchange_begin(dnsr_sess);
  • uspace/lib/c/include/inet/dnsr.h

    rc55cbbf r287d729  
    4646
    4747extern int dnsr_init(void);
    48 extern int dnsr_name2host(char *, dnsr_hostinfo_t **);
     48extern int dnsr_name2host(const char *, dnsr_hostinfo_t **);
    4949extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *);
    5050extern int dnsr_get_srvaddr(inet_addr_t *);
Note: See TracChangeset for help on using the changeset viewer.