Changeset 287d729 in mainline for uspace/app/nterm/conn.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/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));
Note: See TracChangeset for help on using the changeset viewer.