Changes in uspace/app/ping/ping.c [a62ceaf:9749e47] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
ra62ceaf r9749e47 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/dnsr.h> 39 40 #include <inet/addr.h> 40 #include <inet/host.h>41 41 #include <inet/inetping.h> 42 42 #include <io/console.h> … … 214 214 int main(int argc, char *argv[]) 215 215 { 216 dnsr_hostinfo_t *hinfo = NULL; 216 217 char *asrc = NULL; 217 218 char *adest = NULL; 218 219 char *sdest = NULL; 219 char *host;220 const char *errmsg;221 220 ip_ver_t ip_ver = ip_any; 222 221 … … 261 260 } 262 261 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; 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; 270 273 } 271 274 … … 289 292 } 290 293 291 rc = asprintf(&sdest, "%s (%s)", host, adest); 292 if (rc < 0) { 293 printf("Out of memory.\n"); 294 goto error; 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; 295 303 } 296 304 … … 322 330 free(adest); 323 331 free(sdest); 332 dnsr_hostinfo_destroy(hinfo); 324 333 return 0; 325 334 … … 328 337 free(adest); 329 338 free(sdest); 339 dnsr_hostinfo_destroy(hinfo); 330 340 return 1; 331 341 }
Note:
See TracChangeset
for help on using the changeset viewer.