summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/ipft_pc.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ipfilter/lib/ipft_pc.c')
-rw-r--r--contrib/ipfilter/lib/ipft_pc.c165
1 files changed, 75 insertions, 90 deletions
diff --git a/contrib/ipfilter/lib/ipft_pc.c b/contrib/ipfilter/lib/ipft_pc.c
index 0f31a10..3a264bd 100644
--- a/contrib/ipfilter/lib/ipft_pc.c
+++ b/contrib/ipfilter/lib/ipft_pc.c
@@ -1,19 +1,17 @@
/* $FreeBSD$ */
/*
- * Copyright (C) 2000-2005 by Darren Reed.
+ * Copyright (C) 2012 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
- * $Id: ipft_pc.c,v 1.10.2.2 2006/06/16 17:21:03 darrenr Exp $
+ * $Id$
*/
#include "ipf.h"
-#include "pcap-ipf.h"
-#include "bpf-ipf.h"
#include "ipt.h"
#if !defined(lint)
-static const char rcsid[] = "@(#)$Id: ipft_pc.c,v 1.10.2.2 2006/06/16 17:21:03 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id$";
#endif
struct llc {
@@ -29,79 +27,61 @@ struct llc {
*/
static struct llc llcs[] = {
- { DLT_NULL, 0, 0, 0 },
- { DLT_EN10MB, 14, 12, 2 },
- { DLT_EN3MB, 0, 0, 0 },
- { DLT_AX25, 0, 0, 0 },
- { DLT_PRONET, 0, 0, 0 },
- { DLT_CHAOS, 0, 0, 0 },
- { DLT_IEEE802, 0, 0, 0 },
- { DLT_ARCNET, 0, 0, 0 },
- { DLT_SLIP, 0, 0, 0 },
- { DLT_PPP, 0, 0, 0 },
- { DLT_FDDI, 0, 0, 0 },
-#ifdef DLT_ATMRFC1483
- { DLT_ATMRFC1483, 0, 0, 0 },
-#endif
- { DLT_RAW, 0, 0, 0 },
-#ifdef DLT_ENC
- { DLT_ENC, 0, 0, 0 },
-#endif
-#ifdef DLT_SLIP_BSDOS
- { DLT_SLIP_BSDOS, 0, 0, 0 },
-#endif
-#ifdef DLT_PPP_BSDOS
- { DLT_PPP_BSDOS, 0, 0, 0 },
-#endif
-#ifdef DLT_HIPPI
- { DLT_HIPPI, 0, 0, 0 },
-#endif
-#ifdef DLT_HDLC
- { DLT_HDLC, 0, 0, 0 },
-#endif
-#ifdef DLT_PPP_SERIAL
- { DLT_PPP_SERIAL, 4, 4, 0 },
-#endif
-#ifdef DLT_PPP_ETHER
- { DLT_PPP_ETHER, 8, 8, 0 },
-#endif
-#ifdef DLT_ECONET
- { DLT_ECONET, 0, 0, 0 },
-#endif
+ { 0, 0, 0, 0 }, /* DLT_NULL */
+ { 1, 14, 12, 2 }, /* DLT_Ethernet */
+ { 10, 0, 0, 0 }, /* DLT_FDDI */
+ { 12, 0, 0, 0 }, /* DLT_RAW */
{ -1, -1, -1, -1 }
};
-static int pcap_open __P((char *));
-static int pcap_close __P((void));
-static int pcap_readip __P((char *, int, char **, int *));
-static void swap_hdr __P((pcaphdr_t *));
-static int pcap_read_rec __P((struct pcap_pkthdr *));
+typedef struct {
+ u_int id;
+ u_short major;
+ u_short minor;
+ u_int timezone;
+ u_int sigfigs;
+ u_int snaplen;
+ u_int type;
+} fileheader_t;
+
+typedef struct {
+ u_32_t seconds;
+ u_32_t microseconds;
+ u_32_t caplen;
+ u_32_t wirelen;
+} packetheader_t;
+
+static int ipcap_open __P((char *));
+static int ipcap_close __P((void));
+static int ipcap_readip __P((mb_t *, char **, int *));
+static int ipcap_read_rec __P((packetheader_t *));
+static void iswap_hdr __P((fileheader_t *));
static int pfd = -1, swapped = 0;
static struct llc *llcp = NULL;
-struct ipread pcap = { pcap_open, pcap_close, pcap_readip, 0 };
+struct ipread pcap = { ipcap_open, ipcap_close, ipcap_readip, 0 };
#define SWAPLONG(y) \
((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
#define SWAPSHORT(y) \
( (((y)&0xff)<<8) | (((y)&0xff00)>>8) )
-static void swap_hdr(p)
-pcaphdr_t *p;
+static void iswap_hdr(p)
+ fileheader_t *p;
{
- p->pc_v_maj = SWAPSHORT(p->pc_v_maj);
- p->pc_v_min = SWAPSHORT(p->pc_v_min);
- p->pc_zone = SWAPLONG(p->pc_zone);
- p->pc_sigfigs = SWAPLONG(p->pc_sigfigs);
- p->pc_slen = SWAPLONG(p->pc_slen);
- p->pc_type = SWAPLONG(p->pc_type);
+ p->major = SWAPSHORT(p->major);
+ p->minor = SWAPSHORT(p->minor);
+ p->timezone = SWAPLONG(p->timezone);
+ p->sigfigs = SWAPLONG(p->sigfigs);
+ p->snaplen = SWAPLONG(p->snaplen);
+ p->type = SWAPLONG(p->type);
}
-static int pcap_open(fname)
-char *fname;
+static int ipcap_open(fname)
+ char *fname;
{
- pcaphdr_t ph;
+ fileheader_t ph;
int fd, i;
if (pfd != -1)
@@ -115,22 +95,17 @@ char *fname;
if (read(fd, (char *)&ph, sizeof(ph)) != sizeof(ph))
return -2;
- if (ph.pc_id != TCPDUMP_MAGIC) {
- if (SWAPLONG(ph.pc_id) != TCPDUMP_MAGIC) {
+ if (ph.id != 0xa1b2c3d4) {
+ if (SWAPLONG(ph.id) != 0xa1b2c3d4) {
(void) close(fd);
return -2;
}
swapped = 1;
- swap_hdr(&ph);
- }
-
- if (ph.pc_v_maj != PCAP_VERSION_MAJ) {
- (void) close(fd);
- return -2;
+ iswap_hdr(&ph);
}
for (i = 0; llcs[i].lc_type != -1; i++)
- if (llcs[i].lc_type == ph.pc_type) {
+ if (llcs[i].lc_type == ph.type) {
llcp = llcs + i;
break;
}
@@ -143,13 +118,13 @@ char *fname;
pfd = fd;
printf("opened pcap file %s:\n", fname);
printf("\tid: %08x version: %d.%d type: %d snap %d\n",
- ph.pc_id, ph.pc_v_maj, ph.pc_v_min, ph.pc_type, ph.pc_slen);
+ ph.id, ph.major, ph.minor, ph.type, ph.snaplen);
return fd;
}
-static int pcap_close()
+static int ipcap_close()
{
return close(pfd);
}
@@ -159,8 +134,8 @@ static int pcap_close()
* read in the header (and validate) which should be the first record
* in a pcap file.
*/
-static int pcap_read_rec(rec)
-struct pcap_pkthdr *rec;
+static int ipcap_read_rec(rec)
+ packetheader_t *rec;
{
int n, p, i;
char *s;
@@ -177,13 +152,13 @@ struct pcap_pkthdr *rec;
}
if (swapped) {
- rec->ph_clen = SWAPLONG(rec->ph_clen);
- rec->ph_len = SWAPLONG(rec->ph_len);
- rec->ph_ts.tv_sec = SWAPLONG(rec->ph_ts.tv_sec);
- rec->ph_ts.tv_usec = SWAPLONG(rec->ph_ts.tv_usec);
+ rec->caplen = SWAPLONG(rec->caplen);
+ rec->wirelen = SWAPLONG(rec->wirelen);
+ rec->seconds = SWAPLONG(rec->seconds);
+ rec->microseconds = SWAPLONG(rec->microseconds);
}
- p = rec->ph_clen;
- n = MIN(p, rec->ph_len);
+ p = rec->caplen;
+ n = MIN(p, rec->wirelen);
if (!n || n < 0)
return -3;
@@ -198,15 +173,15 @@ struct pcap_pkthdr *rec;
* read an entire pcap packet record. only the data part is copied into
* the available buffer, with the number of bytes copied returned.
*/
-static int pcap_read(buf, cnt)
-char *buf;
-int cnt;
+static int ipcap_read(buf, cnt)
+ char *buf;
+ int cnt;
{
- struct pcap_pkthdr rec;
+ packetheader_t rec;
static char *bufp = NULL;
int i, n;
- if ((i = pcap_read_rec(&rec)) <= 0)
+ if ((i = ipcap_read_rec(&rec)) <= 0)
return i;
if (!bufp)
@@ -227,20 +202,29 @@ int cnt;
/*
* return only an IP packet read into buf
*/
-static int pcap_readip(buf, cnt, ifn, dir)
-char *buf, **ifn;
-int cnt, *dir;
+static int ipcap_readip(mb, ifn, dir)
+ mb_t *mb;
+ char **ifn;
+ int *dir;
{
static char *bufp = NULL;
- struct pcap_pkthdr rec;
+ packetheader_t rec;
struct llc *l;
char *s, ty[4];
int i, j, n;
+ char *buf;
+ int cnt;
+#if 0
+ ifn = ifn; /* gcc -Wextra */
+ dir = dir; /* gcc -Wextra */
+#endif
+ buf = (char *)mb->mb_buf;
+ cnt = sizeof(mb->mb_buf);
l = llcp;
/* do { */
- if ((i = pcap_read_rec(&rec)) <= 0)
+ if ((i = ipcap_read_rec(&rec)) <= 0)
return i;
if (!bufp)
@@ -265,5 +249,6 @@ int cnt, *dir;
/* } while (ty[0] != 0x8 && ty[1] != 0); */
n = MIN(i, cnt);
bcopy(s, buf, n);
+ mb->mb_len = n;
return n;
}
OpenPOWER on IntegriCloud