@@ -59,11 +59,7 @@ int ping_host(host_t *host, ping_t *ping) {
59
59
60
60
if (host -> ping_method == PING_ICMP ) {
61
61
if (set .icmp_avail == FALSE) {
62
- if (is_debug_device (host -> id )) {
63
- SPINE_LOG (("Device[%i] DEBUG Falling back to UDP Ping Due to SetUID Issues" , host -> id ));
64
- } else {
65
- SPINE_LOG_DEBUG (("Device[%i] DEBUG Falling back to UDP Ping Due to SetUID Issues" , host -> id ));
66
- }
62
+ SPINE_LOG (("Device[%i] DEBUG Falling back to UDP Ping Due to SetUID Issues" , host -> id ));
67
63
host -> ping_method = PING_UDP ;
68
64
}
69
65
}
@@ -387,26 +383,13 @@ int ping_icmp(host_t *host, ping_t *ping) {
387
383
return HOST_DOWN ;
388
384
}
389
385
390
- /* record start time */
391
- if (total_time == 0 ) {
392
- /* establish timeout value */
393
- timeout .tv_sec = rint (host_timeout / 1000 );
394
- timeout .tv_usec = rint ((int ) host_timeout % 1000 ) * 1000 ;
395
-
396
- /* set the socket send and receive timeout */
397
- setsockopt (icmp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
398
- setsockopt (icmp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
399
-
400
- begin_time = get_time_as_double ();
401
- } else {
402
- /* decrement the timeout value by the total time */
403
- timeout .tv_sec = rint ((host_timeout - total_time ) / 1000 );
404
- timeout .tv_usec = ((int ) (host_timeout - total_time ) % 1000 ) * 1000 ;
386
+ /* decrement the timeout value by the total time */
387
+ timeout .tv_sec = rint ((host_timeout - total_time ) / 1000 );
388
+ timeout .tv_usec = ((int ) (host_timeout - total_time ) % 1000 ) * 1000 ;
405
389
406
- /* set the socket send and receive timeout */
407
- setsockopt (icmp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
408
- setsockopt (icmp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
409
- }
390
+ /* set the socket send and receive timeout */
391
+ setsockopt (icmp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
392
+ setsockopt (icmp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
410
393
411
394
/* send packet to destination */
412
395
return_code = sendto (icmp_socket , packet , packet_len , 0 , (struct sockaddr * ) & fromname , sizeof (fromname ));
@@ -432,21 +415,22 @@ int ping_icmp(host_t *host, ping_t *ping) {
432
415
433
416
if (return_code < 0 ) {
434
417
if (errno == EINTR ) {
418
+ /* call was interrupted by some system event */
419
+
435
420
if (is_debug_device (host -> id )) {
436
421
SPINE_LOG (("Device[%i] DEBUG: Received EINTR" , host -> id ));
437
422
} else {
438
423
SPINE_LOG_DEBUG (("Device[%i] DEBUG: Received EINTR" , host -> id ));
439
424
}
440
- /* call was interrupted by some system event */
441
- // usleep(10000);
425
+
442
426
goto keep_listening ;
443
427
}
444
428
} else {
445
429
ip = (struct ip * ) socket_reply ;
446
430
pkt = (struct icmp * ) (socket_reply + (ip -> ip_hl << 2 ));
447
431
448
432
if (fromname .sin_addr .s_addr == recvname .sin_addr .s_addr ) {
449
- if (( pkt -> icmp_type == ICMP_ECHOREPLY ) ) {
433
+ if (pkt -> icmp_type == ICMP_ECHOREPLY ) {
450
434
if (is_debug_device (host -> id )) {
451
435
SPINE_LOG (("Device[%i] DEBUG: ICMP Device Alive, Try Count:%i, Time:%.4f ms" , host -> id , retry_count + 1 , (total_time )));
452
436
} else {
@@ -591,6 +575,8 @@ int ping_udp(host_t *host, ping_t *ping) {
591
575
/* set total time */
592
576
total_time = 0 ;
593
577
578
+ begin_time = get_time_as_double ();
579
+
594
580
/* remove "udp:" from hostname */
595
581
new_hostname = remove_tcp_udp_from_hostname (host -> hostname );
596
582
@@ -644,8 +630,6 @@ int ping_udp(host_t *host, ping_t *ping) {
644
630
/* set the socket send and receive timeout */
645
631
setsockopt (udp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
646
632
setsockopt (udp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
647
-
648
- begin_time = get_time_as_double ();
649
633
} else {
650
634
/* decrement the timeout value by the total time */
651
635
timeout .tv_sec = rint ((host_timeout - total_time ) / 1000 );
@@ -769,6 +753,12 @@ int ping_tcp(host_t *host, ping_t *ping) {
769
753
/* initilize the socket */
770
754
tcp_socket = socket (AF_INET , SOCK_STREAM , IPPROTO_TCP );
771
755
756
+ /* initialize total time */
757
+ total_time = 0 ;
758
+
759
+ /* initialize begin time */
760
+ begin_time = get_time_as_double ();
761
+
772
762
/* hostname must be nonblank */
773
763
if ((strlen (host -> hostname ) != 0 ) && (tcp_socket != -1 )) {
774
764
/* initialize variables */
@@ -781,26 +771,13 @@ int ping_tcp(host_t *host, ping_t *ping) {
781
771
retry_count = 0 ;
782
772
783
773
while (1 ) {
784
- /* record start time */
785
- if (total_time == 0 ) {
786
- /* establish timeout value */
787
- timeout .tv_sec = rint (host_timeout / 1000 );
788
- timeout .tv_usec = ((int ) host_timeout % 1000 ) * 1000 ;
774
+ /* establish timeout value */
775
+ timeout .tv_sec = rint (host_timeout / 1000 );
776
+ timeout .tv_usec = ((int ) host_timeout % 1000 ) * 1000 ;
789
777
790
- /* set the socket send and receive timeout */
791
- setsockopt (tcp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
792
- setsockopt (tcp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
793
-
794
- begin_time = get_time_as_double ();
795
- } else {
796
- /* decrement the timeout value by the total time */
797
- timeout .tv_sec = rint ((host_timeout - total_time ) / 1000 );
798
- timeout .tv_usec = ((int ) (host_timeout - total_time ) % 1000 ) * 1000 ;
799
-
800
- /* set the socket send and receive timeout */
801
- setsockopt (tcp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
802
- setsockopt (tcp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
803
- }
778
+ /* set the socket send and receive timeout */
779
+ setsockopt (tcp_socket , SOL_SOCKET , SO_RCVTIMEO , (char * )& timeout , sizeof (timeout ));
780
+ setsockopt (tcp_socket , SOL_SOCKET , SO_SNDTIMEO , (char * )& timeout , sizeof (timeout ));
804
781
805
782
/* make the connection */
806
783
return_code = connect (tcp_socket , (struct sockaddr * ) & servername , sizeof (servername ));
@@ -901,7 +878,7 @@ int init_sockaddr(struct sockaddr_in *name, const char *hostname, unsigned short
901
878
int rv ;
902
879
903
880
buf = malloc (len * sizeof (char ));
904
- memset (buf , 0 , sizeof (buf ));
881
+ memset (buf , 0 , len * sizeof (char ));
905
882
906
883
while (1 ) {
907
884
rv = gethostbyname_r (hostname , & result_buf , buf , len ,
@@ -1107,20 +1084,20 @@ void update_host_status(int status, host_t *host, ping_t *ping, int availability
1107
1084
case AVAIL_SNMP_OR_PING :
1108
1085
case AVAIL_SNMP_AND_PING :
1109
1086
if ((strlen (host -> snmp_community ) == 0 ) && (host -> snmp_version < 3 )) {
1110
- snprintf (host -> status_last_error , SMALL_BUFSIZE , "%s" , ping -> ping_response );
1087
+ snprintf (host -> status_last_error , BUFSIZE , "%s" , ping -> ping_response );
1111
1088
} else {
1112
- snprintf (host -> status_last_error , SMALL_BUFSIZE ,"%s, %s" ,ping -> snmp_response ,ping -> ping_response );
1089
+ snprintf (host -> status_last_error , BUFSIZE ,"%s, %s" ,ping -> snmp_response ,ping -> ping_response );
1113
1090
}
1114
1091
break ;
1115
1092
case AVAIL_SNMP :
1116
1093
if ((strlen (host -> snmp_community ) == 0 ) && (host -> snmp_version < 3 )) {
1117
- snprintf (host -> status_last_error , SMALL_BUFSIZE , "%s" , "Device does not require SNMP" );
1094
+ snprintf (host -> status_last_error , BUFSIZE , "%s" , "Device does not require SNMP" );
1118
1095
} else {
1119
- snprintf (host -> status_last_error , SMALL_BUFSIZE , "%s" , ping -> snmp_response );
1096
+ snprintf (host -> status_last_error , BUFSIZE , "%s" , ping -> snmp_response );
1120
1097
}
1121
1098
break ;
1122
1099
default :
1123
- snprintf (host -> status_last_error , SMALL_BUFSIZE , "%s" , ping -> ping_response );
1100
+ snprintf (host -> status_last_error , BUFSIZE , "%s" , ping -> ping_response );
1124
1101
}
1125
1102
1126
1103
/* determine if to send an alert and update remainder of statistics */
0 commit comments