build: fix install dependencies in Makefile template
[netsniff-ng-new.git] / proto_icmpv4.c
blobe6ebd433ba510fc58256ef65d1dde16acee4dac0
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <netinet/in.h> /* for ntohs() */
11 #include "proto.h"
12 #include "protos.h"
13 #include "csum.h"
14 #include "pkt_buff.h"
15 #include "built_in.h"
17 struct icmphdr {
18 uint8_t type;
19 uint8_t code;
20 uint16_t checksum;
21 union {
22 struct {
23 uint16_t id;
24 uint16_t sequence;
25 } echo;
26 uint32_t gateway;
27 struct {
28 uint16_t ____unused;
29 uint16_t mtu;
30 } frag;
31 } un;
32 } __packed;
34 static void icmp(struct pkt_buff *pkt)
36 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
37 uint16_t csum;
39 if (icmp == NULL)
40 return;
42 csum = calc_csum(icmp, pkt_len(pkt) + sizeof(*icmp));
44 tprintf(" [ ICMP ");
45 tprintf("Type (%u), ", icmp->type);
46 tprintf("Code (%u), ", icmp->code);
47 tprintf("CSum (0x%.4x) is %s", ntohs(icmp->checksum),
48 csum ? colorize_start_full(black, red) "bogus (!)"
49 colorize_end() : "ok");
50 tprintf(" ]\n");
53 static void icmp_less(struct pkt_buff *pkt)
55 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
57 if (icmp == NULL)
58 return;
60 tprintf(" Type %u Code %u", icmp->type, icmp->code);
63 struct protocol icmpv4_ops = {
64 .key = 0x01,
65 .print_full = icmp,
66 .print_less = icmp_less,