Changeset 8b863a62 in mainline for uspace/app/dnsres/dnsres.c


Ignore:
Timestamp:
2014-04-16T17:14:06Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
f857e8b
Parents:
dba3e2c (diff), 70b570c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    rdba3e2c r8b863a62  
    3939#include <stdlib.h>
    4040
    41 #define NAME "dnsres"
     41#define NAME  "dnsres"
    4242
    4343static void print_syntax(void)
    4444{
    45         printf("syntax: " NAME " <host-name>\n");
     45        printf("Syntax: %s [-4|-6] <host-name>\n", NAME);
    4646}
    4747
    4848int main(int argc, char *argv[])
    4949{
    50         int rc;
    51         dnsr_hostinfo_t *hinfo;
    52         char *hname;
    53         char *saddr;
    54 
    55         if (argc != 2) {
     50        if ((argc < 2) || (argc > 3)) {
    5651                print_syntax();
    5752                return 1;
    5853        }
    59 
    60         hname = argv[1];
    61 
    62         rc = dnsr_name2host(hname, &hinfo);
     54       
     55        uint16_t ver;
     56        char *hname;
     57       
     58        if (str_cmp(argv[1], "-4") == 0) {
     59                if (argc < 3) {
     60                        print_syntax();
     61                        return 1;
     62                }
     63               
     64                ver = ip_v4;
     65                hname = argv[2];
     66        } else if (str_cmp(argv[1], "-6") == 0) {
     67                if (argc < 3) {
     68                        print_syntax();
     69                        return 1;
     70                }
     71               
     72                ver = ip_v6;
     73                hname = argv[2];
     74        } else {
     75                ver = ip_any;
     76                hname = argv[1];
     77        }
     78       
     79        dnsr_hostinfo_t *hinfo;
     80        int rc = dnsr_name2host(hname, &hinfo, ver);
    6381        if (rc != EOK) {
    64                 printf(NAME ": Error resolving '%s'.\n", argv[1]);
    65                 return 1;
     82                printf("%s: Error resolving '%s'.\n", NAME, hname);
     83                return rc;
    6684        }
    67 
     85       
     86        char *saddr;
    6887        rc = inet_addr_format(&hinfo->addr, &saddr);
    6988        if (rc != EOK) {
    7089                dnsr_hostinfo_destroy(hinfo);
    71                 printf(NAME ": Out of memory.\n");
    72                 return 1;
     90                printf("%s: Error formatting address.\n", NAME);
     91                return rc;
    7392        }
    74 
     93       
    7594        printf("Host name: %s\n", hname);
     95       
    7696        if (str_cmp(hname, hinfo->cname) != 0)
    7797                printf("Canonical name: %s\n", hinfo->cname);
     98       
    7899        printf("Address: %s\n", saddr);
    79 
     100       
    80101        dnsr_hostinfo_destroy(hinfo);
    81102        free(saddr);
    82 
     103       
    83104        return 0;
    84105}
Note: See TracChangeset for help on using the changeset viewer.