xDLC frames other than I and UI frames may have a payload, e.g. TEST
[obnox/wireshark/wip.git] / ipproto.c
1 /* ipproto.c
2  * Routines for converting IPv4 protocol/v6 nxthdr field into string
3  *
4  * $Id: ipproto.c,v 1.6 2000/01/22 06:22:12 guy Exp $
5  *
6  * Gilbert Ramirez <gram@xiexie.org>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #ifdef HAVE_NETDB_H
37 # include <netdb.h>
38 #endif
39
40 #ifdef NEED_SNPRINTF_H
41 # ifdef HAVE_STDARG_H
42 #  include <stdarg.h>
43 # else
44 #  include <varargs.h>
45 # endif
46 # include "snprintf.h"
47 #endif
48
49 #include <glib.h>
50
51 #ifndef __GLOBALS_H__
52 #include "globals.h"
53 #endif
54
55 #include "packet.h"
56 #include "etypes.h"
57 #include "packet-ip.h"
58 #include "packet-ipv6.h"
59
60 static const value_string ipproto_val[] = {
61     { IP_PROTO_ICMP,    "ICMP" },
62     { IP_PROTO_IGMP,    "IGMP" },
63     { IP_PROTO_TCP,     "TCP" },
64     { IP_PROTO_UDP,     "UDP" },
65     { IP_PROTO_OSPF,    "OSPF" },
66 #if 0
67     { IP_PROTO_IP,      "IPv4" },
68 #endif
69     { IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" },
70     { IP_PROTO_ICMP,    "ICMP" },
71     { IP_PROTO_IGMP,    "IGMP" },
72     { IP_PROTO_GGP,     "GGP" },
73     { IP_PROTO_IPIP,    "IPIP" },
74     { IP_PROTO_IPV4,    "IPv4" },
75     { IP_PROTO_TCP,     "TCP" },
76     { IP_PROTO_EGP,     "EGP" },
77     { IP_PROTO_PUP,     "PUP" },
78     { IP_PROTO_UDP,     "UDP" },
79     { IP_PROTO_IDP,     "IDP" },
80     { IP_PROTO_TP,      "TP" },
81     { IP_PROTO_IPV6,    "IPv6" },
82     { IP_PROTO_ROUTING, "IPv6 routing" },
83     { IP_PROTO_FRAGMENT,        "IPv6 fragment" },
84     { IP_PROTO_RSVP,    "RSVP" },
85     { IP_PROTO_GRE,     "GRE" },
86     { IP_PROTO_ESP,     "ESP" },
87     { IP_PROTO_AH,      "AH" },
88     { IP_PROTO_ICMPV6,  "ICMPv6" },
89     { IP_PROTO_NONE,    "IPv6 no next header" },
90     { IP_PROTO_DSTOPTS, "IPv6 dstination option" },
91     { IP_PROTO_EON,     "EON" },
92     { IP_PROTO_OSPF,    "OSPF" },
93     { IP_PROTO_ENCAP,   "ENCAP" },
94     { IP_PROTO_PIM,     "PIM" },
95     { IP_PROTO_IPCOMP,  "IPComp" },
96     { IP_PROTO_VRRP,    "VRRP" },
97     { 0,                NULL },
98 };
99
100 const char *ipprotostr(int proto) {
101     static char buf[128];
102     const char *s;
103 #ifdef HAVE_GETPROTOBYNUMBER
104     struct protoent *pe;
105 #endif
106
107     if ((s = match_strval(proto, ipproto_val)) != NULL)
108         goto ok;
109
110 #ifdef HAVE_GETPROTOBYNUMBER
111     if (g_resolving_actif) {
112         pe = getprotobynumber(proto);
113         if (pe) {
114             s = pe->p_name;
115             goto ok;
116         }
117     }
118 #endif
119
120     s = "Unknown";
121
122 ok:
123     snprintf(buf, sizeof(buf), "%s", s);
124     return buf;
125 }