Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nterm/conn.c

    ra62ceaf r204ba47  
    3737#include <errno.h>
    3838#include <fibril.h>
     39#include <inet/dnsr.h>
    3940#include <inet/endpoint.h>
    40 #include <inet/hostport.h>
    4141#include <inet/tcp.h>
    4242#include <stdio.h>
     
    8686}
    8787
    88 int conn_open(const char *hostport)
     88int conn_open(const char *host, const char *port_s)
    8989{
    9090        inet_ep2_t epp;
    91         const char *errmsg;
    92         int rc;
    9391
    94         inet_ep2_init(&epp);
    95         rc = inet_hostport_plookup_one(hostport, ip_any, &epp.remote, NULL,
    96             &errmsg);
     92        /* Interpret as address */
     93        inet_addr_t iaddr;
     94        int rc = inet_addr_parse(host, &iaddr);
     95
    9796        if (rc != EOK) {
    98                 printf("Error: %s (host:port %s).\n", errmsg, hostport);
     97                /* Interpret as a host name */
     98                dnsr_hostinfo_t *hinfo = NULL;
     99                rc = dnsr_name2host(host, &hinfo, ip_any);
     100
     101                if (rc != EOK) {
     102                        printf("Error resolving host '%s'.\n", host);
     103                        goto error;
     104                }
     105
     106                iaddr = hinfo->addr;
     107        }
     108
     109        char *endptr;
     110        uint16_t port = strtol(port_s, &endptr, 10);
     111        if (*endptr != '\0') {
     112                printf("Invalid port number %s\n", port_s);
    99113                goto error;
    100114        }
    101115
    102         printf("Connecting to %s\n", hostport);
    103         char *s;
    104         rc = inet_addr_format(&epp.remote.addr, &s);
    105         if (rc != EOK)
    106                 goto error;
     116        inet_ep2_init(&epp);
     117        epp.remote.addr = iaddr;
     118        epp.remote.port = port;
     119
     120        printf("Connecting to host %s port %u\n", host, port);
    107121
    108122        rc = tcp_create(&tcp);
Note: See TracChangeset for help on using the changeset viewer.