Give the code that computes protocol statistics a progress dialog box,
[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.10 2001/03/05 20:11:36 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 #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,   "EIGRP" },
57     { IP_PROTO_IGRP,    "IGRP" },
58     { IP_PROTO_TCP,     "TCP" },
59     { IP_PROTO_UDP,     "UDP" },
60     { IP_PROTO_OSPF,    "OSPF" },
61 #if 0
62     { IP_PROTO_IP,      "IPv4" },
63 #endif
64     { IP_PROTO_HOPOPTS, "IPv6 hop-by-hop option" },
65     { IP_PROTO_ICMP,    "ICMP" },
66     { IP_PROTO_IGMP,    "IGMP" },
67     { IP_PROTO_GGP,     "GGP" },
68     { IP_PROTO_IPIP,    "IPIP" },
69 #if 0
70     { IP_PROTO_IPV4,    "IPv4" },
71 #endif
72     { IP_PROTO_EGP,     "EGP" },
73     { IP_PROTO_PUP,     "PUP" },
74     { IP_PROTO_UDP,     "UDP" },
75     { IP_PROTO_IDP,     "IDP" },
76     { IP_PROTO_TP,      "TP" },
77     { IP_PROTO_IPV6,    "IPv6" },
78     { IP_PROTO_ROUTING, "IPv6 routing" },
79     { IP_PROTO_FRAGMENT,"IPv6 fragment" },
80     { IP_PROTO_RSVP,    "RSVP" },
81     { IP_PROTO_GRE,     "GRE" },
82     { IP_PROTO_ESP,     "ESP" },
83     { IP_PROTO_AH,      "AH" },
84     { IP_PROTO_ICMPV6,  "ICMPv6" },
85     { IP_PROTO_NONE,    "IPv6 no next header" },
86     { IP_PROTO_DSTOPTS, "IPv6 destination option" },
87     { IP_PROTO_EON,     "EON" },
88     { IP_PROTO_OSPF,    "OSPF" },
89     { IP_PROTO_ENCAP,   "ENCAP" },
90     { IP_PROTO_PIM,     "PIM" },
91     { IP_PROTO_IPCOMP,  "IPComp" },
92     { IP_PROTO_VRRP,    "VRRP" },
93     { IP_PROTO_VINES,   "VINES" },
94     { IP_PROTO_SCTP,    "SCTP" },
95     { 0,                NULL },
96 };
97
98 const char *ipprotostr(int proto) {
99     static char buf[128];
100     const char *s;
101 #ifdef HAVE_GETPROTOBYNUMBER
102     struct protoent *pe;
103 #endif
104
105     if ((s = match_strval(proto, ipproto_val)) != NULL)
106         goto ok;
107
108 #ifdef HAVE_GETPROTOBYNUMBER
109     if (g_resolving_actif) {
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 }