Assume all AT_NONE addresses are the same, as they have no address data
[obnox/wireshark/wip.git] / epan / packet_info.h
1 /* packet_info.h
2  * Definitions for packet info structures and routines
3  *
4  * $Id: packet_info.h,v 1.31 2003/02/28 20:30:06 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __PACKET_INFO_H__
26 #define __PACKET_INFO_H__
27
28 #include "frame_data.h"
29 #include "tvbuff.h"
30
31 /* Types of addresses Ethereal knows about. */
32 typedef enum {
33   AT_NONE,              /* no link-layer address */
34   AT_ETHER,             /* MAC (Ethernet, 802.x, FDDI) address */
35   AT_IPv4,              /* IPv4 */
36   AT_IPv6,              /* IPv6 */
37   AT_IPX,               /* IPX */
38   AT_SNA,               /* SNA */
39   AT_ATALK,             /* Appletalk DDP */
40   AT_VINES,             /* Banyan Vines */
41   AT_OSI,               /* OSI NSAP */
42   AT_ARCNET,            /* ARCNET */
43   AT_FC                 /* Fibre Channel */
44 } address_type;
45
46 typedef struct _address {
47   address_type  type;           /* type of address */
48   int           len;            /* length of address, in bytes */
49   const guint8 *data;           /* bytes that constitute address */
50 } address;
51
52 #define SET_ADDRESS(addr, addr_type, addr_len, addr_data) { \
53         (addr)->type = (addr_type); \
54         (addr)->len = (addr_len); \
55         (addr)->data = (addr_data); \
56         }
57
58 /*
59  * Given two addresses, return
60  *  0 if the addresses are equal,
61  *  a positive number if addr1>addr2 in some nondefined metric,
62  *  a negative number if addr1<addr2 in some nondefined metric
63  */
64 #define CMP_ADDRESS(addr1, addr2) \
65         (       ((addr1)->type > (addr2)->type)?1:      \
66                 ((addr1)->type < (addr2)->type)?-1:     \
67                 ((addr1)->len  > (addr2)->len) ?1:      \
68                 ((addr1)->len  < (addr2)->len) ?-1:     \
69                 memcmp((addr1)->data, (addr2)->data, (addr1)->len)\
70         )
71
72 /*
73  * Given two addresses, return "true" if they're equal, "false" otherwise.
74  * Addresses are equal only if they have the same type; if the type is
75  * AT_NONE, they are then equal, otherwise they must have the same
76  * amount of data and the data must be the same.
77  */
78 #define ADDRESSES_EQUAL(addr1, addr2)                                   \
79         (                                                               \
80          (addr1)->type == (addr2)->type &&                              \
81          (                                                              \
82           (addr1)->type == AT_NONE ||                                   \
83           (                                                             \
84            (addr1)->len == (addr2)->len &&                              \
85            memcmp((addr1)->data, (addr2)->data, (addr1)->len) == 0      \
86           )                                                             \
87          )                                                              \
88         )
89
90 /*
91  * Copy an address, allocating a new buffer for the address data.
92  */
93 #define COPY_ADDRESS(to, from) { \
94         guint8 *COPY_ADDRESS_data; \
95         (to)->type = (from)->type; \
96         (to)->len = (from)->len; \
97         COPY_ADDRESS_data = g_malloc((from)->len); \
98         memcpy(COPY_ADDRESS_data, (from)->data, (from)->len); \
99         (to)->data = COPY_ADDRESS_data; \
100         }
101
102 /* Types of port numbers Ethereal knows about. */
103 typedef enum {
104   PT_NONE,              /* no port number */
105   PT_SCTP,              /* SCTP */
106   PT_TCP,               /* TCP */
107   PT_UDP,               /* UDP */
108   PT_IPX,               /* IPX sockets */
109   PT_NCP,               /* NCP connection */
110   PT_EXCHG,     /* Fibre Channel exchange */
111   PT_DDP                /* DDP AppleTalk connection */
112 } port_type;
113
114 /* Types of circuit IDs Ethereal knows about. */
115 typedef enum {
116   CT_NONE,              /* no port number */
117   CT_DLCI,              /* Frame Relay DLCI */
118   CT_ISDN,              /* ISDN channel number */
119   CT_X25                /* X.25 logical channel number */
120   /* Could also have ATM VPI/VCI pairs */
121 } circuit_type;
122
123 #define P2P_DIR_UNKNOWN -1
124 #define P2P_DIR_SENT    0
125 #define P2P_DIR_RECV    1
126
127 typedef struct _packet_info {
128   const char *current_proto;    /* name of protocol currently being dissected */
129   column_info *cinfo;           /* Column formatting information */
130   frame_data *fd;
131   union wtap_pseudo_header *pseudo_header;
132   GSList *data_src;             /* Frame data sources */
133   address dl_src;               /* link-layer source address */
134   address dl_dst;               /* link-layer destination address */
135   address net_src;              /* network-layer source address */
136   address net_dst;              /* network-layer destination address */
137   address src;                  /* source address (net if present, DL otherwise )*/
138   address dst;                  /* destination address (net if present, DL otherwise )*/
139   guint32 ethertype;            /* Ethernet Type Code, if this is an Ethernet packet */
140   guint32 ipproto;              /* IP protocol, if this is an IP packet */
141   guint32 ipxptype;             /* IPX packet type, if this is an IPX packet */
142   circuit_type ctype;           /* type of circuit, for protocols with a VC identifier */
143   guint32 circuit_id;           /* circuit ID, for protocols with a VC identifier */
144   char   *noreassembly_reason;  /* reason why reassembly wasn't done, if any */
145   gboolean fragmented;          /* TRUE if the protocol is only a fragment */
146   gboolean in_error_pkt;        /* TRUE if we're inside an {ICMP,CLNP,...} error packet */
147   port_type ptype;              /* type of the following two port numbers */
148   guint32 srcport;              /* source port */
149   guint32 destport;             /* destination port */
150   guint32 match_port;
151   guint16 can_desegment;        /* >0 if this segment could be desegmented.
152                                    A dissector that can offer this API (e.g. TCP)
153                                    sets can_desegment=2, then can_desegment is
154                                    decremented by 1 each time we pass to the next
155                                    subdissector. Thus only the dissector immediately
156                                    above the protocol which sets the flag can use it*/
157   int desegment_offset;         /* offset of stuff needing desegmentation */
158   guint32 desegment_len;        /* requested desegmentation additional length */
159   int     iplen;
160   int     iphdrlen;
161   int     p2p_dir;
162   guint16 oxid;                 /* next 2 fields reqd to identify fibre */
163   guint16 rxid;                 /* channel conversations */
164   guint8  r_ctl;                /* R_CTL field in Fibre Channel Protocol */
165   guint8  pad;
166   guint16 src_idx;              /* Source port index (Cisco MDS-specific) */
167   guint16 dst_idx;              /* Dest port index (Cisco MDS-specific) */
168   guint16 vsan;                 /* Fibre channel/Cisco MDS-specific */
169   void    *private_data;        /* pointer to data passed from one dissector to another */
170   void    *decrypted_data;      /* pointer to description of decrypted payload structure */
171 } packet_info;
172
173 #endif /* __PACKET_INFO_H__ */