aboutsummaryrefslogtreecommitdiffstats
path: root/pcapio.c
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2012-03-12 15:40:57 +0000
committerAnders Broman <anders.broman@ericsson.com>2012-03-12 15:40:57 +0000
commitcbde63643e0a8e4e014fba5d508a88ae300859c6 (patch)
tree6277ff8b8724a20e7bbd186633a38c5d422ad3f6 /pcapio.c
parent0400088936dda3a2f0315c7b38eef26bb884b2b6 (diff)
From Jose Pedro Oliveira:
Enforce the modelines in dumpcap.c and in pcapio.c svn path=/trunk/; revision=41505
Diffstat (limited to 'pcapio.c')
-rw-r--r--pcapio.c1060
1 files changed, 530 insertions, 530 deletions
diff --git a/pcapio.c b/pcapio.c
index d45853123a..75915a1948 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -5,14 +5,14 @@
* only a file descriptor. libpcap 0.9[.x] has "pcap_dump_fopen()", which
* provides that, but
*
- * 1) earlier versions of libpcap doesn't have it
+ * 1) earlier versions of libpcap doesn't have it
*
* and
*
- * 2) WinPcap doesn't have it, because a file descriptor opened
- * by code built for one version of the MSVC++ C library
- * can't be used by library routines built for another version
- * (e.g., threaded vs. unthreaded).
+ * 2) WinPcap doesn't have it, because a file descriptor opened
+ * by code built for one version of the MSVC++ C library
+ * can't be used by library routines built for another version
+ * (e.g., threaded vs. unthreaded).
*
* Libpcap's pcap_dump() also doesn't return any error indications.
*
@@ -69,28 +69,28 @@
which uses the same common file format as PCAP_MAGIC, but the
timestamps are saved in nanosecond resolution instead of microseconds.
PCAP_SWAPPED_NSEC_MAGIC is a byte-swapped version of that. */
-#define PCAP_MAGIC 0xa1b2c3d4
-#define PCAP_SWAPPED_MAGIC 0xd4c3b2a1
-#define PCAP_NSEC_MAGIC 0xa1b23c4d
-#define PCAP_SWAPPED_NSEC_MAGIC 0x4d3cb2a1
+#define PCAP_MAGIC 0xa1b2c3d4
+#define PCAP_SWAPPED_MAGIC 0xd4c3b2a1
+#define PCAP_NSEC_MAGIC 0xa1b23c4d
+#define PCAP_SWAPPED_NSEC_MAGIC 0x4d3cb2a1
/* "libpcap" file header. */
struct pcap_hdr {
- guint32 magic; /* magic number */
- guint16 version_major; /* major version number */
- guint16 version_minor; /* minor version number */
- gint32 thiszone; /* GMT to local correction */
- guint32 sigfigs; /* accuracy of timestamps */
- guint32 snaplen; /* max length of captured packets, in octets */
- guint32 network; /* data link type */
+ guint32 magic; /* magic number */
+ guint16 version_major; /* major version number */
+ guint16 version_minor; /* minor version number */
+ gint32 thiszone; /* GMT to local correction */
+ guint32 sigfigs; /* accuracy of timestamps */
+ guint32 snaplen; /* max length of captured packets, in octets */
+ guint32 network; /* data link type */
};
/* "libpcap" record header. */
struct pcaprec_hdr {
- guint32 ts_sec; /* timestamp seconds */
- guint32 ts_usec; /* timestamp microseconds (nsecs for PCAP_NSEC_MAGIC) */
- guint32 incl_len; /* number of octets of packet saved in file */
- guint32 orig_len; /* actual length of packet */
+ guint32 ts_sec; /* timestamp seconds */
+ guint32 ts_usec; /* timestamp microseconds (nsecs for PCAP_NSEC_MAGIC) */
+ guint32 incl_len; /* number of octets of packet saved in file */
+ guint32 orig_len; /* actual length of packet */
};
/* Magic numbers in ".pcapng" files.
@@ -110,52 +110,52 @@ struct pcaprec_hdr {
/* Section Header Block without options and trailing Block Total Length */
struct shb {
- guint32 block_type;
- guint32 block_total_length;
- guint32 byte_order_magic;
- guint16 major_version;
- guint16 minor_version;
- guint64 section_length;
+ guint32 block_type;
+ guint32 block_total_length;
+ guint32 byte_order_magic;
+ guint16 major_version;
+ guint16 minor_version;
+ guint64 section_length;
};
#define SECTION_HEADER_BLOCK_TYPE 0x0A0D0D0A
/* Interface Decription Block without options and trailing Block Total Length */
struct idb {
- guint32 block_type;
- guint32 block_total_length;
- guint16 link_type;
- guint16 reserved;
- guint32 snap_len;
+ guint32 block_type;
+ guint32 block_total_length;
+ guint16 link_type;
+ guint16 reserved;
+ guint32 snap_len;
};
#define INTERFACE_DESCRIPTION_BLOCK_TYPE 0x00000001
/* Interface Statistics Block without actual packet, options, and trailing
Block Total Length */
struct isb {
- guint32 block_type;
- guint32 block_total_length;
- guint32 interface_id;
- guint32 timestamp_high;
- guint32 timestamp_low;
+ guint32 block_type;
+ guint32 block_total_length;
+ guint32 interface_id;
+ guint32 timestamp_high;
+ guint32 timestamp_low;
};
#define INTERFACE_STATISTICS_BLOCK_TYPE 0x00000005
/* Enhanced Packet Block without actual packet, options, and trailing
Block Total Length */
struct epb {
- guint32 block_type;
- guint32 block_total_length;
- guint32 interface_id;
- guint32 timestamp_high;
- guint32 timestamp_low;
- guint32 captured_len;
- guint32 packet_len;
+ guint32 block_type;
+ guint32 block_total_length;
+ guint32 interface_id;
+ guint32 timestamp_high;
+ guint32 timestamp_low;
+ guint32 captured_len;
+ guint32 packet_len;
};
#define ENHANCED_PACKET_BLOCK_TYPE 0x00000006
struct option {
- guint16 type;
- guint16 value_length;
+ guint16 type;
+ guint16 value_length;
};
#define OPT_ENDOFOPT 0
#define OPT_COMMENT 1
@@ -179,33 +179,33 @@ struct option {
#define WRITE_DATA(file_pointer, data_pointer, data_length, written_length, error_pointer) \
{ \
- do { \
- size_t nwritten; \
- \
- nwritten = fwrite(data_pointer, 1, data_length, file_pointer); \
- if (nwritten != data_length) { \
- if (nwritten == 0 && ferror(file_pointer)) { \
- *error_pointer = errno; \
- } else { \
- *error_pointer = 0; \
- } \
- return FALSE; \
- } \
- written_length += (long)nwritten; \
- } while (0); \
+ do { \
+ size_t nwritten; \
+ \
+ nwritten = fwrite(data_pointer, 1, data_length, file_pointer); \
+ if (nwritten != data_length) { \
+ if (nwritten == 0 && ferror(file_pointer)) { \
+ *error_pointer = errno; \
+ } else { \
+ *error_pointer = 0; \
+ } \
+ return FALSE; \
+ } \
+ written_length += (long)nwritten; \
+ } while (0); \
}
/* Returns a FILE * to write to on success, NULL on failure */
FILE *
libpcap_fdopen(int fd, int *err)
{
- FILE *fp;
+ FILE *fp;
- fp = fdopen(fd, "wb");
- if (fp == NULL) {
- *err = errno;
- }
- return fp;
+ fp = fdopen(fd, "wb");
+ if (fp == NULL) {
+ *err = errno;
+ }
+ return fp;
}
/* Write the file header to a dump file.
@@ -214,28 +214,28 @@ libpcap_fdopen(int fd, int *err)
gboolean
libpcap_write_file_header(FILE *fp, int linktype, int snaplen, gboolean ts_nsecs, long *bytes_written, int *err)
{
- struct pcap_hdr file_hdr;
- size_t nwritten;
-
- file_hdr.magic = ts_nsecs ? PCAP_NSEC_MAGIC : PCAP_MAGIC;
- /* current "libpcap" format is 2.4 */
- file_hdr.version_major = 2;
- file_hdr.version_minor = 4;
- file_hdr.thiszone = 0; /* XXX - current offset? */
- file_hdr.sigfigs = 0; /* unknown, but also apparently unused */
- file_hdr.snaplen = snaplen;
- file_hdr.network = linktype;
- nwritten = fwrite(&file_hdr, 1, sizeof(file_hdr), fp);
- if (nwritten != sizeof(file_hdr)) {
- if (nwritten == 0 && ferror(fp))
- *err = errno;
- else
- *err = 0; /* short write */
- return FALSE;
- }
- *bytes_written += sizeof(file_hdr);
-
- return TRUE;
+ struct pcap_hdr file_hdr;
+ size_t nwritten;
+
+ file_hdr.magic = ts_nsecs ? PCAP_NSEC_MAGIC : PCAP_MAGIC;
+ /* current "libpcap" format is 2.4 */
+ file_hdr.version_major = 2;
+ file_hdr.version_minor = 4;
+ file_hdr.thiszone = 0; /* XXX - current offset? */
+ file_hdr.sigfigs = 0; /* unknown, but also apparently unused */
+ file_hdr.snaplen = snaplen;
+ file_hdr.network = linktype;
+ nwritten = fwrite(&file_hdr, 1, sizeof(file_hdr), fp);
+ if (nwritten != sizeof(file_hdr)) {
+ if (nwritten == 0 && ferror(fp))
+ *err = errno;
+ else
+ *err = 0; /* short write */
+ return FALSE;
+ }
+ *bytes_written += sizeof(file_hdr);
+
+ return TRUE;
}
/* Write a record for a packet to a dump file.
@@ -244,33 +244,33 @@ gboolean
libpcap_write_packet(FILE *fp, const struct pcap_pkthdr *phdr, const u_char *pd,
long *bytes_written, int *err)
{
- struct pcaprec_hdr rec_hdr;
- size_t nwritten;
-
- rec_hdr.ts_sec = phdr->ts.tv_sec;
- rec_hdr.ts_usec = phdr->ts.tv_usec;
- rec_hdr.incl_len = phdr->caplen;
- rec_hdr.orig_len = phdr->len;
- nwritten = fwrite(&rec_hdr, 1, sizeof rec_hdr, fp);
- if (nwritten != sizeof rec_hdr) {
- if (nwritten == 0 && ferror(fp))
- *err = errno;
- else
- *err = 0; /* short write */
- return FALSE;
- }
- *bytes_written += sizeof rec_hdr;
-
- nwritten = fwrite(pd, 1, phdr->caplen, fp);
- if (nwritten != phdr->caplen) {
- if (nwritten == 0 && ferror(fp))
- *err = errno;
- else
- *err = 0; /* short write */
- return FALSE;
- }
- *bytes_written += phdr->caplen;
- return TRUE;
+ struct pcaprec_hdr rec_hdr;
+ size_t nwritten;
+
+ rec_hdr.ts_sec = phdr->ts.tv_sec;
+ rec_hdr.ts_usec = phdr->ts.tv_usec;
+ rec_hdr.incl_len = phdr->caplen;
+ rec_hdr.orig_len = phdr->len;
+ nwritten = fwrite(&rec_hdr, 1, sizeof rec_hdr, fp);
+ if (nwritten != sizeof rec_hdr) {
+ if (nwritten == 0 && ferror(fp))
+ *err = errno;
+ else
+ *err = 0; /* short write */
+ return FALSE;
+ }
+ *bytes_written += sizeof rec_hdr;
+
+ nwritten = fwrite(pd, 1, phdr->caplen, fp);
+ if (nwritten != phdr->caplen) {
+ if (nwritten == 0 && ferror(fp))
+ *err = errno;
+ else
+ *err = 0; /* short write */
+ return FALSE;
+ }
+ *bytes_written += phdr->caplen;
+ return TRUE;
}
gboolean
@@ -283,98 +283,98 @@ libpcap_write_session_header_block(FILE *fp,
long *bytes_written,
int *err)
{
- struct shb shb;
- struct option option;
- guint32 block_total_length;
- const guint32 padding = 0;
- gboolean have_options = FALSE;
-
- /* Size of base header */
- block_total_length = sizeof(struct shb) +
- sizeof(guint32);
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(comment) + 1));
- have_options = TRUE;
- }
- if ((hw != NULL) && (strlen(hw) > 0) && (strlen(hw) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(hw) + 1));
- have_options = TRUE;
- }
- if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(os) + 1));
- have_options = TRUE;
- }
- if ((appname != NULL) && (strlen(appname) > 0) && (strlen(appname) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(appname) + 1));
- have_options = TRUE;
- }
- /* If we have options add size of end-of-options */
- if (have_options) {
- block_total_length += sizeof(struct option);
- }
- /* write shb header */
- shb.block_type = SECTION_HEADER_BLOCK_TYPE;
- shb.block_total_length = block_total_length;
- shb.byte_order_magic = PCAPNG_MAGIC;
- shb.major_version = PCAPNG_MAJOR_VERSION;
- shb.minor_version = PCAPNG_MINOR_VERSION;
- shb.section_length = section_length;
- WRITE_DATA(fp, &shb, sizeof(struct shb), *bytes_written, err);
-
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- /* write opt_comment options */
- option.type = OPT_COMMENT;
- option.value_length = (guint16)(strlen(comment) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
- if ((strlen(comment) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4, *bytes_written, err);
- }
- }
- if ((hw != NULL) && (strlen(hw) > 0) && (strlen(hw) < G_MAXUINT16)) {
- /* write shb_hardware options */
- option.type = SHB_HARDWARE;
- option.value_length = (guint16)(strlen(hw) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, hw, strlen(hw) + 1, *bytes_written, err);
- if ((strlen(hw) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(hw) + 1) % 4, *bytes_written, err);
- }
- }
- if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
- /* write shb_os options */
- option.type = SHB_OS;
- option.value_length = (guint16)(strlen(os) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, os, strlen(os) + 1, *bytes_written, err);
- if ((strlen(os) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(os) + 1) % 4, *bytes_written, err);
- }
- }
- if ((appname != NULL) && (strlen(appname) > 0) && (strlen(appname) < G_MAXUINT16)) {
- /* write shb_userappl options */
- option.type = SHB_USERAPPL;
- option.value_length = (guint16)(strlen(appname) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, appname, strlen(appname) + 1, *bytes_written, err);
- if ((strlen(appname) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(appname) + 1) % 4, *bytes_written, err);
- }
- }
- if (have_options) {
- /* write end of options */
- option.type = OPT_ENDOFOPT;
- option.value_length = 0;
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- }
-
- /* write the trailing block total length */
- WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
- return TRUE;
+ struct shb shb;
+ struct option option;
+ guint32 block_total_length;
+ const guint32 padding = 0;
+ gboolean have_options = FALSE;
+
+ /* Size of base header */
+ block_total_length = sizeof(struct shb) +
+ sizeof(guint32);
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(comment) + 1));
+ have_options = TRUE;
+ }
+ if ((hw != NULL) && (strlen(hw) > 0) && (strlen(hw) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(hw) + 1));
+ have_options = TRUE;
+ }
+ if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(os) + 1));
+ have_options = TRUE;
+ }
+ if ((appname != NULL) && (strlen(appname) > 0) && (strlen(appname) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(appname) + 1));
+ have_options = TRUE;
+ }
+ /* If we have options add size of end-of-options */
+ if (have_options) {
+ block_total_length += sizeof(struct option);
+ }
+ /* write shb header */
+ shb.block_type = SECTION_HEADER_BLOCK_TYPE;
+ shb.block_total_length = block_total_length;
+ shb.byte_order_magic = PCAPNG_MAGIC;
+ shb.major_version = PCAPNG_MAJOR_VERSION;
+ shb.minor_version = PCAPNG_MINOR_VERSION;
+ shb.section_length = section_length;
+ WRITE_DATA(fp, &shb, sizeof(struct shb), *bytes_written, err);
+
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ /* write opt_comment options */
+ option.type = OPT_COMMENT;
+ option.value_length = (guint16)(strlen(comment) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
+ if ((strlen(comment) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4, *bytes_written, err);
+ }
+ }
+ if ((hw != NULL) && (strlen(hw) > 0) && (strlen(hw) < G_MAXUINT16)) {
+ /* write shb_hardware options */
+ option.type = SHB_HARDWARE;
+ option.value_length = (guint16)(strlen(hw) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, hw, strlen(hw) + 1, *bytes_written, err);
+ if ((strlen(hw) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(hw) + 1) % 4, *bytes_written, err);
+ }
+ }
+ if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
+ /* write shb_os options */
+ option.type = SHB_OS;
+ option.value_length = (guint16)(strlen(os) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, os, strlen(os) + 1, *bytes_written, err);
+ if ((strlen(os) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(os) + 1) % 4, *bytes_written, err);
+ }
+ }
+ if ((appname != NULL) && (strlen(appname) > 0) && (strlen(appname) < G_MAXUINT16)) {
+ /* write shb_userappl options */
+ option.type = SHB_USERAPPL;
+ option.value_length = (guint16)(strlen(appname) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, appname, strlen(appname) + 1, *bytes_written, err);
+ if ((strlen(appname) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(appname) + 1) % 4, *bytes_written, err);
+ }
+ }
+ if (have_options) {
+ /* write end of options */
+ option.type = OPT_ENDOFOPT;
+ option.value_length = 0;
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ }
+
+ /* write the trailing block total length */
+ WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
+ return TRUE;
}
gboolean
@@ -391,161 +391,161 @@ libpcap_write_interface_description_block(FILE *fp,
guint8 tsresol, /* IDB_TSRESOL 9 */
int *err)
{
- struct idb idb;
- struct option option;
- guint32 block_total_length;
- const guint32 padding = 0;
- gboolean have_options = FALSE;
-
- block_total_length = sizeof(struct idb) + sizeof(guint32);
- /* 01 - OPT_COMMENT */
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(comment) + 1));
- have_options = TRUE;
- }
-
- /* 02 - IDB_NAME */
- if ((name != NULL) && (strlen(name) > 0) && (strlen(name) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(name) + 1));
- have_options = TRUE;
- }
-
- /* 03 - IDB_DESCRIPTION */
- if ((descr != NULL) && (strlen(descr) > 0) && (strlen(descr) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(descr) + 1));
- have_options = TRUE;
- }
-
- /* 08 - IDB_IF_SPEED */
- if (if_speed != 0) {
- block_total_length += sizeof(struct option) + sizeof(guint64);
- have_options = TRUE;
- }
-
- /* 09 - IDB_TSRESOL */
- if (tsresol != 0) {
- block_total_length += sizeof(struct option) + sizeof(struct option);
- have_options = TRUE;
- }
-
- /* 11 - IDB_FILTER */
- if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(filter) + 1 + 1));
- have_options = TRUE;
- }
-
- /* 12 - IDB_OS */
- if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(os) + 1));
- have_options = TRUE;
- }
-
- /* If we have options add size of end-of-options */
- if (have_options) {
- block_total_length += sizeof(struct option);
- }
-
- /* write block header */
- idb.block_type = INTERFACE_DESCRIPTION_BLOCK_TYPE;
- idb.block_total_length = block_total_length;
- idb.link_type = link_type;
- idb.reserved = 0;
- idb.snap_len = snap_len;
- WRITE_DATA(fp, &idb, sizeof(struct idb), *bytes_written, err);
-
- /* 01 - OPT_COMMENT - write comment string if applicable */
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- option.type = OPT_COMMENT;
- option.value_length = (guint16)(strlen(comment) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
- if ((strlen(comment) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4 , *bytes_written, err);
- }
- }
-
- /* 02 - IDB_NAME - write interface name string if applicable */
- if ((name != NULL) && (strlen(name) > 0) && (strlen(name) < G_MAXUINT16)) {
- option.type = IDB_NAME;
- option.value_length = (guint16)(strlen(name) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, name, strlen(name) + 1, *bytes_written, err);
- if ((strlen(name) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(name) + 1) % 4 , *bytes_written, err);
- }
- }
-
- /* 03 - IDB_DESCRIPTION */
- /* write interface description string if applicable */
- if ((descr != NULL) && (strlen(descr) > 0) && (strlen(descr) < G_MAXUINT16)) {
- option.type = IDB_DESCRIPTION;
- option.value_length = (guint16)(strlen(descr) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, name, strlen(descr) + 1, *bytes_written, err);
- if ((strlen(descr) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(descr) + 1) % 4 , *bytes_written, err);
- }
- }
-
- /* 08 - IDB_IF_SPEED */
- if (if_speed != 0) {
- option.type = IDB_IF_SPEED;
- option.value_length = sizeof(guint64);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &if_speed, sizeof(guint64), *bytes_written, err);
- }
-
- /* 09 - IDB_TSRESOL */
- if (tsresol != 0) {
- option.type = IDB_TSRESOL;
- option.value_length = sizeof(guint8);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &tsresol, sizeof(guint8), *bytes_written, err);
- WRITE_DATA(fp, &padding, 3 , *bytes_written, err);
- }
-
- /* 11 - IDB_FILTER - write filter string if applicable
- * We only write version 1 of the filter, libpcap string
- */
- if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
- option.type = IDB_FILTER;
- option.value_length = (guint16)(strlen(filter) + 1 + 1 );
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
-
- /* The first byte of the Option Data keeps a code of the filter used, 0 = lipbpcap filter string */
- WRITE_DATA(fp, &padding, 1, *bytes_written, err);
- WRITE_DATA(fp, filter, strlen(filter) + 1, *bytes_written, err);
- if ((strlen(filter) + 2) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(filter) + 2) % 4 , *bytes_written, err);
- }
- }
-
- /* 12 - IDB_OS - write os string if applicable */
- if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
- option.type = IDB_OS;
- option.value_length = (guint16)(strlen(os) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, os, strlen(os) + 1, *bytes_written, err);
- if ((strlen(os) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(os) + 1) % 4 , *bytes_written, err);
- }
- }
-
- if (have_options) {
- /* write end of options */
- option.type = OPT_ENDOFOPT;
- option.value_length = 0;
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- }
-
- /* write the trailing Block Total Length */
- WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
- return TRUE;
+ struct idb idb;
+ struct option option;
+ guint32 block_total_length;
+ const guint32 padding = 0;
+ gboolean have_options = FALSE;
+
+ block_total_length = sizeof(struct idb) + sizeof(guint32);
+ /* 01 - OPT_COMMENT */
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(comment) + 1));
+ have_options = TRUE;
+ }
+
+ /* 02 - IDB_NAME */
+ if ((name != NULL) && (strlen(name) > 0) && (strlen(name) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(name) + 1));
+ have_options = TRUE;
+ }
+
+ /* 03 - IDB_DESCRIPTION */
+ if ((descr != NULL) && (strlen(descr) > 0) && (strlen(descr) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(descr) + 1));
+ have_options = TRUE;
+ }
+
+ /* 08 - IDB_IF_SPEED */
+ if (if_speed != 0) {
+ block_total_length += sizeof(struct option) + sizeof(guint64);
+ have_options = TRUE;
+ }
+
+ /* 09 - IDB_TSRESOL */
+ if (tsresol != 0) {
+ block_total_length += sizeof(struct option) + sizeof(struct option);
+ have_options = TRUE;
+ }
+
+ /* 11 - IDB_FILTER */
+ if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(filter) + 1 + 1));
+ have_options = TRUE;
+ }
+
+ /* 12 - IDB_OS */
+ if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(os) + 1));
+ have_options = TRUE;
+ }
+
+ /* If we have options add size of end-of-options */
+ if (have_options) {
+ block_total_length += sizeof(struct option);
+ }
+
+ /* write block header */
+ idb.block_type = INTERFACE_DESCRIPTION_BLOCK_TYPE;
+ idb.block_total_length = block_total_length;
+ idb.link_type = link_type;
+ idb.reserved = 0;
+ idb.snap_len = snap_len;
+ WRITE_DATA(fp, &idb, sizeof(struct idb), *bytes_written, err);
+
+ /* 01 - OPT_COMMENT - write comment string if applicable */
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ option.type = OPT_COMMENT;
+ option.value_length = (guint16)(strlen(comment) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
+ if ((strlen(comment) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4 , *bytes_written, err);
+ }
+ }
+
+ /* 02 - IDB_NAME - write interface name string if applicable */
+ if ((name != NULL) && (strlen(name) > 0) && (strlen(name) < G_MAXUINT16)) {
+ option.type = IDB_NAME;
+ option.value_length = (guint16)(strlen(name) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, name, strlen(name) + 1, *bytes_written, err);
+ if ((strlen(name) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(name) + 1) % 4 , *bytes_written, err);
+ }
+ }
+
+ /* 03 - IDB_DESCRIPTION */
+ /* write interface description string if applicable */
+ if ((descr != NULL) && (strlen(descr) > 0) && (strlen(descr) < G_MAXUINT16)) {
+ option.type = IDB_DESCRIPTION;
+ option.value_length = (guint16)(strlen(descr) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, name, strlen(descr) + 1, *bytes_written, err);
+ if ((strlen(descr) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(descr) + 1) % 4 , *bytes_written, err);
+ }
+ }
+
+ /* 08 - IDB_IF_SPEED */
+ if (if_speed != 0) {
+ option.type = IDB_IF_SPEED;
+ option.value_length = sizeof(guint64);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &if_speed, sizeof(guint64), *bytes_written, err);
+ }
+
+ /* 09 - IDB_TSRESOL */
+ if (tsresol != 0) {
+ option.type = IDB_TSRESOL;
+ option.value_length = sizeof(guint8);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &tsresol, sizeof(guint8), *bytes_written, err);
+ WRITE_DATA(fp, &padding, 3 , *bytes_written, err);
+ }
+
+ /* 11 - IDB_FILTER - write filter string if applicable
+ * We only write version 1 of the filter, libpcap string
+ */
+ if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
+ option.type = IDB_FILTER;
+ option.value_length = (guint16)(strlen(filter) + 1 + 1 );
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+
+ /* The first byte of the Option Data keeps a code of the filter used, 0 = lipbpcap filter string */
+ WRITE_DATA(fp, &padding, 1, *bytes_written, err);
+ WRITE_DATA(fp, filter, strlen(filter) + 1, *bytes_written, err);
+ if ((strlen(filter) + 2) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(filter) + 2) % 4 , *bytes_written, err);
+ }
+ }
+
+ /* 12 - IDB_OS - write os string if applicable */
+ if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
+ option.type = IDB_OS;
+ option.value_length = (guint16)(strlen(os) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, os, strlen(os) + 1, *bytes_written, err);
+ if ((strlen(os) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(os) + 1) % 4 , *bytes_written, err);
+ }
+ }
+
+ if (have_options) {
+ /* write end of options */
+ option.type = OPT_ENDOFOPT;
+ option.value_length = 0;
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ }
+
+ /* write the trailing Block Total Length */
+ WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
+ return TRUE;
}
/* Write a record for a packet to a dump file.
@@ -554,35 +554,35 @@ gboolean
libpcap_write_enhanced_packet_block(FILE *fp,
const struct pcap_pkthdr *phdr,
guint32 interface_id,
- guint ts_mul,
+ guint ts_mul,
const u_char *pd,
long *bytes_written,
int *err)
{
- struct epb epb;
- guint32 block_total_length;
- guint64 timestamp;
- const guint32 padding = 0;
-
- block_total_length = sizeof(struct epb) +
- ADD_PADDING(phdr->caplen) +
- sizeof(guint32);
- timestamp = (guint64)(phdr->ts.tv_sec) * ts_mul +
- (guint64)(phdr->ts.tv_usec);
- epb.block_type = ENHANCED_PACKET_BLOCK_TYPE;
- epb.block_total_length = block_total_length;
- epb.interface_id = interface_id;
- epb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
- epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
- epb.captured_len = phdr->caplen;
- epb.packet_len = phdr->len;
- WRITE_DATA(fp, &epb, sizeof(struct epb), *bytes_written, err);
- WRITE_DATA(fp, pd, phdr->caplen, *bytes_written, err);
- if (phdr->caplen % 4) {
- WRITE_DATA(fp, &padding, 4 - phdr->caplen % 4, *bytes_written, err);
- }
- WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
- return TRUE;
+ struct epb epb;
+ guint32 block_total_length;
+ guint64 timestamp;
+ const guint32 padding = 0;
+
+ block_total_length = sizeof(struct epb) +
+ ADD_PADDING(phdr->caplen) +
+ sizeof(guint32);
+ timestamp = (guint64)(phdr->ts.tv_sec) * ts_mul +
+ (guint64)(phdr->ts.tv_usec);
+ epb.block_type = ENHANCED_PACKET_BLOCK_TYPE;
+ epb.block_total_length = block_total_length;
+ epb.interface_id = interface_id;
+ epb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
+ epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
+ epb.captured_len = phdr->caplen;
+ epb.packet_len = phdr->len;
+ WRITE_DATA(fp, &epb, sizeof(struct epb), *bytes_written, err);
+ WRITE_DATA(fp, pd, phdr->caplen, *bytes_written, err);
+ if (phdr->caplen % 4) {
+ WRITE_DATA(fp, &padding, 4 - phdr->caplen % 4, *bytes_written, err);
+ }
+ WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
+ return TRUE;
}
gboolean
@@ -595,166 +595,166 @@ libpcap_write_interface_statistics_block(FILE *fp,
guint64 isb_endtime, /* ISB_ENDTIME 3 */
int *err)
{
- struct isb isb;
+ struct isb isb;
#ifdef _WIN32
- FILETIME now;
+ FILETIME now;
#else
- struct timeval now;
+ struct timeval now;
#endif
- struct option option;
- struct pcap_stat stats;
- guint32 block_total_length;
- guint64 timestamp;
- guint64 counter;
- gboolean stats_retrieved;
- gboolean have_options = FALSE;
- const guint32 padding = 0;
+ struct option option;
+ struct pcap_stat stats;
+ guint32 block_total_length;
+ guint64 timestamp;
+ guint64 counter;
+ gboolean stats_retrieved;
+ gboolean have_options = FALSE;
+ const guint32 padding = 0;
#ifdef _WIN32
- /*
- * Current time, represented as 100-nanosecond intervals since
- * January 1, 1601, 00:00:00 UTC.
- *
- * I think DWORD might be signed, so cast both parts of "now"
- * to guint32 so that the sign bit doesn't get treated specially.
- *
- * Windows 8 provides GetSystemTimePreciseAsFileTime which we
- * might want to use instead.
- */
- GetSystemTimeAsFileTime(&now);
- timestamp = (((guint64)(guint32)now.dwHighDateTime) << 32) +
- (guint32)now.dwLowDateTime;
-
- /*
- * Convert to same thing but as 1-microsecond, i.e. 1000-nanosecond,
- * intervals.
- */
- timestamp /= 10;
-
- /*
- * Subtract difference, in microseconds, between January 1, 1601
- * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC.
- */
- timestamp -= G_GINT64_CONSTANT(11644473600000000U);
+ /*
+ * Current time, represented as 100-nanosecond intervals since
+ * January 1, 1601, 00:00:00 UTC.
+ *
+ * I think DWORD might be signed, so cast both parts of "now"
+ * to guint32 so that the sign bit doesn't get treated specially.
+ *
+ * Windows 8 provides GetSystemTimePreciseAsFileTime which we
+ * might want to use instead.
+ */
+ GetSystemTimeAsFileTime(&now);
+ timestamp = (((guint64)(guint32)now.dwHighDateTime) << 32) +
+ (guint32)now.dwLowDateTime;
+
+ /*
+ * Convert to same thing but as 1-microsecond, i.e. 1000-nanosecond,
+ * intervals.
+ */
+ timestamp /= 10;
+
+ /*
+ * Subtract difference, in microseconds, between January 1, 1601
+ * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC.
+ */
+ timestamp -= G_GINT64_CONSTANT(11644473600000000U);
#else
- /*
- * Current time, represented as seconds and microseconds since
- * January 1, 1970, 00:00:00 UTC.
- */
- gettimeofday(&now, NULL);
-
- /*
- * Convert to delta in microseconds.
- */
- timestamp = (guint64)(now.tv_sec) * 1000000 +
- (guint64)(now.tv_usec);
+ /*
+ * Current time, represented as seconds and microseconds since
+ * January 1, 1970, 00:00:00 UTC.
+ */
+ gettimeofday(&now, NULL);
+
+ /*
+ * Convert to delta in microseconds.
+ */
+ timestamp = (guint64)(now.tv_sec) * 1000000 +
+ (guint64)(now.tv_usec);
#endif
- if (pcap_stats(pd, &stats) < 0) {
- stats_retrieved = FALSE;
- g_warning("pcap_stats() failed.");
- } else {
- stats_retrieved = TRUE;
- have_options = TRUE;
- }
- block_total_length = sizeof(struct isb) +
- sizeof(guint32);
- if (stats_retrieved) {
- block_total_length += 2 * sizeof(struct option) + 2 * sizeof(guint64); /* ISB_IFRECV + ISB_IFDROP */
- }
- /* OPT_COMMENT */
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- block_total_length += sizeof(struct option) +
- (guint16)(ADD_PADDING(strlen(comment) + 1));
- have_options = TRUE;
- }
- if (isb_starttime !=0) {
- block_total_length += sizeof(struct option) + sizeof(guint64); /* ISB_STARTTIME */
- have_options = TRUE;
- }
- if (isb_endtime !=0) {
- block_total_length += sizeof(struct option) + sizeof(guint64); /* ISB_ENDTIME */
- have_options = TRUE;
- }
- /* If we have options add size of end-of-options */
- if (have_options) {
- block_total_length += sizeof(struct option);
- }
-
- isb.block_type = INTERFACE_STATISTICS_BLOCK_TYPE;
- isb.block_total_length = block_total_length;
- isb.interface_id = interface_id;
- isb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
- isb.timestamp_low = (guint32)(timestamp & 0xffffffff);
- WRITE_DATA(fp, &isb, sizeof(struct isb), *bytes_written, err);
-
- /* write comment string if applicable */
- if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
- option.type = OPT_COMMENT;
- option.value_length = (guint16)(strlen(comment) + 1);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
- if ((strlen(comment) + 1) % 4) {
- WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4 , *bytes_written, err);
- }
- }
-
- if (isb_starttime !=0) {
- option.type = ISB_STARTTIME;
- option.value_length = sizeof(guint64);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &isb_starttime, sizeof(guint64), *bytes_written, err);
- }
- if (isb_endtime !=0) {
- option.type = ISB_ENDTIME;
- option.value_length = sizeof(guint64);
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &isb_endtime, sizeof(guint64), *bytes_written, err);
- }
- if (stats_retrieved) {
- /* */
- option.type = ISB_IFRECV;
- option.value_length = sizeof(guint64);
- counter = stats.ps_recv;
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
- /* */
- option.type = ISB_IFDROP;
- option.value_length = sizeof(guint64);
- counter = stats.ps_drop;
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
- }
- if (have_options) {
- /* write end of options */
- option.type = OPT_ENDOFOPT;
- option.value_length = 0;
- WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
- }
-
- WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
-
- return TRUE;
+ if (pcap_stats(pd, &stats) < 0) {
+ stats_retrieved = FALSE;
+ g_warning("pcap_stats() failed.");
+ } else {
+ stats_retrieved = TRUE;
+ have_options = TRUE;
+ }
+ block_total_length = sizeof(struct isb) +
+ sizeof(guint32);
+ if (stats_retrieved) {
+ block_total_length += 2 * sizeof(struct option) + 2 * sizeof(guint64); /* ISB_IFRECV + ISB_IFDROP */
+ }
+ /* OPT_COMMENT */
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ block_total_length += sizeof(struct option) +
+ (guint16)(ADD_PADDING(strlen(comment) + 1));
+ have_options = TRUE;
+ }
+ if (isb_starttime !=0) {
+ block_total_length += sizeof(struct option) + sizeof(guint64); /* ISB_STARTTIME */
+ have_options = TRUE;
+ }
+ if (isb_endtime !=0) {
+ block_total_length += sizeof(struct option) + sizeof(guint64); /* ISB_ENDTIME */
+ have_options = TRUE;
+ }
+ /* If we have options add size of end-of-options */
+ if (have_options) {
+ block_total_length += sizeof(struct option);
+ }
+
+ isb.block_type = INTERFACE_STATISTICS_BLOCK_TYPE;
+ isb.block_total_length = block_total_length;
+ isb.interface_id = interface_id;
+ isb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
+ isb.timestamp_low = (guint32)(timestamp & 0xffffffff);
+ WRITE_DATA(fp, &isb, sizeof(struct isb), *bytes_written, err);
+
+ /* write comment string if applicable */
+ if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
+ option.type = OPT_COMMENT;
+ option.value_length = (guint16)(strlen(comment) + 1);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, comment, strlen(comment) + 1, *bytes_written, err);
+ if ((strlen(comment) + 1) % 4) {
+ WRITE_DATA(fp, &padding, 4 - (strlen(comment) + 1) % 4 , *bytes_written, err);
+ }
+ }
+
+ if (isb_starttime !=0) {
+ option.type = ISB_STARTTIME;
+ option.value_length = sizeof(guint64);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &isb_starttime, sizeof(guint64), *bytes_written, err);
+ }
+ if (isb_endtime !=0) {
+ option.type = ISB_ENDTIME;
+ option.value_length = sizeof(guint64);
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &isb_endtime, sizeof(guint64), *bytes_written, err);
+ }
+ if (stats_retrieved) {
+ /* */
+ option.type = ISB_IFRECV;
+ option.value_length = sizeof(guint64);
+ counter = stats.ps_recv;
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
+ /* */
+ option.type = ISB_IFDROP;
+ option.value_length = sizeof(guint64);
+ counter = stats.ps_drop;
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ WRITE_DATA(fp, &counter, sizeof(guint64), *bytes_written, err);
+ }
+ if (have_options) {
+ /* write end of options */
+ option.type = OPT_ENDOFOPT;
+ option.value_length = 0;
+ WRITE_DATA(fp, &option, sizeof(struct option), *bytes_written, err);
+ }
+
+ WRITE_DATA(fp, &block_total_length, sizeof(guint32), *bytes_written, err);
+
+ return TRUE;
}
gboolean
libpcap_dump_flush(FILE *pd, int *err)
{
- if (fflush(pd) == EOF) {
- if (err != NULL)
- *err = errno;
- return FALSE;
- }
- return TRUE;
+ if (fflush(pd) == EOF) {
+ if (err != NULL)
+ *err = errno;
+ return FALSE;
+ }
+ return TRUE;
}
gboolean
libpcap_dump_close(FILE *pd, int *err)
{
- if (fclose(pd) == EOF) {
- if (err != NULL)
- *err = errno;
- return FALSE;
- }
- return TRUE;
+ if (fclose(pd) == EOF) {
+ if (err != NULL)
+ *err = errno;
+ return FALSE;
+ }
+ return TRUE;
}
#endif /* HAVE_LIBPCAP */