Changes in uspace/app/ping/ping.c [a62ceaf:9749e47] in mainline


Ignore:
File:
1 edited

Legend:

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

    ra62ceaf r9749e47  
    3737#include <errno.h>
    3838#include <fibril_synch.h>
     39#include <inet/dnsr.h>
    3940#include <inet/addr.h>
    40 #include <inet/host.h>
    4141#include <inet/inetping.h>
    4242#include <io/console.h>
     
    214214int main(int argc, char *argv[])
    215215{
     216        dnsr_hostinfo_t *hinfo = NULL;
    216217        char *asrc = NULL;
    217218        char *adest = NULL;
    218219        char *sdest = NULL;
    219         char *host;
    220         const char *errmsg;
    221220        ip_ver_t ip_ver = ip_any;
    222221       
     
    261260        }
    262261       
    263         host = argv[optind];
    264        
    265         /* Look up host */
    266         rc = inet_host_plookup_one(host, ip_ver, &dest_addr, NULL, &errmsg);
    267         if (rc != EOK) {
    268                 printf("Error resolving host '%s' (%s).\n", host, errmsg);
    269                 goto error;
     262        /* Parse destination address */
     263        rc = inet_addr_parse(argv[optind], &dest_addr);
     264        if (rc != EOK) {
     265                /* Try interpreting as a host name */
     266                rc = dnsr_name2host(argv[optind], &hinfo, ip_ver);
     267                if (rc != EOK) {
     268                        printf("Error resolving host '%s'.\n", argv[optind]);
     269                        goto error;
     270                }
     271               
     272                dest_addr = hinfo->addr;
    270273        }
    271274       
     
    289292        }
    290293       
    291         rc = asprintf(&sdest, "%s (%s)", host, adest);
    292         if (rc < 0) {
    293                 printf("Out of memory.\n");
    294                 goto error;
     294        if (hinfo != NULL) {
     295                rc = asprintf(&sdest, "%s (%s)", hinfo->cname, adest);
     296                if (rc < 0) {
     297                        printf("Out of memory.\n");
     298                        goto error;
     299                }
     300        } else {
     301                sdest = adest;
     302                adest = NULL;
    295303        }
    296304       
     
    322330        free(adest);
    323331        free(sdest);
     332        dnsr_hostinfo_destroy(hinfo);
    324333        return 0;
    325334       
     
    328337        free(adest);
    329338        free(sdest);
     339        dnsr_hostinfo_destroy(hinfo);
    330340        return 1;
    331341}
Note: See TracChangeset for help on using the changeset viewer.