1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/****************************************************************************
** File: icmp.c
**
** Author: Mike Borella
**
** Comments: Dump ICMP information
**
*****************************************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include "config.h"
#include "icmp.h"
extern u_char *packet_end;
/*----------------------------------------------------------------------------
**
** dump_icmp()
**
** Parse ICMP header and dump fields
**
**----------------------------------------------------------------------------
*/
void dump_icmp(u_char *bp)
{
ICMPhdr *icmph;
echoext *echo;
icmph = (ICMPhdr *) bp;
printf("----------------------------------------------------------\n");
printf(" ICMP Header\n");
printf("----------------------------------------------------------\n");
printf("Type: %d ", icmph->type);
switch (icmph->type)
{
case 0:
printf("(echo reply)\n");
printf("Code %d\n", icmph->code);
echo = (echoext *) (bp + sizeof(ICMPhdr));
printf("Identifier %d\n", echo->id);
printf("Sequence number %d\n", echo->seqno);
break;
case 3:
printf("(dest unreachable)\n");
printf("Code: %d ", icmph->code);
switch (icmph->code)
{
case 0:
printf("(network)\n");
break;
case 1:
printf("(host)\n");
break;
case 2:
printf("(protocol)\n");
break;
case 3:
printf("(port)\n");
break;
case 4:
printf("(fragment needed)\n");
break;
case 5:
printf("(source route failed)\n");
break;
case 6:
printf("(network unknown)\n");
break;
case 7:
printf("(host unknown)\n");
break;
case 9:
printf("(network prohibited)\n");
break;
case 10:
printf("(host prohibited)\n");
break;
case 11:
printf("(network unreachable for TOS)\n");
break;
case 12:
printf("(host unreachable for TOS)\n");
break;
case 13:
printf("(communication filtered)\n");
break;
case 14:
printf("(host precedence violation)\n");
break;
case 15:
printf("(precedence cutoff)\n");
break;
default:
printf("(unknown code)\n");
break;
} /* code */
break;
case 4:
printf("(source quench)\n");
printf("Code: %d ", icmph->code);
break;
case 5:
printf("(redirect)\n");
printf("Code: %d ", icmph->code);
switch(icmph->code)
{
case 0:
printf("(network)\n");
break;
case 1:
printf("(host)\n");
break;
case 2:
printf("(TOS and network)\n");
break;
case 3:
printf("(TOS and host)\n");
break;
}
break;
case 8:
printf("(echo request)\n");
printf("Code %d\n", icmph->code);
echo = (echoext *) (bp + sizeof(ICMPhdr));
printf("Identifier %d\n", echo->id);
printf("Sequence number %d\n", echo->seqno);
break;
case 9:
printf("(router advertisement)\n");
printf("Code: %d ", icmph->code);
break;
case 10:
printf("(router solicitation)\n");
printf("Code: %d ", icmph->code);
break;
case 11:
printf("(time exceeded)\n");
printf("Code: %d ", icmph->code);
break;
case 12:
printf("(parameter error)\n");
printf("Code: %d ", icmph->code);
break;
case 13:
printf("(timestamp request)\n");
printf("Code: %d ", icmph->code);
break;
case 14:
printf("(timestamp reply)\n");
printf("Code: %d ", icmph->code);
break;
case 17:
printf("(address mask request)\n");
printf("Code: %d ", icmph->code);
break;
case 18:
printf("(address mask reply)\n");
printf("Code: %d ", icmph->code);
break;
default:
printf("(unknown type)\n");
printf("Code: %d ", icmph->code);
break;
}
printf("Checksum: %d\n", ntohs(icmph->csum));
return;
}
|