Changeset 31e9fe0 in mainline for uspace/app/dnsres
- Timestamp:
- 2013-04-23T22:05:01Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c55cbbf
- Parents:
- dc95342
- Location:
- uspace/app/dnsres
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnsres/dnsres.c
rdc95342 r31e9fe0 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 30 30 * @{ 31 31 */ 32 /** 33 * @file 32 /** @file DNS query utility. 34 33 */ 35 34 35 #include <errno.h> 36 #include <inet/dnsr.h> 36 37 #include <stdio.h> 37 38 #include <stdlib.h> 38 #include <errno.h>39 39 40 #include "dns_msg.h" 41 #include "dns_std.h" 42 #include "query.h" 40 #define NAME "dnsres" 43 41 44 #define NAME "dnsres" 42 static void print_syntax(void) 43 { 44 printf("syntax: " NAME " <host-name>\n"); 45 } 45 46 46 47 static int addr_format(inet_addr_t *addr, char **bufp) … … 60 61 int main(int argc, char *argv[]) 61 62 { 62 dns_host_info_t *hinfo;63 char *astr;64 63 int rc; 64 dnsr_hostinfo_t *hinfo; 65 char *saddr; 65 66 66 printf("%s: DNS Resolution Service\n", NAME); 67 rc = dns_name2host(argc < 2 ? "helenos.org" : argv[1], &hinfo); 68 printf("dns_name2host() -> rc = %d\n", rc); 67 rc = dnsr_init(); 68 if (rc != EOK) { 69 printf(NAME ": Failed connecting to DNS resolution service " 70 "(%d).\n", rc); 71 return 1; 72 } 69 73 70 if (rc == EOK) { 71 rc = addr_format(&hinfo->addr, &astr); 72 if (rc != EOK) { 73 dns_hostinfo_destroy(hinfo); 74 printf("Out of memory\n"); 75 return ENOMEM; 76 } 74 if (argc != 2) { 75 print_syntax(); 76 return 1; 77 } 77 78 78 printf("hostname: %s\n", hinfo->name);79 printf("IPv4 address: %s\n", astr);80 free(astr);81 dns_hostinfo_destroy(hinfo);79 rc = dnsr_name2host(argv[1], &hinfo); 80 if (rc != EOK) { 81 printf(NAME ": Error resolving '%s'.\n", argv[1]); 82 return 1; 82 83 } 84 85 rc = addr_format(&hinfo->addr, &saddr); 86 if (rc != EOK) { 87 dnsr_hostinfo_destroy(hinfo); 88 printf(NAME ": Out of memory.\n"); 89 return 1; 90 } 91 92 printf("Host name: %s address: %s\n", hinfo->name, saddr); 93 dnsr_hostinfo_destroy(hinfo); 94 free(saddr); 83 95 84 96 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.