Skip to content

Commit

Permalink
The SITA code in pcap-linux.c shares very little with the Linux code;
Browse files Browse the repository at this point in the history
move it into pcap-sita.c, and make --with-sita set the pcap type to
"sita", so we build pcap-sita.c instead of, rather than in addition to,
pcap-linux.c.

Use "bpf_u_int32" rather than "ulong" in the SITA code, as it's intended
to be 32 bits long (the "l" in "htonl()" and "ntohl()" is historical -
they work on 32-bit quantities, and the "l" dates back to the days when
32-bit processors were a bit newer and 16-bit Unix was more common).

Those changes also, at least in theory, makes the SITA support work on
other Unix-compatible platforms; note that in README.sita.

Clean up pcap-sita.c, making routines no longer called outside it
static, folding trivial wrappers, and fixing various warnings.

Put the routines used by fad-sita.c and defined by pcap-sita.c into
pcap-sita.h.  Remove from pcap-sita.h the files that are now static to
pcap-sita.c.  Include pcap-sita.h in both fad-sita.c and pcap-sita.c, so
that we do cross-file prototype checking.
  • Loading branch information
yuguy committed Jan 6, 2008
1 parent 92c5d33 commit f57d847
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 98 deletions.
9 changes: 6 additions & 3 deletions README.sita
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ The following instructions apply if you have a Linux platform and want
libpcap to support the 'ACN' WAN/LAN router product from from SITA
(http://www.sita.aero)

This might also work on non-Linux Unix-compatible platforms, but that
has not been tested.

See also the libpcap INSTALL.txt file for further libpcap configuration
options.

Expand Down Expand Up @@ -48,9 +51,9 @@ All captured packets are then forwarded across that TCP session
back to the local 'top layer' for forwarding to the actual
sniffing program (wireshark...)

Note that the DLT_SITA protocol includes a proprietary header
that is documented as part of the SITA dissector of Wireshark
and is also described in 'pcap-sita.html' for posterity sake.
Note that the DLT_SITA link-layer type includes a proprietary header
that is documented as part of the SITA dissector of Wireshark and is
also described in 'pcap-sita.html' for posterity sake.

That header provides:
- Packet direction (in/out) (1 octet)
Expand Down
43 changes: 25 additions & 18 deletions configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/sh
# From configure.in Revision: 1.143 .
# From configure.in Revision: 1.144 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59.
#
Expand Down Expand Up @@ -856,8 +856,8 @@ Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--without-gcc don't use gcc
--with-pcap=TYPE use packet capture TYPE
--with-sita include SITA support
--with-pcap=TYPE use packet capture TYPE
--with-dag[=DIR] include Endace DAG support ("yes", "no" or DIR; default="yes" on BSD and Linux if present)
--with-dag-includes=DIR Endace DAG include directory
--with-dag-libraries=DIR Endace DAG library directory
Expand Down Expand Up @@ -5931,6 +5931,27 @@ fi
echo "$as_me:$LINENO: result: ${enable_protochain}" >&5
echo "${ECHO_T}${enable_protochain}" >&6
#
# SITA support is mutually exclusive with native capture support;
# "--with-sita" selects SITA support.
#
# Check whether --with-sita or --without-sita was given.
if test "${with_sita+set}" = set; then
withval="$with_sita"
cat >>confdefs.h <<\_ACEOF
#define SITA 1
_ACEOF
{ echo "$as_me:$LINENO: Enabling SITA ACN support" >&5
echo "$as_me: Enabling SITA ACN support" >&6;}
V_PCAP=sita
V_FINDALLDEVS=sita
else
if test -z "$with_pcap" && test "$cross_compiling" = yes; then
{ { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
Expand Down Expand Up @@ -6356,6 +6377,8 @@ fi
fi
fi;
echo "$as_me:$LINENO: checking if --enable-ipv6 option is specified" >&5
echo $ECHO_N "checking if --enable-ipv6 option is specified... $ECHO_C" >&6
# Check whether --enable-ipv6 or --disable-ipv6 was given.
Expand Down Expand Up @@ -6685,22 +6708,6 @@ cat >>confdefs.h <<\_ACEOF
_ACEOF
fi
# Check whether --with-sita or --without-sita was given.
if test "${with_sita+set}" = set; then
withval="$with_sita"
cat >>confdefs.h <<\_ACEOF
#define SITA 1
_ACEOF
SSRC="pcap-sita.c"
{ echo "$as_me:$LINENO: Enabling SITA ACN support" >&5
echo "$as_me: Enabling SITA ACN support" >&6;}
V_FINDALLDEVS=sita
fi;
;;
dag)
Expand Down
24 changes: 15 additions & 9 deletions configure.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.143 2008-01-01 03:49:11 guy Exp $ (LBL)
dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.144 2008-01-06 20:23:17 guy Exp $ (LBL)
dnl
dnl Copyright (c) 1994, 1995, 1996, 1997
dnl The Regents of the University of California. All rights reserved.
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_REVISION($Revision: 1.143 $)
AC_REVISION($Revision: 1.144 $)
AC_PREREQ(2.50)
AC_INIT(pcap.c)

Expand Down Expand Up @@ -197,6 +197,18 @@ if test "$enable_protochain" = "disabled"; then
fi
AC_MSG_RESULT(${enable_protochain})

#
# SITA support is mutually exclusive with native capture support;
# "--with-sita" selects SITA support.
#
AC_ARG_WITH(sita, [ --with-sita include SITA support],
[
AC_DEFINE(SITA,1,[include ACN support])
AC_MSG_NOTICE(Enabling SITA ACN support)
V_PCAP=sita
V_FINDALLDEVS=sita
],
[
dnl
dnl Not all versions of test support -c (character special) but it's a
dnl better way of testing since the device might be protected. So we
Expand Down Expand Up @@ -335,6 +347,7 @@ else
;;
esac])
fi
])

AC_MSG_CHECKING(if --enable-ipv6 option is specified)
AC_ARG_ENABLE(ipv6, [ --enable-ipv6 build IPv6-capable version])
Expand Down Expand Up @@ -396,13 +409,6 @@ linux)
AC_MSG_ERROR(version 2 or higher required; see the INSTALL doc for more info)
fi
AC_LBL_TPACKET_STATS
AC_ARG_WITH(sita, [ --with-sita include SITA support],
[
AC_DEFINE(SITA,1,[include ACN support])
SSRC="pcap-sita.c"
AC_MSG_NOTICE(Enabling SITA ACN support)
V_FINDALLDEVS=sita
])
;;

dag)
Expand Down
5 changes: 2 additions & 3 deletions fad-sita.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
#include <string.h>
#include "pcap-int.h"

extern pcap_if_t *acn_if_list; /* pcap's list of available interfaces */
#include "pcap-sita.h"

extern int acn_parse_hosts_file(char *errbuf);
extern int acn_findalldevs(char *errbuf);
extern pcap_if_t *acn_if_list; /* pcap's list of available interfaces */

int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) {

Expand Down
12 changes: 7 additions & 5 deletions pcap-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.86 2007-10-17 18:52:41 guy Exp $ (LBL)
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.87 2008-01-06 20:23:17 guy Exp $ (LBL)
*/

#ifndef pcap_int_h
Expand Down Expand Up @@ -114,20 +114,22 @@ struct pcap_md {
char *device; /* device name */
#ifdef linux
int sock_packet; /* using Linux 2.0 compatible interface */
int timeout; /* timeout specified to pcap_open_live */
int clear_promisc; /* must clear promiscuous mode when we close */
int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */
int ifindex; /* interface index of device we're bound to */
int lo_ifindex; /* interface index of the loopback device */
struct pcap *next; /* list of open promiscuous sock_packet pcaps */
u_int packets_read; /* count of packets read with recvfrom() */
#endif
#endif /* linux */
#if defined(linux) || defined(SITA)
int timeout; /* timeout specified to pcap_open_live */
int clear_promisc; /* must clear promiscuous mode when we close */
#endif /* linux || SITA */

#ifdef HAVE_DAG_API
#ifdef HAVE_DAG_STREAMS_API
u_char *dag_mem_bottom; /* DAG card current memory bottom pointer */
u_char *dag_mem_top; /* DAG card current memory top pointer */
#else
#else /* HAVE_DAG_STREAMS_API */
void *dag_mem_base; /* DAG card memory base address */
u_int dag_mem_bottom; /* DAG card current memory bottom offset */
u_int dag_mem_top; /* DAG card current memory top offset */
Expand Down
29 changes: 1 addition & 28 deletions pcap-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.132 2008-01-05 22:32:31 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.133 2008-01-06 20:23:17 guy Exp $ (LBL)";
#endif

/*
Expand Down Expand Up @@ -103,10 +103,6 @@ static const char rcsid[] _U_ =
#include "pcap-bt-linux.h"
#endif

#ifdef SITA
#include "pcap-sita.h"
#endif

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -332,14 +328,8 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
handle->getnonblock_op = pcap_getnonblock_fd;
handle->setnonblock_op = pcap_setnonblock_fd;
handle->close_op = pcap_close_linux;

#ifdef SITA
handle->read_op = pcap_read_acn;
handle->stats_op = pcap_stats_acn;
#else
handle->read_op = pcap_read_linux;
handle->stats_op = pcap_stats_linux;
#endif

/*
* NULL and "any" are special devices which give us the hint to
Expand Down Expand Up @@ -375,12 +365,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
* trying both methods with the newer method preferred.
*/

#ifdef SITA
live_open_ok = acn_open_live((unsigned char *)device, ebuf, &handle->linktype);
handle->md.clear_promisc = promisc;
handle->fd = live_open_ok;
handle->bufsize = handle->snapshot;
#else
if ((err = live_open_new(handle, device, promisc, to_ms, ebuf)) == 1) {
live_open_ok = 1;
if (live_open_mmap(handle, ebuf) == 1)
Expand All @@ -391,7 +375,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
if (live_open_old(handle, device, promisc, to_ms, ebuf))
live_open_ok = 1;
}
#endif
if (!live_open_ok) {
/*
* Both methods to open the packet socket failed. Tidy
Expand All @@ -405,7 +388,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
return NULL;
}

#ifndef SITA
/*
* Compute the buffer size.
*
Expand Down Expand Up @@ -488,7 +470,6 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
}
handle->bufsize = handle->snapshot;
}
#endif

/* Allocate the buffer */

Expand Down Expand Up @@ -986,9 +967,6 @@ pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
return -1;
}

#ifdef SITA
return acn_setfilter(handle->fd, filter);
#else
/* Make our private copy of the filter */

if (install_bpf_program(handle, filter) < 0)
Expand Down Expand Up @@ -1104,7 +1082,6 @@ pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
#endif /* SO_ATTACH_FILTER */

return 0;
#endif /* SITA */
}

/*
Expand Down Expand Up @@ -2107,9 +2084,6 @@ static void pcap_close_all(void)

static void pcap_close_linux( pcap_t *handle )
{
#ifdef SITA
pcap_close_acn(handle);
#else
struct pcap *p, *prevp;
struct ifreq ifr;

Expand Down Expand Up @@ -2178,7 +2152,6 @@ static void pcap_close_linux( pcap_t *handle )
free(handle->md.device);
handle->md.device = NULL;
pcap_close_common(handle);
#endif /* SITA */
}

/*
Expand Down
Loading

0 comments on commit f57d847

Please sign in to comment.