/*
 * netsniff-ng - the packet sniffing beast
 * Copyright 2009, 2010 Daniel Borkmann.
 * Subject to the GPL, version 2.
 */

#include <stdio.h>
#include <stdint.h>
#include <netinet/in.h>    /* for ntohs() */

#include "proto.h"
#include "protos.h"
#include "csum.h"
#include "pkt_buff.h"
#include "built_in.h"

struct icmphdr {
	uint8_t type;
	uint8_t code;
	uint16_t checksum;
	union {
		struct {
			uint16_t id;
			uint16_t sequence;
		} echo;
		uint32_t gateway;
		struct {
			uint16_t ____unused;
			uint16_t mtu;
		} frag;
	} un;
} __packed;

static void icmp(struct pkt_buff *pkt)
{
	struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));
	uint16_t csum;

	if (icmp == NULL)
		return;

	csum = calc_csum(icmp, pkt_len(pkt) + sizeof(*icmp), 0);

	tprintf(" [ ICMP ");
	tprintf("Type (%u), ", icmp->type);
	tprintf("Code (%u), ", icmp->code);
	tprintf("CSum (0x%.4x) is %s", ntohs(icmp->checksum),
		csum ? colorize_start_full(black, red) "bogus (!)"
		       colorize_end() : "ok");
	tprintf(" ]\n");
}

static void icmp_less(struct pkt_buff *pkt)
{
	struct icmphdr *icmp = (struct icmphdr *) pkt_pull(pkt, sizeof(*icmp));

	if (icmp == NULL)
		return;

	tprintf(" Type %u Code %u", icmp->type, icmp->code);
}

struct protocol icmpv4_ops = {
	.key = 0x01,
	.print_full = icmp,
	.print_less = icmp_less,
};
></td></tr>
<tr><td class='sub'>net-next plumbings</td><td class='sub right'>Tobias Klauser</td></tr></table>
<table class='tabs'><tr><td>
<a href='/cgit.cgi/linux/net-next.git/'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>refs</a><a class='active' href='/cgit.cgi/linux/net-next.git/log/net/nfc/nfc.h'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/net/nfc/nfc.h?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/net/nfc/nfc.h?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/net/nfc/nfc.h?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/net/nfc/nfc.h'>
<input type='hidden' name='id' value='422e21e7619bb8751aa1cd32a9b671b1baaf3d18'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/net?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>net</a>/<a href='/cgit.cgi/linux/net-next.git/log/net/nfc?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>nfc</a>/<a href='/cgit.cgi/linux/net-next.git/log/net/nfc/nfc.h?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18'>nfc.h</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/net/nfc/nfc.h?id=422e21e7619bb8751aa1cd32a9b671b1baaf3d18&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>