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_LINUX_SLL 113
#define | LINKTYPE_LTALK 114
#define | LINKTYPE_ECONET 115
#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_ENC 109
#define | LINKTYPE_LANE8023 110
#define | LINKTYPE_HIPPI 111
#define | LINKTYPE_HDLC 112
#define | LINKTYPE_IPFILTER 116
#define | LINKTYPE_PFLOG 117
#define | LINKTYPE_HHDLC 121
#define | LINKTYPE_RIO 124
#define | LINKTYPE_PCI_EXP 125
#define | LINKTYPE_AURORA 126
## 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)
pcap_t * | pcap_open_offline (const char *fname, char *errbuf)
| Deprecated
int | sf_next_packet (pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, 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.
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 []
linktype_map | map []

## Define Documentation

#define LINKTYPE_AIRONET_HEADER 120

| Definition at line 166 of file savefile.c.

#define LINKTYPE_ARCNET DLT_ARCNET

| Definition at line 126 of file savefile.c.

#define LINKTYPE_ARCNET_LINUX 129

| Definition at line 174 of file savefile.c.

#define LINKTYPE_ATM_CLIP 106

| Definition at line 156 of file savefile.c.

#define LINKTYPE_ATM_RFC1483 100

| Definition at line 150 of file savefile.c.

#define LINKTYPE_AURORA 126

| Definition at line 188 of file savefile.c.

#define LINKTYPE_AX25 DLT_AX25

| Definition at line 122 of file savefile.c.

#define LINKTYPE_C_HDLC 104

| Definition at line 154 of file savefile.c.

#define LINKTYPE_CHAOS DLT_CHAOS

| Definition at line 124 of file savefile.c.

#define LINKTYPE_CISCO_IOS 118

| Definition at line 164 of file savefile.c.

#define LINKTYPE_ECONET 115

| Definition at line 162 of file savefile.c.

#define LINKTYPE_ENC 109

| Definition at line 179 of file savefile.c.

#define LINKTYPE_ETHERNET DLT_EN10MB

| Definition at line 120 of file savefile.c.

#define LINKTYPE_EXP_ETHERNET DLT_EN3MB

| Definition at line 121 of file savefile.c.

#define LINKTYPE_FDDI DLT_FDDI

| Definition at line 129 of file savefile.c.

#define LINKTYPE_FRELAY 107

| Definition at line 157 of file savefile.c.

#define LINKTYPE_HDLC 112

| Definition at line 182 of file savefile.c.

#define LINKTYPE_HHDLC 121

| Definition at line 185 of file savefile.c.

#define LINKTYPE_HIPPI 111

| Definition at line 181 of file savefile.c.

#define LINKTYPE_IEEE802_11 105

| Definition at line 155 of file savefile.c.

#define LINKTYPE_IEEE802_11_RADIO 127

| Definition at line 170 of file savefile.c.

#define LINKTYPE_IP_OVER_FC 122

| Definition at line 167 of file savefile.c.

#define LINKTYPE_IPFILTER 116

| Definition at line 183 of file savefile.c.

#define LINKTYPE_LANE8023 110

| Definition at line 180 of file savefile.c.

#define LINKTYPE_LINUX_SLL 113

| Definition at line 160 of file savefile.c.

#define LINKTYPE_LOOP 108

| Definition at line 158 of file savefile.c.

#define LINKTYPE_LTALK 114

| Definition at line 161 of file savefile.c.

#define LINKTYPE_NULL DLT_NULL

| Definition at line 119 of file savefile.c.

#define LINKTYPE_PCI_EXP 125

| Definition at line 187 of file savefile.c.

#define LINKTYPE_PFLOG 117

| Definition at line 184 of file savefile.c.

#define LINKTYPE_PPP DLT_PPP

| Definition at line 128 of file savefile.c.

#define LINKTYPE_PPP_BSDOS 103

| Definition at line 153 of file savefile.c.

#define LINKTYPE_PPP_ETHER 51

| Definition at line 148 of file savefile.c.

#define LINKTYPE_PPP_HDLC 50

| Definition at line 146 of file savefile.c.

#define LINKTYPE_PRISM_HEADER 119

| Definition at line 165 of file savefile.c.

#define LINKTYPE_PRONET DLT_PRONET

| Definition at line 123 of file savefile.c.

#define LINKTYPE_RAW 101

| Definition at line 151 of file savefile.c.

#define LINKTYPE_RIO 124

| Definition at line 186 of file savefile.c.

#define LINKTYPE_SLIP DLT_SLIP

| Definition at line 127 of file savefile.c.

#define LINKTYPE_SLIP_BSDOS 102

| Definition at line 152 of file savefile.c.

#define LINKTYPE_SUNATM 123

| Definition at line 168 of file savefile.c.

#define LINKTYPE_TOKEN_RING DLT_IEEE802

| Definition at line 125 of file savefile.c.

#define LINKTYPE_TZSP 128

| Definition at line 172 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 72 of file savefile.c.

#define SFERR_BADVERSION 2

| Definition at line 71 of file savefile.c.

#define SFERR_EOF 4

| Definition at line 73 of file savefile.c.

#define SFERR_TRUNC 1

| Definition at line 70 of file savefile.c.

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

| Definition at line 65 of file savefile.c.

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

| Definition at line 67 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 320 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 338 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 650 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 715 of file savefile.c.

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

| Definition at line 705 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 669 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 619 of file savefile.c. References bpf_filter(), pcap_pkthdr::caplen, pcap_pkthdr::len, n, and sf_next_packet(). Referenced by pcap_dispatch(), pcap_loop(), and pcap_next_ex().

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

| Deprecated Deprecated: Use the pcap_open() instead. It opens a savefile in the tcpdump/libpcap format to read the packets. 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 387 of file savefile.c. References bpf_u_int32, linktype_to_dlt(), PATCHED_TCPDUMP_MAGIC, pcap_fddipad, pcap_strerror(), pcap_t, PCAP_VERSION_MAJOR, snprintf, swap_hdr(), and TCPDUMP_MAGIC. Referenced by pcap_findalldevs_ex(), and pcap_open().

int sf_next_packet | ( | pcap_t * | p,
|  | struct pcap_pkthdr * | hdr,
|  | u_char * | buf,
|  | int | buflen
| ) |

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

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

| Definition at line 356 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 376 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

struct linktype_map map[]`[static]`

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

const char rcsid[]`[static]`

| Initial value:
        "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.75 2003/01/23 07:24:53 guy Exp $ (LBL)"
Definition at line 32 of file savefile.c.

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