1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/****************************************************************************
**
** File: loopback.c
**
** Author: Mike Borella
**
** Comments: Dump loopback packets
**
*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <pcap.h>
#include "config.h"
#include "loopback.h"
#include "ip.h"
#define INET_FAMILY 524288
u_char *packet_ptr;
u_char *packet_end;
/*----------------------------------------------------------------------------
**
** dump_loopback()
**
** Process packets from DLT_NULL device
**
**----------------------------------------------------------------------------
*/
void dump_loopback(u_char *user, const struct pcap_pkthdr *h, u_char *p)
{
int length;
int caplen;
u_int32_t family;
/*
* Get total packet length and length of the captured section
*/
length = h->len;
caplen = h->caplen;
/*
* Dump header announcement
*/
printf("=================================================================\n");
printf(" Loopback Header(%u.%06u)\n",
(u_int32_t) h->ts.tv_sec, (u_int32_t) h->ts.tv_usec);
printf("-----------------------------------------------------------------\n");
/*
* Check for truncated header
*/
if (caplen < LOOPBACK_HEADER_LEN)
{
printf("Loopback header too short! (%d bytes)\n", length);
return;
}
/*
* Dump header field
*/
printf("Address family ");
memcpy((void *) &family, (void *) p, LOOPBACK_HEADER_LEN);
if (family == INET_FAMILY)
printf("Internet\n");
else
{
printf("Unknown (%d)\n", family);
return;
}
/*
* Some printers want to get back at the link level addresses,
* and/or check that they're not walking off the end of the packet.
* Rather than pass them all the way down, we set these globals.
*/
packet_ptr = p;
packet_end = p + caplen;
/*
* Check for IEEE 802 (LLC) encapsulation. If not, assume regular ethernet
*/
p += LOOPBACK_HEADER_LEN;
dump_ip(p, length);
return;
}
|