netsniff-ng: help: stdout can be pcap or traqfgen config
[netsniff-ng.git] / proto_icmpv4.c
blobbdf11909d93a973dbc2ed1a8e0109281eaf746cd
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <netinet/in.h> /* for ntohs() */
12 #include "proto.h"
13 #include "protos.h"
14 #include "csum.h"
15 #include "dissector_eth.h"
16 #include "pkt_buff.h"
17 #include "built_in.h"
19 struct icmphdr {
20 uint8_t type;
21 uint8_t code;
22 uint16_t checksum;
23 union {
24 struct {
25 uint16_t id;
26 uint16_t sequence;
27 } echo;
28 uint32_t gateway;
29 struct {
30 uint16_t ____unused;
31 uint16_t mtu;
32 } frag;
33 } un;
34 } __packed;
36 static void icmp(struct pkt_buff *pkt)
38 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
39 uint16_t csum;
41 if (icmp == NULL)
42 return;
44 csum = calc_csum(icmp, pkt_len(pkt) + sizeof(*icmp), 0);
46 tprintf(" [ ICMP ");
47 tprintf("Type (%u), ", icmp->type);
48 tprintf("Code (%u), ", icmp->code);
49 tprintf("CSum (0x%.4x) is %s", ntohs(icmp->checksum),
50 csum ? colorize_start_full(black, red) "bogus (!)"
51 colorize_end() : "ok");
52 tprintf(" ]\n");
55 static void icmp_less(struct pkt_buff *pkt)
57 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
59 if (icmp == NULL)
60 return;
62 tprintf(" Type %u Code %u", icmp->type, icmp->code);
65 struct protocol icmpv4_ops = {
66 .key = 0x01,
67 .print_full = icmp,
68 .print_less = icmp_less,