@@ -217,8 +217,8 @@ static char *zflag = NULL; /* compress each savefile using a specified command
217
217
static int immediate_mode ;
218
218
#endif
219
219
220
- static int infodelay ;
221
220
static int infoprint ;
221
+ static int gotalarm ;
222
222
223
223
char * program_name ;
224
224
@@ -2387,6 +2387,9 @@ DIAG_ON_CLANG(assign-enum)
2387
2387
*/
2388
2388
struct itimerval timer ;
2389
2389
(void )setsignal (SIGALRM , verbose_stats_dump );
2390
+ alarm (1 );
2391
+ /* signal alarm to get the first iteration ASAP */
2392
+ gotalarm = 1 ;
2390
2393
timer .it_interval .tv_sec = 1 ;
2391
2394
timer .it_interval .tv_usec = 0 ;
2392
2395
timer .it_value .tv_sec = 1 ;
@@ -2738,8 +2741,6 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
2738
2741
2739
2742
++ packets_captured ;
2740
2743
2741
- ++ infodelay ;
2742
-
2743
2744
dump_info = (struct dump_info * )user ;
2744
2745
2745
2746
/*
@@ -2941,9 +2942,16 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
2941
2942
if (dump_info -> ndo != NULL )
2942
2943
pretty_print_packet (dump_info -> ndo , h , sp , packets_captured );
2943
2944
2944
- -- infodelay ;
2945
- if (infoprint )
2945
+ if (infoprint ) {
2946
2946
info (0 );
2947
+ infoprint = 0 ;
2948
+ }
2949
+
2950
+ if (gotalarm ) {
2951
+ fprintf (stderr , "Got %u\r" , packets_captured );
2952
+ gotalarm = 0 ;
2953
+ alarm (1 );
2954
+ }
2947
2955
}
2948
2956
2949
2957
static void
@@ -2953,8 +2961,6 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
2953
2961
2954
2962
++ packets_captured ;
2955
2963
2956
- ++ infodelay ;
2957
-
2958
2964
dump_info = (struct dump_info * )user ;
2959
2965
2960
2966
pcap_dump ((u_char * )dump_info -> pdd , h , sp );
@@ -2966,33 +2972,36 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
2966
2972
if (dump_info -> ndo != NULL )
2967
2973
pretty_print_packet (dump_info -> ndo , h , sp , packets_captured );
2968
2974
2969
- -- infodelay ;
2970
- if (infoprint )
2975
+ if (infoprint ) {
2971
2976
info (0 );
2977
+ infoprint = 0 ;
2978
+ }
2972
2979
}
2973
2980
2974
2981
static void
2975
2982
print_packet (u_char * user , const struct pcap_pkthdr * h , const u_char * sp )
2976
2983
{
2977
2984
++ packets_captured ;
2978
2985
2979
- ++ infodelay ;
2980
-
2981
2986
pretty_print_packet ((netdissect_options * )user , h , sp , packets_captured );
2982
2987
2983
- -- infodelay ;
2984
- if (infoprint )
2988
+ if (infoprint ) {
2985
2989
info (0 );
2990
+ infoprint = 0 ;
2991
+ }
2992
+
2993
+ if (gotalarm ) {
2994
+ fprintf (stderr , "Got %u\r" , packets_captured );
2995
+ gotalarm = 0 ;
2996
+ alarm (1 );
2997
+ }
2986
2998
}
2987
2999
2988
3000
#ifdef SIGNAL_REQ_INFO
2989
3001
static void
2990
3002
requestinfo (int signo _U_ )
2991
3003
{
2992
- if (infodelay )
2993
- ++ infoprint ;
2994
- else
2995
- info (0 );
3004
+ infoprint = 1 ;
2996
3005
}
2997
3006
#endif
2998
3007
@@ -3010,7 +3019,7 @@ print_packets_captured (void)
3010
3019
{
3011
3020
static u_int prev_packets_captured , first = 1 ;
3012
3021
3013
- if (infodelay == 0 && ( first || packets_captured != prev_packets_captured ) ) {
3022
+ if (first || packets_captured != prev_packets_captured ) {
3014
3023
fprintf (stderr , "Got %u\r" , packets_captured );
3015
3024
first = 0 ;
3016
3025
prev_packets_captured = packets_captured ;
@@ -3024,12 +3033,12 @@ print_packets_captured (void)
3024
3033
static void CALLBACK verbose_stats_dump (PVOID param _U_ ,
3025
3034
BOOLEAN timer_fired _U_ )
3026
3035
{
3027
- print_packets_captured () ;
3036
+ gotalarm = 1 ;
3028
3037
}
3029
3038
#else /* _WIN32 */
3030
3039
static void verbose_stats_dump (int sig _U_ )
3031
3040
{
3032
- print_packets_captured () ;
3041
+ gotalarm = 1 ;
3033
3042
}
3034
3043
#endif /* _WIN32 */
3035
3044
0 commit comments