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