Changes in uspace/app/ping/ping.c [ccdc63e:9749e47] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
rccdc63e r9749e47 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <net/socket_codes.h>40 39 #include <inet/dnsr.h> 41 40 #include <inet/addr.h> … … 77 76 }; 78 77 79 static addr32_t src;80 static addr32_t dest;78 static inet_addr_t src_addr; 79 static inet_addr_t dest_addr; 81 80 82 81 static bool repeat_forever = false; 83 82 static size_t repeat_count = 1; 84 83 85 static const char *short_options = " rn:";84 static const char *short_options = "46rn:"; 86 85 87 86 static void print_syntax(void) 88 87 { 89 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"); 90 92 } 91 93 … … 108 110 static int ping_ev_recv(inetping_sdu_t *sdu) 109 111 { 110 inet_addr_t src_addr;111 inet_addr_set(sdu->src, &src_addr);112 113 inet_addr_t dest_addr;114 inet_addr_set(sdu->dest, &dest_addr);115 116 112 char *asrc; 117 113 int rc = inet_addr_format(&src_addr, &asrc); … … 140 136 inetping_sdu_t sdu; 141 137 142 sdu.src = src ;143 sdu.dest = dest ;138 sdu.src = src_addr; 139 sdu.dest = dest_addr; 144 140 sdu.seq_no = seq_no; 145 141 sdu.data = (void *) "foo"; … … 222 218 char *adest = NULL; 223 219 char *sdest = NULL; 220 ip_ver_t ip_ver = ip_any; 224 221 225 222 int rc = inetping_init(&ev_ops); … … 244 241 } 245 242 break; 243 case '4': 244 ip_ver = ip_v4; 245 break; 246 case '6': 247 ip_ver = ip_v6; 248 break; 246 249 default: 247 250 printf("Unknown option passed.\n"); … … 258 261 259 262 /* Parse destination address */ 260 inet_addr_t dest_addr;261 263 rc = inet_addr_parse(argv[optind], &dest_addr); 262 264 if (rc != EOK) { 263 265 /* Try interpreting as a host name */ 264 rc = dnsr_name2host(argv[optind], &hinfo, AF_INET);266 rc = dnsr_name2host(argv[optind], &hinfo, ip_ver); 265 267 if (rc != EOK) { 266 268 printf("Error resolving host '%s'.\n", argv[optind]); … … 271 273 } 272 274 273 uint16_t af = inet_addr_get(&dest_addr, &dest, NULL);274 if (af != AF_INET) {275 printf("Destination '%s' is not an IPv4 address.\n",276 argv[optind]);277 goto error;278 }279 280 275 /* Determine source address */ 281 rc = inetping_get_srcaddr( dest, &src);276 rc = inetping_get_srcaddr(&dest_addr, &src_addr); 282 277 if (rc != EOK) { 283 278 printf("Failed determining source address.\n"); 284 279 goto error; 285 280 } 286 287 inet_addr_t src_addr;288 inet_addr_set(src, &src_addr);289 281 290 282 rc = inet_addr_format(&src_addr, &asrc);
Note:
See TracChangeset
for help on using the changeset viewer.