@@ -1898,10 +1898,10 @@ static int process_ng(FILE *in)
18981898 int aktseek ;
18991899
19001900 while (1 ) {
1901- block_header_t pcapngbh ;
1902- interface_description_block_t pcapngidb ;
1901+ block_header_t pcapng_bh ;
1902+ interface_description_block_t pcapng_idb ;
19031903
1904- res = fread (& pcapngbh , 1 , BH_SIZE , in );
1904+ res = fread (& pcapng_bh , 1 , BH_SIZE , in );
19051905 if (res == 0 ) {
19061906 break ;
19071907 }
@@ -1912,175 +1912,177 @@ static int process_ng(FILE *in)
19121912 }
19131913
19141914 if (verbosity >= 4 )
1915- fprintf (stderr , "pcap-ng block type %u\n" , pcapngbh .block_type );
1915+ fprintf (stderr , "pcap-ng block type %u\n" , pcapng_bh .block_type );
19161916
19171917 /* SHB, Section Header Block */
1918- if (pcapngbh .block_type == PCAPNGBLOCKTYPE ) {
1919- section_header_block_t pcapngshb ;
1918+ if (pcapng_bh .block_type == PCAPNGBLOCKTYPE ) {
1919+ section_header_block_t pcapng_shb ;
19201920
1921- res = fread (& pcapngshb , 1 , SHB_SIZE , in );
1921+ res = fread (& pcapng_shb , 1 , SHB_SIZE , in );
19221922 if (res != SHB_SIZE ) {
1923- fprintf (stderr , "%s: Failed to read pcapng SHB: %s\n" ,
1923+ fprintf (stderr , "%s: Failed to read pcap-ng SHB: %s\n" ,
19241924 filename , feof (in ) ? "EOF" : strerror (errno ));
19251925 break ;
19261926 }
19271927
1928- swap_needed = (pcapngshb .byte_order_magic == PCAPNGMAGICNUMBERBE );
1928+ swap_needed = (pcapng_shb .byte_order_magic == PCAPNGMAGICNUMBERBE );
19291929 swap_needed ^= !ARCH_LITTLE_ENDIAN ;
19301930
19311931 if (swap_needed ) {
1932- pcapngbh .block_type = swap32u (pcapngbh .block_type );
1933- pcapngbh .total_length = swap32u (pcapngbh .total_length );
1934- pcapngshb .byte_order_magic = swap32u (pcapngshb .byte_order_magic );
1935- pcapngshb .major_version = swap16u (pcapngshb .major_version );
1936- pcapngshb .minor_version = swap16u (pcapngshb .minor_version );
1937- pcapngshb .section_length = swap64u (pcapngshb .section_length );
1932+ pcapng_bh .block_type = swap32u (pcapng_bh .block_type );
1933+ pcapng_bh .total_length = swap32u (pcapng_bh .total_length );
1934+ pcapng_shb .byte_order_magic = swap32u (pcapng_shb .byte_order_magic );
1935+ pcapng_shb .major_version = swap16u (pcapng_shb .major_version );
1936+ pcapng_shb .minor_version = swap16u (pcapng_shb .minor_version );
1937+ pcapng_shb .section_length = swap64u (pcapng_shb .section_length );
19381938 }
19391939
19401940 aktseek = ftell (in );
1941- if (pcapngbh .total_length > (SHB_SIZE + BH_SIZE + 4 )) {
1942- pcapng_option_walk (in , pcapngbh .total_length );
1941+ if (pcapng_bh .total_length > (SHB_SIZE + BH_SIZE + 4 )) {
1942+ pcapng_option_walk (in , pcapng_bh .total_length );
19431943 }
1944- fseek_chk (in , aktseek + pcapngbh .total_length - BH_SIZE - SHB_SIZE , SEEK_SET );
1945- memset (& pcapngidb , 0 , sizeof (pcapngidb ));
1944+
1945+ memset (& pcapng_idb , 0 , sizeof (pcapng_idb ));
1946+
1947+ fseek_chk (in , aktseek + pcapng_bh .total_length - BH_SIZE - SHB_SIZE , SEEK_SET );
19461948 }
19471949
19481950 /* IDB, Interface Description Block */
1949- else if (pcapngbh .block_type == 1 ) {
1950- res = fread (& pcapngidb , 1 , IDB_SIZE , in );
1951+ else if (pcapng_bh .block_type == 1 ) {
1952+ res = fread (& pcapng_idb , 1 , IDB_SIZE , in );
19511953 if (res != IDB_SIZE ) {
1952- fprintf (stderr , "%s: Failed to get pcapng IDB: %s\n" ,
1954+ fprintf (stderr , "%s: Failed to get pcap-ng IDB: %s\n" ,
19531955 filename , feof (in ) ? "EOF" : strerror (errno ));
19541956 break ;
19551957 }
19561958 if (swap_needed ) {
1957- pcapngidb .linktype = swap16u (pcapngidb .linktype );
1958- pcapngidb .snaplen = swap32u (pcapngidb .snaplen );
1959+ pcapng_idb .linktype = swap16u (pcapng_idb .linktype );
1960+ pcapng_idb .snaplen = swap32u (pcapng_idb .snaplen );
19591961 }
19601962
1961- fseek_chk (in , pcapngbh .total_length - BH_SIZE - IDB_SIZE , SEEK_CUR );
1963+ fseek_chk (in , pcapng_bh .total_length - BH_SIZE - IDB_SIZE , SEEK_CUR );
19621964 }
19631965
19641966 /* PB, Packet Block (deprecated) */
1965- else if (pcapngbh .block_type == 2 ) {
1966- packet_block_t pcapngpb ;
1967+ else if (pcapng_bh .block_type == 2 ) {
1968+ packet_block_t pcapng_pb ;
19671969
1968- res = fread (& pcapngpb , 1 , PB_SIZE , in );
1970+ res = fread (& pcapng_pb , 1 , PB_SIZE , in );
19691971 if (res != PB_SIZE ) {
1970- fprintf (stderr , "%s: Failed to get pcapng PB: %s\n" ,
1972+ fprintf (stderr , "%s: Failed to get pcap-ng PB: %s\n" ,
19711973 filename , feof (in ) ? "EOF" : strerror (errno ));
19721974 break ;
19731975 }
19741976 if (swap_needed ) {
1975- pcapngpb .interface_id = swap16u (pcapngpb .interface_id );
1976- pcapngpb .drops_count = swap16u (pcapngpb .drops_count );
1977- pcapngpb .timestamp_high = swap32u (pcapngpb .timestamp_high );
1978- pcapngpb .timestamp_low = swap32u (pcapngpb .timestamp_low );
1979- pcapngpb .caplen = swap32u (pcapngpb .caplen );
1980- pcapngpb .len = swap32u (pcapngpb .len );
1977+ pcapng_pb .interface_id = swap16u (pcapng_pb .interface_id );
1978+ pcapng_pb .drops_count = swap16u (pcapng_pb .drops_count );
1979+ pcapng_pb .timestamp_high = swap32u (pcapng_pb .timestamp_high );
1980+ pcapng_pb .timestamp_low = swap32u (pcapng_pb .timestamp_low );
1981+ pcapng_pb .caplen = swap32u (pcapng_pb .caplen );
1982+ pcapng_pb .len = swap32u (pcapng_pb .len );
19811983 }
19821984
1983- if ((pcapngpb .timestamp_high == 0 ) &&
1984- (pcapngpb .timestamp_low == 0 ) && !warn_wpaclean ++ )
1985+ if ((pcapng_pb .timestamp_high == 0 ) &&
1986+ (pcapng_pb .timestamp_low == 0 ) && !warn_wpaclean ++ )
19851987 fprintf (stderr ,
19861988"**\n** Warning: %s seems to be processed with some dubious tool like\n"
19871989"** 'wpaclean'. Important information may be lost.\n**\n" , filename );
19881990
19891991 MEM_FREE (full_packet );
1990- safe_malloc (full_packet , pcapngpb .caplen );
1991- res = fread (full_packet , 1 , pcapngpb .caplen , in );
1992- if (res != pcapngpb .caplen ) {
1992+ safe_malloc (full_packet , pcapng_pb .caplen );
1993+ res = fread (full_packet , 1 , pcapng_pb .caplen , in );
1994+ if (res != pcapng_pb .caplen ) {
19931995 fprintf (stderr , "%s: Failed to read packet: %s\n" ,
19941996 filename , feof (in ) ? "EOF" : strerror (errno ));
19951997 break ;
19961998 }
1997- fseek_chk (in , pcapngbh .total_length - BH_SIZE - PB_SIZE - pcapngpb .caplen , SEEK_CUR );
1999+ fseek_chk (in , pcapng_bh .total_length - BH_SIZE - PB_SIZE - pcapng_pb .caplen , SEEK_CUR );
19982000
1999- if (pcapngpb .caplen > 0 ) {
2000- snap_len = pcapngpb .caplen ;
2001- orig_len = pcapngpb .len ;
2002- abs_ts64 = (((uint64_t )pcapngpb .timestamp_high << 32 ) +
2003- pcapngpb .timestamp_low );
2001+ if (pcapng_pb .caplen > 0 ) {
2002+ snap_len = pcapng_pb .caplen ;
2003+ orig_len = pcapng_pb .len ;
2004+ abs_ts64 = (((uint64_t )pcapng_pb .timestamp_high << 32 ) +
2005+ pcapng_pb .timestamp_low );
20042006 if (!start_ts64 )
20052007 start_ts64 = abs_ts64 ;
20062008 cur_ts64 = abs_ts64 - start_ts64 ;
2007- if (!process_packet (pcapngidb .linktype ))
2009+ if (!process_packet (pcapng_idb .linktype ))
20082010 break ;
20092011 }
20102012 }
20112013
20122014 /* SPB, Simple Packet Block (legacy/limited) */
2013- else if (pcapngbh .block_type == 3 ) {
2014- simple_packet_block_t pcapngspb ;
2015+ else if (pcapng_bh .block_type == 3 ) {
2016+ simple_packet_block_t pcapng_spb ;
20152017
2016- res = fread (& pcapngspb , 1 , SPB_SIZE , in );
2018+ res = fread (& pcapng_spb , 1 , SPB_SIZE , in );
20172019 if (res != SPB_SIZE ) {
2018- fprintf (stderr , "%s: Failed to read pcapng SPB: %s\n" ,
2020+ fprintf (stderr , "%s: Failed to read pcap-ng SPB: %s\n" ,
20192021 filename , feof (in ) ? "EOF" : strerror (errno ));
20202022 break ;
20212023 }
20222024 if (swap_needed ) {
2023- pcapngspb .len = swap32u (pcapngspb .len );
2025+ pcapng_spb .len = swap32u (pcapng_spb .len );
20242026 }
20252027
20262028 MEM_FREE (full_packet );
2027- safe_malloc (full_packet , pcapngspb .len );
2028- res = fread (full_packet , 1 , pcapngspb .len , in );
2029- if (res != pcapngspb .len ) {
2029+ safe_malloc (full_packet , pcapng_spb .len );
2030+ res = fread (full_packet , 1 , pcapng_spb .len , in );
2031+ if (res != pcapng_spb .len ) {
20302032 fprintf (stderr , "%s: Failed to read packet: %s\n" ,
20312033 filename , feof (in ) ? "EOF" : strerror (errno ));
20322034 break ;
20332035 }
2034- fseek_chk (in , pcapngbh .total_length - BH_SIZE - SPB_SIZE - pcapngspb .len , SEEK_CUR );
2036+ fseek_chk (in , pcapng_bh .total_length - BH_SIZE - SPB_SIZE - pcapng_spb .len , SEEK_CUR );
20352037
2036- if (pcapngspb .len > 0 ) {
2037- snap_len = pcapngspb .len ;
2038- orig_len = pcapngspb .len ;
2038+ if (pcapng_spb .len > 0 ) {
2039+ snap_len = pcapng_spb .len ;
2040+ orig_len = pcapng_spb .len ;
20392041 abs_ts64 = cur_ts64 = 0 ;
2040- if (!process_packet (pcapngidb .linktype ))
2042+ if (!process_packet (pcapng_idb .linktype ))
20412043 break ;
20422044 }
20432045 }
20442046
20452047 /* EPB, Enhanced Packet Block */
2046- else if (pcapngbh .block_type == 6 ) {
2047- enhanced_packet_block_t pcapngepb ;
2048+ else if (pcapng_bh .block_type == 6 ) {
2049+ enhanced_packet_block_t pcapng_epb ;
20482050
2049- res = fread (& pcapngepb , 1 , EPB_SIZE , in );
2051+ res = fread (& pcapng_epb , 1 , EPB_SIZE , in );
20502052 if (res != EPB_SIZE ) {
2051- fprintf (stderr , "%s: Failed to get pcapng EPB: %s\n" ,
2053+ fprintf (stderr , "%s: Failed to get pcap-ng EPB: %s\n" ,
20522054 filename , feof (in ) ? "EOF" : strerror (errno ));
20532055 break ;
20542056 }
20552057
20562058 if (swap_needed ) {
2057- pcapngepb .interface_id = swap32u (pcapngepb .interface_id );
2058- pcapngepb .timestamp_high = swap32u (pcapngepb .timestamp_high );
2059- pcapngepb .timestamp_low = swap32u (pcapngepb .timestamp_low );
2060- pcapngepb .caplen = swap32u (pcapngepb .caplen );
2061- pcapngepb .len = swap32u (pcapngepb .len );
2059+ pcapng_epb .interface_id = swap32u (pcapng_epb .interface_id );
2060+ pcapng_epb .timestamp_high = swap32u (pcapng_epb .timestamp_high );
2061+ pcapng_epb .timestamp_low = swap32u (pcapng_epb .timestamp_low );
2062+ pcapng_epb .caplen = swap32u (pcapng_epb .caplen );
2063+ pcapng_epb .len = swap32u (pcapng_epb .len );
20622064 }
20632065
20642066 MEM_FREE (full_packet );
2065- safe_malloc (full_packet , pcapngepb .caplen );
2066- res = fread (full_packet , 1 , pcapngepb .caplen , in );
2067- if (res != pcapngepb .caplen ) {
2067+ safe_malloc (full_packet , pcapng_epb .caplen );
2068+ res = fread (full_packet , 1 , pcapng_epb .caplen , in );
2069+ if (res != pcapng_epb .caplen ) {
20682070 fprintf (stderr , "%s: Failed to read packet: %s\n" ,
20692071 filename , feof (in ) ? "EOF" : strerror (errno ));
20702072 break ;
20712073 }
2072- fseek_chk (in , pcapngbh .total_length - BH_SIZE - EPB_SIZE - pcapngepb .caplen , SEEK_CUR );
2074+ fseek_chk (in , pcapng_bh .total_length - BH_SIZE - EPB_SIZE - pcapng_epb .caplen , SEEK_CUR );
20732075
2074- if (pcapngepb .caplen > 0 ) {
2075- snap_len = pcapngepb .caplen ;
2076- orig_len = pcapngepb .len ;
2076+ if (pcapng_epb .caplen > 0 ) {
2077+ snap_len = pcapng_epb .caplen ;
2078+ orig_len = pcapng_epb .len ;
20772079 // FIXME: Honor if_tsresol from Interface Description Block
2078- abs_ts64 = (((uint64_t )pcapngepb .timestamp_high << 32 ) +
2079- pcapngepb .timestamp_low );
2080+ abs_ts64 = (((uint64_t )pcapng_epb .timestamp_high << 32 ) +
2081+ pcapng_epb .timestamp_low );
20802082 if (!start_ts64 )
20812083 start_ts64 = abs_ts64 ;
20822084 cur_ts64 = abs_ts64 - start_ts64 ;
2083- if (!process_packet (pcapngidb .linktype ))
2085+ if (!process_packet (pcapng_idb .linktype ))
20842086 break ;
20852087 }
20862088 }
@@ -2090,7 +2092,7 @@ static int process_ng(FILE *in)
20902092 if (verbosity >= 4 )
20912093 fprintf (stderr , "Skipping (unhandled block type)\n" );
20922094
2093- fseek_chk (in , pcapngbh .total_length - BH_SIZE , SEEK_CUR );
2095+ fseek_chk (in , pcapng_bh .total_length - BH_SIZE , SEEK_CUR );
20942096 }
20952097 }
20962098
@@ -2114,8 +2116,8 @@ static int get_next_packet(FILE *in)
21142116 }
21152117
21162118 if (swap_needed ) {
2117- pkt_hdr .ts_sec = swap32u (pkt_hdr .ts_sec );
2118- pkt_hdr .ts_usec = swap32u (pkt_hdr .ts_usec );
2119+ pkt_hdr .ts_sec = swap32u (pkt_hdr .ts_sec );
2120+ pkt_hdr .ts_usec = swap32u (pkt_hdr .ts_usec );
21192121 pkt_hdr .snap_len = swap32u (pkt_hdr .snap_len );
21202122 pkt_hdr .orig_len = swap32u (pkt_hdr .orig_len );
21212123 }
@@ -2176,12 +2178,12 @@ static int process(FILE *in)
21762178 swap_needed ^= !ARCH_LITTLE_ENDIAN ;
21772179
21782180 if (swap_needed ) {
2179- main_hdr .magic_number = swap32u (main_hdr .magic_number );
2181+ main_hdr .magic_number = swap32u (main_hdr .magic_number );
21802182 main_hdr .version_major = swap16u (main_hdr .version_major );
21812183 main_hdr .version_minor = swap16u (main_hdr .version_minor );
2182- main_hdr .sigfigs = swap32u (main_hdr .sigfigs );
2183- main_hdr .snaplen = swap32u (main_hdr .snaplen );
2184- main_hdr .network = swap32u (main_hdr .network );
2184+ main_hdr .sigfigs = swap32u (main_hdr .sigfigs );
2185+ main_hdr .snaplen = swap32u (main_hdr .snaplen );
2186+ main_hdr .network = swap32u (main_hdr .network );
21852187 }
21862188
21872189
0 commit comments