improving dissector_fuzz
[netsniff-ng.git] / src / proto_icmpv4.h
blob563730dc62678170b1de95472b67c68612b7981c
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 #ifndef PROTO_ICMP_H
9 #define PROTO_ICMP_H
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <netinet/in.h> /* for ntohs() */
15 #include "proto_struct.h"
16 #include "dissector_eth.h"
17 #include "pkt_buff.h"
18 #include "built_in.h"
20 struct icmphdr {
21 uint8_t type;
22 uint8_t code;
23 uint16_t checksum;
24 union {
25 struct {
26 uint16_t id;
27 uint16_t sequence;
28 } echo;
29 uint32_t gateway;
30 struct {
31 uint16_t ____unused;
32 uint16_t mtu;
33 } frag;
34 } un;
35 } __packed;
37 static inline void icmp(struct pkt_buff *pkt)
39 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
41 if (icmp == NULL)
42 return;
44 tprintf(" [ ICMP ");
45 tprintf("Type (%u), ", icmp->type);
46 tprintf("Code (%u), ", icmp->code);
47 tprintf("CSum (0x%.4x)", ntohs(icmp->checksum));
48 tprintf(" ]\n");
51 static inline void icmp_less(struct pkt_buff *pkt)
53 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
55 if (icmp == NULL)
56 return;
58 tprintf(" Type %u Code %u", icmp->type, icmp->code);
61 struct protocol icmp_ops = {
62 .key = 0x01,
63 .print_full = icmp,
64 .print_less = icmp_less,
67 #endif /* PROTO_ICMP_H */