File: pcapio.h

package info (click to toggle)
wireshark 4.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 351,244 kB
  • sloc: ansic: 3,101,885; cpp: 129,710; xml: 100,972; python: 56,512; perl: 24,575; sh: 5,874; lex: 4,383; pascal: 4,304; makefile: 165; ruby: 113; objc: 91; tcl: 35
file content (127 lines) | stat: -rw-r--r-- 6,079 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/** @file
 *
 * Declarations of our own routines for writing pcap and pcapng files.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Derived from code in the Wiretap Library
 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#pragma once

#include <wiretap/wtap.h>

typedef struct pcapio_writer pcapio_writer;

extern pcapio_writer*
writecap_fopen(const char *filename, wtap_compression_type ctype, int *err);

extern pcapio_writer*
writecap_fdopen(int fd, wtap_compression_type ctype, int *err);

extern pcapio_writer*
writecap_open_stdout(wtap_compression_type ctype, int *err);

extern bool
writecap_flush(pcapio_writer* pfile, int *err);

/* Close open file handles and frees memory associated with pfile.
 *
 * Return true on success, returns false and sets err (optional) on failure.
 * err can be NULL, e.g. if closing after some other failure that is more
 * relevant to report, or when exiting a program. */
extern bool
writecap_close(pcapio_writer* pfile, int *err);

/* Writing pcap files */

/** Write the file header to a dump file.
   Returns true on success, false on failure.
   Sets "*err" to an error code, or 0 for a short write, on failure*/
extern bool
libpcap_write_file_header(pcapio_writer* pfile, int linktype, int snaplen,
                          bool ts_nsecs, uint64_t *bytes_written, int *err);

/** Write a record for a packet to a dump file.
   Returns true on success, false on failure. */
extern bool
libpcap_write_packet(pcapio_writer* pfile,
                     time_t sec, uint32_t usec,
                     uint32_t caplen, uint32_t len,
                     const uint8_t *pd,
                     uint64_t *bytes_written, int *err);

/* Writing pcapng files */

/* Write a pre-formatted pcapng block */
extern bool
pcapng_write_block(pcapio_writer* pfile,
                   const uint8_t *data,
                   uint32_t block_total_length,
                   uint64_t *bytes_written,
                   int *err);

/** Write a section header block (SHB)
 *
 */
extern bool
pcapng_write_section_header_block(pcapio_writer* pfile,  /**< Write information */
                                  GPtrArray *comments,  /**< Comments on the section, Optinon 1 opt_comment
                                                         * UTF-8 strings containing comments that areassociated to the current block.
                                                         */
                                  const char *hw,       /**< HW, Optinon 2 shb_hardware
                                                         * An UTF-8 string containing the description of the hardware  used to create this section.
                                                         */
                                  const char *os,       /**< Operating system name, Optinon 3 shb_os
                                                         * An UTF-8 string containing the name of the operating system used to create this section.
                                                         */
                                  const char *appname,  /**< Application name, Optinon 4 shb_userappl
                                                         * An UTF-8 string containing the name of the application  used to create this section.
                                                         */
                                  uint64_t section_length, /**< Length of section */
                                  uint64_t *bytes_written, /**< Number of written bytes */
                                  int *err /**< Error type */
                                  );

extern bool
pcapng_write_interface_description_block(pcapio_writer* pfile,
                                         const char *comment,  /* OPT_COMMENT           1 */
                                         const char *name,     /* IDB_NAME              2 */
                                         const char *descr,    /* IDB_DESCRIPTION       3 */
                                         const char *filter,   /* IDB_FILTER           11 */
                                         const char *os,       /* IDB_OS               12 */
                                         const char *hardware, /* IDB_HARDWARE         15 */
                                         int link_type,
                                         int snap_len,
                                         uint64_t *bytes_written,
                                         uint64_t if_speed,     /* IDB_IF_SPEED          8 */
                                         uint8_t tsresol,       /* IDB_TSRESOL           9 */
                                         int *err);

extern bool
pcapng_write_interface_statistics_block(pcapio_writer* pfile,
                                        uint32_t interface_id,
                                        uint64_t *bytes_written,
                                        const char *comment,   /* OPT_COMMENT           1 */
                                        uint64_t isb_starttime, /* ISB_STARTTIME         2 */
                                        uint64_t isb_endtime,   /* ISB_ENDTIME           3 */
                                        uint64_t isb_ifrecv,    /* ISB_IFRECV            4 */
                                        uint64_t isb_ifdrop,    /* ISB_IFDROP            5 */
                                        int *err);

extern bool
pcapng_write_enhanced_packet_block(pcapio_writer* pfile,
                                   const char *comment,
                                   time_t sec, uint32_t usec,
                                   uint32_t caplen, uint32_t len,
                                   uint32_t interface_id,
                                   unsigned ts_mul,
                                   const uint8_t *pd,
                                   uint32_t flags,
                                   uint64_t *bytes_written,
                                   int *err);