Changeset 9749e47 in mainline for uspace/app/ping/ping.c
- Timestamp:
- 2013-10-04T19:23:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1d04b2
- Parents:
- 26de91a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
r26de91a r9749e47 76 76 }; 77 77 78 static addr32_t src;79 static addr32_t dest;78 static inet_addr_t src_addr; 79 static inet_addr_t dest_addr; 80 80 81 81 static bool repeat_forever = false; 82 82 static size_t repeat_count = 1; 83 83 84 static const char *short_options = " rn:";84 static const char *short_options = "46rn:"; 85 85 86 86 static void print_syntax(void) 87 87 { 88 printf("Syntax: %s [-n <count>|-r] <host>\n", NAME); 88 printf("Syntax: %s [<options>] <host>\n", NAME); 89 printf("\t-n <count> Repeat the specified number of times\n"); 90 printf("\t-r Repeat forever\n"); 91 printf("\t-4|-6 Use IPv4 or IPv6 destination host address\n"); 89 92 } 90 93 … … 107 110 static int ping_ev_recv(inetping_sdu_t *sdu) 108 111 { 109 inet_addr_t src_addr;110 inet_addr_set(sdu->src, &src_addr);111 112 inet_addr_t dest_addr;113 inet_addr_set(sdu->dest, &dest_addr);114 115 112 char *asrc; 116 113 int rc = inet_addr_format(&src_addr, &asrc); … … 139 136 inetping_sdu_t sdu; 140 137 141 sdu.src = src ;142 sdu.dest = dest ;138 sdu.src = src_addr; 139 sdu.dest = dest_addr; 143 140 sdu.seq_no = seq_no; 144 141 sdu.data = (void *) "foo"; … … 221 218 char *adest = NULL; 222 219 char *sdest = NULL; 220 ip_ver_t ip_ver = ip_any; 223 221 224 222 int rc = inetping_init(&ev_ops); … … 243 241 } 244 242 break; 243 case '4': 244 ip_ver = ip_v4; 245 break; 246 case '6': 247 ip_ver = ip_v6; 248 break; 245 249 default: 246 250 printf("Unknown option passed.\n"); … … 257 261 258 262 /* Parse destination address */ 259 inet_addr_t dest_addr;260 263 rc = inet_addr_parse(argv[optind], &dest_addr); 261 264 if (rc != EOK) { 262 265 /* Try interpreting as a host name */ 263 rc = dnsr_name2host(argv[optind], &hinfo, ip_v 4);266 rc = dnsr_name2host(argv[optind], &hinfo, ip_ver); 264 267 if (rc != EOK) { 265 268 printf("Error resolving host '%s'.\n", argv[optind]); … … 270 273 } 271 274 272 ip_ver_t ver = inet_addr_get(&dest_addr, &dest, NULL);273 if (ver != ip_v4) {274 printf("Destination '%s' is not an IPv4 address.\n",275 argv[optind]);276 goto error;277 }278 279 275 /* Determine source address */ 280 rc = inetping_get_srcaddr( dest, &src);276 rc = inetping_get_srcaddr(&dest_addr, &src_addr); 281 277 if (rc != EOK) { 282 278 printf("Failed determining source address.\n"); 283 279 goto error; 284 280 } 285 286 inet_addr_t src_addr;287 inet_addr_set(src, &src_addr);288 281 289 282 rc = inet_addr_format(&src_addr, &asrc);
Note:
See TracChangeset
for help on using the changeset viewer.