Changes in uspace/app/dnsres/dnsres.c [cd18cd1:a2e3ee6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnsres/dnsres.c
rcd18cd1 ra2e3ee6 36 36 #include <inet/addr.h> 37 37 #include <inet/dnsr.h> 38 #include <net/socket_codes.h>39 38 #include <stdio.h> 40 39 #include <stdlib.h> 41 40 42 #define NAME 41 #define NAME "dnsres" 43 42 44 43 static void print_syntax(void) 45 44 { 46 printf(" Syntax: %s [-4|-6] <host-name>\n", NAME);45 printf("syntax: " NAME " <host-name>\n"); 47 46 } 48 47 49 48 int main(int argc, char *argv[]) 50 49 { 51 if ((argc < 2) || (argc > 3)) { 50 int rc; 51 dnsr_hostinfo_t *hinfo; 52 char *hname; 53 char *saddr; 54 55 if (argc != 2) { 52 56 print_syntax(); 53 57 return 1; 54 58 } 55 56 uint16_t af; 57 char *hname; 58 59 if (str_cmp(argv[1], "-4") == 0) { 60 if (argc < 3) { 61 print_syntax(); 62 return 1; 63 } 64 65 af = AF_INET; 66 hname = argv[2]; 67 } else if (str_cmp(argv[1], "-6") == 0) { 68 if (argc < 3) { 69 print_syntax(); 70 return 1; 71 } 72 73 af = AF_INET6; 74 hname = argv[2]; 75 } else { 76 af = 0; 77 hname = argv[1]; 59 60 hname = argv[1]; 61 62 rc = dnsr_name2host(hname, &hinfo); 63 if (rc != EOK) { 64 printf(NAME ": Error resolving '%s'.\n", argv[1]); 65 return 1; 78 66 } 79 80 dnsr_hostinfo_t *hinfo; 81 int rc = dnsr_name2host(hname, &hinfo, af); 82 if (rc != EOK) { 83 printf("%s: Error resolving '%s'.\n", NAME, hname); 84 return rc; 85 } 86 87 char *saddr; 67 88 68 rc = inet_addr_format(&hinfo->addr, &saddr); 89 69 if (rc != EOK) { 90 70 dnsr_hostinfo_destroy(hinfo); 91 printf( "%s: Error formatting address.\n", NAME);92 return rc;71 printf(NAME ": Out of memory.\n"); 72 return 1; 93 73 } 94 74 95 75 printf("Host name: %s\n", hname); 96 97 76 if (str_cmp(hname, hinfo->cname) != 0) 98 77 printf("Canonical name: %s\n", hinfo->cname); 99 100 78 printf("Address: %s\n", saddr); 101 79 102 80 dnsr_hostinfo_destroy(hinfo); 103 81 free(saddr); 104 82 105 83 return 0; 106 84 }
Note:
See TracChangeset
for help on using the changeset viewer.