@@ -895,6 +895,54 @@ get_next_file(FILE *VFile, char *ptr)
895
895
return ret ;
896
896
}
897
897
898
+ static int
899
+ open_pcap_file (const char * path , const netdissect_options * ndo )
900
+ {
901
+ int dlt ;
902
+ const char * dlt_name ;
903
+ char ebuf [PCAP_ERRBUF_SIZE ];
904
+ static int sll_warning_printed = 0 ;
905
+ #ifdef HAVE_CAPSICUM
906
+ cap_rights_t rights ;
907
+ #endif /* HAVE_CAPSICUM */
908
+
909
+ #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
910
+ pd = pcap_open_offline_with_tstamp_precision (path ,
911
+ ndo -> ndo_tstamp_precision , ebuf );
912
+ #else
913
+ pd = pcap_open_offline (path , ebuf );
914
+ #endif
915
+
916
+ if (pd == NULL )
917
+ error ("%s" , ebuf );
918
+ #ifdef HAVE_CAPSICUM
919
+ cap_rights_init (& rights , CAP_READ );
920
+ if (cap_rights_limit (fileno (pcap_file (pd )), & rights ) < 0 &&
921
+ errno != ENOSYS ) {
922
+ error ("unable to limit pcap descriptor" );
923
+ }
924
+ #endif
925
+ dlt = pcap_datalink (pd );
926
+ dlt_name = pcap_datalink_val_to_name (dlt );
927
+ fprintf (stderr , "reading from file %s" , path );
928
+ if (dlt_name == NULL ) {
929
+ fprintf (stderr , ", link-type %u" , dlt );
930
+ } else {
931
+ fprintf (stderr , ", link-type %s (%s)" , dlt_name ,
932
+ pcap_datalink_val_to_description (dlt ));
933
+ }
934
+ fprintf (stderr , ", snapshot length %d\n" , pcap_snapshot (pd ));
935
+ #ifdef DLT_LINUX_SLL2
936
+ if (!sll_warning_printed && dlt == DLT_LINUX_SLL2 )
937
+ {
938
+ fprintf (stderr , "Warning: interface names might be incorrect\n" );
939
+ sll_warning_printed = 1 ;
940
+ }
941
+ #endif
942
+
943
+ return dlt ;
944
+ }
945
+
898
946
#ifdef HAVE_CASPER
899
947
static cap_channel_t *
900
948
capdns_setup (void )
@@ -1476,7 +1524,6 @@ main(int argc, char **argv)
1476
1524
char * endp ;
1477
1525
pcap_handler callback ;
1478
1526
int dlt ;
1479
- const char * dlt_name ;
1480
1527
struct bpf_program fcode ;
1481
1528
#ifndef _WIN32
1482
1529
void (* oldhandler )(int );
@@ -2121,36 +2168,7 @@ main(int argc, char **argv)
2121
2168
RFileName = VFileLine ;
2122
2169
}
2123
2170
2124
- #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
2125
- pd = pcap_open_offline_with_tstamp_precision (RFileName ,
2126
- ndo -> ndo_tstamp_precision , ebuf );
2127
- #else
2128
- pd = pcap_open_offline (RFileName , ebuf );
2129
- #endif
2130
-
2131
- if (pd == NULL )
2132
- error ("%s" , ebuf );
2133
- #ifdef HAVE_CAPSICUM
2134
- cap_rights_init (& rights , CAP_READ );
2135
- if (cap_rights_limit (fileno (pcap_file (pd )), & rights ) < 0 &&
2136
- errno != ENOSYS ) {
2137
- error ("unable to limit pcap descriptor" );
2138
- }
2139
- #endif
2140
- dlt = pcap_datalink (pd );
2141
- dlt_name = pcap_datalink_val_to_name (dlt );
2142
- fprintf (stderr , "reading from file %s" , RFileName );
2143
- if (dlt_name == NULL ) {
2144
- fprintf (stderr , ", link-type %u" , dlt );
2145
- } else {
2146
- fprintf (stderr , ", link-type %s (%s)" , dlt_name ,
2147
- pcap_datalink_val_to_description (dlt ));
2148
- }
2149
- fprintf (stderr , ", snapshot length %d\n" , pcap_snapshot (pd ));
2150
- #ifdef DLT_LINUX_SLL2
2151
- if (dlt == DLT_LINUX_SLL2 )
2152
- fprintf (stderr , "Warning: interface names might be incorrect\n" );
2153
- #endif
2171
+ dlt = open_pcap_file (RFileName , ndo );
2154
2172
} else if (dflag && !device ) {
2155
2173
int dump_dlt = DLT_EN10MB ;
2156
2174
/*
@@ -2604,6 +2622,8 @@ DIAG_ON_ASSIGN_ENUM
2604
2622
* to a file from the -V file). Print a message to
2605
2623
* the standard error on UN*X.
2606
2624
*/
2625
+ const char * dlt_name ;
2626
+
2607
2627
if (!ndo -> ndo_vflag && !WFileName ) {
2608
2628
(void )fprintf (stderr ,
2609
2629
"%s: verbose output suppressed, use -v[v]... for full protocol decode\n" ,
@@ -2683,17 +2703,7 @@ DIAG_ON_ASSIGN_ENUM
2683
2703
int new_dlt ;
2684
2704
2685
2705
RFileName = VFileLine ;
2686
- pd = pcap_open_offline (RFileName , ebuf );
2687
- if (pd == NULL )
2688
- error ("%s" , ebuf );
2689
- #ifdef HAVE_CAPSICUM
2690
- cap_rights_init (& rights , CAP_READ );
2691
- if (cap_rights_limit (fileno (pcap_file (pd )),
2692
- & rights ) < 0 && errno != ENOSYS ) {
2693
- error ("unable to limit pcap descriptor" );
2694
- }
2695
- #endif
2696
- new_dlt = pcap_datalink (pd );
2706
+ new_dlt = open_pcap_file (RFileName , ndo );
2697
2707
if (new_dlt != dlt ) {
2698
2708
/*
2699
2709
* The new file has a different
@@ -2735,20 +2745,6 @@ DIAG_ON_ASSIGN_ENUM
2735
2745
*/
2736
2746
if (pcap_setfilter (pd , & fcode ) < 0 )
2737
2747
error ("%s" , pcap_geterr (pd ));
2738
-
2739
- /*
2740
- * Report the new file.
2741
- */
2742
- dlt_name = pcap_datalink_val_to_name (dlt );
2743
- fprintf (stderr , "reading from file %s" , RFileName );
2744
- if (dlt_name == NULL ) {
2745
- fprintf (stderr , ", link-type %u" , dlt );
2746
- } else {
2747
- fprintf (stderr , ", link-type %s (%s)" ,
2748
- dlt_name ,
2749
- pcap_datalink_val_to_description (dlt ));
2750
- }
2751
- fprintf (stderr , ", snapshot length %d\n" , pcap_snapshot (pd ));
2752
2748
}
2753
2749
}
2754
2750
}
0 commit comments