Add HP Switch Protocol SAP value
[obnox/wireshark/wip.git] / epan / address.h
1 /* address.h
2  * Definitions for structures storing addresses, and for the type of
3  * variables holding port-type values
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __ADDRESS_H__
27 #define __ADDRESS_H__
28
29 /* Types of addresses Wireshark knows about. */
30 /* If a new address type is added here, a string representation procedure should */
31 /* also be included in address_to_str_buf defined in to_str.c, for presentation purposes */
32
33 typedef enum {
34   AT_NONE,              /* no link-layer address */
35   AT_ETHER,             /* MAC (Ethernet, 802.x, FDDI) address */
36   AT_IPv4,              /* IPv4 */
37   AT_IPv6,              /* IPv6 */
38   AT_IPX,               /* IPX */
39   AT_SNA,               /* SNA */
40   AT_ATALK,             /* Appletalk DDP */
41   AT_VINES,             /* Banyan Vines */
42   AT_OSI,               /* OSI NSAP */
43   AT_ARCNET,    /* ARCNET */
44   AT_FC,                /* Fibre Channel */
45   AT_SS7PC,             /* SS7 Point Code */
46   AT_STRINGZ,   /* null-terminated string */
47   AT_EUI64,             /* IEEE EUI-64 */
48   AT_URI,               /* URI/URL/URN */
49   AT_TIPC,              /* TIPC Address Zone,Subnetwork,Processor */
50   AT_USB                /* USB Device address 
51                          * (0xffffffff represents the host) */
52 } address_type;
53
54 typedef struct _address {
55   address_type  type;           /* type of address */
56   int           len;            /* length of address, in bytes */
57   const guint8 *data;           /* bytes that constitute address */
58 } address;
59
60 #define SET_ADDRESS(addr, addr_type, addr_len, addr_data) { \
61         (addr)->type = (addr_type); \
62         (addr)->len = (addr_len); \
63         (addr)->data = (void *)(addr_data); \
64         }
65
66 /*
67  * Given two addresses, return
68  *  0 if the addresses are equal,
69  *  a positive number if addr1>addr2 in some nondefined metric,
70  *  a negative number if addr1<addr2 in some nondefined metric
71  */
72 #define CMP_ADDRESS(addr1, addr2) \
73         (       ((addr1)->type > (addr2)->type)?1:      \
74                 ((addr1)->type < (addr2)->type)?-1:     \
75                 ((addr1)->len  > (addr2)->len) ?1:      \
76                 ((addr1)->len  < (addr2)->len) ?-1:     \
77                 memcmp((addr1)->data, (addr2)->data, (addr1)->len)\
78         )
79
80 /*
81  * Given two addresses, return "true" if they're equal, "false" otherwise.
82  * Addresses are equal only if they have the same type; if the type is
83  * AT_NONE, they are then equal, otherwise they must have the same
84  * amount of data and the data must be the same.
85  */
86 #define ADDRESSES_EQUAL(addr1, addr2)                                   \
87         (                                                               \
88          (addr1)->type == (addr2)->type &&                              \
89          (                                                              \
90           (addr1)->type == AT_NONE ||                                   \
91           (                                                             \
92            (addr1)->len == (addr2)->len &&                              \
93            memcmp((addr1)->data, (addr2)->data, (addr1)->len) == 0      \
94           )                                                             \
95          )                                                              \
96         )
97
98 /*
99  * Copy an address, allocating a new buffer for the address data.
100  */
101 #define COPY_ADDRESS(to, from) { \
102         guint8 *COPY_ADDRESS_data; \
103         (to)->type = (from)->type; \
104         (to)->len = (from)->len; \
105         COPY_ADDRESS_data = g_malloc((from)->len); \
106         memcpy(COPY_ADDRESS_data, (from)->data, (from)->len); \
107         (to)->data = COPY_ADDRESS_data; \
108         }
109
110 /* Types of port numbers Wireshark knows about. */
111 typedef enum {
112   PT_NONE,              /* no port number */
113   PT_SCTP,              /* SCTP */
114   PT_TCP,               /* TCP */
115   PT_UDP,               /* UDP */
116   PT_DCCP,              /* DCCP */
117   PT_IPX,               /* IPX sockets */
118   PT_NCP,               /* NCP connection */
119   PT_EXCHG,             /* Fibre Channel exchange */
120   PT_DDP,               /* DDP AppleTalk connection */
121   PT_SBCCS,             /* FICON */
122   PT_IDP,               /* XNS IDP sockets */
123   PT_TIPC,              /* TIPC PORT */
124   PT_USB                /* USB endpoint 0xffff means the host */
125 } port_type;
126
127 /* Types of circuit IDs Wireshark knows about. */
128 typedef enum {
129   CT_NONE,              /* no circuit type */
130   CT_DLCI,              /* Frame Relay DLCI */
131   CT_ISDN,              /* ISDN channel number */
132   CT_X25,               /* X.25 logical channel number */
133   CT_ISUP,              /* ISDN User Part CIC */
134   CT_IAX2,              /* IAX2 call id */
135   CT_H223,              /* H.223 logical channel number */
136   CT_BICC               /* BICC Circuit identifier */
137   /* Could also have ATM VPI/VCI pairs */
138 } circuit_type;
139
140 #endif /* __ADDRESS_H__ */
141