1 /****************************************************************************
2 ** File: ip_protocols.c
3 **
4 ** Author: Mike Borella
5 **
6 ** Comments: Functions to handle certain IP protocol numbers
7 **
8 ** $Id: ip_protocols.c,v 1.18 2001/11/02 00:23:06 mborella Exp $
9 **
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation; either version 2 of the License, or
13 ** (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 Library 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 
26 #include "global.h"
27 #include "ip_protocols.h"
28 
29 #define IP_PROTO_ARRAY_SIZE 256
30 
31 /*
32  * Make an array that will hold all of the pointers to protocol functions
33  */
34 
35 void (*ip_proto_func[IP_PROTO_ARRAY_SIZE])(packet_t *);
36 
37 /*
38  * Fill the array up with pointers.  I'd like to do this in global space
39  * so that this function does not have to be explicitly called...but I can't
40  * get that to work right (won't compile).  Help?
41  */
42 
init_ip_protocols(void)43 void init_ip_protocols(void)
44 {
45   int i;
46 
47   for (i = 0; i < 256; i++)
48     ip_proto_func[i] = NULL;
49 
50   ip_proto_func[PROTO_ICMP]     = dump_icmp;
51   ip_proto_func[PROTO_IGMP]     = dump_igmp;
52   ip_proto_func[PROTO_IPENCAP]  = dump_ip;
53   ip_proto_func[PROTO_TCP]      = dump_tcp;
54   ip_proto_func[PROTO_UDP]      = dump_udp;
55   ip_proto_func[PROTO_GRE]      = dump_gre;
56   ip_proto_func[PROTO_RSVP]     = dump_rsvp;
57   ip_proto_func[PROTO_ESP]      = dump_esp;
58   ip_proto_func[PROTO_AH]       = dump_ah;
59   ip_proto_func[PROTO_OSPF]     = dump_ospf;
60   ip_proto_func[PROTO_IPV6ICMP] = dump_icmpv6;
61   ip_proto_func[PROTO_IPV6]     = dump_ipv6;
62 
63   ip_proto_func[PROTO_PUP] = dump_tcp;
64 }
65 
66 /*
67  * IP protocol map.  There appears to be 3 different types of IP in IP
68  * encapsulation.  Weird.  I'm not sure which is(are) really used...
69  */
70 
71 strmap_t ipproto_map[] =
72 {
73   { PROTO_IPV6HOP,         "IPv6 hop by hop" },
74   { PROTO_ICMP,            "ICMP" },
75   { PROTO_IGMP,            "IGMP" },
76   { PROTO_GGP,             "GGP" },
77   { PROTO_IPENCAP,         "IP encapsulation" },
78   { PROTO_ST,              "ST" },
79   { PROTO_TCP,             "TCP" },
80   { PROTO_CBT,             "CBT" },
81   { PROTO_EGP,             "EGP" },
82   { PROTO_IGP,             "IGP" },
83   { PROTO_PUP,             "PUP" },
84   { PROTO_UDP,             "UDP" },
85   { PROTO_HMP,             "HMP" },
86   { PROTO_XNSIDP,          "XNS IDP" },
87   { PROTO_RDP,             "RDP" },
88   { PROTO_IPV6,            "IPv6" },
89   { PROTO_IPV6ROUTE,       "IPv6 route" },
90   { PROTO_IPV6FRAG,        "IPv6 fragmentation" },
91   { PROTO_IDRP,            "IDRP" },
92   { PROTO_RSVP,            "RSVP" },
93   { PROTO_GRE,             "GRE" },
94   { PROTO_ESP,             "ESP" },
95   { PROTO_AH,              "AH" },
96   { PROTO_NARP,            "NARP" },
97   { PROTO_IPV6ICMP,        "ICMPv6" },
98   { PROTO_IPV6NONEXT,      "IPv6 no next header" },
99   { PROTO_IPV6OPTS,        "IPv6 options" },
100   { PROTO_RSPF,            "Radio shortest path first" },
101   { PROTO_VMTP,            "Versatile message transport" },
102   { PROTO_OSPF,            "OSPF" },
103   { PROTO_IPIP,            "IPinIP" },
104   { PROTO_ENCAP,           "IPinIP encapsulation" },
105   { 0, "" }
106 };
107 
108