dissectors: Remove unnecessary includes of dissector_eth.h
[netsniff-ng.git] / proto_icmpv4.c
blob5ef074d6553ff5008fcb46bb8fe2fd076c346a9d
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 "csum.h"
13 #include "pkt_buff.h"
14 #include "built_in.h"
16 struct icmphdr {
17 uint8_t type;
18 uint8_t code;
19 uint16_t checksum;
20 union {
21 struct {
22 uint16_t id;
23 uint16_t sequence;
24 } echo;
25 uint32_t gateway;
26 struct {
27 uint16_t ____unused;
28 uint16_t mtu;
29 } frag;
30 } un;
31 } __packed;
33 static void icmp(struct pkt_buff *pkt)
35 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
36 uint16_t csum;
38 if (icmp == NULL)
39 return;
41 csum = calc_csum(icmp, pkt_len(pkt) + sizeof(*icmp), 0);
43 tprintf(" [ ICMP ");
44 tprintf("Type (%u), ", icmp->type);
45 tprintf("Code (%u), ", icmp->code);
46 tprintf("CSum (0x%.4x) is %s", ntohs(icmp->checksum),
47 csum ? colorize_start_full(black, red) "bogus (!)"
48 colorize_end() : "ok");
49 tprintf(" ]\n");
52 static void icmp_less(struct pkt_buff *pkt)
54 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
56 if (icmp == NULL)
57 return;
59 tprintf(" Type %u Code %u", icmp->type, icmp->code);
62 struct protocol icmpv4_ops = {
63 .key = 0x01,
64 .print_full = icmp,
65 .print_less = icmp_less,