summaryrefslogtreecommitdiffstats
path: root/contrib/libpcap
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libpcap')
-rw-r--r--contrib/libpcap/FREEBSD-upgrade36
-rw-r--r--contrib/libpcap/aclocal.m4900
-rw-r--r--contrib/libpcap/bpf/net/bpf.h419
-rw-r--r--contrib/libpcap/gencode.c274
-rw-r--r--contrib/libpcap/gencode.h6
-rw-r--r--contrib/libpcap/grammar.y6
-rw-r--r--contrib/libpcap/nametoaddr.c11
-rw-r--r--contrib/libpcap/nlpid.h1
-rw-r--r--contrib/libpcap/packaging/pcap.spec65
-rw-r--r--contrib/libpcap/pcap-int.h32
-rw-r--r--contrib/libpcap/pcap-namedb.h3
-rw-r--r--contrib/libpcap/pcap.348
-rw-r--r--contrib/libpcap/pcap.h24
-rw-r--r--contrib/libpcap/rawss7.h105
-rw-r--r--contrib/libpcap/scanner.l6
-rw-r--r--contrib/libpcap/snprintf.c632
16 files changed, 165 insertions, 2403 deletions
diff --git a/contrib/libpcap/FREEBSD-upgrade b/contrib/libpcap/FREEBSD-upgrade
new file mode 100644
index 0000000..78d134c
--- /dev/null
+++ b/contrib/libpcap/FREEBSD-upgrade
@@ -0,0 +1,36 @@
+$FreeBSD$
+
+This directory contains virgin copies of the original distribution files
+on a "vendor" branch. Do not, under any circumstances, attempt to upgrade
+the files in this directory via patches and a cvs commit.
+
+To upgrade to a newer version of libpcap, when it is available:
+ 1. Unpack the new version into an empty directory.
+ [Do not make ANY changes to the files.]
+
+ 2. Use the command:
+ cvs import -m 'Virgin import of LBL libpcap v<version>' \
+ -I SUNOS4 -I linux-include \
+ src/contrib/libpcap LBL v<version>
+
+ For example, to do the import of version 0.2.1, I typed:
+ cvs import -m 'Virgin import of LBL libpcap v0.2.1' \
+ -I SUNOS4 -I linux-include \
+ src/contrib/libpcap LBL v0_2_1
+
+ 3. Follow the instructions printed out in step 2 to resolve any
+ conflicts between local FreeBSD changes and the newer version.
+
+ 4. Update the shared library version number in
+ src/lib/libpcap/Makefile as described in the
+ handbook section 18.
+
+Do not, under any circumstances, deviate from this procedure.
+
+To make local changes to libpcap, simply patch and commit to the main
+branch (aka HEAD). Never make local changes on the LBL branch.
+
+All local changes should be submitted to "tcpdump-workers@tcpdump.org" for
+inclusion in the next vendor release of tcpdump and libpcap.
+
+pst@freebsd.org - 19 Aug 1996
diff --git a/contrib/libpcap/aclocal.m4 b/contrib/libpcap/aclocal.m4
deleted file mode 100644
index 1efb474..0000000
--- a/contrib/libpcap/aclocal.m4
+++ /dev/null
@@ -1,900 +0,0 @@
-dnl @(#) $Header: /tcpdump/master/libpcap/aclocal.m4,v 1.85.2.1 2005/04/21 03:42:09 guy Exp $ (LBL)
-dnl
-dnl Copyright (c) 1995, 1996, 1997, 1998
-dnl The Regents of the University of California. All rights reserved.
-dnl
-dnl Redistribution and use in source and binary forms, with or without
-dnl modification, are permitted provided that: (1) source code distributions
-dnl retain the above copyright notice and this paragraph in its entirety, (2)
-dnl distributions including binary code include the above copyright notice and
-dnl this paragraph in its entirety in the documentation or other materials
-dnl provided with the distribution, and (3) all advertising materials mentioning
-dnl features or use of this software display the following acknowledgement:
-dnl ``This product includes software developed by the University of California,
-dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
-dnl the University nor the names of its contributors may be used to endorse
-dnl or promote products derived from this software without specific prior
-dnl written permission.
-dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
-dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
-dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-dnl
-dnl LBL autoconf macros
-dnl
-
-dnl
-dnl Determine which compiler we're using (cc or gcc)
-dnl If using gcc, determine the version number
-dnl If using cc, require that it support ansi prototypes
-dnl If using gcc, use -O2 (otherwise use -O)
-dnl If using cc, explicitly specify /usr/local/include
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_C_INIT(copt, incls)
-dnl
-dnl results:
-dnl
-dnl $1 (copt set)
-dnl $2 (incls set)
-dnl CC
-dnl LDFLAGS
-dnl ac_cv_lbl_gcc_vers
-dnl LBL_CFLAGS
-dnl
-AC_DEFUN(AC_LBL_C_INIT,
- [AC_PREREQ(2.12)
- AC_BEFORE([$0], [AC_PROG_CC])
- AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
- AC_BEFORE([$0], [AC_LBL_DEVEL])
- AC_ARG_WITH(gcc, [ --without-gcc don't use gcc])
- $1="-O"
- $2=""
- if test "${srcdir}" != "." ; then
- $2="-I\$(srcdir)"
- fi
- if test "${CFLAGS+set}" = set; then
- LBL_CFLAGS="$CFLAGS"
- fi
- if test -z "$CC" ; then
- case "$target_os" in
-
- bsdi*)
- AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
- if test $SHLICC2 = yes ; then
- CC=shlicc2
- export CC
- fi
- ;;
- esac
- fi
- if test -z "$CC" -a "$with_gcc" = no ; then
- CC=cc
- export CC
- fi
- AC_PROG_CC
- if test "$GCC" = yes ; then
- if test "$SHLICC2" = yes ; then
- ac_cv_lbl_gcc_vers=2
- $1="-O2"
- else
- AC_MSG_CHECKING(gcc version)
- AC_CACHE_VAL(ac_cv_lbl_gcc_vers,
- ac_cv_lbl_gcc_vers=`$CC -v 2>&1 | \
- sed -e '/^gcc version /!d' \
- -e 's/^gcc version //' \
- -e 's/ .*//' -e 's/^[[[^0-9]]]*//' \
- -e 's/\..*//'`)
- AC_MSG_RESULT($ac_cv_lbl_gcc_vers)
- if test $ac_cv_lbl_gcc_vers -gt 1 ; then
- $1="-O2"
- fi
- fi
- else
- AC_MSG_CHECKING(that $CC handles ansi prototypes)
- AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes,
- AC_TRY_COMPILE(
- [#include <sys/types.h>],
- [int frob(int, char *)],
- ac_cv_lbl_cc_ansi_prototypes=yes,
- ac_cv_lbl_cc_ansi_prototypes=no))
- AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes)
- if test $ac_cv_lbl_cc_ansi_prototypes = no ; then
- case "$target_os" in
-
- hpux*)
- AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
- savedcflags="$CFLAGS"
- CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
- AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa,
- AC_TRY_COMPILE(
- [#include <sys/types.h>],
- [int frob(int, char *)],
- ac_cv_lbl_cc_hpux_cc_aa=yes,
- ac_cv_lbl_cc_hpux_cc_aa=no))
- AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa)
- if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then
- AC_MSG_ERROR(see the INSTALL doc for more info)
- fi
- CFLAGS="$savedcflags"
- V_CCOPT="-Aa $V_CCOPT"
- AC_DEFINE(_HPUX_SOURCE,1,[needed on HP-UX])
- ;;
-
- *)
- AC_MSG_ERROR(see the INSTALL doc for more info)
- ;;
- esac
- fi
- $2="$$2 -I/usr/local/include"
- LDFLAGS="$LDFLAGS -L/usr/local/lib"
-
- case "$target_os" in
-
- irix*)
- V_CCOPT="$V_CCOPT -xansi -signed -g3"
- ;;
-
- osf*)
- V_CCOPT="$V_CCOPT -std1 -g3"
- ;;
-
- ultrix*)
- AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
- AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
- AC_TRY_COMPILE(
- [#include <sys/types.h>],
- [struct a { int b; };
- void c(const struct a *)],
- ac_cv_lbl_cc_const_proto=yes,
- ac_cv_lbl_cc_const_proto=no))
- AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
- if test $ac_cv_lbl_cc_const_proto = no ; then
- AC_DEFINE(const,)
- fi
- ;;
- esac
- fi
-])
-
-#
-# Try compiling a sample of the type of code that appears in
-# gencode.c with "inline", "__inline__", and "__inline".
-#
-# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
-# as it just tests whether a function returning "int" can be inlined;
-# at least some versions of HP's C compiler can inline that, but can't
-# inline a function that returns a struct pointer.
-#
-# Make sure we use the V_CCOPT flags, because some of those might
-# disable inlining.
-#
-AC_DEFUN(AC_LBL_C_INLINE,
- [AC_MSG_CHECKING(for inline)
- save_CFLAGS="$CFLAGS"
- CFLAGS="$V_CCOPT"
- AC_CACHE_VAL(ac_cv_lbl_inline, [
- ac_cv_lbl_inline=""
- ac_lbl_cc_inline=no
- for ac_lbl_inline in inline __inline__ __inline
- do
- AC_TRY_COMPILE(
- [#define inline $ac_lbl_inline
- static inline struct iltest *foo(void);
- struct iltest {
- int iltest1;
- int iltest2;
- };
-
- static inline struct iltest *
- foo()
- {
- static struct iltest xxx;
-
- return &xxx;
- }],,ac_lbl_cc_inline=yes,)
- if test "$ac_lbl_cc_inline" = yes ; then
- break;
- fi
- done
- if test "$ac_lbl_cc_inline" = yes ; then
- ac_cv_lbl_inline=$ac_lbl_inline
- fi])
- CFLAGS="$save_CFLAGS"
- if test ! -z "$ac_cv_lbl_inline" ; then
- AC_MSG_RESULT($ac_cv_lbl_inline)
- else
- AC_MSG_RESULT(no)
- fi
- AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
-
-dnl
-dnl Use pfopen.c if available and pfopen() not in standard libraries
-dnl Require libpcap
-dnl Look for libpcap in ..
-dnl Use the installed libpcap if there is no local version
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_LIBPCAP(pcapdep, incls)
-dnl
-dnl results:
-dnl
-dnl $1 (pcapdep set)
-dnl $2 (incls appended)
-dnl LIBS
-dnl LBL_LIBS
-dnl
-AC_DEFUN(AC_LBL_LIBPCAP,
- [AC_REQUIRE([AC_LBL_LIBRARY_NET])
- dnl
- dnl save a copy before locating libpcap.a
- dnl
- LBL_LIBS="$LIBS"
- pfopen=/usr/examples/packetfilter/pfopen.c
- if test -f $pfopen ; then
- AC_CHECK_FUNCS(pfopen)
- if test $ac_cv_func_pfopen = "no" ; then
- AC_MSG_RESULT(Using $pfopen)
- LIBS="$LIBS $pfopen"
- fi
- fi
- AC_MSG_CHECKING(for local pcap library)
- libpcap=FAIL
- lastdir=FAIL
- places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
- egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
- for dir in $places ../libpcap libpcap ; do
- basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'`
- if test $lastdir = $basedir ; then
- dnl skip alphas when an actual release is present
- continue;
- fi
- lastdir=$dir
- if test -r $dir/pcap.c ; then
- libpcap=$dir/libpcap.a
- d=$dir
- dnl continue and select the last one that exists
- fi
- done
- if test $libpcap = FAIL ; then
- AC_MSG_RESULT(not found)
- AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
- if test $libpcap = FAIL ; then
- AC_MSG_ERROR(see the INSTALL doc for more info)
- fi
- else
- $1=$libpcap
- $2="-I$d $$2"
- AC_MSG_RESULT($libpcap)
- fi
- LIBS="$libpcap $LIBS"
- case "$target_os" in
-
- aix*)
- pseexe="/lib/pse.exp"
- AC_MSG_CHECKING(for $pseexe)
- if test -f $pseexe ; then
- AC_MSG_RESULT(yes)
- LIBS="$LIBS -I:$pseexe"
- fi
- ;;
- esac])
-
-dnl
-dnl Define RETSIGTYPE and RETSIGVAL
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_TYPE_SIGNAL
-dnl
-dnl results:
-dnl
-dnl RETSIGTYPE (defined)
-dnl RETSIGVAL (defined)
-dnl
-AC_DEFUN(AC_LBL_TYPE_SIGNAL,
- [AC_BEFORE([$0], [AC_LBL_LIBPCAP])
- AC_TYPE_SIGNAL
- if test "$ac_cv_type_signal" = void ; then
- AC_DEFINE(RETSIGVAL,[],[return value of signal handlers])
- else
- AC_DEFINE(RETSIGVAL,(0),[return value of signal handlers])
- fi
- case "$target_os" in
-
- irix*)
- AC_DEFINE(_BSD_SIGNALS,1,[get BSD semantics on Irix])
- ;;
-
- *)
- dnl prefer sigset() to sigaction()
- AC_CHECK_FUNCS(sigset)
- if test $ac_cv_func_sigset = no ; then
- AC_CHECK_FUNCS(sigaction)
- fi
- ;;
- esac])
-
-dnl
-dnl If using gcc, make sure we have ANSI ioctl definitions
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_FIXINCLUDES
-dnl
-AC_DEFUN(AC_LBL_FIXINCLUDES,
- [if test "$GCC" = yes ; then
- AC_MSG_CHECKING(for ANSI ioctl definitions)
- AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
- AC_TRY_COMPILE(
- [/*
- * This generates a "duplicate case value" when fixincludes
- * has not be run.
- */
-# include <sys/types.h>
-# include <sys/time.h>
-# include <sys/ioctl.h>
-# ifdef HAVE_SYS_IOCCOM_H
-# include <sys/ioccom.h>
-# endif],
- [switch (0) {
- case _IO('A', 1):;
- case _IO('B', 1):;
- }],
- ac_cv_lbl_gcc_fixincludes=yes,
- ac_cv_lbl_gcc_fixincludes=no))
- AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
- if test $ac_cv_lbl_gcc_fixincludes = no ; then
- # Don't cache failure
- unset ac_cv_lbl_gcc_fixincludes
- AC_MSG_ERROR(see the INSTALL for more info)
- fi
- fi])
-
-dnl
-dnl Check for flex, default to lex
-dnl Require flex 2.4 or higher
-dnl Check for bison, default to yacc
-dnl Default to lex/yacc if both flex and bison are not available
-dnl Define the yy prefix string if using flex and bison
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
-dnl
-dnl results:
-dnl
-dnl $1 (lex set)
-dnl $2 (yacc appended)
-dnl $3 (optional flex and bison -P prefix)
-dnl
-AC_DEFUN(AC_LBL_LEX_AND_YACC,
- [AC_ARG_WITH(flex, [ --without-flex don't use flex])
- AC_ARG_WITH(bison, [ --without-bison don't use bison])
- if test "$with_flex" = no ; then
- $1=lex
- else
- AC_CHECK_PROGS($1, flex, lex)
- fi
- if test "$$1" = flex ; then
- # The -V flag was added in 2.4
- AC_MSG_CHECKING(for flex 2.4 or higher)
- AC_CACHE_VAL(ac_cv_lbl_flex_v24,
- if flex -V >/dev/null 2>&1; then
- ac_cv_lbl_flex_v24=yes
- else
- ac_cv_lbl_flex_v24=no
- fi)
- AC_MSG_RESULT($ac_cv_lbl_flex_v24)
- if test $ac_cv_lbl_flex_v24 = no ; then
- s="2.4 or higher required"
- AC_MSG_WARN(ignoring obsolete flex executable ($s))
- $1=lex
- fi
- fi
- if test "$with_bison" = no ; then
- $2=yacc
- else
- AC_CHECK_PROGS($2, bison, yacc)
- fi
- if test "$$2" = bison ; then
- $2="$$2 -y"
- fi
- if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
- AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
- $1=lex
- $2=yacc
- fi
- if test "$$1" = flex -a -n "$3" ; then
- $1="$$1 -P$3"
- $2="$$2 -p $3"
- fi])
-
-dnl
-dnl Checks to see if union wait is used with WEXITSTATUS()
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_UNION_WAIT
-dnl
-dnl results:
-dnl
-dnl DECLWAITSTATUS (defined)
-dnl
-AC_DEFUN(AC_LBL_UNION_WAIT,
- [AC_MSG_CHECKING(if union wait is used)
- AC_CACHE_VAL(ac_cv_lbl_union_wait,
- AC_TRY_COMPILE([
-# include <sys/types.h>
-# include <sys/wait.h>],
- [int status;
- u_int i = WEXITSTATUS(status);
- u_int j = waitpid(0, &status, 0);],
- ac_cv_lbl_union_wait=no,
- ac_cv_lbl_union_wait=yes))
- AC_MSG_RESULT($ac_cv_lbl_union_wait)
- if test $ac_cv_lbl_union_wait = yes ; then
- AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
- else
- AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
- fi])
-
-dnl
-dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_SOCKADDR_SA_LEN
-dnl
-dnl results:
-dnl
-dnl HAVE_SOCKADDR_SA_LEN (defined)
-dnl
-AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
- [AC_MSG_CHECKING(if sockaddr struct has sa_len member)
- AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
- AC_TRY_COMPILE([
-# include <sys/types.h>
-# include <sys/socket.h>],
- [u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
- ac_cv_lbl_sockaddr_has_sa_len=yes,
- ac_cv_lbl_sockaddr_has_sa_len=no))
- AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
- if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
- AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has sa_len])
- fi])
-
-dnl
-dnl Checks to see if there's a sockaddr_storage structure
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_SOCKADDR_STORAGE
-dnl
-dnl results:
-dnl
-dnl HAVE_SOCKADDR_STORAGE (defined)
-dnl
-AC_DEFUN(AC_LBL_SOCKADDR_STORAGE,
- [AC_MSG_CHECKING(if sockaddr_storage struct exists)
- AC_CACHE_VAL(ac_cv_lbl_has_sockaddr_storage,
- AC_TRY_COMPILE([
-# include <sys/types.h>
-# include <sys/socket.h>],
- [u_int i = sizeof (struct sockaddr_storage)],
- ac_cv_lbl_has_sockaddr_storage=yes,
- ac_cv_lbl_has_sockaddr_storage=no))
- AC_MSG_RESULT($ac_cv_lbl_has_sockaddr_storage)
- if test $ac_cv_lbl_has_sockaddr_storage = yes ; then
- AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[if struct sockaddr_storage exists])
- fi])
-
-dnl
-dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
-dnl dl_module_id_1 member
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
-dnl
-dnl results:
-dnl
-dnl HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined)
-dnl
-dnl NOTE: any compile failure means we conclude that it doesn't have
-dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h>
-dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type,
-dnl we conclude it doesn't have that member (which is OK, as either we
-dnl won't be using code that would use that member, or we wouldn't
-dnl compile in any case).
-dnl
-AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1,
- [AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member)
- AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
- AC_TRY_COMPILE([
-# include <sys/types.h>
-# include <sys/dlpi.h>
-# include <sys/dlpi_ext.h>],
- [u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)],
- ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes,
- ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no))
- AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1)
- if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
- AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1,1,[if ppa_info_t_dl_module_id exists])
- fi])
-
-dnl
-dnl Checks to see if -R is used
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_HAVE_RUN_PATH
-dnl
-dnl results:
-dnl
-dnl ac_cv_lbl_have_run_path (yes or no)
-dnl
-AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
- [AC_MSG_CHECKING(for ${CC-cc} -R)
- AC_CACHE_VAL(ac_cv_lbl_have_run_path,
- [echo 'main(){}' > conftest.c
- ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
- if test ! -s conftest.out ; then
- ac_cv_lbl_have_run_path=yes
- else
- ac_cv_lbl_have_run_path=no
- fi
- rm -f conftest*])
- AC_MSG_RESULT($ac_cv_lbl_have_run_path)
- ])
-
-dnl
-dnl Due to the stupid way it's implemented, AC_CHECK_TYPE is nearly useless.
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_CHECK_TYPE
-dnl
-dnl results:
-dnl
-dnl int32_t (defined)
-dnl u_int32_t (defined)
-dnl
-AC_DEFUN(AC_LBL_CHECK_TYPE,
- [AC_MSG_CHECKING(for $1 using $CC)
- AC_CACHE_VAL(ac_cv_lbl_have_$1,
- AC_TRY_COMPILE([
-# include "confdefs.h"
-# include <sys/types.h>
-# if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-# endif],
- [$1 i],
- ac_cv_lbl_have_$1=yes,
- ac_cv_lbl_have_$1=no))
- AC_MSG_RESULT($ac_cv_lbl_have_$1)
- if test $ac_cv_lbl_have_$1 = no ; then
- AC_DEFINE($1, $2, [if we have $1])
- fi])
-
-dnl
-dnl Checks to see if unaligned memory accesses fail
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_UNALIGNED_ACCESS
-dnl
-dnl results:
-dnl
-dnl LBL_ALIGN (DEFINED)
-dnl
-AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
- [AC_MSG_CHECKING(if unaligned accesses fail)
- AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
- [case "$host_cpu" in
-
- #
- # These are CPU types where:
- #
- # the CPU faults on an unaligned access, but at least some
- # OSes that support that CPU catch the fault and simulate
- # the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
- # the simulation is slow, so we don't want to use it;
- #
- # the CPU, I infer (from the old
- #
- # XXX: should also check that they don't do weird things (like on arm)
- #
- # comment) doesn't fault on unaligned accesses, but doesn't
- # do a normal unaligned fetch, either (e.g., presumably, ARM);
- #
- # for whatever reason, the test program doesn't work
- # (this has been claimed to be the case for several of those
- # CPUs - I don't know what the problem is; the problem
- # was reported as "the test program dumps core" for SuperH,
- # but that's what the test program is *supposed* to do -
- # it dumps core before it writes anything, so the test
- # for an empty output file should find an empty output
- # file and conclude that unaligned accesses don't work).
- #
- # This run-time test won't work if you're cross-compiling, so
- # in order to support cross-compiling for a particular CPU,
- # we have to wire in the list of CPU types anyway, as far as
- # I know, so perhaps we should just have a set of CPUs on
- # which we know it doesn't work, a set of CPUs on which we
- # know it does work, and have the script just fail on other
- # cpu types and update it when such a failure occurs.
- #
- alpha*|arm*|hp*|mips*|sh*|sparc*|ia64|nv1)
- ac_cv_lbl_unaligned_fail=yes
- ;;
-
- *)
- cat >conftest.c <<EOF
-# include <sys/types.h>
-# include <sys/wait.h>
-# include <stdio.h>
- unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
- main() {
- unsigned int i;
- pid_t pid;
- int status;
- /* avoid "core dumped" message */
- pid = fork();
- if (pid < 0)
- exit(2);
- if (pid > 0) {
- /* parent */
- pid = waitpid(pid, &status, 0);
- if (pid < 0)
- exit(3);
- exit(!WIFEXITED(status));
- }
- /* child */
- i = *(unsigned int *)&a[[1]];
- printf("%d\n", i);
- exit(0);
- }
-EOF
- ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
- conftest.c $LIBS >/dev/null 2>&1
- if test ! -x conftest ; then
- dnl failed to compile for some reason
- ac_cv_lbl_unaligned_fail=yes
- else
- ./conftest >conftest.out
- if test ! -s conftest.out ; then
- ac_cv_lbl_unaligned_fail=yes
- else
- ac_cv_lbl_unaligned_fail=no
- fi
- fi
- rm -f conftest* core core.conftest
- ;;
- esac])
- AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
- if test $ac_cv_lbl_unaligned_fail = yes ; then
- AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
- fi])
-
-dnl
-dnl If using gcc and the file .devel exists:
-dnl Compile with -g (if supported) and -Wall
-dnl If using gcc 2, do extra prototype checking
-dnl If an os prototype include exists, symlink os-proto.h to it
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_DEVEL(copt)
-dnl
-dnl results:
-dnl
-dnl $1 (copt appended)
-dnl HAVE_OS_PROTO_H (defined)
-dnl os-proto.h (symlinked)
-dnl
-AC_DEFUN(AC_LBL_DEVEL,
- [rm -f os-proto.h
- if test "${LBL_CFLAGS+set}" = set; then
- $1="$$1 ${LBL_CFLAGS}"
- fi
- if test -f .devel ; then
- if test "$GCC" = yes ; then
- if test "${LBL_CFLAGS+set}" != set; then
- if test "$ac_cv_prog_cc_g" = yes ; then
- $1="-g $$1"
- fi
- $1="$$1 -Wall"
- if test $ac_cv_lbl_gcc_vers -gt 1 ; then
- $1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
- fi
- fi
- else
- case "$target_os" in
-
- irix6*)
- V_CCOPT="$V_CCOPT -n32"
- ;;
-
- *)
- ;;
- esac
- fi
- os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
- name="lbl/os-$os.h"
- if test -f $name ; then
- ln -s $name os-proto.h
- AC_DEFINE(HAVE_OS_PROTO_H,1,[if there's an os_proto.h])
- else
- AC_MSG_WARN(can't find $name)
- fi
- fi])
-
-dnl
-dnl Improved version of AC_CHECK_LIB
-dnl
-dnl Thanks to John Hawkinson (jhawk@mit.edu)
-dnl
-dnl usage:
-dnl
-dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
-dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
-dnl
-dnl results:
-dnl
-dnl LIBS
-dnl
-
-define(AC_LBL_CHECK_LIB,
-[AC_MSG_CHECKING([for $2 in -l$1])
-dnl Use a cache variable name containing both the library and function name,
-dnl because the test really is for library $1 defining function $2, not
-dnl just for library $1. Separate tests with the same $1 and different $2's
-dnl may have different results.
-ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
-AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
-[ac_save_LIBS="$LIBS"
-LIBS="-l$1 $5 $LIBS"
-AC_TRY_LINK(dnl
-ifelse([$2], [main], , dnl Avoid conflicting decl of main.
-[/* Override any gcc2 internal prototype to avoid an error. */
-]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
-extern "C"
-#endif
-])dnl
-[/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char $2();
-]),
- [$2()],
- eval "ac_cv_lbl_lib_$ac_lib_var=yes",
- eval "ac_cv_lbl_lib_$ac_lib_var=no")
-LIBS="$ac_save_LIBS"
-])dnl
-if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
- AC_MSG_RESULT(yes)
- ifelse([$3], ,
-[changequote(, )dnl
- ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
- -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
-changequote([, ])dnl
- AC_DEFINE_UNQUOTED($ac_tr_lib)
- LIBS="-l$1 $LIBS"
-], [$3])
-else
- AC_MSG_RESULT(no)
-ifelse([$4], , , [$4
-])dnl
-fi
-])
-
-dnl
-dnl AC_LBL_LIBRARY_NET
-dnl
-dnl This test is for network applications that need socket() and
-dnl gethostbyname() -ish functions. Under Solaris, those applications
-dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
-dnl with "-lnsl" but should *not* link with "-lsocket" because
-dnl libsocket.a breaks a number of things (for instance:
-dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
-dnl versions of IRIX).
-dnl
-dnl Unfortunately, many application developers are not aware of this,
-dnl and mistakenly write tests that cause -lsocket to be used under
-dnl IRIX. It is also easy to write tests that cause -lnsl to be used
-dnl under operating systems where neither are necessary (or useful),
-dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
-dnl
-dnl This test exists so that every application developer does not test
-dnl this in a different, and subtly broken fashion.
-
-dnl It has been argued that this test should be broken up into two
-dnl seperate tests, one for the resolver libraries, and one for the
-dnl libraries necessary for using Sockets API. Unfortunately, the two
-dnl are carefully intertwined and allowing the autoconf user to use
-dnl them independantly potentially results in unfortunate ordering
-dnl dependancies -- as such, such component macros would have to
-dnl carefully use indirection and be aware if the other components were
-dnl executed. Since other autoconf macros do not go to this trouble,
-dnl and almost no applications use sockets without the resolver, this
-dnl complexity has not been implemented.
-dnl
-dnl The check for libresolv is in case you are attempting to link
-dnl statically and happen to have a libresolv.a lying around (and no
-dnl libnsl.a).
-dnl
-AC_DEFUN(AC_LBL_LIBRARY_NET, [
- # Most operating systems have gethostbyname() in the default searched
- # libraries (i.e. libc):
- # Some OSes (eg. Solaris) place it in libnsl
- # Some strange OSes (SINIX) have it in libsocket:
- AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
- # Unfortunately libsocket sometimes depends on libnsl and
- # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
- if test "$ac_cv_search_gethostbyname" = "no"
- then
- AC_CHECK_LIB(socket, gethostbyname,
- LIBS="-lsocket -lnsl $LIBS", , -lnsl)
- fi
- AC_SEARCH_LIBS(socket, socket, ,
- AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
- # DLPI needs putmsg under HPUX so test for -lstr while we're at it
- AC_SEARCH_LIBS(putmsg, str)
- ])
-
-dnl
-dnl Test for __attribute__
-dnl
-
-AC_DEFUN(AC_C___ATTRIBUTE__, [
-AC_MSG_CHECKING(for __attribute__)
-AC_CACHE_VAL(ac_cv___attribute__, [
-AC_COMPILE_IFELSE(
- AC_LANG_SOURCE([[
-#include <stdlib.h>
-
-static void foo(void) __attribute__ ((noreturn));
-
-static void
-foo(void)
-{
- exit(1);
-}
-
-int
-main(int argc, char **argv)
-{
- foo();
-}
- ]]),
-ac_cv___attribute__=yes,
-ac_cv___attribute__=no)])
-if test "$ac_cv___attribute__" = "yes"; then
- AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
- V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
-else
- V_DEFS="$V_DEFS -D_U_=\"\""
-fi
-AC_MSG_RESULT($ac_cv___attribute__)
-])
-
-dnl
-dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
-dnl If so then pcap-linux.c can use this to report proper statistics.
-dnl
-dnl -Scott Barron
-dnl
-AC_DEFUN(AC_LBL_TPACKET_STATS,
- [AC_MSG_CHECKING(if if_packet.h has tpacket_stats defined)
- AC_CACHE_VAL(ac_cv_lbl_tpacket_stats,
- AC_TRY_COMPILE([
-# include <linux/if_packet.h>],
- [struct tpacket_stats stats],
- ac_cv_lbl_tpacket_stats=yes,
- ac_cv_lbl_tpacket_stats=no))
- AC_MSG_RESULT($ac_cv_lbl_tpacket_stats)
- if test $ac_cv_lbl_tpacket_stats = yes; then
- AC_DEFINE(HAVE_TPACKET_STATS,1,[if if_packet.h has tpacket_stats defined])
- fi])
diff --git a/contrib/libpcap/bpf/net/bpf.h b/contrib/libpcap/bpf/net/bpf.h
deleted file mode 100644
index 8c73f3a..0000000
--- a/contrib/libpcap/bpf/net/bpf.h
+++ /dev/null
@@ -1,419 +0,0 @@
-/*-
- * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from the Stanford/CMU enet packet filter,
- * (net/enet.c) distributed as part of 4.3BSD, and code contributed
- * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
- * Berkeley Laboratory.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)bpf.h 7.1 (Berkeley) 5/7/91
- *
- * @(#) $Header: /tcpdump/master/libpcap/bpf/net/bpf.h,v 1.51 2001/11/28 05:50:05 guy Exp $ (LBL)
- */
-
-#ifndef BPF_MAJOR_VERSION
-
-/* BSD style release date */
-#define BPF_RELEASE 199606
-
-typedef int bpf_int32;
-typedef u_int bpf_u_int32;
-
-/*
- * Alignment macros. BPF_WORDALIGN rounds up to the next
- * even multiple of BPF_ALIGNMENT.
- */
-#ifndef __NetBSD__
-#define BPF_ALIGNMENT sizeof(bpf_int32)
-#else
-#define BPF_ALIGNMENT sizeof(long)
-#endif
-#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
-
-#define BPF_MAXINSNS 512
-#define BPF_MAXBUFSIZE 0x8000
-#define BPF_MINBUFSIZE 32
-
-/*
- * Structure for BIOCSETF.
- */
-struct bpf_program {
- u_int bf_len;
- struct bpf_insn *bf_insns;
-};
-
-/*
- * Struct returned by BIOCGSTATS.
- */
-struct bpf_stat {
- u_int bs_recv; /* number of packets received */
- u_int bs_drop; /* number of packets dropped */
-};
-
-/*
- * Struct return by BIOCVERSION. This represents the version number of
- * the filter language described by the instruction encodings below.
- * bpf understands a program iff kernel_major == filter_major &&
- * kernel_minor >= filter_minor, that is, if the value returned by the
- * running kernel has the same major number and a minor number equal
- * equal to or less than the filter being downloaded. Otherwise, the
- * results are undefined, meaning an error may be returned or packets
- * may be accepted haphazardly.
- * It has nothing to do with the source code version.
- */
-struct bpf_version {
- u_short bv_major;
- u_short bv_minor;
-};
-/* Current version number of filter architecture. */
-#define BPF_MAJOR_VERSION 1
-#define BPF_MINOR_VERSION 1
-
-/*
- * BPF ioctls
- *
- * The first set is for compatibility with Sun's pcc style
- * header files. If your using gcc, we assume that you
- * have run fixincludes so the latter set should work.
- */
-#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
-#define BIOCGBLEN _IOR(B,102, u_int)
-#define BIOCSBLEN _IOWR(B,102, u_int)
-#define BIOCSETF _IOW(B,103, struct bpf_program)
-#define BIOCFLUSH _IO(B,104)
-#define BIOCPROMISC _IO(B,105)
-#define BIOCGDLT _IOR(B,106, u_int)
-#define BIOCGETIF _IOR(B,107, struct ifreq)
-#define BIOCSETIF _IOW(B,108, struct ifreq)
-#define BIOCSRTIMEOUT _IOW(B,109, struct timeval)
-#define BIOCGRTIMEOUT _IOR(B,110, struct timeval)
-#define BIOCGSTATS _IOR(B,111, struct bpf_stat)
-#define BIOCIMMEDIATE _IOW(B,112, u_int)
-#define BIOCVERSION _IOR(B,113, struct bpf_version)
-#define BIOCSTCPF _IOW(B,114, struct bpf_program)
-#define BIOCSUDPF _IOW(B,115, struct bpf_program)
-#else
-#define BIOCGBLEN _IOR('B',102, u_int)
-#define BIOCSBLEN _IOWR('B',102, u_int)
-#define BIOCSETF _IOW('B',103, struct bpf_program)
-#define BIOCFLUSH _IO('B',104)
-#define BIOCPROMISC _IO('B',105)
-#define BIOCGDLT _IOR('B',106, u_int)
-#define BIOCGETIF _IOR('B',107, struct ifreq)
-#define BIOCSETIF _IOW('B',108, struct ifreq)
-#define BIOCSRTIMEOUT _IOW('B',109, struct timeval)
-#define BIOCGRTIMEOUT _IOR('B',110, struct timeval)
-#define BIOCGSTATS _IOR('B',111, struct bpf_stat)
-#define BIOCIMMEDIATE _IOW('B',112, u_int)
-#define BIOCVERSION _IOR('B',113, struct bpf_version)
-#define BIOCSTCPF _IOW('B',114, struct bpf_program)
-#define BIOCSUDPF _IOW('B',115, struct bpf_program)
-#endif
-
-/*
- * Structure prepended to each packet.
- */
-struct bpf_hdr {
- struct timeval bh_tstamp; /* time stamp */
- bpf_u_int32 bh_caplen; /* length of captured portion */
- bpf_u_int32 bh_datalen; /* original length of packet */
- u_short bh_hdrlen; /* length of bpf header (this struct
- plus alignment padding) */
-};
-/*
- * Because the structure above is not a multiple of 4 bytes, some compilers
- * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
- * Only the kernel needs to know about it; applications use bh_hdrlen.
- */
-#if defined(KERNEL) || defined(_KERNEL)
-#define SIZEOF_BPF_HDR 18
-#endif
-
-/*
- * Data-link level type codes.
- */
-
-/*
- * These are the types that are the same on all platforms; on other
- * platforms, a <net/bpf.h> should be supplied that defines the additional
- * DLT_* codes appropriately for that platform (the BSDs, for example,
- * should not just pick up this version of "bpf.h"; they should also define
- * the additional DLT_* codes used by their kernels, as well as the values
- * defined here - and, if the values they use for particular DLT_ types
- * differ from those here, they should use their values, not the ones
- * here).
- */
-#define DLT_NULL 0 /* no link-layer encapsulation */
-#define DLT_EN10MB 1 /* Ethernet (10Mb) */
-#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
-#define DLT_AX25 3 /* Amateur Radio AX.25 */
-#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
-#define DLT_CHAOS 5 /* Chaos */
-#define DLT_IEEE802 6 /* IEEE 802 Networks */
-#define DLT_ARCNET 7 /* ARCNET */
-#define DLT_SLIP 8 /* Serial Line IP */
-#define DLT_PPP 9 /* Point-to-point Protocol */
-#define DLT_FDDI 10 /* FDDI */
-
-/*
- * These are values from the traditional libpcap "bpf.h".
- * Ports of this to particular platforms should replace these definitions
- * with the ones appropriate to that platform, if the values are
- * different on that platform.
- */
-#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */
-#define DLT_RAW 12 /* raw IP */
-
-/*
- * These are values from BSD/OS's "bpf.h".
- * These are not the same as the values from the traditional libpcap
- * "bpf.h"; however, these values shouldn't be generated by any
- * OS other than BSD/OS, so the correct values to use here are the
- * BSD/OS values.
- *
- * Platforms that have already assigned these values to other
- * DLT_ codes, however, should give these codes the values
- * from that platform, so that programs that use these codes will
- * continue to compile - even though they won't correctly read
- * files of these types.
- */
-#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
-#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
-
-#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
-
-/*
- * These values are defined by NetBSD; other platforms should refrain from
- * using them for other purposes, so that NetBSD savefiles with link
- * types of 50 or 51 can be read as this type on all platforms.
- */
-#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
-#define DLT_PPP_ETHER 51 /* PPP over Ethernet */
-
-/*
- * Values between 100 and 103 are used in capture file headers as
- * link-layer types corresponding to DLT_ types that differ
- * between platforms; don't use those values for new DLT_ new types.
- */
-
-/*
- * This value was defined by libpcap 0.5; platforms that have defined
- * it with a different value should define it here with that value -
- * a link type of 104 in a save file will be mapped to DLT_C_HDLC,
- * whatever value that happens to be, so programs will correctly
- * handle files with that link type regardless of the value of
- * DLT_C_HDLC.
- *
- * The name DLT_C_HDLC was used by BSD/OS; we use that name for source
- * compatibility with programs written for BSD/OS.
- *
- * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
- * for source compatibility with programs written for libpcap 0.5.
- */
-#define DLT_C_HDLC 104 /* Cisco HDLC */
-#define DLT_CHDLC DLT_C_HDLC
-
-#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
-
-/*
- * Values between 106 and 107 are used in capture file headers as
- * link-layer types corresponding to DLT_ types that might differ
- * between platforms; don't use those values for new DLT_ new types.
- */
-
-/*
- * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
- * that the AF_ type in the link-layer header is in network byte order.
- *
- * OpenBSD defines it as 12, but that collides with DLT_RAW, so we
- * define it as 108 here. If OpenBSD picks up this file, it should
- * define DLT_LOOP as 12 in its version, as per the comment above -
- * and should not use 108 as a DLT_ value.
- */
-#define DLT_LOOP 108
-
-/*
- * Values between 109 and 112 are used in capture file headers as
- * link-layer types corresponding to DLT_ types that might differ
- * between platforms; don't use those values for new DLT_ types
- * other than the corresponding DLT_ types.
- */
-
-/*
- * This is for Linux cooked sockets.
- */
-#define DLT_LINUX_SLL 113
-
-/*
- * Apple LocalTalk hardware.
- */
-#define DLT_LTALK 114
-
-/*
- * Acorn Econet.
- */
-#define DLT_ECONET 115
-
-/*
- * Reserved for use with OpenBSD ipfilter.
- */
-#define DLT_IPFILTER 116
-
-/*
- * Reserved for use in capture-file headers as a link-layer type
- * corresponding to OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD,
- * but that's DLT_LANE8023 in SuSE 6.3, so we can't use 17 for it
- * in capture-file headers.
- */
-#define DLT_PFLOG 117
-
-/*
- * Registered for Cisco-internal use.
- */
-#define DLT_CISCO_IOS 118
-
-/*
- * Reserved for 802.11 cards using the Prism II chips, with a link-layer
- * header including Prism monitor mode information plus an 802.11
- * header.
- */
-#define DLT_PRISM_HEADER 119
-
-/*
- * Reserved for Aironet 802.11 cards, with an Aironet link-layer header
- * (see Doug Ambrisko's FreeBSD patches).
- */
-#define DLT_AIRONET_HEADER 120
-
-/*
- * The instruction encodings.
- */
-/* instruction classes */
-#define BPF_CLASS(code) ((code) & 0x07)
-#define BPF_LD 0x00
-#define BPF_LDX 0x01
-#define BPF_ST 0x02
-#define BPF_STX 0x03
-#define BPF_ALU 0x04
-#define BPF_JMP 0x05
-#define BPF_RET 0x06
-#define BPF_MISC 0x07
-
-/* ld/ldx fields */
-#define BPF_SIZE(code) ((code) & 0x18)
-#define BPF_W 0x00
-#define BPF_H 0x08
-#define BPF_B 0x10
-#define BPF_MODE(code) ((code) & 0xe0)
-#define BPF_IMM 0x00
-#define BPF_ABS 0x20
-#define BPF_IND 0x40
-#define BPF_MEM 0x60
-#define BPF_LEN 0x80
-#define BPF_MSH 0xa0
-
-/* alu/jmp fields */
-#define BPF_OP(code) ((code) & 0xf0)
-#define BPF_ADD 0x00
-#define BPF_SUB 0x10
-#define BPF_MUL 0x20
-#define BPF_DIV 0x30
-#define BPF_OR 0x40
-#define BPF_AND 0x50
-#define BPF_LSH 0x60
-#define BPF_RSH 0x70
-#define BPF_NEG 0x80
-#define BPF_JA 0x00
-#define BPF_JEQ 0x10
-#define BPF_JGT 0x20
-#define BPF_JGE 0x30
-#define BPF_JSET 0x40
-#define BPF_SRC(code) ((code) & 0x08)
-#define BPF_K 0x00
-#define BPF_X 0x08
-
-/* ret - BPF_K and BPF_X also apply */
-#define BPF_RVAL(code) ((code) & 0x18)
-#define BPF_A 0x10
-
-/* misc */
-#define BPF_MISCOP(code) ((code) & 0xf8)
-#define BPF_TAX 0x00
-#define BPF_TXA 0x80
-
-/*
- * The instruction data structure.
- */
-struct bpf_insn {
- u_short code;
- u_char jt;
- u_char jf;
- bpf_int32 k;
-};
-
-/*
- * Macros for insn array initializers.
- */
-#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
-#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
-
-#if defined(BSD) && (defined(KERNEL) || defined(_KERNEL))
-/*
- * Systems based on non-BSD kernels don't have ifnet's (or they don't mean
- * anything if it is in <net/if.h>) and won't work like this.
- */
-# if __STDC__
-extern void bpf_tap(struct ifnet *, u_char *, u_int);
-extern void bpf_mtap(struct ifnet *, struct mbuf *);
-extern void bpfattach(struct ifnet *, u_int, u_int);
-extern void bpfilterattach(int);
-# else
-extern void bpf_tap();
-extern void bpf_mtap();
-extern void bpfattach();
-extern void bpfilterattach();
-# endif /* __STDC__ */
-#endif /* BSD && (_KERNEL || KERNEL) */
-#if __STDC__
-extern int bpf_validate(struct bpf_insn *, int);
-extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
-#else
-extern int bpf_validate();
-extern u_int bpf_filter();
-#endif
-
-/*
- * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
- */
-#define BPF_MEMWORDS 16
-
-#endif
diff --git a/contrib/libpcap/gencode.c b/contrib/libpcap/gencode.c
index 8672171..8830fcb 100644
--- a/contrib/libpcap/gencode.c
+++ b/contrib/libpcap/gencode.c
@@ -18,10 +18,12 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.34 2005/09/05 09:08:04 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.24 2005/06/20 21:52:53 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -84,6 +86,7 @@ static const char rcsid[] _U_ =
#endif /*INET6*/
#include <pcap-namedb.h>
+#undef ETHERMTU
#define ETHERMTU 1500
#ifndef IPPROTO_SCTP
@@ -100,8 +103,8 @@ static const char rcsid[] _U_ =
static jmp_buf top_ctx;
static pcap_t *bpf_pcap;
-/* Hack for updating VLAN, MPLS, and PPPoE offsets. */
-static u_int orig_linktype = -1U, orig_nl = -1U, label_stack_depth = -1U;
+/* Hack for updating VLAN, MPLS offsets. */
+static u_int orig_linktype = -1U, orig_nl = -1U;
/* XXX */
#ifdef PCAP_FDDIPAD
@@ -205,7 +208,6 @@ static struct block *gen_thostop(const u_char *, int);
static struct block *gen_wlanhostop(const u_char *, int);
static struct block *gen_ipfchostop(const u_char *, int);
static struct block *gen_dnhostop(bpf_u_int32, int);
-static struct block *gen_mpls_linktype(int);
static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int);
#ifdef INET6
static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int);
@@ -779,9 +781,6 @@ init_linktype(p)
off_proto = -1;
off_payload = -1;
- /*
- * And assume we're not doing SS7.
- */
off_sio = -1;
off_opc = -1;
off_dpc = -1;
@@ -794,7 +793,6 @@ init_linktype(p)
orig_linktype = -1;
orig_nl = -1;
- label_stack_depth = 0;
reg_ll_size = -1;
@@ -1118,12 +1116,8 @@ init_linktype(p)
off_nl_nosnap = PFLOG_HDRLEN; /* no 802.2 LLC */
return;
- case DLT_JUNIPER_MFR:
case DLT_JUNIPER_MLFR:
case DLT_JUNIPER_MLPPP:
- case DLT_JUNIPER_PPP:
- case DLT_JUNIPER_CHDLC:
- case DLT_JUNIPER_FRELAY:
off_linktype = 4;
off_nl = 4;
off_nl_nosnap = -1; /* no 802.2 LLC */
@@ -1144,7 +1138,6 @@ init_linktype(p)
/* frames captured on a Juniper PPPoE service PIC
* contain raw ethernet frames */
case DLT_JUNIPER_PPPOE:
- case DLT_JUNIPER_ETHER:
off_linktype = 16;
off_nl = 18; /* Ethernet II */
off_nl_nosnap = 21; /* 802.3+802.2 */
@@ -1861,25 +1854,6 @@ gen_linktype(proto)
{
struct block *b0, *b1, *b2;
- /* are we checking MPLS-encapsulated packets? */
- if (label_stack_depth > 0) {
- switch (proto) {
- case ETHERTYPE_IP:
- case PPP_IP:
- /* FIXME add other L3 proto IDs */
- return gen_mpls_linktype(Q_IP);
-
- case ETHERTYPE_IPV6:
- case PPP_IPV6:
- /* FIXME add other L3 proto IDs */
- return gen_mpls_linktype(Q_IPV6);
-
- default:
- bpf_error("unsupported protocol over mpls");
- /* NOTREACHED */
- }
- }
-
switch (linktype) {
case DLT_EN10MB:
@@ -2269,7 +2243,6 @@ gen_linktype(proto)
/*NOTREACHED*/
break;
- case DLT_JUNIPER_MFR:
case DLT_JUNIPER_MLFR:
case DLT_JUNIPER_MLPPP:
case DLT_JUNIPER_ATM1:
@@ -2280,10 +2253,6 @@ gen_linktype(proto)
case DLT_JUNIPER_ES:
case DLT_JUNIPER_MONITOR:
case DLT_JUNIPER_SERVICES:
- case DLT_JUNIPER_ETHER:
- case DLT_JUNIPER_PPP:
- case DLT_JUNIPER_FRELAY:
- case DLT_JUNIPER_CHDLC:
/* just lets verify the magic number for now -
* on ATM we may have up to 6 different encapsulations on the wire
* and need a lot of heuristics to figure out that the payload
@@ -3068,40 +3037,6 @@ gen_dnhostop(addr, dir)
return b1;
}
-/*
- * Generate a check for IPv4 or IPv6 for MPLS-encapsulated packets;
- * test the bottom-of-stack bit, and then check the version number
- * field in the IP header.
- */
-static struct block *
-gen_mpls_linktype(proto)
- int proto;
-{
- struct block *b0, *b1;
-
- switch (proto) {
-
- case Q_IP:
- /* match the bottom-of-stack bit */
- b0 = gen_mcmp(OR_NET, -2, BPF_B, 0x01, 0x01);
- /* match the IPv4 version number */
- b1 = gen_mcmp(OR_NET, 0, BPF_B, 0x40, 0xf0);
- gen_and(b0, b1);
- return b1;
-
- case Q_IPV6:
- /* match the bottom-of-stack bit */
- b0 = gen_mcmp(OR_NET, -2, BPF_B, 0x01, 0x01);
- /* match the IPv4 version number */
- b1 = gen_mcmp(OR_NET, 0, BPF_B, 0x60, 0xf0);
- gen_and(b0, b1);
- return b1;
-
- default:
- abort();
- }
-}
-
static struct block *
gen_host(addr, mask, proto, dir)
bpf_u_int32 addr;
@@ -3115,15 +3050,11 @@ gen_host(addr, mask, proto, dir)
case Q_DEFAULT:
b0 = gen_host(addr, mask, Q_IP, dir);
- /*
- * Only check for non-IPv4 addresses if we're not
- * checking MPLS-encapsulated packets.
- */
- if (label_stack_depth == 0) {
- b1 = gen_host(addr, mask, Q_ARP, dir);
- gen_or(b0, b1);
- b0 = gen_host(addr, mask, Q_RARP, dir);
- gen_or(b1, b0);
+ if (off_linktype != (u_int)-1) {
+ b1 = gen_host(addr, mask, Q_ARP, dir);
+ gen_or(b0, b1);
+ b0 = gen_host(addr, mask, Q_RARP, dir);
+ gen_or(b1, b0);
}
return b0;
@@ -4465,7 +4396,6 @@ gen_proto(v, proto, dir)
*
* So we always check for ETHERTYPE_IP.
*/
-
b0 = gen_linktype(ETHERTYPE_IP);
#ifndef CHASE_CHAIN
b1 = gen_cmp(OR_NET, 9, BPF_B, (bpf_int32)v);
@@ -6056,7 +5986,6 @@ gen_inbound(dir)
}
break;
- case DLT_JUNIPER_MFR:
case DLT_JUNIPER_MLFR:
case DLT_JUNIPER_MLPPP:
case DLT_JUNIPER_ATM1:
@@ -6067,10 +5996,6 @@ gen_inbound(dir)
case DLT_JUNIPER_ES:
case DLT_JUNIPER_MONITOR:
case DLT_JUNIPER_SERVICES:
- case DLT_JUNIPER_ETHER:
- case DLT_JUNIPER_PPP:
- case DLT_JUNIPER_FRELAY:
- case DLT_JUNIPER_CHDLC:
/* juniper flags (including direction) are stored
* the byte after the 3-byte magic number */
if (dir) {
@@ -6114,7 +6039,7 @@ gen_pf_ifname(const char *ifname)
return (b0);
}
-/* PF firewall log ruleset name */
+/* PF firewall log matched interface */
struct block *
gen_pf_ruleset(char *ruleset)
{
@@ -6253,11 +6178,7 @@ struct block *
gen_vlan(vlan_num)
int vlan_num;
{
- struct block *b0, *b1;
-
- /* can't check for VLAN-encapsulated packets inside MPLS */
- if (label_stack_depth > 0)
- bpf_error("no VLAN match after MPLS");
+ struct block *b0;
/*
* Change the offsets to point to the type and data fields within
@@ -6289,28 +6210,30 @@ gen_vlan(vlan_num)
* be done assuming a VLAN, even though the "or" could be viewed
* as meaning "or, if this isn't a VLAN packet...".
*/
- orig_linktype = off_linktype; /* save original values */
- orig_nl = off_nl;
+ orig_linktype = off_linktype; /* save original values */
+ orig_nl = off_nl;
- switch (linktype) {
+ switch (linktype) {
- case DLT_EN10MB:
- off_linktype += 4;
- off_nl_nosnap += 4;
- off_nl += 4;
- break;
+ case DLT_EN10MB:
+ off_linktype += 4;
+ off_nl_nosnap += 4;
+ off_nl += 4;
+ break;
- default:
- bpf_error("no VLAN support for data link type %d",
- linktype);
- /*NOTREACHED*/
- }
+ default:
+ bpf_error("no VLAN support for data link type %d",
+ linktype);
+ /*NOTREACHED*/
+ }
/* check for VLAN */
b0 = gen_cmp(OR_LINK, orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_8021Q);
/* If a specific VLAN is requested, check VLAN id */
if (vlan_num >= 0) {
+ struct block *b1;
+
b1 = gen_mcmp(OR_LINK, orig_nl, BPF_H, (bpf_int32)vlan_num,
0x0fff);
gen_and(b0, b1);
@@ -6327,7 +6250,7 @@ struct block *
gen_mpls(label_num)
int label_num;
{
- struct block *b0,*b1;
+ struct block *b0;
/*
* Change the offsets to point to the type and data fields within
@@ -6338,46 +6261,44 @@ gen_mpls(label_num)
*
* XXX - this is a bit of a kludge. See comments in gen_vlan().
*/
+ orig_linktype = off_linktype; /* save original values */
orig_nl = off_nl;
- if (label_stack_depth > 0) {
- /* just match the bottom-of-stack bit clear */
- b0 = gen_mcmp(OR_LINK, orig_nl-2, BPF_B, 0, 0x01);
- } else {
- /*
- * Indicate that we're checking MPLS-encapsulated headers,
- * to make sure higher level code generators don't try to
- * match against IP-related protocols such as Q_ARP, Q_RARP
- * etc.
- */
- switch (linktype) {
-
- case DLT_C_HDLC: /* fall through */
- case DLT_EN10MB:
- b0 = gen_cmp(OR_LINK, off_linktype, BPF_H,
- (bpf_int32)ETHERTYPE_MPLS);
- break;
-
- case DLT_PPP:
- b0 = gen_cmp(OR_LINK, off_linktype, BPF_H,
- (bpf_int32)PPP_MPLS_UCAST);
- break;
-
- /* FIXME add other DLT_s ...
- * for Frame-Relay/and ATM this may get messy due to SNAP headers
- * leave it for now */
-
- default:
- bpf_error("no MPLS support for data link type %d",
+ switch (linktype) {
+
+ case DLT_C_HDLC: /* fall through */
+ case DLT_EN10MB:
+ off_nl_nosnap += 4;
+ off_nl += 4;
+
+ b0 = gen_cmp(OR_LINK, orig_linktype, BPF_H,
+ (bpf_int32)ETHERTYPE_MPLS);
+ break;
+
+ case DLT_PPP:
+ off_nl_nosnap += 4;
+ off_nl += 4;
+
+ b0 = gen_cmp(OR_LINK, orig_linktype, BPF_H,
+ (bpf_int32)PPP_MPLS_UCAST);
+ break;
+
+ /* FIXME add other DLT_s ...
+ * for Frame-Relay/and ATM this may get messy due to SNAP headers
+ * leave it for now */
+
+ default:
+ bpf_error("no MPLS support for data link type %d",
linktype);
- b0 = NULL;
- /*NOTREACHED*/
- break;
- }
+ b0 = NULL;
+ /*NOTREACHED*/
+ break;
}
/* If a specific MPLS label is requested, check it */
if (label_num >= 0) {
+ struct block *b1;
+
label_num = label_num << 12; /* label is shifted 12 bits on the wire */
b1 = gen_mcmp(OR_LINK, orig_nl, BPF_W, (bpf_int32)label_num,
0xfffff000); /* only compare the first 20 bits */
@@ -6385,84 +6306,9 @@ gen_mpls(label_num)
b0 = b1;
}
- off_nl_nosnap += 4;
- off_nl += 4;
- label_stack_depth++;
return (b0);
}
-/*
- * Support PPPOE discovery and session.
- */
-struct block *
-gen_pppoed()
-{
- /* check for PPPoE discovery */
- return gen_linktype((bpf_int32)ETHERTYPE_PPPOED);
-}
-
-struct block *
-gen_pppoes()
-{
- struct block *b0;
-
- /*
- * Test against the PPPoE session link-layer type.
- */
- b0 = gen_linktype((bpf_int32)ETHERTYPE_PPPOES);
-
- /*
- * Change the offsets to point to the type and data fields within
- * the PPP packet.
- *
- * XXX - this is a bit of a kludge. If we were to split the
- * compiler into a parser that parses an expression and
- * generates an expression tree, and a code generator that
- * takes an expression tree (which could come from our
- * parser or from some other parser) and generates BPF code,
- * we could perhaps make the offsets parameters of routines
- * and, in the handler for an "AND" node, pass to subnodes
- * other than the PPPoE node the adjusted offsets.
- *
- * This would mean that "pppoes" would, instead of changing the
- * behavior of *all* tests after it, change only the behavior
- * of tests ANDed with it. That would change the documented
- * semantics of "pppoes", which might break some expressions.
- * However, it would mean that "(pppoes and ip) or ip" would check
- * both for VLAN-encapsulated IP and IP-over-Ethernet, rather than
- * checking only for VLAN-encapsulated IP, so that could still
- * be considered worth doing; it wouldn't break expressions
- * that are of the form "pppoes and ..." which I suspect are the
- * most common expressions involving "pppoes". "pppoes or ..."
- * doesn't necessarily do what the user would really want, now,
- * as all the "or ..." tests would be done assuming PPPoE, even
- * though the "or" could be viewed as meaning "or, if this isn't
- * a PPPoE packet...".
- */
- orig_linktype = off_linktype; /* save original values */
- orig_nl = off_nl;
-
- /*
- * The "network-layer" protocol is PPPoE, which has a 6-byte
- * PPPoE header, followed by PPP payload, so we set the
- * offsets to the network layer offset plus 6 bytes for
- * the PPPoE header plus the values appropriate for PPP when
- * encapsulated in Ethernet (which means there's no HDLC
- * encapsulation).
- */
- off_linktype = orig_nl + 6;
- off_nl = orig_nl + 6 + 2;
- off_nl_nosnap = orig_nl + 6 + 2;
-
- /*
- * Set the link-layer type to PPP, as all subsequent tests will
- * be on the encapsulated PPP header.
- */
- linktype = DLT_PPP;
-
- return b0;
-}
-
struct block *
gen_atmfield_code(atmfield, jvalue, jtype, reverse)
int atmfield;
diff --git a/contrib/libpcap/gencode.h b/contrib/libpcap/gencode.h
index 5abc251..d6dbd00 100644
--- a/contrib/libpcap/gencode.h
+++ b/contrib/libpcap/gencode.h
@@ -18,7 +18,8 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.6 2005/09/05 09:08:06 guy Exp $ (LBL)
+ * $FreeBSD$
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.5 2005/06/20 21:30:17 guy Exp $ (LBL)
*/
/*
@@ -289,9 +290,6 @@ struct block *gen_inbound(int);
struct block *gen_vlan(int);
struct block *gen_mpls(int);
-struct block *gen_pppoed(void);
-struct block *gen_pppoes(void);
-
struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse);
struct block *gen_atmtype_abbrev(int type);
struct block *gen_atmmulti_abbrev(int type);
diff --git a/contrib/libpcap/grammar.y b/contrib/libpcap/grammar.y
index c2f96f1..3e40006 100644
--- a/contrib/libpcap/grammar.y
+++ b/contrib/libpcap/grammar.y
@@ -19,10 +19,11 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
+ * $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.5 2005/09/05 09:08:06 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.86.2.4 2005/06/20 21:30:17 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -131,7 +132,6 @@ pcap_parse()
%token LEN
%token IPV6 ICMPV6 AH ESP
%token VLAN MPLS
-%token PPPOED PPPOES
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
%token STP
%token IPX
@@ -334,8 +334,6 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
| VLAN { $$ = gen_vlan(-1); }
| MPLS pnum { $$ = gen_mpls($2); }
| MPLS { $$ = gen_mpls(-1); }
- | PPPOED { $$ = gen_pppoed(); }
- | PPPOES { $$ = gen_pppoes(); }
| pfvar { $$ = $1; }
;
diff --git a/contrib/libpcap/nametoaddr.c b/contrib/libpcap/nametoaddr.c
index a795e49..fe4c582 100644
--- a/contrib/libpcap/nametoaddr.c
+++ b/contrib/libpcap/nametoaddr.c
@@ -20,6 +20,8 @@
*
* Name to id translation routines used by the scanner.
* These functions are not time critical.
+ *
+ * $FreeBSD$
*/
#ifndef lint
@@ -282,7 +284,16 @@ struct eproto {
/* Static data base of ether protocol types. */
struct eproto eproto_db[] = {
+#if 0
+ /* The FreeBSD elf linker generates a request to copy this array
+ * (including its size) when you link with -lpcap. In order to
+ * not bump the major version number of this libpcap.so, we need
+ * to ensure that the array stays the same size. Since PUP is
+ * likely never seen in real life any more, it's the first to
+ * be sacrificed (in favor of ip6).
+ */
{ "pup", ETHERTYPE_PUP },
+#endif
{ "xns", ETHERTYPE_NS },
{ "ip", ETHERTYPE_IP },
#ifdef INET6
diff --git a/contrib/libpcap/nlpid.h b/contrib/libpcap/nlpid.h
index c3ab8c2..7ea2963 100644
--- a/contrib/libpcap/nlpid.h
+++ b/contrib/libpcap/nlpid.h
@@ -15,6 +15,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
+ * $FreeBSD$
* @(#) $Header: /tcpdump/master/libpcap/nlpid.h,v 1.2 2002/12/06 00:01:34 hannes Exp $ (Juniper)
*/
diff --git a/contrib/libpcap/packaging/pcap.spec b/contrib/libpcap/packaging/pcap.spec
deleted file mode 100644
index e9ff7cf..0000000
--- a/contrib/libpcap/packaging/pcap.spec
+++ /dev/null
@@ -1,65 +0,0 @@
-%define prefix /usr
-%define version 0.8
-
-Summary: packet capture library
-Name: libpcap
-Version: %version
-Release: 1
-Group: Development/Libraries
-Copyright: BSD
-Source: libpcap-0.8.tar.gz
-BuildRoot: /tmp/%{name}-buildroot
-URL: http://www.tcpdump.org
-
-%description
-Packet-capture library LIBPCAP 0.8
-Now maintained by "The Tcpdump Group"
-See http://www.tcpdump.org
-Please send inquiries/comments/reports to tcpdump-workers@tcpdump.org
-
-%prep
-%setup
-
-%post
-ldconfig
-
-%build
-CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%prefix
-make
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT/usr/{lib,include}
-mkdir -p $RPM_BUILD_ROOT/usr/share/man
-mkdir -p $RPM_BUILD_ROOT/usr/include/net
-mkdir -p $RPM_BUILD_ROOT/usr/man/man3
-make install DESTDIR=$RPM_BUILD_ROOT mandir=/usr/share/man
-cd $RPM_BUILD_ROOT/usr/lib
-V1=`echo 0.8 | sed 's/\\.[^\.]*$//g'`
-V2=`echo 0.8 | sed 's/\\.[^\.]*\.[^\.]*$//g'`
-ln -sf libpcap.so.0.8 libpcap.so.$V1
-if test "$V2" -ne "$V1"; then
- ln -sf libpcap.so.$V1 libpcap.so.$V2
- ln -sf libpcap.so.$V2 libpcap.so
-else
- ln -sf libpcap.so.$V1 libpcap.so
-fi
-
-#install -m 755 -o root libpcap.a $RPM_BUILD_ROOT/usr/lib
-#install -m 644 -o root pcap.3 $RPM_BUILD_ROOT/usr/man/man3
-#install -m 644 -o root pcap.h $RPM_BUILD_ROOT/usr/include
-#install -m 644 -o root pcap-bpf.h $RPM_BUILD_ROOT/usr/include/net
-#install -m 644 -o root pcap-namedb.h $RPM_BUILD_ROOT/usr/include
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%files
-%defattr(-,root,root)
-%doc LICENSE CHANGES INSTALL.txt README.linux TODO VERSION CREDITS packaging/pcap.spec
-/usr/lib/libpcap.a
-/usr/share/man/man3/*
-/usr/include/pcap.h
-/usr/include/pcap-bpf.h
-/usr/include/pcap-namedb.h
-/usr/lib/libpcap.so*
diff --git a/contrib/libpcap/pcap-int.h b/contrib/libpcap/pcap-int.h
index dfa9170..01fe105 100644
--- a/contrib/libpcap/pcap-int.h
+++ b/contrib/libpcap/pcap-int.h
@@ -30,7 +30,8 @@
* 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.68.2.6 2005/07/07 06:56:04 guy Exp $ (LBL)
+ * $FreeBSD$
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68.2.2 2005/05/03 18:54:36 guy Exp $ (LBL)
*/
#ifndef pcap_int_h
@@ -91,21 +92,12 @@ struct pcap_md {
#endif
#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
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 */
-#endif /* HAVE_DAG_STREAMS_API */
+ u_int dag_mem_bottom; /* DAG card current memory bottom pointer */
+ u_int dag_mem_top; /* DAG card current memory top pointer */
int dag_fcs_bits; /* Number of checksum bits from link layer */
int dag_offset_flags; /* Flags to pass to dag_offset(). */
- int dag_stream; /* DAG stream number */
- int dag_timeout; /* timeout specified to pcap_open_live.
- * Same as in linux above, introduce
- * generally? */
-#endif /* HAVE_DAG_API */
+#endif
};
/*
@@ -160,7 +152,7 @@ struct pcap {
u_char *pkt;
/* We're accepting only packets in this direction/these directions. */
- pcap_direction_t direction;
+ direction_t direction;
/*
* Methods.
@@ -168,7 +160,7 @@ struct pcap {
int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
int (*inject_op)(pcap_t *, const void *, size_t);
int (*setfilter_op)(pcap_t *, struct bpf_program *);
- int (*setdirection_op)(pcap_t *, pcap_direction_t);
+ int (*setdirection_op)(pcap_t *, direction_t);
int (*set_datalink_op)(pcap_t *, int);
int (*getnonblock_op)(pcap_t *, char *);
int (*setnonblock_op)(pcap_t *, int, char *);
@@ -268,16 +260,6 @@ int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
#include <stdarg.h>
-#if !defined(HAVE_SNPRINTF)
-#define snprintf pcap_snprintf
-extern int snprintf (char *, size_t, const char *, ...);
-#endif
-
-#if !defined(HAVE_VSNPRINTF)
-#define vsnprintf pcap_vsnprintf
-extern int vsnprintf (char *, size_t, const char *, va_list ap);
-#endif
-
/*
* Routines that most pcap implementations can use for non-blocking mode.
*/
diff --git a/contrib/libpcap/pcap-namedb.h b/contrib/libpcap/pcap-namedb.h
index acaabd9..bbd06b0 100644
--- a/contrib/libpcap/pcap-namedb.h
+++ b/contrib/libpcap/pcap-namedb.h
@@ -30,7 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.10.2.1 2005/04/19 04:26:08 guy Exp $ (LBL)
+ * $FreeBSD$
+ * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.10 2005/03/17 07:02:32 guy Exp $ (LBL)
*/
#ifndef lib_pcap_namedb_h
diff --git a/contrib/libpcap/pcap.3 b/contrib/libpcap/pcap.3
index 727a53e..adf5729 100644
--- a/contrib/libpcap/pcap.3
+++ b/contrib/libpcap/pcap.3
@@ -1,4 +1,4 @@
-.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3,v 1.64.2.8 2005/09/07 08:29:17 guy Exp $
+.\" @(#) $Header: /tcpdump/master/libpcap/pcap.3,v 1.64.2.4 2005/06/03 20:36:56 guy Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@@ -19,6 +19,8 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
+.\" $FreeBSD$
+.\"
.TH PCAP 3 "27 February 2004"
.SH NAME
pcap \- Packet Capture library
@@ -80,7 +82,7 @@ int pcap_compile(pcap_t *p, struct bpf_program *fp,
char *str, int optimize, bpf_u_int32 netmask)
int pcap_setfilter(pcap_t *p, struct bpf_program *fp)
void pcap_freecode(struct bpf_program *)
-int pcap_setdirection(pcap_t *p, pcap_direction_t d)
+int pcap_setdirection(pcap_t *p, direction_t d)
.ft
.LP
.ft B
@@ -689,11 +691,7 @@ supplied to
as the source link-layer address, if the header contains such an
address, might be changed to be the address assigned to the interface on
which the packet it sent, if the platform doesn't support sending
-completely raw and unchanged packets. Even worse, some drivers on some
-platforms might change the link-layer type field to whatever value
-libpcap used when attaching to the device, even on platforms that
-.I do
-nominally support sending completely raw and unchanged packets.
+completely raw and unchanged packets.
.PP
.B pcap_sendpacket()
is like
@@ -785,23 +783,23 @@ has been made the filter program for a pcap structure by a call to
.PP
.B pcap_setdirection()
is used to specify a direction that packets will be captured.
-.I pcap_direction_t
+.I direction_t
is one of the constants
-.BR PCAP_D_IN ,
-.B PCAP_D_OUT
+.BR D_IN ,
+.B D_OUT
or
-.BR PCAP_D_INOUT .
-.B PCAP_D_IN
+.BR D_INOUT .
+.B D_IN
will only capture packets received by the device,
-.B PCAP_D_OUT
+.B D_OUT
will only capture packets sent by the device and
-.B PCAP_D_INOUT
+.B D_INOUT
will capture packets received by or sent by the device.
-.B PCAP_D_INOUT
+.B D_INOUT
is the default setting if this function is not called. This isn't
necessarily supported on all platforms; some platforms might return an
error, and some other platforms might not support
-.BR PCAP_D_OUT .
+.BR D_OUT .
This operation is not supported if a ``savefile'' is being read.
.B \-1
is returned on failure,
@@ -1117,6 +1115,24 @@ name. NULL is returned on failure.
translates a data link type value to a short description of that data
link type. NULL is returned on failure.
.PP
+.B pcap_list_datalinks()
+is used to get a list of the supported data link types of the interface
+associated with the pcap descriptor.
+.B pcap_list_datalinks()
+allocates an array to hold the list and sets
+.IR *dlt_buf .
+The caller is responsible for freeing the array.
+.B \-1
+is returned on failure;
+otherwise, the number of data link types in the array is returned.
+.PP
+.B pcap_set_datalink()
+is used to set the current data link type of the pcap descriptor
+to the type specified by
+.IR dlt .
+.B \-1
+is returned on failure.
+.PP
.B pcap_snapshot()
returns the snapshot length specified when
.B pcap_open_live()
diff --git a/contrib/libpcap/pcap.h b/contrib/libpcap/pcap.h
index 535c7da..a302ac7 100644
--- a/contrib/libpcap/pcap.h
+++ b/contrib/libpcap/pcap.h
@@ -31,21 +31,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52.2.5 2005/07/07 02:04:36 guy Exp $ (LBL)
+ * $FreeBSD$
+ * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52 2004/12/18 08:52:11 guy Exp $ (LBL)
*/
#ifndef lib_pcap_h
#define lib_pcap_h
-#if defined(WIN32)
- #include <pcap-stdinc.h>
-#elif defined(MSDOS)
- #include <sys/types.h>
- #include <sys/socket.h> /* u_int, u_char etc. */
-#else /* UN*X */
- #include <sys/types.h>
- #include <sys/time.h>
-#endif /* WIN32/MSDOS/UN*X */
+#include <sys/types.h>
+#include <sys/time.h>
#include <net/bpf.h>
@@ -119,10 +113,10 @@ struct pcap_file_header {
};
typedef enum {
- PCAP_D_INOUT = 0,
- PCAP_D_IN,
- PCAP_D_OUT
-} pcap_direction_t;
+ D_INOUT = 0,
+ D_IN,
+ D_OUT
+} direction_t;
/*
* Each packet in the dump file is prepended with this generic header.
@@ -222,7 +216,7 @@ int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
void pcap_breakloop(pcap_t *);
int pcap_stats(pcap_t *, struct pcap_stat *);
int pcap_setfilter(pcap_t *, struct bpf_program *);
-int pcap_setdirection(pcap_t *, pcap_direction_t);
+int pcap_setdirection(pcap_t *, direction_t);
int pcap_getnonblock(pcap_t *, char *);
int pcap_setnonblock(pcap_t *, int, char *);
void pcap_perror(pcap_t *, char *);
diff --git a/contrib/libpcap/rawss7.h b/contrib/libpcap/rawss7.h
deleted file mode 100644
index 8f8d058..0000000
--- a/contrib/libpcap/rawss7.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
-/*
- * Copyright (c) 2003 - The tcpdump group.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor of the Laboratory may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#) $Header: /tcpdump/master/libpcap/rawss7.h,v 1.1 2003/09/10 19:55:36 mcr Exp $ (LBL)
- */
-
-/*
- * This file is never used in libpcap or tcpdump. It is provided as
- * documentation linktypes 139 through 142 only.
- */
-
-/*
- * Date: Tue, 09 Sep 2003 09:41:04 -0400
- * From: Jeff Morriss <jeff.morriss[AT]ulticom.com>
- * To: tcpdump-workers@tcpdump.org
- * Subject: [tcpdump-workers] request for LINKTYPE_
- *
- * We've had some discussion over on ethereal-dev about a "fake link" or
- * "raw SS7" dissector that allows dumping an arbitrary protocol into a
- * file without any (otherwise necessary) lower level protocols. The
- * common example has been dumping MTP3 into a file without, well, MTP2 or
- * M2PA.
- *
- * We want to store these protocols directly in PCAP file format because
- * it's well defined and there isn't another (popular) file format for
- * capturing SS7 messages that we can reverse engineer (and we want to read
- * these files into Ethereal). Rather than creating a new file format, it's
- * a lot easier to just allocate a LINKTYPE_.
- *
- * Here is the original post thread:
- *
- * http://ethereal.com/lists/ethereal-dev/200306/threads.html#00200
- *
- * July's thread on the subject:
- *
- * http://ethereal.com/lists/ethereal-dev/200307/threads.html#00124
- *
- * August's thread:
- *
- * http://ethereal.com/lists/ethereal-dev/200308/threads.html#00193
- *
- *
- * and one of the last messages--which is why I'm mailing you today:
- *
- * http://ethereal.com/lists/ethereal-dev/200308/msg00193.html
- *
- *
- * Based on the message in the last URL, I'd like to request a new
- * LINKTYPE_: LINKTYPE_RAWSS7.
- *
- * This packets in this file type will contain a header:
- */
-
-typedef struct _rawss7_hdr {
- /* NOTE: These are in network-byte order. */
- guint32 type;
- guint16 length;
- guint16 spare;
-} rawss7_hdr;
-
-/*
- *
- * followed by protocol data for whatever protocol 'type' indicates.
- *
- * There was some discussion about these protocol 'type's being allocated by
- * tcpdump-workers as well. In fact it would be handy to have one place to
- * allocate such numbers, so what do you think about allocating 3 more (for
- * now) LINKTYPE_'s:
- */
-
-#define LINKTYPE_RAWSS7_MTP2 140
-#define LINKTYPE_RAWSS7_MTP3 141
-#define LINKTYPE_RAWSS7_SCCP 142
-
-/*
- *
- * There is no reason this can't be used to store non-SS7 protocols, but
- * it's what we need to use it for now...
- *
- */
diff --git a/contrib/libpcap/scanner.l b/contrib/libpcap/scanner.l
index 7650316..2bed45b 100644
--- a/contrib/libpcap/scanner.l
+++ b/contrib/libpcap/scanner.l
@@ -18,11 +18,13 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $FreeBSD$
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.4 2005/09/05 09:08:07 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.99.2.3 2005/06/20 21:30:19 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -262,8 +264,6 @@ outbound return OUTBOUND;
vlan return VLAN;
mpls return MPLS;
-pppoed return PPPOED;
-pppoes return PPPOES;
lane return LANE;
llc return LLC;
diff --git a/contrib/libpcap/snprintf.c b/contrib/libpcap/snprintf.c
deleted file mode 100644
index 111e78e..0000000
--- a/contrib/libpcap/snprintf.c
+++ /dev/null
@@ -1,632 +0,0 @@
-/*
- * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan
- * (Royal Institute of Technology, Stockholm, Sweden).
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/* $Id: snprintf.c,v 1.1 2003/12/15 01:35:05 guy Exp $ */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/snprintf.c,v 1.1 2003/12/15 01:35:05 guy Exp $";
-#endif
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-
-#include <pcap-int.h>
-
-enum format_flags {
- minus_flag = 1,
- plus_flag = 2,
- space_flag = 4,
- alternate_flag = 8,
- zero_flag = 16
-};
-
-/*
- * Common state
- */
-
-struct state {
- unsigned char *str;
- unsigned char *s;
- unsigned char *theend;
- size_t sz;
- size_t max_sz;
- int (*append_char)(struct state *, unsigned char);
- int (*reserve)(struct state *, size_t);
- /* XXX - methods */
-};
-
-#ifndef HAVE_VSNPRINTF
-static int
-sn_reserve (struct state *state, size_t n)
-{
- return state->s + n > state->theend;
-}
-
-static int
-sn_append_char (struct state *state, unsigned char c)
-{
- if (sn_reserve (state, 1)) {
- return 1;
- } else {
- *state->s++ = c;
- return 0;
- }
-}
-#endif
-
-#if 0
-static int
-as_reserve (struct state *state, size_t n)
-{
- if (state->s + n > state->theend) {
- int off = state->s - state->str;
- unsigned char *tmp;
-
- if (state->max_sz && state->sz >= state->max_sz)
- return 1;
-
- state->sz = max(state->sz * 2, state->sz + n);
- if (state->max_sz)
- state->sz = min(state->sz, state->max_sz);
- tmp = realloc (state->str, state->sz);
- if (tmp == NULL)
- return 1;
- state->str = tmp;
- state->s = state->str + off;
- state->theend = state->str + state->sz - 1;
- }
- return 0;
-}
-
-static int
-as_append_char (struct state *state, unsigned char c)
-{
- if(as_reserve (state, 1))
- return 1;
- else {
- *state->s++ = c;
- return 0;
- }
-}
-#endif
-
-static int
-append_number(struct state *state,
- unsigned long num, unsigned base, char *rep,
- int width, int prec, int flags, int minusp)
-{
- int len = 0;
- int i;
-
- /* given precision, ignore zero flag */
- if(prec != -1)
- flags &= ~zero_flag;
- else
- prec = 1;
- /* zero value with zero precision -> "" */
- if(prec == 0 && num == 0)
- return 0;
- do{
- if((*state->append_char)(state, rep[num % base]))
- return 1;
- len++;
- num /= base;
- }while(num);
- prec -= len;
- /* pad with prec zeros */
- while(prec-- > 0){
- if((*state->append_char)(state, '0'))
- return 1;
- len++;
- }
- /* add length of alternate prefix (added later) to len */
- if(flags & alternate_flag && (base == 16 || base == 8))
- len += base / 8;
- /* pad with zeros */
- if(flags & zero_flag){
- width -= len;
- if(minusp || (flags & space_flag) || (flags & plus_flag))
- width--;
- while(width-- > 0){
- if((*state->append_char)(state, '0'))
- return 1;
- len++;
- }
- }
- /* add alternate prefix */
- if(flags & alternate_flag && (base == 16 || base == 8)){
- if(base == 16)
- if((*state->append_char)(state, rep[10] + 23)) /* XXX */
- return 1;
- if((*state->append_char)(state, '0'))
- return 1;
- }
- /* add sign */
- if(minusp){
- if((*state->append_char)(state, '-'))
- return 1;
- len++;
- } else if(flags & plus_flag) {
- if((*state->append_char)(state, '+'))
- return 1;
- len++;
- } else if(flags & space_flag) {
- if((*state->append_char)(state, ' '))
- return 1;
- len++;
- }
- if(flags & minus_flag)
- /* swap before padding with spaces */
- for(i = 0; i < len / 2; i++){
- char c = state->s[-i-1];
- state->s[-i-1] = state->s[-len+i];
- state->s[-len+i] = c;
- }
- width -= len;
- while(width-- > 0){
- if((*state->append_char)(state, ' '))
- return 1;
- len++;
- }
- if(!(flags & minus_flag))
- /* swap after padding with spaces */
- for(i = 0; i < len / 2; i++){
- char c = state->s[-i-1];
- state->s[-i-1] = state->s[-len+i];
- state->s[-len+i] = c;
- }
-
- return 0;
-}
-
-static int
-append_string (struct state *state,
- unsigned char *arg,
- int width,
- int prec,
- int flags)
-{
- if(prec != -1)
- width -= prec;
- else
- width -= strlen((char *)arg);
- if(!(flags & minus_flag))
- while(width-- > 0)
- if((*state->append_char) (state, ' '))
- return 1;
- if (prec != -1) {
- while (*arg && prec--)
- if ((*state->append_char) (state, *arg++))
- return 1;
- } else {
- while (*arg)
- if ((*state->append_char) (state, *arg++))
- return 1;
- }
- if(flags & minus_flag)
- while(width-- > 0)
- if((*state->append_char) (state, ' '))
- return 1;
- return 0;
-}
-
-static int
-append_char(struct state *state,
- unsigned char arg,
- int width,
- int flags)
-{
- while(!(flags & minus_flag) && --width > 0)
- if((*state->append_char) (state, ' '))
- return 1;
-
- if((*state->append_char) (state, arg))
- return 1;
- while((flags & minus_flag) && --width > 0)
- if((*state->append_char) (state, ' '))
- return 1;
-
- return 0;
-}
-
-/*
- * This can't be made into a function...
- */
-
-#define PARSE_INT_FORMAT(res, arg, unsig) \
-if (long_flag) \
- res = (unsig long)va_arg(arg, unsig long); \
-else if (short_flag) \
- res = (unsig short)va_arg(arg, unsig int); \
-else \
- res = (unsig int)va_arg(arg, unsig int)
-
-/*
- * zyxprintf - return 0 or -1
- */
-
-static int
-xyzprintf (struct state *state, const char *char_format, va_list ap)
-{
- const unsigned char *format = (const unsigned char *)char_format;
- unsigned char c;
-
- while((c = *format++)) {
- if (c == '%') {
- int flags = 0;
- int width = 0;
- int prec = -1;
- int long_flag = 0;
- int short_flag = 0;
-
- /* flags */
- while((c = *format++)){
- if(c == '-')
- flags |= minus_flag;
- else if(c == '+')
- flags |= plus_flag;
- else if(c == ' ')
- flags |= space_flag;
- else if(c == '#')
- flags |= alternate_flag;
- else if(c == '0')
- flags |= zero_flag;
- else
- break;
- }
-
- if((flags & space_flag) && (flags & plus_flag))
- flags ^= space_flag;
-
- if((flags & minus_flag) && (flags & zero_flag))
- flags ^= zero_flag;
-
- /* width */
- if (isdigit(c))
- do {
- width = width * 10 + c - '0';
- c = *format++;
- } while(isdigit(c));
- else if(c == '*') {
- width = va_arg(ap, int);
- c = *format++;
- }
-
- /* precision */
- if (c == '.') {
- prec = 0;
- c = *format++;
- if (isdigit(c))
- do {
- prec = prec * 10 + c - '0';
- c = *format++;
- } while(isdigit(c));
- else if (c == '*') {
- prec = va_arg(ap, int);
- c = *format++;
- }
- }
-
- /* size */
-
- if (c == 'h') {
- short_flag = 1;
- c = *format++;
- } else if (c == 'l') {
- long_flag = 1;
- c = *format++;
- }
-
- switch (c) {
- case 'c' :
- if(append_char(state, va_arg(ap, int), width, flags))
- return -1;
- break;
- case 's' :
- if (append_string(state,
- va_arg(ap, unsigned char*),
- width,
- prec,
- flags))
- return -1;
- break;
- case 'd' :
- case 'i' : {
- long arg;
- unsigned long num;
- int minusp = 0;
-
- PARSE_INT_FORMAT(arg, ap, signed);
-
- if (arg < 0) {
- minusp = 1;
- num = -arg;
- } else
- num = arg;
-
- if (append_number (state, num, 10, "0123456789",
- width, prec, flags, minusp))
- return -1;
- break;
- }
- case 'u' : {
- unsigned long arg;
-
- PARSE_INT_FORMAT(arg, ap, unsigned);
-
- if (append_number (state, arg, 10, "0123456789",
- width, prec, flags, 0))
- return -1;
- break;
- }
- case 'o' : {
- unsigned long arg;
-
- PARSE_INT_FORMAT(arg, ap, unsigned);
-
- if (append_number (state, arg, 010, "01234567",
- width, prec, flags, 0))
- return -1;
- break;
- }
- case 'x' : {
- unsigned long arg;
-
- PARSE_INT_FORMAT(arg, ap, unsigned);
-
- if (append_number (state, arg, 0x10, "0123456789abcdef",
- width, prec, flags, 0))
- return -1;
- break;
- }
- case 'X' :{
- unsigned long arg;
-
- PARSE_INT_FORMAT(arg, ap, unsigned);
-
- if (append_number (state, arg, 0x10, "0123456789ABCDEF",
- width, prec, flags, 0))
- return -1;
- break;
- }
- case 'p' : {
- unsigned long arg = (unsigned long)va_arg(ap, void*);
-
- if (append_number (state, arg, 0x10, "0123456789ABCDEF",
- width, prec, flags, 0))
- return -1;
- break;
- }
- case 'n' : {
- int *arg = va_arg(ap, int*);
- *arg = state->s - state->str;
- break;
- }
- case '\0' :
- --format;
- /* FALLTHROUGH */
- case '%' :
- if ((*state->append_char)(state, c))
- return -1;
- break;
- default :
- if ( (*state->append_char)(state, '%')
- || (*state->append_char)(state, c))
- return -1;
- break;
- }
- } else
- if ((*state->append_char) (state, c))
- return -1;
- }
- return 0;
-}
-
-#ifndef HAVE_SNPRINTF
-int
-snprintf (char *str, size_t sz, const char *format, ...)
-{
- va_list args;
- int ret;
-
- va_start(args, format);
- ret = vsnprintf (str, sz, format, args);
-
-#ifdef PARANOIA
- {
- int ret2;
- char *tmp;
-
- tmp = malloc (sz);
- if (tmp == NULL)
- abort ();
-
- ret2 = vsprintf (tmp, format, args);
- if (ret != ret2 || strcmp(str, tmp))
- abort ();
- free (tmp);
- }
-#endif
-
- va_end(args);
- return ret;
-}
-#endif
-
-#if 0
-#ifndef HAVE_ASPRINTF
-int
-asprintf (char **ret, const char *format, ...)
-{
- va_list args;
- int val;
-
- va_start(args, format);
- val = vasprintf (ret, format, args);
-
-#ifdef PARANOIA
- {
- int ret2;
- char *tmp;
- tmp = malloc (val + 1);
- if (tmp == NULL)
- abort ();
-
- ret2 = vsprintf (tmp, format, args);
- if (val != ret2 || strcmp(*ret, tmp))
- abort ();
- free (tmp);
- }
-#endif
-
- va_end(args);
- return val;
-}
-#endif
-
-#ifndef HAVE_ASNPRINTF
-int
-asnprintf (char **ret, size_t max_sz, const char *format, ...)
-{
- va_list args;
- int val;
-
- va_start(args, format);
- val = vasnprintf (ret, max_sz, format, args);
-
-#ifdef PARANOIA
- {
- int ret2;
- char *tmp;
- tmp = malloc (val + 1);
- if (tmp == NULL)
- abort ();
-
- ret2 = vsprintf (tmp, format, args);
- if (val != ret2 || strcmp(*ret, tmp))
- abort ();
- free (tmp);
- }
-#endif
-
- va_end(args);
- return val;
-}
-#endif
-
-#ifndef HAVE_VASPRINTF
-int
-vasprintf (char **ret, const char *format, va_list args)
-{
- return vasnprintf (ret, 0, format, args);
-}
-#endif
-
-
-#ifndef HAVE_VASNPRINTF
-int
-vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
-{
- int st;
- size_t len;
- struct state state;
-
- state.max_sz = max_sz;
- state.sz = 1;
- state.str = malloc(state.sz);
- if (state.str == NULL) {
- *ret = NULL;
- return -1;
- }
- state.s = state.str;
- state.theend = state.s + state.sz - 1;
- state.append_char = as_append_char;
- state.reserve = as_reserve;
-
- st = xyzprintf (&state, format, args);
- if (st) {
- free (state.str);
- *ret = NULL;
- return -1;
- } else {
- char *tmp;
-
- *state.s = '\0';
- len = state.s - state.str;
- tmp = realloc (state.str, len+1);
- if (tmp == NULL) {
- free (state.str);
- *ret = NULL;
- return -1;
- }
- *ret = tmp;
- return len;
- }
-}
-#endif
-#endif
-
-#ifndef HAVE_VSNPRINTF
-int
-vsnprintf (char *str, size_t sz, const char *format, va_list args)
-{
- struct state state;
- int ret;
- unsigned char *ustr = (unsigned char *)str;
-
- state.max_sz = 0;
- state.sz = sz;
- state.str = ustr;
- state.s = ustr;
- state.theend = ustr + sz - 1;
- state.append_char = sn_append_char;
- state.reserve = sn_reserve;
-
- ret = xyzprintf (&state, format, args);
- *state.s = '\0';
- if (ret)
- return sz;
- else
- return state.s - state.str;
-}
-#endif
-
OpenPOWER on IntegriCloud