Changeset c55cbbf in mainline for uspace/app/ping/ping.c
- Timestamp:
- 2013-04-24T06:52:50Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 287d729
- Parents:
- 31e9fe0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
r31e9fe0 rc55cbbf 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/dnsr.h> 39 40 #include <inet/inetping.h> 40 41 #include <io/console.h> … … 213 214 int main(int argc, char *argv[]) 214 215 { 216 dnsr_hostinfo_t *hinfo = NULL; 217 char *asrc = NULL; 218 char *adest = NULL; 219 char *sdest = NULL; 215 220 int rc; 216 221 int argi; … … 220 225 printf(NAME ": Failed connecting to internet ping service " 221 226 "(%d).\n", rc); 222 return 1;227 goto error; 223 228 } 224 229 … … 233 238 if (argc - argi != 1) { 234 239 print_syntax(); 235 return 1;240 goto error; 236 241 } 237 242 … … 239 244 rc = addr_parse(argv[argi], &dest_addr); 240 245 if (rc != EOK) { 241 printf(NAME ": Invalid address format.\n"); 242 print_syntax(); 243 return 1; 246 /* Try interpreting as a host name */ 247 rc = dnsr_init(); 248 if (rc != EOK) { 249 printf(NAME ": Failed connecting DNS resolution " 250 "service (%d).\n", rc); 251 goto error; 252 } 253 254 rc = dnsr_name2host(argv[argi], &hinfo); 255 if (rc != EOK) { 256 printf(NAME ": Error resolving host '%s'.\n", argv[argi]); 257 goto error; 258 } 259 260 dest_addr = hinfo->addr; 244 261 } 245 262 … … 248 265 if (rc != EOK) { 249 266 printf(NAME ": Failed determining source address.\n"); 250 return 1; 251 } 267 goto error; 268 } 269 270 rc = addr_format(&src_addr, &asrc); 271 if (rc != EOK) { 272 printf(NAME ": Out of memory.\n"); 273 goto error; 274 } 275 276 rc = addr_format(&dest_addr, &adest); 277 if (rc != EOK) { 278 printf(NAME ": Out of memory.\n"); 279 goto error; 280 } 281 282 if (hinfo != NULL) { 283 rc = asprintf(&sdest, "%s (%s)", hinfo->name, adest); 284 if (rc < 0) { 285 printf(NAME ": Out of memory.\n"); 286 goto error; 287 } 288 } else { 289 sdest = adest; 290 adest = NULL; 291 } 292 293 printf("Sending ICMP echo request from %s to %s.\n", 294 asrc, sdest); 252 295 253 296 fid_t fid; … … 257 300 if (fid == 0) { 258 301 printf(NAME ": Failed creating transmit fibril.\n"); 259 return 1;302 goto error; 260 303 } 261 304 … … 265 308 if (fid == 0) { 266 309 printf(NAME ": Failed creating input fibril.\n"); 267 return 1;310 goto error; 268 311 } 269 312 … … 283 326 if (rc == ETIMEOUT) { 284 327 printf(NAME ": Echo request timed out.\n"); 285 return 1; 286 } 287 328 goto error; 329 } 330 331 free(asrc); 332 free(adest); 333 free(sdest); 334 dnsr_hostinfo_destroy(hinfo); 288 335 return 0; 336 error: 337 free(asrc); 338 free(adest); 339 free(sdest); 340 dnsr_hostinfo_destroy(hinfo); 341 return 1; 289 342 } 290 343
Note:
See TracChangeset
for help on using the changeset viewer.