Frame numbers are unsigned.
[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.21 2003/02/04 20:16:57 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 #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 "ipproto.h"
36 #include <epan/packet.h>
37 #include <epan/resolv.h>
38 #include "packet-ip.h"
39
40 #ifdef NEED_SNPRINTF_H
41 # include "snprintf.h"
42 #endif
43
44 static const value_string ipproto_val[] = {
45     { IP_PROTO_ICMP,    "ICMP" },
46     { IP_PROTO_IGMP,    "IGMP" },
47     { IP_PROTO_EIGRP,   "EIGRP" },
48     { IP_PROTO_IGRP,    "IGRP" },
49     { IP_PROTO_TCP,     "TCP" },
50     { IP_PROTO_UDP,     "UDP" },
51     { IP_PROTO_OSPF,    "OSPF" },
52 #if 0
53     { IP_PROTO_IP,      "IPv4" },
54 #endif
55     { IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" },
56     { IP_PROTO_ICMP,    "ICMP" },
57     { IP_PROTO_IGMP,    "IGMP" },
58     { IP_PROTO_GGP,     "GGP" },
59     { IP_PROTO_IPIP,    "IPIP" },
60 #if 0
61     { IP_PROTO_IPV4,    "IPv4" },
62 #endif
63     { IP_PROTO_EGP,     "EGP" },
64     { IP_PROTO_PUP,     "PUP" },
65     { IP_PROTO_UDP,     "UDP" },
66     { IP_PROTO_IDP,     "IDP" },
67     { IP_PROTO_TP,      "TP" },
68     { IP_PROTO_IPV6,    "IPv6" },
69     { IP_PROTO_ROUTING, "IPv6 routing" },
70     { IP_PROTO_FRAGMENT,"IPv6 fragment" },
71     { IP_PROTO_RSVP,    "RSVP" },
72     { IP_PROTO_GRE,     "GRE" },
73     { IP_PROTO_ESP,     "ESP" },
74     { IP_PROTO_AH,      "AH" },
75     { IP_PROTO_ICMPV6,  "ICMPv6" },
76     { IP_PROTO_NONE,    "IPv6 no next header" },
77     { IP_PROTO_DSTOPTS, "IPv6 destination option" },
78     { IP_PROTO_MIPV6,   "Mobile IPv6" },
79     { IP_PROTO_EON,     "EON" },
80     { IP_PROTO_OSPF,    "OSPF" },
81     { IP_PROTO_ENCAP,   "ENCAP" },
82     { IP_PROTO_PIM,     "PIM" },
83     { IP_PROTO_IPCOMP,  "IPComp" },
84     { IP_PROTO_VRRP,    "VRRP" },
85     { IP_PROTO_VINES,   "VINES" },
86     { IP_PROTO_PGM,     "PGM" },
87     { IP_PROTO_SCTP,    "SCTP" },
88     { 0,                NULL },
89 };
90
91 const char *ipprotostr(int proto) {
92     static char buf[128];
93     const char *s;
94 #ifdef HAVE_GETPROTOBYNUMBER
95     struct protoent *pe;
96 #endif
97
98     if ((s = match_strval(proto, ipproto_val)) != NULL)
99         goto ok;
100
101 #ifdef HAVE_GETPROTOBYNUMBER
102     /*
103      * XXX - have another flag for resolving network-layer
104      * protocol names?
105      */
106     if (g_resolv_flags != 0) {
107         pe = getprotobynumber(proto);
108         if (pe) {
109             s = pe->p_name;
110             goto ok;
111         }
112     }
113 #endif
114
115     s = "Unknown";
116
117 ok:
118     snprintf(buf, sizeof(buf), "%s", s);
119     return buf;
120 }