dect
/
libpcap
Archived
13
0
Fork 0

The data link layer isn't settable, so get rid of

"septel_set_datalink()".

It's also always the same, so get rid of "septel_get_datalink()".

Add an inject routine that just returns an error.

Get rid of a malloc() whose result was neither used nor freed.

Clean up indentation.
This commit is contained in:
guy 2005-06-21 01:03:23 +00:00
parent e4f76eba56
commit 60f0eb71cb
1 changed files with 130 additions and 141 deletions

View File

@ -16,7 +16,7 @@
#ifndef lint #ifndef lint
static const char rcsid[] _U_ = static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-septel.c,v 1.1.2.1 2005-06-20 21:30:18 guy Exp $"; "@(#) $Header: /tcpdump/master/libpcap/pcap-septel.c,v 1.1.2.2 2005-06-21 01:03:23 guy Exp $";
#endif #endif
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -47,7 +47,7 @@ static const char rcsid[] _U_ =
#endif /* HAVE_SEPTEL_API */ #endif /* HAVE_SEPTEL_API */
#ifdef SEPTEL_ONLY #ifdef SEPTEL_ONLY
/* This code is required when compiling for a DAG device only. */ /* This code is required when compiling for a Septel device only. */
#include "pcap-septel.h" #include "pcap-septel.h"
/* Replace dag function names with pcap equivalent. */ /* Replace dag function names with pcap equivalent. */
@ -57,8 +57,6 @@ static const char rcsid[] _U_ =
static int septel_setfilter(pcap_t *p, struct bpf_program *fp); static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
static int septel_stats(pcap_t *p, struct pcap_stat *ps); static int septel_stats(pcap_t *p, struct pcap_stat *ps);
static int septel_set_datalink(pcap_t *p, int dlt);
static int septel_get_datalink(pcap_t *p);
static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf); static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
static void septel_platform_close(pcap_t *p) { static void septel_platform_close(pcap_t *p) {
@ -92,14 +90,12 @@ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
int caplen = 0; int caplen = 0;
int counter = 0; int counter = 0;
struct pcap_pkthdr pcap_header; struct pcap_pkthdr pcap_header;
u_char *dp ; u_char *dp ;
dp = malloc(320); /* 320 = size of param area */
/* /*
* Has "pcap_breakloop()" been called? * Has "pcap_breakloop()" been called?
*/ */
loop: loop:
if (p->break_loop) { if (p->break_loop) {
/* /*
* Yes - clear the flag that indicates that * Yes - clear the flag that indicates that
@ -120,7 +116,8 @@ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
m = (MSG*)h; m = (MSG*)h;
/* a couter is added here to avoid an infinite loop /* a couter is added here to avoid an infinite loop
* that will cause our capture program GUI to freeze while waiting for a packet*/ * that will cause our capture program GUI to freeze while waiting
* for a packet*/
counter++ ; counter++ ;
} }
@ -131,12 +128,14 @@ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
t = h->type ; t = h->type ;
/* catch only messages with type = 0xcf00 or 0x8f01 corrsponding to ss7 messages*/ /* catch only messages with type = 0xcf00 or 0x8f01 corrsponding to ss7 messages*/
/* XXX = why not use API_MSG_TX_REQ for 0xcf00 and API_MSG_RX_IND
* for 0x8f01? */
if ((t != 0xcf00) && (t != 0x8f01)) { if ((t != 0xcf00) && (t != 0x8f01)) {
relm(h); relm(h);
goto loop ; goto loop ;
} }
/* XXX - is API_MSG_RX_IND for an MTP2 or MTP3 message? */
dp = get_param(m);/* get pointer to MSG parameter area (m->param) */ dp = get_param(m);/* get pointer to MSG parameter area (m->param) */
packet_len = m->len; packet_len = m->len;
caplen = p->snapshot ; caplen = p->snapshot ;
@ -185,12 +184,20 @@ static int septel_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
processed++; processed++;
} }
while (processed < cnt) ;
while (processed < cnt ) ;
return processed ; return processed ;
} }
static int
septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
{
strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
PCAP_ERRBUF_SIZE);
return (-1);
}
/* /*
* Get a handle for a live capture from the given Septel device. Always pass a NULL device * Get a handle for a live capture from the given Septel device. Always pass a NULL device
* The promisc flag is ignored because Septel cards have built-in tracing. * The promisc flag is ignored because Septel cards have built-in tracing.
@ -214,22 +221,19 @@ pcap_t *septel_open_live(const char *device, int snaplen, int promisc, int to_ms
handle->snapshot = snaplen; handle->snapshot = snaplen;
if ((handle->linktype = septel_get_datalink(handle)) < 0) { handle->linktype = DLT_MTP2;
snprintf(ebuf, PCAP_ERRBUF_SIZE, "septel_get_linktype %s: unknown linktype\n", device);
goto fail;
}
handle->bufsize = 0; handle->bufsize = 0;
/* /*
* "select()" and "poll()" don't work on Septel queues * "select()" and "poll()" don't work on Septel queues
*/ */
handle->selectable_fd = -1; handle->selectable_fd = -1;
handle->read_op = septel_read; handle->read_op = septel_read;
handle->inject_op = septel_inject;
handle->setfilter_op = septel_setfilter; handle->setfilter_op = septel_setfilter;
handle->set_datalink_op = septel_set_datalink; handle->set_datalink_op = NULL; /* can't change data link type */
handle->getnonblock_op = pcap_getnonblock_fd; handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = septel_setnonblock; handle->setnonblock_op = septel_setnonblock;
handle->stats_op = septel_stats; handle->stats_op = septel_stats;
@ -271,10 +275,10 @@ unsigned char *p;
/* /*
* Installs the given bpf filter program in the given pcap structure. There is * Installs the given bpf filter program in the given pcap structure. There is
* no attempt to store the filter in kernel memory as that is not supported * no attempt to store the filter in kernel memory as that is not supported
* with SEPTEL cards. * with Septel cards.
*/ */
static int septel_setfilter(pcap_t *p, struct bpf_program *fp) { static int septel_setfilter(pcap_t *p, struct bpf_program *fp) {
if (!p) if (!p)
return -1; return -1;
if (!fp) { if (!fp) {
strncpy(p->errbuf, "setfilter: No filter specified", strncpy(p->errbuf, "setfilter: No filter specified",
@ -292,27 +296,12 @@ if (!p)
p->md.use_bpf = 0; p->md.use_bpf = 0;
return (0); return (0);
} }
static int
septel_set_datalink(pcap_t *p, int dlt)
{
return (0);
}
static int static int
septel_setnonblock(pcap_t *p, int nonblock, char *errbuf) septel_setnonblock(pcap_t *p, int nonblock, char *errbuf)
{ {
return (0); return (0);
} }
static int
septel_get_datalink(pcap_t *p)
{
int linktype = -1;
return DLT_MTP2;
}