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 KUZNETZOV_TCPDUMP_MAGIC   0xa1b2cd34
#define FMESQUITA_TCPDUMP_MAGIC   0xa1b234cd
#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 /* not really an error, just a status */
#define LINKTYPE_NULL   DLT_NULL
#define LINKTYPE_ETHERNET   DLT_EN10MB /* also for 100Mb and up */
#define LINKTYPE_EXP_ETHERNET   DLT_EN3MB /* 3Mb experimental Ethernet */
#define LINKTYPE_AX25   DLT_AX25
#define LINKTYPE_PRONET   DLT_PRONET
#define LINKTYPE_CHAOS   DLT_CHAOS
#define LINKTYPE_TOKEN_RING   DLT_IEEE802 /* DLT_IEEE802 is used for Token Ring */
#define LINKTYPE_ARCNET   DLT_ARCNET /* BSD-style headers */
#define LINKTYPE_SLIP   DLT_SLIP
#define LINKTYPE_PPP   DLT_PPP
#define LINKTYPE_FDDI   DLT_FDDI
#define LINKTYPE_PPP_HDLC   50 /* PPP in HDLC-like framing */
#define LINKTYPE_PPP_ETHER   51 /* NetBSD PPP-over-Ethernet */
#define LINKTYPE_SYMANTEC_FIREWALL   99 /* Symantec Enterprise Firewall */
#define LINKTYPE_ATM_RFC1483   100 /* LLC/SNAP-encapsulated ATM */
#define LINKTYPE_RAW   101 /* raw IP */
#define LINKTYPE_SLIP_BSDOS   102 /* BSD/OS SLIP BPF header */
#define LINKTYPE_PPP_BSDOS   103 /* BSD/OS PPP BPF header */
#define LINKTYPE_C_HDLC   104 /* Cisco HDLC */
#define LINKTYPE_IEEE802_11   105 /* IEEE 802.11 (wireless) */
#define LINKTYPE_ATM_CLIP   106 /* Linux Classical IP over ATM */
#define LINKTYPE_FRELAY   107 /* Frame Relay */
#define LINKTYPE_LOOP   108 /* OpenBSD loopback */
#define LINKTYPE_ENC   109 /* OpenBSD IPSEC enc */
#define LINKTYPE_LANE8023   110 /* ATM LANE + 802.3 */
#define LINKTYPE_HIPPI   111 /* NetBSD HIPPI */
#define LINKTYPE_HDLC   112 /* NetBSD HDLC framing */
#define LINKTYPE_LINUX_SLL   113 /* Linux cooked socket capture */
#define LINKTYPE_LTALK   114 /* Apple LocalTalk hardware */
#define LINKTYPE_ECONET   115 /* Acorn Econet */
#define LINKTYPE_IPFILTER   116
#define LINKTYPE_PFLOG   117 /* OpenBSD DLT_PFLOG */
#define LINKTYPE_CISCO_IOS   118 /* For Cisco-internal use */
#define LINKTYPE_PRISM_HEADER   119 /* 802.11+Prism II monitor mode */
#define LINKTYPE_AIRONET_HEADER   120 /* FreeBSD Aironet driver stuff */
#define LINKTYPE_HHDLC   121
#define LINKTYPE_IP_OVER_FC   122 /* RFC 2625 IP-over-Fibre Channel */
#define LINKTYPE_SUNATM   123 /* Solaris+SunATM */
#define LINKTYPE_RIO   124 /* RapidIO */
#define LINKTYPE_PCI_EXP   125 /* PCI Express */
#define LINKTYPE_AURORA   126 /* Xilinx Aurora link layer */
#define LINKTYPE_IEEE802_11_RADIO   127 /* 802.11 plus BSD radio header */
#define LINKTYPE_TZSP   128 /* Tazmen Sniffer Protocol */
#define LINKTYPE_ARCNET_LINUX   129 /* Linux-style headers */
#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 /* Apple IP-over-IEEE 1394 cooked header */
#define LINKTYPE_RAWSS7   139 /* see rawss7.h for */
#define LINKTYPE_RAWSS7_MTP2   140 /* information on these */
#define LINKTYPE_RAWSS7_MTP3   141 /* definitions */
#define LINKTYPE_RAWSS7_SCCP   142
#define LINKTYPE_DOCSIS   143 /* DOCSIS MAC frames */
#define LINKTYPE_LINUX_IRDA   144 /* Linux-IrDA */
#define LINKTYPE_IBM_SP   145
#define LINKTYPE_IBM_SN   146
#define LINKTYPE_USER0   147
#define LINKTYPE_USER1   148
#define LINKTYPE_USER2   149
#define LINKTYPE_USER3   150
#define LINKTYPE_USER4   151
#define LINKTYPE_USER5   152
#define LINKTYPE_USER6   153
#define LINKTYPE_USER7   154
#define LINKTYPE_USER8   155
#define LINKTYPE_USER9   156
#define LINKTYPE_USER10   157
#define LINKTYPE_USER11   158
#define LINKTYPE_USER12   159
#define LINKTYPE_USER13   160
#define LINKTYPE_USER14   161
#define LINKTYPE_USER15   162
#define LINKTYPE_IEEE802_11_RADIO_AVS   163 /* 802.11 plus AVS radio header */
#define LINKTYPE_JUNIPER_MONITOR   164
#define LINKTYPE_BACNET_MS_TP   165

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_tpcap_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_tpcap_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 FMESQUITA_TCPDUMP_MAGIC   0xa1b234cd
 

Definition at line 66 of file savefile.c.

#define KUZNETZOV_TCPDUMP_MAGIC   0xa1b2cd34
 

Definition at line 60 of file savefile.c.

Referenced by pcap_open_offline().

#define LINKTYPE_AIRONET_HEADER   120 /* FreeBSD Aironet driver stuff */
 

Definition at line 209 of file savefile.c.

#define LINKTYPE_APPLE_IP_OVER_IEEE1394   138 /* Apple IP-over-IEEE 1394 cooked header */
 

Definition at line 256 of file savefile.c.

#define LINKTYPE_ARCNET   DLT_ARCNET /* BSD-style headers */
 

Definition at line 148 of file savefile.c.

#define LINKTYPE_ARCNET_LINUX   129 /* Linux-style headers */
 

Definition at line 239 of file savefile.c.

#define LINKTYPE_ATM_CLIP   106 /* Linux Classical IP over ATM */
 

Definition at line 185 of file savefile.c.

#define LINKTYPE_ATM_RFC1483   100 /* LLC/SNAP-encapsulated ATM */
 

Definition at line 179 of file savefile.c.

#define LINKTYPE_AURORA   126 /* Xilinx Aurora link layer */
 

Definition at line 225 of file savefile.c.

#define LINKTYPE_AX25   DLT_AX25
 

Definition at line 144 of file savefile.c.

#define LINKTYPE_BACNET_MS_TP   165
 

Definition at line 346 of file savefile.c.

#define LINKTYPE_C_HDLC   104 /* Cisco HDLC */
 

Definition at line 183 of file savefile.c.

#define LINKTYPE_CHAOS   DLT_CHAOS
 

Definition at line 146 of file savefile.c.

#define LINKTYPE_CISCO_IOS   118 /* For Cisco-internal use */
 

Definition at line 207 of file savefile.c.

#define LINKTYPE_DOCSIS   143 /* DOCSIS MAC frames */
 

Definition at line 268 of file savefile.c.

#define LINKTYPE_ECONET   115 /* Acorn Econet */
 

Definition at line 199 of file savefile.c.

#define LINKTYPE_ENC   109 /* OpenBSD IPSEC enc */
 

Definition at line 188 of file savefile.c.

#define LINKTYPE_ETHERNET   DLT_EN10MB /* also for 100Mb and up */
 

Definition at line 142 of file savefile.c.

#define LINKTYPE_EXP_ETHERNET   DLT_EN3MB /* 3Mb experimental Ethernet */
 

Definition at line 143 of file savefile.c.

#define LINKTYPE_FDDI   DLT_FDDI
 

Definition at line 151 of file savefile.c.

#define LINKTYPE_FRELAY   107 /* Frame Relay */
 

Definition at line 186 of file savefile.c.

#define LINKTYPE_HDLC   112 /* NetBSD HDLC framing */
 

Definition at line 195 of file savefile.c.

#define LINKTYPE_HHDLC   121
 

Definition at line 214 of file savefile.c.

#define LINKTYPE_HIPPI   111 /* NetBSD HIPPI */
 

Definition at line 194 of file savefile.c.

#define LINKTYPE_IBM_SN   146
 

Definition at line 276 of file savefile.c.

#define LINKTYPE_IBM_SP   145
 

Definition at line 275 of file savefile.c.

#define LINKTYPE_IEEE802_11   105 /* IEEE 802.11 (wireless) */
 

Definition at line 184 of file savefile.c.

#define LINKTYPE_IEEE802_11_RADIO   127 /* 802.11 plus BSD radio header */
 

Definition at line 227 of file savefile.c.

#define LINKTYPE_IEEE802_11_RADIO_AVS   163 /* 802.11 plus AVS radio header */
 

Definition at line 331 of file savefile.c.

#define LINKTYPE_IP_OVER_FC   122 /* RFC 2625 IP-over-Fibre Channel */
 

Definition at line 216 of file savefile.c.

#define LINKTYPE_IPFILTER   116
 

Definition at line 204 of file savefile.c.

#define LINKTYPE_JUNIPER_ATM1   137
 

Definition at line 254 of file savefile.c.

#define LINKTYPE_JUNIPER_ATM2   135
 

Definition at line 252 of file savefile.c.

#define LINKTYPE_JUNIPER_ES   132
 

Definition at line 249 of file savefile.c.

#define LINKTYPE_JUNIPER_GGSN   133
 

Definition at line 250 of file savefile.c.

#define LINKTYPE_JUNIPER_MFR   134
 

Definition at line 251 of file savefile.c.

#define LINKTYPE_JUNIPER_MLFR   131
 

Definition at line 248 of file savefile.c.

#define LINKTYPE_JUNIPER_MLPPP   130
 

Definition at line 247 of file savefile.c.

#define LINKTYPE_JUNIPER_MONITOR   164
 

Definition at line 339 of file savefile.c.

#define LINKTYPE_JUNIPER_SERVICES   136
 

Definition at line 253 of file savefile.c.

#define LINKTYPE_LANE8023   110 /* ATM LANE + 802.3 */
 

Definition at line 193 of file savefile.c.

#define LINKTYPE_LINUX_IRDA   144 /* Linux-IrDA */
 

Definition at line 270 of file savefile.c.

#define LINKTYPE_LINUX_SLL   113 /* Linux cooked socket capture */
 

Definition at line 197 of file savefile.c.

#define LINKTYPE_LOOP   108 /* OpenBSD loopback */
 

Definition at line 187 of file savefile.c.

#define LINKTYPE_LTALK   114 /* Apple LocalTalk hardware */
 

Definition at line 198 of file savefile.c.

#define LINKTYPE_NULL   DLT_NULL
 

Definition at line 141 of file savefile.c.

#define LINKTYPE_PCI_EXP   125 /* PCI Express */
 

Definition at line 224 of file savefile.c.

#define LINKTYPE_PFLOG   117 /* OpenBSD DLT_PFLOG */
 

Definition at line 206 of file savefile.c.

#define LINKTYPE_PPP   DLT_PPP
 

Definition at line 150 of file savefile.c.

#define LINKTYPE_PPP_BSDOS   103 /* BSD/OS PPP BPF header */
 

Definition at line 182 of file savefile.c.

#define LINKTYPE_PPP_ETHER   51 /* NetBSD PPP-over-Ethernet */
 

Definition at line 170 of file savefile.c.

#define LINKTYPE_PPP_HDLC   50 /* PPP in HDLC-like framing */
 

Definition at line 168 of file savefile.c.

#define LINKTYPE_PRISM_HEADER   119 /* 802.11+Prism II monitor mode */
 

Definition at line 208 of file savefile.c.

#define LINKTYPE_PRONET   DLT_PRONET
 

Definition at line 145 of file savefile.c.

#define LINKTYPE_RAW   101 /* raw IP */
 

Definition at line 180 of file savefile.c.

#define LINKTYPE_RAWSS7   139 /* see rawss7.h for */
 

Definition at line 258 of file savefile.c.

#define LINKTYPE_RAWSS7_MTP2   140 /* information on these */
 

Definition at line 259 of file savefile.c.

#define LINKTYPE_RAWSS7_MTP3   141 /* definitions */
 

Definition at line 260 of file savefile.c.

#define LINKTYPE_RAWSS7_SCCP   142
 

Definition at line 261 of file savefile.c.

#define LINKTYPE_RIO   124 /* RapidIO */
 

Definition at line 223 of file savefile.c.

#define LINKTYPE_SLIP   DLT_SLIP
 

Definition at line 149 of file savefile.c.

#define LINKTYPE_SLIP_BSDOS   102 /* BSD/OS SLIP BPF header */
 

Definition at line 181 of file savefile.c.

#define LINKTYPE_SUNATM   123 /* Solaris+SunATM */
 

Definition at line 217 of file savefile.c.

#define LINKTYPE_SYMANTEC_FIREWALL   99 /* Symantec Enterprise Firewall */
 

Definition at line 177 of file savefile.c.

#define LINKTYPE_TOKEN_RING   DLT_IEEE802 /* DLT_IEEE802 is used for Token Ring */
 

Definition at line 147 of file savefile.c.

#define LINKTYPE_TZSP   128 /* Tazmen Sniffer Protocol */
 

Definition at line 237 of file savefile.c.

#define LINKTYPE_USER0   147
 

Definition at line 304 of file savefile.c.

#define LINKTYPE_USER1   148
 

Definition at line 305 of file savefile.c.

#define LINKTYPE_USER10   157
 

Definition at line 314 of file savefile.c.

#define LINKTYPE_USER11   158
 

Definition at line 315 of file savefile.c.

#define LINKTYPE_USER12   159
 

Definition at line 316 of file savefile.c.

#define LINKTYPE_USER13   160
 

Definition at line 317 of file savefile.c.

#define LINKTYPE_USER14   161
 

Definition at line 318 of file savefile.c.

#define LINKTYPE_USER15   162
 

Definition at line 319 of file savefile.c.

#define LINKTYPE_USER2   149
 

Definition at line 306 of file savefile.c.

#define LINKTYPE_USER3   150
 

Definition at line 307 of file savefile.c.

#define LINKTYPE_USER4   151
 

Definition at line 308 of file savefile.c.

#define LINKTYPE_USER5   152
 

Definition at line 309 of file savefile.c.

#define LINKTYPE_USER6   153
 

Definition at line 310 of file savefile.c.

#define LINKTYPE_USER7   154
 

Definition at line 311 of file savefile.c.

#define LINKTYPE_USER8   155
 

Definition at line 312 of file savefile.c.

#define LINKTYPE_USER9   156
 

Definition at line 313 of file savefile.c.

#define SFERR_BADF   3
 

Definition at line 88 of file savefile.c.

#define SFERR_BADVERSION   2
 

Definition at line 87 of file savefile.c.

#define SFERR_EOF   4 /* not really an error, just a status */
 

Definition at line 89 of file savefile.c.

#define SFERR_TRUNC   1
 

Definition at line 86 of file savefile.c.

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

Definition at line 81 of file savefile.c.

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

Definition at line 83 of file savefile.c.

Referenced by swap_hdr().

#define TCPDUMP_MAGIC   0xa1b2c3d4
 

Definition at line 55 of file savefile.c.


Function Documentation

int dlt_to_linktype int  dlt  )  [static]
 

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

References linktype_map::dlt, linktype_map::linktype, and map.

Referenced by pcap_open_offline().

FILE* pcap_dump_file pcap_dumper_t p  ) 
 

Definition at line 1078 of file savefile.c.

int pcap_dump_flush pcap_dumper_t p  ) 
 

Definition at line 1084 of file savefile.c.

int pcap_offline_read pcap_t p,
int  cnt,
pcap_handler  callback,
u_char *  user
 

Definition at line 938 of file savefile.c.

References pcap_pkthdr::caplen, pcap_pkthdr::len, 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().

void sf_close pcap_t p  )  [static]
 

Definition at line 608 of file savefile.c.

Referenced by pcap_open_offline().

int sf_getnonblock pcap_t p,
char *  errbuf
[static]
 

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

References bpf_u_int32, pcap_pkthdr::caplen, pcap_pkthdr::len, PCAP_ERRBUF_SIZE, pcap_strerror(), snprintf, SWAPLONG, and pcap_pkthdr::ts.

Referenced by pcap_offline_read().

int sf_setnonblock pcap_t p,
int  nonblock,
char *  errbuf
[static]
 

Definition at line 590 of file savefile.c.

Referenced by pcap_open_offline().

int sf_stats pcap_t p,
struct pcap_stat ps
[static]
 

Definition at line 600 of file savefile.c.

References PCAP_ERRBUF_SIZE, and snprintf.

Referenced by pcap_open_offline().

int sf_write_header FILE *  fp,
int  linktype,
int  thiszone,
int  snaplen
[static]
 

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

References pcap_file_header::linktype, pcap_file_header::sigfigs, pcap_file_header::snaplen, SWAPLONG, 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.92.2.12 2004/08/17 17:56:27 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.