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