The Sniffer-reading code now checks to make sure that it is trying
[obnox/wireshark/wip.git] / wiretap / wtap.h
1 /* wtap.h
2  *
3  * $Id: wtap.h,v 1.5 1998/11/15 05:29:17 guy Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.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
24 /* Encapsulation types */
25 #define WTAP_ENCAP_NONE                         0
26 #define WTAP_ENCAP_ETHERNET                     1
27 #define WTAP_ENCAP_TR                           2
28 #define WTAP_ENCAP_SLIP                         3
29 #define WTAP_ENCAP_PPP                          4
30 #define WTAP_ENCAP_FDDI                         5
31 #define WTAP_ENCAP_RAW_IP                       6
32 #define WTAP_ENCAP_ARCNET                       7
33
34 /* File types that can be read by wiretap */
35 #define WTAP_FILE_UNKNOWN                       0
36 #define WTAP_FILE_WTAP                          1
37 #define WTAP_FILE_PCAP                          2
38 #define WTAP_FILE_LANALYZER                     3
39 #define WTAP_FILE_NGSNIFFER                     4
40 #define WTAP_FILE_SNOOP                         6
41 #define WTAP_FILE_IPTRACE                       7
42
43 #include <sys/types.h>
44 #include <sys/time.h>
45 #include <glib.h>
46 #include <stdio.h>
47 #include <buffer.h>
48
49 typedef struct {
50         guint16 pkt_len;
51         double  timeunit;
52 } ngsniffer_t;
53
54 typedef struct {
55         guint16 pkt_len;
56         guint32 totpktt;
57 } lanalyzer_t;
58
59 typedef struct {
60         int     byte_swapped;
61         guint16 version_major;
62         guint16 version_minor;
63 } libpcap_t;
64
65 struct wtap_pkthdr {
66         struct timeval ts;
67         guint32 caplen;
68         guint32 len;
69 };
70
71 typedef void (*wtap_handler)(u_char*, const struct wtap_pkthdr*,
72                 int, const u_char *);
73
74 struct wtap;
75 typedef int (*subtype_func)(struct wtap*);
76 typedef struct wtap {
77         FILE*                   fh;
78         int                             file_type;
79         int             snapshot_length;
80         unsigned long   frame_number;
81         unsigned long   file_byte_offset;
82         Buffer                  frame_buffer;
83         struct wtap_pkthdr      phdr;
84
85         union {
86                 libpcap_t               *pcap;
87                 lanalyzer_t             *lanalyzer;
88                 ngsniffer_t             *ngsniffer;
89         } capture;
90
91         subtype_func    subtype_read;   
92         int                             encapsulation;
93 } wtap;
94
95
96 wtap* wtap_open_offline(char *filename, int filetype);
97 void wtap_loop(wtap *wth, int, wtap_handler, u_char*);
98
99 FILE* wtap_file(wtap *wth);
100 int wtap_snapshot_length(wtap *wth); /* per file */
101 int wtap_file_type(wtap *wth);
102 int wtap_encapsulation(wtap *wth); /* per file */
103 void wtap_close(wtap *wth);
104
105
106 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
107  * byte array, returns the value of the two or four bytes at the pointer.
108  * The pletoh[sl] versions return the little-endian representation.
109  */
110
111 #define pntohs(p)  ((guint16)                       \
112                     ((guint16)*((guint8 *)p+0)<<8|  \
113                      (guint16)*((guint8 *)p+1)<<0))
114
115 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
116                     (guint32)*((guint8 *)p+1)<<16|  \
117                     (guint32)*((guint8 *)p+2)<<8|   \
118                     (guint32)*((guint8 *)p+3)<<0)
119
120 #define pletohs(p) ((guint16)                       \
121                     ((guint16)*((guint8 *)p+1)<<8|  \
122                      (guint16)*((guint8 *)p+0)<<0))
123
124 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
125                     (guint32)*((guint8 *)p+2)<<16|  \
126                     (guint32)*((guint8 *)p+1)<<8|   \
127                     (guint32)*((guint8 *)p+0)<<0)
128
129
130
131 #define DLT_NULL        0       /* no link-layer encapsulation */
132 #define DLT_EN10MB      1       /* Ethernet (10Mb) */
133 #define DLT_EN3MB       2       /* Experimental Ethernet (3Mb) */
134 #define DLT_AX25        3       /* Amateur Radio AX.25 */
135 #define DLT_PRONET      4       /* Proteon ProNET Token Ring */
136 #define DLT_CHAOS       5       /* Chaos */
137 #define DLT_IEEE802     6       /* IEEE 802 Networks */
138 #define DLT_ARCNET      7       /* ARCNET */
139 #define DLT_SLIP        8       /* Serial Line IP */
140 #define DLT_PPP         9       /* Point-to-point Protocol */
141 #define DLT_FDDI        10      /* FDDI */
142 #define DLT_ATM_RFC1483 11      /* LLC/SNAP encapsulated atm */
143 #define DLT_RAW         12      /* raw IP */
144 #define DLT_SLIP_BSDOS  13      /* BSD/OS Serial Line IP */
145 #define DLT_PPP_BSDOS   14      /* BSD/OS Point-to-point Protocol */