"This file format can't be written to a pipe" and "this file format
[obnox/wireshark/wip.git] / wiretap / libpcap.h
1 /* libpcap.h
2  *
3  * $Id$
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  */
22
23 #ifndef __W_LIBPCAP_H__
24 #define __W_LIBPCAP_H__
25
26 /* Magic numbers in "libpcap" files.
27
28    "libpcap" file records are written in the byte order of the host that
29    writes them, and the reader is expected to fix this up.
30
31    PCAP_MAGIC is the magic number, in host byte order; PCAP_SWAPPED_MAGIC
32    is a byte-swapped version of that.
33
34    PCAP_MODIFIED_MAGIC is for Alexey Kuznetsov's modified "libpcap"
35    format, as generated on Linux systems that have a "libpcap" with
36    his patches, at
37
38         http://ftp.sunet.se/pub/os/Linux/ip-routing/lbl-tools/
39
40    applied; PCAP_SWAPPED_MODIFIED_MAGIC is the byte-swapped version. 
41
42    PCAP_NSEC_MAGIC is for Ulf Lamping's modified "libpcap" format,
43    which uses the same common file format as PCAP_MAGIC, but the 
44    timestamps are saved in nanosecond resolution instead of microseconds.
45    PCAP_SWAPPED_NSEC_MAGIC is a byte-swapped version of that. */
46 #define PCAP_MAGIC                      0xa1b2c3d4
47 #define PCAP_SWAPPED_MAGIC              0xd4c3b2a1
48 #define PCAP_MODIFIED_MAGIC             0xa1b2cd34
49 #define PCAP_SWAPPED_MODIFIED_MAGIC     0x34cdb2a1
50 #define PCAP_NSEC_MAGIC                 0xa1b23c4d
51 #define PCAP_SWAPPED_NSEC_MAGIC         0x4d3cb2a1
52
53 /* "libpcap" file header (minus magic number). */
54 struct pcap_hdr {
55         guint16 version_major;  /* major version number */
56         guint16 version_minor;  /* minor version number */
57         gint32  thiszone;       /* GMT to local correction */
58         guint32 sigfigs;        /* accuracy of timestamps */
59         guint32 snaplen;        /* max length of captured packets, in octets */
60         guint32 network;        /* data link type */
61 };
62
63 /* "libpcap" record header. */
64 struct pcaprec_hdr {
65         guint32 ts_sec;         /* timestamp seconds */
66         guint32 ts_usec;        /* timestamp microseconds (nsecs for PCAP_NSEC_MAGIC) */
67         guint32 incl_len;       /* number of octets of packet saved in file */
68         guint32 orig_len;       /* actual length of packet */
69 };
70
71 /* "libpcap" record header for Alexey's patched version. */
72 struct pcaprec_modified_hdr {
73         struct pcaprec_hdr hdr; /* the regular header */
74         guint32 ifindex;        /* index, in *capturing* machine's list of
75                                    interfaces, of the interface on which this
76                                    packet came in. */
77         guint16 protocol;       /* Ethernet packet type */
78         guint8 pkt_type;        /* broadcast/multicast/etc. indication */
79         guint8 pad;             /* pad to a 4-byte boundary */
80 };
81
82 /* "libpcap" record header for Alexey's patched version in its ss990915
83    incarnation; this version shows up in SuSE Linux 6.3. */
84 struct pcaprec_ss990915_hdr {
85         struct pcaprec_hdr hdr; /* the regular header */
86         guint32 ifindex;        /* index, in *capturing* machine's list of
87                                    interfaces, of the interface on which this
88                                    packet came in. */
89         guint16 protocol;       /* Ethernet packet type */
90         guint8 pkt_type;        /* broadcast/multicast/etc. indication */
91         guint8 cpu1, cpu2;      /* SMP debugging gunk? */
92         guint8 pad[3];          /* pad to a 4-byte boundary */
93 };
94
95 /* "libpcap" record header for version used on some Nokia boxes (firewalls?) */
96 struct pcaprec_nokia_hdr {
97         struct pcaprec_hdr hdr; /* the regular header */
98         guint8 stuff[4];        /* mysterious stuff */
99 };
100
101 int libpcap_open(wtap *wth, int *err, gchar **err_info);
102 gboolean libpcap_dump_open(wtap_dumper *wdh, int *err);
103 int libpcap_dump_can_write_encap(int encap);
104
105 #endif