dissectors: lldp: Implement dissection of Management Address TLV
[netsniff-ng.git] / proto_icmpv4.c
blobb86c73bf77ead0be389849bd8bdc3b03061361a9
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 "dissector_eth.h"
15 #include "pkt_buff.h"
16 #include "built_in.h"
18 struct icmphdr {
19 uint8_t type;
20 uint8_t code;
21 uint16_t checksum;
22 union {
23 struct {
24 uint16_t id;
25 uint16_t sequence;
26 } echo;
27 uint32_t gateway;
28 struct {
29 uint16_t ____unused;
30 uint16_t mtu;
31 } frag;
32 } un;
33 } __packed;
35 static void icmp(struct pkt_buff *pkt)
37 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
39 if (icmp == NULL)
40 return;
42 tprintf(" [ ICMP ");
43 tprintf("Type (%u), ", icmp->type);
44 tprintf("Code (%u), ", icmp->code);
45 tprintf("CSum (0x%.4x)", ntohs(icmp->checksum));
46 tprintf(" ]\n");
49 static void icmp_less(struct pkt_buff *pkt)
51 struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
53 if (icmp == NULL)
54 return;
56 tprintf(" Type %u Code %u", icmp->type, icmp->code);
59 struct protocol icmpv4_ops = {
60 .key = 0x01,
61 .print_full = icmp,
62 .print_less = icmp_less,