forked from antirez/hping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logicmp.c
74 lines (65 loc) · 1.88 KB
/
logicmp.c
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
/*
* $smu-mark$
* $name: logicmp.c$
* $author: Salvatore Sanfilippo <antirez@invece.org>$
* $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
* $license: This software is under GPL version 2 of license$
* $date: Fri Nov 5 11:55:48 MET 1999$
* $rev: 8$
*/
/* $Id: logicmp.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
#include <stdio.h>
#include <sys/types.h> /* this should be not needed, but ip_icmp.h lacks it */
#include "hping2.h"
#include "globals.h"
void log_icmp_timeexc(char *src_addr, unsigned short icmp_code)
{
switch(icmp_code) {
case ICMP_EXC_TTL:
printf("TTL 0 during transit from ip=%s", src_addr);
break;
case ICMP_EXC_FRAGTIME:
printf("TTL 0 during reassembly from ip=%s", src_addr);
break;
}
if (opt_gethost) {
char *hostn;
fflush(stdout);
hostn = get_hostname(src_addr);
printf("name=%s", (hostn) ? hostn : "UNKNOWN");
}
putchar('\n');
}
void log_icmp_unreach(char *src_addr, unsigned short icmp_code)
{
static char* icmp_unreach_msg[]={
"Network Unreachable from", /* code 0 */
"Host Unreachable from", /* code 1 */
"Protocol Unreachable from", /* code 2 */
"Port Unreachable from", /* code 3 */
"Fragmentation Needed/DF set from", /* code 4 */
"Source Route failed from", /* code 5 */
NULL, /* code 6 */
NULL, /* code 7 */
NULL, /* code 8 */
NULL, /* code 9 */
NULL, /* code 10 */
NULL, /* code 11 */
NULL, /* code 12 */
"Packet filtered from", /* code 13 */
"Precedence violation from", /* code 14 */
"precedence cut off from" /* code 15 */
};
if (icmp_unreach_msg[icmp_code] != NULL)
printf("ICMP %s ip=%s", icmp_unreach_msg[icmp_code], src_addr);
else
printf("ICMP Unreachable type=%d from ip=%s",
icmp_code, src_addr);
if (opt_gethost) {
char *hostn;
fflush(stdout);
hostn = get_hostname(src_addr);
printf("name=%s", (hostn) ? hostn : "UNKNOWN");
}
putchar('\n');
}