289530f0881569bd7cb8b21fca1afe0aa2b2708e
[obnox/wireshark/wip.git] / epan / ipproto.c
1 /* ipproto.c
2  * Routines for converting IPv4 protocol/IPv6 nxthdr field into string
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef HAVE_NETDB_H
30 # include <netdb.h>
31 #endif
32
33 #include <glib.h>
34
35 #include <epan/packet.h>
36 #include <epan/ipproto.h>
37 #include <epan/addr_resolv.h>
38 #include <epan/dissectors/packet-ip.h>
39 #include <epan/strutil.h>
40
41 const value_string ipproto_val[] = {
42 #if 0
43     { IP_PROTO_IP,      "IPv4" },
44 #endif
45     { IP_PROTO_TCP,     "TCP" },
46     { IP_PROTO_UDP,     "UDP" },
47     { IP_PROTO_RDP,     "Reliable Data" },
48
49     { IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" },
50     { IP_PROTO_ICMP,    "ICMP" },
51     { IP_PROTO_IGMP,    "IGMP" },
52     { IP_PROTO_GGP,     "GGP" },
53     { IP_PROTO_IPIP,    "IPIP" },
54 #if 0
55     { IP_PROTO_IPV4,    "IPv4" },
56 #endif
57     { IP_PROTO_STREAM,  "Stream" },
58     { IP_PROTO_CBT,     "CBT" },
59     { IP_PROTO_EGP,     "EGP" },
60     { IP_PROTO_IGP,     "IGRP" },
61     { IP_PROTO_BBN_RCC, "BBN RCC" },
62     { IP_PROTO_NVPII,   "Network Voice" },
63     { IP_PROTO_PUP,     "PUP" },
64     { IP_PROTO_ARGUS,   "ARGUS" },
65     { IP_PROTO_EMCON,   "EMCON" },
66     { IP_PROTO_XNET,    "XNET" },
67     { IP_PROTO_CHAOS,   "CHAOS" },
68     { IP_PROTO_MUX,     "Multiplex" },
69     { IP_PROTO_DCNMEAS, "DCN Measurement" },
70     { IP_PROTO_HMP,     "Host Monitoring" },
71     { IP_PROTO_PRM,     "Packet radio" },
72     { IP_PROTO_IDP,     "IDP" },
73     { IP_PROTO_TRUNK1,  "Trunk-1" },
74     { IP_PROTO_TRUNK2,  "Trunk-2" },
75     { IP_PROTO_LEAF1,   "Leaf-1" },
76     { IP_PROTO_LEAF2,   "Leaf-2" },
77     { IP_PROTO_IRT,     "IRT" },
78     { IP_PROTO_TP,      "ISO TP4" },
79     { IP_PROTO_BULK,    "Bulk Data" },
80     { IP_PROTO_MFE_NSP, "MFE NSP" },
81     { IP_PROTO_MERIT,   "Merit Internodal" },
82     { IP_PROTO_DCCP,    "Datagram Congestion Control Protocol" },
83     { IP_PROTO_3PC,     "3rd Party Connect" },
84     { IP_PROTO_IDPR,    "Interdomain routing" },
85     { IP_PROTO_XTP,     "XTP" },
86     { IP_PROTO_DDP,     "Datagram delivery"},
87     { IP_PROTO_CMTP,    "Control Message" },
88     { IP_PROTO_TPPP,    "TP++" },
89     { IP_PROTO_IL,      "IL" },
90     { IP_PROTO_IPV6,    "IPv6" },
91     { IP_PROTO_SDRP,    "Source demand routing" },
92     { IP_PROTO_ROUTING, "IPv6 routing" },
93     { IP_PROTO_FRAGMENT,"IPv6 fragment" },
94     { IP_PROTO_IDRP,    "IDRP" },
95     { IP_PROTO_RSVP,    "RSVP" },
96     { IP_PROTO_GRE,     "GRE" },
97     { IP_PROTO_DSR,     "Dynamic source routing" },
98     { IP_PROTO_BNA,     "BNA" },
99     { IP_PROTO_ESP,     "ESP" },
100     { IP_PROTO_AH,      "AH" },
101     { IP_PROTO_INSLP,   "INSLP" },
102     { IP_PROTO_SWIPE,   "SWIPE" },
103     { IP_PROTO_NARP,    "NBMA ARP"},
104     { IP_PROTO_TLSP,    "TLSP Kryptonet" },
105     { IP_PROTO_SKIP,    "SKIP" },
106     { IP_PROTO_ICMPV6,  "ICMPv6" },
107     { IP_PROTO_NONE,    "IPv6 no next header" },
108     { IP_PROTO_DSTOPTS, "IPv6 destination option" },
109     { IP_PROTO_SHIM6_OLD, "SHIM6 header" },
110     { IP_PROTO_MIPV6_OLD, "Mobile IPv6 (old)" },
111     { IP_PROTO_SATEXPAK,"SATNET EXPAK" },
112     { IP_PROTO_KRYPTOLAN, "Kryptolan" },
113     { IP_PROTO_RVD,     "Remote Virtual Disk" },
114     { IP_PROTO_IPPC,    "IPPC" },
115     { IP_PROTO_SATMON,  "SATNET Monitoring" },
116     { IP_PROTO_VISA,    "VISA" },
117     { IP_PROTO_IPCV,    "IPCV" },
118     { IP_PROTO_CPNX,    "CPNX" },
119     { IP_PROTO_CPHB,    "CPHB" },
120     { IP_PROTO_WSN,     "Wang Span" },
121     { IP_PROTO_PVP,     "Packet Video" },
122     { IP_PROTO_BRSATMON,"Backroom SATNET Mon" },
123     { IP_PROTO_SUNND,   "Sun ND Protocol" },
124     { IP_PROTO_WBMON,   "Wideband Mon" },
125     { IP_PROTO_WBEXPAK, "Wideband Expak" },
126     { IP_PROTO_ISOIP,   "ISO Internet Protocol" },
127     { IP_PROTO_VMTP,    "VMTP" },
128     { IP_PROTO_SVMTP,   "Secure VMTP" },
129     { IP_PROTO_VINES,   "VINES" },
130     { IP_PROTO_TTP,     "TTP" },
131     { IP_PROTO_NSFNETIGP,"NSFNET IGP" },
132     { IP_PROTO_DGP,     "Dissimilar Gateway" },
133     { IP_PROTO_TCF,     "TCF" },
134     { IP_PROTO_EIGRP,   "EIGRP" },
135     { IP_PROTO_OSPF,    "OSPF IGP" },
136     { IP_PROTO_SPRITE,  "Sprite RPC" },
137     { IP_PROTO_LARP,    "Locus ARP" },
138     { IP_PROTO_MTP,     "Multicast Transport" },
139     { IP_PROTO_AX25,    "AX.25 Frames" },
140     { IP_PROTO_IPINIP,  "IP in IP" },
141     { IP_PROTO_MICP,    "MICP" },
142     { IP_PROTO_SCCCP,   "Semaphore" },
143     { IP_PROTO_ETHERIP, "Ether in IP" },
144     { IP_PROTO_ENCAP,   "ENCAP" },
145     { IP_PROTO_GMTP,    "GMTP" },
146     { IP_PROTO_IFMP,    "Ipsilon Flow" },
147     { IP_PROTO_PNNI,    "PNNI over IP" },
148     { IP_PROTO_PIM,     "PIM" },
149     { IP_PROTO_ARIS,    "ARIS" },
150     { IP_PROTO_SCPS,    "SCPS" },
151     { IP_PROTO_QNX,     "QNX" },
152     { IP_PROTO_AN,      "Active Networks" },
153     { IP_PROTO_IPCOMP,  "IPComp" },
154     { IP_PROTO_SNP,     "Sitara Networks" },
155     { IP_PROTO_COMPAQ,  "Compaq Peer" },
156     { IP_PROTO_IPX,     "IPX IN IP" },
157     { IP_PROTO_VRRP,    "VRRP" },
158     { IP_PROTO_PGM,     "PGM" },
159     { IP_PROTO_L2TP,    "Layer 2 Tunneling" },
160     { IP_PROTO_DDX,     "DDX" },
161     { IP_PROTO_IATP,    "IATP" },
162     { IP_PROTO_STP,     "STP" },
163     { IP_PROTO_SRP,     "SpectraLink" },
164     { IP_PROTO_UTI,     "UTI" },
165     { IP_PROTO_SMP,     "SMP" },
166     { IP_PROTO_SM,      "SM" },
167     { IP_PROTO_PTP,     "PTP" },
168     { IP_PROTO_ISIS,    "ISIS over IP" },
169     { IP_PROTO_FIRE,    "FIRE" },
170     { IP_PROTO_CRTP,    "CRTP" },
171     { IP_PROTO_CRUDP,   "CRUDP" },
172     { IP_PROTO_SSCOPMCE,"SSCOPMCE" },
173     { IP_PROTO_IPLT,    "IPLT" },
174     { IP_PROTO_SPS,     "Secure Packet" },
175     { IP_PROTO_PIPE,    "PIPE" },
176     { IP_PROTO_SCTP,    "SCTP" },
177     { IP_PROTO_FC,      "Fibre Channel" },
178     { IP_PROTO_RSVPE2EI,"RSVP E2EI" },
179     { IP_PROTO_MIPV6,   "Mobile IPv6" },
180     { IP_PROTO_UDPLITE, "UDPlite" },
181     { IP_PROTO_MPLS_IN_IP, "MPLS in IP" },
182     { IP_PROTO_MANET,   "MANET" },
183     { IP_PROTO_HIP,     "HIP" },
184     { IP_PROTO_SHIM6,   "Shim6 header" },
185     { IP_PROTO_AX4000,  "AX/4000 Testframe" },
186     { IP_PROTO_NCS_HEARTBEAT,"Novell NCS Heartbeat" },
187     { 0,                NULL },
188 };
189
190 const char *ipprotostr(int proto) {
191     const char *s;
192
193     if ((s = match_strval(proto, ipproto_val)) != NULL)
194         return s;
195
196     s = "Unknown";
197
198 #ifdef HAVE_GETPROTOBYNUMBER
199     /*
200      * XXX - have another flag for resolving network-layer
201      * protocol names?
202      */
203     if (g_resolv_flags != 0) {
204         static char buf[128];
205         struct protoent *pe;
206         
207         pe = getprotobynumber(proto);
208         if (pe) {
209             g_strlcpy(buf, pe->p_name, sizeof(buf));
210             s = buf;
211         }
212     }
213 #endif
214     return s;
215 }