Changeset a62ceaf in mainline for uspace/app/ping/ping.c


Ignore:
Timestamp:
2016-02-29T19:19:19Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
129b92c6
Parents:
5147ff1
Message:

Need better interfaces for handling internet host and host:port specifications.

File:
1 edited

Legend:

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

    r5147ff1 ra62ceaf  
    3737#include <errno.h>
    3838#include <fibril_synch.h>
    39 #include <inet/dnsr.h>
    4039#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;
    217216        char *asrc = NULL;
    218217        char *adest = NULL;
    219218        char *sdest = NULL;
     219        char *host;
     220        const char *errmsg;
    220221        ip_ver_t ip_ver = ip_any;
    221222       
     
    260261        }
    261262       
    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;
     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;
    273270        }
    274271       
     
    292289        }
    293290       
    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;
     291        rc = asprintf(&sdest, "%s (%s)", host, adest);
     292        if (rc < 0) {
     293                printf("Out of memory.\n");
     294                goto error;
    303295        }
    304296       
     
    330322        free(adest);
    331323        free(sdest);
    332         dnsr_hostinfo_destroy(hinfo);
    333324        return 0;
    334325       
     
    337328        free(adest);
    338329        free(sdest);
    339         dnsr_hostinfo_destroy(hinfo);
    340330        return 1;
    341331}
Note: See TracChangeset for help on using the changeset viewer.