aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/akcom-udpecho.c75
1 files changed, 34 insertions, 41 deletions
diff --git a/src/akcom-udpecho.c b/src/akcom-udpecho.c
index e667511..5a4b1f7 100644
--- a/src/akcom-udpecho.c
+++ b/src/akcom-udpecho.c
@@ -132,13 +132,6 @@ struct udp_echo_plus
132}; 132};
133 133
134 134
135union udp_buffer
136{
137 uint8_t * data;
138 struct udp_echo_plus * echoplus;
139};
140
141
142///////////////// 135/////////////////
143// // 136// //
144// Variables // 137// Variables //
@@ -237,8 +230,8 @@ main(
237 struct timespec start; 230 struct timespec start;
238 struct timespec now; 231 struct timespec now;
239 struct pollfd fds[2]; 232 struct pollfd fds[2];
240 union udp_buffer sndbuff; 233 struct udp_echo_plus * sndbuff;
241 union udp_buffer rcvbuff; 234 struct udp_echo_plus * rcvbuff;
242 235
243 // getopt options 236 // getopt options
244 static char short_opt[] = "46c:dehi:qrs:t:vV"; 237 static char short_opt[] = "46c:dehi:qrs:t:vV";
@@ -351,36 +344,36 @@ main(
351 cnf_packetsize = sizeof(struct udp_echo_plus); 344 cnf_packetsize = sizeof(struct udp_echo_plus);
352 345
353 // allocate receive buffer 346 // allocate receive buffer
354 if ((rcvbuff.data = malloc(cnf_packetsize)) == NULL) 347 if ((rcvbuff = malloc(cnf_packetsize)) == NULL)
355 { 348 {
356 fprintf(stderr, "%s: out of virtual memory\n", prog_name); 349 fprintf(stderr, "%s: out of virtual memory\n", prog_name);
357 return(1); 350 return(1);
358 }; 351 };
359 352
360 // allocate send buffer 353 // allocate send buffer
361 if ((sndbuff.data = malloc(cnf_packetsize)) == NULL) 354 if ((sndbuff = malloc(cnf_packetsize)) == NULL)
362 { 355 {
363 fprintf(stderr, "%s: out of virtual memory\n", prog_name); 356 fprintf(stderr, "%s: out of virtual memory\n", prog_name);
364 free(rcvbuff.data); 357 free(rcvbuff);
365 return(1); 358 return(1);
366 }; 359 };
367 memset(sndbuff.data, 0, sizeof(struct udp_echo_plus)); 360 memset(sndbuff, 0, sizeof(struct udp_echo_plus));
368 sndbuff.echoplus->iteration = htonl(1); 361 sndbuff->iteration = htonl(1);
369 if (cnf_packetsize > sizeof(struct udp_echo_plus)) 362 if (cnf_packetsize > sizeof(struct udp_echo_plus))
370 { 363 {
371 if ((fd = open("/dev/urandom", O_RDONLY)) == -1) 364 if ((fd = open("/dev/urandom", O_RDONLY)) == -1)
372 { 365 {
373 fprintf(stderr, "%s: open(/dev/urandom): %s\n", prog_name, strerror(errno)); 366 fprintf(stderr, "%s: open(/dev/urandom): %s\n", prog_name, strerror(errno));
374 free(rcvbuff.data); 367 free(rcvbuff);
375 free(sndbuff.data); 368 free(sndbuff);
376 return(1); 369 return(1);
377 }; 370 };
378 if (read(fd, sndbuff.echoplus->bytes, cnf_packetsize-sizeof(struct udp_echo_plus)) == -1) 371 if (read(fd, sndbuff->bytes, cnf_packetsize-sizeof(struct udp_echo_plus)) == -1)
379 { 372 {
380 fprintf(stderr, "%s: read(): %s\n", prog_name, strerror(errno)); 373 fprintf(stderr, "%s: read(): %s\n", prog_name, strerror(errno));
381 close(fd); 374 close(fd);
382 free(sndbuff.data); 375 free(sndbuff);
383 free(rcvbuff.data); 376 free(rcvbuff);
384 return(1); 377 return(1);
385 }; 378 };
386 close(fd); 379 close(fd);
@@ -399,8 +392,8 @@ main(
399 // resolve host 392 // resolve host
400 if ((s = my_socket(cnf_host, cnf_port, cnf_ai_family)) == -1) 393 if ((s = my_socket(cnf_host, cnf_port, cnf_ai_family)) == -1)
401 { 394 {
402 free(sndbuff.data); 395 free(sndbuff);
403 free(rcvbuff.data); 396 free(rcvbuff);
404 return(1); 397 return(1);
405 }; 398 };
406 fds[0].fd = s; 399 fds[0].fd = s;
@@ -447,32 +440,32 @@ main(
447 if ((count < (epoch/(10000*cnf_interval))) && ((count < cnf_count) || (!(cnf_count))) ) 440 if ((count < (epoch/(10000*cnf_interval))) && ((count < cnf_count) || (!(cnf_count))) )
448 { 441 {
449 count++; 442 count++;
450 sndbuff.echoplus->req_sn = htonl(count); 443 sndbuff->req_sn = htonl(count);
451 send(s, sndbuff.data, cnf_packetsize, 0); 444 send(s, sndbuff, cnf_packetsize, 0);
452 }; 445 };
453 446
454 // receive UDP echo response 447 // receive UDP echo response
455 if ((rc = poll(fds, 1, 0)) > 0) 448 if ((rc = poll(fds, 1, 0)) > 0)
456 { 449 {
457 if ((size = recv(s, rcvbuff.data, cnf_packetsize, 0)) == (ssize_t)cnf_packetsize) 450 if ((size = recv(s, rcvbuff, cnf_packetsize, 0)) == (ssize_t)cnf_packetsize)
458 { 451 {
459 rcvbuff.echoplus->req_sn = ntohl(rcvbuff.echoplus->req_sn); 452 rcvbuff->req_sn = ntohl(rcvbuff->req_sn);
460 rcvbuff.echoplus->res_sn = ntohl(rcvbuff.echoplus->res_sn); 453 rcvbuff->res_sn = ntohl(rcvbuff->res_sn);
461 rcvbuff.echoplus->recv_time = ntohl(rcvbuff.echoplus->recv_time); 454 rcvbuff->recv_time = ntohl(rcvbuff->recv_time);
462 rcvbuff.echoplus->reply_time = ntohl(rcvbuff.echoplus->reply_time); 455 rcvbuff->reply_time = ntohl(rcvbuff->reply_time);
463 rcvbuff.echoplus->failures = ntohl(rcvbuff.echoplus->failures); 456 rcvbuff->failures = ntohl(rcvbuff->failures);
464 rcvbuff.echoplus->iteration = ntohl(1); 457 rcvbuff->iteration = ntohl(1);
465 if ((cnf_debug)) 458 if ((cnf_debug))
466 { 459 {
467 printf(" packet: GenSN/REspSN: %08" PRIx32 " %08" PRIx32 "\n", rcvbuff.echoplus->req_sn, rcvbuff.echoplus->res_sn); 460 printf(" packet: GenSN/REspSN: %08" PRIx32 " %08" PRIx32 "\n", rcvbuff->req_sn, rcvbuff->res_sn);
468 printf(" Recv/Reply Time: %08" PRIx32 " %08" PRIx32 "\n", rcvbuff.echoplus->recv_time, rcvbuff.echoplus->reply_time); 461 printf(" Recv/Reply Time: %08" PRIx32 " %08" PRIx32 "\n", rcvbuff->recv_time, rcvbuff->reply_time);
469 printf(" Failures: %08" PRIx32 "\n", rcvbuff.echoplus->failures); 462 printf(" Failures: %08" PRIx32 "\n", rcvbuff->failures);
470 printf(" Iteration: %08" PRIx32 "\n", rcvbuff.echoplus->iteration); 463 printf(" Iteration: %08" PRIx32 "\n", rcvbuff->iteration);
471 }; 464 };
472 rcvd++; 465 rcvd++;
473 delay = rcvbuff.echoplus->reply_time - rcvbuff.echoplus->recv_time; 466 delay = rcvbuff->reply_time - rcvbuff->recv_time;
474 delay /= 100000000; 467 delay /= 100000000;
475 epoch -= (rcvbuff.echoplus->req_sn * 10000); 468 epoch -= (rcvbuff->req_sn * 10000);
476 epoch_adj = epoch - delay; 469 epoch_adj = epoch - delay;
477 avg += epoch; 470 avg += epoch;
478 avg_adj += epoch_adj; 471 avg_adj += epoch_adj;
@@ -487,8 +480,8 @@ main(
487 if ((cnf_echoplus)) 480 if ((cnf_echoplus))
488 { 481 {
489 printf("udpecho_seq=%u failures=%" PRIu32 " time=%" PRIu64 ".%" PRIu64 " ms delay=%" PRIu64 ".%" PRIu64 " ms adj_time=%" PRIu64 ".%" PRIu64 " ms\n", 482 printf("udpecho_seq=%u failures=%" PRIu32 " time=%" PRIu64 ".%" PRIu64 " ms delay=%" PRIu64 ".%" PRIu64 " ms adj_time=%" PRIu64 ".%" PRIu64 " ms\n",
490 rcvbuff.echoplus->req_sn, 483 rcvbuff->req_sn,
491 rcvbuff.echoplus->failures, 484 rcvbuff->failures,
492 epoch/10, epoch%10, 485 epoch/10, epoch%10,
493 delay/10, delay%10, 486 delay/10, delay%10,
494 epoch_adj/10, epoch_adj%10 487 epoch_adj/10, epoch_adj%10
@@ -496,7 +489,7 @@ main(
496 } else 489 } else
497 { 490 {
498 printf("udpecho_seq=%u time=%" PRIu64 ".%" PRIu64 " ms\n", 491 printf("udpecho_seq=%u time=%" PRIu64 ".%" PRIu64 " ms\n",
499 rcvbuff.echoplus->req_sn, 492 rcvbuff->req_sn,
500 epoch/10, epoch%10 493 epoch/10, epoch%10
501 ); 494 );
502 }; 495 };
@@ -535,8 +528,8 @@ main(
535 528
536 529
537 // free resources 530 // free resources
538 free(sndbuff.data); 531 free(sndbuff);
539 free(rcvbuff.data); 532 free(rcvbuff);
540 close(s); 533 close(s);
541 534
542 535