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