forked from Rup0rt/pcapfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcapng.h
97 lines (87 loc) · 3.38 KB
/
pcapng.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
*
* Copyright (c) 2012-2021 Robert Krause ([email protected])
*
* This file is part of Pcapfix.
*
* Pcapfix is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or any later version.
*
* Pcapfix is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Pcapfix. If not, see http://www.gnu.org/licenses/.
*
******************************************************************************/
#ifndef PF_PCAPNG
#define PF_PCAPNG
/* http://www.winpcap.org/ntar/draft/PCAP-DumpFileFormat.html */
/* http://wiki.wireshark.org/Development/PcapNg */
#define BYTE_ORDER_MAGIC 0x1a2b3c4d /* pcapng default byte order magic - non swapped */
#define TYPE_SHB 0x0A0D0D0A /* Section Header Block */
#define TYPE_IDB 0x00000001 /* Interface Description Block */
#define TYPE_PB 0x00000002 /* Packet Block */
#define TYPE_SPB 0x00000003 /* Simple Packet Block */
#define TYPE_NRB 0x00000004 /* Name Resolution Block */
#define TYPE_ISB 0x00000005 /* Interface Statistics Block */
#define TYPE_EPB 0x00000006 /* Enhanced Packet Block */
#define PCAPNG_MAX_SNAPLEN 262144 /* maximum snap length */
/*
* Function: fix_pcapng
* ---------------------
* tries to fix a pcapng file
*
* pcap: file pointer to input file
* pcap_fix: file pointer to output file
*
* returns: >0 success (number of corruptions fixed)
* 0 success (nothing to fix)
* -1 error (not a pcap file)
* -2 error (unable to repair)
* -3 error (EOF while reading input file)
*
*/
int fix_pcapng(FILE *pcap, FILE *pcap_fix);
/*
* Function: find_valid_block
* ---------------------------
* searches for the next valid block beginning at current file pointer position
*
* pcap: file pointer to input file
* filesize: size of input file in bytes
*
* returns: 0 success (next block header has been found, file pointer is set to start of block)
* -1 error (reached EOF without finding a valid block)
*
*/
int find_valid_block(FILE *pcap, off_t filesize);
/*
* Function: write_shb
* --------------------
* creates a raw section header block (SHB) and writes it into output file
* (there will be no information inside except that it has been added by pcapfix)
*
* pcap_fix: file pointer to output file
*
* returns: 0 success (new shb has been written to output file)
* -1 error (cannot write to output file)
*
*/
int write_shb(FILE *pcap_fix, char* writebuffer, off_t* writepos);
/*
* Function: write_idb
* --------------------
* creates a raw interface description block (IDB) and writes it into output file
* (there will be no information inside except that it has been added by pcapfix)
*
* pcap_fix: file pointer to output file
*
* returns: 0 success (new shb has been written to output file)
* -1 error (cannot write to output file)
*
*/
int write_idb(FILE *pcap_fix, char* writebuffer, off_t* writepos);
#endif