source: libpacketdump/ip_1.c @ 243bfd1

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 243bfd1 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26#include <stdio.h>
27#include <inttypes.h>
28#include <dlfcn.h>
29#include "libpacketdump.h"
30
31static char *unreach_types[]={
32        "Destination Network Unreachable",
33        "Destination Host Unreachable",
34        "Destination Protocol Unreachable",
35        "Destination Port Unreachable",
36        "Fragmentation Required And Dont Fragment Set",
37        "Source Route Failed",
38        "Destination Network Unknown",
39        "Destination Host Unknown",
40        "Source Host Isolated",
41        "Destination Network Administratively Prohibited",
42        "Destination Host Administratively Prohibited",
43        "Destination Network Unreachable For Type Of Service",
44        "Destination Host Unreachable For Type Of Service",
45        "Communication Administratively Prohibited",
46        "Host Precedence Violation",
47        "Precedence Cutoff In Effect",
48};
49
50DLLEXPORT void decode(int link_type UNUSED,const char *packet,unsigned len)
51{
52        libtrace_icmp_t *icmp = (libtrace_icmp_t*)packet;
53        int ippresent = 0;
54        if (len<1)
55                return;
56        printf(" ICMP:");
57        switch(icmp->type) {
58                case 0:
59                        printf(" Type: 0 (ICMP Echo Reply) Sequence: ");
60                        if (len < 4)
61                                printf("(Truncated)\n");
62                        else
63                                printf("%u\n", ntohs(icmp->un.echo.sequence));
64                        break;
65                case 3:
66                        printf(" Type: 3 (ICMP Destination Unreachable)\n");
67                        if (len<2)
68                                return;
69                        if (icmp->code<sizeof(unreach_types)) {
70                                printf(" ICMP: Code: %i (%s)\n",icmp->code,
71                                                unreach_types[icmp->code]);
72                        }
73                        else {
74                                printf(" ICMP: Code: %i (Unknown)\n",icmp->code);
75                        }
76                        ippresent = 1;
77                        break;
78                case 8:
79                        printf(" Type: 8 (ICMP Echo Request) Sequence: ");
80                        if (len < 4)
81                                printf("(Truncated)\n");
82                        else
83                                printf("%u\n", ntohs(icmp->un.echo.sequence));
84                        break;
85                case 11:
86                        printf(" Type: 11 (ICMP TTL Exceeded)\n");
87                        ippresent = 1;
88                        break;
89                default:
90                        printf(" Type: %i (Unknown)\n",icmp->type);
91                        break;
92
93        }
94        printf(" ICMP: Checksum: ");
95        if (len < 8)
96                printf("(Truncated)\n");
97        else
98                printf("%u\n", ntohs(icmp->checksum));
99
100        if (ippresent) {
101                decode_next(packet+8,len-8,
102                                "eth",0x0800);
103        }
104
105
106        return;
107}
Note: See TracBrowser for help on using the repository browser.