@@ -99,7 +99,7 @@ void check_length_order(
99
99
100
100
if (resolve_probe_addresses (& param , & dest_sockaddr , & src_sockaddr )) {
101
101
fprintf (stderr , "Error decoding localhost address\n" );
102
- exit (1 );
102
+ exit (EXIT_FAILURE );
103
103
}
104
104
105
105
/* First attempt to ping the localhost with network byte order */
@@ -111,7 +111,7 @@ void check_length_order(
111
111
& dest_sockaddr , & src_sockaddr , & param );
112
112
if (packet_size < 0 ) {
113
113
perror ("Unable to send to localhost" );
114
- exit (1 );
114
+ exit (EXIT_FAILURE );
115
115
}
116
116
117
117
bytes_sent = send_packet (
@@ -129,14 +129,14 @@ void check_length_order(
129
129
& dest_sockaddr , & src_sockaddr , & param );
130
130
if (packet_size < 0 ) {
131
131
perror ("Unable to send to localhost" );
132
- exit (1 );
132
+ exit (EXIT_FAILURE );
133
133
}
134
134
135
135
bytes_sent = send_packet (
136
136
net_state , & param , packet , packet_size , & dest_sockaddr );
137
137
if (bytes_sent < 0 ) {
138
138
perror ("Unable to send with swapped length" );
139
- exit (1 );
139
+ exit (EXIT_FAILURE );
140
140
}
141
141
}
142
142
@@ -171,12 +171,12 @@ void set_socket_nonblocking(
171
171
flags = fcntl (socket , F_GETFL , 0 );
172
172
if (flags == -1 ) {
173
173
perror ("Unexpected socket F_GETFL error" );
174
- exit (1 );
174
+ exit (EXIT_FAILURE );
175
175
}
176
176
177
177
if (fcntl (socket , F_SETFL , flags | O_NONBLOCK )) {
178
178
perror ("Unexpected socket F_SETFL O_NONBLOCK error" );
179
- exit (1 );
179
+ exit (EXIT_FAILURE );
180
180
}
181
181
}
182
182
@@ -192,7 +192,7 @@ void open_ip4_sockets(
192
192
send_socket = socket (AF_INET , SOCK_RAW , IPPROTO_RAW );
193
193
if (send_socket == -1 ) {
194
194
perror ("Failure opening IPv4 send socket" );
195
- exit (1 );
195
+ exit (EXIT_FAILURE );
196
196
}
197
197
198
198
/*
@@ -203,7 +203,7 @@ void open_ip4_sockets(
203
203
send_socket , IPPROTO_IP , IP_HDRINCL , & trueopt , sizeof (int ))) {
204
204
205
205
perror ("Failure to set IP_HDRINCL" );
206
- exit (1 );
206
+ exit (EXIT_FAILURE );
207
207
}
208
208
209
209
/*
@@ -213,7 +213,7 @@ void open_ip4_sockets(
213
213
recv_socket = socket (AF_INET , SOCK_RAW , IPPROTO_ICMP );
214
214
if (recv_socket == -1 ) {
215
215
perror ("Failure opening IPv4 receive socket" );
216
- exit (1 );
216
+ exit (EXIT_FAILURE );
217
217
}
218
218
219
219
net_state -> platform .ip4_send_socket = send_socket ;
@@ -232,19 +232,19 @@ void open_ip6_sockets(
232
232
send_socket_icmp = socket (AF_INET6 , SOCK_RAW , IPPROTO_ICMPV6 );
233
233
if (send_socket_icmp == -1 ) {
234
234
perror ("Failure opening ICMPv6 send socket" );
235
- exit (1 );
235
+ exit (EXIT_FAILURE );
236
236
}
237
237
238
238
send_socket_udp = socket (AF_INET6 , SOCK_RAW , IPPROTO_UDP );
239
239
if (send_socket_udp == -1 ) {
240
240
perror ("Failure opening UDPv6 send socket" );
241
- exit (1 );
241
+ exit (EXIT_FAILURE );
242
242
}
243
243
244
244
recv_socket = socket (AF_INET6 , SOCK_RAW , IPPROTO_ICMPV6 );
245
245
if (recv_socket == -1 ) {
246
246
perror ("Failure opening IPv6 receive socket" );
247
- exit (1 );
247
+ exit (EXIT_FAILURE );
248
248
}
249
249
250
250
set_socket_nonblocking (recv_socket );
@@ -352,13 +352,13 @@ void send_probe(
352
352
353
353
if (resolve_probe_addresses (param , & probe -> remote_addr , & src_sockaddr )) {
354
354
printf ("%d invalid-argument\n" , param -> command_token );
355
- free_probe (probe );
355
+ free_probe (net_state , probe );
356
356
return ;
357
357
}
358
358
359
359
if (gettimeofday (& probe -> platform .departure_time , NULL )) {
360
360
perror ("gettimeofday failure" );
361
- exit (1 );
361
+ exit (EXIT_FAILURE );
362
362
}
363
363
364
364
packet_size = construct_packet (
@@ -375,10 +375,11 @@ void send_probe(
375
375
*/
376
376
if (errno == ECONNREFUSED ) {
377
377
receive_probe (
378
- probe , ICMP_ECHOREPLY , & probe -> remote_addr , NULL , 0 , NULL );
378
+ net_state , probe , ICMP_ECHOREPLY ,
379
+ & probe -> remote_addr , NULL , 0 , NULL );
379
380
} else {
380
381
report_packet_error (param -> command_token );
381
- free_probe (probe );
382
+ free_probe (net_state , probe );
382
383
}
383
384
384
385
return ;
@@ -390,7 +391,7 @@ void send_probe(
390
391
packet , packet_size , & probe -> remote_addr ) == -1 ) {
391
392
392
393
report_packet_error (param -> command_token );
393
- free_probe (probe );
394
+ free_probe (net_state , probe );
394
395
return ;
395
396
}
396
397
}
@@ -429,6 +430,7 @@ void platform_free_probe(
429
430
to the platform agnostic response handling.
430
431
*/
431
432
void receive_probe (
433
+ struct net_state_t * net_state ,
432
434
struct probe_t * probe ,
433
435
int icmp_type ,
434
436
const struct sockaddr_storage * remote_addr ,
@@ -443,7 +445,7 @@ void receive_probe(
443
445
if (timestamp == NULL ) {
444
446
if (gettimeofday (& now , NULL )) {
445
447
perror ("gettimeofday failure" );
446
- exit (1 );
448
+ exit (EXIT_FAILURE );
447
449
}
448
450
449
451
timestamp = & now ;
@@ -454,7 +456,8 @@ void receive_probe(
454
456
timestamp -> tv_usec - departure_time -> tv_usec ;
455
457
456
458
respond_to_probe (
457
- probe , icmp_type , remote_addr , round_trip_us , mpls_count , mpls );
459
+ net_state , probe , icmp_type ,
460
+ remote_addr , round_trip_us , mpls_count , mpls );
458
461
}
459
462
460
463
/*
@@ -486,7 +489,7 @@ void receive_replies_from_icmp_socket(
486
489
*/
487
490
if (gettimeofday (& timestamp , NULL )) {
488
491
perror ("gettimeofday failure" );
489
- exit (1 );
492
+ exit (EXIT_FAILURE );
490
493
}
491
494
492
495
if (packet_length == -1 ) {
@@ -507,7 +510,7 @@ void receive_replies_from_icmp_socket(
507
510
}
508
511
509
512
perror ("Failure receiving replies" );
510
- exit (1 );
513
+ exit (EXIT_FAILURE );
511
514
}
512
515
513
516
handle_received_packet (
@@ -547,7 +550,7 @@ void receive_replies_from_probe_socket(
547
550
return ;
548
551
} else {
549
552
perror ("probe socket select error" );
550
- exit (1 );
553
+ exit (EXIT_FAILURE );
551
554
}
552
555
}
553
556
@@ -560,7 +563,7 @@ void receive_replies_from_probe_socket(
560
563
561
564
if (getsockopt (probe_socket , SOL_SOCKET , SO_ERROR , & err , & err_length )) {
562
565
perror ("probe socket SO_ERROR" );
563
- exit (1 );
566
+ exit (EXIT_FAILURE );
564
567
}
565
568
566
569
/*
@@ -569,20 +572,21 @@ void receive_replies_from_probe_socket(
569
572
*/
570
573
if (!err || err == ECONNREFUSED ) {
571
574
receive_probe (
572
- probe , ICMP_ECHOREPLY , & probe -> remote_addr , NULL , 0 , NULL );
575
+ net_state , probe , ICMP_ECHOREPLY ,
576
+ & probe -> remote_addr , NULL , 0 , NULL );
573
577
} else {
574
578
errno = err ;
575
579
report_packet_error (probe -> token );
576
- free_probe (probe );
580
+ free_probe (net_state , probe );
577
581
}
578
582
}
579
583
580
584
/* Check both the IPv4 and IPv6 sockets for incoming packets */
581
585
void receive_replies (
582
586
struct net_state_t * net_state )
583
587
{
584
- int i ;
585
588
struct probe_t * probe ;
589
+ struct probe_t * probe_safe_iter ;
586
590
587
591
receive_replies_from_icmp_socket (
588
592
net_state , net_state -> platform .ip4_recv_socket ,
@@ -592,12 +596,11 @@ void receive_replies(
592
596
net_state , net_state -> platform .ip6_recv_socket ,
593
597
handle_received_ip6_packet );
594
598
595
- for (i = 0 ; i < MAX_PROBES ; i ++ ) {
596
- probe = & net_state -> probes [i ];
599
+ LIST_FOREACH_SAFE (
600
+ probe , & net_state -> outstanding_probes ,
601
+ probe_list_entry , probe_safe_iter ) {
597
602
598
- if (probe -> used ) {
599
- receive_replies_from_probe_socket (net_state , probe );
600
- }
603
+ receive_replies_from_probe_socket (net_state , probe );
601
604
}
602
605
}
603
606
@@ -609,18 +612,16 @@ int gather_probe_sockets(
609
612
const struct net_state_t * net_state ,
610
613
fd_set * write_set )
611
614
{
612
- int i ;
613
615
int probe_socket ;
614
616
int nfds ;
615
617
const struct probe_t * probe ;
616
618
617
619
nfds = 0 ;
618
620
619
- for (i = 0 ; i < MAX_PROBES ; i ++ ) {
620
- probe = & net_state -> probes [i ];
621
+ LIST_FOREACH (probe , & net_state -> outstanding_probes , probe_list_entry ) {
621
622
probe_socket = probe -> platform .socket ;
622
623
623
- if (probe -> used && probe_socket ) {
624
+ if (probe_socket ) {
624
625
FD_SET (probe_socket , write_set );
625
626
if (probe_socket >= nfds ) {
626
627
nfds = probe_socket + 1 ;
@@ -641,26 +642,22 @@ void check_probe_timeouts(
641
642
{
642
643
struct timeval now ;
643
644
struct probe_t * probe ;
644
- int i ;
645
+ struct probe_t * probe_safe_iter ;
645
646
646
647
if (gettimeofday (& now , NULL )) {
647
648
perror ("gettimeofday failure" );
648
- exit (1 );
649
+ exit (EXIT_FAILURE );
649
650
}
650
651
651
- for (i = 0 ; i < MAX_PROBES ; i ++ ) {
652
- probe = & net_state -> probes [i ];
653
-
654
- /* Don't check probes which aren't currently outstanding */
655
- if (!probe -> used ) {
656
- continue ;
657
- }
652
+ LIST_FOREACH_SAFE (
653
+ probe , & net_state -> outstanding_probes ,
654
+ probe_list_entry , probe_safe_iter ) {
658
655
659
656
if (compare_timeval (probe -> platform .timeout_time , now ) < 0 ) {
660
657
/* Report timeout to the command stream */
661
658
printf ("%d no-reply\n" , probe -> token );
662
659
663
- free_probe (probe );
660
+ free_probe (net_state , probe );
664
661
}
665
662
}
666
663
}
@@ -677,24 +674,18 @@ bool get_next_probe_timeout(
677
674
const struct net_state_t * net_state ,
678
675
struct timeval * timeout )
679
676
{
680
- int i ;
681
677
bool have_timeout ;
682
678
const struct probe_t * probe ;
683
679
struct timeval now ;
684
680
struct timeval probe_timeout ;
685
681
686
682
if (gettimeofday (& now , NULL )) {
687
683
perror ("gettimeofday failure" );
688
- exit (1 );
684
+ exit (EXIT_FAILURE );
689
685
}
690
686
691
687
have_timeout = false;
692
- for (i = 0 ; i < MAX_PROBES ; i ++ ) {
693
- probe = & net_state -> probes [i ];
694
- if (!probe -> used ) {
695
- continue ;
696
- }
697
-
688
+ LIST_FOREACH (probe , & net_state -> outstanding_probes , probe_list_entry ) {
698
689
probe_timeout .tv_sec =
699
690
probe -> platform .timeout_time .tv_sec - now .tv_sec ;
700
691
probe_timeout .tv_usec =
0 commit comments