Main Page Modules Data Structures File List Data Fields Globals Related Pages

# savefile.c File Reference

`#include <errno.h>`
`#include <memory.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "pcap-int.h"`

Go to the source code of this file.

## Data Structures
struct | linktype_map
## Defines
#define | TCPDUMP_MAGIC 0xa1b2c3d4
#define | PATCHED_TCPDUMP_MAGIC 0xa1b2cd34
#define | SWAPLONG(y) ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
#define | SWAPSHORT(y) ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
#define | SFERR_TRUNC 1
#define | SFERR_BADVERSION 2
#define | SFERR_BADF 3
#define | SFERR_EOF 4
#define | LINKTYPE_NULL DLT_NULL
#define | LINKTYPE_ETHERNET DLT_EN10MB
#define | LINKTYPE_EXP_ETHERNET DLT_EN3MB
#define | LINKTYPE_AX25 DLT_AX25
#define | LINKTYPE_PRONET DLT_PRONET
#define | LINKTYPE_CHAOS DLT_CHAOS
#define | LINKTYPE_TOKEN_RING DLT_IEEE802
#define | LINKTYPE_ARCNET DLT_ARCNET
#define | LINKTYPE_SLIP DLT_SLIP
#define | LINKTYPE_PPP DLT_PPP
#define | LINKTYPE_FDDI DLT_FDDI
#define | LINKTYPE_PPP_HDLC 50
#define | LINKTYPE_PPP_ETHER 51
#define | LINKTYPE_ATM_RFC1483 100
#define | LINKTYPE_RAW 101
#define | LINKTYPE_SLIP_BSDOS 102
#define | LINKTYPE_PPP_BSDOS 103
#define | LINKTYPE_C_HDLC 104
#define | LINKTYPE_IEEE802_11 105
#define | LINKTYPE_ATM_CLIP 106
#define | LINKTYPE_FRELAY 107
#define | LINKTYPE_LOOP 108
#define | LINKTYPE_ENC 109
#define | LINKTYPE_LINUX_SLL 113
#define | LINKTYPE_LTALK 114
#define | LINKTYPE_ECONET 115
#define | LINKTYPE_PFLOG 117
#define | LINKTYPE_CISCO_IOS 118
#define | LINKTYPE_PRISM_HEADER 119
#define | LINKTYPE_AIRONET_HEADER 120
#define | LINKTYPE_IP_OVER_FC 122
#define | LINKTYPE_SUNATM 123
#define | LINKTYPE_IEEE802_11_RADIO 127
#define | LINKTYPE_TZSP 128
#define | LINKTYPE_ARCNET_LINUX 129
#define | LINKTYPE_JUNIPER_MLPPP 130
#define | LINKTYPE_JUNIPER_MLFR 131
#define | LINKTYPE_JUNIPER_ES 132
#define | LINKTYPE_JUNIPER_GGSN 133
#define | LINKTYPE_JUNIPER_MFR 134
#define | LINKTYPE_JUNIPER_ATM2 135
#define | LINKTYPE_JUNIPER_SERVICES 136
#define | LINKTYPE_JUNIPER_ATM1 137
#define | LINKTYPE_APPLE_IP_OVER_IEEE1394 138
#define | LINKTYPE_RAWSS7 139
#define | LINKTYPE_RAWSS7_MTP2 140
#define | LINKTYPE_RAWSS7_MTP3 141
#define | LINKTYPE_RAWSS7_SCCP 142
#define | LINKTYPE_DOCSIS 143
#define | LINKTYPE_LINUX_IRDA 144
#define | LINKTYPE_LANE8023 110
#define | LINKTYPE_HIPPI 111
#define | LINKTYPE_HDLC 112
#define | LINKTYPE_IPFILTER 116
#define | LINKTYPE_HHDLC 121
#define | LINKTYPE_RIO 124
#define | LINKTYPE_PCI_EXP 125
#define | LINKTYPE_AURORA 126
#define | LINKTYPE_IBM_SP 145
#define | LINKTYPE_IBM_SN 146
## Functions
int | dlt_to_linktype (int dlt)
int | linktype_to_dlt (int linktype)
int | sf_write_header (FILE *fp, int linktype, int thiszone, int snaplen)
void | swap_hdr (struct pcap_file_header *hp)
int | sf_getnonblock (pcap_t *p, char *errbuf)
int | sf_setnonblock (pcap_t *p, int nonblock, char *errbuf)
int | sf_stats (pcap_t *p, struct pcap_stat *ps)
void | sf_close (pcap_t *p)
pcap_t * | pcap_open_offline (const char *fname, char *errbuf)
| It opens a savefile in the tcpdump/libpcap format to read the packets.
int | sf_next_packet (pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, u_int buflen)
int | pcap_offline_read (pcap_t *p, int cnt, pcap_handler callback, u_char *user)
void | pcap_dump (u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
| Saves a packet to disk.
pcap_dumper_t * | pcap_dump_open (pcap_t *p, const char *fname)
| Opens a file to write the network traffic.
FILE * | pcap_dump_file (pcap_dumper_t *p)
int | pcap_dump_flush (pcap_dumper_t *p)
void | pcap_dump_close (pcap_dumper_t *p)
| pcap_dump_close() closes the "savefile".
## Variables
const char rcsid[] | _U_
linktype_map | map []

## Define Documentation

#define LINKTYPE_AIRONET_HEADER 120

| Definition at line 171 of file savefile.c.

#define LINKTYPE_APPLE_IP_OVER_IEEE1394 138

| Definition at line 190 of file savefile.c.

#define LINKTYPE_ARCNET DLT_ARCNET

| Definition at line 129 of file savefile.c.

#define LINKTYPE_ARCNET_LINUX 129

| Definition at line 179 of file savefile.c.

#define LINKTYPE_ATM_CLIP 106

| Definition at line 159 of file savefile.c.

#define LINKTYPE_ATM_RFC1483 100

| Definition at line 153 of file savefile.c.

#define LINKTYPE_AURORA 126

| Definition at line 211 of file savefile.c.

#define LINKTYPE_AX25 DLT_AX25

| Definition at line 125 of file savefile.c.

#define LINKTYPE_C_HDLC 104

| Definition at line 157 of file savefile.c.

#define LINKTYPE_CHAOS DLT_CHAOS

| Definition at line 127 of file savefile.c.

#define LINKTYPE_CISCO_IOS 118

| Definition at line 169 of file savefile.c.

#define LINKTYPE_DOCSIS 143

| Definition at line 197 of file savefile.c.

#define LINKTYPE_ECONET 115

| Definition at line 166 of file savefile.c.

#define LINKTYPE_ENC 109

| Definition at line 162 of file savefile.c.

#define LINKTYPE_ETHERNET DLT_EN10MB

| Definition at line 123 of file savefile.c.

#define LINKTYPE_EXP_ETHERNET DLT_EN3MB

| Definition at line 124 of file savefile.c.

#define LINKTYPE_FDDI DLT_FDDI

| Definition at line 132 of file savefile.c.

#define LINKTYPE_FRELAY 107

| Definition at line 160 of file savefile.c.

#define LINKTYPE_HDLC 112

| Definition at line 206 of file savefile.c.

#define LINKTYPE_HHDLC 121

| Definition at line 208 of file savefile.c.

#define LINKTYPE_HIPPI 111

| Definition at line 205 of file savefile.c.

#define LINKTYPE_IBM_SN 146

| Definition at line 213 of file savefile.c.

#define LINKTYPE_IBM_SP 145

| Definition at line 212 of file savefile.c.

#define LINKTYPE_IEEE802_11 105

| Definition at line 158 of file savefile.c.

#define LINKTYPE_IEEE802_11_RADIO 127

| Definition at line 175 of file savefile.c.

#define LINKTYPE_IP_OVER_FC 122

| Definition at line 172 of file savefile.c.

#define LINKTYPE_IPFILTER 116

| Definition at line 207 of file savefile.c.

#define LINKTYPE_JUNIPER_ATM1 137

| Definition at line 188 of file savefile.c.

#define LINKTYPE_JUNIPER_ATM2 135

| Definition at line 186 of file savefile.c.

#define LINKTYPE_JUNIPER_ES 132

| Definition at line 183 of file savefile.c.

#define LINKTYPE_JUNIPER_GGSN 133

| Definition at line 184 of file savefile.c.

#define LINKTYPE_JUNIPER_MFR 134

| Definition at line 185 of file savefile.c.

#define LINKTYPE_JUNIPER_MLFR 131

| Definition at line 182 of file savefile.c.

#define LINKTYPE_JUNIPER_MLPPP 130

| Definition at line 181 of file savefile.c.

#define LINKTYPE_JUNIPER_SERVICES 136

| Definition at line 187 of file savefile.c.

#define LINKTYPE_LANE8023 110

| Definition at line 204 of file savefile.c.

#define LINKTYPE_LINUX_IRDA 144

| Definition at line 199 of file savefile.c.

#define LINKTYPE_LINUX_SLL 113

| Definition at line 164 of file savefile.c.

#define LINKTYPE_LOOP 108

| Definition at line 161 of file savefile.c.

#define LINKTYPE_LTALK 114

| Definition at line 165 of file savefile.c.

#define LINKTYPE_NULL DLT_NULL

| Definition at line 122 of file savefile.c.

#define LINKTYPE_PCI_EXP 125

| Definition at line 210 of file savefile.c.

#define LINKTYPE_PFLOG 117

| Definition at line 168 of file savefile.c.

#define LINKTYPE_PPP DLT_PPP

| Definition at line 131 of file savefile.c.

#define LINKTYPE_PPP_BSDOS 103

| Definition at line 156 of file savefile.c.

#define LINKTYPE_PPP_ETHER 51

| Definition at line 151 of file savefile.c.

#define LINKTYPE_PPP_HDLC 50

| Definition at line 149 of file savefile.c.

#define LINKTYPE_PRISM_HEADER 119

| Definition at line 170 of file savefile.c.

#define LINKTYPE_PRONET DLT_PRONET

| Definition at line 126 of file savefile.c.

#define LINKTYPE_RAW 101

| Definition at line 154 of file savefile.c.

#define LINKTYPE_RAWSS7 139

| Definition at line 192 of file savefile.c.

#define LINKTYPE_RAWSS7_MTP2 140

| Definition at line 193 of file savefile.c.

#define LINKTYPE_RAWSS7_MTP3 141

| Definition at line 194 of file savefile.c.

#define LINKTYPE_RAWSS7_SCCP 142

| Definition at line 195 of file savefile.c.

#define LINKTYPE_RIO 124

| Definition at line 209 of file savefile.c.

#define LINKTYPE_SLIP DLT_SLIP

| Definition at line 130 of file savefile.c.

#define LINKTYPE_SLIP_BSDOS 102

| Definition at line 155 of file savefile.c.

#define LINKTYPE_SUNATM 123

| Definition at line 173 of file savefile.c.

#define LINKTYPE_TOKEN_RING DLT_IEEE802

| Definition at line 128 of file savefile.c.

#define LINKTYPE_TZSP 128

| Definition at line 177 of file savefile.c.

#define PATCHED_TCPDUMP_MAGIC 0xa1b2cd34

| Definition at line 53 of file savefile.c. Referenced by pcap_open_offline().

#define SFERR_BADF 3

| Definition at line 75 of file savefile.c.

#define SFERR_BADVERSION 2

| Definition at line 74 of file savefile.c.

#define SFERR_EOF 4

| Definition at line 76 of file savefile.c.

#define SFERR_TRUNC 1

| Definition at line 73 of file savefile.c.

#define SWAPLONG | ( | y |  | ) | ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))

| Definition at line 68 of file savefile.c.

#define SWAPSHORT | ( | y |  | ) | ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )

| Definition at line 70 of file savefile.c. Referenced by swap_hdr().

#define TCPDUMP_MAGIC 0xa1b2c3d4

| Definition at line 52 of file savefile.c.

## Function Documentation

int dlt_to_linktype | ( | int | dlt | ) | `[static]`

| Definition at line 371 of file savefile.c. References linktype_map::dlt, linktype_map::linktype, and map. Referenced by pcap_dump_open().

int linktype_to_dlt | ( | int | linktype | ) | `[static]`

| Definition at line 389 of file savefile.c. References linktype_map::dlt, linktype_map::linktype, and map. Referenced by pcap_open_offline().

void pcap_dump | ( | u_char * | user,
|  | const struct pcap_pkthdr * | h,
|  | const u_char * | sp
| ) |

| Saves a packet to disk. pcap_dump() outputs a packet to the "savefile" opened with pcap_dump_open(). Note that its calling arguments are suitable for use with pcap_dispatch() or pcap_loop(). If called directly, the user parameter is of type pcap_dumper_t as returned by pcap_dump_open(). See also: pcap_dump_open(), pcap_dump_close(), pcap_dispatch(), pcap_loop() Definition at line 869 of file savefile.c. References pcap_pkthdr::caplen, pcap_pkthdr::len, and pcap_pkthdr::ts. Referenced by main().

void pcap_dump_close | ( | pcap_dumper_t * | p | ) |

| pcap_dump_close() closes the "savefile". See also: pcap_dump_open(), pcap_dump() Definition at line 943 of file savefile.c.

FILE* pcap_dump_file | ( | pcap_dumper_t * | p | ) |

| Definition at line 927 of file savefile.c.

int pcap_dump_flush | ( | pcap_dumper_t * | p | ) |

| Definition at line 933 of file savefile.c.

pcap_dumper_t* pcap_dump_open | ( | pcap_t * | p,
|  | const char * | fname
| ) |

| Opens a file to write the network traffic. pcap_dump_open() is called to open a "savefile" for writing. fname is the name of the file to open. The name "-" in a synonym for stdout. If NULL is returned, pcap_geterr() can be used to get the error text. See also: pcap_dump_close(), pcap_file(), pcap_dump () Definition at line 888 of file savefile.c. References dlt_to_linktype(), pcap_dumper_t, pcap_strerror(), sf_write_header(), and snprintf. Referenced by main().

int pcap_offline_read | ( | pcap_t * | p,
|  | int | cnt,
|  | pcap_handler | callback,
|  | u_char * | user
| ) |

| Definition at line 785 of file savefile.c. References pcap_pkthdr::caplen, pcap_pkthdr::len, n, PCAP_SAMP_1_EVERY_N, PCAP_SAMP_FIRST_AFTER_N_MS, sf_next_packet(), and pcap_pkthdr::ts. Referenced by pcap_loop(), pcap_next_ex(), and pcap_open_offline().

pcap_t* pcap_open_offline | ( | const char * | fname,
|  | char * | errbuf
| ) |

| It opens a savefile in the tcpdump/libpcap format to read the packets. Deprecated: Use the pcap_open() instead. pcap_open_offline() is called to open a "savefile" for reading. fname specifies the name of the file to open. The file has the same format as those used by tcpdump(1) and tcpslice(1). The name "-" in a synonym for stdin. errbuf is used to return error text and is only set when pcap_open_offline() fails and returns NULL. See also: pcap_open_live(), pcap_dump_open(), pcap_findalldevs(), pcap_close() Definition at line 475 of file savefile.c. References bpf_u_int32, linktype_to_dlt(), PATCHED_TCPDUMP_MAGIC, pcap_fddipad, pcap_offline_read(), pcap_strerror(), pcap_t, PCAP_VERSION_MAJOR, sf_close(), sf_getnonblock(), sf_setnonblock(), sf_stats(), snprintf, swap_hdr(), and TCPDUMP_MAGIC. Referenced by pcap_findalldevs_ex(), and pcap_open().

void sf_close | ( | pcap_t * | p | ) | `[static]`

| Definition at line 466 of file savefile.c. Referenced by pcap_open_offline().

int sf_getnonblock | ( | pcap_t * | p,
|  | char * | errbuf
| ) | `[static]`

| Definition at line 438 of file savefile.c. Referenced by pcap_open_offline().

int sf_next_packet | ( | pcap_t * | p,
|  | struct pcap_pkthdr * | hdr,
|  | u_char * | buf,
|  | u_int | buflen
| ) | `[static]`

| Definition at line 642 of file savefile.c. References bpf_u_int32, pcap_pkthdr::caplen, pcap_pkthdr::len, pcap_strerror(), snprintf, and pcap_pkthdr::ts. Referenced by pcap_offline_read().

int sf_setnonblock | ( | pcap_t * | p,
|  | int | nonblock,
|  | char * | errbuf
| ) | `[static]`

| Definition at line 448 of file savefile.c. Referenced by pcap_open_offline().

int sf_stats | ( | pcap_t * | p,
|  | struct pcap_stat * | ps
| ) | `[static]`

| Definition at line 458 of file savefile.c. References snprintf. Referenced by pcap_open_offline().

int sf_write_header | ( | FILE * | fp,
|  | int | linktype,
|  | int | thiszone,
|  | int | snaplen
| ) | `[static]`

| Definition at line 407 of file savefile.c. References pcap_file_header::linktype, pcap_file_header::magic, PCAP_VERSION_MAJOR, PCAP_VERSION_MINOR, pcap_file_header::sigfigs, pcap_file_header::snaplen, TCPDUMP_MAGIC, pcap_file_header::thiszone, pcap_file_header::version_major, and pcap_file_header::version_minor. Referenced by pcap_dump_open().

void swap_hdr | ( | struct pcap_file_header * | hp | ) | `[static]`

| Definition at line 427 of file savefile.c. References pcap_file_header::linktype, pcap_file_header::sigfigs, pcap_file_header::snaplen, SWAPSHORT, pcap_file_header::thiszone, pcap_file_header::version_major, and pcap_file_header::version_minor. Referenced by pcap_open_offline().

## Variable Documentation

const char rcsid [] _U_`[static]`

| Initial value:
        "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.100 2003/12/21 21:58:50 guy Exp $ (LBL)"
Definition at line 32 of file savefile.c.

struct linktype_map map[]`[static]`

| Referenced by dlt_to_linktype(), and linktype_to_dlt().

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.