From f1107301e876358422b46c3217bc21ae039f7f42 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 19 Nov 2019 17:53:36 +0000 Subject: [PATCH] Update to libpcap 1.9.1 (initial commit, no Nmap-specific patches) --- libpcap/CHANGES | 72 + libpcap/CMakeLists.txt | 368 +- libpcap/CREDITS | 2 +- libpcap/INSTALL.md | 5 +- libpcap/Makefile.in | 62 +- ...01-Don-t-autogenerate-Lex-Yacc-files.patch | 103 - .../0002-Disable-unnecessary-features.patch | 64 - libpcap/NMAP_MODIFICATIONS/HOWTO-UPGRADE | 25 - libpcap/VERSION | 2 +- libpcap/aclocal.m4 | 25 +- libpcap/bpf_filter.c | 21 +- libpcap/cmake/Modules/FindPacket.cmake | 13 +- libpcap/cmakeconfig.h.in | 23 +- libpcap/config.h.in | 18 +- libpcap/configure | 1990 ++++-- libpcap/configure.ac | 357 +- libpcap/fmtutils.c | 99 +- libpcap/fmtutils.h | 5 + libpcap/ftmacros.h | 18 +- libpcap/gencode.c | 1883 ++++-- libpcap/gencode.h | 55 +- libpcap/grammar.c | 3665 ----------- libpcap/grammar.h | 323 - libpcap/grammar.y | 312 +- libpcap/missing/asprintf.c | 101 + libpcap/missing/snprintf.c | 12 +- libpcap/missing/strlcat.c | 61 + libpcap/missing/strlcpy.c | 56 + libpcap/missing/win_asprintf.c | 51 + libpcap/missing/win_snprintf.c | 12 + libpcap/nametoaddr.c | 17 +- libpcap/optimize.c | 316 +- libpcap/pcap-bpf.c | 108 +- libpcap/pcap-bt-linux.c | 15 +- libpcap/pcap-bt-monitor-linux.c | 3 +- libpcap/pcap-common.c | 76 +- libpcap/pcap-dag.c | 67 +- libpcap/pcap-dlpi.c | 14 +- libpcap/pcap-dos.c | 4 +- libpcap/pcap-filter.manmisc.in | 26 +- libpcap/pcap-int.h | 36 +- libpcap/pcap-libdlpi.c | 2 +- libpcap/pcap-linktype.manmisc.in | 2 +- libpcap/pcap-linux.c | 807 ++- libpcap/pcap-netfilter-linux.c | 4 +- libpcap/pcap-netmap.c | 2 +- libpcap/pcap-new.c | 85 +- libpcap/pcap-npf.c | 236 +- libpcap/pcap-null.c | 6 +- libpcap/pcap-rpcap.c | 622 +- libpcap/pcap-rpcap.h | 4 +- libpcap/pcap-savefile.manfile.in | 2 +- libpcap/pcap-septel.c | 11 +- libpcap/pcap-sita.c | 2 +- libpcap/pcap-sita.html | 2 +- libpcap/pcap-snf.c | 4 +- libpcap/pcap-tc.c | 23 +- libpcap/pcap-tstamp.manmisc.in | 19 +- libpcap/pcap-usb-linux.c | 273 +- libpcap/pcap.3pcap.in | 43 +- libpcap/pcap.c | 394 +- libpcap/pcap/bpf.h | 11 - libpcap/pcap/compiler-tests.h | 2 +- libpcap/pcap/dlt.h | 61 +- libpcap/pcap/funcattrs.h | 14 +- libpcap/pcap/pcap-inttypes.h | 11 + libpcap/pcap/pcap.h | 51 +- libpcap/pcap/sll.h | 40 +- libpcap/pcap/socket.h | 93 + libpcap/pcap_activate.3pcap | 8 +- libpcap/pcap_breakloop.3pcap | 23 +- libpcap/pcap_can_set_rfmon.3pcap | 6 +- libpcap/pcap_compile.3pcap.in | 23 +- libpcap/pcap_create.3pcap | 4 +- libpcap/pcap_datalink.3pcap.in | 4 +- libpcap/pcap_datalink_name_to_val.3pcap | 6 +- libpcap/pcap_datalink_val_to_name.3pcap | 14 +- libpcap/pcap_dump.3pcap | 9 +- libpcap/pcap_dump_file.3pcap | 2 +- libpcap/pcap_dump_flush.3pcap | 10 +- libpcap/pcap_dump_ftell.3pcap | 15 +- libpcap/pcap_dump_open.3pcap.in | 33 +- libpcap/pcap_file.3pcap | 16 +- libpcap/pcap_fileno.3pcap | 21 +- libpcap/pcap_findalldevs.3pcap | 37 +- libpcap/pcap_freecode.3pcap | 6 +- libpcap/pcap_get_selectable_fd.3pcap | 42 +- libpcap/pcap_get_tstamp_precision.3pcap.in | 4 + libpcap/pcap_inject.3pcap | 22 +- libpcap/pcap_is_swapped.3pcap | 4 +- libpcap/pcap_list_datalinks.3pcap.in | 14 +- libpcap/pcap_list_tstamp_types.3pcap.in | 23 +- libpcap/pcap_lookupdev.3pcap | 11 +- libpcap/pcap_lookupnet.3pcap | 9 +- libpcap/pcap_loop.3pcap | 37 +- libpcap/pcap_next_ex.3pcap | 26 +- libpcap/pcap_offline_filter.3pcap | 4 +- libpcap/pcap_open_dead.3pcap.in | 11 +- libpcap/pcap_open_live.3pcap | 2 +- libpcap/pcap_open_offline.3pcap.in | 9 +- libpcap/pcap_set_datalink.3pcap | 16 +- libpcap/pcap_set_immediate_mode.3pcap | 47 - libpcap/pcap_set_timeout.3pcap | 2 +- libpcap/pcap_set_tstamp_precision.3pcap.in | 13 +- libpcap/pcap_set_tstamp_type.3pcap.in | 21 +- libpcap/pcap_setdirection.3pcap | 15 +- libpcap/pcap_setfilter.3pcap | 17 +- libpcap/pcap_setnonblock.3pcap | 22 +- libpcap/pcap_snapshot.3pcap | 8 +- libpcap/pcap_stats.3pcap | 17 +- libpcap/pcap_strerror.3pcap | 2 +- libpcap/pcap_tstamp_type_name_to_val.3pcap | 5 +- libpcap/pcap_tstamp_type_val_to_name.3pcap | 5 +- libpcap/portability.h | 91 +- libpcap/rpcap-protocol.h | 157 +- libpcap/savefile.c | 49 +- libpcap/scanner.c | 5463 ----------------- libpcap/scanner.h | 383 -- libpcap/scanner.l | 37 +- libpcap/sf-pcap.c | 169 +- libpcap/sf-pcap.h | 2 +- libpcap/sf-pcapng.c | 145 +- libpcap/sf-pcapng.h | 2 +- libpcap/sockutils.c | 332 +- libpcap/sockutils.h | 76 +- 125 files changed, 7238 insertions(+), 13624 deletions(-) delete mode 100644 libpcap/NMAP_MODIFICATIONS/0001-Don-t-autogenerate-Lex-Yacc-files.patch delete mode 100644 libpcap/NMAP_MODIFICATIONS/0002-Disable-unnecessary-features.patch delete mode 100644 libpcap/NMAP_MODIFICATIONS/HOWTO-UPGRADE delete mode 100644 libpcap/grammar.c delete mode 100644 libpcap/grammar.h create mode 100644 libpcap/missing/asprintf.c create mode 100644 libpcap/missing/strlcat.c create mode 100644 libpcap/missing/strlcpy.c create mode 100644 libpcap/missing/win_asprintf.c create mode 100644 libpcap/pcap/socket.h delete mode 100644 libpcap/pcap_set_immediate_mode.3pcap delete mode 100644 libpcap/scanner.c delete mode 100644 libpcap/scanner.h diff --git a/libpcap/CHANGES b/libpcap/CHANGES index 4607f14a2..89e739c46 100644 --- a/libpcap/CHANGES +++ b/libpcap/CHANGES @@ -1,3 +1,75 @@ +Sunday, July 22, 2018 + Summary for 1.9.1 libpcap release + Mention pcap_get_required_select_timeout() in the main pcap man page + Fix pcap-usb-linux.c build on systems with musl + Fix assorted man page and other documentation issues + Plug assorted memory leaks + Documentation changes to use https: + Changes to how time stamp calculations are done + Lots of tweaks to make newer compilers happier and warning-free and + to fix instances of C undefined behavior + Warn if AC_PROG_CC_C99 can't enable C99 support + Rename pcap_set_protocol() to pcap_set_protocol_linux(). + Align pcap_t private data on an 8-byte boundary. + Fix various error messages + Use 64-bit clean API in dag_findalldevs() + Fix cleaning up after some errors + Work around some ethtool ioctl bugs in newer Linux kernels (GitHub + issue #689) + Add backwards compatibility sections to some man pages (GitHub issue + #745) + Fix autotool configuration on AIX and macOS + Don't export bpf_filter_with_aux_data() or struct bpf_aux_data; + they're internal-only and subject to change + Fix pcapng block size checking + On macOS, don't build rpcapd or test programs any fatter than they + need to be + Fix reading of capture statistics for Linux USB + Fix packet size values for Linux USB packets (GitHub issue #808) + Check only VID in VLAN test in filterss (GitHub issue #461) + Fix pcap_list_datalinks on 802.11 devices on macOS + Fix overflows with very large snapshot length in pcap file + Improve parsing of rpcapd configuration file (GitHub issue #767) + Handle systems without strlcpy() or strlcat() better + Fix crashes and other errors with invalid filter expressions + Fix use of uninitialized file descriptor in remote capture + Fix some CMake issues + Fix some divide-by-zero issues with the filter compiler + Work around a GNU libc bug in pcap_nametonetaddr() + Add support for DLT_LINUX_SLL2 + Fix handling of the packet-count argument for Myricom SNF devices + Fix --disable-rdma in configure script (GitHub issue #782) + Fix compilation of TurboCap support (GitHub issue #764) + Constify first argument to pcap_findalldevs_ex() + Fix a number of issues when running rpcapd as an inetd-style daemon + Fix CMake issues with D-Bus libraries + In rpcapd, clean up termination of a capture session + Redo remote capture protocol negotiation + In rpcapd, report the same error for "invalid user name" and + "invalid password", to make brute-forcing harder + For remote captures, add an error code for "the server requires TLS" + Fix pcap_dump_fopen() on Windows to avoid clashes between + {Win,N}Pcap and application C runtimes + Fix exporting of functions from Windows DLLs (GitHub issue #810) + Fix building as part of Npcap + Allow rpcapd to rebind more rapidly + Fix building shared libpcap library on midipix (midipix.org) + Fix hack to detect UTF-16LE adapter names on Windows not to go past + the end of the string + Fix handling of "wireless WAN" (mobile phone network modems) on + Windows with WinPcap/Npcap (GitHub issue #824) + Have pcap_dump_open_append() create the dump file if it doesn't + exists (GitHub issue #247) + Fix the maxmum snapshot length for DLT_USBPCAP + Use -fPIC when building for 64-bit SPARC on Linux (GitHub issue #837) + Fix CMake 64-bit library installation directory on some Linux + distributions + Boost the TPACKET_V3 timeout to the maximum if a timeout of 0 was + specified + Five CVE-2019-15161, CVE-2019-15162, CVE-2019-15163, CVE-2019-15164, CVE-2019-15165 + Fixes for CVE-2018-16301, errors in pcapng reading. + PCAPNG reader applies some sanity checks before doing malloc(). + Sunday, June 24, 2018, by mcr@sandelman.ca Summary for 1.9.0 libpcap release Added testing system to libpcap, independent of tcpdump diff --git a/libpcap/CMakeLists.txt b/libpcap/CMakeLists.txt index 905ba61aa..55b93f14d 100644 --- a/libpcap/CMakeLists.txt +++ b/libpcap/CMakeLists.txt @@ -9,7 +9,7 @@ if(POLICY CMP0042) cmake_policy(SET CMP0042 OLD) endif() -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) project(pcap) @@ -135,83 +135,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") option(BUILD_WITH_LIBNL "Build with libnl" ON) endif() -# -# By default, build universal with the appropriate set of architectures -# for the OS on which we're doing the build. -# -if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") - # - # Get the major version of Darwin. - # - string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}") - - if(SYSTEM_VERSION_MAJOR LESS 8) - # - # Pre-Tiger. Build only for 32-bit PowerPC. - # - set(CMAKE_OSX_ARCHITECTURES "ppc") - elseif(SYSTEM_VERSION_MAJOR EQUAL 8) - # - # Tiger. Is this prior to, or with, Intel support? - # - # Get the minor version of Darwin. - # - string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION}) - string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}") - if(SYSTEM_VERSION_MINOR LESS 4) - # - # Prior to Intel support. Build for 32-bit - # PowerPC and 64-bit PowerPC, with 32-bit PowerPC - # first. (I'm guessing that's what Apple does.) - # - set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64") - elseif(SYSTEM_VERSION_MINOR LESS 7) - # - # With Intel support but prior to x86-64 support. - # Build for 32-bit PowerPC, 64-bit PowerPC, and x86, - # with 32-bit PowerPC first. - # (I'm guessing that's what Apple does.) - # - set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386") - else() - # - # With Intel support including x86-64 support. - # Build for 32-bit PowerPC, 64-bit PowerPC, x86, - # and x86-64, with 32-bit PowerPC first. - # (I'm guessing that's what Apple does.) - # - set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64") - endif() - elseif(SYSTEM_VERSION_MAJOR EQUAL 9) - # - # Leopard. Build for 32-bit PowerPC, 64-bit - # PowerPC, x86, and x86-64, with 32-bit PowerPC - # first. (That's what Apple does.) - # - set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64") - elseif(SYSTEM_VERSION_MAJOR EQUAL 10) - # - # Snow Leopard. Build for x86-64, x86, and - # 32-bit PowerPC, with x86-64 first. (That's - # what Apple does, even though Snow Leopard - # doesn't run on PPC, so PPC libpcap runs under - # Rosetta, and Rosetta doesn't support BPF - # ioctls, so PPC programs can't do live - # captures.) - # - set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc") - else() - # - # Post-Snow Leopard. Build for x86-64 and - # x86, with x86-64 first. (That's probably what - # Apple does, given that Rosetta is gone.) - # XXX - update if and when Apple drops support - # for 32-bit x86 code. - # - set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") - endif() -endif() - # # Additional capture modules. # @@ -233,7 +156,7 @@ option(DISABLE_RDMA "Disable RDMA sniffing support" OFF) option(DISABLE_DAG "Disable Endace DAG card support" OFF) option(DISABLE_SEPTEL "Disable Septel card support" OFF) -set(SEPTEL_ROOT "${CMAKE_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API") +set(SEPTEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API") option(DISABLE_SNF "Disable Myricom SNF support" OFF) @@ -289,6 +212,7 @@ include_directories( include(CheckFunctionExists) include(CMakePushCheckState) +include(CheckSymbolExists) if(WIN32) @@ -310,6 +234,14 @@ if(WIN32) cmake_pop_check_state() endif(PACKET_FOUND) + message(STATUS "checking for Npcap's version.h") + check_symbol_exists(WINPCAP_PRODUCT_NAME "../../version.h" HAVE_VERSION_H) + if(HAVE_VERSION_H) + message(STATUS "HAVE version.h") + else(HAVE_VERSION_H) + message(STATUS "MISSING version.h") + endif(HAVE_VERSION_H) + endif(WIN32) if(MSVC) @@ -343,6 +275,11 @@ include(CheckIncludeFiles) include(CheckStructHasMember) include(CheckTypeSize) +# +# Tests are a bit expensive with Visual Studio on Windows, so, on +# Windows, we skip tests for UN*X-only headers and functions. +# + # # Header files. # @@ -395,12 +332,44 @@ endif(NOT WIN32) # check_function_exists(strerror HAVE_STRERROR) check_function_exists(strerror_r HAVE_STRERROR_R) -check_function_exists(strerror_s HAVE_STRERROR_S) +if(HAVE_STRERROR_R) + # + # We have strerror_r; if we define _GNU_SOURCE, is it a + # POSIX-compliant strerror_r() or a GNU strerror_r()? + # + check_c_source_compiles( +"#define _GNU_SOURCE +#include + +/* Define it GNU-style; that will cause an error if it's not GNU-style */ +extern char *strerror_r(int, char *, size_t); + +int +main(void) +{ + return 0; +} +" + HAVE_GNU_STRERROR_R) + if(NOT HAVE_GNU_STRERROR_R) + set(HAVE_POSIX_STRERROR_R YES) + endif(NOT HAVE_GNU_STRERROR_R) +else(HAVE_STRERROR_R) + # + # We don't have strerror_r; do we have strerror_s? + # + check_function_exists(strerror_s HAVE_STRERROR_S) +endif(HAVE_STRERROR_R) check_function_exists(strlcpy HAVE_STRLCPY) check_function_exists(strlcat HAVE_STRLCAT) check_function_exists(snprintf HAVE_SNPRINTF) check_function_exists(vsnprintf HAVE_VSNPRINTF) +check_function_exists(asprintf HAVE_ASPRINTF) +check_function_exists(vasprintf HAVE_VASPRINTF) check_function_exists(strtok_r HAVE_STRTOK_R) +if(NOT WIN32) + check_function_exists(vsyslog HAVE_VSYSLOG) +endif() # # These tests are for network applications that need socket functions @@ -429,7 +398,6 @@ check_function_exists(strtok_r HAVE_STRTOK_R) # set(PCAP_LINK_LIBRARIES "") include(CheckLibraryExists) -include(CheckSymbolExists) if(WIN32) # # We need winsock2.h and ws2tcpip.h. @@ -865,11 +833,61 @@ set(PROJECT_SOURCE_LIST_C ) if(WIN32) - set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c) + # + # For now, we assume we don't have snprintf() or that it's not one + # that behaves enough like C99's snprintf() for our purposes (i.e., + # it doesn't null-terminate the string if it truncates it to fit in + # the buffer), so we have to provide our own (a wrapper around + # _snprintf() that null-terminates the buffer). + # + # We also assume we don't have asprintf(), and provide an implementation + # that uses _vscprintf() to determine how big the string needs to be. + # + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} + missing/win_snprintf.c missing/win_asprintf.c) else() + # + # Either: + # + # we have snprintf() and vsnprintf(), and have asprintf() and + # vasprintf(); + # + # we have snprintf() and vsnprintf(), but don't have asprintf() + # or vasprintf(); + # + # we have neither snprintf() nor vsnprintf(), and don't have + # asprintf() or vasprintf(), either. + # + # We assume that if we have asprintf() we have vasprintf(), as well + # as snprintf() and vsnprintf(), and that if we have snprintf() we + # have vsnprintf(). + # + # For the first case, we don't need any replacement routines. + # For the second case, we need replacement asprintf()/vasprintf() + # routines. + # For the third case, we need replacement snprintf()/vsnprintf() and + # asprintf()/vasprintf() routines. + # if(NOT HAVE_SNPRINTF) + # + # We assume we have none of them; missing/snprintf.c supplies + # all of them. + # set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c) - endif(NOT HAVE_SNPRINTF) + elif(NOT HAVE_ASPRINTF) + # + # We assume we have snprintf()/vsnprintf() but lack + # asprintf()/vasprintf(); missing/asprintf.c supplies + # the latter (using vsnprintf()). + # + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/asprintf.c) + endif() + if(NOT HAVE_STRLCAT) + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c) + endif(NOT HAVE_STRLCAT) + if(NOT HAVE_STRLCPY) + set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c) + endif(NOT HAVE_STRLCPY) if(NOT HAVE_STRTOK_R) set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c) endif(NOT HAVE_STRTOK_R) @@ -931,13 +949,16 @@ else() # as it's a Linux, it should use packet sockets, # instead. # - # # We need: # # sys/types.h, because FreeBSD 10's net/bpf.h # requires that various BSD-style integer types # be defined; # + # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h + # doesn't include it but does use struct timeval + # in ioctl definitions; + # # sys/ioctl.h and, if we have it, sys/ioccom.h, # because net/bpf.h defines ioctls; # @@ -952,9 +973,9 @@ else() # of those headers itself. # if(HAVE_SYS_IOCCOM_H) - check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF) + check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF) else(HAVE_SYS_IOCCOM_H) - check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF) + check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF) endif(HAVE_SYS_IOCCOM_H) endif(HAVE_NET_BPF_H) check_include_file(net/pfilt.h HAVE_NET_PFILT_H) @@ -1436,7 +1457,28 @@ if(NOT DISABLE_DBUS) set(PCAP_SUPPORT_DBUS TRUE) set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c) include_directories(${DBUS_INCLUDE_DIRS}) - set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARIES}) + + # + # This "helpfully" supplies DBUS_LIBRARIES as a bunch of + # library names - not paths - and DBUS_LIBRARY_DIRS as + # a bunch of directories. + # + # CMake *really* doesn't like the notion of specifying "here are + # the directories in which to look for libraries" except in + # find_library() calls; it *really* prefers using full paths to + # library files, rather than library names. + # + # Find the libraries and add their full paths. + # + set(DBUS_LIBRARY_FULLPATHS) + foreach(_lib IN LISTS DBUS_LIBRARIES) + # + # Try to find this library, so we get its full path. + # + find_library(_libfullpath ${_lib} HINTS ${DBUS_LIBRARY_DIRS}) + list(APPEND DBUS_LIBRARY_FULLPATHS ${_libfullpath}) + endforeach() + set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARY_FULLPATHS}) endif(DBUS_FOUND) endif(NOT DISABLE_DBUS) @@ -1582,7 +1624,7 @@ if(ENABLE_REMOTE) # the check. # cmake_push_check_state() - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR}) + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}) check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL) check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS) cmake_pop_check_state() @@ -1597,7 +1639,7 @@ endif(ENABLE_REMOTE) # # Check and add warning options if we have a .devel file. # -if(EXISTS ${CMAKE_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel) # # Warning options. # @@ -1808,10 +1850,12 @@ set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES # # Assume, by default, no support for shared libraries and V7/BSD -# convention for man pages (file formats in section 5, miscellaneous -# info in section 7, administrative commands and daemons in section 8). +# convention for man pages (devices in section 4, file formats in +# section 5, miscellaneous info in section 7, administrative commands +# and daemons in section 8). Individual cases can override this. # Individual cases can override this. # +set(MAN_DEVICES 4) set(MAN_FILE_FORMATS 5) set(MAN_MISC_INFO 7) set(MAN_ADMIN_COMMANDS 8) @@ -1869,6 +1913,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1") # set(MAN_FILE_FORMATS 4) set(MAN_MISC_INFO 5) + set(MAN_DEVICES 7) elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*") # # SunOS 5.x. @@ -1892,6 +1937,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.] set(MAN_ADMIN_COMMANDS 1m) set(MAN_FILE_FORMATS 4) set(MAN_MISC_INFO 5) + set(MAN_DEVICES 7D) endif() endif() @@ -1944,6 +1990,16 @@ if(BUILD_SHARED_LIBS) add_dependencies(${LIBRARY_NAME} SerializeTarget) set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS BUILDING_PCAP) + # + # No matter what the library is called - it might be called "wpcap" + # in a Windows build - the symbol to define to indicate that we're + # building the library, rather than a program using the library, + # and thus that we're exporting functions defined in our public + # header files, rather than importing those functions, is + # pcap_EXPORTS. + # + set_target_properties(${LIBRARY_NAME} PROPERTIES + DEFINE_SYMBOL pcap_EXPORTS) endif(BUILD_SHARED_LIBS) add_library(${LIBRARY_NAME}_static STATIC @@ -2020,6 +2076,118 @@ if(NOT C_ADDITIONAL_FLAGS STREQUAL "") set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS}) endif() +# +# On macOS, build libpcap for the appropriate architectures, if +# CMAKE_OSX_ARCHITECTURES isn't set (if it is, let that control +# the architectures for which to build it). +# +if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") + # + # Get the major version of Darwin. + # + string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}") + + if(SYSTEM_VERSION_MAJOR LESS 8) + # + # Pre-Tiger. Build only for 32-bit PowerPC. + # + set(OSX_LIBRARY_ARCHITECTURES "ppc") + elseif(SYSTEM_VERSION_MAJOR EQUAL 8) + # + # Tiger. Is this prior to, or with, Intel support? + # + # Get the minor version of Darwin. + # + string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION}) + string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}") + if(SYSTEM_VERSION_MINOR LESS 4) + # + # Prior to Intel support. Build for 32-bit + # PowerPC and 64-bit PowerPC, with 32-bit PowerPC + # first. (I'm guessing that's what Apple does.) + # + set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64") + elseif(SYSTEM_VERSION_MINOR LESS 7) + # + # With Intel support but prior to x86-64 support. + # Build for 32-bit PowerPC, 64-bit PowerPC, and 32-bit x86, + # with 32-bit PowerPC first. + # (I'm guessing that's what Apple does.) + # + set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386") + else() + # + # With Intel support including x86-64 support. + # Build for 32-bit PowerPC, 64-bit PowerPC, 32-bit x86, + # and x86-64, with 32-bit PowerPC first. + # (I'm guessing that's what Apple does.) + # + set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64") + endif() + elseif(SYSTEM_VERSION_MAJOR EQUAL 9) + # + # Leopard. Build for 32-bit PowerPC, 64-bit + # PowerPC, 32-bit x86, and x86-64, with 32-bit PowerPC + # first. (That's what Apple does.) + # + set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64") + elseif(SYSTEM_VERSION_MAJOR EQUAL 10) + # + # Snow Leopard. Build for x86-64, 32-bit x86, and + # 32-bit PowerPC, with x86-64 first. (That's + # what Apple does, even though Snow Leopard + # doesn't run on PPC, so PPC libpcap runs under + # Rosetta, and Rosetta doesn't support BPF + # ioctls, so PPC programs can't do live + # captures.) + # + set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386;ppc") + else() + # + # Post-Snow Leopard. Build for x86-64 and 32-bit x86, + # with x86-64 first. (That's what Apple does) + # XXX - update if and when Apple drops support + # for 32-bit x86 code and if and when Apple adds + # ARM-based Macs. (You're on your own for iOS etc.) + # + # XXX - check whether we *can* build for i386 and, if not, + # suggest that the user install the /usr/include headers if + # they want to build fat. + # + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "-arch i386") + check_c_source_compiles( +"int +main(void) +{ + return 0; +} +" + X86_32_BIT_SUPPORTED) + cmake_pop_check_state() + if(X86_32_BIT_SUPPORTED) + set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386") + else() + set(OSX_LIBRARY_ARCHITECTURES "x86_64") + if(SYSTEM_VERSION_MAJOR LESS 18) + # + # Pre-Mojave; the command-line tools should be sufficient to + # enable 32-bit x86 builds. + # + message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools") + else() + message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package") + endif() + endif() + endif() + if(BUILD_SHARED_LIBS) + set_target_properties(${LIBRARY_NAME} PROPERTIES + OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}") + endif(BUILD_SHARED_LIBS) + set_target_properties(${LIBRARY_NAME}_static PROPERTIES + OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}") +endif() + ###################################### # Write out the config.h file ###################################### @@ -2079,6 +2247,7 @@ set(MAN3PCAP_EXPAND pcap_list_tstamp_types.3pcap.in pcap_open_dead.3pcap.in pcap_open_offline.3pcap.in + pcap_set_immediate_mode.3pcap.in pcap_set_tstamp_precision.3pcap.in pcap_set_tstamp_type.3pcap.in ) @@ -2114,7 +2283,6 @@ set(MAN3PCAP_NOEXPAND pcap_open_live.3pcap pcap_set_buffer_size.3pcap pcap_set_datalink.3pcap - pcap_set_immediate_mode.3pcap pcap_set_promisc.3pcap pcap_set_protocol_linux.3pcap pcap_set_rfmon.3pcap @@ -2179,7 +2347,7 @@ if(WIN32) endif(NOT MINGW) endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8) else(WIN32) - install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION lib) + install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) endif(WIN32) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap) @@ -2225,8 +2393,8 @@ if(NOT MSVC) foreach(LIB ${PCAP_LINK_LIBRARIES}) set(LIBS "${LIBS} -l${LIB}") endforeach(LIB) - configure_file(${CMAKE_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY) - configure_file(${CMAKE_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig) @@ -2238,17 +2406,17 @@ if(NOT MSVC) # set(MAN1 "") foreach(MANPAGE ${MAN1_NOEXPAND}) - set(MAN1 ${MAN1} ${CMAKE_SOURCE_DIR}/${MANPAGE}) + set(MAN1 ${MAN1} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE}) endforeach(MANPAGE) install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) set(MAN3PCAP "") foreach(MANPAGE ${MAN3PCAP_NOEXPAND}) - set(MAN3PCAP ${MAN3PCAP} ${CMAKE_SOURCE_DIR}/${MANPAGE}) + set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE}) endforeach(MANPAGE) foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND}) string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE}) - configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) endforeach(TEMPLATE_MANPAGE) install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) @@ -2272,7 +2440,7 @@ if(NOT MSVC) set(MANFILE "") foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND}) string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE}) - configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) endforeach(TEMPLATE_MANPAGE) install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS}) @@ -2280,7 +2448,7 @@ if(NOT MSVC) set(MANMISC "") foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND}) string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE}) - configure_file(${CMAKE_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY) set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE}) endforeach(TEMPLATE_MANPAGE) install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO}) diff --git a/libpcap/CREDITS b/libpcap/CREDITS index 8b7e7ce89..f7abc1f32 100644 --- a/libpcap/CREDITS +++ b/libpcap/CREDITS @@ -129,7 +129,7 @@ Additional people who have contributed patches (in alphabetical order): Olaf Kirch Ollie Wild Onno van der Linden - Paolo Abeni and redhat dot com + Paolo Abeni Patrick Marie Patrick McHardy Paul Mundt diff --git a/libpcap/INSTALL.md b/libpcap/INSTALL.md index 96c87a2ce..3a303fe0a 100644 --- a/libpcap/INSTALL.md +++ b/libpcap/INSTALL.md @@ -266,15 +266,14 @@ doc/README.macos - notes on using libpcap on macOS doc/README.septel - notes on using libpcap to capture on Intel/Septel devices doc/README.sita - notes on using libpcap to capture on SITA devices doc/README.tru64 - notes on using libpcap on Digital/Tru64 UNIX -doc/README.Win32 - notes on using libpcap on Win32 systems (with WinPcap) +doc/README.Win32 - notes on using libpcap on Win32 systems (with Npcap) VERSION - version of this release acconfig.h - support for post-2.13 autoconf aclocal.m4 - autoconf macros arcnet.h - ARCNET definitions atmuni31.h - ATM Q.2931 definitions -bpf/net - copy of bpf_filter.c bpf_dump.c - BPF program printing routines -bpf_filter.c - symlink to bpf/net/bpf_filter.c +bpf_filter.c - BPF filtering routines bpf_image.c - BPF disassembly routine config.guess - autoconf support config.h.in - autoconf input diff --git a/libpcap/Makefile.in b/libpcap/Makefile.in index 7723396cb..5a6b165da 100644 --- a/libpcap/Makefile.in +++ b/libpcap/Makefile.in @@ -69,13 +69,16 @@ INSTALL_RPCAPD=@INSTALL_RPCAPD@ EXTRA_NETWORK_LIBS=@EXTRA_NETWORK_LIBS@ # Standard CFLAGS for building members of a shared library -FULL_CFLAGS = $(CCOPT) $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS) +FULL_CFLAGS = $(CCOPT) @V_LIB_CCOPT_FAT@ $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS) INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ RANLIB = @RANLIB@ +LEX = @LEX@ +YACC = @YACC@ + # Explicitly define compilation rule since SunOS 4's make doesn't like gcc. # Also, gcc does not remove the .o before forking 'as', which can be a # problem if you don't own the file but can write to the directory. @@ -114,6 +117,7 @@ PUBHDR = \ pcap/nflog.h \ pcap/pcap.h \ pcap/sll.h \ + pcap/socket.h \ pcap/vlan.h \ pcap/usb.h @@ -150,7 +154,7 @@ TAGFILES = \ $(SRC) $(HDR) CLEANFILES = $(OBJ) libpcap.a libpcap.so.`cat $(srcdir)/VERSION` \ - $(PROG)-`cat $(srcdir)/VERSION`.tar.gz \ + $(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENSRC) $(GENHDR) \ lex.yy.c pcap-config libpcap.pc MAN1 = pcap-config.1 @@ -165,6 +169,7 @@ MAN3PCAP_EXPAND = \ pcap_list_tstamp_types.3pcap.in \ pcap_open_dead.3pcap.in \ pcap_open_offline.3pcap.in \ + pcap_set_immediate_mode.3pcap.in \ pcap_set_tstamp_precision.3pcap.in \ pcap_set_tstamp_type.3pcap.in @@ -200,7 +205,6 @@ MAN3PCAP_NOEXPAND = \ pcap_open_live.3pcap \ pcap_set_buffer_size.3pcap \ pcap_set_datalink.3pcap \ - pcap_set_immediate_mode.3pcap \ pcap_set_promisc.3pcap \ pcap_set_protocol_linux.3pcap \ pcap_set_rfmon.3pcap \ @@ -273,10 +277,14 @@ EXTRA_DIST = \ lbl/os-sunos4.h \ lbl/os-ultrix4.h \ libpcap.pc.in \ + missing/asprintf.c \ missing/getopt.c \ missing/getopt.h \ missing/snprintf.c \ + missing/strlcat.c \ + missing/strlcpy.c \ missing/strtok_r.c \ + missing/win_asprintf.c \ missing/win_snprintf.c \ mkdep \ msdos/bin2c.c \ @@ -344,12 +352,13 @@ EXTRA_DIST = \ rpcapd/fileconf.c \ rpcapd/fileconf.h \ rpcapd/log.h \ - rpcapd/log-stderr.c \ + rpcapd/log.c \ rpcapd/org.tcpdump.rpcapd.plist \ rpcapd/rpcapd.c \ rpcapd/rpcapd.h \ rpcapd/rpcapd.inetd.conf \ rpcapd/rpcapd.manadmin.in \ + rpcapd/rpcapd-config.manfile.in \ rpcapd/rpcapd.rc \ rpcapd/rpcapd.socket \ rpcapd/rpcapd.xinetd.conf \ @@ -378,15 +387,6 @@ EXTRA_DIST = \ all: libpcap.a shared $(BUILD_RPCAPD) libpcap.pc pcap-config -# Inhibit implicit rule Make seems to have for using yacc/lex to -# recompile new scanner.c/grammar.c -- we ship ones which we want to -# use instead. -grammar.c: - echo "Not rebuilding grammar.c" - -scanner.c: - echo "Not rebuilding scanner.c" - libpcap.a: $(OBJ) @rm -f $@ $(AR) rc $@ $(OBJ) $(ADDLARCHIVEOBJS) @@ -423,7 +423,7 @@ libpcap.dylib: $(OBJ) MAJOR_VER=A; \ COMPAT_VER=1; \ CURRENT_VER=`sed 's/[^0-9.].*$$//' $(srcdir)/VERSION`; \ - $(CC) -dynamiclib -undefined error $(LDFLAGS) \ + $(CC) -dynamiclib -undefined error $(LDFLAGS) @V_LIB_LDFLAGS_FAT@ \ -o libpcap.$$VER.dylib $(OBJ) $(ADDLOBJS) $(LIBS) \ -install_name $(libdir)/libpcap.$$MAJOR_VER.dylib \ -compatibility_version $$COMPAT_VER \ @@ -468,18 +468,45 @@ libpcap.shareda: $(OBJ) # libpcap.none: +scanner.c: $(srcdir)/scanner.l + $(LEX) -P pcap_ --header-file=scanner.h --nounput -o scanner.c $< +scanner.h: scanner.c +## Recover from the removal of $@ + @if test -f $@; then :; else \ + rm -f scanner.c; \ + $(MAKE) $(MAKEFLAGS) scanner.c; \ + fi + scanner.o: scanner.c grammar.h $(CC) $(FULL_CFLAGS) -c scanner.c +grammar.c: $(srcdir)/grammar.y + $(YACC) -p pcap_ -o grammar.c -d $< +grammar.h: grammar.c +## Recover from the removal of $@ + @if test -f $@; then :; else \ + rm -f grammar.c; \ + $(MAKE) $(MAKEFLAGS) grammar.c; \ + fi + grammar.o: grammar.c scanner.h $(CC) $(FULL_CFLAGS) -c grammar.c gencode.o: $(srcdir)/gencode.c grammar.h scanner.h $(CC) $(FULL_CFLAGS) -c $(srcdir)/gencode.c +asprintf.o: $(srcdir)/missing/asprintf.c + $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/asprintf.c + snprintf.o: $(srcdir)/missing/snprintf.c $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c +strlcat.o: $(srcdir)/missing/strlcat.c + $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c + +strlcpy.o: $(srcdir)/missing/strlcpy.c + $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c + strtok_r.o: $(srcdir)/missing/strtok_r.c $(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strtok_r.c @@ -563,6 +590,9 @@ install: install-shared install-archive libpcap.pc pcap-config @INSTALL_RPCAPD@ rm -f pcap_datalink_val_to_description.3pcap && \ $(LN_S) pcap_datalink_val_to_name.3pcap \ pcap_datalink_val_to_description.3pcap && \ + rm -f pcap_datalink_val_to_description_or_dlt.3pcap && \ + $(LN_S) pcap_datalink_val_to_name.3pcap \ + pcap_datalink_val_to_description_or_dlt.3pcap && \ rm -f pcap_dump_fopen.3pcap && \ $(LN_S) pcap_dump_open.3pcap pcap_dump_fopen.3pcap && \ rm -f pcap_freealldevs.3pcap && \ @@ -711,8 +741,8 @@ uninstall-rpcapd: clean: rm -f $(CLEANFILES) - cd rpcapd && $(MAKE) clean - cd testprogs && $(MAKE) clean + cd rpcapd; $(MAKE) clean + cd testprogs; $(MAKE) clean distclean: clean rm -f Makefile config.cache config.log config.status \ diff --git a/libpcap/NMAP_MODIFICATIONS/0001-Don-t-autogenerate-Lex-Yacc-files.patch b/libpcap/NMAP_MODIFICATIONS/0001-Don-t-autogenerate-Lex-Yacc-files.patch deleted file mode 100644 index d5bc17405..000000000 --- a/libpcap/NMAP_MODIFICATIONS/0001-Don-t-autogenerate-Lex-Yacc-files.patch +++ /dev/null @@ -1,103 +0,0 @@ -diff --git a/libpcap/Makefile.in b/libpcap/Makefile.in -index dff75ec..38e7bb1 100644 ---- a/libpcap/Makefile.in -+++ b/libpcap/Makefile.in -@@ -76,9 +76,6 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ - INSTALL_DATA = @INSTALL_DATA@ - RANLIB = @RANLIB@ - --LEX = @LEX@ --YACC = @YACC@ -- - # Explicitly define compilation rule since SunOS 4's make doesn't like gcc. - # Also, gcc does not remove the .o before forking 'as', which can be a - # problem if you don't own the file but can write to the directory. -@@ -153,7 +150,7 @@ TAGFILES = \ - $(SRC) $(HDR) - - CLEANFILES = $(OBJ) libpcap.a libpcap.so.`cat $(srcdir)/VERSION` \ -- $(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENSRC) $(GENHDR) \ -+ $(PROG)-`cat $(srcdir)/VERSION`.tar.gz \ - lex.yy.c pcap-config libpcap.pc - - MAN1 = pcap-config.1 -@@ -381,6 +378,15 @@ EXTRA_DIST = \ - - all: libpcap.a shared $(BUILD_RPCAPD) libpcap.pc pcap-config - -+# Inhibit implicit rule Make seems to have for using yacc/lex to -+# recompile new scanner.c/grammar.c -- we ship ones which we want to -+# use instead. -+grammar.c: -+ echo "Not rebuilding grammar.c" -+ -+scanner.c: -+ echo "Not rebuilding scanner.c" -+ - libpcap.a: $(OBJ) - @rm -f $@ - $(AR) rc $@ $(OBJ) $(ADDLARCHIVEOBJS) -@@ -462,27 +468,9 @@ libpcap.shareda: $(OBJ) - # - libpcap.none: - --scanner.c: $(srcdir)/scanner.l -- $(LEX) -P pcap_ --header-file=scanner.h --nounput -o scanner.c $< --scanner.h: scanner.c --## Recover from the removal of $@ -- @if test -f $@; then :; else \ -- rm -f scanner.c; \ -- $(MAKE) $(MAKEFLAGS) scanner.c; \ -- fi -- - scanner.o: scanner.c grammar.h - $(CC) $(FULL_CFLAGS) -c scanner.c - --grammar.c: $(srcdir)/grammar.y -- $(YACC) -p pcap_ -o grammar.c -d $< --grammar.h: grammar.c --## Recover from the removal of $@ -- @if test -f $@; then :; else \ -- rm -f grammar.c; \ -- $(MAKE) $(MAKEFLAGS) grammar.c; \ -- fi -- - grammar.o: grammar.c scanner.h - $(CC) $(FULL_CFLAGS) -c grammar.c - -diff --git a/libpcap/configure.ac b/libpcap/configure.ac -index eff6eb8..0127f0a 100644 ---- a/libpcap/configure.ac -+++ b/libpcap/configure.ac -@@ -1462,7 +1462,7 @@ yes) AC_MSG_RESULT(yes) - #include "ftmacros.h" - #include - ]) -- -+ AC_CONFIG_FILES([rpcapd/Makefile rpcapd/rpcapd.manadmin]) - AC_DEFINE(ENABLE_REMOTE,, - [Define to 1 if remote packet capture is to be supported]) - SSRC="$SSRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c" -@@ -1867,14 +1867,12 @@ AC_SUBST(V_CCOPT) - AC_SUBST(V_DEFS) - AC_SUBST(V_FINDALLDEVS) - AC_SUBST(V_INCLS) --AC_SUBST(V_LEX) - AC_SUBST(V_PCAP) - AC_SUBST(V_SHLIB_CCOPT) - AC_SUBST(V_SHLIB_CMD) - AC_SUBST(V_SHLIB_OPT) - AC_SUBST(V_SONAME_OPT) - AC_SUBST(V_RPATH_OPT) --AC_SUBST(V_YACC) - AC_SUBST(ADDLOBJS) - AC_SUBST(ADDLARCHIVEOBJS) - AC_SUBST(SSRC) -@@ -2275,6 +2273,6 @@ AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc - pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap - pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap - pcap_open_offline.3pcap pcap_set_tstamp_precision.3pcap -- pcap_set_tstamp_type.3pcap rpcapd/Makefile rpcapd/rpcapd.manadmin -+ pcap_set_tstamp_type.3pcap - testprogs/Makefile) - exit 0 diff --git a/libpcap/NMAP_MODIFICATIONS/0002-Disable-unnecessary-features.patch b/libpcap/NMAP_MODIFICATIONS/0002-Disable-unnecessary-features.patch deleted file mode 100644 index 2040894bf..000000000 --- a/libpcap/NMAP_MODIFICATIONS/0002-Disable-unnecessary-features.patch +++ /dev/null @@ -1,64 +0,0 @@ -diff --git a/libpcap/configure.ac b/libpcap/configure.ac -index 0127f0a..4b35daa 100644 ---- a/libpcap/configure.ac -+++ b/libpcap/configure.ac -@@ -743,10 +743,10 @@ linux) - # Do we have libnl? - # - AC_ARG_WITH(libnl, -- AC_HELP_STRING([--without-libnl],[disable libnl support @<:@default=yes, on Linux, if present@:>@]), -+ AC_HELP_STRING([--without-libnl],[disable libnl support @<:@default=disabled@:>@]), - with_libnl=$withval,with_libnl=if_available) - -- if test x$with_libnl != xno ; then -+ if test x$with_libnl = xyes ; then - have_any_nl="no" - - incdir=-I/usr/include/libnl3 -@@ -1814,8 +1814,8 @@ solaris*) - esac - - AC_ARG_ENABLE(shared, --AC_HELP_STRING([--enable-shared],[build shared libraries @<:@default=yes, if support available@:>@])) --test "x$enable_shared" = "xno" && DYEXT="none" -+AC_HELP_STRING([--enable-shared],[build shared libraries @<:@default=no@:>@])) -+test "x$enable_shared" != "xyes" && DYEXT="none" - - AC_PROG_RANLIB - AC_CHECK_TOOL([AR], [ar]) -@@ -1887,9 +1887,9 @@ AC_SUBST(RPCAPD_LIBS) - AC_SUBST(EXTRA_NETWORK_LIBS) - - AC_ARG_ENABLE([usb], --[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=yes, if support available@:>@])], -+[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=no@:>@])], - [], -- [enable_usb=yes]) -+ [enable_usb=no]) - - if test "xxx_only" = yes; then - # User requested something-else-only pcap, so they don't -@@ -2035,9 +2035,9 @@ fi - - - AC_ARG_ENABLE([bluetooth], --[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])], -+[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=no@:>@])], - [], -- [enable_bluetooth=ifsupportavailable]) -+ [enable_bluetooth=no]) - - if test "xxx_only" = yes; then - # User requested something-else-only pcap, so they don't -@@ -2120,9 +2120,9 @@ if test "x$enable_bluetooth" != "xno" ; then - fi - - AC_ARG_ENABLE([dbus], --[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])], -+[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=no@:>@])], - [], -- [enable_dbus=ifavailable]) -+ [enable_dbus=no]) - - if test "xxx_only" = yes; then - # User requested something-else-only pcap, so they don't diff --git a/libpcap/NMAP_MODIFICATIONS/HOWTO-UPGRADE b/libpcap/NMAP_MODIFICATIONS/HOWTO-UPGRADE deleted file mode 100644 index bdd4c16c1..000000000 --- a/libpcap/NMAP_MODIFICATIONS/HOWTO-UPGRADE +++ /dev/null @@ -1,25 +0,0 @@ -Download libpcap-X.Y.tar.gz from http://www.tcpdump.org/#latest-release -and verify the signature. - -cd -# Make a copy of this directory. -cp -r ~/nmap/libpcap/NMAP_MODIFICATIONS . -tar xzvf libpcap-X.Y.tar.gz -cd nmap -rsync -rv --delete ~/libpcap-X.Y/ ~/nmap/libpcap/ -git add -A libpcap -cd libpcap -./configure -make grammar.c scanner.c scanner.h -git add grammar.c scanner.c scanner.h -cd .. -# Apply patches. -git apply ~/NMAP_MODIFICATIONS/000* -# Make changes as necessary and update the patch files -cd libpcap -autoconf -cd .. -git add -u libpcap -mv ~/NMAP_MODIFICATIONS libpcap/ -git add libpcap/NMAP_MODIFICATIONS -git commit -m "Upgrade libpcap to X.Y." diff --git a/libpcap/VERSION b/libpcap/VERSION index f8e233b27..9ab8337f3 100644 --- a/libpcap/VERSION +++ b/libpcap/VERSION @@ -1 +1 @@ -1.9.0 +1.9.1 diff --git a/libpcap/aclocal.m4 b/libpcap/aclocal.m4 index ac163d426..aa91e846e 100644 --- a/libpcap/aclocal.m4 +++ b/libpcap/aclocal.m4 @@ -484,7 +484,7 @@ AC_DEFUN(AC_LBL_SHLIBS_INIT, aix*) ;; - freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*) + freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|midipix*) # # Platforms where the linker is the GNU linker # or accepts command-line arguments like @@ -501,7 +501,7 @@ AC_DEFUN(AC_LBL_SHLIBS_INIT, sparc64*) case "$host_os" in - freebsd*|openbsd*) + freebsd*|openbsd*|linux*) PIC_OPT=-fPIC ;; esac @@ -878,22 +878,23 @@ AC_DEFUN(AC_LBL_DEVEL, # if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR() + AC_LBL_CHECK_COMPILER_OPT($1, -W) AC_LBL_CHECK_COMPILER_OPT($1, -Wall) - AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare) - AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes) - AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes) - AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow) - AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement) - AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused) - AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation) AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma) + AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement) + AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation) + AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral) AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn) + AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes) + AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations) + AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow) + AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare) + AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes) + AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter) + AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused) # Warns about safeguards added in case the enums are # extended # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default) - AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations) - AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter) - AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral) # # This can cause problems with ntohs(), ntohl(), # htons(), and htonl() on some platforms, such diff --git a/libpcap/bpf_filter.c b/libpcap/bpf_filter.c index 615ed3fc3..33872ff4b 100644 --- a/libpcap/bpf_filter.c +++ b/libpcap/bpf_filter.c @@ -51,7 +51,7 @@ #include #endif /* _WIN32 */ -#include +#include #include @@ -328,11 +328,17 @@ bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, continue; case BPF_ALU|BPF_LSH|BPF_X: - A <<= X; + if (X < 32) + A <<= X; + else + A = 0; continue; case BPF_ALU|BPF_RSH|BPF_X: - A >>= X; + if (X < 32) + A >>= X; + else + A = 0; continue; case BPF_ALU|BPF_ADD|BPF_K: @@ -378,10 +384,13 @@ bpf_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p, case BPF_ALU|BPF_NEG: /* * Most BPF arithmetic is unsigned, but negation - * can't be unsigned; throw some casts to - * specify what we're trying to do. + * can't be unsigned; respecify it as subtracting + * the accumulator from 0U, so that 1) we don't + * get compiler warnings about negating an unsigned + * value and 2) don't get UBSan warnings about + * the result of negating 0x80000000 being undefined. */ - A = (u_int32)(-(int32)A); + A = (0U - A); continue; case BPF_MISC|BPF_TAX: diff --git a/libpcap/cmake/Modules/FindPacket.cmake b/libpcap/cmake/Modules/FindPacket.cmake index 1311cdb94..f114875bf 100644 --- a/libpcap/cmake/Modules/FindPacket.cmake +++ b/libpcap/cmake/Modules/FindPacket.cmake @@ -49,9 +49,17 @@ # # The 64-bit Packet.lib is located under /x64 -set(64BIT_SUBDIR "") if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(64BIT_SUBDIR "/x64") + # + # For the WinPcap and Npcap SDKs, the Lib subdirectory of the top-level + # directory contains 32-bit libraries; the 64-bit libraries are in the + # Lib/x64 directory. + # + # The only way to *FORCE* CMake to look in the Lib/x64 directory + # without searching in the Lib directory first appears to be to set + # CMAKE_LIBRARY_ARCHITECTURE to "x64". + # + set(CMAKE_LIBRARY_ARCHITECTURE "x64") endif() # Find the header @@ -64,7 +72,6 @@ find_path(PACKET_INCLUDE_DIR Packet32.h find_library(PACKET_LIBRARY NAMES Packet packet HINTS "${PACKET_DLL_DIR}" ENV PACKET_DLL_DIR - PATH_SUFFIXES Lib${64BIT_SUBDIR} lib${64BIT_SUBDIR} ) # Set PACKET_FOUND to TRUE if PACKET_INCLUDE_DIR and PACKET_LIBRARY are TRUE. diff --git a/libpcap/cmakeconfig.h.in b/libpcap/cmakeconfig.h.in index 6760cec76..1639925e3 100644 --- a/libpcap/cmakeconfig.h.in +++ b/libpcap/cmakeconfig.h.in @@ -15,6 +15,9 @@ /* define if we have the AIX getprotobyname_r() */ #cmakedefine HAVE_AIX_GETPROTOBYNAME_R 1 +/* Define to 1 if you have the `asprintf' function. */ +#cmakedefine HAVE_ASPRINTF 1 + /* define if you have the DAG API */ #cmakedefine HAVE_DAG_API 1 @@ -48,6 +51,9 @@ /* Define to 1 if you have the `getspnam' function. */ #cmakedefine HAVE_GETSPNAM 1 +/* Define to 1 if you have a GNU-style `strerror_r' function. */ +#cmakedefine HAVE_GNU_STRERROR_R 1 + /* on HP-UX 10.20 or later */ #cmakedefine HAVE_HPUX10_20_OR_LATER 1 @@ -138,9 +144,15 @@ /* if there's an os_proto.h for this platform, to use additional prototypes */ #cmakedefine HAVE_OS_PROTO_H 1 -/* Define to 1 if Packet32 API (WinPcap NPF driver) is available */ +/* Define to 1 if Packet32 API (Npcap driver) is available */ #cmakedefine HAVE_PACKET32 1 +/* Define to 1 if NPcap's version.h is available */ +#cmakedefine HAVE_VERSION_H 1 + +/* Define to 1 if you have a POSIX-style `strerror_r' function. */ +#cmakedefine HAVE_POSIX_STRERROR_R 1 + /* define if net/pfvar.h defines PF_NAT through PF_NORDR */ #cmakedefine HAVE_PF_NAT_THROUGH_PF_NORDR 1 @@ -174,9 +186,6 @@ /* Define to 1 if you have the `strerror' function. */ #cmakedefine HAVE_STRERROR 1 -/* Define to 1 if you have the `strerror_r' function. */ -#cmakedefine HAVE_STRERROR_R 1 - /* Define to 1 if you have the `strerror_s' function. */ #cmakedefine HAVE_STRERROR_S 1 @@ -256,9 +265,15 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNISTD_H 1 +/* Define to 1 if you have the `vasprintf' function. */ +#cmakedefine HAVE_VASPRINTF 1 + /* Define to 1 if you have the `vsnprintf' function. */ #cmakedefine HAVE_VSNPRINTF 1 +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + /* Define to 1 if you have the `PacketIsLoopbackAdapter' function. */ #cmakedefine HAVE_PACKET_IS_LOOPBACK_ADAPTER 1 diff --git a/libpcap/config.h.in b/libpcap/config.h.in index b1a20a441..94db7bbc4 100644 --- a/libpcap/config.h.in +++ b/libpcap/config.h.in @@ -15,6 +15,9 @@ /* define if we have the AIX getprotobyname_r() */ #undef HAVE_AIX_GETPROTOBYNAME_R +/* Define to 1 if you have the `asprintf' function. */ +#undef HAVE_ASPRINTF + /* Define to 1 if you have the header file. */ #undef HAVE_DAGAPI_H @@ -54,6 +57,9 @@ /* Define to 1 if you have the `getspnam' function. */ #undef HAVE_GETSPNAM +/* Define to 1 if you have a GNU-style `strerror_r' function. */ +#undef HAVE_GNU_STRERROR_R + /* on HP-UX 10.20 or later */ #undef HAVE_HPUX10_20_OR_LATER @@ -150,6 +156,9 @@ /* define if net/pfvar.h defines PF_NAT through PF_NORDR */ #undef HAVE_PF_NAT_THROUGH_PF_NORDR +/* Define to 1 if you have a POSIX-style `strerror_r' function. */ +#undef HAVE_POSIX_STRERROR_R + /* define if you have the Septel API */ #undef HAVE_SEPTEL_API @@ -180,9 +189,6 @@ /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR -/* Define to 1 if you have the `strerror_r' function. */ -#undef HAVE_STRERROR_R - /* Define to 1 if you have the `strerror_s' function. */ #undef HAVE_STRERROR_S @@ -262,9 +268,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `vasprintf' function. */ +#undef HAVE_VASPRINTF + /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + /* IPv6 */ #undef INET6 diff --git a/libpcap/configure b/libpcap/configure index d0c01564f..fa15fc731 100755 --- a/libpcap/configure +++ b/libpcap/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for pcap 1.9.0. +# Generated by GNU Autoconf 2.69 for pcap 1.9.1. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='pcap' PACKAGE_TARNAME='pcap' -PACKAGE_VERSION='1.9.0' -PACKAGE_STRING='pcap 1.9.0' +PACKAGE_VERSION='1.9.1' +PACKAGE_STRING='pcap 1.9.1' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -645,25 +645,37 @@ PTHREAD_LIBS MAN_ADMIN_COMMANDS MAN_MISC_INFO MAN_FILE_FORMATS +MAN_DEVICES DYEXT SSRC ADDLARCHIVEOBJS ADDLOBJS +V_YACC V_RPATH_OPT V_SONAME_OPT V_SHLIB_OPT V_SHLIB_CMD V_SHLIB_CCOPT V_PCAP +V_LEX V_INCLS V_FINDALLDEVS V_DEFS +V_PROG_LDFLAGS_FAT +V_PROG_CCOPT_FAT +V_LIB_LDFLAGS_FAT +V_LIB_CCOPT_FAT V_CCOPT MKDEP DEPENDENCY_CFLAG LN_S AR RANLIB +YFLAGS +YACC +LEXLIB +LEX_OUTPUT_ROOT +LEX PCAP_SUPPORT_PACKET_RING VALGRINDTEST_SRC LIBOBJS @@ -767,7 +779,9 @@ CFLAGS LDFLAGS LIBS CPPFLAGS -CPP' +CPP +YACC +YFLAGS' # Initialize some variables set by options. @@ -1318,7 +1332,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pcap 1.9.0 to adapt to many kinds of systems. +\`configure' configures pcap 1.9.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1385,7 +1399,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pcap 1.9.0:";; + short | recursive ) echo "Configuration of pcap 1.9.1:";; esac cat <<\_ACEOF @@ -1402,12 +1416,16 @@ Optional Features: --enable-optimizer-dbg build optimizer debugging code --enable-yydebug build parser debugging code --disable-universal don't build universal on macOS - --enable-shared build shared libraries [default=no] - --enable-usb enable USB capture support [default=no] + --enable-shared build shared libraries [default=yes, if support + available] + --enable-usb enable USB capture support [default=yes, if support + available] --enable-netmap enable netmap support [default=yes, if support available] - --enable-bluetooth enable Bluetooth support [default=no] - --enable-dbus enable D-Bus capture support [default=no] + --enable-bluetooth enable Bluetooth support [default=yes, if support + available] + --enable-dbus enable D-Bus capture support [default=yes, if + support available] --enable-rdma enable RDMA capture support [default=yes, if support available] @@ -1417,7 +1435,8 @@ Optional Packages: --without-gcc don't use gcc --with-sita include SITA support --with-pcap=TYPE use packet capture TYPE - --without-libnl disable libnl support [default=disabled] + --without-libnl disable libnl support [default=yes, on Linux, if + present] --with-dag[=DIR] include Endace DAG support (located in directory DIR, if supplied). [default=yes, if present] --with-dag-includes=IDIR @@ -1445,6 +1464,12 @@ Some influential environment variables: CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor + YACC The `Yet Another Compiler Compiler' implementation to use. + Defaults to the first program found out of: `bison -y', `byacc', + `yacc'. + YFLAGS The list of arguments that will be passed by default to $YACC. + This script will default YFLAGS to the empty string to avoid a + default value of `-d' given by some make applications. Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -1512,7 +1537,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pcap configure 1.9.0 +pcap configure 1.9.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2034,7 +2059,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pcap $as_me 1.9.0, which was +It was created by pcap $as_me 1.9.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3568,6 +3593,10 @@ if test "x$ac_cv_prog_cc_c99" != xno; then : fi +if test "$ac_cv_prog_cc_c99" = "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: The C compiler does not support C99; there may be compiler errors" >&5 +$as_echo "$as_me: WARNING: The C compiler does not support C99; there may be compiler errors" >&2;} +fi @@ -3989,7 +4018,7 @@ $as_echo "#define const /**/" >>confdefs.h aix*) ;; - freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*) + freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|midipix*) # # Platforms where the linker is the GNU linker # or accepts command-line arguments like @@ -4006,7 +4035,7 @@ $as_echo "#define const /**/" >>confdefs.h sparc64*) case "$host_os" in - freebsd*|openbsd*) + freebsd*|openbsd*|linux*) PIC_OPT=-fPIC ;; esac @@ -4990,19 +5019,120 @@ $as_echo "$ac_cv_lbl_gcc_fixincludes" >&6; } fi fi -for ac_func in strerror strerror_r strerror_s strlcpy strlcat +for ac_func in strerror do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" -if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + ac_fn_c_check_func "$LINENO" "strerror" "ac_cv_func_strerror" +if test "x$ac_cv_func_strerror" = xyes; then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +#define HAVE_STRERROR 1 +_ACEOF + +fi +done + +ac_fn_c_check_func "$LINENO" "strerror_r" "ac_cv_func_strerror_r" +if test "x$ac_cv_func_strerror_r" = xyes; then : + + # + # We have strerror_r; if we define _GNU_SOURCE, is it a + # POSIX-compliant strerror_r() or a GNU strerror_r()? + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether strerror_r is GNU-style" >&5 +$as_echo_n "checking whether strerror_r is GNU-style... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #define _GNU_SOURCE +#include + +/* Define it GNU-style; that will cause an error if it's not GNU-style */ +extern char *strerror_r(int, char *, size_t); + +int +main(void) +{ + return 0; +} + + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # GNU-style + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GNU_STRERROR_R /**/" >>confdefs.h + + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +$as_echo "#define HAVE_POSIX_STRERROR_R /**/" >>confdefs.h + + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +else + + # + # We don't have strerror_r; do we have strerror_s? + # + for ac_func in strerror_s +do : + ac_fn_c_check_func "$LINENO" "strerror_s" "ac_cv_func_strerror_s" +if test "x$ac_cv_func_strerror_s" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRERROR_S 1 _ACEOF fi done +fi + + +# +# Thanks, IBM, for not providing vsyslog() in AIX! +# +for ac_func in vsyslog +do : + ac_fn_c_check_func "$LINENO" "vsyslog" "ac_cv_func_vsyslog" +if test "x$ac_cv_func_vsyslog" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_VSYSLOG 1 +_ACEOF + +fi +done + + +# +# Either: +# +# we have snprintf() and vsnprintf(), and have asprintf() and +# vasprintf(); +# +# we have snprintf() and vsnprintf(), but don't have asprintf() +# or vasprintf(); +# +# we have neither snprintf() nor vsnprintf(), and don't have +# asprintf() or vasprintf(), either. +# +# We assume that if we have asprintf() we have vasprintf(), as well +# as snprintf() and vsnprintf(), and that if we have snprintf() we +# have vsnprintf(). +# +# For the first case, we don't need any replacement routines. +# For the second case, we need replacement asprintf()/vasprintf() +# routines. +# For the third case, we need replacement snprintf()/vsnprintf() and +# asprintf()/vasprintf() routines. +# needsnprintf=no for ac_func in vsnprintf snprintf do : @@ -5018,13 +5148,90 @@ else fi done +needasprintf=no +for ac_func in vasprintf asprintf +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +else + needasprintf=yes +fi +done + if test $needsnprintf = yes; then + # + # We assume we have none of them; missing/snprintf.c supplies + # all of them. + # case " $LIBOBJS " in *" snprintf.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS snprintf.$ac_objext" ;; esac +elif test $needasprintf = yes; then + # + # We assume we have snprintf()/vsnprintf() but lack + # asprintf()/vasprintf(); missing/asprintf.c supplies + # the latter (using vsnprintf()). + # + case " $LIBOBJS " in + *" asprintf.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS asprintf.$ac_objext" + ;; +esac + +fi + +needstrlcat=no +for ac_func in strlcat +do : + ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat" +if test "x$ac_cv_func_strlcat" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRLCAT 1 +_ACEOF + +else + needstrlcat=yes +fi +done + +if test $needstrlcat = yes; then + case " $LIBOBJS " in + *" strlcat.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strlcat.$ac_objext" + ;; +esac + +fi + +needstrlcpy=no +for ac_func in strlcpy +do : + ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy" +if test "x$ac_cv_func_strlcpy" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRLCPY 1 +_ACEOF + +else + needstrlcpy=yes +fi +done + +if test $needstrlcpy = yes; then + case " $LIBOBJS " in + *" strlcpy.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strlcpy.$ac_objext" + ;; +esac + fi needstrtok_r=no @@ -5954,6 +6161,10 @@ done # requires that various BSD-style integer types # be defined; # + # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h + # doesn't include it but does use struct timeval + # in ioctl definitions; + # # sys/ioctl.h and, if we have it, sys/ioccom.h, # because net/bpf.h defines ioctls; # @@ -5976,6 +6187,7 @@ else /* end confdefs.h. */ #include +#include #include #include #ifdef HAVE_SYS_IOCCOM_H @@ -6304,7 +6516,7 @@ else fi - if test x$with_libnl = xyes ; then + if test x$with_libnl != xno ; then have_any_nl="no" incdir=-I/usr/include/libnl3 @@ -7656,7 +7868,6 @@ _ACEOF fi - ac_config_files="$ac_config_files rpcapd/Makefile rpcapd/rpcapd.manadmin" $as_echo "#define ENABLE_REMOTE /**/" >>confdefs.h @@ -7700,15 +7911,274 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${enable_yydebug-no}" >&5 $as_echo "${enable_yydebug-no}" >&6; } +# +# Look for {f}lex. +# +for ac_prog in flex lex +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LEX"; then + ac_cv_prog_LEX="$LEX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_LEX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LEX=$ac_cv_prog_LEX +if test -n "$LEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LEX" >&5 +$as_echo "$LEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$LEX" && break +done +test -n "$LEX" || LEX=":" + +if test "x$LEX" != "x:"; then + cat >conftest.l <<_ACEOF +%% +a { ECHO; } +b { REJECT; } +c { yymore (); } +d { yyless (1); } +e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument. */ + yyless ((input () != 0)); } +f { unput (yytext[0]); } +. { BEGIN INITIAL; } +%% +#ifdef YYTEXT_POINTER +extern char *yytext; +#endif +int +main (void) +{ + return ! yylex () + ! yywrap (); +} +_ACEOF +{ { ac_try="$LEX conftest.l" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$LEX conftest.l") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking lex output file root" >&5 +$as_echo_n "checking lex output file root... " >&6; } +if ${ac_cv_prog_lex_root+:} false; then : + $as_echo_n "(cached) " >&6 +else + +if test -f lex.yy.c; then + ac_cv_prog_lex_root=lex.yy +elif test -f lexyy.c; then + ac_cv_prog_lex_root=lexyy +else + as_fn_error $? "cannot find output from $LEX; giving up" "$LINENO" 5 +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_lex_root" >&5 +$as_echo "$ac_cv_prog_lex_root" >&6; } +LEX_OUTPUT_ROOT=$ac_cv_prog_lex_root + +if test -z "${LEXLIB+set}"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking lex library" >&5 +$as_echo_n "checking lex library... " >&6; } +if ${ac_cv_lib_lex+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ac_save_LIBS=$LIBS + ac_cv_lib_lex='none needed' + for ac_lib in '' -lfl -ll; do + LIBS="$ac_lib $ac_save_LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +`cat $LEX_OUTPUT_ROOT.c` +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_lex=$ac_lib +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + test "$ac_cv_lib_lex" != 'none needed' && break + done + LIBS=$ac_save_LIBS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lex" >&5 +$as_echo "$ac_cv_lib_lex" >&6; } + test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether yytext is a pointer" >&5 +$as_echo_n "checking whether yytext is a pointer... " >&6; } +if ${ac_cv_prog_lex_yytext_pointer+:} false; then : + $as_echo_n "(cached) " >&6 +else + # POSIX says lex can declare yytext either as a pointer or an array; the +# default is implementation-dependent. Figure out which it is, since +# not all implementations provide the %pointer and %array declarations. +ac_cv_prog_lex_yytext_pointer=no +ac_save_LIBS=$LIBS +LIBS="$LEXLIB $ac_save_LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #define YYTEXT_POINTER 1 +`cat $LEX_OUTPUT_ROOT.c` +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_prog_lex_yytext_pointer=yes +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_save_LIBS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_lex_yytext_pointer" >&5 +$as_echo "$ac_cv_prog_lex_yytext_pointer" >&6; } +if test $ac_cv_prog_lex_yytext_pointer = yes; then + +$as_echo "#define YYTEXT_POINTER 1" >>confdefs.h + +fi +rm -f conftest.l $LEX_OUTPUT_ROOT.c + +fi +if test "$LEX" = ":"; then + as_fn_error $? "Neither flex nor lex was found." "$LINENO" 5 +fi + +# +# Make sure {f}lex supports the -P, --header-file, and --nounput flags +# and supports processing our scanner.l. +# +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable lex" >&5 +$as_echo_n "checking for capable lex... " >&6; } +if ${tcpdump_cv_capable_lex+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $LEX -P pcap_ --header-file=/dev/null --nounput -t $srcdir/scanner.l > /dev/null 2>&1; then + tcpdump_cv_capable_lex=yes + else + tcpdump_cv_capable_lex=insufficient + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcpdump_cv_capable_lex" >&5 +$as_echo "$tcpdump_cv_capable_lex" >&6; } +if test $tcpdump_cv_capable_lex = insufficient ; then + as_fn_error $? "$LEX is insufficient to compile libpcap. + libpcap requires Flex 2.5.31 or later, or a compatible version of lex." "$LINENO" 5 +fi + +# +# Look for yacc/bison/byacc. +# +for ac_prog in 'bison -y' byacc +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_YACC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$YACC"; then + ac_cv_prog_YACC="$YACC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_YACC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +YACC=$ac_cv_prog_YACC +if test -n "$YACC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $YACC" >&5 +$as_echo "$YACC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$YACC" && break +done +test -n "$YACC" || YACC="yacc" + + +# +# Make sure it supports the -p flag and supports processing our +# grammar.y. +# +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for capable yacc/bison" >&5 +$as_echo_n "checking for capable yacc/bison... " >&6; } +if ${tcpdump_cv_capable_yacc+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then + tcpdump_cv_capable_yacc=yes + else + tcpdump_cv_capable_yacc=insufficient + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcpdump_cv_capable_yacc" >&5 +$as_echo "$tcpdump_cv_capable_yacc" >&6; } +if test $tcpdump_cv_capable_yacc = insufficient ; then + as_fn_error $? "$YACC is insufficient to compile libpcap. + libpcap requires Bison, a newer version of Berkeley YACC with support + for reentrant parsers, or another YACC compatible with them." "$LINENO" 5 +fi + # # Do various checks for various OSes and versions of those OSes. # # Assume, by default, no support for shared libraries and V7/BSD -# convention for man pages (file formats in section 5, miscellaneous -# info in section 7, administrative commands and daemons in section 8). -# Individual cases can override this. +# convention for man pages (devices in section 4, file formats in +# section 5, miscellaneous info in section 7, administrative commands +# and daemons in section 8). Individual cases can override this. # DYEXT="none" +MAN_DEVICES=4 MAN_FILE_FORMATS=5 MAN_MISC_INFO=7 MAN_ADMIN_COMMANDS=8 @@ -7770,79 +8240,168 @@ fi if test "$enable_universal" != "no"; then case "$host_os" in - darwin0-7.*) + darwin[0-7].*) # # Pre-Tiger. Build only for 32-bit PowerPC; no # need for any special compiler or linker flags. # ;; - darwin8.0123*) + darwin8.[0123]|darwin8.[0123].*) # - # Tiger, prior to Intel support. Build for 32-bit - # PowerPC and 64-bit PowerPC, with 32-bit PowerPC - # first. (I'm guessing that's what Apple does.) - # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64" - ;; - - darwin8.456*) - # - # Tiger, subsequent to Intel support but prior to - # x86-64 support. Build for 32-bit PowerPC, 64-bit - # PowerPC, and x86, with 32-bit PowerPC first. + # Tiger, prior to Intel support. Build + # libraries and executables for 32-bit PowerPC + # and 64-bit PowerPC, with 32-bit PowerPC first. # (I'm guessing that's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386" + # (The double brackets are needed because + # autotools/m4 use brackets as a quoting + # character; the double brackets turn into + # single brackets in the generated configure + # file.) + # + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64" + ;; + + darwin8.[456]|darwin.[456].*) + # + # Tiger, subsequent to Intel support but prior + # to x86-64 support. Build libraries and + # executables for 32-bit PowerPC, 64-bit + # PowerPC, and 32-bit x86, with 32-bit PowerPC + # first. (I'm guessing that's what Apple does.) + # + # (The double brackets are needed because + # autotools/m4 use brackets as a quoting + # character; the double brackets turn into + # single brackets in the generated configure + # file.) + # + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386" ;; darwin8.*) # # All other Tiger, so subsequent to x86-64 - # support. Build for 32-bit PowerPC, 64-bit - # PowerPC, x86, and x86-64, and with 32-bit PowerPC - # first. (I'm guessing that's what Apple does.) + # support. Build libraries and executables for + # 32-bit PowerPC, 64-bit PowerPC, 32-bit x86, + # and x86-64, with 32-bit PowerPC first. (I'm + # guessing that's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" ;; darwin9.*) # - # Leopard. Build for 32-bit PowerPC, 64-bit - # PowerPC, x86, and x86-64, with 32-bit PowerPC - # first. (That's what Apple does.) + # Leopard. Build libraries for 32-bit PowerPC, + # 64-bit PowerPC, 32-bit x86, and x86-64, with + # 32-bit PowerPC first, and build executables + # for 32-bit x86 and 32-bit PowerPC, with 32-bit + # x86 first. (That's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_CCOPT_FAT="-arch i386 -arch ppc" + V_PROG_LDFLAGS_FAT="-arch i386 -arch ppc" ;; darwin10.*) # - # Snow Leopard. Build for x86-64, x86, and - # 32-bit PowerPC, with x86-64 first. (That's - # what Apple does, even though Snow Leopard - # doesn't run on PPC, so PPC libpcap runs under - # Rosetta, and Rosetta doesn't support BPF - # ioctls, so PPC programs can't do live - # captures.) + # Snow Leopard. Build libraries for x86-64, + # 32-bit x86, and 32-bit PowerPC, with x86-64 + # first, and build executables for x86-64 and + # 32-bit x86, with x86-64 first. (That's what + # Apple does, even though Snow Leopard doesn't + # run on PPC, so PPC libpcap runs under Rosetta, + # and Rosetta doesn't support BPF ioctls, so PPC + # programs can't do live captures.) # - V_CCOPT="$V_CCOPT -arch x86_64 -arch i386 -arch ppc" - LDFLAGS="$LDFLAGS -arch x86_64 -arch i386 -arch ppc" + V_LIB_CCOPT_FAT="-arch x86_64 -arch i386 -arch ppc" + V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386 -arch ppc" + V_PROG_CCOPT_FAT="-arch x86_64 -arch i386" + V_PROG_LDFLAGS_FAT="-arch x86_64 -arch i386" ;; darwin*) # - # Post-Snow Leopard. Build for x86-64 and - # x86, with x86-64 first. (That's probably what - # Apple does, given that Rosetta is gone.) + # Post-Snow Leopard. Build libraries for x86-64 + # and 32-bit x86, with x86-64 first, and build + # executables only for x86-64. (That's what + # Apple does.) This requires no special flags + # for programs. # XXX - update if and when Apple drops support - # for 32-bit x86 code. + # for 32-bit x86 code and if and when Apple adds + # ARM-based Macs. (You're on your own for iOS + # etc.) # - V_CCOPT="$V_CCOPT -arch x86_64 -arch i386" - LDFLAGS="$LDFLAGS -arch x86_64 -arch i386" + # XXX - check whether we *can* build for + # i386 and, if not, suggest that the user + # install the /usr/include headers if they + # want to build fat. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether building for 32-bit x86 is supported" >&5 +$as_echo_n "checking whether building for 32-bit x86 is supported... " >&6; } + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -arch i386" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + V_LIB_CCOPT_FAT="-arch x86_64 -arch i386" + V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386" + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + V_LIB_CCOPT_FAT="-arch x86_64" + V_LIB_LDFLAGS_FAT="-arch x86_64" + case "$host_os" in + + darwin18.*) + # + # Mojave; you need to install the + # /usr/include headers to get + # 32-bit x86 builds to work. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package" >&5 +$as_echo "$as_me: WARNING: Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package" >&2;} + ;; + + *) + # + # Pre-Mojave; the command-line + # tools should be sufficient to + # enable 32-bit x86 builds. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Compiling for 32-bit x86 gives an error; try installing the command-line tools" >&5 +$as_echo "$as_me: WARNING: Compiling for 32-bit x86 gives an error; try installing the command-line tools" >&2;} + ;; + esac + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$save_CFLAGS" ;; esac fi @@ -7914,7 +8473,7 @@ irix*) MAN_MISC_INFO=5 ;; -linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*) +linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*|midipix*) DYEXT="so" # @@ -7937,6 +8496,7 @@ osf*) # MAN_FILE_FORMATS=4 MAN_MISC_INFO=5 + MAN_DEVICES=7 ;; sinix*) @@ -8002,6 +8562,7 @@ $as_echo "#define HAVE_SOLARIS 1" >>confdefs.h MAN_ADMIN_COMMANDS=1m MAN_FILE_FORMATS=4 MAN_MISC_INFO=5 + MAN_DEVICES=7D esac ;; esac @@ -8011,7 +8572,7 @@ if test "${enable_shared+set}" = set; then : enableval=$enable_shared; fi -test "x$enable_shared" != "xyes" && DYEXT="none" +test "x$enable_shared" = "xno" && DYEXT="none" if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. @@ -8257,6 +8818,88 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext CFLAGS="$save_CFLAGS" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -W option" >&5 +$as_echo_n "checking whether the compiler supports the -W option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-W" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -W" + elif expr "x-W" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -W" + elif expr "x-W" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -W" + else + CFLAGS="$CFLAGS -W" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -W " >&5 +$as_echo_n "checking whether -W ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -W" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wall option" >&5 $as_echo_n "checking whether the compiler supports the -Wall option... " >&6; } save_CFLAGS="$CFLAGS" @@ -8339,580 +8982,6 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wsign-compare option" >&5 -$as_echo_n "checking whether the compiler supports the -Wsign-compare option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wsign-compare" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wsign-compare" - elif expr "x-Wsign-compare" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wsign-compare" - elif expr "x-Wsign-compare" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wsign-compare" - else - CFLAGS="$CFLAGS -Wsign-compare" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wsign-compare " >&5 -$as_echo_n "checking whether -Wsign-compare ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wsign-compare" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wmissing-prototypes option" >&5 -$as_echo_n "checking whether the compiler supports the -Wmissing-prototypes option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wmissing-prototypes" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wmissing-prototypes" - elif expr "x-Wmissing-prototypes" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wmissing-prototypes" - elif expr "x-Wmissing-prototypes" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wmissing-prototypes" - else - CFLAGS="$CFLAGS -Wmissing-prototypes" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wmissing-prototypes " >&5 -$as_echo_n "checking whether -Wmissing-prototypes ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wmissing-prototypes" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wstrict-prototypes option" >&5 -$as_echo_n "checking whether the compiler supports the -Wstrict-prototypes option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wstrict-prototypes" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wstrict-prototypes" - elif expr "x-Wstrict-prototypes" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wstrict-prototypes" - elif expr "x-Wstrict-prototypes" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wstrict-prototypes" - else - CFLAGS="$CFLAGS -Wstrict-prototypes" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wstrict-prototypes " >&5 -$as_echo_n "checking whether -Wstrict-prototypes ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wstrict-prototypes" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wshadow option" >&5 -$as_echo_n "checking whether the compiler supports the -Wshadow option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wshadow" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wshadow" - elif expr "x-Wshadow" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wshadow" - elif expr "x-Wshadow" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wshadow" - else - CFLAGS="$CFLAGS -Wshadow" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wshadow " >&5 -$as_echo_n "checking whether -Wshadow ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wshadow" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wdeclaration-after-statement option" >&5 -$as_echo_n "checking whether the compiler supports the -Wdeclaration-after-statement option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wdeclaration-after-statement" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wdeclaration-after-statement" - elif expr "x-Wdeclaration-after-statement" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wdeclaration-after-statement" - elif expr "x-Wdeclaration-after-statement" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wdeclaration-after-statement" - else - CFLAGS="$CFLAGS -Wdeclaration-after-statement" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wdeclaration-after-statement " >&5 -$as_echo_n "checking whether -Wdeclaration-after-statement ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wdeclaration-after-statement" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wused-but-marked-unused option" >&5 -$as_echo_n "checking whether the compiler supports the -Wused-but-marked-unused option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wused-but-marked-unused" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wused-but-marked-unused" - elif expr "x-Wused-but-marked-unused" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wused-but-marked-unused" - elif expr "x-Wused-but-marked-unused" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wused-but-marked-unused" - else - CFLAGS="$CFLAGS -Wused-but-marked-unused" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wused-but-marked-unused " >&5 -$as_echo_n "checking whether -Wused-but-marked-unused ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wused-but-marked-unused" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wdocumentation option" >&5 -$as_echo_n "checking whether the compiler supports the -Wdocumentation option... " >&6; } - save_CFLAGS="$CFLAGS" - if expr "x-Wdocumentation" : "x-W.*" >/dev/null - then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wdocumentation" - elif expr "x-Wdocumentation" : "x-f.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wdocumentation" - elif expr "x-Wdocumentation" : "x-m.*" >/dev/null - then - CFLAGS="$CFLAGS -Werror -Wdocumentation" - else - CFLAGS="$CFLAGS -Wdocumentation" - fi - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ -return 0 - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=yes - # - # The compile supports this; do we have some C code for - # which the warning should *not* appear? - # We test the fourth argument because the third argument - # could contain quotes, breaking the test. - # - if test "x" != "x" - then - CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wdocumentation " >&5 -$as_echo_n "checking whether -Wdocumentation ... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - # - # Not a problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - -else - - # - # A problem. - # - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - can_add_to_cflags=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - CFLAGS="$save_CFLAGS" - if test x"$can_add_to_cflags" = "xyes" - then - V_CCOPT="$V_CCOPT -Wdocumentation" - fi - -else - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - CFLAGS="$save_CFLAGS" - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wcomma option" >&5 $as_echo_n "checking whether the compiler supports the -Wcomma option... " >&6; } save_CFLAGS="$CFLAGS" @@ -8995,6 +9064,252 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wdeclaration-after-statement option" >&5 +$as_echo_n "checking whether the compiler supports the -Wdeclaration-after-statement option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wdeclaration-after-statement" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wdeclaration-after-statement" + elif expr "x-Wdeclaration-after-statement" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wdeclaration-after-statement" + elif expr "x-Wdeclaration-after-statement" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wdeclaration-after-statement" + else + CFLAGS="$CFLAGS -Wdeclaration-after-statement" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wdeclaration-after-statement " >&5 +$as_echo_n "checking whether -Wdeclaration-after-statement ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wdeclaration-after-statement" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wdocumentation option" >&5 +$as_echo_n "checking whether the compiler supports the -Wdocumentation option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wdocumentation" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wdocumentation" + elif expr "x-Wdocumentation" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wdocumentation" + elif expr "x-Wdocumentation" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wdocumentation" + else + CFLAGS="$CFLAGS -Wdocumentation" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wdocumentation " >&5 +$as_echo_n "checking whether -Wdocumentation ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wdocumentation" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wformat-nonliteral option" >&5 +$as_echo_n "checking whether the compiler supports the -Wformat-nonliteral option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wformat-nonliteral" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wformat-nonliteral" + elif expr "x-Wformat-nonliteral" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wformat-nonliteral" + elif expr "x-Wformat-nonliteral" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wformat-nonliteral" + else + CFLAGS="$CFLAGS -Wformat-nonliteral" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wformat-nonliteral " >&5 +$as_echo_n "checking whether -Wformat-nonliteral ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wformat-nonliteral" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wmissing-noreturn option" >&5 $as_echo_n "checking whether the compiler supports the -Wmissing-noreturn option... " >&6; } save_CFLAGS="$CFLAGS" @@ -9076,9 +9391,88 @@ $as_echo "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - # Warns about safeguards added in case the enums are - # extended - # AC_LBL_CHECK_COMPILER_OPT(V_CCOPT, -Wcovered-switch-default) + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wmissing-prototypes option" >&5 +$as_echo_n "checking whether the compiler supports the -Wmissing-prototypes option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wmissing-prototypes" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wmissing-prototypes" + elif expr "x-Wmissing-prototypes" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wmissing-prototypes" + elif expr "x-Wmissing-prototypes" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wmissing-prototypes" + else + CFLAGS="$CFLAGS -Wmissing-prototypes" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wmissing-prototypes " >&5 +$as_echo_n "checking whether -Wmissing-prototypes ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wmissing-prototypes" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wmissing-variable-declarations option" >&5 $as_echo_n "checking whether the compiler supports the -Wmissing-variable-declarations option... " >&6; } @@ -9162,6 +9556,252 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wshadow option" >&5 +$as_echo_n "checking whether the compiler supports the -Wshadow option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wshadow" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wshadow" + elif expr "x-Wshadow" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wshadow" + elif expr "x-Wshadow" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wshadow" + else + CFLAGS="$CFLAGS -Wshadow" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wshadow " >&5 +$as_echo_n "checking whether -Wshadow ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wshadow" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wsign-compare option" >&5 +$as_echo_n "checking whether the compiler supports the -Wsign-compare option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wsign-compare" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wsign-compare" + elif expr "x-Wsign-compare" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wsign-compare" + elif expr "x-Wsign-compare" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wsign-compare" + else + CFLAGS="$CFLAGS -Wsign-compare" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wsign-compare " >&5 +$as_echo_n "checking whether -Wsign-compare ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wsign-compare" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wstrict-prototypes option" >&5 +$as_echo_n "checking whether the compiler supports the -Wstrict-prototypes option... " >&6; } + save_CFLAGS="$CFLAGS" + if expr "x-Wstrict-prototypes" : "x-W.*" >/dev/null + then + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wstrict-prototypes" + elif expr "x-Wstrict-prototypes" : "x-f.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wstrict-prototypes" + elif expr "x-Wstrict-prototypes" : "x-m.*" >/dev/null + then + CFLAGS="$CFLAGS -Werror -Wstrict-prototypes" + else + CFLAGS="$CFLAGS -Wstrict-prototypes" + fi + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +return 0 + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=yes + # + # The compile supports this; do we have some C code for + # which the warning should *not* appear? + # We test the fourth argument because the third argument + # could contain quotes, breaking the test. + # + if test "x" != "x" + then + CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wstrict-prototypes " >&5 +$as_echo_n "checking whether -Wstrict-prototypes ... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # + # Not a problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +else + + # + # A problem. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + can_add_to_cflags=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + CFLAGS="$save_CFLAGS" + if test x"$can_add_to_cflags" = "xyes" + then + V_CCOPT="$V_CCOPT -Wstrict-prototypes" + fi + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + CFLAGS="$save_CFLAGS" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wunused-parameter option" >&5 $as_echo_n "checking whether the compiler supports the -Wunused-parameter option... " >&6; } save_CFLAGS="$CFLAGS" @@ -9244,20 +9884,20 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wformat-nonliteral option" >&5 -$as_echo_n "checking whether the compiler supports the -Wformat-nonliteral option... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wused-but-marked-unused option" >&5 +$as_echo_n "checking whether the compiler supports the -Wused-but-marked-unused option... " >&6; } save_CFLAGS="$CFLAGS" - if expr "x-Wformat-nonliteral" : "x-W.*" >/dev/null + if expr "x-Wused-but-marked-unused" : "x-W.*" >/dev/null then - CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wformat-nonliteral" - elif expr "x-Wformat-nonliteral" : "x-f.*" >/dev/null + CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wused-but-marked-unused" + elif expr "x-Wused-but-marked-unused" : "x-f.*" >/dev/null then - CFLAGS="$CFLAGS -Werror -Wformat-nonliteral" - elif expr "x-Wformat-nonliteral" : "x-m.*" >/dev/null + CFLAGS="$CFLAGS -Werror -Wused-but-marked-unused" + elif expr "x-Wused-but-marked-unused" : "x-m.*" >/dev/null then - CFLAGS="$CFLAGS -Werror -Wformat-nonliteral" + CFLAGS="$CFLAGS -Werror -Wused-but-marked-unused" else - CFLAGS="$CFLAGS -Wformat-nonliteral" + CFLAGS="$CFLAGS -Wused-but-marked-unused" fi cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -9284,8 +9924,8 @@ $as_echo "yes" >&6; } if test "x" != "x" then CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wformat-nonliteral " >&5 -$as_echo_n "checking whether -Wformat-nonliteral ... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wused-but-marked-unused " >&5 +$as_echo_n "checking whether -Wused-but-marked-unused ... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -9313,7 +9953,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext CFLAGS="$save_CFLAGS" if test x"$can_add_to_cflags" = "xyes" then - V_CCOPT="$V_CCOPT -Wformat-nonliteral" + V_CCOPT="$V_CCOPT -Wused-but-marked-unused" fi else @@ -9325,6 +9965,9 @@ $as_echo "no" >&6; } fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + # Warns about safeguards added in case the enums are + # extended + # AC_LBL_CHECK_COMPILER_OPT(V_CCOPT, -Wcovered-switch-default) # # This can cause problems with ntohs(), ntohl(), # htons(), and htonl() on some platforms, such @@ -9735,6 +10378,13 @@ $as_echo "#define LBL_ALIGN 1" >>confdefs.h + + + + + + + @@ -9747,7 +10397,7 @@ $as_echo "#define LBL_ALIGN 1" >>confdefs.h if test "${enable_usb+set}" = set; then : enableval=$enable_usb; else - enable_usb=no + enable_usb=yes fi @@ -9996,7 +10646,7 @@ fi if test "${enable_bluetooth+set}" = set; then : enableval=$enable_bluetooth; else - enable_bluetooth=no + enable_bluetooth=ifsupportavailable fi @@ -10121,7 +10771,7 @@ fi if test "${enable_dbus+set}" = set; then : enableval=$enable_dbus; else - enable_dbus=no + enable_dbus=ifavailable fi @@ -10271,17 +10921,17 @@ fi if test "${enable_rdma+set}" = set; then : enableval=$enable_rdma; else - enable_rdmasniff=ifavailable + enable_rdma=ifavailable fi if test "xxx_only" = yes; then # User requested something-else-only pcap, so they don't # want RDMA support. - enable_rdmasniff=no + enable_rdma=no fi -if test "x$enable_rdmasniff" != "xno"; then +if test "x$enable_rdma" != "xno"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ibv_get_device_list in -libverbs" >&5 $as_echo_n "checking for ibv_get_device_list in -libverbs... " >&6; } if ${ac_cv_lib_ibverbs_ibv_get_device_list+:} false; then : @@ -10481,7 +11131,7 @@ ac_config_headers="$ac_config_headers config.h" ac_config_commands="$ac_config_commands default-1" -ac_config_files="$ac_config_files Makefile pcap-filter.manmisc pcap-linktype.manmisc pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap pcap_open_offline.3pcap pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap testprogs/Makefile" +ac_config_files="$ac_config_files Makefile pcap-filter.manmisc pcap-linktype.manmisc pcap-tstamp.manmisc pcap-savefile.manfile pcap.3pcap pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile testprogs/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -10989,7 +11639,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pcap $as_me 1.9.0, which was +This file was extended by pcap $as_me 1.9.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -11055,7 +11705,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -pcap config.status 1.9.0 +pcap config.status 1.9.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -11182,8 +11832,6 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 for ac_config_target in $ac_config_targets do case $ac_config_target in - "rpcapd/Makefile") CONFIG_FILES="$CONFIG_FILES rpcapd/Makefile" ;; - "rpcapd/rpcapd.manadmin") CONFIG_FILES="$CONFIG_FILES rpcapd/rpcapd.manadmin" ;; "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "default-1") CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; @@ -11200,8 +11848,12 @@ do "pcap_list_tstamp_types.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_list_tstamp_types.3pcap" ;; "pcap_open_dead.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_open_dead.3pcap" ;; "pcap_open_offline.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_open_offline.3pcap" ;; + "pcap_set_immediate_mode.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_set_immediate_mode.3pcap" ;; "pcap_set_tstamp_precision.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_set_tstamp_precision.3pcap" ;; "pcap_set_tstamp_type.3pcap") CONFIG_FILES="$CONFIG_FILES pcap_set_tstamp_type.3pcap" ;; + "rpcapd/Makefile") CONFIG_FILES="$CONFIG_FILES rpcapd/Makefile" ;; + "rpcapd/rpcapd.manadmin") CONFIG_FILES="$CONFIG_FILES rpcapd/rpcapd.manadmin" ;; + "rpcapd/rpcapd-config.manfile") CONFIG_FILES="$CONFIG_FILES rpcapd/rpcapd-config.manfile" ;; "testprogs/Makefile") CONFIG_FILES="$CONFIG_FILES testprogs/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/libpcap/configure.ac b/libpcap/configure.ac index 93c884186..eba272395 100644 --- a/libpcap/configure.ac +++ b/libpcap/configure.ac @@ -28,6 +28,9 @@ AC_LBL_C_INIT_BEFORE_CC(V_CCOPT, V_INCLS) # At minimum, we want C++/C99-style // comments. # AC_PROG_CC_C99 +if test "$ac_cv_prog_cc_c99" = "no"; then + AC_MSG_WARN([The C compiler does not support C99; there may be compiler errors]) +fi AC_LBL_C_INIT(V_CCOPT, V_INCLS) AC_LBL_SHLIBS_INIT AC_LBL_C_INLINE @@ -83,13 +86,109 @@ esac AC_LBL_FIXINCLUDES -AC_CHECK_FUNCS(strerror strerror_r strerror_s strlcpy strlcat) +AC_CHECK_FUNCS(strerror) +AC_CHECK_FUNC(strerror_r, + [ + # + # We have strerror_r; if we define _GNU_SOURCE, is it a + # POSIX-compliant strerror_r() or a GNU strerror_r()? + # + AC_MSG_CHECKING(whether strerror_r is GNU-style) + AC_COMPILE_IFELSE( + [ + AC_LANG_SOURCE( +#define _GNU_SOURCE +#include +/* Define it GNU-style; that will cause an error if it's not GNU-style */ +extern char *strerror_r(int, char *, size_t); + +int +main(void) +{ + return 0; +} +) + ], + [ + # GNU-style + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_GNU_STRERROR_R,, + [Define to 1 if you have a GNU-style `strerror_r' function.]) + ], + [ + AC_MSG_RESULT(no) + AC_DEFINE(HAVE_POSIX_STRERROR_R,, + [Define to 1 if you have a POSIX-style `strerror_r' function.]) + ]) + ], + [ + # + # We don't have strerror_r; do we have strerror_s? + # + AC_CHECK_FUNCS(strerror_s) + ]) + +# +# Thanks, IBM, for not providing vsyslog() in AIX! +# +AC_CHECK_FUNCS(vsyslog) + +# +# Either: +# +# we have snprintf() and vsnprintf(), and have asprintf() and +# vasprintf(); +# +# we have snprintf() and vsnprintf(), but don't have asprintf() +# or vasprintf(); +# +# we have neither snprintf() nor vsnprintf(), and don't have +# asprintf() or vasprintf(), either. +# +# We assume that if we have asprintf() we have vasprintf(), as well +# as snprintf() and vsnprintf(), and that if we have snprintf() we +# have vsnprintf(). +# +# For the first case, we don't need any replacement routines. +# For the second case, we need replacement asprintf()/vasprintf() +# routines. +# For the third case, we need replacement snprintf()/vsnprintf() and +# asprintf()/vasprintf() routines. +# needsnprintf=no AC_CHECK_FUNCS(vsnprintf snprintf,, [needsnprintf=yes]) +needasprintf=no +AC_CHECK_FUNCS(vasprintf asprintf,, + [needasprintf=yes]) if test $needsnprintf = yes; then + # + # We assume we have none of them; missing/snprintf.c supplies + # all of them. + # AC_LIBOBJ([snprintf]) +elif test $needasprintf = yes; then + # + # We assume we have snprintf()/vsnprintf() but lack + # asprintf()/vasprintf(); missing/asprintf.c supplies + # the latter (using vsnprintf()). + # + AC_LIBOBJ([asprintf]) +fi + +needstrlcat=no +AC_CHECK_FUNCS(strlcat,, + [needstrlcat=yes]) +if test $needstrlcat = yes; then + AC_LIBOBJ([strlcat]) +fi + +needstrlcpy=no +AC_CHECK_FUNCS(strlcpy,, + [needstrlcpy=yes]) +if test $needstrlcpy = yes; then + AC_LIBOBJ([strlcpy]) fi needstrtok_r=no @@ -550,6 +649,10 @@ else # requires that various BSD-style integer types # be defined; # + # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h + # doesn't include it but does use struct timeval + # in ioctl definitions; + # # sys/ioctl.h and, if we have it, sys/ioccom.h, # because net/bpf.h defines ioctls; # @@ -568,6 +671,7 @@ else AC_TRY_COMPILE( [ #include +#include #include #include #ifdef HAVE_SYS_IOCCOM_H @@ -743,10 +847,10 @@ linux) # Do we have libnl? # AC_ARG_WITH(libnl, - AC_HELP_STRING([--without-libnl],[disable libnl support @<:@default=disabled@:>@]), + AC_HELP_STRING([--without-libnl],[disable libnl support @<:@default=yes, on Linux, if present@:>@]), with_libnl=$withval,with_libnl=if_available) - if test x$with_libnl = xyes ; then + if test x$with_libnl != xno ; then have_any_nl="no" incdir=-I/usr/include/libnl3 @@ -1462,7 +1566,7 @@ yes) AC_MSG_RESULT(yes) #include "ftmacros.h" #include ]) - AC_CONFIG_FILES([rpcapd/Makefile rpcapd/rpcapd.manadmin]) + AC_DEFINE(ENABLE_REMOTE,, [Define to 1 if remote packet capture is to be supported]) SSRC="$SSRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c" @@ -1489,15 +1593,60 @@ if test "$enable_yydebug" = "yes"; then fi AC_MSG_RESULT(${enable_yydebug-no}) +# +# Look for {f}lex. +# +AC_PROG_LEX +if test "$LEX" = ":"; then + AC_MSG_ERROR([Neither flex nor lex was found.]) +fi + +# +# Make sure {f}lex supports the -P, --header-file, and --nounput flags +# and supports processing our scanner.l. +# +AC_CACHE_CHECK([for capable lex], tcpdump_cv_capable_lex, + if $LEX -P pcap_ --header-file=/dev/null --nounput -t $srcdir/scanner.l > /dev/null 2>&1; then + tcpdump_cv_capable_lex=yes + else + tcpdump_cv_capable_lex=insufficient + fi) +if test $tcpdump_cv_capable_lex = insufficient ; then + AC_MSG_ERROR([$LEX is insufficient to compile libpcap. + libpcap requires Flex 2.5.31 or later, or a compatible version of lex.]) +fi + +# +# Look for yacc/bison/byacc. +# +AC_PROG_YACC + +# +# Make sure it supports the -p flag and supports processing our +# grammar.y. +# +AC_CACHE_CHECK([for capable yacc/bison], tcpdump_cv_capable_yacc, + if $YACC -p pcap_ -o /dev/null $srcdir/grammar.y >/dev/null 2>&1; then + tcpdump_cv_capable_yacc=yes + else + tcpdump_cv_capable_yacc=insufficient + fi) +if test $tcpdump_cv_capable_yacc = insufficient ; then + AC_MSG_ERROR([$YACC is insufficient to compile libpcap. + libpcap requires Bison, a newer version of Berkeley YACC with support + for reentrant parsers, or another YACC compatible with them.]) +fi + # # Do various checks for various OSes and versions of those OSes. # # Assume, by default, no support for shared libraries and V7/BSD -# convention for man pages (file formats in section 5, miscellaneous -# info in section 7, administrative commands and daemons in section 8). -# Individual cases can override this. +# convention for man pages (devices in section 4, file formats in +# section 5, miscellaneous info in section 7, administrative commands +# and daemons in section 8). Individual cases can override this. # DYEXT="none" +MAN_DEVICES=4 MAN_FILE_FORMATS=5 MAN_MISC_INFO=7 MAN_ADMIN_COMMANDS=8 @@ -1553,79 +1702,151 @@ darwin*) if test "$enable_universal" != "no"; then case "$host_os" in - darwin[0-7].*) + darwin[[0-7]].*) # # Pre-Tiger. Build only for 32-bit PowerPC; no # need for any special compiler or linker flags. # ;; - darwin8.[0123]*) + darwin8.[[0123]]|darwin8.[[0123]].*) # - # Tiger, prior to Intel support. Build for 32-bit - # PowerPC and 64-bit PowerPC, with 32-bit PowerPC - # first. (I'm guessing that's what Apple does.) - # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64" - ;; - - darwin8.[456]*) - # - # Tiger, subsequent to Intel support but prior to - # x86-64 support. Build for 32-bit PowerPC, 64-bit - # PowerPC, and x86, with 32-bit PowerPC first. + # Tiger, prior to Intel support. Build + # libraries and executables for 32-bit PowerPC + # and 64-bit PowerPC, with 32-bit PowerPC first. # (I'm guessing that's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386" + # (The double brackets are needed because + # autotools/m4 use brackets as a quoting + # character; the double brackets turn into + # single brackets in the generated configure + # file.) + # + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64" + ;; + + darwin8.[[456]]|darwin.[[456]].*) + # + # Tiger, subsequent to Intel support but prior + # to x86-64 support. Build libraries and + # executables for 32-bit PowerPC, 64-bit + # PowerPC, and 32-bit x86, with 32-bit PowerPC + # first. (I'm guessing that's what Apple does.) + # + # (The double brackets are needed because + # autotools/m4 use brackets as a quoting + # character; the double brackets turn into + # single brackets in the generated configure + # file.) + # + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386" ;; darwin8.*) # # All other Tiger, so subsequent to x86-64 - # support. Build for 32-bit PowerPC, 64-bit - # PowerPC, x86, and x86-64, and with 32-bit PowerPC - # first. (I'm guessing that's what Apple does.) + # support. Build libraries and executables for + # 32-bit PowerPC, 64-bit PowerPC, 32-bit x86, + # and x86-64, with 32-bit PowerPC first. (I'm + # guessing that's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" ;; darwin9.*) # - # Leopard. Build for 32-bit PowerPC, 64-bit - # PowerPC, x86, and x86-64, with 32-bit PowerPC - # first. (That's what Apple does.) + # Leopard. Build libraries for 32-bit PowerPC, + # 64-bit PowerPC, 32-bit x86, and x86-64, with + # 32-bit PowerPC first, and build executables + # for 32-bit x86 and 32-bit PowerPC, with 32-bit + # x86 first. (That's what Apple does.) # - V_CCOPT="$V_CCOPT -arch ppc -arch ppc64 -arch i386 -arch x86_64" - LDFLAGS="$LDFLAGS -arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_CCOPT_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_LIB_LDFLAGS_FAT="-arch ppc -arch ppc64 -arch i386 -arch x86_64" + V_PROG_CCOPT_FAT="-arch i386 -arch ppc" + V_PROG_LDFLAGS_FAT="-arch i386 -arch ppc" ;; darwin10.*) # - # Snow Leopard. Build for x86-64, x86, and - # 32-bit PowerPC, with x86-64 first. (That's - # what Apple does, even though Snow Leopard - # doesn't run on PPC, so PPC libpcap runs under - # Rosetta, and Rosetta doesn't support BPF - # ioctls, so PPC programs can't do live - # captures.) + # Snow Leopard. Build libraries for x86-64, + # 32-bit x86, and 32-bit PowerPC, with x86-64 + # first, and build executables for x86-64 and + # 32-bit x86, with x86-64 first. (That's what + # Apple does, even though Snow Leopard doesn't + # run on PPC, so PPC libpcap runs under Rosetta, + # and Rosetta doesn't support BPF ioctls, so PPC + # programs can't do live captures.) # - V_CCOPT="$V_CCOPT -arch x86_64 -arch i386 -arch ppc" - LDFLAGS="$LDFLAGS -arch x86_64 -arch i386 -arch ppc" + V_LIB_CCOPT_FAT="-arch x86_64 -arch i386 -arch ppc" + V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386 -arch ppc" + V_PROG_CCOPT_FAT="-arch x86_64 -arch i386" + V_PROG_LDFLAGS_FAT="-arch x86_64 -arch i386" ;; darwin*) # - # Post-Snow Leopard. Build for x86-64 and - # x86, with x86-64 first. (That's probably what - # Apple does, given that Rosetta is gone.) + # Post-Snow Leopard. Build libraries for x86-64 + # and 32-bit x86, with x86-64 first, and build + # executables only for x86-64. (That's what + # Apple does.) This requires no special flags + # for programs. # XXX - update if and when Apple drops support - # for 32-bit x86 code. + # for 32-bit x86 code and if and when Apple adds + # ARM-based Macs. (You're on your own for iOS + # etc.) # - V_CCOPT="$V_CCOPT -arch x86_64 -arch i386" - LDFLAGS="$LDFLAGS -arch x86_64 -arch i386" + # XXX - check whether we *can* build for + # i386 and, if not, suggest that the user + # install the /usr/include headers if they + # want to build fat. + # + AC_MSG_CHECKING(whether building for 32-bit x86 is supported) + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -arch i386" + AC_TRY_COMPILE( + [], + [return 0;], + [ + AC_MSG_RESULT(yes) + V_LIB_CCOPT_FAT="-arch x86_64 -arch i386" + V_LIB_LDFLAGS_FAT="-arch x86_64 -arch i386" + ], + [ + AC_MSG_RESULT(no) + V_LIB_CCOPT_FAT="-arch x86_64" + V_LIB_LDFLAGS_FAT="-arch x86_64" + case "$host_os" in + + darwin18.*) + # + # Mojave; you need to install the + # /usr/include headers to get + # 32-bit x86 builds to work. + # + AC_MSG_WARN([Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package]) + ;; + + *) + # + # Pre-Mojave; the command-line + # tools should be sufficient to + # enable 32-bit x86 builds. + # + AC_MSG_WARN([Compiling for 32-bit x86 gives an error; try installing the command-line tools]) + ;; + esac + ]) + CFLAGS="$save_CFLAGS" ;; esac fi @@ -1699,7 +1920,7 @@ irix*) MAN_MISC_INFO=5 ;; -linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*) +linux*|freebsd*|netbsd*|openbsd*|dragonfly*|kfreebsd*|gnu*|midipix*) DYEXT="so" # @@ -1722,6 +1943,7 @@ osf*) # MAN_FILE_FORMATS=4 MAN_MISC_INFO=5 + MAN_DEVICES=7 ;; sinix*) @@ -1765,13 +1987,14 @@ solaris*) MAN_ADMIN_COMMANDS=1m MAN_FILE_FORMATS=4 MAN_MISC_INFO=5 + MAN_DEVICES=7D esac ;; esac AC_ARG_ENABLE(shared, -AC_HELP_STRING([--enable-shared],[build shared libraries @<:@default=no@:>@])) -test "x$enable_shared" != "xyes" && DYEXT="none" +AC_HELP_STRING([--enable-shared],[build shared libraries @<:@default=yes, if support available@:>@])) +test "x$enable_shared" = "xno" && DYEXT="none" AC_PROG_RANLIB AC_CHECK_TOOL([AR], [ar]) @@ -1820,19 +2043,26 @@ AC_CHECK_MEMBERS([dl_hp_ppa_info_t.dl_module_id_1],,, AC_LBL_UNALIGNED_ACCESS AC_SUBST(V_CCOPT) +AC_SUBST(V_LIB_CCOPT_FAT) +AC_SUBST(V_LIB_LDFLAGS_FAT) +AC_SUBST(V_PROG_CCOPT_FAT) +AC_SUBST(V_PROG_LDFLAGS_FAT) AC_SUBST(V_DEFS) AC_SUBST(V_FINDALLDEVS) AC_SUBST(V_INCLS) +AC_SUBST(V_LEX) AC_SUBST(V_PCAP) AC_SUBST(V_SHLIB_CCOPT) AC_SUBST(V_SHLIB_CMD) AC_SUBST(V_SHLIB_OPT) AC_SUBST(V_SONAME_OPT) AC_SUBST(V_RPATH_OPT) +AC_SUBST(V_YACC) AC_SUBST(ADDLOBJS) AC_SUBST(ADDLARCHIVEOBJS) AC_SUBST(SSRC) AC_SUBST(DYEXT) +AC_SUBST(MAN_DEVICES) AC_SUBST(MAN_FILE_FORMATS) AC_SUBST(MAN_MISC_INFO) AC_SUBST(MAN_ADMIN_COMMANDS) @@ -1843,9 +2073,9 @@ AC_SUBST(RPCAPD_LIBS) AC_SUBST(EXTRA_NETWORK_LIBS) AC_ARG_ENABLE([usb], -[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=no@:>@])], +[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=yes, if support available@:>@])], [], - [enable_usb=no]) + [enable_usb=yes]) if test "xxx_only" = yes; then # User requested something-else-only pcap, so they don't @@ -1991,9 +2221,9 @@ fi AC_ARG_ENABLE([bluetooth], -[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=no@:>@])], +[AC_HELP_STRING([--enable-bluetooth],[enable Bluetooth support @<:@default=yes, if support available@:>@])], [], - [enable_bluetooth=no]) + [enable_bluetooth=ifsupportavailable]) if test "xxx_only" = yes; then # User requested something-else-only pcap, so they don't @@ -2076,9 +2306,9 @@ if test "x$enable_bluetooth" != "xno" ; then fi AC_ARG_ENABLE([dbus], -[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=no@:>@])], +[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])], [], - [enable_dbus=no]) + [enable_dbus=ifavailable]) if test "xxx_only" = yes; then # User requested something-else-only pcap, so they don't @@ -2167,15 +2397,15 @@ fi AC_ARG_ENABLE([rdma], [AC_HELP_STRING([--enable-rdma],[enable RDMA capture support @<:@default=yes, if support available@:>@])], [], - [enable_rdmasniff=ifavailable]) + [enable_rdma=ifavailable]) if test "xxx_only" = yes; then # User requested something-else-only pcap, so they don't # want RDMA support. - enable_rdmasniff=no + enable_rdma=no fi -if test "x$enable_rdmasniff" != "xno"; then +if test "x$enable_rdma" != "xno"; then AC_CHECK_LIB(ibverbs, ibv_get_device_list, [ AC_CHECK_HEADER(infiniband/verbs.h, [ # @@ -2228,7 +2458,8 @@ AC_OUTPUT(Makefile pcap-filter.manmisc pcap-linktype.manmisc pcap_compile.3pcap pcap_datalink.3pcap pcap_dump_open.3pcap pcap_get_tstamp_precision.3pcap pcap_list_datalinks.3pcap pcap_list_tstamp_types.3pcap pcap_open_dead.3pcap - pcap_open_offline.3pcap pcap_set_tstamp_precision.3pcap - pcap_set_tstamp_type.3pcap + pcap_open_offline.3pcap pcap_set_immediate_mode.3pcap + pcap_set_tstamp_precision.3pcap pcap_set_tstamp_type.3pcap + rpcapd/Makefile rpcapd/rpcapd.manadmin rpcapd/rpcapd-config.manfile testprogs/Makefile) exit 0 diff --git a/libpcap/fmtutils.c b/libpcap/fmtutils.c index f1a890732..091e0d35e 100644 --- a/libpcap/fmtutils.c +++ b/libpcap/fmtutils.c @@ -65,11 +65,6 @@ pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, size_t msglen; char *p; size_t errbuflen_remaining; -#if defined(HAVE_STRERROR_S) - errno_t err; -#elif defined(HAVE_STRERROR_R) - int err; -#endif va_start(ap, fmt); pcap_vsnprintf(errbuf, errbuflen, fmt, ap); @@ -96,7 +91,10 @@ pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, * Now append the string for the error code. */ #if defined(HAVE_STRERROR_S) - err = strerror_s(p, errbuflen_remaining, errnum); + /* + * We have a Windows-style strerror_s(). + */ + errno_t err = strerror_s(p, errbuflen_remaining, errnum); if (err != 0) { /* * It doesn't appear to be documented anywhere obvious @@ -104,8 +102,24 @@ pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, */ pcap_snprintf(p, errbuflen_remaining, "Error %d", errnum); } -#elif defined(HAVE_STRERROR_R) - err = strerror_r(errnum, p, errbuflen_remaining); +#elif defined(HAVE_GNU_STRERROR_R) + /* + * We have a GNU-style strerror_r(), which is *not* guaranteed to + * do anything to the buffer handed to it, and which returns a + * pointer to the error string, which may or may not be in + * the buffer. + * + * It is, however, guaranteed to succeed. + */ + char strerror_buf[PCAP_ERRBUF_SIZE]; + char *errstring = strerror_r(errnum, strerror_buf, PCAP_ERRBUF_SIZE); + pcap_snprintf(p, errbuflen_remaining, "%s", errstring); +#elif defined(HAVE_POSIX_STRERROR_R) + /* + * We have a POSIX-style strerror_r(), which is guaranteed to fill + * in the buffer, but is not guaranteed to succeed. + */ + int err = strerror_r(errnum, p, errbuflen_remaining); if (err == EINVAL) { /* * UNIX 03 says this isn't guaranteed to produce a @@ -129,3 +143,72 @@ pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, pcap_snprintf(p, errbuflen_remaining, "%s", pcap_strerror(errnum)); #endif } + +#ifdef _WIN32 +/* + * Generate an error message based on a format, arguments, and a + * Win32 error, with a message for the Win32 error after the formatted output. + */ +void +pcap_fmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum, + const char *fmt, ...) +{ + va_list ap; + size_t msglen; + char *p; + size_t errbuflen_remaining; + DWORD retval; + char win32_errbuf[PCAP_ERRBUF_SIZE+1]; + + va_start(ap, fmt); + pcap_vsnprintf(errbuf, errbuflen, fmt, ap); + va_end(ap); + msglen = strlen(errbuf); + + /* + * Do we have enough space to append ": "? + * Including the terminating '\0', that's 3 bytes. + */ + if (msglen + 3 > errbuflen) { + /* No - just give them what we've produced. */ + return; + } + p = errbuf + msglen; + errbuflen_remaining = errbuflen - msglen; + *p++ = ':'; + *p++ = ' '; + *p = '\0'; + msglen += 2; + errbuflen_remaining -= 2; + + /* + * Now append the string for the error code. + * + * XXX - what language ID to use? + * + * For UN*Xes, pcap_strerror() may or may not return localized + * strings. + * + * We currently don't have localized messages for libpcap, but + * we might want to do so. On the other hand, if most of these + * messages are going to be read by libpcap developers and + * perhaps by developers of libpcap-based applications, English + * might be a better choice, so the developer doesn't have to + * get the message translated if it's in a language they don't + * happen to understand. + */ + retval = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + win32_errbuf, PCAP_ERRBUF_SIZE, NULL); + if (retval == 0) { + /* + * Failed. + */ + pcap_snprintf(p, errbuflen_remaining, + "Couldn't get error message for error (%lu)", errnum); + return; + } + + pcap_snprintf(p, errbuflen_remaining, "%s (%lu)", win32_errbuf, errnum); +} +#endif diff --git a/libpcap/fmtutils.h b/libpcap/fmtutils.h index 62c78fdba..838948bcd 100644 --- a/libpcap/fmtutils.h +++ b/libpcap/fmtutils.h @@ -43,6 +43,11 @@ extern "C" { void pcap_fmt_errmsg_for_errno(char *, size_t, int, PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5); +#ifdef _WIN32 +void pcap_fmt_errmsg_for_win32_err(char *, size_t, DWORD, + PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5); +#endif + #ifdef __cplusplus } #endif diff --git a/libpcap/ftmacros.h b/libpcap/ftmacros.h index de8da98e3..cd3daebdf 100644 --- a/libpcap/ftmacros.h +++ b/libpcap/ftmacros.h @@ -85,20 +85,14 @@ */ #elif defined(__linux__) || defined(linux) || defined(__linux) /* - * We can't turn _GNU_SOURCE on because some versions of GNU Libc - * will give the GNU version of strerror_r(), which returns a - * string pointer and doesn't necessarily fill in the buffer, - * rather than the standard version of strerror_r(), which - * returns 0 or an errno and always fills in the buffer. We - * require both of the latter behaviors. + * Turn on _GNU_SOURCE to get everything GNU libc has to offer, + * including asprintf(). * - * So we try turning everything else on that we can. This includes - * defining _XOPEN_SOURCE as 600, because we want to force crypt() - * to be declared on systems that use GNU libc, such as most Linux - * distributions. + * Unfortunately, one thing it has to offer is a strerror_r() + * that's not POSIX-compliant, but we deal with that in + * pcap_fmt_errmsg_for_errno(). */ - #define _POSIX_C_SOURCE 200809L - #define _XOPEN_SOURCE 600 + #define _GNU_SOURCE /* * We turn on both _DEFAULT_SOURCE and _BSD_SOURCE to try to get diff --git a/libpcap/gencode.c b/libpcap/gencode.c index 959a56e6e..e3425cd9e 100644 --- a/libpcap/gencode.c +++ b/libpcap/gencode.c @@ -50,6 +50,8 @@ #include "pcap-int.h" +#include "extract.h" + #include "ethertype.h" #include "nlpid.h" #include "llc.h" @@ -276,6 +278,13 @@ struct _compiler_state { */ struct addrinfo *ai; + /* + * Another thing that's allocated is the result of pcap_ether_aton(); + * it must be freed with free(). This variable points to any + * address that would need to be freed. + */ + u_char *e; + /* * Various code constructs need to know the layout of the packet. * These values give the necessary offsets from the beginning @@ -417,35 +426,49 @@ struct _compiler_state { int cur_chunk; }; -void PCAP_NORETURN -bpf_syntax_error(compiler_state_t *cstate, const char *msg) +/* + * For use by routines outside this file. + */ +/* VARARGS */ +void +bpf_set_error(compiler_state_t *cstate, const char *fmt, ...) { - bpf_error(cstate, "syntax error in filter expression: %s", msg); - /* NOTREACHED */ + va_list ap; + + va_start(ap, fmt); + (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, + fmt, ap); + va_end(ap); } +/* + * For use *ONLY* in routines in this file. + */ +static void PCAP_NORETURN bpf_error(compiler_state_t *, const char *, ...) + PCAP_PRINTFLIKE(2, 3); + /* VARARGS */ -void PCAP_NORETURN +static void PCAP_NORETURN bpf_error(compiler_state_t *cstate, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - if (cstate->bpf_pcap != NULL) - (void)pcap_vsnprintf(pcap_geterr(cstate->bpf_pcap), - PCAP_ERRBUF_SIZE, fmt, ap); + (void)pcap_vsnprintf(cstate->bpf_pcap->errbuf, PCAP_ERRBUF_SIZE, + fmt, ap); va_end(ap); longjmp(cstate->top_ctx, 1); - /* NOTREACHED */ + /*NOTREACHED*/ } -static void init_linktype(compiler_state_t *, pcap_t *); +static int init_linktype(compiler_state_t *, pcap_t *); static void init_regs(compiler_state_t *); static int alloc_reg(compiler_state_t *); static void free_reg(compiler_state_t *, int); static void initchunks(compiler_state_t *cstate); +static void *newchunk_nolongjmp(compiler_state_t *cstate, size_t); static void *newchunk(compiler_state_t *cstate, size_t); static void freechunks(compiler_state_t *cstate); static inline struct block *new_block(compiler_state_t *cstate, int); @@ -543,6 +566,9 @@ static struct block *gen_check_802_11_data_frame(compiler_state_t *); static struct block *gen_geneve_ll_check(compiler_state_t *cstate); static struct block *gen_ppi_dlt_check(compiler_state_t *); +static struct block *gen_atmfield_code_internal(compiler_state_t *, int, + bpf_int32, bpf_u_int32, int); +static struct block *gen_atmtype_llc(compiler_state_t *); static struct block *gen_msg_abbrev(compiler_state_t *, int type); static void @@ -558,7 +584,7 @@ initchunks(compiler_state_t *cstate) } static void * -newchunk(compiler_state_t *cstate, size_t n) +newchunk_nolongjmp(compiler_state_t *cstate, size_t n) { struct chunk *cp; int k; @@ -576,21 +602,40 @@ newchunk(compiler_state_t *cstate, size_t n) if (n > cp->n_left) { ++cp; k = ++cstate->cur_chunk; - if (k >= NCHUNKS) - bpf_error(cstate, "out of memory"); + if (k >= NCHUNKS) { + bpf_set_error(cstate, "out of memory"); + return (NULL); + } size = CHUNK0SIZE << k; cp->m = (void *)malloc(size); - if (cp->m == NULL) - bpf_error(cstate, "out of memory"); + if (cp->m == NULL) { + bpf_set_error(cstate, "out of memory"); + return (NULL); + } memset((char *)cp->m, 0, size); cp->n_left = size; - if (n > size) - bpf_error(cstate, "out of memory"); + if (n > size) { + bpf_set_error(cstate, "out of memory"); + return (NULL); + } } cp->n_left -= n; return (void *)((char *)cp->m + cp->n_left); } +static void * +newchunk(compiler_state_t *cstate, size_t n) +{ + void *p; + + p = newchunk_nolongjmp(cstate, n); + if (p == NULL) { + longjmp(cstate->top_ctx, 1); + /*NOTREACHED*/ + } + return (p); +} + static void freechunks(compiler_state_t *cstate) { @@ -603,14 +648,19 @@ freechunks(compiler_state_t *cstate) /* * A strdup whose allocations are freed after code generation is over. + * This is used by the lexical analyzer, so it can't longjmp; it just + * returns NULL on an allocation error, and the callers must check + * for it. */ char * sdup(compiler_state_t *cstate, const char *s) { size_t n = strlen(s) + 1; - char *cp = newchunk(cstate, n); + char *cp = newchunk_nolongjmp(cstate, n); - strlcpy(cp, s, n); + if (cp == NULL) + return (NULL); + pcap_strlcpy(cp, s, n); return (cp); } @@ -662,7 +712,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program, compiler_state_t cstate; const char * volatile xbuf = buf; yyscan_t scanner = NULL; - YY_BUFFER_STATE in_buffer = NULL; + volatile YY_BUFFER_STATE in_buffer = NULL; u_int len; int rc; @@ -697,7 +747,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program, * filter for this pcap_t; we might be running it from userland * on captured packets to do packet classification. We really * need a better way of handling this, but this is all that - * the WinPcap code did. + * the WinPcap remote capture code did. */ if (p->save_current_filter_op != NULL) (p->save_current_filter_op)(p, buf); @@ -708,20 +758,12 @@ pcap_compile(pcap_t *p, struct bpf_program *program, #ifdef INET6 cstate.ai = NULL; #endif + cstate.e = NULL; cstate.ic.root = NULL; cstate.ic.cur_mark = 0; cstate.bpf_pcap = p; init_regs(&cstate); - if (setjmp(cstate.top_ctx)) { -#ifdef INET6 - if (cstate.ai != NULL) - freeaddrinfo(cstate.ai); -#endif - rc = -1; - goto quit; - } - cstate.netmask = mask; cstate.snaplen = pcap_snapshot(p); @@ -743,19 +785,53 @@ pcap_compile(pcap_t *p, struct bpf_program *program, */ pcap_set_extra(&cstate, scanner); - init_linktype(&cstate, p); - (void)pcap_parse(scanner, &cstate); + if (init_linktype(&cstate, p) == -1) { + rc = -1; + goto quit; + } + if (pcap_parse(scanner, &cstate) != 0) { +#ifdef INET6 + if (cstate.ai != NULL) + freeaddrinfo(cstate.ai); +#endif + if (cstate.e != NULL) + free(cstate.e); + rc = -1; + goto quit; + } - if (cstate.ic.root == NULL) + if (cstate.ic.root == NULL) { + /* + * Catch errors reported by gen_retblk(). + */ + if (setjmp(cstate.top_ctx)) { + rc = -1; + goto quit; + } cstate.ic.root = gen_retblk(&cstate, cstate.snaplen); + } if (optimize && !cstate.no_optimize) { - bpf_optimize(&cstate, &cstate.ic); + if (bpf_optimize(&cstate.ic, p->errbuf) == -1) { + /* Failure */ + rc = -1; + goto quit; + } if (cstate.ic.root == NULL || - (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) - bpf_error(&cstate, "expression rejects all packets"); + (cstate.ic.root->s.code == (BPF_RET|BPF_K) && cstate.ic.root->s.k == 0)) { + (void)pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "expression rejects all packets"); + rc = -1; + goto quit; + } + } + program->bf_insns = icode_to_fcode(&cstate.ic, + cstate.ic.root, &len, p->errbuf); + if (program->bf_insns == NULL) { + /* Failure */ + rc = -1; + goto quit; } - program->bf_insns = icode_to_fcode(&cstate, &cstate.ic, cstate.ic.root, &len); program->bf_len = len; rc = 0; /* We're all okay */ @@ -851,11 +927,18 @@ merge(struct block *b0, struct block *b1) *p = b1; } -void +int finish_parse(compiler_state_t *cstate, struct block *p) { struct block *ppi_dlt_check; + /* + * Catch errors reported by us and routines below us, and return -1 + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (-1); + /* * Insert before the statements of the first (root) block any * statements needed to load the lengths of any variable-length @@ -898,6 +981,7 @@ finish_parse(compiler_state_t *cstate, struct block *p) p->sense = !p->sense; backpatch(p, gen_retblk(cstate, 0)); cstate->ic.root = p->head; + return (0); } void @@ -975,13 +1059,22 @@ gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, { register struct block *b, *tmp; + /* + * XXX - the actual *instructions* do unsigned comparisons on + * most platforms, and the load instructions don't do sign + * extension, so gen_cmp() should really take an unsigned + * value argument. + * + * As the load instructons also don't do sign-extension, we + * fetch the values from the byte array as unsigned. We don't + * want to use the signed versions of the extract calls. + */ b = NULL; while (size >= 4) { register const u_char *p = &v[size - 4]; - bpf_int32 w = ((bpf_int32)p[0] << 24) | - ((bpf_int32)p[1] << 16) | ((bpf_int32)p[2] << 8) | p[3]; - tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, w); + tmp = gen_cmp(cstate, offrel, offset + size - 4, BPF_W, + (bpf_int32)EXTRACT_32BITS(p)); if (b != NULL) gen_and(b, tmp); b = tmp; @@ -989,9 +1082,9 @@ gen_bcmp(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, } while (size >= 2) { register const u_char *p = &v[size - 2]; - bpf_int32 w = ((bpf_int32)p[0] << 8) | p[1]; - tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, w); + tmp = gen_cmp(cstate, offrel, offset + size - 2, BPF_H, + (bpf_int32)EXTRACT_16BITS(p)); if (b != NULL) gen_and(b, tmp); b = tmp; @@ -1036,7 +1129,7 @@ gen_ncmp(compiler_state_t *cstate, enum e_offrel offrel, bpf_u_int32 offset, return b; } -static void +static int init_linktype(compiler_state_t *cstate, pcap_t *p) { cstate->pcap_fddipad = p->fddipad; @@ -1241,6 +1334,7 @@ init_linktype(compiler_state_t *cstate, pcap_t *p) cstate->off_linkhdr.is_variable = 1; /* Fall through, 802.11 doesn't have a variable link * prefix but is otherwise the same. */ + /* FALLTHROUGH */ case DLT_IEEE802_11: /* @@ -1330,13 +1424,20 @@ init_linktype(compiler_state_t *cstate, pcap_t *p) cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ break; - case DLT_LINUX_SLL: /* fake header for Linux cooked socket */ + case DLT_LINUX_SLL: /* fake header for Linux cooked socket v1 */ cstate->off_linktype.constant_part = 14; cstate->off_linkpl.constant_part = 16; cstate->off_nl = 0; cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ break; + case DLT_LINUX_SLL2: /* fake header for Linux cooked socket v2 */ + cstate->off_linktype.constant_part = 0; + cstate->off_linkpl.constant_part = 20; + cstate->off_nl = 0; + cstate->off_nl_nosnap = 0; /* no 802.2 LLC */ + break; + case DLT_LTALK: /* * LocalTalk does have a 1-byte type field in the LLAP header, @@ -1612,12 +1713,14 @@ init_linktype(compiler_state_t *cstate, pcap_t *p) cstate->off_nl = OFFSET_NOT_SET; cstate->off_nl_nosnap = OFFSET_NOT_SET; } else { - bpf_error(cstate, "unknown data link type %d", cstate->linktype); + bpf_set_error(cstate, "unknown data link type %d", cstate->linktype); + return (-1); } break; } cstate->off_outermostlinkhdr = cstate->off_prevlinkhdr = cstate->off_linkhdr; + return (0); } /* @@ -1669,6 +1772,19 @@ gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, { struct slist *s, *s2; + /* + * Squelch warnings from compilers that *don't* assume that + * offrel always has a valid enum value and therefore don't + * assume that we'll always go through one of the case arms. + * + * If we have a default case, compilers that *do* assume that + * will then complain about the default case code being + * unreachable. + * + * Damned if you do, damned if you don't. + */ + s = NULL; + switch (offrel) { case OR_PACKET: @@ -1732,10 +1848,6 @@ gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset, case OR_TRAN_IPV6: s = gen_load_absoffsetrel(cstate, &cstate->off_linkpl, cstate->off_nl + 40 + offset, size); break; - - default: - abort(); - /* NOTREACHED */ } return s; } @@ -2059,12 +2171,12 @@ gen_ipnet_linktype(compiler_state_t *cstate, int proto) case ETHERTYPE_IP: return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, (bpf_int32)IPH_AF_INET); - /* NOTREACHED */ + /*NOTREACHED*/ case ETHERTYPE_IPV6: return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_B, (bpf_int32)IPH_AF_INET6); - /* NOTREACHED */ + /*NOTREACHED*/ default: break; @@ -3041,7 +3153,7 @@ gen_linktype(compiler_state_t *cstate, int proto) default: bpf_error(cstate, "unsupported protocol over mpls"); - /* NOTREACHED */ + /*NOTREACHED*/ } } @@ -3062,7 +3174,6 @@ gen_linktype(compiler_state_t *cstate, int proto) gen_and(b0, b1); return b1; /*NOTREACHED*/ - break; case DLT_C_HDLC: switch (proto) { @@ -3074,9 +3185,7 @@ gen_linktype(compiler_state_t *cstate, int proto) default: return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); /*NOTREACHED*/ - break; } - break; case DLT_IEEE802_11: case DLT_PRISM_HEADER: @@ -3095,7 +3204,6 @@ gen_linktype(compiler_state_t *cstate, int proto) gen_and(b0, b1); return b1; /*NOTREACHED*/ - break; case DLT_FDDI: /* @@ -3103,7 +3211,6 @@ gen_linktype(compiler_state_t *cstate, int proto) */ return gen_llc_linktype(cstate, proto); /*NOTREACHED*/ - break; case DLT_IEEE802: /* @@ -3111,14 +3218,12 @@ gen_linktype(compiler_state_t *cstate, int proto) */ return gen_llc_linktype(cstate, proto); /*NOTREACHED*/ - break; case DLT_ATM_RFC1483: case DLT_ATM_CLIP: case DLT_IP_OVER_FC: return gen_llc_linktype(cstate, proto); /*NOTREACHED*/ - break; case DLT_SUNATM: /* @@ -3128,17 +3233,15 @@ gen_linktype(compiler_state_t *cstate, int proto) * * Check for LLC encapsulation and then check the protocol. */ - b0 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); b1 = gen_llc_linktype(cstate, proto); gen_and(b0, b1); return b1; /*NOTREACHED*/ - break; case DLT_LINUX_SLL: return gen_linux_sll_linktype(cstate, proto); /*NOTREACHED*/ - break; case DLT_SLIP: case DLT_SLIP_BSDOS: @@ -3164,7 +3267,6 @@ gen_linktype(compiler_state_t *cstate, int proto) return gen_false(cstate); /* always false */ } /*NOTREACHED*/ - break; case DLT_IPV4: /* @@ -3176,7 +3278,6 @@ gen_linktype(compiler_state_t *cstate, int proto) /* Checking for something other than IPv4; always false */ return gen_false(cstate); /*NOTREACHED*/ - break; case DLT_IPV6: /* @@ -3188,7 +3289,6 @@ gen_linktype(compiler_state_t *cstate, int proto) /* Checking for something other than IPv6; always false */ return gen_false(cstate); /*NOTREACHED*/ - break; case DLT_PPP: case DLT_PPP_PPPD: @@ -3201,7 +3301,6 @@ gen_linktype(compiler_state_t *cstate, int proto) proto = ethertype_to_ppptype(proto); return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); /*NOTREACHED*/ - break; case DLT_PPP_BSDOS: /* @@ -3228,7 +3327,6 @@ gen_linktype(compiler_state_t *cstate, int proto) (bpf_int32)proto); } /*NOTREACHED*/ - break; case DLT_NULL: case DLT_LOOP: @@ -3323,7 +3421,6 @@ gen_linktype(compiler_state_t *cstate, int proto) else return gen_false(cstate); /*NOTREACHED*/ - break; #endif /* HAVE_NET_PFVAR_H */ case DLT_ARCNET: @@ -3366,7 +3463,6 @@ gen_linktype(compiler_state_t *cstate, int proto) (bpf_int32)ARCTYPE_ATALK)); } /*NOTREACHED*/ - break; case DLT_LTALK: switch (proto) { @@ -3376,7 +3472,6 @@ gen_linktype(compiler_state_t *cstate, int proto) return gen_false(cstate); } /*NOTREACHED*/ - break; case DLT_FRELAY: /* @@ -3420,7 +3515,6 @@ gen_linktype(compiler_state_t *cstate, int proto) return gen_false(cstate); } /*NOTREACHED*/ - break; case DLT_MFR: bpf_error(cstate, "Multi-link Frame Relay link-layer type filtering not implemented"); @@ -3511,7 +3605,8 @@ gen_linktype(compiler_state_t *cstate, int proto) case DLT_RAIF1: bpf_error(cstate, "RAIF1 link-layer type filtering not implemented"); - case DLT_IPMB: + case DLT_IPMB_KONTRON: + case DLT_IPMB_LINUX: bpf_error(cstate, "IPMB link-layer type filtering not implemented"); case DLT_AX25_KISS: @@ -3538,20 +3633,16 @@ gen_linktype(compiler_state_t *cstate, int proto) * above.) */ return gen_cmp(cstate, OR_LINKTYPE, 0, BPF_H, (bpf_int32)proto); + /*NOTREACHED */ } else { /* * No; report an error. */ - description = pcap_datalink_val_to_description(cstate->linktype); - if (description != NULL) { - bpf_error(cstate, "%s link-layer type filtering not implemented", - description); - } else { - bpf_error(cstate, "DLT %u link-layer type filtering not implemented", - cstate->linktype); - } + description = pcap_datalink_val_to_description_or_dlt(cstate->linktype); + bpf_error(cstate, "%s link-layer type filtering not implemented", + description); + /*NOTREACHED */ } - break; } } @@ -3581,8 +3672,8 @@ gen_snap(compiler_state_t *cstate, bpf_u_int32 orgcode, bpf_u_int32 ptype) /* * Generate code to match frames with an LLC header. */ -struct block * -gen_llc(compiler_state_t *cstate) +static struct block * +gen_llc_internal(compiler_state_t *cstate) { struct block *b0, *b1; @@ -3609,7 +3700,7 @@ gen_llc(compiler_state_t *cstate) /* * We check for LLC traffic. */ - b0 = gen_atmtype_abbrev(cstate, A_LLC); + b0 = gen_atmtype_llc(cstate); return b0; case DLT_IEEE802: /* Token Ring */ @@ -3647,21 +3738,42 @@ gen_llc(compiler_state_t *cstate) return b0; default: - bpf_error(cstate, "'llc' not supported for linktype %d", cstate->linktype); - /* NOTREACHED */ + bpf_error(cstate, "'llc' not supported for %s", + pcap_datalink_val_to_description_or_dlt(cstate->linktype)); + /*NOTREACHED*/ } } +struct block * +gen_llc(compiler_state_t *cstate) +{ + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_llc_internal(cstate); +} + struct block * gen_llc_i(compiler_state_t *cstate) { struct block *b0, *b1; struct slist *s; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Check whether this is an LLC frame. */ - b0 = gen_llc(cstate); + b0 = gen_llc_internal(cstate); /* * Load the control byte and test the low-order bit; it must @@ -3681,10 +3793,17 @@ gen_llc_s(compiler_state_t *cstate) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Check whether this is an LLC frame. */ - b0 = gen_llc(cstate); + b0 = gen_llc_internal(cstate); /* * Now compare the low-order 2 bit of the control byte against @@ -3700,10 +3819,17 @@ gen_llc_u(compiler_state_t *cstate) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Check whether this is an LLC frame. */ - b0 = gen_llc(cstate); + b0 = gen_llc_internal(cstate); /* * Now compare the low-order 2 bit of the control byte against @@ -3719,10 +3845,17 @@ gen_llc_s_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Check whether this is an LLC frame. */ - b0 = gen_llc(cstate); + b0 = gen_llc_internal(cstate); /* * Now check for an S frame with the appropriate type. @@ -3737,10 +3870,17 @@ gen_llc_u_subtype(compiler_state_t *cstate, bpf_u_int32 subtype) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Check whether this is an LLC frame. */ - b0 = gen_llc(cstate); + b0 = gen_llc_internal(cstate); /* * Now check for a U frame with the appropriate type. @@ -3860,8 +4000,8 @@ gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, gen_and(b0, b1); return b1; - case Q_OR: case Q_DEFAULT: + case Q_OR: b0 = gen_hostop(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); b1 = gen_hostop(cstate, addr, mask, Q_DST, proto, src_off, dst_off); gen_or(b0, b1); @@ -3869,30 +4009,31 @@ gen_hostop(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ default: abort(); + /*NOTREACHED*/ } b0 = gen_linktype(cstate, proto); b1 = gen_mcmp(cstate, OR_LINKPL, offset, BPF_W, (bpf_int32)addr, mask); @@ -3925,8 +4066,8 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, gen_and(b0, b1); return b1; - case Q_OR: case Q_DEFAULT: + case Q_OR: b0 = gen_hostop6(cstate, addr, mask, Q_SRC, proto, src_off, dst_off); b1 = gen_hostop6(cstate, addr, mask, Q_DST, proto, src_off, dst_off); gen_or(b0, b1); @@ -3934,30 +4075,31 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr, case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); - break; + /*NOTREACHED*/ default: abort(); + /*NOTREACHED*/ } /* this order is important */ a = (uint32_t *)addr; @@ -4002,30 +4144,30 @@ gen_ehostop(compiler_state_t *cstate, const u_char *eaddr, int dir) case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is only supported on 802.11 with 802.11 headers"); - break; + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -4058,30 +4200,30 @@ gen_fhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is only supported on 802.11"); - break; + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -4114,30 +4256,30 @@ gen_thostop(compiler_state_t *cstate, const u_char *eaddr, int dir) case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is only supported on 802.11"); - break; + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -4426,6 +4568,68 @@ gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) gen_and(b1, b0); return b0; + case Q_AND: + b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); + b1 = gen_wlanhostop(cstate, eaddr, Q_DST); + gen_and(b0, b1); + return b1; + + case Q_DEFAULT: + case Q_OR: + b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); + b1 = gen_wlanhostop(cstate, eaddr, Q_DST); + gen_or(b0, b1); + return b1; + + /* + * XXX - add BSSID keyword? + */ + case Q_ADDR1: + return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); + + case Q_ADDR2: + /* + * Not present in CTS or ACK control frames. + */ + b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, + IEEE80211_FC0_TYPE_MASK); + gen_not(b0); + b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, + IEEE80211_FC0_SUBTYPE_MASK); + gen_not(b1); + b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, + IEEE80211_FC0_SUBTYPE_MASK); + gen_not(b2); + gen_and(b1, b2); + gen_or(b0, b2); + b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); + gen_and(b2, b1); + return b1; + + case Q_ADDR3: + /* + * Not present in control frames. + */ + b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, + IEEE80211_FC0_TYPE_MASK); + gen_not(b0); + b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); + gen_and(b0, b1); + return b1; + + case Q_ADDR4: + /* + * Present only if the direction mask has both "From DS" + * and "To DS" set. Neither control frames nor management + * frames should have both of those set, so we don't + * check the frame type. + */ + b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, + IEEE80211_FC1_DIR_DSTODS, IEEE80211_FC1_DIR_MASK); + b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); + gen_and(b0, b1); + return b1; + case Q_RA: /* * Not present in management frames; addr1 in other @@ -4496,71 +4700,9 @@ gen_wlanhostop(compiler_state_t *cstate, const u_char *eaddr, int dir) b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); gen_and(b2, b1); return b1; - - /* - * XXX - add BSSID keyword? - */ - case Q_ADDR1: - return (gen_bcmp(cstate, OR_LINKHDR, 4, 6, eaddr)); - - case Q_ADDR2: - /* - * Not present in CTS or ACK control frames. - */ - b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, - IEEE80211_FC0_TYPE_MASK); - gen_not(b0); - b1 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_CTS, - IEEE80211_FC0_SUBTYPE_MASK); - gen_not(b1); - b2 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_SUBTYPE_ACK, - IEEE80211_FC0_SUBTYPE_MASK); - gen_not(b2); - gen_and(b1, b2); - gen_or(b0, b2); - b1 = gen_bcmp(cstate, OR_LINKHDR, 10, 6, eaddr); - gen_and(b2, b1); - return b1; - - case Q_ADDR3: - /* - * Not present in control frames. - */ - b0 = gen_mcmp(cstate, OR_LINKHDR, 0, BPF_B, IEEE80211_FC0_TYPE_CTL, - IEEE80211_FC0_TYPE_MASK); - gen_not(b0); - b1 = gen_bcmp(cstate, OR_LINKHDR, 16, 6, eaddr); - gen_and(b0, b1); - return b1; - - case Q_ADDR4: - /* - * Present only if the direction mask has both "From DS" - * and "To DS" set. Neither control frames nor management - * frames should have both of those set, so we don't - * check the frame type. - */ - b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, - IEEE80211_FC1_DIR_DSTODS, IEEE80211_FC1_DIR_MASK); - b1 = gen_bcmp(cstate, OR_LINKHDR, 24, 6, eaddr); - gen_and(b0, b1); - return b1; - - case Q_AND: - b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); - b1 = gen_wlanhostop(cstate, eaddr, Q_DST); - gen_and(b0, b1); - return b1; - - case Q_DEFAULT: - case Q_OR: - b0 = gen_wlanhostop(cstate, eaddr, Q_SRC); - b1 = gen_wlanhostop(cstate, eaddr, Q_DST); - gen_or(b0, b1); - return b1; } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -4595,30 +4737,30 @@ gen_ipfchostop(compiler_state_t *cstate, const u_char *eaddr, int dir) case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is only supported on 802.11"); - break; + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -4665,19 +4807,41 @@ gen_dnhostop(compiler_state_t *cstate, bpf_u_int32 addr, int dir) gen_and(b0, b1); return b1; - case Q_OR: case Q_DEFAULT: + case Q_OR: /* Inefficient because we do our Calvinball dance twice */ b0 = gen_dnhostop(cstate, addr, Q_SRC); b1 = gen_dnhostop(cstate, addr, Q_DST); gen_or(b0, b1); return b1; - case Q_ISO: - bpf_error(cstate, "ISO host filtering not implemented"); + case Q_ADDR1: + bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ + + case Q_ADDR2: + bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ + + case Q_ADDR3: + bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ + + case Q_ADDR4: + bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ + + case Q_RA: + bpf_error(cstate, "'ra' is not a valid qualifier for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ + + case Q_TA: + bpf_error(cstate, "'ta' is not a valid qualifier for addresses other than 802.11 MAC addresses"); + /*NOTREACHED*/ default: abort(); + /*NOTREACHED*/ } b0 = gen_linktype(cstate, ETHERTYPE_DN); /* Check for pad = 1, long header case */ @@ -4769,6 +4933,9 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, } return b0; + case Q_LINK: + bpf_error(cstate, "link-layer modifier applied to %s", typestr); + case Q_IP: return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_IP, 12, 16); @@ -4778,12 +4945,12 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, case Q_ARP: return gen_hostop(cstate, addr, mask, dir, ETHERTYPE_ARP, 14, 24); - case Q_TCP: - bpf_error(cstate, "'tcp' modifier applied to %s", typestr); - case Q_SCTP: bpf_error(cstate, "'sctp' modifier applied to %s", typestr); + case Q_TCP: + bpf_error(cstate, "'tcp' modifier applied to %s", typestr); + case Q_UDP: bpf_error(cstate, "'udp' modifier applied to %s", typestr); @@ -4796,36 +4963,24 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, case Q_IGRP: bpf_error(cstate, "'igrp' modifier applied to %s", typestr); - case Q_PIM: - bpf_error(cstate, "'pim' modifier applied to %s", typestr); - - case Q_VRRP: - bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); - - case Q_CARP: - bpf_error(cstate, "'carp' modifier applied to %s", typestr); - case Q_ATALK: - bpf_error(cstate, "ATALK host filtering not implemented"); - - case Q_AARP: - bpf_error(cstate, "AARP host filtering not implemented"); + bpf_error(cstate, "AppleTalk host filtering not implemented"); case Q_DECNET: return gen_dnhostop(cstate, addr, dir); - case Q_SCA: - bpf_error(cstate, "SCA host filtering not implemented"); - case Q_LAT: bpf_error(cstate, "LAT host filtering not implemented"); - case Q_MOPDL: - bpf_error(cstate, "MOPDL host filtering not implemented"); + case Q_SCA: + bpf_error(cstate, "SCA host filtering not implemented"); case Q_MOPRC: bpf_error(cstate, "MOPRC host filtering not implemented"); + case Q_MOPDL: + bpf_error(cstate, "MOPDL host filtering not implemented"); + case Q_IPV6: bpf_error(cstate, "'ip6' modifier applied to ip host"); @@ -4838,6 +4993,15 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, case Q_ESP: bpf_error(cstate, "'esp' modifier applied to %s", typestr); + case Q_PIM: + bpf_error(cstate, "'pim' modifier applied to %s", typestr); + + case Q_VRRP: + bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); + + case Q_AARP: + bpf_error(cstate, "AARP host filtering not implemented"); + case Q_ISO: bpf_error(cstate, "ISO host filtering not implemented"); @@ -4859,13 +5023,37 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask, case Q_NETBEUI: bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); + case Q_ISIS_L1: + bpf_error(cstate, "'l1' modifier applied to %s", typestr); + + case Q_ISIS_L2: + bpf_error(cstate, "'l2' modifier applied to %s", typestr); + + case Q_ISIS_IIH: + bpf_error(cstate, "'iih' modifier applied to %s", typestr); + + case Q_ISIS_SNP: + bpf_error(cstate, "'snp' modifier applied to %s", typestr); + + case Q_ISIS_CSNP: + bpf_error(cstate, "'csnp' modifier applied to %s", typestr); + + case Q_ISIS_PSNP: + bpf_error(cstate, "'psnp' modifier applied to %s", typestr); + + case Q_ISIS_LSP: + bpf_error(cstate, "'lsp' modifier applied to %s", typestr); + case Q_RADIO: bpf_error(cstate, "'radio' modifier applied to %s", typestr); + case Q_CARP: + bpf_error(cstate, "'carp' modifier applied to %s", typestr); + default: abort(); } - /* NOTREACHED */ + /*NOTREACHED*/ } #ifdef INET6 @@ -4898,93 +5086,114 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr, bpf_error(cstate, "'arp' modifier applied to ip6 %s", typestr); case Q_SCTP: - bpf_error(cstate, "'sctp' modifier applied to %s", typestr); + bpf_error(cstate, "'sctp' modifier applied to ip6 %s", typestr); case Q_TCP: - bpf_error(cstate, "'tcp' modifier applied to %s", typestr); + bpf_error(cstate, "'tcp' modifier applied to ip6 %s", typestr); case Q_UDP: - bpf_error(cstate, "'udp' modifier applied to %s", typestr); + bpf_error(cstate, "'udp' modifier applied to ip6 %s", typestr); case Q_ICMP: - bpf_error(cstate, "'icmp' modifier applied to %s", typestr); + bpf_error(cstate, "'icmp' modifier applied to ip6 %s", typestr); case Q_IGMP: - bpf_error(cstate, "'igmp' modifier applied to %s", typestr); + bpf_error(cstate, "'igmp' modifier applied to ip6 %s", typestr); case Q_IGRP: - bpf_error(cstate, "'igrp' modifier applied to %s", typestr); - - case Q_PIM: - bpf_error(cstate, "'pim' modifier applied to %s", typestr); - - case Q_VRRP: - bpf_error(cstate, "'vrrp' modifier applied to %s", typestr); - - case Q_CARP: - bpf_error(cstate, "'carp' modifier applied to %s", typestr); + bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr); case Q_ATALK: - bpf_error(cstate, "ATALK host filtering not implemented"); - - case Q_AARP: - bpf_error(cstate, "AARP host filtering not implemented"); + bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr); case Q_DECNET: bpf_error(cstate, "'decnet' modifier applied to ip6 %s", typestr); - case Q_SCA: - bpf_error(cstate, "SCA host filtering not implemented"); - case Q_LAT: - bpf_error(cstate, "LAT host filtering not implemented"); + bpf_error(cstate, "'lat' modifier applied to ip6 %s", typestr); - case Q_MOPDL: - bpf_error(cstate, "MOPDL host filtering not implemented"); + case Q_SCA: + bpf_error(cstate, "'sca' modifier applied to ip6 %s", typestr); case Q_MOPRC: - bpf_error(cstate, "MOPRC host filtering not implemented"); + bpf_error(cstate, "'moprc' modifier applied to ip6 %s", typestr); + + case Q_MOPDL: + bpf_error(cstate, "'mopdl' modifier applied to ip6 %s", typestr); case Q_IPV6: return gen_hostop6(cstate, addr, mask, dir, ETHERTYPE_IPV6, 8, 24); case Q_ICMPV6: - bpf_error(cstate, "'icmp6' modifier applied to %s", typestr); + bpf_error(cstate, "'icmp6' modifier applied to ip6 %s", typestr); case Q_AH: - bpf_error(cstate, "'ah' modifier applied to %s", typestr); + bpf_error(cstate, "'ah' modifier applied to ip6 %s", typestr); case Q_ESP: - bpf_error(cstate, "'esp' modifier applied to %s", typestr); + bpf_error(cstate, "'esp' modifier applied to ip6 %s", typestr); + + case Q_PIM: + bpf_error(cstate, "'pim' modifier applied to ip6 %s", typestr); + + case Q_VRRP: + bpf_error(cstate, "'vrrp' modifier applied to ip6 %s", typestr); + + case Q_AARP: + bpf_error(cstate, "'aarp' modifier applied to ip6 %s", typestr); case Q_ISO: - bpf_error(cstate, "ISO host filtering not implemented"); + bpf_error(cstate, "'iso' modifier applied to ip6 %s", typestr); case Q_ESIS: - bpf_error(cstate, "'esis' modifier applied to %s", typestr); + bpf_error(cstate, "'esis' modifier applied to ip6 %s", typestr); case Q_ISIS: - bpf_error(cstate, "'isis' modifier applied to %s", typestr); + bpf_error(cstate, "'isis' modifier applied to ip6 %s", typestr); case Q_CLNP: - bpf_error(cstate, "'clnp' modifier applied to %s", typestr); + bpf_error(cstate, "'clnp' modifier applied to ip6 %s", typestr); case Q_STP: - bpf_error(cstate, "'stp' modifier applied to %s", typestr); + bpf_error(cstate, "'stp' modifier applied to ip6 %s", typestr); case Q_IPX: - bpf_error(cstate, "IPX host filtering not implemented"); + bpf_error(cstate, "'ipx' modifier applied to ip6 %s", typestr); case Q_NETBEUI: - bpf_error(cstate, "'netbeui' modifier applied to %s", typestr); + bpf_error(cstate, "'netbeui' modifier applied to ip6 %s", typestr); + + case Q_ISIS_L1: + bpf_error(cstate, "'l1' modifier applied to ip6 %s", typestr); + + case Q_ISIS_L2: + bpf_error(cstate, "'l2' modifier applied to ip6 %s", typestr); + + case Q_ISIS_IIH: + bpf_error(cstate, "'iih' modifier applied to ip6 %s", typestr); + + case Q_ISIS_SNP: + bpf_error(cstate, "'snp' modifier applied to ip6 %s", typestr); + + case Q_ISIS_CSNP: + bpf_error(cstate, "'csnp' modifier applied to ip6 %s", typestr); + + case Q_ISIS_PSNP: + bpf_error(cstate, "'psnp' modifier applied to ip6 %s", typestr); + + case Q_ISIS_LSP: + bpf_error(cstate, "'lsp' modifier applied to ip6 %s", typestr); case Q_RADIO: - bpf_error(cstate, "'radio' modifier applied to %s", typestr); + bpf_error(cstate, "'radio' modifier applied to ip6 %s", typestr); + + case Q_CARP: + bpf_error(cstate, "'carp' modifier applied to ip6 %s", typestr); default: abort(); } - /* NOTREACHED */ + /*NOTREACHED*/ } #endif @@ -5091,12 +5300,12 @@ gen_gateway(compiler_state_t *cstate, const u_char *eaddr, return b1; } bpf_error(cstate, "illegal modifier of 'gateway'"); - /* NOTREACHED */ + /*NOTREACHED*/ } #endif -struct block * -gen_proto_abbrev(compiler_state_t *cstate, int proto) +static struct block * +gen_proto_abbrev_internal(compiler_state_t *cstate, int proto) { struct block *b0; struct block *b1; @@ -5335,6 +5544,19 @@ gen_proto_abbrev(compiler_state_t *cstate, int proto) return b1; } +struct block * +gen_proto_abbrev(compiler_state_t *cstate, int proto) +{ + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_proto_abbrev_internal(cstate, proto); +} + static struct block * gen_ipfrag(compiler_state_t *cstate) { @@ -5391,21 +5613,46 @@ gen_portop(compiler_state_t *cstate, int port, int proto, int dir) b1 = gen_portatom(cstate, 2, (bpf_int32)port); break; - case Q_OR: - case Q_DEFAULT: - tmp = gen_portatom(cstate, 0, (bpf_int32)port); - b1 = gen_portatom(cstate, 2, (bpf_int32)port); - gen_or(tmp, b1); - break; - case Q_AND: tmp = gen_portatom(cstate, 0, (bpf_int32)port); b1 = gen_portatom(cstate, 2, (bpf_int32)port); gen_and(tmp, b1); break; + case Q_DEFAULT: + case Q_OR: + tmp = gen_portatom(cstate, 0, (bpf_int32)port); + b1 = gen_portatom(cstate, 2, (bpf_int32)port); + gen_or(tmp, b1); + break; + + case Q_ADDR1: + bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for ports"); + /*NOTREACHED*/ + + case Q_ADDR2: + bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for ports"); + /*NOTREACHED*/ + + case Q_ADDR3: + bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for ports"); + /*NOTREACHED*/ + + case Q_ADDR4: + bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for ports"); + /*NOTREACHED*/ + + case Q_RA: + bpf_error(cstate, "'ra' is not a valid qualifier for ports"); + /*NOTREACHED*/ + + case Q_TA: + bpf_error(cstate, "'ta' is not a valid qualifier for ports"); + /*NOTREACHED*/ + default: abort(); + /*NOTREACHED*/ } gen_and(b0, b1); @@ -5476,19 +5723,19 @@ gen_portop6(compiler_state_t *cstate, int port, int proto, int dir) b1 = gen_portatom6(cstate, 2, (bpf_int32)port); break; - case Q_OR: - case Q_DEFAULT: - tmp = gen_portatom6(cstate, 0, (bpf_int32)port); - b1 = gen_portatom6(cstate, 2, (bpf_int32)port); - gen_or(tmp, b1); - break; - case Q_AND: tmp = gen_portatom6(cstate, 0, (bpf_int32)port); b1 = gen_portatom6(cstate, 2, (bpf_int32)port); gen_and(tmp, b1); break; + case Q_DEFAULT: + case Q_OR: + tmp = gen_portatom6(cstate, 0, (bpf_int32)port); + b1 = gen_portatom6(cstate, 2, (bpf_int32)port); + gen_or(tmp, b1); + break; + default: abort(); } @@ -5573,21 +5820,46 @@ gen_portrangeop(compiler_state_t *cstate, int port1, int port2, int proto, b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); break; - case Q_OR: - case Q_DEFAULT: - tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); - b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); - gen_or(tmp, b1); - break; - case Q_AND: tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); gen_and(tmp, b1); break; + case Q_DEFAULT: + case Q_OR: + tmp = gen_portrangeatom(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); + b1 = gen_portrangeatom(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); + gen_or(tmp, b1); + break; + + case Q_ADDR1: + bpf_error(cstate, "'addr1' and 'address1' are not valid qualifiers for port ranges"); + /*NOTREACHED*/ + + case Q_ADDR2: + bpf_error(cstate, "'addr2' and 'address2' are not valid qualifiers for port ranges"); + /*NOTREACHED*/ + + case Q_ADDR3: + bpf_error(cstate, "'addr3' and 'address3' are not valid qualifiers for port ranges"); + /*NOTREACHED*/ + + case Q_ADDR4: + bpf_error(cstate, "'addr4' and 'address4' are not valid qualifiers for port ranges"); + /*NOTREACHED*/ + + case Q_RA: + bpf_error(cstate, "'ra' is not a valid qualifier for port ranges"); + /*NOTREACHED*/ + + case Q_TA: + bpf_error(cstate, "'ta' is not a valid qualifier for port ranges"); + /*NOTREACHED*/ + default: abort(); + /*NOTREACHED*/ } gen_and(b0, b1); @@ -5669,19 +5941,19 @@ gen_portrangeop6(compiler_state_t *cstate, int port1, int port2, int proto, b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); break; - case Q_OR: - case Q_DEFAULT: - tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); - b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); - gen_or(tmp, b1); - break; - case Q_AND: tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); gen_and(tmp, b1); break; + case Q_DEFAULT: + case Q_OR: + tmp = gen_portrangeatom6(cstate, 0, (bpf_int32)port1, (bpf_int32)port2); + b1 = gen_portrangeatom6(cstate, 2, (bpf_int32)port1, (bpf_int32)port2); + gen_or(tmp, b1); + break; + default: abort(); } @@ -6116,6 +6388,9 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir) gen_or(b0, b1); return b1; + case Q_LINK: + return gen_linktype(cstate, v); + case Q_IP: /* * For FDDI, RFC 1188 says that SNAP encapsulation is used, @@ -6141,6 +6416,104 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir) gen_and(b0, b1); return b1; + case Q_ARP: + bpf_error(cstate, "arp does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_RARP: + bpf_error(cstate, "rarp does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_SCTP: + bpf_error(cstate, "'sctp proto' is bogus"); + /*NOTREACHED*/ + + case Q_TCP: + bpf_error(cstate, "'tcp proto' is bogus"); + /*NOTREACHED*/ + + case Q_UDP: + bpf_error(cstate, "'udp proto' is bogus"); + /*NOTREACHED*/ + + case Q_ICMP: + bpf_error(cstate, "'icmp proto' is bogus"); + /*NOTREACHED*/ + + case Q_IGMP: + bpf_error(cstate, "'igmp proto' is bogus"); + /*NOTREACHED*/ + + case Q_IGRP: + bpf_error(cstate, "'igrp proto' is bogus"); + /*NOTREACHED*/ + + case Q_ATALK: + bpf_error(cstate, "AppleTalk encapsulation is not specifiable"); + /*NOTREACHED*/ + + case Q_DECNET: + bpf_error(cstate, "DECNET encapsulation is not specifiable"); + /*NOTREACHED*/ + + case Q_LAT: + bpf_error(cstate, "LAT does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_SCA: + bpf_error(cstate, "SCA does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_MOPRC: + bpf_error(cstate, "MOPRC does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_MOPDL: + bpf_error(cstate, "MOPDL does not encapsulate another protocol"); + /*NOTREACHED*/ + + case Q_IPV6: + b0 = gen_linktype(cstate, ETHERTYPE_IPV6); +#ifndef CHASE_CHAIN + /* + * Also check for a fragment header before the final + * header. + */ + b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); + b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, (bpf_int32)v); + gen_and(b2, b1); + b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)v); + gen_or(b2, b1); +#else + b1 = gen_protochain(cstate, v, Q_IPV6); +#endif + gen_and(b0, b1); + return b1; + + case Q_ICMPV6: + bpf_error(cstate, "'icmp6 proto' is bogus"); + /*NOTREACHED*/ + + case Q_AH: + bpf_error(cstate, "'ah proto' is bogus"); + /*NOTREACHED*/ + + case Q_ESP: + bpf_error(cstate, "'ah proto' is bogus"); + /*NOTREACHED*/ + + case Q_PIM: + bpf_error(cstate, "'pim proto' is bogus"); + /*NOTREACHED*/ + + case Q_VRRP: + bpf_error(cstate, "'vrrp proto' is bogus"); + /*NOTREACHED*/ + + case Q_AARP: + bpf_error(cstate, "'aarp proto' is bogus"); + /*NOTREACHED*/ + case Q_ISO: switch (cstate->linktype) { @@ -6165,7 +6538,6 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir) */ return gen_cmp(cstate, OR_LINKHDR, 2, BPF_H, (0x03<<8) | v); /*NOTREACHED*/ - break; case DLT_C_HDLC: /* @@ -6185,6 +6557,10 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir) return b1; } + case Q_ESIS: + bpf_error(cstate, "'esis proto' is bogus"); + /*NOTREACHED*/ + case Q_ISIS: b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT); /* @@ -6195,121 +6571,63 @@ gen_proto(compiler_state_t *cstate, int v, int proto, int dir) gen_and(b0, b1); return b1; - case Q_ARP: - bpf_error(cstate, "arp does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_RARP: - bpf_error(cstate, "rarp does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_ATALK: - bpf_error(cstate, "atalk encapsulation is not specifiable"); - /* NOTREACHED */ - - case Q_DECNET: - bpf_error(cstate, "decnet encapsulation is not specifiable"); - /* NOTREACHED */ - - case Q_SCA: - bpf_error(cstate, "sca does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_LAT: - bpf_error(cstate, "lat does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_MOPRC: - bpf_error(cstate, "moprc does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_MOPDL: - bpf_error(cstate, "mopdl does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_LINK: - return gen_linktype(cstate, v); - - case Q_UDP: - bpf_error(cstate, "'udp proto' is bogus"); - /* NOTREACHED */ - - case Q_TCP: - bpf_error(cstate, "'tcp proto' is bogus"); - /* NOTREACHED */ - - case Q_SCTP: - bpf_error(cstate, "'sctp proto' is bogus"); - /* NOTREACHED */ - - case Q_ICMP: - bpf_error(cstate, "'icmp proto' is bogus"); - /* NOTREACHED */ - - case Q_IGMP: - bpf_error(cstate, "'igmp proto' is bogus"); - /* NOTREACHED */ - - case Q_IGRP: - bpf_error(cstate, "'igrp proto' is bogus"); - /* NOTREACHED */ - - case Q_PIM: - bpf_error(cstate, "'pim proto' is bogus"); - /* NOTREACHED */ - - case Q_VRRP: - bpf_error(cstate, "'vrrp proto' is bogus"); - /* NOTREACHED */ - - case Q_CARP: - bpf_error(cstate, "'carp proto' is bogus"); - /* NOTREACHED */ - - case Q_IPV6: - b0 = gen_linktype(cstate, ETHERTYPE_IPV6); -#ifndef CHASE_CHAIN - /* - * Also check for a fragment header before the final - * header. - */ - b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, IPPROTO_FRAGMENT); - b1 = gen_cmp(cstate, OR_LINKPL, 40, BPF_B, (bpf_int32)v); - gen_and(b2, b1); - b2 = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, (bpf_int32)v); - gen_or(b2, b1); -#else - b1 = gen_protochain(cstate, v, Q_IPV6); -#endif - gen_and(b0, b1); - return b1; - - case Q_ICMPV6: - bpf_error(cstate, "'icmp6 proto' is bogus"); - - case Q_AH: - bpf_error(cstate, "'ah proto' is bogus"); - - case Q_ESP: - bpf_error(cstate, "'ah proto' is bogus"); + case Q_CLNP: + bpf_error(cstate, "'clnp proto' is not supported"); + /*NOTREACHED*/ case Q_STP: bpf_error(cstate, "'stp proto' is bogus"); + /*NOTREACHED*/ case Q_IPX: bpf_error(cstate, "'ipx proto' is bogus"); + /*NOTREACHED*/ case Q_NETBEUI: bpf_error(cstate, "'netbeui proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_L1: + bpf_error(cstate, "'l1 proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_L2: + bpf_error(cstate, "'l2 proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_IIH: + bpf_error(cstate, "'iih proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_SNP: + bpf_error(cstate, "'snp proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_CSNP: + bpf_error(cstate, "'csnp proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_PSNP: + bpf_error(cstate, "'psnp proto' is bogus"); + /*NOTREACHED*/ + + case Q_ISIS_LSP: + bpf_error(cstate, "'lsp proto' is bogus"); + /*NOTREACHED*/ case Q_RADIO: bpf_error(cstate, "'radio proto' is bogus"); + /*NOTREACHED*/ + + case Q_CARP: + bpf_error(cstate, "'carp proto' is bogus"); + /*NOTREACHED*/ default: abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * @@ -6331,6 +6649,13 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q) int port, real_proto; int port1, port2; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (q.addr) { case Q_NET: @@ -6609,10 +6934,10 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q) case Q_UNDEF: syntax(cstate); - /* NOTREACHED */ + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * @@ -6622,6 +6947,13 @@ gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, register int nlen, mlen; bpf_u_int32 n, m; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + nlen = __pcap_atoin(s1, &n); /* Promote short ipaddr */ n <<= 32 - nlen; @@ -6657,19 +6989,28 @@ gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, default: bpf_error(cstate, "Mask syntax for networks only"); - /* NOTREACHED */ + /*NOTREACHED*/ } - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) { bpf_u_int32 mask; - int proto = q.proto; - int dir = q.dir; + int proto; + int dir; register int vlen; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + proto = q.proto; + dir = q.dir; if (s == NULL) vlen = 32; else if (q.proto == Q_DECNET) { @@ -6750,7 +7091,7 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) case Q_GATEWAY: bpf_error(cstate, "'gateway' requires a name"); - /* NOTREACHED */ + /*NOTREACHED*/ case Q_PROTO: return gen_proto(cstate, (int)v, proto, dir); @@ -6760,13 +7101,13 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) case Q_UNDEF: syntax(cstate); - /* NOTREACHED */ + /*NOTREACHED*/ default: abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } - /* NOTREACHED */ + /*NOTREACHED*/ } #ifdef INET6 @@ -6780,6 +7121,13 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, struct block *b; uint32_t *a, *m; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (s2) bpf_error(cstate, "no mask %s supported", s2); @@ -6823,45 +7171,64 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2, default: bpf_error(cstate, "invalid qualifier against IPv6 address"); - /* NOTREACHED */ + /*NOTREACHED*/ } } #endif /*INET6*/ struct block * -gen_ecode(compiler_state_t *cstate, const u_char *eaddr, struct qual q) +gen_ecode(compiler_state_t *cstate, const char *s, struct qual q) { struct block *b, *tmp; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { + cstate->e = pcap_ether_aton(s); + if (cstate->e == NULL) + bpf_error(cstate, "malloc"); switch (cstate->linktype) { case DLT_EN10MB: case DLT_NETANALYZER: case DLT_NETANALYZER_TRANSPARENT: tmp = gen_prevlinkhdr_check(cstate); - b = gen_ehostop(cstate, eaddr, (int)q.dir); + b = gen_ehostop(cstate, cstate->e, (int)q.dir); if (tmp != NULL) gen_and(tmp, b); - return b; + break; case DLT_FDDI: - return gen_fhostop(cstate, eaddr, (int)q.dir); + b = gen_fhostop(cstate, cstate->e, (int)q.dir); + break; case DLT_IEEE802: - return gen_thostop(cstate, eaddr, (int)q.dir); + b = gen_thostop(cstate, cstate->e, (int)q.dir); + break; case DLT_IEEE802_11: case DLT_PRISM_HEADER: case DLT_IEEE802_11_RADIO_AVS: case DLT_IEEE802_11_RADIO: case DLT_PPI: - return gen_wlanhostop(cstate, eaddr, (int)q.dir); - case DLT_IP_OVER_FC: - return gen_ipfchostop(cstate, eaddr, (int)q.dir); - default: - bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); + b = gen_wlanhostop(cstate, cstate->e, (int)q.dir); break; + case DLT_IP_OVER_FC: + b = gen_ipfchostop(cstate, cstate->e, (int)q.dir); + break; + default: + free(cstate->e); + cstate->e = NULL; + bpf_error(cstate, "ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel"); + /*NOTREACHED*/ } + free(cstate->e); + cstate->e = NULL; + return (b); } bpf_error(cstate, "ethernet address used in non-ether expression"); - /* NOTREACHED */ + /*NOTREACHED*/ } void @@ -6903,8 +7270,8 @@ xfer_to_a(compiler_state_t *cstate, struct arth *a) * (1, 2, or 4) at that offset into that register, making it the register * for "index". */ -struct arth * -gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) +static struct arth * +gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst, int size) { struct slist *s, *tmp; struct block *b; @@ -7050,7 +7417,7 @@ gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) * Do the computation only if the packet contains * the protocol in question. */ - b = gen_proto_abbrev(cstate, proto); + b = gen_proto_abbrev_internal(cstate, proto); if (inst->b) gen_and(inst->b, b); inst->b = b; @@ -7108,10 +7475,10 @@ gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) * if this is an IP datagram and is the first or * only fragment of that datagram. */ - gen_and(gen_proto_abbrev(cstate, proto), b = gen_ipfrag(cstate)); + gen_and(gen_proto_abbrev_internal(cstate, proto), b = gen_ipfrag(cstate)); if (inst->b) gen_and(inst->b, b); - gen_and(gen_proto_abbrev(cstate, Q_IP), b); + gen_and(gen_proto_abbrev_internal(cstate, Q_IP), b); inst->b = b; break; case Q_ICMPV6: @@ -7119,7 +7486,7 @@ gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) * Do the computation only if the packet contains * the protocol in question. */ - b = gen_proto_abbrev(cstate, Q_IPV6); + b = gen_proto_abbrev_internal(cstate, Q_IPV6); if (inst->b) { gen_and(inst->b, b); } @@ -7176,8 +7543,21 @@ gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) return inst; } -struct block * -gen_relation(compiler_state_t *cstate, int code, struct arth *a0, +struct arth * +gen_load(compiler_state_t *cstate, int proto, struct arth *inst, int size) +{ + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_load_internal(cstate, proto, inst, size); +} + +static struct block * +gen_relation_internal(compiler_state_t *cstate, int code, struct arth *a0, struct arth *a1, int reversed) { struct slist *s0, *s1, *s2; @@ -7220,13 +7600,36 @@ gen_relation(compiler_state_t *cstate, int code, struct arth *a0, return b; } +struct block * +gen_relation(compiler_state_t *cstate, int code, struct arth *a0, + struct arth *a1, int reversed) +{ + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_relation_internal(cstate, code, a0, a1, reversed); +} + struct arth * gen_loadlen(compiler_state_t *cstate) { - int regno = alloc_reg(cstate); - struct arth *a = (struct arth *)newchunk(cstate, sizeof(*a)); + int regno; + struct arth *a; struct slist *s; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + regno = alloc_reg(cstate); + a = (struct arth *)newchunk(cstate, sizeof(*a)); s = new_stmt(cstate, BPF_LD|BPF_LEN); s->next = new_stmt(cstate, BPF_ST); s->next->s.k = regno; @@ -7236,8 +7639,8 @@ gen_loadlen(compiler_state_t *cstate) return a; } -struct arth * -gen_loadi(compiler_state_t *cstate, int val) +static struct arth * +gen_loadi_internal(compiler_state_t *cstate, int val) { struct arth *a; struct slist *s; @@ -7258,10 +7661,36 @@ gen_loadi(compiler_state_t *cstate, int val) } struct arth * -gen_neg(compiler_state_t *cstate, struct arth *a) +gen_loadi(compiler_state_t *cstate, int val) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_loadi_internal(cstate, val); +} + +/* + * The a_arg dance is to avoid annoying whining by compilers that + * a might be clobbered by longjmp - yeah, it might, but *WHO CARES*? + * It's not *used* after setjmp returns. + */ +struct arth * +gen_neg(compiler_state_t *cstate, struct arth *a_arg) +{ + struct arth *a = a_arg; struct slist *s; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + s = xfer_to_a(cstate, a); sappend(a->s, s); s = new_stmt(cstate, BPF_ALU|BPF_NEG); @@ -7274,15 +7703,31 @@ gen_neg(compiler_state_t *cstate, struct arth *a) return a; } +/* + * The a0_arg dance is to avoid annoying whining by compilers that + * a0 might be clobbered by longjmp - yeah, it might, but *WHO CARES*? + * It's not *used* after setjmp returns. + */ struct arth * -gen_arth(compiler_state_t *cstate, int code, struct arth *a0, +gen_arth(compiler_state_t *cstate, int code, struct arth *a0_arg, struct arth *a1) { + struct arth *a0 = a0_arg; struct slist *s0, *s1, *s2; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Disallow division by, or modulus by, zero; we do this here * so that it gets done even if the optimizer is disabled. + * + * Also disallow shifts by a value greater than 31; we do this + * here, for the same reason. */ if (code == BPF_DIV) { if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0) @@ -7290,6 +7735,15 @@ gen_arth(compiler_state_t *cstate, int code, struct arth *a0, } else if (code == BPF_MOD) { if (a1->s->s.code == (BPF_LD|BPF_IMM) && a1->s->s.k == 0) bpf_error(cstate, "modulus by zero"); + } else if (code == BPF_LSH || code == BPF_RSH) { + /* + * XXX - we need to make up our minds as to what integers + * are signed and what integers are unsigned in BPF programs + * and in our IR. + */ + if (a1->s->s.code == (BPF_LD|BPF_IMM) && + (a1->s->s.k < 0 || a1->s->s.k > 31)) + bpf_error(cstate, "shift by more than 31 bits"); } s0 = xfer_to_x(cstate, a1); s1 = xfer_to_a(cstate, a0); @@ -7337,7 +7791,7 @@ alloc_reg(compiler_state_t *cstate) } } bpf_error(cstate, "too many registers needed to evaluate expression"); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -7367,6 +7821,13 @@ gen_len(compiler_state_t *cstate, int jmp, int n) struct block * gen_greater(compiler_state_t *cstate, int n) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + return gen_len(cstate, BPF_JGE, n); } @@ -7378,6 +7839,13 @@ gen_less(compiler_state_t *cstate, int n) { struct block *b; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + b = gen_len(cstate, BPF_JGT, n); gen_not(b); @@ -7400,6 +7868,13 @@ gen_byteop(compiler_state_t *cstate, int op, int idx, int val) struct block *b; struct slist *s; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (op) { default: abort(); @@ -7440,6 +7915,13 @@ gen_broadcast(compiler_state_t *cstate, int proto) struct block *b0, *b1, *b2; static const u_char ebroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (proto) { case Q_DEFAULT: @@ -7471,7 +7953,7 @@ gen_broadcast(compiler_state_t *cstate, int proto) default: bpf_error(cstate, "not a broadcast link"); } - break; + /*NOTREACHED*/ case Q_IP: /* @@ -7491,7 +7973,7 @@ gen_broadcast(compiler_state_t *cstate, int proto) return b2; } bpf_error(cstate, "only link-layer/IP broadcast filters supported"); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -7518,6 +8000,13 @@ gen_multicast(compiler_state_t *cstate, int proto) register struct block *b0, *b1, *b2; register struct slist *s; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (proto) { case Q_DEFAULT: @@ -7686,7 +8175,7 @@ gen_multicast(compiler_state_t *cstate, int proto) return b1; } bpf_error(cstate, "link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel"); - /* NOTREACHED */ + /*NOTREACHED*/ } /* @@ -7703,14 +8192,21 @@ gen_inbound(compiler_state_t *cstate, int dir) { register struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Only some data link types support inbound/outbound qualifiers. */ switch (cstate->linktype) { case DLT_SLIP: - b0 = gen_relation(cstate, BPF_JEQ, - gen_load(cstate, Q_LINK, gen_loadi(cstate, 0), 1), - gen_loadi(cstate, 0), + b0 = gen_relation_internal(cstate, BPF_JEQ, + gen_load_internal(cstate, Q_LINK, gen_loadi_internal(cstate, 0), 1), + gen_loadi_internal(cstate, 0), dir); break; @@ -7733,6 +8229,15 @@ gen_inbound(compiler_state_t *cstate, int dir) } break; + case DLT_LINUX_SLL2: + /* match outgoing packets */ + b0 = gen_cmp(cstate, OR_LINKHDR, 10, BPF_B, LINUX_SLL_OUTGOING); + if (!dir) { + /* to filter on inbound traffic, invert the match */ + gen_not(b0); + } + break; + #ifdef HAVE_NET_PFVAR_H case DLT_PFLOG: b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, dir), BPF_B, @@ -7809,10 +8314,10 @@ gen_inbound(compiler_state_t *cstate, int dir) */ if (cstate->bpf_pcap->rfile != NULL) { /* We have a FILE *, so this is a savefile */ - bpf_error(cstate, "inbound/outbound not supported on linktype %d when reading savefiles", - cstate->linktype); + bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles", + pcap_datalink_val_to_description_or_dlt(cstate->linktype)); b0 = NULL; - /* NOTREACHED */ + /*NOTREACHED*/ } /* match outgoing packets */ b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_PKTTYPE, BPF_H, @@ -7822,9 +8327,9 @@ gen_inbound(compiler_state_t *cstate, int dir) gen_not(b0); } #else /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */ - bpf_error(cstate, "inbound/outbound not supported on linktype %d", - cstate->linktype); - /* NOTREACHED */ + bpf_error(cstate, "inbound/outbound not supported on %s", + pcap_datalink_val_to_description_or_dlt(cstate->linktype)); + /*NOTREACHED*/ #endif /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */ } return (b0); @@ -7838,18 +8343,26 @@ gen_pf_ifname(compiler_state_t *cstate, const char *ifname) struct block *b0; u_int len, off; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "ifname supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } len = sizeof(((struct pfloghdr *)0)->ifname); off = offsetof(struct pfloghdr, ifname); if (strlen(ifname) >= len) { bpf_error(cstate, "ifname interface names can only be %d characters", len-1); - /* NOTREACHED */ + /*NOTREACHED*/ } - b0 = gen_bcmp(cstate, OR_LINKHDR, off, strlen(ifname), (const u_char *)ifname); + b0 = gen_bcmp(cstate, OR_LINKHDR, off, (u_int)strlen(ifname), + (const u_char *)ifname); return (b0); } @@ -7859,19 +8372,26 @@ gen_pf_ruleset(compiler_state_t *cstate, char *ruleset) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "ruleset supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } if (strlen(ruleset) >= sizeof(((struct pfloghdr *)0)->ruleset)) { bpf_error(cstate, "ruleset names can only be %ld characters", (long)(sizeof(((struct pfloghdr *)0)->ruleset) - 1)); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_bcmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, ruleset), - strlen(ruleset), (const u_char *)ruleset); + (u_int)strlen(ruleset), (const u_char *)ruleset); return (b0); } @@ -7881,9 +8401,16 @@ gen_pf_rnr(compiler_state_t *cstate, int rnr) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "rnr supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, rulenr), BPF_W, @@ -7897,9 +8424,16 @@ gen_pf_srnr(compiler_state_t *cstate, int srnr) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "srnr supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, subrulenr), BPF_W, @@ -7913,9 +8447,16 @@ gen_pf_reason(compiler_state_t *cstate, int reason) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "reason supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, reason), BPF_B, @@ -7929,9 +8470,16 @@ gen_pf_action(compiler_state_t *cstate, int action) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->linktype != DLT_PFLOG) { bpf_error(cstate, "action supported only on PF linktype"); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_cmp(cstate, OR_LINKHDR, offsetof(struct pfloghdr, action), BPF_B, @@ -7942,43 +8490,85 @@ gen_pf_action(compiler_state_t *cstate, int action) struct block * gen_pf_ifname(compiler_state_t *cstate, const char *ifname _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_pf_ruleset(compiler_state_t *cstate, char *ruleset _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_pf_rnr(compiler_state_t *cstate, int rnr _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_pf_srnr(compiler_state_t *cstate, int srnr _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_pf_reason(compiler_state_t *cstate, int reason _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } struct block * gen_pf_action(compiler_state_t *cstate, int action _U_) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /* NOTREACHED */ + /*NOTREACHED*/ } #endif /* HAVE_NET_PFVAR_H */ @@ -7988,6 +8578,13 @@ gen_p80211_type(compiler_state_t *cstate, int type, int mask) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (cstate->linktype) { case DLT_IEEE802_11: @@ -8000,7 +8597,7 @@ gen_p80211_type(compiler_state_t *cstate, int type, int mask) default: bpf_error(cstate, "802.11 link-layer types supported only on 802.11"); - /* NOTREACHED */ + /*NOTREACHED*/ } return (b0); @@ -8011,6 +8608,13 @@ gen_p80211_fcdir(compiler_state_t *cstate, int fcdir) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (cstate->linktype) { case DLT_IEEE802_11: @@ -8021,7 +8625,7 @@ gen_p80211_fcdir(compiler_state_t *cstate, int fcdir) default: bpf_error(cstate, "frame direction supported only with 802.11 headers"); - /* NOTREACHED */ + /*NOTREACHED*/ } b0 = gen_mcmp(cstate, OR_LINKHDR, 1, BPF_B, (bpf_int32)fcdir, @@ -8031,24 +8635,37 @@ gen_p80211_fcdir(compiler_state_t *cstate, int fcdir) } struct block * -gen_acode(compiler_state_t *cstate, const u_char *eaddr, struct qual q) +gen_acode(compiler_state_t *cstate, const char *s, struct qual q) { + struct block *b; + + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (cstate->linktype) { case DLT_ARCNET: case DLT_ARCNET_LINUX: if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && - q.proto == Q_LINK) - return (gen_ahostop(cstate, eaddr, (int)q.dir)); - else { + q.proto == Q_LINK) { + cstate->e = pcap_ether_aton(s); + if (cstate->e == NULL) + bpf_error(cstate, "malloc"); + b = gen_ahostop(cstate, cstate->e, (int)q.dir); + free(cstate->e); + cstate->e = NULL; + return (b); + } else bpf_error(cstate, "ARCnet address used in non-arc expression"); - /* NOTREACHED */ - } - break; + /*NOTREACHED*/ default: bpf_error(cstate, "aid supported only on ARCnet"); - /* NOTREACHED */ + /*NOTREACHED*/ } } @@ -8080,30 +8697,30 @@ gen_ahostop(compiler_state_t *cstate, const u_char *eaddr, int dir) case Q_ADDR1: bpf_error(cstate, "'addr1' and 'address1' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR2: bpf_error(cstate, "'addr2' and 'address2' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR3: bpf_error(cstate, "'addr3' and 'address3' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_ADDR4: bpf_error(cstate, "'addr4' and 'address4' are only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_RA: bpf_error(cstate, "'ra' is only supported on 802.11"); - break; + /*NOTREACHED*/ case Q_TA: bpf_error(cstate, "'ta' is only supported on 802.11"); - break; + /*NOTREACHED*/ } abort(); - /* NOTREACHED */ + /*NOTREACHED*/ } static struct block * @@ -8123,19 +8740,24 @@ gen_vlan_tpid_test(compiler_state_t *cstate) } static struct block * -gen_vlan_vid_test(compiler_state_t *cstate, int vlan_num) +gen_vlan_vid_test(compiler_state_t *cstate, bpf_u_int32 vlan_num) { + if (vlan_num > 0x0fff) { + bpf_error(cstate, "VLAN tag %u greater than maximum %u", + vlan_num, 0x0fff); + } return gen_mcmp(cstate, OR_LINKPL, 0, BPF_H, (bpf_int32)vlan_num, 0x0fff); } static struct block * -gen_vlan_no_bpf_extensions(compiler_state_t *cstate, int vlan_num) +gen_vlan_no_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, + int has_vlan_tag) { struct block *b0, *b1; b0 = gen_vlan_tpid_test(cstate); - if (vlan_num >= 0) { + if (has_vlan_tag) { b1 = gen_vlan_vid_test(cstate, vlan_num); gen_and(b0, b1); b0 = b1; @@ -8218,12 +8840,15 @@ gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) sappend(s, s2); sjeq->s.jt = s2; - /* jump to the test in b_vid (bypass loading VID from packet data) */ + /* Jump to the test in b_vid. We need to jump one instruction before + * the end of the b_vid block so that we only skip loading the TCI + * from packet data and not the 'and' instruction extractging VID. + */ cnt = 0; for (s2 = b_vid->stmts; s2; s2 = s2->next) cnt++; s2 = new_stmt(cstate, JMP(BPF_JA)); - s2->s.k = cnt; + s2->s.k = cnt - 1; sappend(s, s2); /* insert our statements at the beginning of b_vid */ @@ -8240,7 +8865,8 @@ gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid) * update variable part of the offsets */ static struct block * -gen_vlan_bpf_extensions(compiler_state_t *cstate, int vlan_num) +gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num, + int has_vlan_tag) { struct block *b0, *b_tpid, *b_vid = NULL; struct slist *s; @@ -8265,14 +8891,14 @@ gen_vlan_bpf_extensions(compiler_state_t *cstate, int vlan_num) * function but gen_vlan_bpf_extensions() isn't called in that case. */ b_tpid = gen_vlan_tpid_test(cstate); - if (vlan_num >= 0) + if (has_vlan_tag) b_vid = gen_vlan_vid_test(cstate, vlan_num); gen_vlan_patch_tpid_test(cstate, b_tpid); gen_or(b0, b_tpid); b0 = b_tpid; - if (vlan_num >= 0) { + if (has_vlan_tag) { gen_vlan_patch_vid_test(cstate, b_vid); gen_and(b0, b_vid); b0 = b_vid; @@ -8286,10 +8912,17 @@ gen_vlan_bpf_extensions(compiler_state_t *cstate, int vlan_num) * support IEEE 802.1Q VLAN trunk over ethernet */ struct block * -gen_vlan(compiler_state_t *cstate, int vlan_num) +gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag) { struct block *b0; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* can't check for VLAN-encapsulated packets inside MPLS */ if (cstate->label_stack_depth > 0) bpf_error(cstate, "no VLAN match after MPLS"); @@ -8340,24 +8973,27 @@ gen_vlan(compiler_state_t *cstate, int vlan_num) * Do we need special VLAN handling? */ if (cstate->bpf_pcap->bpf_codegen_flags & BPF_SPECIAL_VLAN_HANDLING) - b0 = gen_vlan_bpf_extensions(cstate, vlan_num); + b0 = gen_vlan_bpf_extensions(cstate, vlan_num, + has_vlan_tag); else - b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); + b0 = gen_vlan_no_bpf_extensions(cstate, + vlan_num, has_vlan_tag); } else #endif - b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); + b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, + has_vlan_tag); break; case DLT_IEEE802_11: case DLT_PRISM_HEADER: case DLT_IEEE802_11_RADIO_AVS: case DLT_IEEE802_11_RADIO: - b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num); + b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num, has_vlan_tag); break; default: - bpf_error(cstate, "no VLAN support for data link type %d", - cstate->linktype); + bpf_error(cstate, "no VLAN support for %s", + pcap_datalink_val_to_description_or_dlt(cstate->linktype)); /*NOTREACHED*/ } @@ -8368,12 +9004,25 @@ gen_vlan(compiler_state_t *cstate, int vlan_num) /* * support for MPLS + * + * The label_num_arg dance is to avoid annoying whining by compilers that + * label_num might be clobbered by longjmp - yeah, it might, but *WHO CARES*? + * It's not *used* after setjmp returns. */ struct block * -gen_mpls(compiler_state_t *cstate, int label_num) +gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg, + int has_label_num) { + volatile bpf_u_int32 label_num = label_num_arg; struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + if (cstate->label_stack_depth > 0) { /* just match the bottom-of-stack bit clear */ b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01); @@ -8400,15 +9049,18 @@ gen_mpls(compiler_state_t *cstate, int label_num) * leave it for now */ default: - bpf_error(cstate, "no MPLS support for data link type %d", - cstate->linktype); + bpf_error(cstate, "no MPLS support for %s", + pcap_datalink_val_to_description_or_dlt(cstate->linktype)); /*NOTREACHED*/ - break; } } /* If a specific MPLS label is requested, check it */ - if (label_num >= 0) { + if (has_label_num) { + if (label_num > 0xFFFFF) { + bpf_error(cstate, "MPLS label %u greater than maximum %u", + label_num, 0xFFFFF); + } label_num = label_num << 12; /* label is shifted 12 bits on the wire */ b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, (bpf_int32)label_num, 0xfffff000); /* only compare the first 20 bits */ @@ -8442,22 +9094,40 @@ gen_mpls(compiler_state_t *cstate, int label_num) struct block * gen_pppoed(compiler_state_t *cstate) { + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* check for PPPoE discovery */ return gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOED); } struct block * -gen_pppoes(compiler_state_t *cstate, int sess_num) +gen_pppoes(compiler_state_t *cstate, bpf_u_int32 sess_num, int has_sess_num) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + /* * Test against the PPPoE session link-layer type. */ b0 = gen_linktype(cstate, (bpf_int32)ETHERTYPE_PPPOES); /* If a specific session is requested, check PPPoE session id */ - if (sess_num >= 0) { + if (has_sess_num) { + if (sess_num > 0x0000ffff) { + bpf_error(cstate, "PPPoE session number %u greater than maximum %u", + sess_num, 0x0000ffff); + } b1 = gen_mcmp(cstate, OR_LINKPL, 0, BPF_W, (bpf_int32)sess_num, 0x0000ffff); gen_and(b0, b1); @@ -8469,29 +9139,8 @@ gen_pppoes(compiler_state_t *cstate, int sess_num) * the PPP packet, and note that this is PPPoE rather than * raw PPP. * - * 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...". + * XXX - this is a bit of a kludge. See the comments in + * gen_vlan(). * * The "network-layer" protocol is PPPoE, which has a 6-byte * PPPoE header, followed by a PPP packet. @@ -8521,7 +9170,7 @@ gen_pppoes(compiler_state_t *cstate, int sess_num) static struct block * gen_geneve_check(compiler_state_t *cstate, struct block *(*gen_portfn)(compiler_state_t *, int, int, int), - enum e_offrel offrel, int vni) + enum e_offrel offrel, bpf_u_int32 vni, int has_vni) { struct block *b0, *b1; @@ -8534,7 +9183,11 @@ gen_geneve_check(compiler_state_t *cstate, gen_and(b0, b1); b0 = b1; - if (vni >= 0) { + if (has_vni) { + if (vni > 0xffffff) { + bpf_error(cstate, "Geneve VNI %u greater than maximum %u", + vni, 0xffffff); + } vni <<= 8; /* VNI is in the upper 3 bytes */ b1 = gen_mcmp(cstate, offrel, 12, BPF_W, (bpf_int32)vni, 0xffffff00); @@ -8551,12 +9204,12 @@ gen_geneve_check(compiler_state_t *cstate, * needed) into register A to be used later to compute * the inner packet offsets. */ static struct block * -gen_geneve4(compiler_state_t *cstate, int vni) +gen_geneve4(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) { struct block *b0, *b1; struct slist *s, *s1; - b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni); + b0 = gen_geneve_check(cstate, gen_port, OR_TRAN_IPV4, vni, has_vni); /* Load the IP header length into A. */ s = gen_loadx_iphdrlen(cstate); @@ -8577,12 +9230,12 @@ gen_geneve4(compiler_state_t *cstate, int vni) } static struct block * -gen_geneve6(compiler_state_t *cstate, int vni) +gen_geneve6(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) { struct block *b0, *b1; struct slist *s, *s1; - b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni); + b0 = gen_geneve_check(cstate, gen_port6, OR_TRAN_IPV6, vni, has_vni); /* Load the IP header length. We need to account for a * variable length link prefix if there is one. */ @@ -8755,13 +9408,20 @@ gen_geneve_offsets(compiler_state_t *cstate) /* Check to see if this is a Geneve packet. */ struct block * -gen_geneve(compiler_state_t *cstate, int vni) +gen_geneve(compiler_state_t *cstate, bpf_u_int32 vni, int has_vni) { struct block *b0, *b1; struct slist *s; - b0 = gen_geneve4(cstate, vni); - b1 = gen_geneve6(cstate, vni); + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + b0 = gen_geneve4(cstate, vni, has_vni); + b1 = gen_geneve6(cstate, vni, has_vni); gen_or(b0, b1); b0 = b1; @@ -8811,9 +9471,9 @@ gen_geneve_ll_check(compiler_state_t *cstate) return b0; } -struct block * -gen_atmfield_code(compiler_state_t *cstate, int atmfield, bpf_int32 jvalue, - bpf_u_int32 jtype, int reverse) +static struct block * +gen_atmfield_code_internal(compiler_state_t *cstate, int atmfield, + bpf_int32 jvalue, bpf_u_int32 jtype, int reverse) { struct block *b0; @@ -8866,28 +9526,80 @@ gen_atmfield_code(compiler_state_t *cstate, int atmfield, bpf_int32 jvalue, return b0; } +static struct block * +gen_atmtype_metac(compiler_state_t *cstate) +{ + struct block *b0, *b1; + + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 1, BPF_JEQ, 0); + gen_and(b0, b1); + return b1; +} + +static struct block * +gen_atmtype_sc(compiler_state_t *cstate) +{ + struct block *b0, *b1; + + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 5, BPF_JEQ, 0); + gen_and(b0, b1); + return b1; +} + +static struct block * +gen_atmtype_llc(compiler_state_t *cstate) +{ + struct block *b0; + + b0 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); + cstate->linktype = cstate->prevlinktype; + return b0; +} + +struct block * +gen_atmfield_code(compiler_state_t *cstate, int atmfield, + bpf_int32 jvalue, bpf_u_int32 jtype, int reverse) +{ + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + return gen_atmfield_code_internal(cstate, atmfield, jvalue, jtype, + reverse); +} + struct block * gen_atmtype_abbrev(compiler_state_t *cstate, int type) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (type) { case A_METAC: /* Get all packets in Meta signalling Circuit */ if (!cstate->is_atm) bpf_error(cstate, "'metac' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 1, BPF_JEQ, 0); - gen_and(b0, b1); + b1 = gen_atmtype_metac(cstate); break; case A_BCC: /* Get all packets in Broadcast Circuit*/ if (!cstate->is_atm) bpf_error(cstate, "'bcc' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 2, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 2, BPF_JEQ, 0); gen_and(b0, b1); break; @@ -8895,8 +9607,8 @@ gen_atmtype_abbrev(compiler_state_t *cstate, int type) /* Get all cells in Segment OAM F4 circuit*/ if (!cstate->is_atm) bpf_error(cstate, "'oam4sc' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 3, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); gen_and(b0, b1); break; @@ -8904,8 +9616,8 @@ gen_atmtype_abbrev(compiler_state_t *cstate, int type) /* Get all cells in End-to-End OAM F4 Circuit*/ if (!cstate->is_atm) bpf_error(cstate, "'oam4ec' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 4, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); gen_and(b0, b1); break; @@ -8913,17 +9625,15 @@ gen_atmtype_abbrev(compiler_state_t *cstate, int type) /* Get all packets in connection Signalling Circuit */ if (!cstate->is_atm) bpf_error(cstate, "'sc' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 5, BPF_JEQ, 0); - gen_and(b0, b1); + b1 = gen_atmtype_sc(cstate); break; case A_ILMIC: /* Get all packets in ILMI Circuit */ if (!cstate->is_atm) bpf_error(cstate, "'ilmic' supported only on raw ATM"); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 16, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 16, BPF_JEQ, 0); gen_and(b0, b1); break; @@ -8931,7 +9641,7 @@ gen_atmtype_abbrev(compiler_state_t *cstate, int type) /* Get all LANE packets */ if (!cstate->is_atm) bpf_error(cstate, "'lane' supported only on raw ATM"); - b1 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_PROTOTYPE, PT_LANE, BPF_JEQ, 0); /* * Arrange that all subsequent tests assume LANE @@ -8954,8 +9664,7 @@ gen_atmtype_abbrev(compiler_state_t *cstate, int type) /* Get all LLC-encapsulated packets */ if (!cstate->is_atm) bpf_error(cstate, "'llc' supported only on raw ATM"); - b1 = gen_atmfield_code(cstate, A_PROTOTYPE, PT_LLC, BPF_JEQ, 0); - cstate->linktype = cstate->prevlinktype; + b1 = gen_atmtype_llc(cstate); break; default: @@ -8976,6 +9685,13 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (type) { case M_FISU: @@ -9038,17 +9754,34 @@ gen_mtp2type_abbrev(compiler_state_t *cstate, int type) return b0; } +/* + * The jvalue_arg dance is to avoid annoying whining by compilers that + * jvalue might be clobbered by longjmp - yeah, it might, but *WHO CARES*? + * It's not *used* after setjmp returns. + */ struct block * -gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, bpf_u_int32 jvalue, - bpf_u_int32 jtype, int reverse) +gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, + bpf_u_int32 jvalue_arg, bpf_u_int32 jtype, int reverse) { + volatile bpf_u_int32 jvalue = jvalue_arg; struct block *b0; bpf_u_int32 val1 , val2 , val3; - u_int newoff_sio = cstate->off_sio; - u_int newoff_opc = cstate->off_opc; - u_int newoff_dpc = cstate->off_dpc; - u_int newoff_sls = cstate->off_sls; + u_int newoff_sio; + u_int newoff_opc; + u_int newoff_dpc; + u_int newoff_sls; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + + newoff_sio = cstate->off_sio; + newoff_opc = cstate->off_opc; + newoff_dpc = cstate->off_dpc; + newoff_sls = cstate->off_sls; switch (mtp3field) { case MH_SIO: @@ -9067,7 +9800,9 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, bpf_u_int32 jvalue, break; case MH_OPC: - newoff_opc+=3; + newoff_opc += 3; + + /* FALLTHROUGH */ case M_OPC: if (cstate->off_opc == OFFSET_NOT_SET) bpf_error(cstate, "'opc' supported only on SS7"); @@ -9111,7 +9846,9 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field, bpf_u_int32 jvalue, break; case MH_SLS: - newoff_sls+=3; + newoff_sls += 3; + /* FALLTHROUGH */ + case M_SLS: if (cstate->off_sls == OFFSET_NOT_SET) bpf_error(cstate, "'sls' supported only on SS7"); @@ -9144,27 +9881,27 @@ gen_msg_abbrev(compiler_state_t *cstate, int type) switch (type) { case A_SETUP: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, SETUP, BPF_JEQ, 0); break; case A_CALLPROCEED: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CALL_PROCEED, BPF_JEQ, 0); break; case A_CONNECT: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT, BPF_JEQ, 0); break; case A_CONNECTACK: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, CONNECT_ACK, BPF_JEQ, 0); break; case A_RELEASE: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE, BPF_JEQ, 0); break; case A_RELEASE_DONE: - b1 = gen_atmfield_code(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_MSGTYPE, RELEASE_DONE, BPF_JEQ, 0); break; default: @@ -9178,22 +9915,34 @@ gen_atmmulti_abbrev(compiler_state_t *cstate, int type) { struct block *b0, *b1; + /* + * Catch errors reported by us and routines below us, and return NULL + * on an error. + */ + if (setjmp(cstate->top_ctx)) + return (NULL); + switch (type) { case A_OAM: if (!cstate->is_atm) bpf_error(cstate, "'oam' supported only on raw ATM"); - b1 = gen_atmmulti_abbrev(cstate, A_OAMF4); + /* OAM F4 type */ + b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); + gen_or(b0, b1); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); + gen_and(b0, b1); break; case A_OAMF4: if (!cstate->is_atm) bpf_error(cstate, "'oamf4' supported only on raw ATM"); /* OAM F4 type */ - b0 = gen_atmfield_code(cstate, A_VCI, 3, BPF_JEQ, 0); - b1 = gen_atmfield_code(cstate, A_VCI, 4, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VCI, 3, BPF_JEQ, 0); + b1 = gen_atmfield_code_internal(cstate, A_VCI, 4, BPF_JEQ, 0); gen_or(b0, b1); - b0 = gen_atmfield_code(cstate, A_VPI, 0, BPF_JEQ, 0); + b0 = gen_atmfield_code_internal(cstate, A_VPI, 0, BPF_JEQ, 0); gen_and(b0, b1); break; @@ -9215,7 +9964,7 @@ gen_atmmulti_abbrev(compiler_state_t *cstate, int type) gen_or(b0, b1); b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); gen_or(b0, b1); - b0 = gen_atmtype_abbrev(cstate, A_SC); + b0 = gen_atmtype_sc(cstate); gen_and(b0, b1); break; @@ -9231,7 +9980,7 @@ gen_atmmulti_abbrev(compiler_state_t *cstate, int type) gen_or(b0, b1); b0 = gen_msg_abbrev(cstate, A_RELEASE_DONE); gen_or(b0, b1); - b0 = gen_atmtype_abbrev(cstate, A_METAC); + b0 = gen_atmtype_metac(cstate); gen_and(b0, b1); break; diff --git a/libpcap/gencode.h b/libpcap/gencode.h index 88def5a8a..cc21e0438 100644 --- a/libpcap/gencode.h +++ b/libpcap/gencode.h @@ -113,16 +113,14 @@ #define Q_ISIS_L2 32 /* PDU types */ #define Q_ISIS_IIH 33 -#define Q_ISIS_LAN_IIH 34 -#define Q_ISIS_PTP_IIH 35 -#define Q_ISIS_SNP 36 -#define Q_ISIS_CSNP 37 -#define Q_ISIS_PSNP 38 -#define Q_ISIS_LSP 39 +#define Q_ISIS_SNP 34 +#define Q_ISIS_CSNP 35 +#define Q_ISIS_PSNP 36 +#define Q_ISIS_LSP 37 -#define Q_RADIO 40 +#define Q_RADIO 38 -#define Q_CARP 41 +#define Q_CARP 39 /* Directional qualifiers. */ @@ -299,8 +297,8 @@ void gen_or(struct block *, struct block *); void gen_not(struct block *); struct block *gen_scode(compiler_state_t *, const char *, struct qual); -struct block *gen_ecode(compiler_state_t *, const u_char *, struct qual); -struct block *gen_acode(compiler_state_t *, const u_char *, struct qual); +struct block *gen_ecode(compiler_state_t *, const char *, struct qual); +struct block *gen_acode(compiler_state_t *, const char *, struct qual); struct block *gen_mcode(compiler_state_t *, const char *, const char *, unsigned int, struct qual); #ifdef INET6 @@ -326,13 +324,13 @@ struct block *gen_llc_u(compiler_state_t *); struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); -struct block *gen_vlan(compiler_state_t *, int); -struct block *gen_mpls(compiler_state_t *, int); +struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int); +struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int); struct block *gen_pppoed(compiler_state_t *); -struct block *gen_pppoes(compiler_state_t *, int); +struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int); -struct block *gen_geneve(compiler_state_t *, int); +struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int); struct block *gen_atmfield_code(compiler_state_t *, int, bpf_int32, bpf_u_int32, int); @@ -343,29 +341,11 @@ struct block *gen_mtp2type_abbrev(compiler_state_t *, int type); struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, bpf_u_int32, int); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_ifname(compiler_state_t *, const char *); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_rnr(compiler_state_t *, int); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_srnr(compiler_state_t *, int); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_ruleset(compiler_state_t *, char *); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_reason(compiler_state_t *, int); -#ifndef HAVE_NET_PFVAR_H -PCAP_NORETURN -#endif struct block *gen_pf_action(compiler_state_t *, int); struct block *gen_p80211_type(compiler_state_t *, int, int); @@ -386,16 +366,15 @@ struct icode { int cur_mark; }; -void bpf_optimize(compiler_state_t *, struct icode *ic); -void PCAP_NORETURN bpf_syntax_error(compiler_state_t *, const char *); -void PCAP_NORETURN bpf_error(compiler_state_t *, const char *, ...) +int bpf_optimize(struct icode *, char *); +void bpf_set_error(compiler_state_t *, const char *, ...) PCAP_PRINTFLIKE(2, 3); -void finish_parse(compiler_state_t *, struct block *); +int finish_parse(compiler_state_t *, struct block *); char *sdup(compiler_state_t *, const char *); -struct bpf_insn *icode_to_fcode(compiler_state_t *, struct icode *, - struct block *, u_int *); +struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, + char *); void sappend(struct slist *, struct slist *); /* diff --git a/libpcap/grammar.c b/libpcap/grammar.c deleted file mode 100644 index 2be760b87..000000000 --- a/libpcap/grammar.c +++ /dev/null @@ -1,3665 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.0.4" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 1 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - - -/* Substitute the variable and function names. */ -#define yyparse pcap_parse -#define yylex pcap_lex -#define yyerror pcap_error -#define yydebug pcap_debug -#define yynerrs pcap_nerrs - - -/* Copy the first part of user declarations. */ -#line 26 "grammar.y" /* yacc.c:339 */ - -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that: (1) source code distributions - * retain the above copyright notice and this paragraph in its entirety, (2) - * distributions including binary code include the above copyright notice and - * this paragraph in its entirety in the documentation or other materials - * provided with the distribution, and (3) all advertising materials mentioning - * features or use of this software display the following acknowledgement: - * ``This product includes software developed by the University of California, - * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#ifndef _WIN32 -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif - -#include -#include -#endif /* _WIN32 */ - -#include - -#include "diag-control.h" - -#include "pcap-int.h" - -#include "gencode.h" -#include "grammar.h" -#include "scanner.h" - -#ifdef HAVE_NET_PFVAR_H -#include -#include -#include -#endif -#include "llc.h" -#include "ieee80211.h" -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#ifdef YYBYACC -/* - * Both Berkeley YACC and Bison define yydebug (under whatever name - * it has) as a global, but Bison does so only if YYDEBUG is defined. - * Berkeley YACC define it even if YYDEBUG isn't defined; declare it - * here to suppress a warning. - */ -#if !defined(YYDEBUG) -extern int yydebug; -#endif - -/* - * In Berkeley YACC, yynerrs (under whatever name it has) is global, - * even if it's building a reentrant parser. In Bison, it's local - * in reentrant parsers. - * - * Declare it to squelch a warning. - */ -extern int yynerrs; -#endif - -#define QSET(q, p, d, a) (q).proto = (unsigned char)(p),\ - (q).dir = (unsigned char)(d),\ - (q).addr = (unsigned char)(a) - -struct tok { - int v; /* value */ - const char *s; /* string */ -}; - -static const struct tok ieee80211_types[] = { - { IEEE80211_FC0_TYPE_DATA, "data" }, - { IEEE80211_FC0_TYPE_MGT, "mgt" }, - { IEEE80211_FC0_TYPE_MGT, "management" }, - { IEEE80211_FC0_TYPE_CTL, "ctl" }, - { IEEE80211_FC0_TYPE_CTL, "control" }, - { 0, NULL } -}; -static const struct tok ieee80211_mgt_subtypes[] = { - { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assocreq" }, - { IEEE80211_FC0_SUBTYPE_ASSOC_REQ, "assoc-req" }, - { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assocresp" }, - { IEEE80211_FC0_SUBTYPE_ASSOC_RESP, "assoc-resp" }, - { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassocreq" }, - { IEEE80211_FC0_SUBTYPE_REASSOC_REQ, "reassoc-req" }, - { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassocresp" }, - { IEEE80211_FC0_SUBTYPE_REASSOC_RESP, "reassoc-resp" }, - { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probereq" }, - { IEEE80211_FC0_SUBTYPE_PROBE_REQ, "probe-req" }, - { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "proberesp" }, - { IEEE80211_FC0_SUBTYPE_PROBE_RESP, "probe-resp" }, - { IEEE80211_FC0_SUBTYPE_BEACON, "beacon" }, - { IEEE80211_FC0_SUBTYPE_ATIM, "atim" }, - { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassoc" }, - { IEEE80211_FC0_SUBTYPE_DISASSOC, "disassociation" }, - { IEEE80211_FC0_SUBTYPE_AUTH, "auth" }, - { IEEE80211_FC0_SUBTYPE_AUTH, "authentication" }, - { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauth" }, - { IEEE80211_FC0_SUBTYPE_DEAUTH, "deauthentication" }, - { 0, NULL } -}; -static const struct tok ieee80211_ctl_subtypes[] = { - { IEEE80211_FC0_SUBTYPE_PS_POLL, "ps-poll" }, - { IEEE80211_FC0_SUBTYPE_RTS, "rts" }, - { IEEE80211_FC0_SUBTYPE_CTS, "cts" }, - { IEEE80211_FC0_SUBTYPE_ACK, "ack" }, - { IEEE80211_FC0_SUBTYPE_CF_END, "cf-end" }, - { IEEE80211_FC0_SUBTYPE_CF_END_ACK, "cf-end-ack" }, - { 0, NULL } -}; -static const struct tok ieee80211_data_subtypes[] = { - { IEEE80211_FC0_SUBTYPE_DATA, "data" }, - { IEEE80211_FC0_SUBTYPE_CF_ACK, "data-cf-ack" }, - { IEEE80211_FC0_SUBTYPE_CF_POLL, "data-cf-poll" }, - { IEEE80211_FC0_SUBTYPE_CF_ACPL, "data-cf-ack-poll" }, - { IEEE80211_FC0_SUBTYPE_NODATA, "null" }, - { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK, "cf-ack" }, - { IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "cf-poll" }, - { IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "cf-ack-poll" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_DATA, "qos-data" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACK, "qos-data-cf-ack" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_POLL, "qos-data-cf-poll" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_CF_ACPL, "qos-data-cf-ack-poll" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA, "qos" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL, "qos-cf-poll" }, - { IEEE80211_FC0_SUBTYPE_QOS|IEEE80211_FC0_SUBTYPE_NODATA_CF_ACPL, "qos-cf-ack-poll" }, - { 0, NULL } -}; -static const struct tok llc_s_subtypes[] = { - { LLC_RR, "rr" }, - { LLC_RNR, "rnr" }, - { LLC_REJ, "rej" }, - { 0, NULL } -}; -static const struct tok llc_u_subtypes[] = { - { LLC_UI, "ui" }, - { LLC_UA, "ua" }, - { LLC_DISC, "disc" }, - { LLC_DM, "dm" }, - { LLC_SABME, "sabme" }, - { LLC_TEST, "test" }, - { LLC_XID, "xid" }, - { LLC_FRMR, "frmr" }, - { 0, NULL } -}; -struct type2tok { - int type; - const struct tok *tok; -}; -static const struct type2tok ieee80211_type_subtypes[] = { - { IEEE80211_FC0_TYPE_MGT, ieee80211_mgt_subtypes }, - { IEEE80211_FC0_TYPE_CTL, ieee80211_ctl_subtypes }, - { IEEE80211_FC0_TYPE_DATA, ieee80211_data_subtypes }, - { 0, NULL } -}; - -static int -str2tok(const char *str, const struct tok *toks) -{ - int i; - - for (i = 0; toks[i].s != NULL; i++) { - if (pcap_strcasecmp(toks[i].s, str) == 0) - return (toks[i].v); - } - return (-1); -} - -static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; - -static PCAP_NORETURN_DEF void -yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg) -{ - bpf_syntax_error(cstate, msg); - /* NOTREACHED */ -} - -#ifdef HAVE_NET_PFVAR_H -static int -pfreason_to_num(compiler_state_t *cstate, const char *reason) -{ - const char *reasons[] = PFRES_NAMES; - int i; - - for (i = 0; reasons[i]; i++) { - if (pcap_strcasecmp(reason, reasons[i]) == 0) - return (i); - } - bpf_error(cstate, "unknown PF reason"); - /*NOTREACHED*/ -} - -static int -pfaction_to_num(compiler_state_t *cstate, const char *action) -{ - if (pcap_strcasecmp(action, "pass") == 0 || - pcap_strcasecmp(action, "accept") == 0) - return (PF_PASS); - else if (pcap_strcasecmp(action, "drop") == 0 || - pcap_strcasecmp(action, "block") == 0) - return (PF_DROP); -#if HAVE_PF_NAT_THROUGH_PF_NORDR - else if (pcap_strcasecmp(action, "rdr") == 0) - return (PF_RDR); - else if (pcap_strcasecmp(action, "nat") == 0) - return (PF_NAT); - else if (pcap_strcasecmp(action, "binat") == 0) - return (PF_BINAT); - else if (pcap_strcasecmp(action, "nordr") == 0) - return (PF_NORDR); -#endif - else { - bpf_error(cstate, "unknown PF action"); - /*NOTREACHED*/ - } -} -#else /* !HAVE_NET_PFVAR_H */ -static PCAP_NORETURN_DEF int -pfreason_to_num(compiler_state_t *cstate, const char *reason _U_) -{ - bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ -} - -static PCAP_NORETURN_DEF int -pfaction_to_num(compiler_state_t *cstate, const char *action _U_) -{ - bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ -} -#endif /* HAVE_NET_PFVAR_H */ - -DIAG_OFF_BISON_BYACC - -#line 332 "grammar.c" /* yacc.c:339 */ - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "grammar.h". */ -#ifndef YY_PCAP_GRAMMAR_H_INCLUDED -# define YY_PCAP_GRAMMAR_H_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int pcap_debug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - DST = 258, - SRC = 259, - HOST = 260, - GATEWAY = 261, - NET = 262, - NETMASK = 263, - PORT = 264, - PORTRANGE = 265, - LESS = 266, - GREATER = 267, - PROTO = 268, - PROTOCHAIN = 269, - CBYTE = 270, - ARP = 271, - RARP = 272, - IP = 273, - SCTP = 274, - TCP = 275, - UDP = 276, - ICMP = 277, - IGMP = 278, - IGRP = 279, - PIM = 280, - VRRP = 281, - CARP = 282, - ATALK = 283, - AARP = 284, - DECNET = 285, - LAT = 286, - SCA = 287, - MOPRC = 288, - MOPDL = 289, - TK_BROADCAST = 290, - TK_MULTICAST = 291, - NUM = 292, - INBOUND = 293, - OUTBOUND = 294, - PF_IFNAME = 295, - PF_RSET = 296, - PF_RNR = 297, - PF_SRNR = 298, - PF_REASON = 299, - PF_ACTION = 300, - TYPE = 301, - SUBTYPE = 302, - DIR = 303, - ADDR1 = 304, - ADDR2 = 305, - ADDR3 = 306, - ADDR4 = 307, - RA = 308, - TA = 309, - LINK = 310, - GEQ = 311, - LEQ = 312, - NEQ = 313, - ID = 314, - EID = 315, - HID = 316, - HID6 = 317, - AID = 318, - LSH = 319, - RSH = 320, - LEN = 321, - IPV6 = 322, - ICMPV6 = 323, - AH = 324, - ESP = 325, - VLAN = 326, - MPLS = 327, - PPPOED = 328, - PPPOES = 329, - GENEVE = 330, - ISO = 331, - ESIS = 332, - CLNP = 333, - ISIS = 334, - L1 = 335, - L2 = 336, - IIH = 337, - LSP = 338, - SNP = 339, - CSNP = 340, - PSNP = 341, - STP = 342, - IPX = 343, - NETBEUI = 344, - LANE = 345, - LLC = 346, - METAC = 347, - BCC = 348, - SC = 349, - ILMIC = 350, - OAMF4EC = 351, - OAMF4SC = 352, - OAM = 353, - OAMF4 = 354, - CONNECTMSG = 355, - METACONNECT = 356, - VPI = 357, - VCI = 358, - RADIO = 359, - FISU = 360, - LSSU = 361, - MSU = 362, - HFISU = 363, - HLSSU = 364, - HMSU = 365, - SIO = 366, - OPC = 367, - DPC = 368, - SLS = 369, - HSIO = 370, - HOPC = 371, - HDPC = 372, - HSLS = 373, - OR = 374, - AND = 375, - UMINUS = 376 - }; -#endif -/* Tokens. */ -#define DST 258 -#define SRC 259 -#define HOST 260 -#define GATEWAY 261 -#define NET 262 -#define NETMASK 263 -#define PORT 264 -#define PORTRANGE 265 -#define LESS 266 -#define GREATER 267 -#define PROTO 268 -#define PROTOCHAIN 269 -#define CBYTE 270 -#define ARP 271 -#define RARP 272 -#define IP 273 -#define SCTP 274 -#define TCP 275 -#define UDP 276 -#define ICMP 277 -#define IGMP 278 -#define IGRP 279 -#define PIM 280 -#define VRRP 281 -#define CARP 282 -#define ATALK 283 -#define AARP 284 -#define DECNET 285 -#define LAT 286 -#define SCA 287 -#define MOPRC 288 -#define MOPDL 289 -#define TK_BROADCAST 290 -#define TK_MULTICAST 291 -#define NUM 292 -#define INBOUND 293 -#define OUTBOUND 294 -#define PF_IFNAME 295 -#define PF_RSET 296 -#define PF_RNR 297 -#define PF_SRNR 298 -#define PF_REASON 299 -#define PF_ACTION 300 -#define TYPE 301 -#define SUBTYPE 302 -#define DIR 303 -#define ADDR1 304 -#define ADDR2 305 -#define ADDR3 306 -#define ADDR4 307 -#define RA 308 -#define TA 309 -#define LINK 310 -#define GEQ 311 -#define LEQ 312 -#define NEQ 313 -#define ID 314 -#define EID 315 -#define HID 316 -#define HID6 317 -#define AID 318 -#define LSH 319 -#define RSH 320 -#define LEN 321 -#define IPV6 322 -#define ICMPV6 323 -#define AH 324 -#define ESP 325 -#define VLAN 326 -#define MPLS 327 -#define PPPOED 328 -#define PPPOES 329 -#define GENEVE 330 -#define ISO 331 -#define ESIS 332 -#define CLNP 333 -#define ISIS 334 -#define L1 335 -#define L2 336 -#define IIH 337 -#define LSP 338 -#define SNP 339 -#define CSNP 340 -#define PSNP 341 -#define STP 342 -#define IPX 343 -#define NETBEUI 344 -#define LANE 345 -#define LLC 346 -#define METAC 347 -#define BCC 348 -#define SC 349 -#define ILMIC 350 -#define OAMF4EC 351 -#define OAMF4SC 352 -#define OAM 353 -#define OAMF4 354 -#define CONNECTMSG 355 -#define METACONNECT 356 -#define VPI 357 -#define VCI 358 -#define RADIO 359 -#define FISU 360 -#define LSSU 361 -#define MSU 362 -#define HFISU 363 -#define HLSSU 364 -#define HMSU 365 -#define SIO 366 -#define OPC 367 -#define DPC 368 -#define SLS 369 -#define HSIO 370 -#define HOPC 371 -#define HDPC 372 -#define HSLS 373 -#define OR 374 -#define AND 375 -#define UMINUS 376 - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - -union YYSTYPE -{ -#line 286 "grammar.y" /* yacc.c:355 */ - - int i; - bpf_u_int32 h; - u_char *e; - char *s; - struct stmt *stmt; - struct arth *a; - struct { - struct qual q; - int atmfieldtype; - int mtp3fieldtype; - struct block *b; - } blk; - struct block *rblk; - -#line 630 "grammar.c" /* yacc.c:355 */ -}; - -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - - -int pcap_parse (void *yyscanner, compiler_state_t *cstate); - -#endif /* !YY_PCAP_GRAMMAR_H_INCLUDED */ - -/* Copy the second part of user declarations. */ - -#line 646 "grammar.c" /* yacc.c:358 */ - -#ifdef short -# undef short -#endif - -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif - -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short int yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short int yytype_int16; -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif -#endif - -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - - -#if ! defined yyoverflow || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yytype_int16 yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 3 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 788 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 139 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 47 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 220 -/* YYNSTATES -- Number of states. */ -#define YYNSTATES 294 - -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 376 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 121, 2, 2, 2, 137, 123, 2, - 130, 129, 126, 124, 2, 125, 2, 127, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 136, 2, - 133, 132, 131, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 134, 2, 135, 138, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 122, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 120, 128 -}; - -#if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 360, 360, 364, 366, 368, 369, 370, 371, 372, - 374, 376, 378, 379, 381, 383, 384, 386, 388, 401, - 410, 419, 428, 437, 439, 441, 443, 444, 445, 447, - 449, 451, 452, 454, 455, 456, 457, 458, 459, 461, - 462, 463, 464, 466, 468, 469, 470, 471, 472, 473, - 476, 477, 480, 481, 482, 483, 484, 485, 486, 487, - 488, 489, 490, 491, 494, 495, 496, 497, 500, 502, - 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, - 533, 534, 535, 536, 537, 538, 539, 540, 542, 543, - 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, - 554, 555, 556, 557, 558, 559, 560, 563, 564, 565, - 566, 567, 568, 571, 576, 579, 583, 586, 587, 593, - 594, 614, 630, 631, 652, 655, 656, 669, 670, 673, - 676, 677, 678, 680, 681, 682, 684, 685, 687, 688, - 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, - 699, 700, 701, 703, 704, 705, 706, 707, 709, 710, - 712, 713, 714, 715, 716, 717, 718, 720, 721, 722, - 723, 726, 727, 729, 730, 731, 732, 734, 741, 742, - 745, 746, 747, 748, 749, 750, 753, 754, 755, 756, - 757, 758, 759, 760, 762, 763, 764, 765, 767, 780, - 781 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE || 0 -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "DST", "SRC", "HOST", "GATEWAY", "NET", - "NETMASK", "PORT", "PORTRANGE", "LESS", "GREATER", "PROTO", "PROTOCHAIN", - "CBYTE", "ARP", "RARP", "IP", "SCTP", "TCP", "UDP", "ICMP", "IGMP", - "IGRP", "PIM", "VRRP", "CARP", "ATALK", "AARP", "DECNET", "LAT", "SCA", - "MOPRC", "MOPDL", "TK_BROADCAST", "TK_MULTICAST", "NUM", "INBOUND", - "OUTBOUND", "PF_IFNAME", "PF_RSET", "PF_RNR", "PF_SRNR", "PF_REASON", - "PF_ACTION", "TYPE", "SUBTYPE", "DIR", "ADDR1", "ADDR2", "ADDR3", - "ADDR4", "RA", "TA", "LINK", "GEQ", "LEQ", "NEQ", "ID", "EID", "HID", - "HID6", "AID", "LSH", "RSH", "LEN", "IPV6", "ICMPV6", "AH", "ESP", - "VLAN", "MPLS", "PPPOED", "PPPOES", "GENEVE", "ISO", "ESIS", "CLNP", - "ISIS", "L1", "L2", "IIH", "LSP", "SNP", "CSNP", "PSNP", "STP", "IPX", - "NETBEUI", "LANE", "LLC", "METAC", "BCC", "SC", "ILMIC", "OAMF4EC", - "OAMF4SC", "OAM", "OAMF4", "CONNECTMSG", "METACONNECT", "VPI", "VCI", - "RADIO", "FISU", "LSSU", "MSU", "HFISU", "HLSSU", "HMSU", "SIO", "OPC", - "DPC", "SLS", "HSIO", "HOPC", "HDPC", "HSLS", "OR", "AND", "'!'", "'|'", - "'&'", "'+'", "'-'", "'*'", "'/'", "UMINUS", "')'", "'('", "'>'", "'='", - "'<'", "'['", "']'", "':'", "'%'", "'^'", "$accept", "prog", "null", - "expr", "and", "or", "id", "nid", "not", "paren", "pid", "qid", "term", - "head", "rterm", "pqual", "dqual", "aqual", "ndaqual", "pname", "other", - "pfvar", "p80211", "type", "subtype", "type_subtype", "pllc", "dir", - "reason", "action", "relop", "irelop", "arth", "narth", "byteop", "pnum", - "atmtype", "atmmultitype", "atmfield", "atmvalue", "atmfieldvalue", - "atmlistvalue", "mtp2type", "mtp3field", "mtp3value", "mtp3fieldvalue", - "mtp3listvalue", YY_NULLPTR -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, - 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 33, 124, 38, 43, 45, 42, 47, 376, 41, - 40, 62, 61, 60, 91, 93, 58, 37, 94 -}; -# endif - -#define YYPACT_NINF -216 - -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-216))) - -#define YYTABLE_NINF -42 - -#define yytable_value_is_error(Yytable_value) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -216, 24, 257, -216, 0, 12, 17, -216, -216, -216, - -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, - -216, -216, -216, -216, -216, -216, -216, -216, -216, 16, - 25, 29, 72, -18, 55, -216, -216, -216, -216, -216, - -216, -25, -25, -216, -25, -25, -216, -216, -216, -216, - -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, - -216, -24, -216, -216, -216, -216, -216, -216, -216, -216, - -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, - -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, - 604, -216, -30, 489, 489, -216, 125, -216, 734, 3, - -216, -216, -216, 183, -216, -216, -216, -216, -5, -216, - 39, -216, -216, -54, -216, -216, -216, -216, -216, -216, - -216, -216, -216, -25, -216, -216, -216, -216, -216, -216, - 604, -16, -108, -216, -216, 373, 373, -216, -103, -10, - 2, -216, -216, -7, 11, -216, -216, -216, 125, 125, - -216, -3, 21, -216, -216, -216, -216, -216, -216, -216, - -216, -216, -12, 77, -9, -216, -216, -216, -216, -216, - -216, 78, -216, -216, -216, 604, -216, -216, -216, 604, - 604, 604, 604, 604, 604, 604, 604, -216, -216, -216, - 604, 604, 604, 604, -216, 111, 113, 114, -216, -216, - -216, 115, 124, 126, -216, -216, -216, -216, -216, -216, - -216, 131, 2, 575, -216, 373, 373, -216, 10, -216, - -216, -216, -216, -216, 112, 137, 138, -216, -216, 47, - -30, 2, 173, 176, 178, 186, -216, -216, 143, -216, - -216, -216, -216, -216, -216, 127, -64, -64, 580, 598, - -104, -104, -108, -108, 575, 575, 575, 575, -216, -98, - -216, -216, -216, -47, -216, -216, -216, -49, -216, -216, - -216, -216, 125, 125, -216, -216, -216, -216, -1, -216, - 156, -216, 111, -216, 115, -216, -216, -216, -216, -216, - 59, -216, -216, -216 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 4, 0, 51, 1, 0, 0, 0, 71, 72, 70, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 85, 86, 88, 87, 178, 113, 114, 0, - 0, 0, 0, 0, 0, 69, 172, 89, 90, 91, - 92, 116, 118, 119, 121, 123, 93, 94, 103, 95, - 96, 97, 98, 99, 100, 102, 101, 104, 105, 106, - 180, 142, 181, 182, 185, 186, 183, 184, 187, 188, - 189, 190, 191, 192, 107, 200, 201, 202, 203, 204, - 205, 206, 207, 208, 209, 210, 211, 212, 213, 24, - 0, 25, 2, 51, 51, 5, 0, 31, 0, 50, - 44, 124, 126, 0, 157, 156, 45, 46, 0, 48, - 0, 110, 111, 0, 127, 128, 129, 130, 147, 148, - 131, 149, 132, 0, 115, 117, 120, 122, 144, 143, - 0, 0, 170, 11, 10, 51, 51, 32, 0, 157, - 156, 15, 21, 18, 20, 22, 39, 12, 0, 0, - 13, 53, 52, 64, 68, 65, 66, 67, 36, 37, - 108, 109, 0, 0, 0, 58, 59, 60, 61, 62, - 63, 34, 35, 38, 125, 0, 151, 153, 155, 0, - 0, 0, 0, 0, 0, 0, 0, 150, 152, 154, - 0, 0, 0, 0, 197, 0, 0, 0, 47, 193, - 218, 0, 0, 0, 49, 214, 174, 173, 176, 177, - 175, 0, 0, 0, 7, 51, 51, 6, 156, 9, - 8, 40, 171, 179, 0, 0, 0, 23, 26, 30, - 0, 29, 0, 0, 0, 0, 137, 138, 134, 141, - 135, 145, 146, 136, 33, 0, 168, 169, 166, 165, - 160, 161, 162, 163, 164, 167, 42, 43, 198, 0, - 194, 195, 219, 0, 215, 216, 112, 156, 17, 16, - 19, 14, 0, 0, 55, 57, 54, 56, 0, 158, - 0, 196, 0, 217, 0, 27, 28, 139, 140, 133, - 0, 199, 220, 159 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -216, -216, -216, 193, -34, -215, -90, -135, 7, -2, - -216, -216, -80, -216, -216, -216, -216, 26, -216, 9, - -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, - -43, 5, -26, -92, -216, -37, -216, -216, -216, -216, - -175, -216, -216, -216, -216, -174, -216 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 1, 2, 138, 135, 136, 227, 147, 148, 130, - 229, 230, 95, 96, 97, 98, 171, 172, 173, 131, - 100, 101, 174, 238, 289, 240, 102, 243, 120, 122, - 192, 193, 103, 104, 211, 105, 106, 107, 108, 198, - 199, 259, 109, 110, 204, 205, 263 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 94, 224, 139, -41, 124, 125, 146, 126, 127, 93, - -13, 99, 26, 137, 228, 273, 133, 134, 128, 118, - 258, 133, 185, 186, 3, 236, 221, 262, 241, 190, - 191, 281, 194, 190, 191, 129, 287, 111, 139, 123, - 123, 119, 123, 123, 282, 214, 219, 237, 284, 112, - 242, 176, 177, 178, 113, 217, 220, 140, 288, 150, - 183, 184, 185, 186, 132, 196, 116, 202, 206, 207, - -29, -29, 133, 190, 191, 114, 200, 208, 209, 210, - 223, 228, 283, 153, 115, 155, 212, 156, 157, 133, - 134, 94, 94, 140, 149, 176, 177, 178, 218, 218, - 93, 93, 99, 99, 213, 91, 195, 291, 201, 117, - 292, 150, 231, 197, 121, 203, 232, 233, 175, 222, - 225, 123, -41, -41, 139, 91, 187, 188, 189, -13, - -13, 223, -41, 216, 216, 137, 239, 175, 226, -13, - 234, 235, 215, 215, 99, 99, 149, 123, 194, 245, - 260, 261, 200, 246, 247, 248, 249, 250, 251, 252, - 253, 264, 26, 265, 254, 255, 256, 257, 266, 91, - 187, 188, 189, 268, 269, 270, 271, 274, 218, 267, - 275, 276, 285, 286, 141, 142, 143, 144, 145, 277, - 278, 179, 180, 290, 293, 92, 272, 244, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 216, 94, 0, 0, 0, 0, 0, - 0, 0, 215, 215, 99, 99, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 150, 150, 0, 0, 176, - 177, 178, 0, 0, 0, 0, 89, 179, 180, 181, - 182, 183, 184, 185, 186, 91, 0, -3, 0, 0, - 0, 0, 279, 280, 190, 191, 0, 0, 4, 5, - 149, 149, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 0, 0, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 0, 0, 181, 182, 183, 184, 185, - 186, 0, 35, 0, 187, 188, 189, 0, 0, 0, - 190, 191, 0, 36, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 85, 86, 87, 88, 0, 0, 89, 0, - 0, 0, 90, 0, 4, 5, 0, 91, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, - 0, 0, 141, 142, 143, 144, 145, 0, 0, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, - 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - 87, 88, 0, 0, 89, 0, 0, 0, 90, 0, - 4, 5, 0, 91, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 0, 0, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 0, 0, - 89, 0, 0, 0, 90, 0, 0, 0, 0, 91, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 179, - 180, 26, 0, 0, 179, 180, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, - 0, 0, 179, 180, 0, 0, 0, 0, 0, 0, - 36, 37, 38, 39, 40, 0, 0, 0, 0, 0, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 0, 0, 0, 181, 182, 183, - 184, 185, 186, 182, 183, 184, 185, 186, 74, 0, - 0, 0, 190, 191, 0, 0, 0, 190, 191, 0, - 0, 0, 183, 184, 185, 186, 0, 0, 0, 90, - 0, 0, 0, 0, 91, 190, 191, 151, 152, 153, - 154, 155, 0, 156, 157, 0, 0, 158, 159, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, - 161, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 162, 163, 164, 165, 166, 167, 168, 169, 170 -}; - -static const yytype_int16 yycheck[] = -{ - 2, 8, 94, 0, 41, 42, 96, 44, 45, 2, - 0, 2, 37, 93, 149, 230, 119, 120, 42, 37, - 195, 119, 126, 127, 0, 37, 129, 201, 37, 137, - 138, 129, 37, 137, 138, 59, 37, 37, 130, 41, - 42, 59, 44, 45, 259, 135, 136, 59, 263, 37, - 59, 56, 57, 58, 37, 135, 136, 94, 59, 96, - 124, 125, 126, 127, 90, 108, 37, 110, 122, 123, - 119, 120, 119, 137, 138, 59, 37, 131, 132, 133, - 129, 216, 129, 5, 59, 7, 123, 9, 10, 119, - 120, 93, 94, 130, 96, 56, 57, 58, 135, 136, - 93, 94, 93, 94, 130, 130, 108, 282, 110, 37, - 284, 148, 149, 108, 59, 110, 119, 120, 134, 129, - 127, 123, 119, 120, 216, 130, 131, 132, 133, 119, - 120, 129, 129, 135, 136, 215, 59, 134, 127, 129, - 119, 120, 135, 136, 135, 136, 148, 149, 37, 175, - 37, 37, 37, 179, 180, 181, 182, 183, 184, 185, - 186, 37, 37, 37, 190, 191, 192, 193, 37, 130, - 131, 132, 133, 61, 37, 37, 129, 4, 215, 216, - 4, 3, 272, 273, 59, 60, 61, 62, 63, 3, - 47, 64, 65, 37, 135, 2, 230, 171, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 215, 216, -1, -1, -1, -1, -1, - -1, -1, 215, 216, 215, 216, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 272, 273, -1, -1, 56, - 57, 58, -1, -1, -1, -1, 121, 64, 65, 122, - 123, 124, 125, 126, 127, 130, -1, 0, -1, -1, - -1, -1, 135, 136, 137, 138, -1, -1, 11, 12, - 272, 273, 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, -1, -1, 37, 38, 39, 40, 41, 42, - 43, 44, 45, -1, -1, 122, 123, 124, 125, 126, - 127, -1, 55, -1, 131, 132, 133, -1, -1, -1, - 137, 138, -1, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, -1, 121, -1, - -1, -1, 125, -1, 11, 12, -1, 130, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, -1, -1, - 37, 38, 39, 40, 41, 42, 43, 44, 45, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 55, -1, - -1, -1, 59, 60, 61, 62, 63, -1, -1, 66, - 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, - 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, -1, 121, -1, -1, -1, 125, -1, - 11, 12, -1, 130, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, -1, -1, 37, 38, 39, 40, - 41, 42, 43, 44, 45, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 55, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, 117, 118, -1, -1, - 121, -1, -1, -1, 125, -1, -1, -1, -1, 130, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 64, - 65, 37, -1, -1, 64, 65, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 55, - -1, -1, 64, 65, -1, -1, -1, -1, -1, -1, - 66, 67, 68, 69, 70, -1, -1, -1, -1, -1, - 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, -1, -1, -1, 122, 123, 124, - 125, 126, 127, 123, 124, 125, 126, 127, 104, -1, - -1, -1, 137, 138, -1, -1, -1, 137, 138, -1, - -1, -1, 124, 125, 126, 127, -1, -1, -1, 125, - -1, -1, -1, -1, 130, 137, 138, 3, 4, 5, - 6, 7, -1, 9, 10, -1, -1, 13, 14, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 35, - 36, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 46, 47, 48, 49, 50, 51, 52, 53, 54 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 140, 141, 0, 11, 12, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 55, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 121, - 125, 130, 142, 147, 148, 151, 152, 153, 154, 158, - 159, 160, 165, 171, 172, 174, 175, 176, 177, 181, - 182, 37, 37, 37, 59, 59, 37, 37, 37, 59, - 167, 59, 168, 148, 174, 174, 174, 174, 42, 59, - 148, 158, 171, 119, 120, 143, 144, 151, 142, 172, - 174, 59, 60, 61, 62, 63, 145, 146, 147, 148, - 174, 3, 4, 5, 6, 7, 9, 10, 13, 14, - 35, 36, 46, 47, 48, 49, 50, 51, 52, 53, - 54, 155, 156, 157, 161, 134, 56, 57, 58, 64, - 65, 122, 123, 124, 125, 126, 127, 131, 132, 133, - 137, 138, 169, 170, 37, 148, 169, 170, 178, 179, - 37, 148, 169, 170, 183, 184, 122, 123, 131, 132, - 133, 173, 174, 171, 145, 147, 148, 151, 174, 145, - 151, 129, 129, 129, 8, 127, 127, 145, 146, 149, - 150, 174, 119, 120, 119, 120, 37, 59, 162, 59, - 164, 37, 59, 166, 156, 171, 171, 171, 171, 171, - 171, 171, 171, 171, 171, 171, 171, 171, 179, 180, - 37, 37, 184, 185, 37, 37, 37, 174, 61, 37, - 37, 129, 143, 144, 4, 4, 3, 3, 47, 135, - 136, 129, 144, 129, 144, 145, 145, 37, 59, 163, - 37, 179, 184, 135 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 139, 140, 140, 141, 142, 142, 142, 142, 142, - 143, 144, 145, 145, 145, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 147, 148, 149, 149, 149, 150, - 150, 151, 151, 152, 152, 152, 152, 152, 152, 153, - 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, - 154, 154, 155, 155, 155, 155, 155, 155, 155, 155, - 155, 155, 155, 155, 156, 156, 156, 156, 157, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 159, 159, - 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, - 159, 159, 159, 159, 159, 159, 159, 160, 160, 160, - 160, 160, 160, 161, 161, 161, 161, 162, 162, 163, - 163, 164, 165, 165, 165, 166, 166, 167, 167, 168, - 169, 169, 169, 170, 170, 170, 171, 171, 172, 172, - 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, - 172, 172, 172, 173, 173, 173, 173, 173, 174, 174, - 175, 175, 175, 175, 175, 175, 175, 176, 176, 176, - 176, 177, 177, 178, 178, 178, 178, 179, 180, 180, - 181, 181, 181, 181, 181, 181, 182, 182, 182, 182, - 182, 182, 182, 182, 183, 183, 183, 183, 184, 185, - 185 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 2, 1, 0, 1, 3, 3, 3, 3, - 1, 1, 1, 1, 3, 1, 3, 3, 1, 3, - 1, 1, 1, 2, 1, 1, 1, 3, 3, 1, - 1, 1, 2, 3, 2, 2, 2, 2, 2, 2, - 3, 1, 3, 3, 1, 1, 1, 2, 1, 2, - 1, 0, 1, 1, 3, 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, - 2, 2, 4, 1, 1, 2, 1, 2, 1, 1, - 2, 1, 2, 1, 1, 2, 1, 2, 2, 2, - 2, 2, 2, 4, 2, 2, 2, 1, 1, 1, - 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 4, 6, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 3, 1, 1, 1, 1, 1, 1, 1, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 2, 3, 1, 1, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, - 3 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (yyscanner, cstate, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value, yyscanner, cstate); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - - -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ - -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, compiler_state_t *cstate) -{ - FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (yyscanner); - YYUSE (cstate); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); -} - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *yyscanner, compiler_state_t *cstate) -{ - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yyscanner, cstate); - YYFPRINTF (yyoutput, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, void *yyscanner, compiler_state_t *cstate) -{ - unsigned long int yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; - int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , yyscanner, cstate); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, cstate); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *yyscanner, compiler_state_t *cstate) -{ - YYUSE (yyvaluep); - YYUSE (yyscanner); - YYUSE (cstate); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - - - -/*----------. -| yyparse. | -`----------*/ - -int -yyparse (void *yyscanner, compiler_state_t *cstate) -{ -/* The lookahead symbol. */ -int yychar; - - -/* The semantic value of the lookahead symbol. */ -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) -YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); - - /* Number of syntax errors so far. */ - int yynerrs; - - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; - - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, yyscanner); - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 2: -#line 361 "grammar.y" /* yacc.c:1646 */ - { - finish_parse(cstate, (yyvsp[0].blk).b); -} -#line 2085 "grammar.c" /* yacc.c:1646 */ - break; - - case 4: -#line 366 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).q = qerr; } -#line 2091 "grammar.c" /* yacc.c:1646 */ - break; - - case 6: -#line 369 "grammar.y" /* yacc.c:1646 */ - { gen_and((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2097 "grammar.c" /* yacc.c:1646 */ - break; - - case 7: -#line 370 "grammar.y" /* yacc.c:1646 */ - { gen_and((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2103 "grammar.c" /* yacc.c:1646 */ - break; - - case 8: -#line 371 "grammar.y" /* yacc.c:1646 */ - { gen_or((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2109 "grammar.c" /* yacc.c:1646 */ - break; - - case 9: -#line 372 "grammar.y" /* yacc.c:1646 */ - { gen_or((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2115 "grammar.c" /* yacc.c:1646 */ - break; - - case 10: -#line 374 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[-1].blk); } -#line 2121 "grammar.c" /* yacc.c:1646 */ - break; - - case 11: -#line 376 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[-1].blk); } -#line 2127 "grammar.c" /* yacc.c:1646 */ - break; - - case 13: -#line 379 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_ncode(cstate, NULL, (bpf_u_int32)(yyvsp[0].i), - (yyval.blk).q = (yyvsp[-1].blk).q); } -#line 2134 "grammar.c" /* yacc.c:1646 */ - break; - - case 14: -#line 381 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[-1].blk); } -#line 2140 "grammar.c" /* yacc.c:1646 */ - break; - - case 15: -#line 383 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_scode(cstate, (yyvsp[0].s), (yyval.blk).q = (yyvsp[-1].blk).q); } -#line 2146 "grammar.c" /* yacc.c:1646 */ - break; - - case 16: -#line 384 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_mcode(cstate, (yyvsp[-2].s), NULL, (yyvsp[0].i), - (yyval.blk).q = (yyvsp[-3].blk).q); } -#line 2153 "grammar.c" /* yacc.c:1646 */ - break; - - case 17: -#line 386 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_mcode(cstate, (yyvsp[-2].s), (yyvsp[0].s), 0, - (yyval.blk).q = (yyvsp[-3].blk).q); } -#line 2160 "grammar.c" /* yacc.c:1646 */ - break; - - case 18: -#line 388 "grammar.y" /* yacc.c:1646 */ - { - /* Decide how to parse HID based on proto */ - (yyval.blk).q = (yyvsp[-1].blk).q; - if ((yyval.blk).q.addr == Q_PORT) - bpf_error(cstate, "'port' modifier applied to ip host"); - else if ((yyval.blk).q.addr == Q_PORTRANGE) - bpf_error(cstate, "'portrange' modifier applied to ip host"); - else if ((yyval.blk).q.addr == Q_PROTO) - bpf_error(cstate, "'proto' modifier applied to ip host"); - else if ((yyval.blk).q.addr == Q_PROTOCHAIN) - bpf_error(cstate, "'protochain' modifier applied to ip host"); - (yyval.blk).b = gen_ncode(cstate, (yyvsp[0].s), 0, (yyval.blk).q); - } -#line 2178 "grammar.c" /* yacc.c:1646 */ - break; - - case 19: -#line 401 "grammar.y" /* yacc.c:1646 */ - { -#ifdef INET6 - (yyval.blk).b = gen_mcode6(cstate, (yyvsp[-2].s), NULL, (yyvsp[0].i), - (yyval.blk).q = (yyvsp[-3].blk).q); -#else - bpf_error(cstate, "'ip6addr/prefixlen' not supported " - "in this configuration"); -#endif /*INET6*/ - } -#line 2192 "grammar.c" /* yacc.c:1646 */ - break; - - case 20: -#line 410 "grammar.y" /* yacc.c:1646 */ - { -#ifdef INET6 - (yyval.blk).b = gen_mcode6(cstate, (yyvsp[0].s), 0, 128, - (yyval.blk).q = (yyvsp[-1].blk).q); -#else - bpf_error(cstate, "'ip6addr' not supported " - "in this configuration"); -#endif /*INET6*/ - } -#line 2206 "grammar.c" /* yacc.c:1646 */ - break; - - case 21: -#line 419 "grammar.y" /* yacc.c:1646 */ - { - (yyval.blk).b = gen_ecode(cstate, (yyvsp[0].e), (yyval.blk).q = (yyvsp[-1].blk).q); - /* - * $1 was allocated by "pcap_ether_aton()", - * so we must free it now that we're done - * with it. - */ - free((yyvsp[0].e)); - } -#line 2220 "grammar.c" /* yacc.c:1646 */ - break; - - case 22: -#line 428 "grammar.y" /* yacc.c:1646 */ - { - (yyval.blk).b = gen_acode(cstate, (yyvsp[0].e), (yyval.blk).q = (yyvsp[-1].blk).q); - /* - * $1 was allocated by "pcap_ether_aton()", - * so we must free it now that we're done - * with it. - */ - free((yyvsp[0].e)); - } -#line 2234 "grammar.c" /* yacc.c:1646 */ - break; - - case 23: -#line 437 "grammar.y" /* yacc.c:1646 */ - { gen_not((yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2240 "grammar.c" /* yacc.c:1646 */ - break; - - case 24: -#line 439 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[-1].blk); } -#line 2246 "grammar.c" /* yacc.c:1646 */ - break; - - case 25: -#line 441 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[-1].blk); } -#line 2252 "grammar.c" /* yacc.c:1646 */ - break; - - case 27: -#line 444 "grammar.y" /* yacc.c:1646 */ - { gen_and((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2258 "grammar.c" /* yacc.c:1646 */ - break; - - case 28: -#line 445 "grammar.y" /* yacc.c:1646 */ - { gen_or((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2264 "grammar.c" /* yacc.c:1646 */ - break; - - case 29: -#line 447 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_ncode(cstate, NULL, (bpf_u_int32)(yyvsp[0].i), - (yyval.blk).q = (yyvsp[-1].blk).q); } -#line 2271 "grammar.c" /* yacc.c:1646 */ - break; - - case 32: -#line 452 "grammar.y" /* yacc.c:1646 */ - { gen_not((yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 2277 "grammar.c" /* yacc.c:1646 */ - break; - - case 33: -#line 454 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-2].i), (yyvsp[-1].i), (yyvsp[0].i)); } -#line 2283 "grammar.c" /* yacc.c:1646 */ - break; - - case 34: -#line 455 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-1].i), (yyvsp[0].i), Q_DEFAULT); } -#line 2289 "grammar.c" /* yacc.c:1646 */ - break; - - case 35: -#line 456 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-1].i), Q_DEFAULT, (yyvsp[0].i)); } -#line 2295 "grammar.c" /* yacc.c:1646 */ - break; - - case 36: -#line 457 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-1].i), Q_DEFAULT, Q_PROTO); } -#line 2301 "grammar.c" /* yacc.c:1646 */ - break; - - case 37: -#line 458 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-1].i), Q_DEFAULT, Q_PROTOCHAIN); } -#line 2307 "grammar.c" /* yacc.c:1646 */ - break; - - case 38: -#line 459 "grammar.y" /* yacc.c:1646 */ - { QSET((yyval.blk).q, (yyvsp[-1].i), Q_DEFAULT, (yyvsp[0].i)); } -#line 2313 "grammar.c" /* yacc.c:1646 */ - break; - - case 39: -#line 461 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk) = (yyvsp[0].blk); } -#line 2319 "grammar.c" /* yacc.c:1646 */ - break; - - case 40: -#line 462 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[-1].blk).b; (yyval.blk).q = (yyvsp[-2].blk).q; } -#line 2325 "grammar.c" /* yacc.c:1646 */ - break; - - case 41: -#line 463 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_proto_abbrev(cstate, (yyvsp[0].i)); (yyval.blk).q = qerr; } -#line 2331 "grammar.c" /* yacc.c:1646 */ - break; - - case 42: -#line 464 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_relation(cstate, (yyvsp[-1].i), (yyvsp[-2].a), (yyvsp[0].a), 0); - (yyval.blk).q = qerr; } -#line 2338 "grammar.c" /* yacc.c:1646 */ - break; - - case 43: -#line 466 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_relation(cstate, (yyvsp[-1].i), (yyvsp[-2].a), (yyvsp[0].a), 1); - (yyval.blk).q = qerr; } -#line 2345 "grammar.c" /* yacc.c:1646 */ - break; - - case 44: -#line 468 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[0].rblk); (yyval.blk).q = qerr; } -#line 2351 "grammar.c" /* yacc.c:1646 */ - break; - - case 45: -#line 469 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_atmtype_abbrev(cstate, (yyvsp[0].i)); (yyval.blk).q = qerr; } -#line 2357 "grammar.c" /* yacc.c:1646 */ - break; - - case 46: -#line 470 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_atmmulti_abbrev(cstate, (yyvsp[0].i)); (yyval.blk).q = qerr; } -#line 2363 "grammar.c" /* yacc.c:1646 */ - break; - - case 47: -#line 471 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[0].blk).b; (yyval.blk).q = qerr; } -#line 2369 "grammar.c" /* yacc.c:1646 */ - break; - - case 48: -#line 472 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_mtp2type_abbrev(cstate, (yyvsp[0].i)); (yyval.blk).q = qerr; } -#line 2375 "grammar.c" /* yacc.c:1646 */ - break; - - case 49: -#line 473 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[0].blk).b; (yyval.blk).q = qerr; } -#line 2381 "grammar.c" /* yacc.c:1646 */ - break; - - case 51: -#line 477 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_DEFAULT; } -#line 2387 "grammar.c" /* yacc.c:1646 */ - break; - - case 52: -#line 480 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_SRC; } -#line 2393 "grammar.c" /* yacc.c:1646 */ - break; - - case 53: -#line 481 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_DST; } -#line 2399 "grammar.c" /* yacc.c:1646 */ - break; - - case 54: -#line 482 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_OR; } -#line 2405 "grammar.c" /* yacc.c:1646 */ - break; - - case 55: -#line 483 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_OR; } -#line 2411 "grammar.c" /* yacc.c:1646 */ - break; - - case 56: -#line 484 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_AND; } -#line 2417 "grammar.c" /* yacc.c:1646 */ - break; - - case 57: -#line 485 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_AND; } -#line 2423 "grammar.c" /* yacc.c:1646 */ - break; - - case 58: -#line 486 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ADDR1; } -#line 2429 "grammar.c" /* yacc.c:1646 */ - break; - - case 59: -#line 487 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ADDR2; } -#line 2435 "grammar.c" /* yacc.c:1646 */ - break; - - case 60: -#line 488 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ADDR3; } -#line 2441 "grammar.c" /* yacc.c:1646 */ - break; - - case 61: -#line 489 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ADDR4; } -#line 2447 "grammar.c" /* yacc.c:1646 */ - break; - - case 62: -#line 490 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_RA; } -#line 2453 "grammar.c" /* yacc.c:1646 */ - break; - - case 63: -#line 491 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_TA; } -#line 2459 "grammar.c" /* yacc.c:1646 */ - break; - - case 64: -#line 494 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_HOST; } -#line 2465 "grammar.c" /* yacc.c:1646 */ - break; - - case 65: -#line 495 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_NET; } -#line 2471 "grammar.c" /* yacc.c:1646 */ - break; - - case 66: -#line 496 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_PORT; } -#line 2477 "grammar.c" /* yacc.c:1646 */ - break; - - case 67: -#line 497 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_PORTRANGE; } -#line 2483 "grammar.c" /* yacc.c:1646 */ - break; - - case 68: -#line 500 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_GATEWAY; } -#line 2489 "grammar.c" /* yacc.c:1646 */ - break; - - case 69: -#line 502 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_LINK; } -#line 2495 "grammar.c" /* yacc.c:1646 */ - break; - - case 70: -#line 503 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_IP; } -#line 2501 "grammar.c" /* yacc.c:1646 */ - break; - - case 71: -#line 504 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ARP; } -#line 2507 "grammar.c" /* yacc.c:1646 */ - break; - - case 72: -#line 505 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_RARP; } -#line 2513 "grammar.c" /* yacc.c:1646 */ - break; - - case 73: -#line 506 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_SCTP; } -#line 2519 "grammar.c" /* yacc.c:1646 */ - break; - - case 74: -#line 507 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_TCP; } -#line 2525 "grammar.c" /* yacc.c:1646 */ - break; - - case 75: -#line 508 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_UDP; } -#line 2531 "grammar.c" /* yacc.c:1646 */ - break; - - case 76: -#line 509 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ICMP; } -#line 2537 "grammar.c" /* yacc.c:1646 */ - break; - - case 77: -#line 510 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_IGMP; } -#line 2543 "grammar.c" /* yacc.c:1646 */ - break; - - case 78: -#line 511 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_IGRP; } -#line 2549 "grammar.c" /* yacc.c:1646 */ - break; - - case 79: -#line 512 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_PIM; } -#line 2555 "grammar.c" /* yacc.c:1646 */ - break; - - case 80: -#line 513 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_VRRP; } -#line 2561 "grammar.c" /* yacc.c:1646 */ - break; - - case 81: -#line 514 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_CARP; } -#line 2567 "grammar.c" /* yacc.c:1646 */ - break; - - case 82: -#line 515 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ATALK; } -#line 2573 "grammar.c" /* yacc.c:1646 */ - break; - - case 83: -#line 516 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_AARP; } -#line 2579 "grammar.c" /* yacc.c:1646 */ - break; - - case 84: -#line 517 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_DECNET; } -#line 2585 "grammar.c" /* yacc.c:1646 */ - break; - - case 85: -#line 518 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_LAT; } -#line 2591 "grammar.c" /* yacc.c:1646 */ - break; - - case 86: -#line 519 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_SCA; } -#line 2597 "grammar.c" /* yacc.c:1646 */ - break; - - case 87: -#line 520 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_MOPDL; } -#line 2603 "grammar.c" /* yacc.c:1646 */ - break; - - case 88: -#line 521 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_MOPRC; } -#line 2609 "grammar.c" /* yacc.c:1646 */ - break; - - case 89: -#line 522 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_IPV6; } -#line 2615 "grammar.c" /* yacc.c:1646 */ - break; - - case 90: -#line 523 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ICMPV6; } -#line 2621 "grammar.c" /* yacc.c:1646 */ - break; - - case 91: -#line 524 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_AH; } -#line 2627 "grammar.c" /* yacc.c:1646 */ - break; - - case 92: -#line 525 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ESP; } -#line 2633 "grammar.c" /* yacc.c:1646 */ - break; - - case 93: -#line 526 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISO; } -#line 2639 "grammar.c" /* yacc.c:1646 */ - break; - - case 94: -#line 527 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ESIS; } -#line 2645 "grammar.c" /* yacc.c:1646 */ - break; - - case 95: -#line 528 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS; } -#line 2651 "grammar.c" /* yacc.c:1646 */ - break; - - case 96: -#line 529 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_L1; } -#line 2657 "grammar.c" /* yacc.c:1646 */ - break; - - case 97: -#line 530 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_L2; } -#line 2663 "grammar.c" /* yacc.c:1646 */ - break; - - case 98: -#line 531 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_IIH; } -#line 2669 "grammar.c" /* yacc.c:1646 */ - break; - - case 99: -#line 532 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_LSP; } -#line 2675 "grammar.c" /* yacc.c:1646 */ - break; - - case 100: -#line 533 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_SNP; } -#line 2681 "grammar.c" /* yacc.c:1646 */ - break; - - case 101: -#line 534 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_PSNP; } -#line 2687 "grammar.c" /* yacc.c:1646 */ - break; - - case 102: -#line 535 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_ISIS_CSNP; } -#line 2693 "grammar.c" /* yacc.c:1646 */ - break; - - case 103: -#line 536 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_CLNP; } -#line 2699 "grammar.c" /* yacc.c:1646 */ - break; - - case 104: -#line 537 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_STP; } -#line 2705 "grammar.c" /* yacc.c:1646 */ - break; - - case 105: -#line 538 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_IPX; } -#line 2711 "grammar.c" /* yacc.c:1646 */ - break; - - case 106: -#line 539 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_NETBEUI; } -#line 2717 "grammar.c" /* yacc.c:1646 */ - break; - - case 107: -#line 540 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = Q_RADIO; } -#line 2723 "grammar.c" /* yacc.c:1646 */ - break; - - case 108: -#line 542 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_broadcast(cstate, (yyvsp[-1].i)); } -#line 2729 "grammar.c" /* yacc.c:1646 */ - break; - - case 109: -#line 543 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_multicast(cstate, (yyvsp[-1].i)); } -#line 2735 "grammar.c" /* yacc.c:1646 */ - break; - - case 110: -#line 544 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_less(cstate, (yyvsp[0].i)); } -#line 2741 "grammar.c" /* yacc.c:1646 */ - break; - - case 111: -#line 545 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_greater(cstate, (yyvsp[0].i)); } -#line 2747 "grammar.c" /* yacc.c:1646 */ - break; - - case 112: -#line 546 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_byteop(cstate, (yyvsp[-1].i), (yyvsp[-2].i), (yyvsp[0].i)); } -#line 2753 "grammar.c" /* yacc.c:1646 */ - break; - - case 113: -#line 547 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_inbound(cstate, 0); } -#line 2759 "grammar.c" /* yacc.c:1646 */ - break; - - case 114: -#line 548 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_inbound(cstate, 1); } -#line 2765 "grammar.c" /* yacc.c:1646 */ - break; - - case 115: -#line 549 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_vlan(cstate, (yyvsp[0].i)); } -#line 2771 "grammar.c" /* yacc.c:1646 */ - break; - - case 116: -#line 550 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_vlan(cstate, -1); } -#line 2777 "grammar.c" /* yacc.c:1646 */ - break; - - case 117: -#line 551 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_mpls(cstate, (yyvsp[0].i)); } -#line 2783 "grammar.c" /* yacc.c:1646 */ - break; - - case 118: -#line 552 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_mpls(cstate, -1); } -#line 2789 "grammar.c" /* yacc.c:1646 */ - break; - - case 119: -#line 553 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pppoed(cstate); } -#line 2795 "grammar.c" /* yacc.c:1646 */ - break; - - case 120: -#line 554 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pppoes(cstate, (yyvsp[0].i)); } -#line 2801 "grammar.c" /* yacc.c:1646 */ - break; - - case 121: -#line 555 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pppoes(cstate, -1); } -#line 2807 "grammar.c" /* yacc.c:1646 */ - break; - - case 122: -#line 556 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_geneve(cstate, (yyvsp[0].i)); } -#line 2813 "grammar.c" /* yacc.c:1646 */ - break; - - case 123: -#line 557 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_geneve(cstate, -1); } -#line 2819 "grammar.c" /* yacc.c:1646 */ - break; - - case 124: -#line 558 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = (yyvsp[0].rblk); } -#line 2825 "grammar.c" /* yacc.c:1646 */ - break; - - case 125: -#line 559 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = (yyvsp[0].rblk); } -#line 2831 "grammar.c" /* yacc.c:1646 */ - break; - - case 126: -#line 560 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = (yyvsp[0].rblk); } -#line 2837 "grammar.c" /* yacc.c:1646 */ - break; - - case 127: -#line 563 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_ifname(cstate, (yyvsp[0].s)); } -#line 2843 "grammar.c" /* yacc.c:1646 */ - break; - - case 128: -#line 564 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_ruleset(cstate, (yyvsp[0].s)); } -#line 2849 "grammar.c" /* yacc.c:1646 */ - break; - - case 129: -#line 565 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_rnr(cstate, (yyvsp[0].i)); } -#line 2855 "grammar.c" /* yacc.c:1646 */ - break; - - case 130: -#line 566 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_srnr(cstate, (yyvsp[0].i)); } -#line 2861 "grammar.c" /* yacc.c:1646 */ - break; - - case 131: -#line 567 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_reason(cstate, (yyvsp[0].i)); } -#line 2867 "grammar.c" /* yacc.c:1646 */ - break; - - case 132: -#line 568 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_pf_action(cstate, (yyvsp[0].i)); } -#line 2873 "grammar.c" /* yacc.c:1646 */ - break; - - case 133: -#line 572 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_p80211_type(cstate, (yyvsp[-2].i) | (yyvsp[0].i), - IEEE80211_FC0_TYPE_MASK | - IEEE80211_FC0_SUBTYPE_MASK); - } -#line 2882 "grammar.c" /* yacc.c:1646 */ - break; - - case 134: -#line 576 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_p80211_type(cstate, (yyvsp[0].i), - IEEE80211_FC0_TYPE_MASK); - } -#line 2890 "grammar.c" /* yacc.c:1646 */ - break; - - case 135: -#line 579 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_p80211_type(cstate, (yyvsp[0].i), - IEEE80211_FC0_TYPE_MASK | - IEEE80211_FC0_SUBTYPE_MASK); - } -#line 2899 "grammar.c" /* yacc.c:1646 */ - break; - - case 136: -#line 583 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_p80211_fcdir(cstate, (yyvsp[0].i)); } -#line 2905 "grammar.c" /* yacc.c:1646 */ - break; - - case 138: -#line 587 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = str2tok((yyvsp[0].s), ieee80211_types); - if ((yyval.i) == -1) - bpf_error(cstate, "unknown 802.11 type name"); - } -#line 2914 "grammar.c" /* yacc.c:1646 */ - break; - - case 140: -#line 594 "grammar.y" /* yacc.c:1646 */ - { const struct tok *types = NULL; - int i; - for (i = 0;; i++) { - if (ieee80211_type_subtypes[i].tok == NULL) { - /* Ran out of types */ - bpf_error(cstate, "unknown 802.11 type"); - break; - } - if ((yyvsp[(-1) - (1)].i) == ieee80211_type_subtypes[i].type) { - types = ieee80211_type_subtypes[i].tok; - break; - } - } - - (yyval.i) = str2tok((yyvsp[0].s), types); - if ((yyval.i) == -1) - bpf_error(cstate, "unknown 802.11 subtype name"); - } -#line 2937 "grammar.c" /* yacc.c:1646 */ - break; - - case 141: -#line 614 "grammar.y" /* yacc.c:1646 */ - { int i; - for (i = 0;; i++) { - if (ieee80211_type_subtypes[i].tok == NULL) { - /* Ran out of types */ - bpf_error(cstate, "unknown 802.11 type name"); - break; - } - (yyval.i) = str2tok((yyvsp[0].s), ieee80211_type_subtypes[i].tok); - if ((yyval.i) != -1) { - (yyval.i) |= ieee80211_type_subtypes[i].type; - break; - } - } - } -#line 2956 "grammar.c" /* yacc.c:1646 */ - break; - - case 142: -#line 630 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_llc(cstate); } -#line 2962 "grammar.c" /* yacc.c:1646 */ - break; - - case 143: -#line 631 "grammar.y" /* yacc.c:1646 */ - { if (pcap_strcasecmp((yyvsp[0].s), "i") == 0) - (yyval.rblk) = gen_llc_i(cstate); - else if (pcap_strcasecmp((yyvsp[0].s), "s") == 0) - (yyval.rblk) = gen_llc_s(cstate); - else if (pcap_strcasecmp((yyvsp[0].s), "u") == 0) - (yyval.rblk) = gen_llc_u(cstate); - else { - int subtype; - - subtype = str2tok((yyvsp[0].s), llc_s_subtypes); - if (subtype != -1) - (yyval.rblk) = gen_llc_s_subtype(cstate, subtype); - else { - subtype = str2tok((yyvsp[0].s), llc_u_subtypes); - if (subtype == -1) - bpf_error(cstate, "unknown LLC type name \"%s\"", (yyvsp[0].s)); - (yyval.rblk) = gen_llc_u_subtype(cstate, subtype); - } - } - } -#line 2987 "grammar.c" /* yacc.c:1646 */ - break; - - case 144: -#line 652 "grammar.y" /* yacc.c:1646 */ - { (yyval.rblk) = gen_llc_s_subtype(cstate, LLC_RNR); } -#line 2993 "grammar.c" /* yacc.c:1646 */ - break; - - case 146: -#line 656 "grammar.y" /* yacc.c:1646 */ - { if (pcap_strcasecmp((yyvsp[0].s), "nods") == 0) - (yyval.i) = IEEE80211_FC1_DIR_NODS; - else if (pcap_strcasecmp((yyvsp[0].s), "tods") == 0) - (yyval.i) = IEEE80211_FC1_DIR_TODS; - else if (pcap_strcasecmp((yyvsp[0].s), "fromds") == 0) - (yyval.i) = IEEE80211_FC1_DIR_FROMDS; - else if (pcap_strcasecmp((yyvsp[0].s), "dstods") == 0) - (yyval.i) = IEEE80211_FC1_DIR_DSTODS; - else - bpf_error(cstate, "unknown 802.11 direction"); - } -#line 3009 "grammar.c" /* yacc.c:1646 */ - break; - - case 147: -#line 669 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = (yyvsp[0].i); } -#line 3015 "grammar.c" /* yacc.c:1646 */ - break; - - case 148: -#line 670 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = pfreason_to_num(cstate, (yyvsp[0].s)); } -#line 3021 "grammar.c" /* yacc.c:1646 */ - break; - - case 149: -#line 673 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = pfaction_to_num(cstate, (yyvsp[0].s)); } -#line 3027 "grammar.c" /* yacc.c:1646 */ - break; - - case 150: -#line 676 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JGT; } -#line 3033 "grammar.c" /* yacc.c:1646 */ - break; - - case 151: -#line 677 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JGE; } -#line 3039 "grammar.c" /* yacc.c:1646 */ - break; - - case 152: -#line 678 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JEQ; } -#line 3045 "grammar.c" /* yacc.c:1646 */ - break; - - case 153: -#line 680 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JGT; } -#line 3051 "grammar.c" /* yacc.c:1646 */ - break; - - case 154: -#line 681 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JGE; } -#line 3057 "grammar.c" /* yacc.c:1646 */ - break; - - case 155: -#line 682 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = BPF_JEQ; } -#line 3063 "grammar.c" /* yacc.c:1646 */ - break; - - case 156: -#line 684 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_loadi(cstate, (yyvsp[0].i)); } -#line 3069 "grammar.c" /* yacc.c:1646 */ - break; - - case 158: -#line 687 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_load(cstate, (yyvsp[-3].i), (yyvsp[-1].a), 1); } -#line 3075 "grammar.c" /* yacc.c:1646 */ - break; - - case 159: -#line 688 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_load(cstate, (yyvsp[-5].i), (yyvsp[-3].a), (yyvsp[-1].i)); } -#line 3081 "grammar.c" /* yacc.c:1646 */ - break; - - case 160: -#line 689 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_ADD, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3087 "grammar.c" /* yacc.c:1646 */ - break; - - case 161: -#line 690 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_SUB, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3093 "grammar.c" /* yacc.c:1646 */ - break; - - case 162: -#line 691 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_MUL, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3099 "grammar.c" /* yacc.c:1646 */ - break; - - case 163: -#line 692 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_DIV, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3105 "grammar.c" /* yacc.c:1646 */ - break; - - case 164: -#line 693 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_MOD, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3111 "grammar.c" /* yacc.c:1646 */ - break; - - case 165: -#line 694 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_AND, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3117 "grammar.c" /* yacc.c:1646 */ - break; - - case 166: -#line 695 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_OR, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3123 "grammar.c" /* yacc.c:1646 */ - break; - - case 167: -#line 696 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_XOR, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3129 "grammar.c" /* yacc.c:1646 */ - break; - - case 168: -#line 697 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_LSH, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3135 "grammar.c" /* yacc.c:1646 */ - break; - - case 169: -#line 698 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_arth(cstate, BPF_RSH, (yyvsp[-2].a), (yyvsp[0].a)); } -#line 3141 "grammar.c" /* yacc.c:1646 */ - break; - - case 170: -#line 699 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_neg(cstate, (yyvsp[0].a)); } -#line 3147 "grammar.c" /* yacc.c:1646 */ - break; - - case 171: -#line 700 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = (yyvsp[-1].a); } -#line 3153 "grammar.c" /* yacc.c:1646 */ - break; - - case 172: -#line 701 "grammar.y" /* yacc.c:1646 */ - { (yyval.a) = gen_loadlen(cstate); } -#line 3159 "grammar.c" /* yacc.c:1646 */ - break; - - case 173: -#line 703 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = '&'; } -#line 3165 "grammar.c" /* yacc.c:1646 */ - break; - - case 174: -#line 704 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = '|'; } -#line 3171 "grammar.c" /* yacc.c:1646 */ - break; - - case 175: -#line 705 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = '<'; } -#line 3177 "grammar.c" /* yacc.c:1646 */ - break; - - case 176: -#line 706 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = '>'; } -#line 3183 "grammar.c" /* yacc.c:1646 */ - break; - - case 177: -#line 707 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = '='; } -#line 3189 "grammar.c" /* yacc.c:1646 */ - break; - - case 179: -#line 710 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = (yyvsp[-1].i); } -#line 3195 "grammar.c" /* yacc.c:1646 */ - break; - - case 180: -#line 712 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_LANE; } -#line 3201 "grammar.c" /* yacc.c:1646 */ - break; - - case 181: -#line 713 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_METAC; } -#line 3207 "grammar.c" /* yacc.c:1646 */ - break; - - case 182: -#line 714 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_BCC; } -#line 3213 "grammar.c" /* yacc.c:1646 */ - break; - - case 183: -#line 715 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_OAMF4EC; } -#line 3219 "grammar.c" /* yacc.c:1646 */ - break; - - case 184: -#line 716 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_OAMF4SC; } -#line 3225 "grammar.c" /* yacc.c:1646 */ - break; - - case 185: -#line 717 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_SC; } -#line 3231 "grammar.c" /* yacc.c:1646 */ - break; - - case 186: -#line 718 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_ILMIC; } -#line 3237 "grammar.c" /* yacc.c:1646 */ - break; - - case 187: -#line 720 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_OAM; } -#line 3243 "grammar.c" /* yacc.c:1646 */ - break; - - case 188: -#line 721 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_OAMF4; } -#line 3249 "grammar.c" /* yacc.c:1646 */ - break; - - case 189: -#line 722 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_CONNECTMSG; } -#line 3255 "grammar.c" /* yacc.c:1646 */ - break; - - case 190: -#line 723 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = A_METACONNECT; } -#line 3261 "grammar.c" /* yacc.c:1646 */ - break; - - case 191: -#line 726 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).atmfieldtype = A_VPI; } -#line 3267 "grammar.c" /* yacc.c:1646 */ - break; - - case 192: -#line 727 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).atmfieldtype = A_VCI; } -#line 3273 "grammar.c" /* yacc.c:1646 */ - break; - - case 194: -#line 730 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_atmfield_code(cstate, (yyvsp[-2].blk).atmfieldtype, (bpf_int32)(yyvsp[0].i), (bpf_u_int32)(yyvsp[-1].i), 0); } -#line 3279 "grammar.c" /* yacc.c:1646 */ - break; - - case 195: -#line 731 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_atmfield_code(cstate, (yyvsp[-2].blk).atmfieldtype, (bpf_int32)(yyvsp[0].i), (bpf_u_int32)(yyvsp[-1].i), 1); } -#line 3285 "grammar.c" /* yacc.c:1646 */ - break; - - case 196: -#line 732 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[-1].blk).b; (yyval.blk).q = qerr; } -#line 3291 "grammar.c" /* yacc.c:1646 */ - break; - - case 197: -#line 734 "grammar.y" /* yacc.c:1646 */ - { - (yyval.blk).atmfieldtype = (yyvsp[-1].blk).atmfieldtype; - if ((yyval.blk).atmfieldtype == A_VPI || - (yyval.blk).atmfieldtype == A_VCI) - (yyval.blk).b = gen_atmfield_code(cstate, (yyval.blk).atmfieldtype, (bpf_int32) (yyvsp[0].i), BPF_JEQ, 0); - } -#line 3302 "grammar.c" /* yacc.c:1646 */ - break; - - case 199: -#line 742 "grammar.y" /* yacc.c:1646 */ - { gen_or((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 3308 "grammar.c" /* yacc.c:1646 */ - break; - - case 200: -#line 745 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = M_FISU; } -#line 3314 "grammar.c" /* yacc.c:1646 */ - break; - - case 201: -#line 746 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = M_LSSU; } -#line 3320 "grammar.c" /* yacc.c:1646 */ - break; - - case 202: -#line 747 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = M_MSU; } -#line 3326 "grammar.c" /* yacc.c:1646 */ - break; - - case 203: -#line 748 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = MH_FISU; } -#line 3332 "grammar.c" /* yacc.c:1646 */ - break; - - case 204: -#line 749 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = MH_LSSU; } -#line 3338 "grammar.c" /* yacc.c:1646 */ - break; - - case 205: -#line 750 "grammar.y" /* yacc.c:1646 */ - { (yyval.i) = MH_MSU; } -#line 3344 "grammar.c" /* yacc.c:1646 */ - break; - - case 206: -#line 753 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = M_SIO; } -#line 3350 "grammar.c" /* yacc.c:1646 */ - break; - - case 207: -#line 754 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = M_OPC; } -#line 3356 "grammar.c" /* yacc.c:1646 */ - break; - - case 208: -#line 755 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = M_DPC; } -#line 3362 "grammar.c" /* yacc.c:1646 */ - break; - - case 209: -#line 756 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = M_SLS; } -#line 3368 "grammar.c" /* yacc.c:1646 */ - break; - - case 210: -#line 757 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = MH_SIO; } -#line 3374 "grammar.c" /* yacc.c:1646 */ - break; - - case 211: -#line 758 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = MH_OPC; } -#line 3380 "grammar.c" /* yacc.c:1646 */ - break; - - case 212: -#line 759 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = MH_DPC; } -#line 3386 "grammar.c" /* yacc.c:1646 */ - break; - - case 213: -#line 760 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).mtp3fieldtype = MH_SLS; } -#line 3392 "grammar.c" /* yacc.c:1646 */ - break; - - case 215: -#line 763 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_mtp3field_code(cstate, (yyvsp[-2].blk).mtp3fieldtype, (u_int)(yyvsp[0].i), (u_int)(yyvsp[-1].i), 0); } -#line 3398 "grammar.c" /* yacc.c:1646 */ - break; - - case 216: -#line 764 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = gen_mtp3field_code(cstate, (yyvsp[-2].blk).mtp3fieldtype, (u_int)(yyvsp[0].i), (u_int)(yyvsp[-1].i), 1); } -#line 3404 "grammar.c" /* yacc.c:1646 */ - break; - - case 217: -#line 765 "grammar.y" /* yacc.c:1646 */ - { (yyval.blk).b = (yyvsp[-1].blk).b; (yyval.blk).q = qerr; } -#line 3410 "grammar.c" /* yacc.c:1646 */ - break; - - case 218: -#line 767 "grammar.y" /* yacc.c:1646 */ - { - (yyval.blk).mtp3fieldtype = (yyvsp[-1].blk).mtp3fieldtype; - if ((yyval.blk).mtp3fieldtype == M_SIO || - (yyval.blk).mtp3fieldtype == M_OPC || - (yyval.blk).mtp3fieldtype == M_DPC || - (yyval.blk).mtp3fieldtype == M_SLS || - (yyval.blk).mtp3fieldtype == MH_SIO || - (yyval.blk).mtp3fieldtype == MH_OPC || - (yyval.blk).mtp3fieldtype == MH_DPC || - (yyval.blk).mtp3fieldtype == MH_SLS) - (yyval.blk).b = gen_mtp3field_code(cstate, (yyval.blk).mtp3fieldtype, (u_int) (yyvsp[0].i), BPF_JEQ, 0); - } -#line 3427 "grammar.c" /* yacc.c:1646 */ - break; - - case 220: -#line 781 "grammar.y" /* yacc.c:1646 */ - { gen_or((yyvsp[-2].blk).b, (yyvsp[0].blk).b); (yyval.blk) = (yyvsp[0].blk); } -#line 3433 "grammar.c" /* yacc.c:1646 */ - break; - - -#line 3437 "grammar.c" /* yacc.c:1646 */ - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now 'shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*--------------------------------------. -| yyerrlab -- here on detecting error. | -`--------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (yyscanner, cstate, YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yyscanner, cstate, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval, yyscanner, cstate); - yychar = YYEMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - yystos[yystate], yyvsp, yyscanner, cstate); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (yyscanner, cstate, YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, yyscanner, cstate); - } - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yyscanner, cstate); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - return yyresult; -} -#line 783 "grammar.y" /* yacc.c:1906 */ - diff --git a/libpcap/grammar.h b/libpcap/grammar.h deleted file mode 100644 index 286cc7982..000000000 --- a/libpcap/grammar.h +++ /dev/null @@ -1,323 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ - -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -#ifndef YY_PCAP_GRAMMAR_H_INCLUDED -# define YY_PCAP_GRAMMAR_H_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG -extern int pcap_debug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - DST = 258, - SRC = 259, - HOST = 260, - GATEWAY = 261, - NET = 262, - NETMASK = 263, - PORT = 264, - PORTRANGE = 265, - LESS = 266, - GREATER = 267, - PROTO = 268, - PROTOCHAIN = 269, - CBYTE = 270, - ARP = 271, - RARP = 272, - IP = 273, - SCTP = 274, - TCP = 275, - UDP = 276, - ICMP = 277, - IGMP = 278, - IGRP = 279, - PIM = 280, - VRRP = 281, - CARP = 282, - ATALK = 283, - AARP = 284, - DECNET = 285, - LAT = 286, - SCA = 287, - MOPRC = 288, - MOPDL = 289, - TK_BROADCAST = 290, - TK_MULTICAST = 291, - NUM = 292, - INBOUND = 293, - OUTBOUND = 294, - PF_IFNAME = 295, - PF_RSET = 296, - PF_RNR = 297, - PF_SRNR = 298, - PF_REASON = 299, - PF_ACTION = 300, - TYPE = 301, - SUBTYPE = 302, - DIR = 303, - ADDR1 = 304, - ADDR2 = 305, - ADDR3 = 306, - ADDR4 = 307, - RA = 308, - TA = 309, - LINK = 310, - GEQ = 311, - LEQ = 312, - NEQ = 313, - ID = 314, - EID = 315, - HID = 316, - HID6 = 317, - AID = 318, - LSH = 319, - RSH = 320, - LEN = 321, - IPV6 = 322, - ICMPV6 = 323, - AH = 324, - ESP = 325, - VLAN = 326, - MPLS = 327, - PPPOED = 328, - PPPOES = 329, - GENEVE = 330, - ISO = 331, - ESIS = 332, - CLNP = 333, - ISIS = 334, - L1 = 335, - L2 = 336, - IIH = 337, - LSP = 338, - SNP = 339, - CSNP = 340, - PSNP = 341, - STP = 342, - IPX = 343, - NETBEUI = 344, - LANE = 345, - LLC = 346, - METAC = 347, - BCC = 348, - SC = 349, - ILMIC = 350, - OAMF4EC = 351, - OAMF4SC = 352, - OAM = 353, - OAMF4 = 354, - CONNECTMSG = 355, - METACONNECT = 356, - VPI = 357, - VCI = 358, - RADIO = 359, - FISU = 360, - LSSU = 361, - MSU = 362, - HFISU = 363, - HLSSU = 364, - HMSU = 365, - SIO = 366, - OPC = 367, - DPC = 368, - SLS = 369, - HSIO = 370, - HOPC = 371, - HDPC = 372, - HSLS = 373, - OR = 374, - AND = 375, - UMINUS = 376 - }; -#endif -/* Tokens. */ -#define DST 258 -#define SRC 259 -#define HOST 260 -#define GATEWAY 261 -#define NET 262 -#define NETMASK 263 -#define PORT 264 -#define PORTRANGE 265 -#define LESS 266 -#define GREATER 267 -#define PROTO 268 -#define PROTOCHAIN 269 -#define CBYTE 270 -#define ARP 271 -#define RARP 272 -#define IP 273 -#define SCTP 274 -#define TCP 275 -#define UDP 276 -#define ICMP 277 -#define IGMP 278 -#define IGRP 279 -#define PIM 280 -#define VRRP 281 -#define CARP 282 -#define ATALK 283 -#define AARP 284 -#define DECNET 285 -#define LAT 286 -#define SCA 287 -#define MOPRC 288 -#define MOPDL 289 -#define TK_BROADCAST 290 -#define TK_MULTICAST 291 -#define NUM 292 -#define INBOUND 293 -#define OUTBOUND 294 -#define PF_IFNAME 295 -#define PF_RSET 296 -#define PF_RNR 297 -#define PF_SRNR 298 -#define PF_REASON 299 -#define PF_ACTION 300 -#define TYPE 301 -#define SUBTYPE 302 -#define DIR 303 -#define ADDR1 304 -#define ADDR2 305 -#define ADDR3 306 -#define ADDR4 307 -#define RA 308 -#define TA 309 -#define LINK 310 -#define GEQ 311 -#define LEQ 312 -#define NEQ 313 -#define ID 314 -#define EID 315 -#define HID 316 -#define HID6 317 -#define AID 318 -#define LSH 319 -#define RSH 320 -#define LEN 321 -#define IPV6 322 -#define ICMPV6 323 -#define AH 324 -#define ESP 325 -#define VLAN 326 -#define MPLS 327 -#define PPPOED 328 -#define PPPOES 329 -#define GENEVE 330 -#define ISO 331 -#define ESIS 332 -#define CLNP 333 -#define ISIS 334 -#define L1 335 -#define L2 336 -#define IIH 337 -#define LSP 338 -#define SNP 339 -#define CSNP 340 -#define PSNP 341 -#define STP 342 -#define IPX 343 -#define NETBEUI 344 -#define LANE 345 -#define LLC 346 -#define METAC 347 -#define BCC 348 -#define SC 349 -#define ILMIC 350 -#define OAMF4EC 351 -#define OAMF4SC 352 -#define OAM 353 -#define OAMF4 354 -#define CONNECTMSG 355 -#define METACONNECT 356 -#define VPI 357 -#define VCI 358 -#define RADIO 359 -#define FISU 360 -#define LSSU 361 -#define MSU 362 -#define HFISU 363 -#define HLSSU 364 -#define HMSU 365 -#define SIO 366 -#define OPC 367 -#define DPC 368 -#define SLS 369 -#define HSIO 370 -#define HOPC 371 -#define HDPC 372 -#define HSLS 373 -#define OR 374 -#define AND 375 -#define UMINUS 376 - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - -union YYSTYPE -{ -#line 286 "grammar.y" /* yacc.c:1909 */ - - int i; - bpf_u_int32 h; - u_char *e; - char *s; - struct stmt *stmt; - struct arth *a; - struct { - struct qual q; - int atmfieldtype; - int mtp3fieldtype; - struct block *b; - } blk; - struct block *rblk; - -#line 312 "grammar.h" /* yacc.c:1909 */ -}; - -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - - -int pcap_parse (void *yyscanner, compiler_state_t *cstate); - -#endif /* !YY_PCAP_GRAMMAR_H_INCLUDED */ diff --git a/libpcap/grammar.y b/libpcap/grammar.y index be80e2bfc..32cb19c11 100644 --- a/libpcap/grammar.y +++ b/libpcap/grammar.y @@ -216,13 +216,12 @@ str2tok(const char *str, const struct tok *toks) return (-1); } -static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; +static const struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; -static PCAP_NORETURN_DEF void +static void yyerror(void *yyscanner _U_, compiler_state_t *cstate, const char *msg) { - bpf_syntax_error(cstate, msg); - /* NOTREACHED */ + bpf_set_error(cstate, "can't parse filter expression: %s", msg); } #ifdef HAVE_NET_PFVAR_H @@ -236,8 +235,8 @@ pfreason_to_num(compiler_state_t *cstate, const char *reason) if (pcap_strcasecmp(reason, reasons[i]) == 0) return (i); } - bpf_error(cstate, "unknown PF reason"); - /*NOTREACHED*/ + bpf_set_error(cstate, "unknown PF reason"); + return (-1); } static int @@ -260,33 +259,38 @@ pfaction_to_num(compiler_state_t *cstate, const char *action) return (PF_NORDR); #endif else { - bpf_error(cstate, "unknown PF action"); - /*NOTREACHED*/ + bpf_set_error(cstate, "unknown PF action"); + return (-1); } } #else /* !HAVE_NET_PFVAR_H */ -static PCAP_NORETURN_DEF int +static int pfreason_to_num(compiler_state_t *cstate, const char *reason _U_) { - bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ + bpf_set_error(cstate, "libpcap was compiled on a machine without pf support"); + return (-1); } -static PCAP_NORETURN_DEF int +static int pfaction_to_num(compiler_state_t *cstate, const char *action _U_) { - bpf_error(cstate, "libpcap was compiled on a machine without pf support"); - /*NOTREACHED*/ + bpf_set_error(cstate, "libpcap was compiled on a machine without pf support"); + return (-1); } #endif /* HAVE_NET_PFVAR_H */ +/* + * For calls that might return an "an error occurred" value. + */ +#define CHECK_INT_VAL(val) if (val == -1) YYABORT +#define CHECK_PTR_VAL(val) if (val == NULL) YYABORT + DIAG_OFF_BISON_BYACC %} %union { int i; bpf_u_int32 h; - u_char *e; char *s; struct stmt *stmt; struct arth *a; @@ -340,11 +344,9 @@ DIAG_OFF_BISON_BYACC %token RADIO %token FISU LSSU MSU HFISU HLSSU HMSU %token SIO OPC DPC SLS HSIO HOPC HDPC HSLS +%token LEX_ERROR - -%type ID -%type EID -%type AID +%type ID EID AID %type HID HID6 %type NUM action reason type subtype type_subtype dir @@ -359,7 +361,7 @@ DIAG_OFF_BISON_BYACC %% prog: null expr { - finish_parse(cstate, $2.b); + CHECK_INT_VAL(finish_parse(cstate, $2.b)); } | null ; @@ -376,64 +378,58 @@ and: AND { $$ = $0; } or: OR { $$ = $0; } ; id: nid - | pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1, - $$.q = $0.q); } + | pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1, + $$.q = $0.q))); } | paren pid ')' { $$ = $2; } ; -nid: ID { $$.b = gen_scode(cstate, $1, $$.q = $0.q); } - | HID '/' NUM { $$.b = gen_mcode(cstate, $1, NULL, $3, - $$.q = $0.q); } - | HID NETMASK HID { $$.b = gen_mcode(cstate, $1, $3, 0, - $$.q = $0.q); } +nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $0.q))); } + | HID '/' NUM { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3, + $$.q = $0.q))); } + | HID NETMASK HID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0, + $$.q = $0.q))); } | HID { + CHECK_PTR_VAL($1); /* Decide how to parse HID based on proto */ $$.q = $0.q; - if ($$.q.addr == Q_PORT) - bpf_error(cstate, "'port' modifier applied to ip host"); - else if ($$.q.addr == Q_PORTRANGE) - bpf_error(cstate, "'portrange' modifier applied to ip host"); - else if ($$.q.addr == Q_PROTO) - bpf_error(cstate, "'proto' modifier applied to ip host"); - else if ($$.q.addr == Q_PROTOCHAIN) - bpf_error(cstate, "'protochain' modifier applied to ip host"); - $$.b = gen_ncode(cstate, $1, 0, $$.q); + if ($$.q.addr == Q_PORT) { + bpf_set_error(cstate, "'port' modifier applied to ip host"); + YYABORT; + } else if ($$.q.addr == Q_PORTRANGE) { + bpf_set_error(cstate, "'portrange' modifier applied to ip host"); + YYABORT; + } else if ($$.q.addr == Q_PROTO) { + bpf_set_error(cstate, "'proto' modifier applied to ip host"); + YYABORT; + } else if ($$.q.addr == Q_PROTOCHAIN) { + bpf_set_error(cstate, "'protochain' modifier applied to ip host"); + YYABORT; + } + CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q))); } | HID6 '/' NUM { + CHECK_PTR_VAL($1); #ifdef INET6 - $$.b = gen_mcode6(cstate, $1, NULL, $3, - $$.q = $0.q); + CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3, + $$.q = $0.q))); #else - bpf_error(cstate, "'ip6addr/prefixlen' not supported " + bpf_set_error(cstate, "'ip6addr/prefixlen' not supported " "in this configuration"); + YYABORT; #endif /*INET6*/ } | HID6 { + CHECK_PTR_VAL($1); #ifdef INET6 - $$.b = gen_mcode6(cstate, $1, 0, 128, - $$.q = $0.q); + CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128, + $$.q = $0.q))); #else - bpf_error(cstate, "'ip6addr' not supported " + bpf_set_error(cstate, "'ip6addr' not supported " "in this configuration"); + YYABORT; #endif /*INET6*/ } - | EID { - $$.b = gen_ecode(cstate, $1, $$.q = $0.q); - /* - * $1 was allocated by "pcap_ether_aton()", - * so we must free it now that we're done - * with it. - */ - free($1); - } - | AID { - $$.b = gen_acode(cstate, $1, $$.q = $0.q); - /* - * $1 was allocated by "pcap_ether_aton()", - * so we must free it now that we're done - * with it. - */ - free($1); - } + | EID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_ecode(cstate, $1, $$.q = $0.q))); } + | AID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_acode(cstate, $1, $$.q = $0.q))); } | not id { gen_not($2.b); $$ = $2; } ; not: '!' { $$ = $0; } @@ -444,8 +440,8 @@ pid: nid | qid and id { gen_and($1.b, $3.b); $$ = $3; } | qid or id { gen_or($1.b, $3.b); $$ = $3; } ; -qid: pnum { $$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1, - $$.q = $0.q); } +qid: pnum { CHECK_PTR_VAL(($$.b = gen_ncode(cstate, NULL, (bpf_u_int32)$1, + $$.q = $0.q))); } | pid ; term: rterm @@ -455,21 +451,28 @@ head: pqual dqual aqual { QSET($$.q, $1, $2, $3); } | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); } | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); } | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); } - | pqual PROTOCHAIN { QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); } + | pqual PROTOCHAIN { +#ifdef NO_PROTOCHAIN + bpf_set_error(cstate, "protochain not supported"); + YYABORT; +#else + QSET($$.q, $1, Q_DEFAULT, Q_PROTOCHAIN); +#endif + } | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); } ; rterm: head id { $$ = $2; } | paren expr ')' { $$.b = $2.b; $$.q = $1.q; } - | pname { $$.b = gen_proto_abbrev(cstate, $1); $$.q = qerr; } - | arth relop arth { $$.b = gen_relation(cstate, $2, $1, $3, 0); + | pname { CHECK_PTR_VAL(($$.b = gen_proto_abbrev(cstate, $1))); $$.q = qerr; } + | arth relop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 0))); $$.q = qerr; } - | arth irelop arth { $$.b = gen_relation(cstate, $2, $1, $3, 1); + | arth irelop arth { CHECK_PTR_VAL(($$.b = gen_relation(cstate, $2, $1, $3, 1))); $$.q = qerr; } | other { $$.b = $1; $$.q = qerr; } - | atmtype { $$.b = gen_atmtype_abbrev(cstate, $1); $$.q = qerr; } - | atmmultitype { $$.b = gen_atmmulti_abbrev(cstate, $1); $$.q = qerr; } + | atmtype { CHECK_PTR_VAL(($$.b = gen_atmtype_abbrev(cstate, $1))); $$.q = qerr; } + | atmmultitype { CHECK_PTR_VAL(($$.b = gen_atmmulti_abbrev(cstate, $1))); $$.q = qerr; } | atmfield atmvalue { $$.b = $2.b; $$.q = qerr; } - | mtp2type { $$.b = gen_mtp2type_abbrev(cstate, $1); $$.q = qerr; } + | mtp2type { CHECK_PTR_VAL(($$.b = gen_mtp2type_abbrev(cstate, $1))); $$.q = qerr; } | mtp3field mtp3value { $$.b = $2.b; $$.q = qerr; } ; /* protocol level qualifiers */ @@ -539,65 +542,69 @@ pname: LINK { $$ = Q_LINK; } | NETBEUI { $$ = Q_NETBEUI; } | RADIO { $$ = Q_RADIO; } ; -other: pqual TK_BROADCAST { $$ = gen_broadcast(cstate, $1); } - | pqual TK_MULTICAST { $$ = gen_multicast(cstate, $1); } - | LESS NUM { $$ = gen_less(cstate, $2); } - | GREATER NUM { $$ = gen_greater(cstate, $2); } - | CBYTE NUM byteop NUM { $$ = gen_byteop(cstate, $3, $2, $4); } - | INBOUND { $$ = gen_inbound(cstate, 0); } - | OUTBOUND { $$ = gen_inbound(cstate, 1); } - | VLAN pnum { $$ = gen_vlan(cstate, $2); } - | VLAN { $$ = gen_vlan(cstate, -1); } - | MPLS pnum { $$ = gen_mpls(cstate, $2); } - | MPLS { $$ = gen_mpls(cstate, -1); } - | PPPOED { $$ = gen_pppoed(cstate); } - | PPPOES pnum { $$ = gen_pppoes(cstate, $2); } - | PPPOES { $$ = gen_pppoes(cstate, -1); } - | GENEVE pnum { $$ = gen_geneve(cstate, $2); } - | GENEVE { $$ = gen_geneve(cstate, -1); } +other: pqual TK_BROADCAST { CHECK_PTR_VAL(($$ = gen_broadcast(cstate, $1))); } + | pqual TK_MULTICAST { CHECK_PTR_VAL(($$ = gen_multicast(cstate, $1))); } + | LESS NUM { CHECK_PTR_VAL(($$ = gen_less(cstate, $2))); } + | GREATER NUM { CHECK_PTR_VAL(($$ = gen_greater(cstate, $2))); } + | CBYTE NUM byteop NUM { CHECK_PTR_VAL(($$ = gen_byteop(cstate, $3, $2, $4))); } + | INBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 0))); } + | OUTBOUND { CHECK_PTR_VAL(($$ = gen_inbound(cstate, 1))); } + | VLAN pnum { CHECK_PTR_VAL(($$ = gen_vlan(cstate, (bpf_u_int32)$2, 1))); } + | VLAN { CHECK_PTR_VAL(($$ = gen_vlan(cstate, 0, 0))); } + | MPLS pnum { CHECK_PTR_VAL(($$ = gen_mpls(cstate, (bpf_u_int32)$2, 1))); } + | MPLS { CHECK_PTR_VAL(($$ = gen_mpls(cstate, 0, 0))); } + | PPPOED { CHECK_PTR_VAL(($$ = gen_pppoed(cstate))); } + | PPPOES pnum { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, (bpf_u_int32)$2, 1))); } + | PPPOES { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); } + | GENEVE pnum { CHECK_PTR_VAL(($$ = gen_geneve(cstate, (bpf_u_int32)$2, 1))); } + | GENEVE { CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); } | pfvar { $$ = $1; } | pqual p80211 { $$ = $2; } | pllc { $$ = $1; } ; -pfvar: PF_IFNAME ID { $$ = gen_pf_ifname(cstate, $2); } - | PF_RSET ID { $$ = gen_pf_ruleset(cstate, $2); } - | PF_RNR NUM { $$ = gen_pf_rnr(cstate, $2); } - | PF_SRNR NUM { $$ = gen_pf_srnr(cstate, $2); } - | PF_REASON reason { $$ = gen_pf_reason(cstate, $2); } - | PF_ACTION action { $$ = gen_pf_action(cstate, $2); } +pfvar: PF_IFNAME ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); } + | PF_RSET ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); } + | PF_RNR NUM { CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); } + | PF_SRNR NUM { CHECK_PTR_VAL(($$ = gen_pf_srnr(cstate, $2))); } + | PF_REASON reason { CHECK_PTR_VAL(($$ = gen_pf_reason(cstate, $2))); } + | PF_ACTION action { CHECK_PTR_VAL(($$ = gen_pf_action(cstate, $2))); } ; p80211: TYPE type SUBTYPE subtype - { $$ = gen_p80211_type(cstate, $2 | $4, + { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2 | $4, IEEE80211_FC0_TYPE_MASK | - IEEE80211_FC0_SUBTYPE_MASK); + IEEE80211_FC0_SUBTYPE_MASK))); } - | TYPE type { $$ = gen_p80211_type(cstate, $2, - IEEE80211_FC0_TYPE_MASK); + | TYPE type { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2, + IEEE80211_FC0_TYPE_MASK))); } - | SUBTYPE type_subtype { $$ = gen_p80211_type(cstate, $2, + | SUBTYPE type_subtype { CHECK_PTR_VAL(($$ = gen_p80211_type(cstate, $2, IEEE80211_FC0_TYPE_MASK | - IEEE80211_FC0_SUBTYPE_MASK); + IEEE80211_FC0_SUBTYPE_MASK))); } - | DIR dir { $$ = gen_p80211_fcdir(cstate, $2); } + | DIR dir { CHECK_PTR_VAL(($$ = gen_p80211_fcdir(cstate, $2))); } ; type: NUM - | ID { $$ = str2tok($1, ieee80211_types); - if ($$ == -1) - bpf_error(cstate, "unknown 802.11 type name"); + | ID { CHECK_PTR_VAL($1); + $$ = str2tok($1, ieee80211_types); + if ($$ == -1) { + bpf_set_error(cstate, "unknown 802.11 type name"); + YYABORT; + } } ; subtype: NUM | ID { const struct tok *types = NULL; int i; + CHECK_PTR_VAL($1); for (i = 0;; i++) { if (ieee80211_type_subtypes[i].tok == NULL) { /* Ran out of types */ - bpf_error(cstate, "unknown 802.11 type"); - break; + bpf_set_error(cstate, "unknown 802.11 type"); + YYABORT; } if ($-1 == ieee80211_type_subtypes[i].type) { types = ieee80211_type_subtypes[i].tok; @@ -606,17 +613,20 @@ subtype: NUM } $$ = str2tok($1, types); - if ($$ == -1) - bpf_error(cstate, "unknown 802.11 subtype name"); + if ($$ == -1) { + bpf_set_error(cstate, "unknown 802.11 subtype name"); + YYABORT; + } } ; type_subtype: ID { int i; + CHECK_PTR_VAL($1); for (i = 0;; i++) { if (ieee80211_type_subtypes[i].tok == NULL) { /* Ran out of types */ - bpf_error(cstate, "unknown 802.11 type name"); - break; + bpf_set_error(cstate, "unknown 802.11 type name"); + YYABORT; } $$ = str2tok($1, ieee80211_type_subtypes[i].tok); if ($$ != -1) { @@ -627,33 +637,37 @@ type_subtype: ID { int i; } ; -pllc: LLC { $$ = gen_llc(cstate); } - | LLC ID { if (pcap_strcasecmp($2, "i") == 0) - $$ = gen_llc_i(cstate); - else if (pcap_strcasecmp($2, "s") == 0) - $$ = gen_llc_s(cstate); - else if (pcap_strcasecmp($2, "u") == 0) - $$ = gen_llc_u(cstate); - else { +pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); } + | LLC ID { CHECK_PTR_VAL($2); + if (pcap_strcasecmp($2, "i") == 0) { + CHECK_PTR_VAL(($$ = gen_llc_i(cstate))); + } else if (pcap_strcasecmp($2, "s") == 0) { + CHECK_PTR_VAL(($$ = gen_llc_s(cstate))); + } else if (pcap_strcasecmp($2, "u") == 0) { + CHECK_PTR_VAL(($$ = gen_llc_u(cstate))); + } else { int subtype; subtype = str2tok($2, llc_s_subtypes); - if (subtype != -1) - $$ = gen_llc_s_subtype(cstate, subtype); - else { + if (subtype != -1) { + CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, subtype))); + } else { subtype = str2tok($2, llc_u_subtypes); - if (subtype == -1) - bpf_error(cstate, "unknown LLC type name \"%s\"", $2); - $$ = gen_llc_u_subtype(cstate, subtype); + if (subtype == -1) { + bpf_set_error(cstate, "unknown LLC type name \"%s\"", $2); + YYABORT; + } + CHECK_PTR_VAL(($$ = gen_llc_u_subtype(cstate, subtype))); } } } /* sigh, "rnr" is already a keyword for PF */ - | LLC PF_RNR { $$ = gen_llc_s_subtype(cstate, LLC_RNR); } + | LLC PF_RNR { CHECK_PTR_VAL(($$ = gen_llc_s_subtype(cstate, LLC_RNR))); } ; dir: NUM - | ID { if (pcap_strcasecmp($1, "nods") == 0) + | ID { CHECK_PTR_VAL($1); + if (pcap_strcasecmp($1, "nods") == 0) $$ = IEEE80211_FC1_DIR_NODS; else if (pcap_strcasecmp($1, "tods") == 0) $$ = IEEE80211_FC1_DIR_TODS; @@ -661,16 +675,18 @@ dir: NUM $$ = IEEE80211_FC1_DIR_FROMDS; else if (pcap_strcasecmp($1, "dstods") == 0) $$ = IEEE80211_FC1_DIR_DSTODS; - else - bpf_error(cstate, "unknown 802.11 direction"); + else { + bpf_set_error(cstate, "unknown 802.11 direction"); + YYABORT; + } } ; reason: NUM { $$ = $1; } - | ID { $$ = pfreason_to_num(cstate, $1); } + | ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfreason_to_num(cstate, $1))); } ; -action: ID { $$ = pfaction_to_num(cstate, $1); } +action: ID { CHECK_PTR_VAL($1); CHECK_INT_VAL(($$ = pfaction_to_num(cstate, $1))); } ; relop: '>' { $$ = BPF_JGT; } @@ -681,24 +697,24 @@ irelop: LEQ { $$ = BPF_JGT; } | '<' { $$ = BPF_JGE; } | NEQ { $$ = BPF_JEQ; } ; -arth: pnum { $$ = gen_loadi(cstate, $1); } +arth: pnum { CHECK_PTR_VAL(($$ = gen_loadi(cstate, $1))); } | narth ; -narth: pname '[' arth ']' { $$ = gen_load(cstate, $1, $3, 1); } - | pname '[' arth ':' NUM ']' { $$ = gen_load(cstate, $1, $3, $5); } - | arth '+' arth { $$ = gen_arth(cstate, BPF_ADD, $1, $3); } - | arth '-' arth { $$ = gen_arth(cstate, BPF_SUB, $1, $3); } - | arth '*' arth { $$ = gen_arth(cstate, BPF_MUL, $1, $3); } - | arth '/' arth { $$ = gen_arth(cstate, BPF_DIV, $1, $3); } - | arth '%' arth { $$ = gen_arth(cstate, BPF_MOD, $1, $3); } - | arth '&' arth { $$ = gen_arth(cstate, BPF_AND, $1, $3); } - | arth '|' arth { $$ = gen_arth(cstate, BPF_OR, $1, $3); } - | arth '^' arth { $$ = gen_arth(cstate, BPF_XOR, $1, $3); } - | arth LSH arth { $$ = gen_arth(cstate, BPF_LSH, $1, $3); } - | arth RSH arth { $$ = gen_arth(cstate, BPF_RSH, $1, $3); } - | '-' arth %prec UMINUS { $$ = gen_neg(cstate, $2); } +narth: pname '[' arth ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, 1))); } + | pname '[' arth ':' NUM ']' { CHECK_PTR_VAL(($$ = gen_load(cstate, $1, $3, $5))); } + | arth '+' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_ADD, $1, $3))); } + | arth '-' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_SUB, $1, $3))); } + | arth '*' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MUL, $1, $3))); } + | arth '/' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_DIV, $1, $3))); } + | arth '%' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_MOD, $1, $3))); } + | arth '&' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_AND, $1, $3))); } + | arth '|' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_OR, $1, $3))); } + | arth '^' arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_XOR, $1, $3))); } + | arth LSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_LSH, $1, $3))); } + | arth RSH arth { CHECK_PTR_VAL(($$ = gen_arth(cstate, BPF_RSH, $1, $3))); } + | '-' arth %prec UMINUS { CHECK_PTR_VAL(($$ = gen_neg(cstate, $2))); } | paren narth ')' { $$ = $2; } - | LEN { $$ = gen_loadlen(cstate); } + | LEN { CHECK_PTR_VAL(($$ = gen_loadlen(cstate))); } ; byteop: '&' { $$ = '&'; } | '|' { $$ = '|'; } @@ -727,15 +743,15 @@ atmfield: VPI { $$.atmfieldtype = A_VPI; } | VCI { $$.atmfieldtype = A_VCI; } ; atmvalue: atmfieldvalue - | relop NUM { $$.b = gen_atmfield_code(cstate, $0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0); } - | irelop NUM { $$.b = gen_atmfield_code(cstate, $0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1); } + | relop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 0))); } + | irelop NUM { CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $0.atmfieldtype, (bpf_int32)$2, (bpf_u_int32)$1, 1))); } | paren atmlistvalue ')' { $$.b = $2.b; $$.q = qerr; } ; atmfieldvalue: NUM { $$.atmfieldtype = $0.atmfieldtype; if ($$.atmfieldtype == A_VPI || $$.atmfieldtype == A_VCI) - $$.b = gen_atmfield_code(cstate, $$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0); + CHECK_PTR_VAL(($$.b = gen_atmfield_code(cstate, $$.atmfieldtype, (bpf_int32) $1, BPF_JEQ, 0))); } ; atmlistvalue: atmfieldvalue @@ -760,8 +776,8 @@ mtp3field: SIO { $$.mtp3fieldtype = M_SIO; } | HSLS { $$.mtp3fieldtype = MH_SLS; } ; mtp3value: mtp3fieldvalue - | relop NUM { $$.b = gen_mtp3field_code(cstate, $0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0); } - | irelop NUM { $$.b = gen_mtp3field_code(cstate, $0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1); } + | relop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $0.mtp3fieldtype, (u_int)$2, (u_int)$1, 0))); } + | irelop NUM { CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $0.mtp3fieldtype, (u_int)$2, (u_int)$1, 1))); } | paren mtp3listvalue ')' { $$.b = $2.b; $$.q = qerr; } ; mtp3fieldvalue: NUM { @@ -774,7 +790,7 @@ mtp3fieldvalue: NUM { $$.mtp3fieldtype == MH_OPC || $$.mtp3fieldtype == MH_DPC || $$.mtp3fieldtype == MH_SLS) - $$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0); + CHECK_PTR_VAL(($$.b = gen_mtp3field_code(cstate, $$.mtp3fieldtype, (u_int) $1, BPF_JEQ, 0))); } ; mtp3listvalue: mtp3fieldvalue diff --git a/libpcap/missing/asprintf.c b/libpcap/missing/asprintf.c new file mode 100644 index 000000000..3aa55ed9d --- /dev/null +++ b/libpcap/missing/asprintf.c @@ -0,0 +1,101 @@ +#include +#include +#include + +#include "portability.h" + +/* + * vasprintf() and asprintf() for platforms with a C99-compliant + * snprintf() - so that, if you format into a 1-byte buffer, it + * will return how many characters it would have produced had + * it been given an infinite-sized buffer. + */ +int +pcap_vasprintf(char **strp, const char *format, va_list args) +{ + char buf; + int len; + size_t str_size; + char *str; + int ret; + + /* + * XXX - the C99 standard says, in section 7.19.6.5 "Thes + * nprintf function": + * + * The snprintf function is equivalent to fprintf, except that + * the output is written into an array (specified by argument s) + * rather than to a stream. If n is zero, nothing is written, + * and s may be a null pointer. Otherwise, output characters + * beyond the n-1st are discarded rather than being written + * to the array, and a null character is written at the end + * of the characters actually written into the array. + * + * ... + * + * The snprintf function returns the number of characters that + * would have been written had n been sufficiently large, not + * counting the terminating null character, or a negative value + * if an encoding error occurred. Thus, the null-terminated + * output has been completely written if and only if the returned + * value is nonnegative and less than n. + * + * That doesn't make it entirely clear whether, if a null buffer + * pointer and a zero count are passed, it will return the number + * of characters that would have been written had a buffer been + * passed. + * + * And, even if C99 *does*, in fact, say it has to work, it + * doesn't work in Solaris 8, for example - it returns -1 for + * NULL/0, but returns the correct character count for a 1-byte + * buffer. + * + * So we pass a one-character pointer in order to find out how + * many characters this format and those arguments will need + * without actually generating any more of those characters + * than we need. + * + * (The fact that it might happen to work with GNU libc or with + * various BSD libcs is completely uninteresting, as those tend + * to have asprintf() already and thus don't even *need* this + * code; this is for use in those UN*Xes that *don't* have + * asprintf().) + */ + len = vsnprintf(&buf, sizeof buf, format, args); + if (len == -1) { + *strp = NULL; + return (-1); + } + str_size = len + 1; + str = malloc(str_size); + if (str == NULL) { + *strp = NULL; + return (-1); + } + ret = vsnprintf(str, str_size, format, args); + if (ret == -1) { + free(str); + *strp = NULL; + return (-1); + } + *strp = str; + /* + * vsnprintf() shouldn't truncate the string, as we have + * allocated a buffer large enough to hold the string, so its + * return value should be the number of characters written. + */ + return (ret); +} + +int +pcap_asprintf(char **strp, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = pcap_vasprintf(strp, format, args); + va_end(args); + return (ret); +} + diff --git a/libpcap/missing/snprintf.c b/libpcap/missing/snprintf.c index 99f0bdfc2..672aeb86a 100644 --- a/libpcap/missing/snprintf.c +++ b/libpcap/missing/snprintf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan + * Copyright (c) 1995-1999 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -31,6 +31,10 @@ * SUCH DAMAGE. */ +/* + * We use this for platforms that don't have snprintf() at all. + */ + #ifdef HAVE_CONFIG_H #include #endif @@ -42,7 +46,7 @@ #include #include -#include +#include "portability.h" enum format_flags { minus_flag = 1, @@ -525,6 +529,7 @@ pcap_asnprintf (char **ret, size_t max_sz, const char *format, ...) va_start(args, format); val = pcap_vasnprintf (ret, max_sz, format, args); + va_end(args); #ifdef PARANOIA { @@ -534,14 +539,15 @@ pcap_asnprintf (char **ret, size_t max_sz, const char *format, ...) if (tmp == NULL) abort (); + va_start(args, format); ret2 = pcap_vsprintf (tmp, format, args); + va_end(args); if (val != ret2 || strcmp(*ret, tmp)) abort (); free (tmp); } #endif - va_end(args); return val; } #endif diff --git a/libpcap/missing/strlcat.c b/libpcap/missing/strlcat.c new file mode 100644 index 000000000..bb78a3d08 --- /dev/null +++ b/libpcap/missing/strlcat.c @@ -0,0 +1,61 @@ +/* $OpenBSD: pcap_strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "portability.h" + +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +pcap_strlcat(char * restrict dst, const char * restrict src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +} diff --git a/libpcap/missing/strlcpy.c b/libpcap/missing/strlcpy.c new file mode 100644 index 000000000..c552e0d59 --- /dev/null +++ b/libpcap/missing/strlcpy.c @@ -0,0 +1,56 @@ +/* $OpenBSD: pcap_strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "portability.h" + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +} diff --git a/libpcap/missing/win_asprintf.c b/libpcap/missing/win_asprintf.c new file mode 100644 index 000000000..cce629606 --- /dev/null +++ b/libpcap/missing/win_asprintf.c @@ -0,0 +1,51 @@ +#include +#include +#include + +#include "portability.h" + +int +pcap_vasprintf(char **strp, const char *format, va_list args) +{ + int len; + size_t str_size; + char *str; + int ret; + + len = _vscprintf(format, args); + if (len == -1) { + *strp = NULL; + return (-1); + } + str_size = len + 1; + str = malloc(str_size); + if (str == NULL) { + *strp = NULL; + return (-1); + } + ret = pcap_vsnprintf(str, str_size, format, args); + if (ret == -1) { + free(str); + *strp = NULL; + return (-1); + } + *strp = str; + /* + * pcap_vsnprintf() shouldn't truncate the string, as we have + * allocated a buffer large enough to hold the string, so its + * return value should be the number of characters printed. + */ + return (ret); +} + +int +pcap_asprintf(char **strp, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = pcap_vasprintf(strp, format, args); + va_end(args); + return (ret); +} diff --git a/libpcap/missing/win_snprintf.c b/libpcap/missing/win_snprintf.c index 65a8ea1a5..f42240352 100644 --- a/libpcap/missing/win_snprintf.c +++ b/libpcap/missing/win_snprintf.c @@ -1,6 +1,8 @@ #include #include +#include "portability.h" + int pcap_vsnprintf(char *str, size_t str_size, const char *format, va_list args) { @@ -13,6 +15,16 @@ pcap_vsnprintf(char *str, size_t str_size, const char *format, va_list args) * that str is null-terminated, but C99's vsnprintf() * and snprintf() do, and we want to offer C99 behavior, * so forcibly null-terminate the string. + * + * We don't, however, offer C99 behavior for the return + * value; _vsnprintf_s() returns -1, not the number of + * characters that would have been put into the buffer + * had it been large enough, if the string is truncated. + * The only way to get that value is to use _vscprintf(); + * getting that count isn't worth the re-formatting. + * + * XXX - does _vsnprintf_s() return -1 on a formatting + * error? */ str[str_size - 1] = '\0'; return (ret); diff --git a/libpcap/nametoaddr.c b/libpcap/nametoaddr.c index 194ff45b7..7c48bd3a3 100644 --- a/libpcap/nametoaddr.c +++ b/libpcap/nametoaddr.c @@ -231,7 +231,22 @@ pcap_nametonetaddr(const char *name) int h_errnoval; int err; - err = getnetbyname_r(name, &result_buf, buf, sizeof buf, &np, + /* + * Apparently, the man page at + * + * http://man7.org/linux/man-pages/man3/getnetbyname_r.3.html + * + * lies when it says + * + * If the function call successfully obtains a network record, + * then *result is set pointing to result_buf; otherwise, *result + * is set to NULL. + * + * and, in fact, at least in some versions of GNU libc, it does + * *not* always get set if getnetbyname_r() succeeds. + */ + np = NULL; + err = getnetbyname_r(name, &result_buf, buf, sizeof buf, &np, &h_errnoval); if (err != 0) { /* diff --git a/libpcap/optimize.c b/libpcap/optimize.c index 7c6424b01..448452d28 100644 --- a/libpcap/optimize.c +++ b/libpcap/optimize.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -226,6 +227,16 @@ struct vmapinfo { }; typedef struct { + /* + * Place to longjmp to on an error. + */ + jmp_buf top_ctx; + + /* + * The buffer into which to put error message. + */ + char *errbuf; + /* * A flag to indicate that further optimization is needed. * Iterative passes are continued until a given pass yields no @@ -252,19 +263,19 @@ typedef struct { * True if a is in uset {p} */ #define SET_MEMBER(p, a) \ -((p)[(unsigned)(a) / BITS_PER_WORD] & (1 << ((unsigned)(a) % BITS_PER_WORD))) +((p)[(unsigned)(a) / BITS_PER_WORD] & ((bpf_u_int32)1 << ((unsigned)(a) % BITS_PER_WORD))) /* * Add 'a' to uset p. */ #define SET_INSERT(p, a) \ -(p)[(unsigned)(a) / BITS_PER_WORD] |= (1 << ((unsigned)(a) % BITS_PER_WORD)) +(p)[(unsigned)(a) / BITS_PER_WORD] |= ((bpf_u_int32)1 << ((unsigned)(a) % BITS_PER_WORD)) /* * Delete 'a' from uset p. */ #define SET_DELETE(p, a) \ -(p)[(unsigned)(a) / BITS_PER_WORD] &= ~(1 << ((unsigned)(a) % BITS_PER_WORD)) +(p)[(unsigned)(a) / BITS_PER_WORD] &= ~((bpf_u_int32)1 << ((unsigned)(a) % BITS_PER_WORD)) /* * a := a intersect b @@ -311,6 +322,16 @@ typedef struct { } opt_state_t; typedef struct { + /* + * Place to longjmp to on an error. + */ + jmp_buf top_ctx; + + /* + * The buffer into which to put error message. + */ + char *errbuf; + /* * Some pointers used to convert the basic block form of the code, * into the array form that BPF requires. 'fstart' will point to @@ -321,14 +342,16 @@ typedef struct { struct bpf_insn *ftail; } conv_state_t; -static void opt_init(compiler_state_t *, opt_state_t *, struct icode *); +static void opt_init(opt_state_t *, struct icode *); static void opt_cleanup(opt_state_t *); +static void PCAP_NORETURN opt_error(opt_state_t *, const char *, ...) + PCAP_PRINTFLIKE(2, 3); static void intern_blocks(opt_state_t *, struct icode *); static void find_inedges(opt_state_t *, struct block *); #ifdef BDEBUG -static void opt_dump(compiler_state_t *, struct icode *); +static void opt_dump(opt_state_t *, struct icode *); #endif #ifndef MAX @@ -699,8 +722,7 @@ vstore(struct stmt *s, int *valp, int newval, int alter) * (Unary operators are handled elsewhere.) */ static void -fold_op(compiler_state_t *cstate, opt_state_t *opt_state, - struct stmt *s, int v0, int v1) +fold_op(opt_state_t *opt_state, struct stmt *s, int v0, int v1) { bpf_u_int32 a, b; @@ -722,13 +744,13 @@ fold_op(compiler_state_t *cstate, opt_state_t *opt_state, case BPF_DIV: if (b == 0) - bpf_error(cstate, "division by zero"); + opt_error(opt_state, "division by zero"); a /= b; break; case BPF_MOD: if (b == 0) - bpf_error(cstate, "modulus by zero"); + opt_error(opt_state, "modulus by zero"); a %= b; break; @@ -745,11 +767,39 @@ fold_op(compiler_state_t *cstate, opt_state_t *opt_state, break; case BPF_LSH: - a <<= b; + /* + * A left shift of more than the width of the type + * is undefined in C; we'll just treat it as shifting + * all the bits out. + * + * XXX - the BPF interpreter doesn't check for this, + * so its behavior is dependent on the behavior of + * the processor on which it's running. There are + * processors on which it shifts all the bits out + * and processors on which it does no shift. + */ + if (b < 32) + a <<= b; + else + a = 0; break; case BPF_RSH: - a >>= b; + /* + * A right shift of more than the width of the type + * is undefined in C; we'll just treat it as shifting + * all the bits out. + * + * XXX - the BPF interpreter doesn't check for this, + * so its behavior is dependent on the behavior of + * the processor on which it's running. There are + * processors on which it shifts all the bits out + * and processors on which it does no shift. + */ + if (b < 32) + a >>= b; + else + a = 0; break; default: @@ -1041,8 +1091,7 @@ opt_peep(opt_state_t *opt_state, struct block *b) * evaluation and code transformations weren't folded together. */ static void -opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state, - struct stmt *s, int val[], int alter) +opt_stmt(opt_state_t *opt_state, struct stmt *s, int val[], int alter) { int op; int v; @@ -1094,7 +1143,23 @@ opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state, case BPF_ALU|BPF_NEG: if (alter && opt_state->vmap[val[A_ATOM]].is_const) { s->code = BPF_LD|BPF_IMM; - s->k = -opt_state->vmap[val[A_ATOM]].const_val; + /* + * Do this negation as unsigned arithmetic; that's + * what modern BPF engines do, and it guarantees + * that all possible values can be negated. (Yeah, + * negating 0x80000000, the minimum signed 32-bit + * two's-complement value, results in 0x80000000, + * so it's still negative, but we *should* be doing + * all unsigned arithmetic here, to match what + * modern BPF engines do.) + * + * Express it as 0U - (unsigned value) so that we + * don't get compiler warnings about negating an + * unsigned value and don't get UBSan warnings + * about the result of negating 0x80000000 being + * undefined. + */ + s->k = 0U - (bpf_u_int32)(opt_state->vmap[val[A_ATOM]].const_val); val[A_ATOM] = K(s->k); } else @@ -1114,9 +1179,17 @@ opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state, op = BPF_OP(s->code); if (alter) { if (s->k == 0) { - /* don't optimize away "sub #0" + /* + * Optimize operations where the constant + * is zero. + * + * Don't optimize away "sub #0" * as it may be needed later to - * fixup the generated math code */ + * fixup the generated math code. + * + * Fail if we're dividing by zero or taking + * a modulus by zero. + */ if (op == BPF_ADD || op == BPF_LSH || op == BPF_RSH || op == BPF_OR || op == BPF_XOR) { @@ -1128,9 +1201,15 @@ opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state, val[A_ATOM] = K(s->k); break; } + if (op == BPF_DIV) + opt_error(opt_state, + "division by zero"); + if (op == BPF_MOD) + opt_error(opt_state, + "modulus by zero"); } if (opt_state->vmap[val[A_ATOM]].is_const) { - fold_op(cstate, opt_state, s, val[A_ATOM], K(s->k)); + fold_op(opt_state, s, val[A_ATOM], K(s->k)); val[A_ATOM] = K(s->k); break; } @@ -1151,12 +1230,22 @@ opt_stmt(compiler_state_t *cstate, opt_state_t *opt_state, op = BPF_OP(s->code); if (alter && opt_state->vmap[val[X_ATOM]].is_const) { if (opt_state->vmap[val[A_ATOM]].is_const) { - fold_op(cstate, opt_state, s, val[A_ATOM], val[X_ATOM]); + fold_op(opt_state, s, val[A_ATOM], val[X_ATOM]); val[A_ATOM] = K(s->k); } else { s->code = BPF_ALU|BPF_K|op; s->k = opt_state->vmap[val[X_ATOM]].const_val; + /* + * XXX - we need to make up our minds + * as to what integers are signed and + * what integers are unsigned in BPF + * programs and in our IR. + */ + if ((op == BPF_LSH || op == BPF_RSH) && + (s->k < 0 || s->k > 31)) + opt_error(opt_state, + "shift by more than 31 bits"); opt_state->done = 0; val[A_ATOM] = F(opt_state, s->code, val[A_ATOM], K(s->k)); @@ -1275,8 +1364,7 @@ opt_deadstores(opt_state_t *opt_state, register struct block *b) } static void -opt_blk(compiler_state_t *cstate, opt_state_t *opt_state, - struct block *b, int do_stmts) +opt_blk(opt_state_t *opt_state, struct block *b, int do_stmts) { struct slist *s; struct edge *p; @@ -1326,7 +1414,7 @@ opt_blk(compiler_state_t *cstate, opt_state_t *opt_state, aval = b->val[A_ATOM]; xval = b->val[X_ATOM]; for (s = b->stmts; s; s = s->next) - opt_stmt(cstate, opt_state, &s->s, b->val, do_stmts); + opt_stmt(opt_state, &s->s, b->val, do_stmts); /* * This is a special case: if we don't use anything from this @@ -1480,7 +1568,7 @@ opt_j(opt_state_t *opt_state, struct edge *ep) while (x != 0) { k = lowest_set_bit(x); - x &=~ (1 << k); + x &=~ ((bpf_u_int32)1 << k); k += i * BITS_PER_WORD; target = fold_edge(ep->succ, opt_state->edges[k]); @@ -1687,8 +1775,7 @@ and_pullup(opt_state_t *opt_state, struct block *b) } static void -opt_blks(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic, - int do_stmts) +opt_blks(opt_state_t *opt_state, struct icode *ic, int do_stmts) { int i, maxlevel; struct block *p; @@ -1699,7 +1786,7 @@ opt_blks(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic, find_inedges(opt_state, ic->root); for (i = maxlevel; i >= 0; --i) for (p = opt_state->levels[i]; p; p = p->link) - opt_blk(cstate, opt_state, p, do_stmts); + opt_blk(opt_state, p, do_stmts); if (do_stmts) /* @@ -1777,14 +1864,13 @@ opt_root(struct block **b) } static void -opt_loop(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic, - int do_stmts) +opt_loop(opt_state_t *opt_state, struct icode *ic, int do_stmts) { #ifdef BDEBUG if (pcap_optimizer_debug > 1 || pcap_print_dot_graph) { printf("opt_loop(root, %d) begin\n", do_stmts); - opt_dump(cstate, ic); + opt_dump(opt_state, ic); } #endif do { @@ -1794,11 +1880,11 @@ opt_loop(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic, find_closure(opt_state, ic->root); find_ud(opt_state, ic->root); find_edom(opt_state, ic->root); - opt_blks(cstate, opt_state, ic, do_stmts); + opt_blks(opt_state, ic, do_stmts); #ifdef BDEBUG if (pcap_optimizer_debug > 1 || pcap_print_dot_graph) { printf("opt_loop(root, %d) bottom, done=%d\n", do_stmts, opt_state->done); - opt_dump(cstate, ic); + opt_dump(opt_state, ic); } #endif } while (!opt_state->done); @@ -1806,30 +1892,38 @@ opt_loop(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic, /* * Optimize the filter code in its dag representation. + * Return 0 on success, -1 on error. */ -void -bpf_optimize(compiler_state_t *cstate, struct icode *ic) +int +bpf_optimize(struct icode *ic, char *errbuf) { opt_state_t opt_state; - opt_init(cstate, &opt_state, ic); - opt_loop(cstate, &opt_state, ic, 0); - opt_loop(cstate, &opt_state, ic, 1); + memset(&opt_state, 0, sizeof(opt_state)); + opt_state.errbuf = errbuf; + if (setjmp(opt_state.top_ctx)) { + opt_cleanup(&opt_state); + return -1; + } + opt_init(&opt_state, ic); + opt_loop(&opt_state, ic, 0); + opt_loop(&opt_state, ic, 1); intern_blocks(&opt_state, ic); #ifdef BDEBUG if (pcap_optimizer_debug > 1 || pcap_print_dot_graph) { printf("after intern_blocks()\n"); - opt_dump(cstate, ic); + opt_dump(&opt_state, ic); } #endif opt_root(&ic->root); #ifdef BDEBUG if (pcap_optimizer_debug > 1 || pcap_print_dot_graph) { printf("after opt_root()\n"); - opt_dump(cstate, ic); + opt_dump(&opt_state, ic); } #endif opt_cleanup(&opt_state); + return 0; } static void @@ -1943,6 +2037,24 @@ opt_cleanup(opt_state_t *opt_state) free((void *)opt_state->blocks); } +/* + * For optimizer errors. + */ +static void PCAP_NORETURN +opt_error(opt_state_t *opt_state, const char *fmt, ...) +{ + va_list ap; + + if (opt_state->errbuf != NULL) { + va_start(ap, fmt); + (void)pcap_vsnprintf(opt_state->errbuf, + PCAP_ERRBUF_SIZE, fmt, ap); + va_end(ap); + } + longjmp(opt_state->top_ctx, 1); + /* NOTREACHED */ +} + /* * Return the number of stmts in 's'. */ @@ -2027,7 +2139,7 @@ count_stmts(struct icode *ic, struct block *p) * from the total number of blocks and/or statements. */ static void -opt_init(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic) +opt_init(opt_state_t *opt_state, struct icode *ic) { bpf_u_int32 *p; int i, n, max_stmts; @@ -2040,22 +2152,24 @@ opt_init(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic) n = count_blocks(ic, ic->root); opt_state->blocks = (struct block **)calloc(n, sizeof(*opt_state->blocks)); if (opt_state->blocks == NULL) - bpf_error(cstate, "malloc"); + opt_error(opt_state, "malloc"); unMarkAll(ic); opt_state->n_blocks = 0; number_blks_r(opt_state, ic, ic->root); opt_state->n_edges = 2 * opt_state->n_blocks; opt_state->edges = (struct edge **)calloc(opt_state->n_edges, sizeof(*opt_state->edges)); - if (opt_state->edges == NULL) - bpf_error(cstate, "malloc"); + if (opt_state->edges == NULL) { + opt_error(opt_state, "malloc"); + } /* * The number of levels is bounded by the number of nodes. */ opt_state->levels = (struct block **)calloc(opt_state->n_blocks, sizeof(*opt_state->levels)); - if (opt_state->levels == NULL) - bpf_error(cstate, "malloc"); + if (opt_state->levels == NULL) { + opt_error(opt_state, "malloc"); + } opt_state->edgewords = opt_state->n_edges / (8 * sizeof(bpf_u_int32)) + 1; opt_state->nodewords = opt_state->n_blocks / (8 * sizeof(bpf_u_int32)) + 1; @@ -2063,8 +2177,9 @@ opt_init(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic) /* XXX */ opt_state->space = (bpf_u_int32 *)malloc(2 * opt_state->n_blocks * opt_state->nodewords * sizeof(*opt_state->space) + opt_state->n_edges * opt_state->edgewords * sizeof(*opt_state->space)); - if (opt_state->space == NULL) - bpf_error(cstate, "malloc"); + if (opt_state->space == NULL) { + opt_error(opt_state, "malloc"); + } p = opt_state->space; opt_state->all_dom_sets = p; for (i = 0; i < n; ++i) { @@ -2101,9 +2216,13 @@ opt_init(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic) */ opt_state->maxval = 3 * max_stmts; opt_state->vmap = (struct vmapinfo *)calloc(opt_state->maxval, sizeof(*opt_state->vmap)); + if (opt_state->vmap == NULL) { + opt_error(opt_state, "malloc"); + } opt_state->vnode_base = (struct valnode *)calloc(opt_state->maxval, sizeof(*opt_state->vnode_base)); - if (opt_state->vmap == NULL || opt_state->vnode_base == NULL) - bpf_error(cstate, "malloc"); + if (opt_state->vnode_base == NULL) { + opt_error(opt_state, "malloc"); + } } /* @@ -2115,6 +2234,9 @@ opt_init(compiler_state_t *cstate, opt_state_t *opt_state, struct icode *ic) int bids[NBIDS]; #endif +static void PCAP_NORETURN conv_error(conv_state_t *, const char *, ...) + PCAP_PRINTFLIKE(2, 3); + /* * Returns true if successful. Returns false if a branch has * an offset that is too large. If so, we have marked that @@ -2122,8 +2244,7 @@ int bids[NBIDS]; * properly. */ static int -convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, - struct icode *ic, struct block *p) +convert_code_r(conv_state_t *conv_state, struct icode *ic, struct block *p) { struct bpf_insn *dst; struct slist *src; @@ -2136,9 +2257,9 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, return (1); Mark(ic, p); - if (convert_code_r(cstate, conv_state, ic, JF(p)) == 0) + if (convert_code_r(conv_state, ic, JF(p)) == 0) return (0); - if (convert_code_r(cstate, conv_state, ic, JT(p)) == 0) + if (convert_code_r(conv_state, ic, JT(p)) == 0) return (0); slen = slength(p->stmts); @@ -2151,7 +2272,7 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, if (slen) { offset = (struct slist **)calloc(slen, sizeof(struct slist *)); if (!offset) { - bpf_error(cstate, "not enough core"); + conv_error(conv_state, "not enough core"); /*NOTREACHED*/ } } @@ -2175,7 +2296,8 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, if (BPF_CLASS(src->s.code) != BPF_JMP || src->s.code == (BPF_JMP|BPF_JA)) { #if 0 if (src->s.jt || src->s.jf) { - bpf_error(cstate, "illegal jmp destination"); + free(offset); + conv_error(conv_state, "illegal jmp destination"); /*NOTREACHED*/ } #endif @@ -2195,7 +2317,8 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, #endif if (!src->s.jt || !src->s.jf) { - bpf_error(cstate, ljerr, "no jmp destination", off); + free(offset); + conv_error(conv_state, ljerr, "no jmp destination", off); /*NOTREACHED*/ } @@ -2203,12 +2326,14 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, for (i = 0; i < slen; i++) { if (offset[i] == src->s.jt) { if (jt) { - bpf_error(cstate, ljerr, "multiple matches", off); + free(offset); + conv_error(conv_state, ljerr, "multiple matches", off); /*NOTREACHED*/ } if (i - off - 1 >= 256) { - bpf_error(cstate, ljerr, "out-of-range jump", off); + free(offset); + conv_error(conv_state, ljerr, "out-of-range jump", off); /*NOTREACHED*/ } dst->jt = (u_char)(i - off - 1); @@ -2216,11 +2341,13 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, } if (offset[i] == src->s.jf) { if (jf) { - bpf_error(cstate, ljerr, "multiple matches", off); + free(offset); + conv_error(conv_state, ljerr, "multiple matches", off); /*NOTREACHED*/ } if (i - off - 1 >= 256) { - bpf_error(cstate, ljerr, "out-of-range jump", off); + free(offset); + conv_error(conv_state, ljerr, "out-of-range jump", off); /*NOTREACHED*/ } dst->jf = (u_char)(i - off - 1); @@ -2228,7 +2355,8 @@ convert_code_r(compiler_state_t *cstate, conv_state_t *conv_state, } } if (!jt || !jf) { - bpf_error(cstate, ljerr, "no destination found", off); + free(offset); + conv_error(conv_state, ljerr, "no destination found", off); /*NOTREACHED*/ } } @@ -2257,7 +2385,7 @@ filled: } /* branch if T to following jump */ if (extrajmps >= 256) { - bpf_error(cstate, "too many extra jumps"); + conv_error(conv_state, "too many extra jumps"); /*NOTREACHED*/ } dst->jt = (u_char)extrajmps; @@ -2278,7 +2406,7 @@ filled: /* branch if F to following jump */ /* if two jumps are inserted, F goes to second one */ if (extrajmps >= 256) { - bpf_error(cstate, "too many extra jumps"); + conv_error(conv_state, "too many extra jumps"); /*NOTREACHED*/ } dst->jf = (u_char)extrajmps; @@ -2312,13 +2440,20 @@ filled: * done with the filter program. See the pcap man page. */ struct bpf_insn * -icode_to_fcode(compiler_state_t *cstate, struct icode *ic, - struct block *root, u_int *lenp) +icode_to_fcode(struct icode *ic, struct block *root, u_int *lenp, + char *errbuf) { u_int n; struct bpf_insn *fp; conv_state_t conv_state; + conv_state.fstart = NULL; + conv_state.errbuf = errbuf; + if (setjmp(conv_state.top_ctx) != 0) { + free(conv_state.fstart); + return NULL; + } + /* * Loop doing convert_code_r() until no branches remain * with too-large offsets. @@ -2328,14 +2463,18 @@ icode_to_fcode(compiler_state_t *cstate, struct icode *ic, n = *lenp = count_stmts(ic, root); fp = (struct bpf_insn *)malloc(sizeof(*fp) * n); - if (fp == NULL) - bpf_error(cstate, "malloc"); + if (fp == NULL) { + (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "malloc"); + free(fp); + return NULL; + } memset((char *)fp, 0, sizeof(*fp) * n); conv_state.fstart = fp; conv_state.ftail = fp + n; unMarkAll(ic); - if (convert_code_r(cstate, &conv_state, ic, root)) + if (convert_code_r(&conv_state, ic, root)) break; free(fp); } @@ -2343,6 +2482,22 @@ icode_to_fcode(compiler_state_t *cstate, struct icode *ic, return fp; } +/* + * For iconv_to_fconv() errors. + */ +static void PCAP_NORETURN +conv_error(conv_state_t *conv_state, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + (void)pcap_vsnprintf(conv_state->errbuf, + PCAP_ERRBUF_SIZE, fmt, ap); + va_end(ap); + longjmp(conv_state->top_ctx, 1); + /* NOTREACHED */ +} + /* * Make a copy of a BPF program and put it in the "fcode" member of * a "pcap_t". @@ -2452,14 +2607,16 @@ dot_dump_edge(struct icode *ic, struct block *block, FILE *out) * After install graphviz on http://www.graphviz.org/, save it as bpf.dot * and run `dot -Tpng -O bpf.dot' to draw the graph. */ -static void -dot_dump(compiler_state_t *cstate, struct icode *ic) +static int +dot_dump(struct icode *ic, char *errbuf) { struct bpf_program f; FILE *out = stdout; memset(bids, 0, sizeof bids); - f.bf_insns = icode_to_fcode(cstate, ic, ic->root, &f.bf_len); + f.bf_insns = icode_to_fcode(ic, ic->root, &f.bf_len, errbuf); + if (f.bf_insns == NULL) + return -1; fprintf(out, "digraph BPF {\n"); unMarkAll(ic); @@ -2469,30 +2626,39 @@ dot_dump(compiler_state_t *cstate, struct icode *ic) fprintf(out, "}\n"); free((char *)f.bf_insns); + return 0; } -static void -plain_dump(compiler_state_t *cstate, struct icode *ic) +static int +plain_dump(struct icode *ic, char *errbuf) { struct bpf_program f; memset(bids, 0, sizeof bids); - f.bf_insns = icode_to_fcode(cstate, ic, ic->root, &f.bf_len); + f.bf_insns = icode_to_fcode(ic, ic->root, &f.bf_len, errbuf); + if (f.bf_insns == NULL) + return -1; bpf_dump(&f, 1); putchar('\n'); free((char *)f.bf_insns); + return 0; } static void -opt_dump(compiler_state_t *cstate, struct icode *ic) +opt_dump(opt_state_t *opt_state, struct icode *ic) { + int status; + char errbuf[PCAP_ERRBUF_SIZE]; + /* * If the CFG, in DOT format, is requested, output it rather than * the code that would be generated from that graph. */ if (pcap_print_dot_graph) - dot_dump(cstate, ic); + status = dot_dump(ic, errbuf); else - plain_dump(cstate, ic); + status = plain_dump(ic, errbuf); + if (status == -1) + opt_error(opt_state, "opt_dump: icode_to_fcode failed: %s", errbuf); } #endif diff --git a/libpcap/pcap-bpf.c b/libpcap/pcap-bpf.c index 6ce383b0f..4f1a0afbe 100644 --- a/libpcap/pcap-bpf.c +++ b/libpcap/pcap-bpf.c @@ -206,7 +206,7 @@ static int monitor_mode(pcap_t *, int); # endif # if defined(__APPLE__) -static void remove_en(pcap_t *); +static void remove_non_802_11(pcap_t *); static void remove_802_11(pcap_t *); # endif @@ -737,10 +737,10 @@ get_dlt_list(int fd, int v, struct bpf_dltlist *bdlp, char *ebuf) } #endif +#if defined(__APPLE__) static int pcap_can_set_rfmon_bpf(pcap_t *p) { -#if defined(__APPLE__) struct utsname osinfo; struct ifreq ifr; int fd; @@ -799,8 +799,8 @@ pcap_can_set_rfmon_bpf(pcap_t *p) errno, "socket"); return (PCAP_ERROR); } - strlcpy(ifr.ifr_name, "wlt", sizeof(ifr.ifr_name)); - strlcat(ifr.ifr_name, p->opt.device + 2, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, "wlt", sizeof(ifr.ifr_name)); + pcap_strlcat(ifr.ifr_name, p->opt.device + 2, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { /* * No such device? @@ -880,7 +880,11 @@ pcap_can_set_rfmon_bpf(pcap_t *p) close(fd); #endif /* BIOCGDLTLIST */ return (0); +} #elif defined(HAVE_BSD_IEEE80211) +static int +pcap_can_set_rfmon_bpf(pcap_t *p) +{ int ret; ret = monitor_mode(p, 0); @@ -889,10 +893,14 @@ pcap_can_set_rfmon_bpf(pcap_t *p) if (ret == 0) return (1); /* success */ return (ret); -#else - return (0); -#endif } +#else +static int +pcap_can_set_rfmon_bpf(pcap_t *p _U_) +{ + return (0); +} +#endif static int pcap_stats_bpf(pcap_t *p, struct pcap_stat *ps) @@ -1012,18 +1020,21 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user) case EWOULDBLOCK: return (0); - case ENXIO: + case ENXIO: /* FreeBSD, DragonFly BSD, and Darwin */ + case EIO: /* OpenBSD */ + /* NetBSD appears not to return an error in this case */ /* * The device on which we're capturing * went away. * * XXX - we should really return - * PCAP_ERROR_IFACE_NOT_UP, but - * pcap_dispatch() etc. aren't - * defined to retur that. + * an appropriate error for that, + * but pcap_dispatch() etc. aren't + * documented as having error returns + * other than PCAP_ERROR or PCAP_ERROR_BREAK. */ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "The interface went down"); + "The interface disappeared"); return (PCAP_ERROR); #if defined(sun) && !defined(BSD) && !defined(__svr4__) && !defined(__SVR4) @@ -1358,8 +1369,8 @@ bpf_load(char *errbuf) /* Check if the driver is loaded */ memset(&cfg_ld, 0x0, sizeof(cfg_ld)); + pcap_snprintf(buf, sizeof(buf), "%s/%s", DRIVER_PATH, BPF_NAME); cfg_ld.path = buf; - pcap_snprintf(cfg_ld.path, sizeof(cfg_ld.path), "%s/%s", DRIVER_PATH, BPF_NAME); if ((sysconfig(SYS_QUERYLOAD, (void *)&cfg_ld, sizeof(cfg_ld)) == -1) || (cfg_ld.kmid == 0)) { /* Driver isn't loaded, load it now */ @@ -1469,7 +1480,7 @@ pcap_cleanup_bpf(pcap_t *p) s = socket(AF_LOCAL, SOCK_DGRAM, 0); if (s >= 0) { - strlcpy(ifr.ifr_name, pb->device, + pcap_strlcpy(ifr.ifr_name, pb->device, sizeof(ifr.ifr_name)); ioctl(s, SIOCIFDESTROY, &ifr); close(s); @@ -1532,9 +1543,9 @@ check_setif_failure(pcap_t *p, int error) */ fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd != -1) { - strlcpy(ifr.ifr_name, "en", + pcap_strlcpy(ifr.ifr_name, "en", sizeof(ifr.ifr_name)); - strlcat(ifr.ifr_name, p->opt.device + 3, + pcap_strlcat(ifr.ifr_name, p->opt.device + 3, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { /* @@ -1721,7 +1732,7 @@ pcap_activate_bpf(pcap_t *p) goto bad; } znamelen = zonesep - p->opt.device; - (void) strlcpy(path_zname, p->opt.device, znamelen + 1); + (void) pcap_strlcpy(path_zname, p->opt.device, znamelen + 1); ifr.lifr_zoneid = getzoneidbyname(path_zname); if (ifr.lifr_zoneid == -1) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, @@ -1786,7 +1797,7 @@ pcap_activate_bpf(pcap_t *p) */ sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd != -1) { - strlcpy(ifrname, + pcap_strlcpy(ifrname, p->opt.device, ifnamsiz); if (ioctl(sockfd, SIOCGIFFLAGS, (char *)&ifr) < 0) { @@ -1888,7 +1899,7 @@ pcap_activate_bpf(pcap_t *p) /* * Create the interface. */ - strlcpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) { if (errno == EINVAL) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, @@ -2187,7 +2198,7 @@ pcap_activate_bpf(pcap_t *p) * of link-layer types, as selecting * it will keep monitor mode off. */ - remove_en(p); + remove_non_802_11(p); /* * If the new mode we want isn't @@ -2748,12 +2759,21 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) strncpy(req.ifm_name, name, sizeof(req.ifm_name)); if (ioctl(sock, SIOCGIFMEDIA, &req) < 0) { if (errno == EOPNOTSUPP || errno == EINVAL || errno == ENOTTY || - errno == ENODEV) { + errno == ENODEV || errno == EPERM) { /* * Not supported, so we can't provide any * additional information. Assume that * this means that "connected" vs. * "disconnected" doesn't apply. + * + * The ioctl routine for Apple's pktap devices, + * annoyingly, checks for "are you root?" before + * checking whether the ioctl is valid, so it + * returns EPERM, rather than ENOTSUP, for the + * invalid SIOCGIFMEDIA, unless you're root. + * So, just as we do for some ethtool ioctls + * on Linux, which makes the same mistake, we + * also treat EPERM as meaning "not supported". */ *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE; close(sock); @@ -2890,7 +2910,7 @@ monitor_mode(pcap_t *p, int set) default: pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, - errno, "SIOCGIFMEDIA 1"); + errno, "SIOCGIFMEDIA"); close(sock); return (PCAP_ERROR); } @@ -3032,8 +3052,12 @@ find_802_11(struct bpf_dltlist *bdlp) new_dlt = bdlp->bfl_list[i]; break; +#ifdef DLT_PRISM_HEADER case DLT_PRISM_HEADER: +#endif +#ifdef DLT_AIRONET_HEADER case DLT_AIRONET_HEADER: +#endif case DLT_IEEE802_11_RADIO_AVS: /* * 802.11 with radio, but not radiotap. @@ -3068,24 +3092,25 @@ find_802_11(struct bpf_dltlist *bdlp) #if defined(__APPLE__) && defined(BIOCGDLTLIST) /* - * Remove DLT_EN10MB from the list of DLT_ values, as we're in monitor mode, - * and DLT_EN10MB isn't supported in monitor mode. + * Remove non-802.11 header types from the list of DLT_ values, as we're in + * monitor mode, and those header types aren't supported in monitor mode. */ static void -remove_en(pcap_t *p) +remove_non_802_11(pcap_t *p) { int i, j; /* - * Scan the list of DLT_ values and discard DLT_EN10MB. + * Scan the list of DLT_ values and discard non-802.11 ones. */ j = 0; for (i = 0; i < p->dlt_count; i++) { switch (p->dlt_list[i]) { case DLT_EN10MB: + case DLT_RAW: /* - * Don't offer this one. + * Not 802.11. Don't offer this one. */ continue; @@ -3127,10 +3152,17 @@ remove_802_11(pcap_t *p) switch (p->dlt_list[i]) { case DLT_IEEE802_11: +#ifdef DLT_PRISM_HEADER case DLT_PRISM_HEADER: +#endif +#ifdef DLT_AIRONET_HEADER case DLT_AIRONET_HEADER: +#endif case DLT_IEEE802_11_RADIO: case DLT_IEEE802_11_RADIO_AVS: +#ifdef DLT_PPI + case DLT_PPI: +#endif /* * 802.11. Don't offer this one. */ @@ -3222,10 +3254,10 @@ pcap_setfilter_bpf(pcap_t *p, struct bpf_program *fp) * Set direction flag: Which packets do we accept on a forwarding * single device? IN, OUT or both? */ +#if defined(BIOCSDIRECTION) static int pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d) { -#if defined(BIOCSDIRECTION) u_int direction; direction = (d == PCAP_D_IN) ? BPF_D_IN : @@ -3238,7 +3270,11 @@ pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d) return (-1); } return (0); +} #elif defined(BIOCSSEESENT) +static int +pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d) +{ u_int seesent; /* @@ -3258,25 +3294,35 @@ pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d) return (-1); } return (0); +} #else +static int +pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d _U_) +{ (void) pcap_snprintf(p->errbuf, sizeof(p->errbuf), "This system doesn't support BIOCSSEESENT, so the direction can't be set"); return (-1); -#endif } +#endif +#ifdef BIOCSDLT static int pcap_set_datalink_bpf(pcap_t *p, int dlt) { -#ifdef BIOCSDLT if (ioctl(p->fd, BIOCSDLT, &dlt) == -1) { pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf), errno, "Cannot set DLT %d", dlt); return (-1); } -#endif return (0); } +#else +static int +pcap_set_datalink_bpf(pcap_t *p _U_, int dlt _U_) +{ + return (0); +} +#endif /* * Platform-specific information. diff --git a/libpcap/pcap-bt-linux.c b/libpcap/pcap-bt-linux.c index 07ed1c73d..9c8712e95 100644 --- a/libpcap/pcap-bt-linux.c +++ b/libpcap/pcap-bt-linux.c @@ -74,13 +74,14 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str) { struct hci_dev_list_req *dev_list; struct hci_dev_req *dev_req; - int i, sock; + int sock; + unsigned i; int ret = 0; sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (sock < 0) { - /* if bluetooth is not supported this this is not fatal*/ + /* if bluetooth is not supported this is not fatal*/ if (errno == EAFNOSUPPORT) return 0; pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE, @@ -109,10 +110,10 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str) dev_req = dev_list->dev_req; for (i = 0; i < dev_list->dev_num; i++, dev_req++) { - char dev_name[20], dev_descr[30]; + char dev_name[20], dev_descr[40]; - pcap_snprintf(dev_name, 20, BT_IFACE"%d", dev_req->dev_id); - pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i); + pcap_snprintf(dev_name, sizeof(dev_name), BT_IFACE"%u", dev_req->dev_id); + pcap_snprintf(dev_descr, sizeof(dev_descr), "Bluetooth adapter number %u", i); /* * Bluetooth is a wireless technology. @@ -379,8 +380,8 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char static int bt_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on " - "bluetooth devices"); + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Packet injection is not supported on Bluetooth devices"); return (-1); } diff --git a/libpcap/pcap-bt-monitor-linux.c b/libpcap/pcap-bt-monitor-linux.c index c222c100e..a693949d4 100644 --- a/libpcap/pcap-bt-monitor-linux.c +++ b/libpcap/pcap-bt-monitor-linux.c @@ -149,7 +149,8 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch static int bt_monitor_inject(pcap_t *handle, const void *buf _U_, size_t size _U_) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet"); + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Packet injection is not supported yet on Bluetooth monitor devices"); return -1; } diff --git a/libpcap/pcap-common.c b/libpcap/pcap-common.c index b379d8fd8..2a745f0bf 100644 --- a/libpcap/pcap-common.c +++ b/libpcap/pcap-common.c @@ -514,11 +514,20 @@ #define LINKTYPE_RAIF1 198 /* - * IPMB packet for IPMI, beginning with the I2C slave address, followed - * by the netFn and LUN, etc.. Requested by Chanthy Toeung - * . + * IPMB packet for IPMI, beginning with a 2-byte header, followed by + * the I2C slave address, followed by the netFn and LUN, etc.. + * Requested by Chanthy Toeung . + * + * XXX - its DLT_ value used to be called DLT_IPMB, back when we got the + * impression from the email thread requesting it that the packet + * had no extra 2-byte header. We've renamed it; if anybody used + * DLT_IPMB and assumed no 2-byte header, this will cause the compile + * to fail, at which point we'll have to figure out what to do about + * the two header types using the same DLT_/LINKTYPE_ value. If that + * doesn't happen, we'll assume nobody used it and that the redefinition + * is safe. */ -#define LINKTYPE_IPMB 199 +#define LINKTYPE_IPMB_KONTRON 199 /* * Juniper-private data link type, as per request from @@ -549,15 +558,35 @@ */ #define LINKTYPE_LAPD 203 + /* - * Variants of various link-layer headers, with a one-byte direction - * pseudo-header prepended - zero means "received by this host", - * non-zero (any non-zero value) means "sent by this host" - as per - * Will Barker . + * PPP, with a one-byte direction pseudo-header prepended - zero means + * "received by this host", non-zero (any non-zero value) means "sent by + * this host" - as per Will Barker . + */ +#define LINKTYPE_PPP_WITH_DIR 204 /* Don't confuse with LINKTYPE_PPP_PPPD */ + +/* + * Cisco HDLC, with a one-byte direction pseudo-header prepended - zero + * means "received by this host", non-zero (any non-zero value) means + * "sent by this host" - as per Will Barker . */ -#define LINKTYPE_PPP_WITH_DIR 204 /* PPP */ #define LINKTYPE_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ + +/* + * Frame Relay, with a one-byte direction pseudo-header prepended - zero + * means "received by this host" (DCE -> DTE), non-zero (any non-zero + * value) means "sent by this host" (DTE -> DCE) - as per Will Barker + * . + */ #define LINKTYPE_FRELAY_WITH_DIR 206 /* Frame Relay */ + +/* + * LAPB, with a one-byte direction pseudo-header prepended - zero means + * "received by this host" (DCE -> DTE), non-zero (any non-zero value) + * means "sent by this host" (DTE -> DCE)- as per Will Barker + * . + */ #define LINKTYPE_LAPB_WITH_DIR 207 /* LAPB */ /* @@ -1081,7 +1110,12 @@ */ #define LINKTYPE_DISPLAYPORT_AUX 275 -#define LINKTYPE_MATCHING_MAX 275 /* highest value in the "matching" range */ +/* + * Linux cooked sockets v2. + */ +#define LINKTYPE_LINUX_SLL2 276 + +#define LINKTYPE_MATCHING_MAX 276 /* highest value in the "matching" range */ /* * The DLT_ and LINKTYPE_ values in the "matching" range should be the @@ -1240,18 +1274,30 @@ linktype_to_dlt(int linktype) /* * Return the maximum snapshot length for a given DLT_ value. * - * For most link-layer types, we use MAXIMUM_SNAPLEN, but for DLT_DBUS, - * the maximum is 134217728, as per + * For most link-layer types, we use MAXIMUM_SNAPLEN. + * + * For DLT_DBUS, the maximum is 128MiB, as per * * https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages + * + * For DLT_USBPCAP, the maximum is 1MiB, as per + * + * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=15985 */ u_int max_snaplen_for_dlt(int dlt) { - if (dlt == DLT_DBUS) - return 134217728; - else + switch (dlt) { + + case DLT_DBUS: + return 128*1024*1024; + + case DLT_USBPCAP: + return 1024*1024; + + default: return MAXIMUM_SNAPLEN; + } } /* diff --git a/libpcap/pcap-dag.c b/libpcap/pcap-dag.c index 6b7c79197..e076676c4 100644 --- a/libpcap/pcap-dag.c +++ b/libpcap/pcap-dag.c @@ -1,14 +1,6 @@ /* * pcap-dag.c: Packet capture interface for Endace DAG cards. * - * The functionality of this code attempts to mimic that of pcap-linux as much - * as possible. This code is compiled in several different ways depending on - * whether DAG_ONLY and HAVE_DAG_API are defined. If HAVE_DAG_API is not - * defined it should not get compiled in, otherwise if DAG_ONLY is defined then - * the 'dag_' function calls are renamed to 'pcap_' equivalents. If DAG_ONLY - * is not defined then nothing is altered - the dag_ functions will be - * called as required from their pcap-linux/bpf equivalents. - * * Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com) * Modifications: Jesper Peterson * Koryn Grant @@ -258,12 +250,18 @@ dag_platform_cleanup(pcap_t *p) if(pd->dag_ref != NULL) { dag_config_dispose(pd->dag_ref); + /* + * Note: we don't need to call close(p->fd) or + * dag_close(p->fd), as dag_config_dispose(pd->dag_ref) + * does this. + * + * Set p->fd to -1 to make sure that's not done. + */ p->fd = -1; pd->dag_ref = NULL; } delete_pcap_dag(p); pcap_cleanup_live_common(p); - /* Note: don't need to call close(p->fd) or dag_close(p->fd) as dag_config_dispose(pd->dag_ref) does this. */ } static void @@ -722,7 +720,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) static int dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards", PCAP_ERRBUF_SIZE); return (-1); } @@ -746,18 +744,20 @@ static int dag_activate(pcap_t* p) daginf_t* daginf; char * newDev = NULL; char * device = p->opt.device; + int ret; dag_size_t mindata; struct timeval maxwait; struct timeval poll; if (device == NULL) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL"); - return -1; + return PCAP_ERROR; } /* Initialize some components of the pcap structure. */ newDev = (char *)malloc(strlen(device) + 16); if (newDev == NULL) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "Can't allocate string for device name"); goto fail; @@ -765,6 +765,13 @@ static int dag_activate(pcap_t* p) /* Parse input name to get dag device and stream number if provided */ if (dag_parse_name(device, newDev, strlen(device) + 16, &pd->dag_stream) < 0) { + /* + * XXX - it'd be nice if this indicated what was wrong + * with the name. Does this reliably set errno? + * Should this return PCAP_ERROR_NO_SUCH_DEVICE in some + * cases? + */ + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_parse_name"); goto fail; @@ -772,25 +779,40 @@ static int dag_activate(pcap_t* p) device = newDev; if (pd->dag_stream%2) { + ret = PCAP_ERROR; pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: tx (even numbered) streams not supported for capture"); goto fail; } /* setup device parameters */ if((pd->dag_ref = dag_config_init((char *)device)) == NULL) { + /* + * XXX - does this reliably set errno? + */ + if (errno == ENOENT) + ret = PCAP_ERROR_NO_SUCH_DEVICE; + else if (errno == EPERM || errno == EACCES) + ret = PCAP_ERROR_PERM_DENIED; + else + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_config_init %s", device); goto fail; } if((p->fd = dag_config_get_card_fd(pd->dag_ref)) < 0) { + /* + * XXX - does this reliably set errno? + */ + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_config_get_card_fd %s", device); - goto fail; + goto failclose; } /* Open requested stream. Can fail if already locked or on error */ if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_attach_stream"); goto failclose; @@ -809,6 +831,7 @@ static int dag_activate(pcap_t* p) */ if (dag_get_stream_poll64(p->fd, pd->dag_stream, &mindata, &maxwait, &poll) < 0) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_get_stream_poll"); goto faildetach; @@ -853,6 +876,7 @@ static int dag_activate(pcap_t* p) if (dag_set_stream_poll64(p->fd, pd->dag_stream, mindata, &maxwait, &poll) < 0) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_set_stream_poll"); goto faildetach; @@ -875,6 +899,7 @@ static int dag_activate(pcap_t* p) #endif if(dag_start_stream(p->fd, pd->dag_stream) < 0) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "dag_start_stream %s", device); goto faildetach; @@ -910,6 +935,7 @@ static int dag_activate(pcap_t* p) if ((n = atoi(s)) == 0 || n == 16 || n == 32) { pd->dag_fcs_bits = n; } else { + ret = PCAP_ERROR; pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "pcap_activate %s: bad ERF_FCS_BITS value (%d) in environment", device, n); goto failstop; @@ -932,12 +958,15 @@ static int dag_activate(pcap_t* p) pd->dag_timeout = p->opt.timeout; p->linktype = -1; - if (dag_get_datalink(p) < 0) + if (dag_get_datalink(p) < 0) { + ret = PCAP_ERROR; goto failstop; + } p->bufsize = 0; if (new_pcap_dag(p) < 0) { + ret = PCAP_ERROR; pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "new_pcap_dag %s", device); goto failstop; @@ -977,6 +1006,14 @@ faildetach: failclose: dag_config_dispose(pd->dag_ref); + /* + * Note: we don't need to call close(p->fd) or dag_close(p->fd), + * as dag_config_dispose(pd->dag_ref) does this. + * + * Set p->fd to -1 to make sure that's not done. + */ + p->fd = -1; + pd->dag_ref = NULL; delete_pcap_dag(p); fail: @@ -985,7 +1022,7 @@ fail: free((char *)newDev); } - return PCAP_ERROR; + return ret; } pcap_t *dag_create(const char *device, char *ebuf, int *is_ours) @@ -1137,7 +1174,7 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf) } rxstreams = dag_rx_get_stream_count(dagfd); for(stream=0;streamlinktype" and reject the send request if * it's anything other than DLT_EN10MB. */ - strlcpy(p->errbuf, "send: Not supported on this version of this OS", + pcap_strlcpy(p->errbuf, "send: Not supported on this version of this OS", PCAP_ERRBUF_SIZE); ret = -1; #endif /* raw mode */ @@ -363,9 +363,9 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) */ cp = strrchr(name, '/'); if (cp == NULL) - strlcpy(dname, name, sizeof(dname)); + pcap_strlcpy(dname, name, sizeof(dname)); else - strlcpy(dname, cp + 1, sizeof(dname)); + pcap_strlcpy(dname, cp + 1, sizeof(dname)); /* * Split the device name into a device type name and a unit number; @@ -415,7 +415,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) * device name. */ if (*name == '/') - strlcpy(dname, name, sizeof(dname)); + pcap_strlcpy(dname, name, sizeof(dname)); else pcap_snprintf(dname, sizeof(dname), "%s/%s", PCAP_DEV_PREFIX, name); @@ -432,7 +432,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf) * Make a copy of the device pathname, and then remove the unit * number from the device pathname. */ - strlcpy(dname2, dname, sizeof(dname)); + pcap_strlcpy(dname2, dname, sizeof(dname)); *cp = '\0'; /* Try device without unit number */ @@ -968,7 +968,7 @@ dl_dohpuxbind(int fd, char *ebuf) *ebuf = '\0'; hpsap++; if (hpsap > 100) { - strlcpy(ebuf, + pcap_strlcpy(ebuf, "All SAPs from 22 through 100 are in use", PCAP_ERRBUF_SIZE); return (-1); @@ -1547,7 +1547,7 @@ get_release(char *buf, size_t bufsize, bpf_u_int32 *majorp, *minorp = 0; *microp = 0; if (sysinfo(SI_RELEASE, buf, bufsize) < 0) { - strlcpy(buf, "?", bufsize); + pcap_strlcpy(buf, "?", bufsize); return; } cp = buf; diff --git a/libpcap/pcap-dos.c b/libpcap/pcap-dos.c index b1b9ecd72..c159b552a 100644 --- a/libpcap/pcap-dos.c +++ b/libpcap/pcap-dos.c @@ -413,14 +413,14 @@ int pcap_stats_ex (pcap_t *p, struct pcap_stat_ex *se) if (!dev || !dev->get_stats) { - strlcpy (p->errbuf, "detailed device statistics not available", + pcap_strlcpy (p->errbuf, "detailed device statistics not available", PCAP_ERRBUF_SIZE); return (-1); } if (!strnicmp(dev->name,"pkt",3)) { - strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics", + pcap_strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/libpcap/pcap-filter.manmisc.in b/libpcap/pcap-filter.manmisc.in index 3232f7e9d..777e7350c 100644 --- a/libpcap/pcap-filter.manmisc.in +++ b/libpcap/pcap-filter.manmisc.in @@ -29,11 +29,11 @@ pcap-filter \- packet filter syntax is used to compile a string into a filter program. The resulting filter program can then be applied to some stream of packets to determine which packets will be supplied to -.BR pcap_loop() , -.BR pcap_dispatch() , -.BR pcap_next() , +.BR pcap_loop(3PCAP) , +.BR pcap_dispatch(3PCAP) , +.BR pcap_next(3PCAP) , or -.BR pcap_next_ex() . +.BR pcap_next_ex(3PCAP) . .LP The \fIfilter expression\fP consists of one or more .IR primitives . @@ -86,12 +86,6 @@ The and .B addr4 qualifiers are only valid for IEEE 802.11 Wireless LAN link layers. -For some link layers, such as SLIP and the ``cooked'' Linux capture mode -used for the ``any'' device and for some other device types, the -.B inbound -and -.B outbound -qualifiers can be used to specify a desired direction. .IP \fIproto\fP .I proto qualifiers restrict the match to a particular protocol. @@ -466,8 +460,6 @@ Token Ring packets (no check is done for LLC frames); FDDI packets (no check is done for LLC frames); .IP LLC-encapsulated ATM packets, for SunATM on Solaris. -.IP - .IP "\fBllc\fP \Fitype\fR" True if the packet has an 802.2 LLC header and has the specified .IR type . @@ -514,6 +506,16 @@ Exchange Identification (XID) U PDUs \fBfrmr\fR Frame Reject (FRMR) U PDUs .RE +.IP \fBinbound\fP +Packet was received by the host performing the capture rather than being +sent by that host. This is only supported for certain link-layer types, +such as SLIP and the ``cooked'' Linux capture mode +used for the ``any'' device and for some other device types. +.IP \fBoutbound\fP +Packet was sent by the host performing the capture rather than being +received by that host. This is only supported for certain link-layer types, +such as SLIP and the ``cooked'' Linux capture mode +used for the ``any'' device and for some other device types. .IP "\fBifname \fIinterface\fR" True if the packet was logged as coming from the specified interface (applies only to packets logged by OpenBSD's or FreeBSD's diff --git a/libpcap/pcap-int.h b/libpcap/pcap-int.h index 5888df724..5295f8fb4 100644 --- a/libpcap/pcap-int.h +++ b/libpcap/pcap-int.h @@ -86,7 +86,12 @@ extern "C" { * 2) small enough not to cause attempts to allocate huge amounts of * memory; some applications might use the snapshot length in a * savefile header to control the size of the buffer they allocate, - * so a size of, say, 2^31-1 might not work well. + * so a size of, say, 2^31-1 might not work well. (libpcap uses it + * as a hint, but doesn't start out allocating a buffer bigger than + * 2 KiB, and grows the buffer as necessary, but not beyond the + * per-linktype maximum snapshot length. Other code might naively + * use it; we want to avoid writing a too-large snapshot length, + * in order not to cause that code problems.) * * We don't enforce this in pcap_set_snaplen(), but we use it internally. */ @@ -472,13 +477,38 @@ int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32, * "pcap_open_offline_common()" allocates and fills in a pcap_t, for use * by pcap_open_offline routines. * + * "pcap_adjust_snapshot()" adjusts the snapshot to be non-zero and + * fit within an int. + * * "sf_cleanup()" closes the file handle associated with a pcap_t, if * appropriate, and frees all data common to all modules for handling * savefile types. */ pcap_t *pcap_open_offline_common(char *ebuf, size_t size); +bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen); void sf_cleanup(pcap_t *p); +/* + * Internal interfaces for doing user-mode filtering of packets and + * validating filter programs. + */ +/* + * Auxiliary data, for use when interpreting a filter intended for the + * Linux kernel when the kernel rejects the filter (requiring us to + * run it in userland). It contains VLAN tag information. + */ +struct bpf_aux_data { + u_short vlan_tag_present; + u_short vlan_tag; +}; + +/* + * Filtering routine that takes the auxiliary data as an additional + * argument. + */ +u_int bpf_filter_with_aux_data(const struct bpf_insn *, + const u_char *, u_int, u_int, const struct bpf_aux_data *); + /* * Internal interfaces for both "pcap_create()" and routines that * open savefiles. @@ -488,10 +518,6 @@ void sf_cleanup(pcap_t *p); */ void pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *); -#ifdef _WIN32 -void pcap_win32_err_to_str(DWORD, char *); -#endif - int install_bpf_program(pcap_t *, struct bpf_program *); int pcap_strcasecmp(const char *, const char *); diff --git a/libpcap/pcap-libdlpi.c b/libpcap/pcap-libdlpi.c index a0d16693f..a38da8b6d 100644 --- a/libpcap/pcap-libdlpi.c +++ b/libpcap/pcap-libdlpi.c @@ -80,7 +80,7 @@ list_interfaces(const char *linkname, void *arg) lwp->lw_err = ENOMEM; return (B_TRUE); } - (void) strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX); + (void) pcap_strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX); if (lwp->lw_list == NULL) { lwp->lw_list = entry; diff --git a/libpcap/pcap-linktype.manmisc.in b/libpcap/pcap-linktype.manmisc.in index 68919a788..777e9dc73 100644 --- a/libpcap/pcap-linktype.manmisc.in +++ b/libpcap/pcap-linktype.manmisc.in @@ -45,4 +45,4 @@ The names for those values begin with The link-layer header types supported by libpcap are described at https://www.tcpdump.org/linktypes.html. .SH SEE ALSO -pcap_datalink(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap-linux.c b/libpcap/pcap-linux.c index 49144b644..70334b3c8 100644 --- a/libpcap/pcap-linux.c +++ b/libpcap/pcap-linux.c @@ -339,9 +339,6 @@ struct pcap_linux { static int get_if_flags(const char *, bpf_u_int32 *, char *); static int is_wifi(int, const char *); static void map_arphrd_to_dlt(pcap_t *, int, int, const char *, int); -#ifdef HAVE_PF_PACKET_SOCKETS -static short int map_packet_type_to_sll_type(short int); -#endif static int pcap_activate_linux(pcap_t *); static int activate_old(pcap_t *); static int activate_new(pcap_t *); @@ -486,7 +483,7 @@ static int iface_bind_old(int fd, const char *device, char *ebuf); #ifdef SO_ATTACH_FILTER static int fix_program(pcap_t *handle, struct sock_fprog *fcode, int is_mapped); -static int fix_offset(struct bpf_insn *p); +static int fix_offset(pcap_t *handle, struct bpf_insn *p); static int set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode); static int reset_kernel_filter(pcap_t *handle); @@ -977,7 +974,7 @@ added: * Now configure the monitor interface up. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->mondevice, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handlep->mondevice, sizeof(ifr.ifr_name)); if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "%s: Can't get flags for %s", device, @@ -1038,7 +1035,7 @@ is_bonding_device(int fd, const char *device) ifbond ifb; memset(&ifr, 0, sizeof ifr); - strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name); + pcap_strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name); memset(&ifb, 0, sizeof ifb); ifr.ifr_data = (caddr_t)&ifb; if (ioctl(fd, BOND_INFO_QUERY_IOCTL, &ifr) == 0) @@ -1127,7 +1124,7 @@ pcap_can_set_rfmon_linux(pcap_t *handle) /* * Attempt to get the current mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, handle->opt.device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, handle->opt.device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWMODE, &ireq) != -1) { /* @@ -1160,16 +1157,16 @@ static long int linux_if_drops(const char * if_name) { char buffer[512]; - char * bufptr; - FILE * file; - int field_to_convert = 3, if_name_sz = strlen(if_name); + FILE *file; + char *bufptr, *nameptr, *colonptr; + int field_to_convert = 3; long int dropped_pkts = 0; file = fopen("/proc/net/dev", "r"); if (!file) return 0; - while (!dropped_pkts && fgets( buffer, sizeof(buffer), file )) + while (fgets(buffer, sizeof(buffer), file) != NULL) { /* search for 'bytes' -- if its in there, then that means we need to grab the fourth field. otherwise @@ -1180,26 +1177,71 @@ linux_if_drops(const char * if_name) continue; } - /* find iface and make sure it actually matches -- space before the name and : after it */ - if ((bufptr = strstr(buffer, if_name)) && - (bufptr == buffer || *(bufptr-1) == ' ') && - *(bufptr + if_name_sz) == ':') + /* + * See whether this line corresponds to this device. + * The line should have zero or more leading blanks, + * followed by a device name, followed by a colon, + * followed by the statistics. + */ + bufptr = buffer; + /* Skip leading blanks */ + while (*bufptr == ' ') + bufptr++; + nameptr = bufptr; + /* Look for the colon */ + colonptr = strchr(nameptr, ':'); + if (colonptr == NULL) { - bufptr = bufptr + if_name_sz + 1; + /* + * Not found; this could, for example, be the + * header line. + */ + continue; + } + /* Null-terminate the interface name. */ + *colonptr = '\0'; + if (strcmp(if_name, nameptr) == 0) + { + /* + * OK, this line has the statistics for the interface. + * Skip past the interface name. + */ + bufptr = colonptr + 1; /* grab the nth field from it */ - while( --field_to_convert && *bufptr != '\0') + while (--field_to_convert && *bufptr != '\0') { - while (*bufptr != '\0' && *(bufptr++) == ' '); - while (*bufptr != '\0' && *(bufptr++) != ' '); + /* + * This isn't the field we want. + * First, skip any leading blanks before + * the field. + */ + while (*bufptr == ' ') + bufptr++; + + /* + * Now skip the non-blank characters of + * the field. + */ + while (*bufptr != '\0' && *bufptr != ' ') + bufptr++; } - /* get rid of any final spaces */ - while (*bufptr != '\0' && *bufptr == ' ') bufptr++; - - if (*bufptr != '\0') - dropped_pkts = strtol(bufptr, NULL, 10); + if (field_to_convert == 0) + { + /* + * We've found the field we want. + * Skip any leading blanks before it. + */ + while (*bufptr == ' ') + bufptr++; + /* + * Now extract the value, if we have one. + */ + if (*bufptr != '\0') + dropped_pkts = strtol(bufptr, NULL, 10); + } break; } } @@ -1250,7 +1292,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) * in 2.0[.x] kernels. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->device, + pcap_strlcpy(ifr.ifr_name, handlep->device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) { fprintf(stderr, @@ -1314,7 +1356,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) */ oldflags = 0; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handlep->device, + pcap_strlcpy(ifr.ifr_name, handlep->device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) != -1) { if (ifr.ifr_flags & IFF_UP) { @@ -1328,7 +1370,7 @@ static void pcap_cleanup_linux( pcap_t *handle ) /* * Now restore the mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, handlep->device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, handlep->device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.mode = handlep->oldmode; if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) { @@ -1538,7 +1580,8 @@ pcap_activate_linux(pcap_t *handle) if (handlep->device == NULL) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "strdup"); - return PCAP_ERROR; + status = PCAP_ERROR; + goto fail; } /* copy timeout value */ @@ -1602,11 +1645,10 @@ pcap_activate_linux(pcap_t *handle) /* * We failed to set up to use it, or the kernel * supports it, but we failed to enable it. - * ret has been set to the error status to + * status has been set to the error status to * return and, if it's PCAP_ERROR, handle->errbuf * contains the error message. */ - status = ret; goto fail; } } @@ -1750,7 +1792,6 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) int offset; #ifdef HAVE_PF_PACKET_SOCKETS struct sockaddr_ll from; - struct sll_header *hdrp; #else struct sockaddr from; #endif @@ -1774,9 +1815,12 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) * If this is a cooked device, leave extra room for a * fake packet header. */ - if (handlep->cooked) - offset = SLL_HDR_LEN; - else + if (handlep->cooked) { + if (handle->linktype == DLT_LINUX_SLL2) + offset = SLL2_HDR_LEN; + else + offset = SLL_HDR_LEN; + } else offset = 0; #else /* @@ -1906,17 +1950,37 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) * Add the length of the fake header to the length * of packet data we read. */ - packet_len += SLL_HDR_LEN; + if (handle->linktype == DLT_LINUX_SLL2) { + struct sll2_header *hdrp; - hdrp = (struct sll_header *)bp; - hdrp->sll_pkttype = map_packet_type_to_sll_type(from.sll_pkttype); - hdrp->sll_hatype = htons(from.sll_hatype); - hdrp->sll_halen = htons(from.sll_halen); - memcpy(hdrp->sll_addr, from.sll_addr, - (from.sll_halen > SLL_ADDRLEN) ? - SLL_ADDRLEN : - from.sll_halen); - hdrp->sll_protocol = from.sll_protocol; + packet_len += SLL2_HDR_LEN; + + hdrp = (struct sll2_header *)bp; + hdrp->sll2_protocol = from.sll_protocol; + hdrp->sll2_reserved_mbz = 0; + hdrp->sll2_if_index = htonl(from.sll_ifindex); + hdrp->sll2_hatype = htons(from.sll_hatype); + hdrp->sll2_pkttype = from.sll_pkttype; + hdrp->sll2_halen = from.sll_halen; + memcpy(hdrp->sll2_addr, from.sll_addr, + (from.sll_halen > SLL_ADDRLEN) ? + SLL_ADDRLEN : + from.sll_halen); + } else { + struct sll_header *hdrp; + + packet_len += SLL_HDR_LEN; + + hdrp = (struct sll_header *)bp; + hdrp->sll_pkttype = htons(from.sll_pkttype); + hdrp->sll_hatype = htons(from.sll_hatype); + hdrp->sll_halen = htons(from.sll_halen); + memcpy(hdrp->sll_addr, from.sll_addr, + (from.sll_halen > SLL_ADDRLEN) ? + SLL_ADDRLEN : + from.sll_halen); + hdrp->sll_protocol = from.sll_protocol; + } } /* @@ -2121,7 +2185,7 @@ pcap_inject_linux(pcap_t *handle, const void *buf, size_t size) /* * We don't support sending on the "any" device. */ - strlcpy(handle->errbuf, + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported on the \"any\" device", PCAP_ERRBUF_SIZE); return (-1); @@ -2129,13 +2193,13 @@ pcap_inject_linux(pcap_t *handle, const void *buf, size_t size) if (handlep->cooked) { /* - * We don't support sending on the "any" device. + * We don't support sending on cooked-mode sockets. * * XXX - how do you send on a bound cooked-mode * socket? * Is a "sendto()" required there? */ - strlcpy(handle->errbuf, + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported in cooked mode", PCAP_ERRBUF_SIZE); return (-1); @@ -2349,7 +2413,7 @@ add_linux_if(pcap_if_list_t *devlistp, const char *ifname, int fd, char *errbuf) /* * Get the flags for this interface. */ - strlcpy(ifrflags.ifr_name, name, sizeof(ifrflags.ifr_name)); + pcap_strlcpy(ifrflags.ifr_name, name, sizeof(ifrflags.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifrflags) < 0) { if (errno == ENXIO || errno == ENODEV) return (0); /* device doesn't actually exist - ignore it */ @@ -2708,7 +2772,7 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf) #ifdef ETHTOOL_GLINK memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); info.cmd = ETHTOOL_GLINK; ifr.ifr_data = (caddr_t)&info; if (ioctl(sock, SIOCETHTOOL, &ifr) == -1) { @@ -2836,7 +2900,7 @@ pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter, if (!handle) return -1; if (!filter) { - strlcpy(handle->errbuf, "setfilter: No filter specified", + pcap_strlcpy(handle->errbuf, "setfilter: No filter specified", PCAP_ERRBUF_SIZE); return -1; } @@ -3025,41 +3089,6 @@ pcap_setdirection_linux(pcap_t *handle, pcap_direction_t d) return -1; } -#ifdef HAVE_PF_PACKET_SOCKETS -/* - * Map the PACKET_ value to a LINUX_SLL_ value; we - * want the same numerical value to be used in - * the link-layer header even if the numerical values - * for the PACKET_ #defines change, so that programs - * that look at the packet type field will always be - * able to handle DLT_LINUX_SLL captures. - */ -static short int -map_packet_type_to_sll_type(short int sll_pkttype) -{ - switch (sll_pkttype) { - - case PACKET_HOST: - return htons(LINUX_SLL_HOST); - - case PACKET_BROADCAST: - return htons(LINUX_SLL_BROADCAST); - - case PACKET_MULTICAST: - return htons(LINUX_SLL_MULTICAST); - - case PACKET_OTHERHOST: - return htons(LINUX_SLL_OTHERHOST); - - case PACKET_OUTGOING: - return htons(LINUX_SLL_OUTGOING); - - default: - return -1; - } -} -#endif - static int is_wifi(int sock_fd #ifndef IW_MODE_MONITOR @@ -3558,6 +3587,45 @@ static void map_arphrd_to_dlt(pcap_t *handle, int sock_fd, int arptype, /* ===== Functions to interface to the newer kernels ================== */ +#ifdef PACKET_RESERVE +static void +set_dlt_list_cooked(pcap_t *handle, int sock_fd) +{ + socklen_t len; + unsigned int tp_reserve; + + /* + * If we can't do PACKET_RESERVE, we can't reserve extra space + * for a DLL_LINUX_SLL2 header, so we can't support DLT_LINUX_SLL2. + */ + len = sizeof(tp_reserve); + if (getsockopt(sock_fd, SOL_PACKET, PACKET_RESERVE, &tp_reserve, + &len) == 0) { + /* + * Yes, we can do DLL_LINUX_SLL2. + */ + handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2); + /* + * If that fails, just leave the list empty. + */ + if (handle->dlt_list != NULL) { + handle->dlt_list[0] = DLT_LINUX_SLL; + handle->dlt_list[1] = DLT_LINUX_SLL2; + handle->dlt_count = 2; + } + } +} +#else +/* + * The build environment doesn't define PACKET_RESERVE, so we can't reserve + * extra space for a DLL_LINUX_SLL2 header, so we can't support DLT_LINUX_SLL2. + */ +static void +set_dlt_list_cooked(pcap_t *handle _U_, int sock_fd _U_) +{ +} +#endif + /* * Try to open a packet socket using the new kernel PF_PACKET interface. * Returns 1 on success, 0 on an error that means the new interface isn't @@ -3573,7 +3641,7 @@ activate_new(pcap_t *handle) const char *device = handle->opt.device; int is_any_device = (strcmp(device, "any") == 0); int protocol = pcap_protocol(handle); - int sock_fd = -1, arptype; + int sock_fd = -1, arptype, ret; #ifdef HAVE_PACKET_AUXDATA int val; #endif @@ -3602,21 +3670,21 @@ activate_new(pcap_t *handle) */ return 0; } - - pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, - errno, "socket"); if (errno == EPERM || errno == EACCES) { /* * You don't have permission to open the * socket. */ - return PCAP_ERROR_PERM_DENIED; + ret = PCAP_ERROR_PERM_DENIED; } else { /* * Other error. */ - return PCAP_ERROR; + ret = PCAP_ERROR; } + pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, + errno, "socket"); + return ret; } /* It seems the kernel supports the new interface. */ @@ -3711,20 +3779,21 @@ activate_new(pcap_t *handle) } sock_fd = socket(PF_PACKET, SOCK_DGRAM, protocol); if (sock_fd == -1) { - pcap_fmt_errmsg_for_errno(handle->errbuf, - PCAP_ERRBUF_SIZE, errno, "socket"); if (errno == EPERM || errno == EACCES) { /* * You don't have permission to * open the socket. */ - return PCAP_ERROR_PERM_DENIED; + ret = PCAP_ERROR_PERM_DENIED; } else { /* * Other error. */ - return PCAP_ERROR; + ret = PCAP_ERROR; } + pcap_fmt_errmsg_for_errno(handle->errbuf, + PCAP_ERRBUF_SIZE, errno, "socket"); + return ret; } handlep->cooked = 1; @@ -3737,6 +3806,7 @@ activate_new(pcap_t *handle) free(handle->dlt_list); handle->dlt_list = NULL; handle->dlt_count = 0; + set_dlt_list_cooked(handle, sock_fd); } if (handle->linktype == -1) { @@ -3797,6 +3867,9 @@ activate_new(pcap_t *handle) */ handlep->cooked = 1; handle->linktype = DLT_LINUX_SLL; + handle->dlt_list = NULL; + handle->dlt_count = 0; + set_dlt_list_cooked(handle, sock_fd); /* * We're not bound to a device. @@ -3837,7 +3910,7 @@ activate_new(pcap_t *handle) if (setsockopt(sock_fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, - PCAP_ERRBUF_SIZE, errno, "setsockopt"); + PCAP_ERRBUF_SIZE, errno, "setsockopt (PACKET_ADD_MEMBERSHIP)"); close(sock_fd); return PCAP_ERROR; } @@ -3850,7 +3923,7 @@ activate_new(pcap_t *handle) if (setsockopt(sock_fd, SOL_PACKET, PACKET_AUXDATA, &val, sizeof(val)) == -1 && errno != ENOPROTOOPT) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, - errno, "setsockopt"); + errno, "setsockopt (PACKET_AUXDATA)"); close(sock_fd); return PCAP_ERROR; } @@ -3870,10 +3943,14 @@ activate_new(pcap_t *handle) * large enough to hold a "cooked mode" header plus * 1 byte of packet data (so we don't pass a byte * count of 0 to "recvfrom()"). + * XXX - we don't know whether this will be DLT_LINUX_SLL + * or DLT_LINUX_SLL2, so make sure it's big enough for + * a DLT_LINUX_SLL2 "cooked mode" header; a snapshot length + * that small is silly anyway. */ if (handlep->cooked) { - if (handle->snapshot < SLL_HDR_LEN + 1) - handle->snapshot = SLL_HDR_LEN + 1; + if (handle->snapshot < SLL2_HDR_LEN + 1) + handle->snapshot = SLL2_HDR_LEN + 1; } handle->bufsize = handle->snapshot; @@ -3940,7 +4017,7 @@ activate_new(pcap_t *handle) return 1; #else /* HAVE_PF_PACKET_SOCKETS */ - strlcpy(ebuf, + pcap_strlcpy(ebuf, "New packet capturing interface not supported by build " "environment", PCAP_ERRBUF_SIZE); return 0; @@ -4070,10 +4147,20 @@ init_tpacket(pcap_t *handle, int version, const char *version_str) /* * Probe whether kernel supports the specified TPACKET version; * this also gets the length of the header for that version. + * + * This socket option was introduced in 2.6.27, which was + * also the first release with TPACKET_V2 support. */ if (getsockopt(handle->fd, SOL_PACKET, PACKET_HDRLEN, &val, &len) < 0) { - if (errno == ENOPROTOOPT || errno == EINVAL) + if (errno == ENOPROTOOPT || errno == EINVAL) { + /* + * ENOPROTOOPT means the kernel is too old to + * support PACKET_HDRLEN at all, which means + * it either doesn't support TPACKET at all + * or supports only TPACKET_V1. + */ return 1; /* no */ + } /* Failed to even find out; this is a fatal error. */ pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, @@ -4092,7 +4179,10 @@ init_tpacket(pcap_t *handle, int version, const char *version_str) } handlep->tp_version = version; - /* Reserve space for VLAN tag reconstruction */ + /* + * Reserve space for VLAN tag reconstruction. + * This option was also introduced in 2.6.27. + */ val = VLAN_TAG_LEN; if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, &val, sizeof(val)) < 0) { @@ -4203,7 +4293,10 @@ prepare_tpacket_socket(pcap_t *handle) #endif /* HAVE_TPACKET2 */ /* - * OK, we're using TPACKET_V1, as that's all the kernel supports. + * OK, we're using TPACKET_V1, as either that's all the kernel + * supports or it doesn't support TPACKET at all. In the latter + * case, create_ring() will fail, and we'll fall back on non- + * memory-mapped capture. */ handlep->tp_version = TPACKET_V1; handlep->tp_hdrlen = sizeof(struct tpacket_hdr); @@ -4359,7 +4452,7 @@ create_ring(pcap_t *handle, int *status) if (getsockopt(handle->fd, SOL_SOCKET, SO_TYPE, &sk_type, &len) < 0) { pcap_fmt_errmsg_for_errno(handle->errbuf, - PCAP_ERRBUF_SIZE, errno, "getsockopt"); + PCAP_ERRBUF_SIZE, errno, "getsockopt (SO_TYPE)"); *status = PCAP_ERROR; return -1; } @@ -4374,14 +4467,50 @@ create_ring(pcap_t *handle, int *status) * as best we can. */ pcap_fmt_errmsg_for_errno(handle->errbuf, - PCAP_ERRBUF_SIZE, errno, "getsockopt"); + PCAP_ERRBUF_SIZE, errno, + "getsockopt (PACKET_RESERVE)"); + *status = PCAP_ERROR; + return -1; + } + /* + * Older kernel, so we can't use PACKET_RESERVE; + * this means we can't reserver extra space + * for a DLT_LINUX_SLL2 header. + */ + tp_reserve = 0; + } else { + /* + * We can reserve extra space for a DLT_LINUX_SLL2 + * header. Do so. + * + * XXX - we assume that the kernel is still adding + * 16 bytes of extra space; that happens to + * correspond to SLL_HDR_LEN (whether intentionally + * or not - the kernel code has a raw "16" in + * the expression), so we subtract SLL_HDR_LEN + * from SLL2_HDR_LEN to get the additional space + * needed. + * + * XXX - should we use TPACKET_ALIGN(SLL2_HDR_LEN - SLL_HDR_LEN)? + */ + tp_reserve += SLL2_HDR_LEN - SLL_HDR_LEN; + len = sizeof(tp_reserve); + if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, + &tp_reserve, len) < 0) { + pcap_fmt_errmsg_for_errno(handle->errbuf, + PCAP_ERRBUF_SIZE, errno, + "setsockopt (PACKET_RESERVE)"); *status = PCAP_ERROR; return -1; } - tp_reserve = 0; /* older kernel, reserve not supported */ } #else - tp_reserve = 0; /* older kernel, reserve not supported */ + /* + * Build environment for an older kernel, so we can't + * use PACKET_RESERVE; this means we can't reserve + * extra space for a DLT_LINUX_SLL2 header. + */ + tp_reserve = 0; #endif maclen = (sk_type == SOCK_DGRAM) ? 0 : MAX_LINKHEADER_SIZE; /* XXX: in the kernel maclen is calculated from @@ -4425,6 +4554,49 @@ create_ring(pcap_t *handle, int *status) #ifdef HAVE_TPACKET3 case TPACKET_V3: + /* + * If we have TPACKET_V3, we have PACKET_RESERVE. + */ + len = sizeof(tp_reserve); + if (getsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, + &tp_reserve, &len) < 0) { + /* + * Even ENOPROTOOPT is an error - we wouldn't + * be here if the kernel didn't support + * TPACKET_V3, which means it supports + * PACKET_RESERVE. + */ + pcap_fmt_errmsg_for_errno(handle->errbuf, + PCAP_ERRBUF_SIZE, errno, + "getsockopt (PACKET_RESERVE)"); + *status = PCAP_ERROR; + return -1; + } + /* + * We can reserve extra space for a DLT_LINUX_SLL2 + * header. Do so. + * + * XXX - we assume that the kernel is still adding + * 16 bytes of extra space; that happens to + * correspond to SLL_HDR_LEN (whether intentionally + * or not - the kernel code has a raw "16" in + * the expression), so we subtract SLL_HDR_LEN + * from SLL2_HDR_LEN to get the additional space + * needed. + * + * XXX - should we use TPACKET_ALIGN(SLL2_HDR_LEN - SLL_HDR_LEN)? + */ + tp_reserve += SLL2_HDR_LEN - SLL_HDR_LEN; + len = sizeof(tp_reserve); + if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, + &tp_reserve, len) < 0) { + pcap_fmt_errmsg_for_errno(handle->errbuf, + PCAP_ERRBUF_SIZE, errno, + "setsockopt (PACKET_RESERVE)"); + *status = PCAP_ERROR; + return -1; + } + /* The "frames" for this are actually buffers that * contain multiple variable-sized frames. * @@ -4496,7 +4668,7 @@ create_ring(pcap_t *handle, int *status) hwconfig.rx_filter = HWTSTAMP_FILTER_ALL; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); ifr.ifr_data = (void *)&hwconfig; if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) { @@ -4580,7 +4752,26 @@ retry: #ifdef HAVE_TPACKET3 /* timeout value to retire block - use the configured buffering timeout, or default if <0. */ - req.tp_retire_blk_tov = (handlep->timeout>=0)?handlep->timeout:0; + if (handlep->timeout > 0) { + /* Use the user specified timeout as the block timeout */ + req.tp_retire_blk_tov = handlep->timeout; + } else if (handlep->timeout == 0) { + /* + * In pcap, this means "infinite timeout"; TPACKET_V3 + * doesn't support that, so just set it to UINT_MAX + * milliseconds. In the TPACKET_V3 loop, if the + * timeout is 0, and we haven't yet seen any packets, + * and we block and still don't have any packets, we + * keep blocking until we do. + */ + req.tp_retire_blk_tov = UINT_MAX; + } else { + /* + * XXX - this is not valid; use 0, meaning "have the + * kernel pick a default", for now. + */ + req.tp_retire_blk_tov = 0; + } /* private data not used */ req.tp_sizeof_priv = 0; /* Rx ring - feature request bits - none (rxhash will not be filled) */ @@ -4908,13 +5099,27 @@ static int pcap_handle_packet_mmap( struct sockaddr_ll *sll; struct pcap_pkthdr pcaphdr; unsigned int snaplen = tp_snaplen; + struct utsname utsname; /* perform sanity check on internal offset. */ if (tp_mac + tp_snaplen > handle->bufsize) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "corrupted frame on kernel ring mac " - "offset %u + caplen %u > frame len %d", - tp_mac, tp_snaplen, handle->bufsize); + /* + * Report some system information as a debugging aid. + */ + if (uname(&utsname) != -1) { + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "corrupted frame on kernel ring mac " + "offset %u + caplen %u > frame len %d " + "(kernel %.32s version %s, machine %.16s)", + tp_mac, tp_snaplen, handle->bufsize, + utsname.release, utsname.version, + utsname.machine); + } else { + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "corrupted frame on kernel ring mac " + "offset %u + caplen %u > frame len %d", + tp_mac, tp_snaplen, handle->bufsize); + } return -1; } @@ -4932,44 +5137,85 @@ static int pcap_handle_packet_mmap( /* if required build in place the sll header*/ sll = (void *)frame + TPACKET_ALIGN(handlep->tp_hdrlen); if (handlep->cooked) { - struct sll_header *hdrp; + if (handle->linktype == DLT_LINUX_SLL2) { + struct sll2_header *hdrp; - /* - * The kernel should have left us with enough - * space for an sll header; back up the packet - * data pointer into that space, as that'll be - * the beginning of the packet we pass to the - * callback. - */ - bp -= SLL_HDR_LEN; + /* + * The kernel should have left us with enough + * space for an sll header; back up the packet + * data pointer into that space, as that'll be + * the beginning of the packet we pass to the + * callback. + */ + bp -= SLL2_HDR_LEN; - /* - * Let's make sure that's past the end of - * the tpacket header, i.e. >= - * ((u_char *)thdr + TPACKET_HDRLEN), so we - * don't step on the header when we construct - * the sll header. - */ - if (bp < (u_char *)frame + - TPACKET_ALIGN(handlep->tp_hdrlen) + - sizeof(struct sockaddr_ll)) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, - "cooked-mode frame doesn't have room for sll header"); - return -1; + /* + * Let's make sure that's past the end of + * the tpacket header, i.e. >= + * ((u_char *)thdr + TPACKET_HDRLEN), so we + * don't step on the header when we construct + * the sll header. + */ + if (bp < (u_char *)frame + + TPACKET_ALIGN(handlep->tp_hdrlen) + + sizeof(struct sockaddr_ll)) { + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "cooked-mode frame doesn't have room for sll header"); + return -1; + } + + /* + * OK, that worked; construct the sll header. + */ + hdrp = (struct sll2_header *)bp; + hdrp->sll2_protocol = sll->sll_protocol; + hdrp->sll2_reserved_mbz = 0; + hdrp->sll2_if_index = htonl(sll->sll_ifindex); + hdrp->sll2_hatype = htons(sll->sll_hatype); + hdrp->sll2_pkttype = sll->sll_pkttype; + hdrp->sll2_halen = sll->sll_halen; + memcpy(hdrp->sll2_addr, sll->sll_addr, SLL_ADDRLEN); + + snaplen += sizeof(struct sll2_header); + } else { + struct sll_header *hdrp; + + /* + * The kernel should have left us with enough + * space for an sll header; back up the packet + * data pointer into that space, as that'll be + * the beginning of the packet we pass to the + * callback. + */ + bp -= SLL_HDR_LEN; + + /* + * Let's make sure that's past the end of + * the tpacket header, i.e. >= + * ((u_char *)thdr + TPACKET_HDRLEN), so we + * don't step on the header when we construct + * the sll header. + */ + if (bp < (u_char *)frame + + TPACKET_ALIGN(handlep->tp_hdrlen) + + sizeof(struct sockaddr_ll)) { + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "cooked-mode frame doesn't have room for sll header"); + return -1; + } + + /* + * OK, that worked; construct the sll header. + */ + hdrp = (struct sll_header *)bp; + hdrp->sll_pkttype = htons(sll->sll_pkttype); + hdrp->sll_hatype = htons(sll->sll_hatype); + hdrp->sll_halen = htons(sll->sll_halen); + memcpy(hdrp->sll_addr, sll->sll_addr, SLL_ADDRLEN); + hdrp->sll_protocol = sll->sll_protocol; + + snaplen += sizeof(struct sll_header); } - - /* - * OK, that worked; construct the sll header. - */ - hdrp = (struct sll_header *)bp; - hdrp->sll_pkttype = map_packet_type_to_sll_type( - sll->sll_pkttype); - hdrp->sll_hatype = htons(sll->sll_hatype); - hdrp->sll_halen = htons(sll->sll_halen); - memcpy(hdrp->sll_addr, sll->sll_addr, SLL_ADDRLEN); - hdrp->sll_protocol = sll->sll_protocol; - - snaplen += sizeof(struct sll_header); } if (handlep->filter_in_userland && handle->fcode.bf_insns) { @@ -4998,8 +5244,13 @@ static int pcap_handle_packet_mmap( /* if required build in place the sll header*/ if (handlep->cooked) { /* update packet len */ - pcaphdr.caplen += SLL_HDR_LEN; - pcaphdr.len += SLL_HDR_LEN; + if (handle->linktype == DLT_LINUX_SLL2) { + pcaphdr.caplen += SLL2_HDR_LEN; + pcaphdr.len += SLL2_HDR_LEN; + } else { + pcaphdr.caplen += SLL_HDR_LEN; + pcaphdr.len += SLL_HDR_LEN; + } } #if defined(HAVE_TPACKET2) || defined(HAVE_TPACKET3) @@ -5521,7 +5772,7 @@ iface_get_id(int fd, const char *device, char *ebuf) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFINDEX, &ifr) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -5570,7 +5821,7 @@ iface_bind(int fd, int ifindex, char *ebuf, int protocol) if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, - errno, "getsockopt"); + errno, "getsockopt (SO_ERROR)"); return 0; } @@ -5602,19 +5853,22 @@ static int has_wext(int sock_fd, const char *device, char *ebuf) { struct iwreq ireq; + int ret; if (is_bonding_device(sock_fd, device)) return 0; /* bonding device, so don't even try */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWNAME, &ireq) >= 0) return 1; /* yes */ + if (errno == ENODEV) + ret = PCAP_ERROR_NO_SUCH_DEVICE; + else + ret = 0; pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "%s: SIOCGIWNAME", device); - if (errno == ENODEV) - return PCAP_ERROR_NO_SUCH_DEVICE; - return 0; + return ret; } /* @@ -5743,7 +5997,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * return EOPNOTSUPP. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.pointer = (void *)args; ireq.u.data.length = 0; @@ -5943,7 +6197,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) /* * Get the old mode. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWMODE, &ireq) == -1) { /* @@ -5999,7 +6253,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * If it fails, just fall back on SIOCSIWMODE. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.length = 1; /* 1 argument */ args[0] = 3; /* request Prism header */ @@ -6031,7 +6285,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * might get EBUSY. */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "%s: Can't get flags", device); @@ -6052,7 +6306,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) /* * Then turn monitor mode on. */ - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.mode = IW_MODE_MONITOR; if (ioctl(sock_fd, SIOCSIWMODE, &ireq) == -1) { @@ -6092,7 +6346,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Try to select the radiotap header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 3; /* request radiotap header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6103,7 +6357,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * That failed. Try to select the AVS header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 2; /* request AVS header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6114,7 +6368,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * That failed. Try to select the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6132,7 +6386,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Select the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 3; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6144,7 +6398,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Get the current channel. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); if (ioctl(sock_fd, SIOCGIWFREQ, &ireq) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, @@ -6158,7 +6412,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * current value. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ args[1] = channel; /* set channel */ @@ -6172,7 +6426,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 0; /* disallow transmitting */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6184,7 +6438,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6196,7 +6450,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); ireq.u.data.length = 1; /* 1 argument */ ireq.u.data.pointer = "1"; @@ -6209,7 +6463,7 @@ enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) * Force the Prism header. */ memset(&ireq, 0, sizeof ireq); - strlcpy(ireq.ifr_ifrn.ifrn_name, device, + pcap_strlcpy(ireq.ifr_ifrn.ifrn_name, device, sizeof ireq.ifr_ifrn.ifrn_name); args[0] = 1; /* request Prism header */ memcpy(ireq.u.name, args, sizeof (int)); @@ -6357,7 +6611,7 @@ iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf) } memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GET_TS_INFO; ifr.ifr_data = (caddr_t)&info; @@ -6471,21 +6725,35 @@ iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf _U_) * if SIOCETHTOOL isn't defined, or we don't have any #defines for any * of the types of offloading, there's nothing we can do to check, so * we just say "no, we don't". + * + * We treat EOPNOTSUPP, EINVAL and, if eperm_ok is true, EPERM as + * indications that the operation isn't supported. We do EPERM + * weirdly because the SIOCETHTOOL code in later kernels 1) doesn't + * support ETHTOOL_GUFO, 2) also doesn't include it in the list + * of ethtool operations that don't require CAP_NET_ADMIN privileges, + * and 3) does the "is this permitted" check before doing the "is + * this even supported" check, so it fails with "this is not permitted" + * rather than "this is not even supported". To work around this + * annoyance, we only treat EPERM as an error for the first feature, + * and assume that they all do the same permission checks, so if the + * first one is allowed all the others are allowed if supported. */ #if defined(SIOCETHTOOL) && (defined(ETHTOOL_GTSO) || defined(ETHTOOL_GUFO) || defined(ETHTOOL_GGSO) || defined(ETHTOOL_GFLAGS) || defined(ETHTOOL_GGRO)) static int -iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname) +iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname, + int eperm_ok) { struct ifreq ifr; struct ethtool_value eval; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name)); eval.cmd = cmd; eval.data = 0; ifr.ifr_data = (caddr_t)&eval; if (ioctl(handle->fd, SIOCETHTOOL, &ifr) == -1) { - if (errno == EOPNOTSUPP || errno == EINVAL) { + if (errno == EOPNOTSUPP || errno == EINVAL || + (errno == EPERM && eperm_ok)) { /* * OK, let's just return 0, which, in our * case, either means "no, what we're asking @@ -6502,34 +6770,41 @@ iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname) return eval.data; } +/* + * XXX - it's annoying that we have to check for offloading at all, but, + * given that we have to, it's still annoying that we have to check for + * particular types of offloading, especially that shiny new types of + * offloading may be added - and, worse, may not be checkable with + * a particular ETHTOOL_ operation; ETHTOOL_GFEATURES would, in + * theory, give those to you, but the actual flags being used are + * opaque (defined in a non-uapi header), and there doesn't seem to + * be any obvious way to ask the kernel what all the offloading flags + * are - at best, you can ask for a set of strings(!) to get *names* + * for various flags. (That whole mechanism appears to have been + * designed for the sole purpose of letting ethtool report flags + * by name and set flags by name, with the names having no semantics + * ethtool understands.) + */ static int iface_get_offload(pcap_t *handle) { int ret; #ifdef ETHTOOL_GTSO - ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GTSO, "ETHTOOL_GTSO"); + ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GTSO, "ETHTOOL_GTSO", 0); if (ret == -1) return -1; if (ret) return 1; /* TCP segmentation offloading on */ #endif -#ifdef ETHTOOL_GUFO - ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GUFO, "ETHTOOL_GUFO"); - if (ret == -1) - return -1; - if (ret) - return 1; /* UDP fragmentation offloading on */ -#endif - #ifdef ETHTOOL_GGSO /* * XXX - will this cause large unsegmented packets to be * handed to PF_PACKET sockets on transmission? If not, * this need not be checked. */ - ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGSO, "ETHTOOL_GGSO"); + ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGSO, "ETHTOOL_GGSO", 0); if (ret == -1) return -1; if (ret) @@ -6537,7 +6812,7 @@ iface_get_offload(pcap_t *handle) #endif #ifdef ETHTOOL_GFLAGS - ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS"); + ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS", 0); if (ret == -1) return -1; if (ret & ETH_FLAG_LRO) @@ -6550,13 +6825,27 @@ iface_get_offload(pcap_t *handle) * handed to PF_PACKET sockets on receipt? If not, * this need not be checked. */ - ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGRO, "ETHTOOL_GGRO"); + ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGRO, "ETHTOOL_GGRO", 0); if (ret == -1) return -1; if (ret) return 1; /* generic (large) receive offloading on */ #endif +#ifdef ETHTOOL_GUFO + /* + * Do this one last, as support for it was removed in later + * kernels, and it fails with EPERM on those kernels rather + * than with EOPNOTSUPP (see explanation in comment for + * iface_ethtool_flag_ioctl()). + */ + ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GUFO, "ETHTOOL_GUFO", 1); + if (ret == -1) + return -1; + if (ret) + return 1; /* UDP fragmentation offloading on */ +#endif + return 0; } #else /* SIOCETHTOOL */ @@ -6592,8 +6881,17 @@ activate_old(pcap_t *handle) struct utsname utsname; int mtu; - /* Open the socket */ + /* + * PF_INET/SOCK_PACKET sockets must be bound to a device, so we + * can't support the "any" device. + */ + if (strcmp(device, "any") == 0) { + pcap_strlcpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems", + PCAP_ERRBUF_SIZE); + return PCAP_ERROR; + } + /* Open the socket */ handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL)); if (handle->fd == -1) { err = errno; @@ -6620,12 +6918,6 @@ activate_old(pcap_t *handle) handlep->cooked = 0; /* Bind to the given device */ - - if (strcmp(device, "any") == 0) { - strlcpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems", - PCAP_ERRBUF_SIZE); - return PCAP_ERROR; - } if (iface_bind_old(handle->fd, device, handle->errbuf) == -1) return PCAP_ERROR; @@ -6651,7 +6943,7 @@ activate_old(pcap_t *handle) if (handle->opt.promisc) { memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) { pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno, "SIOCGIFFLAGS"); @@ -6757,6 +7049,17 @@ activate_old(pcap_t *handle) * * We can safely pass "recvfrom()" a byte count * based on the snapshot length. + * + * XXX - this "should not happen", as 2.2[.x] + * kernels all have PF_PACKET sockets, and there's + * no configuration option to disable them without + * disabling SOCK_PACKET sockets, because + * SOCK_PACKET sockets are implemented in the same + * source file, net/packet/af_packet.c. There *is* + * an option to disable SOCK_PACKET sockets so that + * you only have PF_PACKET sockets, and the kernel + * will log warning messages for code that uses + * "obsolete (PF_INET,SOCK_PACKET)". */ handle->bufsize = (u_int)handle->snapshot; } @@ -6788,7 +7091,7 @@ iface_bind_old(int fd, const char *device, char *ebuf) socklen_t errlen = sizeof(err); memset(&saddr, 0, sizeof(saddr)); - strlcpy(saddr.sa_data, device, sizeof(saddr.sa_data)); + pcap_strlcpy(saddr.sa_data, device, sizeof(saddr.sa_data)); if (bind(fd, &saddr, sizeof(saddr)) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "bind"); @@ -6799,7 +7102,7 @@ iface_bind_old(int fd, const char *device, char *ebuf) if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, - errno, "getsockopt"); + errno, "getsockopt (SO_ERROR)"); return -1; } @@ -6827,7 +7130,7 @@ iface_get_mtu(int fd, const char *device, char *ebuf) return BIGGER_THAN_ALL_MTUS; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFMTU, &ifr) == -1) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -6845,20 +7148,22 @@ static int iface_get_arptype(int fd, const char *device, char *ebuf) { struct ifreq ifr; + int ret; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) { - pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, - errno, "SIOCGIFHWADDR"); if (errno == ENODEV) { /* * No such device. */ - return PCAP_ERROR_NO_SUCH_DEVICE; - } - return PCAP_ERROR; + ret = PCAP_ERROR_NO_SUCH_DEVICE; + } else + ret = PCAP_ERROR; + pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, + errno, "SIOCGIFHWADDR"); + return ret; } return ifr.ifr_hwaddr.sa_family; @@ -6950,7 +7255,7 @@ fix_program(pcap_t *handle, struct sock_fprog *fcode, int is_mmapped) * Yes, so we need to fix this * instruction. */ - if (fix_offset(p) < 0) { + if (fix_offset(handle, p) < 0) { /* * We failed to do so. * Return 0, so our caller @@ -6968,38 +7273,80 @@ fix_program(pcap_t *handle, struct sock_fprog *fcode, int is_mmapped) } static int -fix_offset(struct bpf_insn *p) +fix_offset(pcap_t *handle, struct bpf_insn *p) { /* - * What's the offset? + * Existing references to auxiliary data shouldn't be adjusted. + * + * Note that SKF_AD_OFF is negative, but p->k is unsigned, so + * we use >= and cast SKF_AD_OFF to unsigned. */ - if (p->k >= SLL_HDR_LEN) { + if (p->k >= (bpf_u_int32)SKF_AD_OFF) + return 0; + if (handle->linktype == DLT_LINUX_SLL2) { /* - * It's within the link-layer payload; that starts at an - * offset of 0, as far as the kernel packet filter is - * concerned, so subtract the length of the link-layer - * header. + * What's the offset? */ - p->k -= SLL_HDR_LEN; - } else if (p->k == 0) { + if (p->k >= SLL2_HDR_LEN) { + /* + * It's within the link-layer payload; that starts + * at an offset of 0, as far as the kernel packet + * filter is concerned, so subtract the length of + * the link-layer header. + */ + p->k -= SLL2_HDR_LEN; + } else if (p->k == 0) { + /* + * It's the protocol field; map it to the + * special magic kernel offset for that field. + */ + p->k = SKF_AD_OFF + SKF_AD_PROTOCOL; + } else if (p->k == 10) { + /* + * It's the packet type field; map it to the + * special magic kernel offset for that field. + */ + p->k = SKF_AD_OFF + SKF_AD_PKTTYPE; + } else if ((bpf_int32)(p->k) > 0) { + /* + * It's within the header, but it's not one of + * those fields; we can't do that in the kernel, + * so punt to userland. + */ + return -1; + } + } else { /* - * It's the packet type field; map it to the special magic - * kernel offset for that field. + * What's the offset? */ - p->k = SKF_AD_OFF + SKF_AD_PKTTYPE; - } else if (p->k == 14) { - /* - * It's the protocol field; map it to the special magic - * kernel offset for that field. - */ - p->k = SKF_AD_OFF + SKF_AD_PROTOCOL; - } else if ((bpf_int32)(p->k) > 0) { - /* - * It's within the header, but it's not one of those - * fields; we can't do that in the kernel, so punt - * to userland. - */ - return -1; + if (p->k >= SLL_HDR_LEN) { + /* + * It's within the link-layer payload; that starts + * at an offset of 0, as far as the kernel packet + * filter is concerned, so subtract the length of + * the link-layer header. + */ + p->k -= SLL_HDR_LEN; + } else if (p->k == 0) { + /* + * It's the packet type field; map it to the + * special magic kernel offset for that field. + */ + p->k = SKF_AD_OFF + SKF_AD_PKTTYPE; + } else if (p->k == 14) { + /* + * It's the protocol field; map it to the + * special magic kernel offset for that field. + */ + p->k = SKF_AD_OFF + SKF_AD_PROTOCOL; + } else if ((bpf_int32)(p->k) > 0) { + /* + * It's within the header, but it's not one of + * those fields; we can't do that in the kernel, + * so punt to userland. + */ + return -1; + } } return 0; } diff --git a/libpcap/pcap-netfilter-linux.c b/libpcap/pcap-netfilter-linux.c index d5c5dcdc4..91bad371b 100644 --- a/libpcap/pcap-netfilter-linux.c +++ b/libpcap/pcap-netfilter-linux.c @@ -301,7 +301,8 @@ netfilter_stats_linux(pcap_t *handle, struct pcap_stat *stats) static int netfilter_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on netfilter devices"); + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Packet injection is not supported on netfilter devices"); return (-1); } @@ -315,6 +316,7 @@ static int netfilter_send_config_msg(const pcap_t *handle, uint16_t msg_type, int ack, u_int8_t family, u_int16_t res_id, const struct my_nfattr *mynfa) { char buf[1024] __attribute__ ((aligned)); + memset(buf, 0, sizeof(buf)); struct nlmsghdr *nlh = (struct nlmsghdr *) buf; struct nfgenmsg *nfg = (struct nfgenmsg *) (buf + sizeof(struct nlmsghdr)); diff --git a/libpcap/pcap-netmap.c b/libpcap/pcap-netmap.c index f1505633f..b2301a7fd 100644 --- a/libpcap/pcap-netmap.c +++ b/libpcap/pcap-netmap.c @@ -67,7 +67,7 @@ pcap_netmap_stats(pcap_t *p, struct pcap_stat *ps) { struct pcap_netmap *pn = p->priv; - ps->ps_recv = pn->rx_pkts; + ps->ps_recv = (u_int)pn->rx_pkts; ps->ps_drop = 0; ps->ps_ifdrop = 0; return 0; diff --git a/libpcap/pcap-new.c b/libpcap/pcap-new.c index 6fa52e6ec..e61cf6ab2 100644 --- a/libpcap/pcap-new.c +++ b/libpcap/pcap-new.c @@ -35,6 +35,8 @@ #include #endif +#include "ftmacros.h" + /* * sockutils.h may include on Windows, and pcap-int.h will * include portability.h, and portability.h, on Windows, expects that @@ -54,11 +56,14 @@ /* String identifier to be used in the pcap_findalldevs_ex() */ #define PCAP_TEXT_SOURCE_FILE "File" +#define PCAP_TEXT_SOURCE_FILE_LEN (sizeof PCAP_TEXT_SOURCE_FILE - 1) /* String identifier to be used in the pcap_findalldevs_ex() */ #define PCAP_TEXT_SOURCE_ADAPTER "Network adapter" +#define PCAP_TEXT_SOURCE_ADAPTER_LEN (sizeof "Network adapter" - 1) /* String identifier to be used in the pcap_findalldevs_ex() */ #define PCAP_TEXT_SOURCE_ON_LOCAL_HOST "on local host" +#define PCAP_TEXT_SOURCE_ON_LOCAL_HOST_LEN (sizeof PCAP_TEXT_SOURCE_ON_LOCAL_HOST + 1) /**************************************************** * * @@ -66,10 +71,12 @@ * * ****************************************************/ -int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf) +int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf) { int type; char name[PCAP_BUF_SIZE], path[PCAP_BUF_SIZE], filename[PCAP_BUF_SIZE]; + size_t pathlen; + size_t stringlen; pcap_t *fp; char tmpstring[PCAP_BUF_SIZE + 1]; /* Needed to convert names and descriptions from 'old' syntax to the 'new' one */ pcap_if_t *lastdev; /* Last device in the pcap_if_t list */ @@ -113,7 +120,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all if (*alldevs == NULL) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "No interfaces found! Make sure libpcap/WinPcap is properly installed" + "No interfaces found! Make sure libpcap/Npcap is properly installed" " on the local machine."); return -1; } @@ -123,6 +130,8 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all dev = *alldevs; while (dev) { + char *localdesc, *desc; + /* Create the new device identifier */ if (pcap_createsrcstr(tmpstring, PCAP_SRC_IFLOCAL, NULL, NULL, dev->name, errbuf) == -1) return -1; @@ -141,20 +150,16 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } - /* Create the new device description */ + /* + * Create the description. + */ if ((dev->description == NULL) || (dev->description[0] == 0)) - pcap_snprintf(tmpstring, sizeof(tmpstring) - 1, "%s '%s' %s", PCAP_TEXT_SOURCE_ADAPTER, - dev->name, PCAP_TEXT_SOURCE_ON_LOCAL_HOST); + localdesc = dev->name; else - pcap_snprintf(tmpstring, sizeof(tmpstring) - 1, "%s '%s' %s", PCAP_TEXT_SOURCE_ADAPTER, - dev->description, PCAP_TEXT_SOURCE_ON_LOCAL_HOST); - - /* Delete the old pointer */ - free(dev->description); - - /* Make a copy of the description */ - dev->description = strdup(tmpstring); - if (dev->description == NULL) + localdesc = dev->description; + if (pcap_asprintf(&desc, "%s '%s' %s", + PCAP_TEXT_SOURCE_ADAPTER, localdesc, + PCAP_TEXT_SOURCE_ON_LOCAL_HOST) == -1) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, @@ -163,6 +168,10 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } + /* Now overwrite the description */ + free(dev->description); + dev->description = desc; + dev = dev->next; } @@ -170,7 +179,6 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all case PCAP_SRC_FILE: { - size_t stringlen; #ifdef _WIN32 WIN32_FIND_DATA filedata; HANDLE filehandle; @@ -202,6 +210,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all /* Save the path for future reference */ pcap_snprintf(path, sizeof(path), "%s", name); + pathlen = strlen(path); #ifdef _WIN32 /* To perform directory listing, Win32 must have an 'asterisk' as ending char */ @@ -236,10 +245,14 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all /* Add all files we find to the list. */ do { - #ifdef _WIN32 + /* Skip the file if the pathname won't fit in the buffer */ + if (pathlen + strlen(filedata.cFileName) >= sizeof(filename)) + continue; pcap_snprintf(filename, sizeof(filename), "%s%s", path, filedata.cFileName); #else + if (pathlen + strlen(filedata->d_name) >= sizeof(filename)) + continue; pcap_snprintf(filename, sizeof(filename), "%s%s", path, filedata->d_name); #endif @@ -287,9 +300,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } - stringlen = strlen(tmpstring); - - dev->name = (char *)malloc(stringlen + 1); + dev->name = strdup(tmpstring); if (dev->name == NULL) { pcap_fmt_errmsg_for_errno(errbuf, @@ -299,19 +310,12 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } - strlcpy(dev->name, tmpstring, stringlen); - - dev->name[stringlen] = 0; - - /* Create the description */ - pcap_snprintf(tmpstring, sizeof(tmpstring) - 1, "%s '%s' %s", PCAP_TEXT_SOURCE_FILE, - filename, PCAP_TEXT_SOURCE_ON_LOCAL_HOST); - - stringlen = strlen(tmpstring); - - dev->description = (char *)malloc(stringlen + 1); - - if (dev->description == NULL) + /* + * Create the description. + */ + if (pcap_asprintf(&dev->description, + "%s '%s' %s", PCAP_TEXT_SOURCE_FILE, + filename, PCAP_TEXT_SOURCE_ON_LOCAL_HOST) == -1) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, @@ -320,9 +324,6 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return -1; } - /* Copy the new device description into the correct memory location */ - strlcpy(dev->description, tmpstring, stringlen + 1); - pcap_close(fp); } } @@ -345,7 +346,7 @@ int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **all return pcap_findalldevs_ex_remote(source, auth, alldevs, errbuf); default: - strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); return -1; } } @@ -357,6 +358,16 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, pcap_t *fp; int status; + /* + * A null device name is equivalent to the "any" device - + * which might not be supported on this platform, but + * this means that you'll get a "not supported" error + * rather than, say, a crash when we try to dereference + * the null pointer. + */ + if (source == NULL) + source = "any"; + if (strlen(source) > PCAP_BUF_SIZE) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The source string is too long. Cannot handle it correctly."); @@ -389,7 +400,7 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, return pcap_open_rpcap(source, snaplen, flags, read_timeout, auth, errbuf); default: - strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE); return NULL; } diff --git a/libpcap/pcap-npf.c b/libpcap/pcap-npf.c index a9ff0ff4d..da4641f37 100644 --- a/libpcap/pcap-npf.c +++ b/libpcap/pcap-npf.c @@ -70,7 +70,7 @@ static int pcap_setnonblock_npf(pcap_t *, int); #define SWAPS(_X) ((_X & 0xff) << 8) | (_X >> 8) /* - * Private data for capturing on WinPcap devices. + * Private data for capturing on WinPcap/Npcap devices. */ struct pcap_win { ADAPTER *adapter; /* the packet32 ADAPTER for the device */ @@ -166,11 +166,8 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp, oid_data_arg->Oid = oid; oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */ if (!PacketRequest(adapter, FALSE, oid_data_arg)) { - char errmsgbuf[PCAP_ERRBUF_SIZE+1]; - - pcap_win32_err_to_str(GetLastError(), errmsgbuf); - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "Error calling PacketRequest: %s", errmsgbuf); + pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "Error calling PacketRequest"); free(oid_data_arg); return (-1); } @@ -193,7 +190,6 @@ pcap_stats_npf(pcap_t *p, struct pcap_stat *ps) { struct pcap_win *pw = p->priv; struct bpf_stat bstats; - char errbuf[PCAP_ERRBUF_SIZE+1]; /* * Try to get statistics. @@ -209,9 +205,8 @@ pcap_stats_npf(pcap_t *p, struct pcap_stat *ps) * to us. */ if (!PacketGetStats(pw->adapter, &bstats)) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "PacketGetStats error: %s", errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "PacketGetStats error"); return (-1); } ps->ps_recv = bstats.bs_recv; @@ -256,7 +251,6 @@ pcap_stats_ex_npf(pcap_t *p, int *pcap_stat_size) { struct pcap_win *pw = p->priv; struct bpf_stat bstats; - char errbuf[PCAP_ERRBUF_SIZE+1]; *pcap_stat_size = sizeof (p->stat); @@ -268,9 +262,8 @@ pcap_stats_ex_npf(pcap_t *p, int *pcap_stat_size) * same layout, but let's not cheat.) */ if (!PacketGetStatsEx(pw->adapter, &bstats)) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "PacketGetStatsEx error: %s", errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "PacketGetStatsEx error"); return (NULL); } p->stat.ps_recv = bstats.bs_recv; @@ -347,7 +340,6 @@ pcap_oid_set_request_npf(pcap_t *p, bpf_u_int32 oid, const void *data, { struct pcap_win *pw = p->priv; PACKET_OID_DATA *oid_data_arg; - char errbuf[PCAP_ERRBUF_SIZE+1]; /* * Allocate a PACKET_OID_DATA structure to hand to PacketRequest(). @@ -367,9 +359,8 @@ pcap_oid_set_request_npf(pcap_t *p, bpf_u_int32 oid, const void *data, oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */ memcpy(oid_data_arg->Data, data, *lenp); if (!PacketRequest(pw->adapter, TRUE, oid_data_arg)) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Error calling PacketRequest: %s", errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "Error calling PacketRequest"); free(oid_data_arg); return (PCAP_ERROR); } @@ -391,7 +382,6 @@ pcap_sendqueue_transmit_npf(pcap_t *p, pcap_send_queue *queue, int sync) { struct pcap_win *pw = p->priv; u_int res; - char errbuf[PCAP_ERRBUF_SIZE+1]; if (pw->adapter==NULL) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, @@ -405,9 +395,8 @@ pcap_sendqueue_transmit_npf(pcap_t *p, pcap_send_queue *queue, int sync) (BOOLEAN)sync); if(res != queue->len){ - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Error opening adapter: %s", errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "Error opening adapter"); } return (res); @@ -534,7 +523,34 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user) */ PacketInitPacket(&Packet, (BYTE *)p->buffer, p->bufsize); if (!PacketReceivePacket(pw->adapter, &Packet, TRUE)) { - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed"); + /* + * Did the device go away? + * If so, the error we get is ERROR_GEN_FAILURE. + */ + DWORD errcode = GetLastError(); + + if (errcode == ERROR_GEN_FAILURE) { + /* + * The device on which we're capturing + * went away, or it became unusable + * by NPF due to a suspend/resume. + * + * XXX - hopefully no other error + * conditions are indicated by this. + * + * XXX - we really should return an + * appropriate error for that, but + * pcap_dispatch() etc. aren't + * documented as having error returns + * other than PCAP_ERROR or PCAP_ERROR_BREAK. + */ + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "The interface disappeared"); + } else { + pcap_fmt_errmsg_for_win32_err(p->errbuf, + PCAP_ERRBUF_SIZE, errcode, + "PacketReceivePacket error"); + } return (PCAP_ERROR); } @@ -873,7 +889,7 @@ pcap_activate_npf(pcap_t *p) struct pcap_win *pw = p->priv; NetType type; int res; - char errbuf[PCAP_ERRBUF_SIZE+1]; + int status = 0; if (p->opt.rfmon) { /* @@ -912,23 +928,35 @@ pcap_activate_npf(pcap_t *p) if (pw->adapter == NULL) { - /* Adapter detected but we are not able to open it. Return failure. */ - pcap_win32_err_to_str(GetLastError(), errbuf); - if (pw->rfmon_selfstart) - { - PacketSetMonitorMode(p->opt.device, 0); + DWORD errcode = GetLastError(); + + /* + * What error did we get when trying to open the adapter? + */ + if (errcode == ERROR_BAD_UNIT) { + /* + * There's no such device. + */ + return (PCAP_ERROR_NO_SUCH_DEVICE); + } else { + /* + * Unknown - report details. + */ + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + errcode, "Error opening adapter"); + if (pw->rfmon_selfstart) + { + PacketSetMonitorMode(p->opt.device, 0); + } + return (PCAP_ERROR); } - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Error opening adapter: %s", errbuf); - return (PCAP_ERROR); } /*get network type*/ if(PacketGetNetType (pw->adapter,&type) == FALSE) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Cannot determine the network type: %s", errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "Cannot determine the network type"); goto bad; } @@ -1006,8 +1034,29 @@ pcap_activate_npf(pcap_t *p) p->linktype = DLT_PPI; break; +#ifdef NdisMediumWirelessWan + case NdisMediumWirelessWan: + p->linktype = DLT_RAW; + break; +#endif + default: - p->linktype = DLT_EN10MB; /*an unknown adapter is assumed to be ethernet*/ + /* + * An unknown medium type is assumed to supply Ethernet + * headers; if not, the user will have to report it, + * so that the medium type and link-layer header type + * can be determined. If we were to fail here, we + * might get the link-layer type in the error, but + * the user wouldn't get a capture, so we wouldn't + * be able to determine the link-layer type; we report + * a warning with the link-layer type, so at least + * some programs will report the warning. + */ + p->linktype = DLT_EN10MB; + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + "Unknown NdisMedium value %d, defaulting to DLT_EN10MB", + type.LinkType); + status = PCAP_WARNING; break; } @@ -1085,10 +1134,9 @@ pcap_activate_npf(pcap_t *p) /* tell the driver to copy the buffer as soon as data arrives */ if(PacketSetMinToCopy(pw->adapter,0)==FALSE) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Error calling PacketSetMinToCopy: %s", - errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, + PCAP_ERRBUF_SIZE, GetLastError(), + "Error calling PacketSetMinToCopy"); goto bad; } } @@ -1097,10 +1145,9 @@ pcap_activate_npf(pcap_t *p) /* tell the driver to copy the buffer only if it contains at least 16K */ if(PacketSetMinToCopy(pw->adapter,16000)==FALSE) { - pcap_win32_err_to_str(GetLastError(), errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "Error calling PacketSetMinToCopy: %s", - errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, + PCAP_ERRBUF_SIZE, GetLastError(), + "Error calling PacketSetMinToCopy"); goto bad; } } @@ -1221,7 +1268,7 @@ pcap_activate_npf(pcap_t *p) */ p->handle = pw->adapter->hFile; - return (0); + return (status); bad: pcap_cleanup_npf(p); return (PCAP_ERROR); @@ -1316,7 +1363,7 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) { if(!fp) { - strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf)); + pcap_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf)); return (-1); } @@ -1345,7 +1392,6 @@ pcap_setnonblock_npf(pcap_t *p, int nonblock) { struct pcap_win *pw = p->priv; int newtimeout; - char win_errbuf[PCAP_ERRBUF_SIZE+1]; if (nonblock) { /* @@ -1365,9 +1411,8 @@ pcap_setnonblock_npf(pcap_t *p, int nonblock) newtimeout = p->opt.timeout; } if (!PacketSetReadTimeout(pw->adapter, newtimeout)) { - pcap_win32_err_to_str(GetLastError(), win_errbuf); - pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "PacketSetReadTimeout: %s", win_errbuf); + pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "PacketSetReadTimeout"); return (-1); } pw->nonblock = (newtimeout == -1); @@ -1684,7 +1729,6 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) char *AdaptersName; ULONG NameLength; char *name; - char our_errbuf[PCAP_ERRBUF_SIZE+1]; /* * Find out how big a buffer we need. @@ -1710,9 +1754,8 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) if (last_error != ERROR_INSUFFICIENT_BUFFER) { - pcap_win32_err_to_str(last_error, our_errbuf); - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "PacketGetAdapterNames: %s", our_errbuf); + pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE, + last_error, "PacketGetAdapterNames"); return (-1); } } @@ -1727,9 +1770,8 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) } if (!PacketGetAdapterNames(AdaptersName, &NameLength)) { - pcap_win32_err_to_str(GetLastError(), our_errbuf); - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "PacketGetAdapterNames: %s", - our_errbuf); + pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "PacketGetAdapterNames"); free(AdaptersName); return (-1); } @@ -1818,7 +1860,6 @@ pcap_lookupdev(char *errbuf) { DWORD dwVersion; DWORD dwWindowsMajorVersion; - char our_errbuf[PCAP_ERRBUF_SIZE+1]; #pragma warning (push) #pragma warning (disable: 4996) /* disable MSVC's GetVersion() deprecated warning here */ @@ -1860,9 +1901,8 @@ pcap_lookupdev(char *errbuf) if ( !PacketGetAdapterNames((PTSTR)TAdaptersName,&NameLength) ) { - pcap_win32_err_to_str(GetLastError(), our_errbuf); - (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "PacketGetAdapterNames: %s", our_errbuf); + pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE, + GetLastError(), "PacketGetAdapterNames"); free(TAdaptersName); return NULL; } @@ -2000,59 +2040,48 @@ static const char *pcap_lib_version_string; * tree. Include version.h from that source tree to get the WinPcap/Npcap * version. * - * XXX - it'd be nice if we could somehow generate the WinPcap version number - * when building WinPcap. (It'd be nice to do so for the packet.dll version - * number as well.) + * XXX - it'd be nice if we could somehow generate the WinPcap/Npcap version + * number when building as part of WinPcap/Npcap. (It'd be nice to do so + * for the packet.dll version number as well.) */ #include "../../version.h" static const char pcap_version_string[] = WINPCAP_PRODUCT_NAME " version " WINPCAP_VER_STRING ", based on " PCAP_VERSION_STRING; -static const char pcap_version_string_packet_dll_fmt[] = - WINPCAP_PRODUCT_NAME " version " WINPCAP_VER_STRING " (packet.dll version %s), based on " PCAP_VERSION_STRING; const char * pcap_lib_version(void) { - char *packet_version_string; - size_t full_pcap_version_string_len; - char *full_pcap_version_string; - if (pcap_lib_version_string == NULL) { /* * Generate the version string. */ - packet_version_string = PacketGetVersion(); + char *packet_version_string = PacketGetVersion(); + if (strcmp(WINPCAP_VER_STRING, packet_version_string) == 0) { /* - * WinPcap version string and packet.dll version - * string are the same; just report the WinPcap + * WinPcap/Npcap version string and packet.dll version + * string are the same; just report the WinPcap/Npcap * version. */ pcap_lib_version_string = pcap_version_string; } else { /* - * WinPcap version string and packet.dll version + * WinPcap/Npcap version string and packet.dll version * string are different; that shouldn't be the * case (the two libraries should come from the - * same version of WinPcap), so we report both + * same version of WinPcap/Npcap), so we report both * versions. - * - * The -2 is for the %s in the format string, - * which will be replaced by packet_version_string. */ - full_pcap_version_string_len = - (sizeof pcap_version_string_packet_dll_fmt - 2) + - strlen(packet_version_string); - full_pcap_version_string = malloc(full_pcap_version_string_len); - if (full_pcap_version_string == NULL) - return (NULL); - pcap_snprintf(full_pcap_version_string, - full_pcap_version_string_len, - pcap_version_string_packet_dll_fmt, - packet_version_string); + char *full_pcap_version_string; + + if (pcap_asprintf(&full_pcap_version_string, + WINPCAP_PRODUCT_NAME " version " WINPCAP_VER_STRING " (packet.dll version %s), based on " PCAP_VERSION_STRING, + packet_version_string) != -1) { + /* Success */ + pcap_lib_version_string = full_pcap_version_string; + } } - pcap_lib_version_string = full_pcap_version_string; } return (pcap_lib_version_string); } @@ -2063,35 +2092,22 @@ pcap_lib_version(void) * libpcap being built for Windows, not as part of a WinPcap/Npcap source * tree. */ -static const char pcap_version_string_packet_dll_fmt[] = - PCAP_VERSION_STRING " (packet.dll version %s)"; const char * pcap_lib_version(void) { - char *packet_version_string; - size_t full_pcap_version_string_len; - char *full_pcap_version_string; - if (pcap_lib_version_string == NULL) { /* * Generate the version string. Report the packet.dll * version. - * - * The -2 is for the %s in the format string, which will - * be replaced by packet_version_string. */ - packet_version_string = PacketGetVersion(); - full_pcap_version_string_len = - (sizeof pcap_version_string_packet_dll_fmt - 2) + - strlen(packet_version_string); - full_pcap_version_string = malloc(full_pcap_version_string_len); - if (full_pcap_version_string == NULL) - return (NULL); - pcap_snprintf(full_pcap_version_string, - full_pcap_version_string_len, - pcap_version_string_packet_dll_fmt, - packet_version_string); - pcap_lib_version_string = full_pcap_version_string; + char *full_pcap_version_string; + + if (pcap_asprintf(&full_pcap_version_string, + PCAP_VERSION_STRING " (packet.dll version %s)", + PacketGetVersion()) != -1) { + /* Success */ + pcap_lib_version_string = full_pcap_version_string; + } } return (pcap_lib_version_string); } diff --git a/libpcap/pcap-null.c b/libpcap/pcap-null.c index 92a5e2d86..2ae27bf82 100644 --- a/libpcap/pcap-null.c +++ b/libpcap/pcap-null.c @@ -32,12 +32,12 @@ static char nosup[] = "live packet capture not supported on this system"; pcap_t * pcap_create_interface(const char *device _U_, char *ebuf) { - (void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE); + (void)pcap_strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE); return (NULL); } int -pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) +pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf _U_) { /* * There are no interfaces on which we can capture. @@ -50,7 +50,7 @@ int pcap_lookupnet(const char *device _U_, bpf_u_int32 *netp _U_, bpf_u_int32 *maskp _U_, char *errbuf) { - (void)strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE); + (void)pcap_strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE); return (-1); } #endif diff --git a/libpcap/pcap-rpcap.c b/libpcap/pcap-rpcap.c index e9d6245bf..705f06f2a 100644 --- a/libpcap/pcap-rpcap.c +++ b/libpcap/pcap-rpcap.c @@ -155,7 +155,6 @@ static void pcap_save_current_filter_rpcap(pcap_t *fp, const char *filter); static int pcap_setfilter_rpcap(pcap_t *fp, struct bpf_program *prog); static int pcap_setsampling_remote(pcap_t *fp); static int pcap_startcapture_remote(pcap_t *fp); -static int rpcap_sendauth(SOCKET sock, uint8 *ver, struct pcap_rmtauth *auth, char *errbuf); static int rpcap_recv_msg_header(SOCKET sock, struct rpcap_header *header, char *errbuf); static int rpcap_check_msg_ver(SOCKET sock, uint8 expected_ver, struct rpcap_header *header, char *errbuf); static int rpcap_check_msg_type(SOCKET sock, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf); @@ -409,7 +408,7 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch return 0; } #endif - sock_geterror("select(): ", p->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("select()", p->errbuf, PCAP_ERRBUF_SIZE); return -1; } @@ -763,6 +762,8 @@ static void pcap_cleanup_rpcap(pcap_t *fp) pr->currentfilter = NULL; } + pcap_cleanup_live_common(fp); + /* To avoid inconsistencies in the number of sock_init() */ sock_cleanup(); } @@ -1069,7 +1070,7 @@ static int pcap_startcapture_remote(pcap_t *fp) saddrlen = sizeof(struct sockaddr_storage); if (getpeername(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) { - sock_geterror("getsockname(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getsockname()", fp->errbuf, PCAP_ERRBUF_SIZE); goto error_nodiscard; } ai_family = ((struct sockaddr_storage *) &saddr)->ss_family; @@ -1078,7 +1079,7 @@ static int pcap_startcapture_remote(pcap_t *fp) if (getnameinfo((struct sockaddr *) &saddr, saddrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST)) { - sock_geterror("getnameinfo(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE); goto error_nodiscard; } @@ -1116,7 +1117,7 @@ static int pcap_startcapture_remote(pcap_t *fp) saddrlen = sizeof(struct sockaddr_storage); if (getsockname(sockdata, (struct sockaddr *) &saddr, &saddrlen) == -1) { - sock_geterror("getsockname(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getsockname()", fp->errbuf, PCAP_ERRBUF_SIZE); goto error_nodiscard; } @@ -1124,7 +1125,7 @@ static int pcap_startcapture_remote(pcap_t *fp) if (getnameinfo((struct sockaddr *) &saddr, saddrlen, NULL, 0, portdata, sizeof(portdata), NI_NUMERICSERV)) { - sock_geterror("getnameinfo(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE); goto error_nodiscard; } } @@ -1234,7 +1235,7 @@ static int pcap_startcapture_remote(pcap_t *fp) if (socktemp == INVALID_SOCKET) { - sock_geterror("accept(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("accept()", fp->errbuf, PCAP_ERRBUF_SIZE); goto error; } @@ -1260,8 +1261,8 @@ static int pcap_startcapture_remote(pcap_t *fp) res = getsockopt(sockdata, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize, &itemp); if (res == -1) { - sock_geterror("pcap_startcapture_remote()", fp->errbuf, PCAP_ERRBUF_SIZE); - SOCK_DEBUG_MESSAGE(fp->errbuf); + sock_geterror("pcap_startcapture_remote(): getsockopt() failed", fp->errbuf, PCAP_ERRBUF_SIZE); + goto error; } /* @@ -1612,21 +1613,19 @@ static int pcap_createfilter_norpcappkt(pcap_t *fp, struct bpf_program *prog) char peeraddress[128]; char peerctrlport[128]; char *newfilter; - const int newstringsize = 1024; - size_t currentfiltersize; /* Get the name/port of our peer */ saddrlen = sizeof(struct sockaddr_storage); if (getpeername(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) { - sock_geterror("getpeername(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getpeername()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } if (getnameinfo((struct sockaddr *) &saddr, saddrlen, peeraddress, sizeof(peeraddress), peerctrlport, sizeof(peerctrlport), NI_NUMERICHOST | NI_NUMERICSERV)) { - sock_geterror("getnameinfo(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } @@ -1634,7 +1633,7 @@ static int pcap_createfilter_norpcappkt(pcap_t *fp, struct bpf_program *prog) /* Get the name/port of the current host */ if (getsockname(pr->rmt_sockctrl, (struct sockaddr *) &saddr, &saddrlen) == -1) { - sock_geterror("getsockname(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getsockname()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } @@ -1642,43 +1641,60 @@ static int pcap_createfilter_norpcappkt(pcap_t *fp, struct bpf_program *prog) if (getnameinfo((struct sockaddr *) &saddr, saddrlen, myaddress, sizeof(myaddress), myctrlport, sizeof(myctrlport), NI_NUMERICHOST | NI_NUMERICSERV)) { - sock_geterror("getnameinfo(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } /* Let's now check the data port */ if (getsockname(pr->rmt_sockdata, (struct sockaddr *) &saddr, &saddrlen) == -1) { - sock_geterror("getsockname(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getsockname()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } /* Get the local port the system picked up */ if (getnameinfo((struct sockaddr *) &saddr, saddrlen, NULL, 0, mydataport, sizeof(mydataport), NI_NUMERICSERV)) { - sock_geterror("getnameinfo(): ", fp->errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE); return -1; } - currentfiltersize = pr->currentfilter ? strlen(pr->currentfilter) : 0; - - newfilter = (char *)malloc(currentfiltersize + newstringsize + 1); - - if (currentfiltersize) + if (pr->currentfilter && pr->currentfilter[0] != '\0') { - pcap_snprintf(newfilter, currentfiltersize + newstringsize, - "(%s) and not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)", - pr->currentfilter, myaddress, peeraddress, myctrlport, peerctrlport, myaddress, peeraddress, mydataport); + /* + * We have a current filter; add items to it to + * filter out this rpcap session. + */ + if (pcap_asprintf(&newfilter, + "(%s) and not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)", + pr->currentfilter, myaddress, peeraddress, + myctrlport, peerctrlport, myaddress, peeraddress, + mydataport) == -1) + { + /* Failed. */ + pcap_snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, + "Can't allocate memory for new filter"); + return -1; + } } else { - pcap_snprintf(newfilter, currentfiltersize + newstringsize, - "not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)", - myaddress, peeraddress, myctrlport, peerctrlport, myaddress, peeraddress, mydataport); + /* + * We have no current filter; construct a filter to + * filter out this rpcap session. + */ + if (pcap_asprintf(&newfilter, + "not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)", + myaddress, peeraddress, myctrlport, peerctrlport, + myaddress, peeraddress, mydataport) == -1) + { + /* Failed. */ + pcap_snprintf(fp->errbuf, PCAP_ERRBUF_SIZE, + "Can't allocate memory for new filter"); + return -1; + } } - newfilter[currentfiltersize + newstringsize] = 0; - /* * This is only an hack to prevent the save_current_filter * routine, which will be called when we call pcap_compile(), @@ -1785,16 +1801,25 @@ static int pcap_setsampling_remote(pcap_t *fp) /* * This function performs authentication and protocol version - * negotiation. It first tries to authenticate with the maximum - * version we support and, if that fails with an "I don't support - * that version" error from the server, and the version number in - * the reply from the server is one we support, tries again with - * that version. + * negotiation. It is required in order to open the connection + * with the other end party. + * + * It sends authentication parameters on the control socket and + * reads the reply. If the reply is a success indication, it + * checks whether the reply includes minimum and maximum supported + * versions from the server; if not, it assumes both are 0, as + * that means it's an older server that doesn't return supported + * version numbers in authentication replies, so it only supports + * version 0. It then tries to determine the maximum version + * supported both by us and by the server. If it can find such a + * version, it sets us up to use that version; otherwise, it fails, + * indicating that there is no version supported by us and by the + * server. * * \param sock: the socket we are currently using. * - * \param ver: pointer to variable holding protocol version number to send - * and to set to the protocol version number in the reply. + * \param ver: pointer to variable to which to set the protocol version + * number we selected. * * \param auth: authentication parameters that have to be sent. * @@ -1807,96 +1832,17 @@ static int pcap_setsampling_remote(pcap_t *fp) * an error message string is returned in the 'errbuf' variable. */ static int rpcap_doauth(SOCKET sockctrl, uint8 *ver, struct pcap_rmtauth *auth, char *errbuf) -{ - int status; - - /* - * Send authentication to the remote machine. - * - * First try with the maximum version number we support. - */ - *ver = RPCAP_MAX_VERSION; - status = rpcap_sendauth(sockctrl, ver, auth, errbuf); - if (status == 0) - { - // - // Success. - // - return 0; - } - if (status == -1) - { - /* Unrecoverable error. */ - return -1; - } - - /* - * The server doesn't support the version we used in the initial - * message, and it sent us back a reply either with the maximum - * version they do support, or with the version we sent, and we - * support that version. *ver has been set to that version; try - * authenticating again with that version. - */ - status = rpcap_sendauth(sockctrl, ver, auth, errbuf); - if (status == 0) - { - // - // Success. - // - return 0; - } - if (status == -1) - { - /* Unrecoverable error. */ - return -1; - } - if (status == -2) - { - /* - * The server doesn't support that version, which - * means there is no version we both support, so - * this is a fatal error. - */ - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The server doesn't support any protocol version that we support"); - return -1; - } - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "rpcap_sendauth() returned %d", status); - return -1; -} - -/* - * This function sends the authentication message. - * - * It sends the authentication parameters on the control socket. - * It is required in order to open the connection with the other end party. - * - * \param sock: the socket we are currently using. - * - * \param ver: pointer to variable holding protocol version number to send - * and to set to the protocol version number in the reply. - * - * \param auth: authentication parameters that have to be sent. - * - * \param errbuf: a pointer to a user-allocated buffer (of size - * PCAP_ERRBUF_SIZE) that will contain the error message (in case there - * is one). It could be a network problem or the fact that the authorization - * failed. - * - * \return '0' if everything is fine, '-2' if the server didn't reply with - * the protocol version we requested but replied with a version we do - * support, or '-1' for other errors. For errors, an error message string - * is returned in the 'errbuf' variable. - */ -static int rpcap_sendauth(SOCKET sock, uint8 *ver, struct pcap_rmtauth *auth, char *errbuf) { char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data that has to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ uint16 length; /* length of the payload of this message */ - uint16 errcode; struct rpcap_auth *rpauth; uint16 auth_type; struct rpcap_header header; size_t str_length; + uint32 plen; + struct rpcap_authreply authreply; /* authentication reply message */ + uint8 ourvers; if (auth) { @@ -1943,12 +1889,11 @@ static int rpcap_sendauth(SOCKET sock, uint8 *ver, struct pcap_rmtauth *auth, ch length = sizeof(struct rpcap_auth); } - if (sock_bufferize(NULL, sizeof(struct rpcap_header), NULL, &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE)) return -1; - rpcap_createhdr((struct rpcap_header *) sendbuf, *ver, + rpcap_createhdr((struct rpcap_header *) sendbuf, 0, RPCAP_MSG_AUTH_REQ, 0, length); rpauth = (struct rpcap_auth *) &sendbuf[sendbufidx]; @@ -1985,62 +1930,104 @@ static int rpcap_sendauth(SOCKET sock, uint8 *ver, struct pcap_rmtauth *auth, ch rpauth->slen2 = htons(rpauth->slen2); } - if (sock_send(sock, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE) < 0) + if (sock_send(sockctrl, sendbuf, sendbufidx, errbuf, + PCAP_ERRBUF_SIZE) < 0) return -1; - /* Receive the reply */ - if (rpcap_recv_msg_header(sock, &header, errbuf) == -1) + /* Receive and process the reply message header */ + if (rpcap_process_msg_header(sockctrl, 0, RPCAP_MSG_AUTH_REQ, + &header, errbuf) == -1) return -1; - if (rpcap_check_msg_type(sock, RPCAP_MSG_AUTH_REQ, &header, - &errcode, errbuf) == -1) + /* + * OK, it's an authentication reply, so we're logged in. + * + * Did it send any additional information? + */ + plen = header.plen; + if (plen != 0) { - /* Error message - or something else, which is a protocol error. */ - if (header.type == RPCAP_MSG_ERROR && - errcode == PCAP_ERR_WRONGVER) + /* Yes - is it big enough to be version information? */ + if (plen < sizeof(struct rpcap_authreply)) { - /* - * The server didn't support the version we sent, - * and replied with the maximum version it supports - * if our version was too big or with the version - * we sent if out version was too small. - * - * Do we also support it? - */ - if (!RPCAP_VERSION_IS_SUPPORTED(header.ver)) - { - /* - * No, so there's no version we both support. - * This is an unrecoverable error. - */ - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The server doesn't support any protocol version that we support"); - return -1; - } - - /* - * OK, use that version, and tell our caller to - * try again. - */ - *ver = header.ver; - return -2; + /* No - discard it and fail. */ + (void)rpcap_discard(sockctrl, plen, NULL); + return -1; } + /* Read the reply body */ + if (rpcap_recv(sockctrl, (char *)&authreply, + sizeof(struct rpcap_authreply), &plen, errbuf) == -1) + { + (void)rpcap_discard(sockctrl, plen, NULL); + return -1; + } + + /* Discard the rest of the message, if there is any. */ + if (rpcap_discard(sockctrl, plen, errbuf) == -1) + return -1; + /* - * Other error - unrecoverable. + * Check the minimum and maximum versions for sanity; + * the minimum must be <= the maximum. */ - return -1; + if (authreply.minvers > authreply.maxvers) + { + /* + * Bogus - give up on this server. + */ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "The server's minimum supported protocol version is greater than its maximum supported protocol version"); + return -1; + } + } + else + { + /* No - it supports only version 0. */ + authreply.minvers = 0; + authreply.maxvers = 0; } /* - * OK, it's an authentication reply, so they're OK with the - * protocol version we sent. - * - * Discard the rest of it. + * OK, let's start with the maximum version the server supports. */ - if (rpcap_discard(sock, header.plen, errbuf) == -1) - return -1; + ourvers = authreply.maxvers; +#if RPCAP_MIN_VERSION != 0 + /* + * If that's less than the minimum version we support, we + * can't communicate. + */ + if (ourvers < RPCAP_MIN_VERSION) + goto novers; +#endif + + /* + * If that's greater than the maximum version we support, + * choose the maximum version we support. + */ + if (ourvers > RPCAP_MAX_VERSION) + { + ourvers = RPCAP_MAX_VERSION; + + /* + * If that's less than the minimum version they + * support, we can't communicate. + */ + if (ourvers < authreply.minvers) + goto novers; + } + + *ver = ourvers; return 0; + +novers: + /* + * There is no version we both support; that is a fatal error. + */ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "The server doesn't support any protocol version that we support"); + return -1; } /* We don't currently support non-blocking mode. */ @@ -2060,6 +2047,103 @@ pcap_setnonblock_rpcap(pcap_t *p, int nonblock _U_) return (-1); } +static int +rpcap_setup_session(const char *source, struct pcap_rmtauth *auth, + int *activep, SOCKET *sockctrlp, uint8 *protocol_versionp, + char *host, char *port, char *iface, char *errbuf) +{ + int type; + struct activehosts *activeconn; /* active connection, if there is one */ + int error; /* 1 if rpcap_remoteact_getsock got an error */ + + /* + * Determine the type of the source (NULL, file, local, remote). + * You must have a valid source string even if we're in active mode, + * because otherwise the call to the following function will fail. + */ + if (pcap_parsesrcstr(source, &type, host, port, iface, errbuf) == -1) + return -1; + + /* + * It must be remote. + */ + if (type != PCAP_SRC_IFREMOTE) + { + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "Non-remote interface passed to remote capture routine"); + return -1; + } + + /* Warning: this call can be the first one called by the user. */ + /* For this reason, we have to initialize the WinSock support. */ + if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) + return -1; + + /* Check for active mode */ + activeconn = rpcap_remoteact_getsock(host, &error, errbuf); + if (activeconn != NULL) + { + *activep = 1; + *sockctrlp = activeconn->sockctrl; + *protocol_versionp = activeconn->protocol_version; + } + else + { + *activep = 0; + struct addrinfo hints; /* temp variable needed to resolve hostnames into to socket representation */ + struct addrinfo *addrinfo; /* temp variable needed to resolve hostnames into to socket representation */ + + if (error) + { + /* + * Call failed. + */ + return -1; + } + + /* + * We're not in active mode; let's try to open a new + * control connection. + */ + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if (port[0] == 0) + { + /* the user chose not to specify the port */ + if (sock_initaddress(host, RPCAP_DEFAULT_NETPORT, + &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) + return -1; + } + else + { + if (sock_initaddress(host, port, &hints, &addrinfo, + errbuf, PCAP_ERRBUF_SIZE) == -1) + return -1; + } + + if ((*sockctrlp = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, + errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) + { + freeaddrinfo(addrinfo); + return -1; + } + + /* addrinfo is no longer used */ + freeaddrinfo(addrinfo); + addrinfo = NULL; + + if (rpcap_doauth(*sockctrlp, protocol_versionp, auth, + errbuf) == -1) + { + sock_close(*sockctrlp, NULL, 0); + return -1; + } + } + return 0; +} + /* * This function opens a remote adapter by opening an RPCAP connection and * so on. @@ -2105,15 +2189,12 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim char *source_str; struct pcap_rpcap *pr; /* structure used when doing a remote live capture */ char host[PCAP_BUF_SIZE], ctrlport[PCAP_BUF_SIZE], iface[PCAP_BUF_SIZE]; - struct activehosts *activeconn; /* active connection, if there is one */ - int error; /* '1' if rpcap_remoteact_getsock returned an error */ SOCKET sockctrl; uint8 protocol_version; /* negotiated protocol version */ int active; uint32 plen; char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data to be sent is buffered */ int sendbufidx = 0; /* index which keeps the number of bytes currently buffered */ - int retval; /* store the return value of the functions */ /* RPCAP-related variables */ struct rpcap_header header; /* header of the RPCAP packet */ @@ -2152,100 +2233,16 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim pr->rmt_flags = flags; /* - * determine the type of the source (NULL, file, local, remote) - * You must have a valid source string even if we're in active mode, because otherwise - * the call to the following function will fail. + * Attempt to set up the session with the server. */ - if (pcap_parsesrcstr(fp->opt.device, &retval, host, ctrlport, iface, errbuf) == -1) + if (rpcap_setup_session(fp->opt.device, auth, &active, &sockctrl, + &protocol_version, host, ctrlport, iface, errbuf) == -1) { + /* Session setup failed. */ pcap_close(fp); return NULL; } - if (retval != PCAP_SRC_IFREMOTE) - { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "This function is able to open only remote interfaces"); - pcap_close(fp); - return NULL; - } - - /* - * Warning: this call can be the first one called by the user. - * For this reason, we have to initialize the WinSock support. - */ - if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) - { - pcap_close(fp); - return NULL; - } - - /* Check for active mode */ - activeconn = rpcap_remoteact_getsock(host, &error, errbuf); - if (activeconn != NULL) - { - sockctrl = activeconn->sockctrl; - protocol_version = activeconn->protocol_version; - active = 1; - } - else - { - struct addrinfo hints; /* temp, needed to open a socket connection */ - struct addrinfo *addrinfo; /* temp, needed to open a socket connection */ - - if (error) - { - /* - * Call failed. - */ - pcap_close(fp); - return NULL; - } - - /* - * We're not in active mode; let's try to open a new - * control connection. - */ - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - if (ctrlport[0] == 0) - { - /* the user chose not to specify the port */ - if (sock_initaddress(host, RPCAP_DEFAULT_NETPORT, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) - { - pcap_close(fp); - return NULL; - } - } - else - { - if (sock_initaddress(host, ctrlport, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) - { - pcap_close(fp); - return NULL; - } - } - - if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) - { - freeaddrinfo(addrinfo); - pcap_close(fp); - return NULL; - } - - /* addrinfo is no longer used */ - freeaddrinfo(addrinfo); - - if (rpcap_doauth(sockctrl, &protocol_version, auth, errbuf) == -1) - { - sock_close(sockctrl, NULL, 0); - pcap_close(fp); - return NULL; - } - active = 0; - } - /* * Now it's time to start playing with the RPCAP protocol * RPCAP open command: create the request message @@ -2277,7 +2274,7 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim goto error; /* Discard the rest of the message, if there is any. */ - if (rpcap_discard(pr->rmt_sockctrl, plen, errbuf) == -1) + if (rpcap_discard(sockctrl, plen, errbuf) == -1) goto error_nodiscard; /* Set proper fields into the pcap_t struct */ @@ -2315,7 +2312,7 @@ error: * We already reported an error; if this gets an error, just * drive on. */ - (void)rpcap_discard(pr->rmt_sockctrl, plen, NULL); + (void)rpcap_discard(sockctrl, plen, NULL); error_nodiscard: if (!active) @@ -2327,8 +2324,10 @@ error_nodiscard: /* String identifier to be used in the pcap_findalldevs_ex() */ #define PCAP_TEXT_SOURCE_ADAPTER "Network adapter" +#define PCAP_TEXT_SOURCE_ADAPTER_LEN (sizeof PCAP_TEXT_SOURCE_ADAPTER - 1) /* String identifier to be used in the pcap_findalldevs_ex() */ #define PCAP_TEXT_SOURCE_ON_REMOTE_HOST "on remote node" +#define PCAP_TEXT_SOURCE_ON_REMOTE_HOST_LEN (sizeof PCAP_TEXT_SOURCE_ON_REMOTE_HOST - 1) static void freeaddr(struct pcap_addr *addr) @@ -2341,10 +2340,8 @@ freeaddr(struct pcap_addr *addr) } int -pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf) +pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf) { - struct activehosts *activeconn; /* active connection, if there is one */ - int error; /* '1' if rpcap_remoteact_getsock returned an error */ uint8 protocol_version; /* protocol version */ SOCKET sockctrl; /* socket descriptor of the control connection */ uint32 plen; @@ -2352,7 +2349,6 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** int i, j; /* temp variables */ int nif; /* Number of interfaces listed */ int active; /* 'true' if we the other end-party is in active mode */ - int type; char host[PCAP_BUF_SIZE], port[PCAP_BUF_SIZE]; char tmpstring[PCAP_BUF_SIZE + 1]; /* Needed to convert names and descriptions from 'old' syntax to the 'new' one */ pcap_if_t *lastdev; /* Last device in the pcap_if_t list */ @@ -2362,72 +2358,14 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** (*alldevs) = NULL; lastdev = NULL; - /* Retrieve the needed data for getting adapter list */ - if (pcap_parsesrcstr(source, &type, host, port, NULL, errbuf) == -1) - return -1; - - /* Warning: this call can be the first one called by the user. */ - /* For this reason, we have to initialize the WinSock support. */ - if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) - return -1; - - /* Check for active mode */ - activeconn = rpcap_remoteact_getsock(host, &error, errbuf); - if (activeconn != NULL) + /* + * Attempt to set up the session with the server. + */ + if (rpcap_setup_session(source, auth, &active, &sockctrl, + &protocol_version, host, port, NULL, errbuf) == -1) { - sockctrl = activeconn->sockctrl; - protocol_version = activeconn->protocol_version; - active = 1; - } - else - { - struct addrinfo hints; /* temp variable needed to resolve hostnames into to socket representation */ - struct addrinfo *addrinfo; /* temp variable needed to resolve hostnames into to socket representation */ - - if (error) - { - /* - * Call failed. - */ - return -1; - } - - /* - * We're not in active mode; let's try to open a new - * control connection. - */ - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - if (port[0] == 0) - { - /* the user chose not to specify the port */ - if (sock_initaddress(host, RPCAP_DEFAULT_NETPORT, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) - return -1; - } - else - { - if (sock_initaddress(host, port, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) - return -1; - } - - if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) - { - freeaddrinfo(addrinfo); - return -1; - } - - /* addrinfo is no longer used */ - freeaddrinfo(addrinfo); - addrinfo = NULL; - - if (rpcap_doauth(sockctrl, &protocol_version, auth, errbuf) == -1) - { - sock_close(sockctrl, NULL, 0); - return -1; - } - active = 0; + /* Session setup failed. */ + return -1; } /* RPCAP findalldevs command */ @@ -2453,7 +2391,6 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** { struct rpcap_findalldevs_if findalldevs_if; char tmpstring2[PCAP_BUF_SIZE + 1]; /* Needed to convert names and descriptions from 'old' syntax to the 'new' one */ - size_t stringlen; struct pcap_addr *addr, *prevaddr; tmpstring2[PCAP_BUF_SIZE] = 0; @@ -2515,21 +2452,17 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** tmpstring[findalldevs_if.namelen] = 0; /* Create the new device identifier */ - if (pcap_createsrcstr(tmpstring2, PCAP_SRC_IFREMOTE, host, port, tmpstring, errbuf) == -1) - return -1; + if (pcap_createsrcstr(tmpstring2, PCAP_SRC_IFREMOTE, + host, port, tmpstring, errbuf) == -1) + goto error; - stringlen = strlen(tmpstring2); - - dev->name = (char *)malloc(stringlen + 1); + dev->name = strdup(tmpstring2); if (dev->name == NULL) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "malloc() failed"); goto error; } - - /* Copy the new device name into the correct memory location */ - strlcpy(dev->name, tmpstring2, stringlen + 1); } if (findalldevs_if.desclen) @@ -2547,22 +2480,14 @@ pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, pcap_if_t ** tmpstring[findalldevs_if.desclen] = 0; - pcap_snprintf(tmpstring2, sizeof(tmpstring2) - 1, "%s '%s' %s %s", PCAP_TEXT_SOURCE_ADAPTER, - tmpstring, PCAP_TEXT_SOURCE_ON_REMOTE_HOST, host); - - stringlen = strlen(tmpstring2); - - dev->description = (char *)malloc(stringlen + 1); - - if (dev->description == NULL) + if (pcap_asprintf(&dev->description, + "%s '%s' %s %s", PCAP_TEXT_SOURCE_ADAPTER, + tmpstring, PCAP_TEXT_SOURCE_ON_REMOTE_HOST, host) == -1) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "malloc() failed"); goto error; } - - /* Copy the new device description into the correct memory location */ - strlcpy(dev->description, tmpstring2, stringlen + 1); } dev->flags = ntohl(findalldevs_if.flags); @@ -2731,7 +2656,6 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * { if (sock_initaddress(address, RPCAP_DEFAULT_NETPORT_ACTIVE, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_DEBUG_MESSAGE(errbuf); return (SOCKET)-2; } } @@ -2739,7 +2663,6 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * { if (sock_initaddress(address, port, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_DEBUG_MESSAGE(errbuf); return (SOCKET)-2; } } @@ -2747,7 +2670,6 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * if ((sockmain = sock_open(addrinfo, SOCKOPEN_SERVER, 1, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { - SOCK_DEBUG_MESSAGE(errbuf); freeaddrinfo(addrinfo); return (SOCKET)-2; } @@ -2765,14 +2687,14 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * if (sockctrl == INVALID_SOCKET) { - sock_geterror("accept(): ", errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("accept()", errbuf, PCAP_ERRBUF_SIZE); return (SOCKET)-2; } /* Get the numeric for of the name of the connecting host */ if (getnameinfo((struct sockaddr *) &from, fromlen, connectinghost, RPCAP_HOSTLIST_SIZE, NULL, 0, NI_NUMERICHOST)) { - sock_geterror("getnameinfo(): ", errbuf, PCAP_ERRBUF_SIZE); + sock_geterror("getnameinfo()", errbuf, PCAP_ERRBUF_SIZE); rpcap_senderror(sockctrl, 0, PCAP_ERR_REMOTEACCEPT, errbuf, NULL); sock_close(sockctrl, NULL, 0); return (SOCKET)-1; @@ -2971,7 +2893,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf) /* if (getnameinfo( (struct sockaddr *) &temp->host, sizeof (struct sockaddr_storage), hoststr, */ /* RPCAP_HOSTLIST_SIZE, NULL, 0, NI_NUMERICHOST) ) */ { - /* sock_geterror("getnameinfo(): ", errbuf, PCAP_ERRBUF_SIZE); */ + /* sock_geterror("getnameinfo()", errbuf, PCAP_ERRBUF_SIZE); */ return -1; } @@ -2984,7 +2906,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf) return -1; } - strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE); + pcap_strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE); hostlist[len - 1] = sep; hostlist[len] = 0; diff --git a/libpcap/pcap-rpcap.h b/libpcap/pcap-rpcap.h index be31c40d1..6ad6d98d6 100644 --- a/libpcap/pcap-rpcap.h +++ b/libpcap/pcap-rpcap.h @@ -43,7 +43,7 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, /* * Internal interfaces for "pcap_findalldevs_ex()". */ -int pcap_findalldevs_ex_remote(char *source, struct pcap_rmtauth *auth, - pcap_if_t **alldevs, char *errbuf); +int pcap_findalldevs_ex_remote(const char *source, + struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf); #endif diff --git a/libpcap/pcap-savefile.manfile.in b/libpcap/pcap-savefile.manfile.in index 451dd90b7..748d7afcf 100644 --- a/libpcap/pcap-savefile.manfile.in +++ b/libpcap/pcap-savefile.manfile.in @@ -130,4 +130,4 @@ the packet not been truncated by the snapshot length. The two lengths will be equal if the number of bytes of packet data are less than or equal to the snapshot length. .SH SEE ALSO -pcap(3PCAP), pcap-linktype(@MAN_MISC_INFO@) +pcap(3PCAP) diff --git a/libpcap/pcap-septel.c b/libpcap/pcap-septel.c index 0471153fd..24cb47bb3 100644 --- a/libpcap/pcap-septel.c +++ b/libpcap/pcap-septel.c @@ -1,15 +1,6 @@ /* * pcap-septel.c: Packet capture interface for Intel/Septel card. * - * The functionality of this code attempts to mimic that of pcap-linux as much - * as possible. This code is compiled in several different ways depending on - * whether SEPTEL_ONLY and HAVE_SEPTEL_API are defined. If HAVE_SEPTEL_API is - * not defined it should not get compiled in, otherwise if SEPTEL_ONLY is - * defined then the 'septel_' function calls are renamed to 'pcap_' - * equivalents. If SEPTEL_ONLY is not defined then nothing is altered - the - * septel_ functions will be called as required from their - * pcap-linux/equivalents. - * * Authors: Gilbert HOYEK (gil_hoyek@hotmail.com), Elias M. KHOURY * (+961 3 485243) */ @@ -182,7 +173,7 @@ loop: static int septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_) { - strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards", + pcap_strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/libpcap/pcap-sita.c b/libpcap/pcap-sita.c index 7c42791aa..b9dda9c55 100644 --- a/libpcap/pcap-sita.c +++ b/libpcap/pcap-sita.c @@ -884,7 +884,7 @@ static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous, } static int pcap_inject_acn(pcap_t *p, const void *buf _U_, size_t size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters", PCAP_ERRBUF_SIZE); return (-1); } diff --git a/libpcap/pcap-sita.html b/libpcap/pcap-sita.html index 97408d850..4a8fe1a27 100644 --- a/libpcap/pcap-sita.html +++ b/libpcap/pcap-sita.html @@ -411,7 +411,7 @@ A { text-decoration:none } Interface ID 1 - A NULL to indicate an an empty 'interface ID'. + A NULL to indicate an empty 'interface ID'. diff --git a/libpcap/pcap-snf.c b/libpcap/pcap-snf.c index 4eae0b399..50d92cd9e 100644 --- a/libpcap/pcap-snf.c +++ b/libpcap/pcap-snf.c @@ -182,8 +182,8 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) hdr.caplen = caplen; hdr.len = req.length; callback(user, &hdr, req.pkt_addr); + n++; } - n++; /* After one successful packet is received, we won't block * again for that timeout. */ @@ -237,7 +237,7 @@ snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) return (-1); } #else - strlcpy(p->errbuf, "Sending packets isn't supported with this snf version", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported with this snf version", PCAP_ERRBUF_SIZE); return (-1); #endif diff --git a/libpcap/pcap-tc.c b/libpcap/pcap-tc.c index 38c702450..65fb0e2b4 100644 --- a/libpcap/pcap-tc.c +++ b/libpcap/pcap-tc.c @@ -123,7 +123,7 @@ static int TcSetDatalink(pcap_t *p, int dlt); static int TcGetNonBlock(pcap_t *p); static int TcSetNonBlock(pcap_t *p, int nonblock); static void TcCleanup(pcap_t *p); -static int TcInject(pcap_t *p, const void *buf, size_t size); +static int TcInject(pcap_t *p, const void *buf, int size); static int TcRead(pcap_t *p, int cnt, pcap_handler callback, u_char *user); static int TcStats(pcap_t *p, struct pcap_stat *ps); static int TcSetFilter(pcap_t *p, struct bpf_program *fp); @@ -440,7 +440,7 @@ TcFindAllDevs(pcap_if_list_t *devlist, char *errbuf) PTC_PORT pPorts = NULL; TC_STATUS status; int result = 0; - pcap_if_t *dev, *cursor; + pcap_if_t *dev; ULONG i; do @@ -472,22 +472,7 @@ TcFindAllDevs(pcap_if_list_t *devlist, char *errbuf) dev = TcCreatePcapIfFromPort(pPorts[i]); if (dev != NULL) - { - /* - * append it at the end - */ - if (devlistp->beginning == NULL) - { - devlistp->beginning = dev; - } - else - { - for (cursor = devlistp->beginning; - cursor->next != NULL; - cursor = cursor->next); - cursor->next = dev; - } - } + add_dev(devlist, dev->name, dev->flags, dev->description, errbuf); } if (numPorts > 0) @@ -846,7 +831,7 @@ static void TcCleanup(pcap_t *p) } /* Send a packet to the network */ -static int TcInject(pcap_t *p, const void *buf, size_t size) +static int TcInject(pcap_t *p, const void *buf, int size) { struct pcap_tc *pt = p->priv; TC_STATUS status; diff --git a/libpcap/pcap-tstamp.manmisc.in b/libpcap/pcap-tstamp.manmisc.in index 38c565183..6437e80e6 100644 --- a/libpcap/pcap-tstamp.manmisc.in +++ b/libpcap/pcap-tstamp.manmisc.in @@ -93,9 +93,9 @@ call and before a call to specify the type of time stamp to be used on the device. The time stamp types are listed here; the first value is the #define to use in code, the second value is the value returned by -.B pcap_tstamp_type_val_to_name() +.B pcap_tstamp_type_val_to_name(3PCAP) and accepted by -.BR pcap_tstamp_type_name_to_val() . +.BR pcap_tstamp_type_name_to_val(3PCAP) . .RS 5 .TP 5 .BR PCAP_TSTAMP_HOST " - " host @@ -149,9 +149,9 @@ call will fail, and the time stamps supplied after the call will have microsecond resolution. .LP When opening a savefile, the -.BR pcap_open_offline_with_tstamp_precision (3PCAP) +.BR \%pcap_open_offline_with_tstamp_precision (3PCAP) and -.BR pcap_fopen_offline_with_tstamp_precision (3PCAP) +.BR \%pcap_fopen_offline_with_tstamp_precision (3PCAP) routines can be used to specify the resolution of time stamps to be read from the file; if the time stamps in the file have a lower resolution, the fraction-of-a-second portion of the time stamps will be scaled to @@ -165,13 +165,4 @@ the time stamp supplied by the hardware or operating system and, when reading a savefile, this does not indicate the actual precision of time stamps in the file. .SH SEE ALSO -.na -pcap_set_tstamp_type(3PCAP), -pcap_list_tstamp_types(3PCAP), -pcap_tstamp_type_val_to_name(3PCAP), -pcap_tstamp_type_name_to_val(3PCAP), -pcap_set_tstamp_precision(3PCAP), -pcap_open_offline_with_tstamp_precision(3PCAP), -\%pcap_fopen_offline_with_tstamp_precision(3PCAP), -\%pcap_get_tstamp_precision(3PCAP) -.ad +pcap(3PCAP) diff --git a/libpcap/pcap-usb-linux.c b/libpcap/pcap-usb-linux.c index 6f8adf65e..b306dca9b 100644 --- a/libpcap/pcap-usb-linux.c +++ b/libpcap/pcap-usb-linux.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -241,7 +242,7 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str) */ if (add_dev(devlistp, dev_name, PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, - "All USB buses", err_str) == NULL) + "Raw USB traffic, all USB buses", err_str) == NULL) return -1; } else { /* @@ -250,7 +251,7 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str) * PCAP_IF_CONNECTION_STATUS_CONNECTED or * PCAP_IF_CONNECTION_STATUS_DISCONNECTED? */ - pcap_snprintf(dev_descr, 30, "USB bus number %d", n); + pcap_snprintf(dev_descr, 30, "Raw USB traffic, bus number %d", n); if (add_dev(devlistp, dev_name, 0, dev_descr, err_str) == NULL) return -1; } @@ -278,7 +279,7 @@ usb_findalldevs(pcap_if_list_t *devlistp, char *err_str) * Split LINUX_USB_MON_DEV into a directory that we'll * scan and a file name prefix that we'll check for. */ - strlcpy(usb_mon_dir, LINUX_USB_MON_DEV, sizeof usb_mon_dir); + pcap_strlcpy(usb_mon_dir, LINUX_USB_MON_DEV, sizeof usb_mon_dir); usb_mon_prefix = strrchr(usb_mon_dir, '/'); if (usb_mon_prefix == NULL) { /* @@ -380,18 +381,102 @@ usb_findalldevs(pcap_if_list_t *devlistp, char *err_str) } } +/* + * Matches what's in mon_bin.c in the Linux kernel. + */ +#define MIN_RING_SIZE (8*1024) +#define MAX_RING_SIZE (1200*1024) + +static int +usb_set_ring_size(pcap_t* handle, int header_size) +{ + /* + * A packet from binary usbmon has: + * + * 1) a fixed-length header, of size header_size; + * 2) descriptors, for isochronous transfers; + * 3) the payload. + * + * The kernel buffer has a size, defaulting to 300KB, with a + * minimum of 8KB and a maximum of 1200KB. The size is set with + * the MON_IOCT_RING_SIZE ioctl; the size passed in is rounded up + * to a page size. + * + * No more than {buffer size}/5 bytes worth of payload is saved. + * Therefore, if we subtract the fixed-length size from the + * snapshot length, we have the biggest payload we want (we + * don't worry about the descriptors - if we have descriptors, + * we'll just discard the last bit of the payload to get it + * to fit). We multiply that result by 5 and set the buffer + * size to that value. + */ + int ring_size; + + if (handle->snapshot < header_size) + handle->snapshot = header_size; + /* The maximum snapshot size is small enough that this won't overflow */ + ring_size = (handle->snapshot - header_size) * 5; + + /* + * Will this get an error? + * (There's no wqy to query the minimum or maximum, so we just + * copy the value from the kernel source. We don't round it + * up to a multiple of the page size.) + */ + if (ring_size > MAX_RING_SIZE) { + /* + * Yes. Lower the ring size to the maximum, and set the + * snapshot length to the value that would give us a + * maximum-size ring. + */ + ring_size = MAX_RING_SIZE; + handle->snapshot = header_size + (MAX_RING_SIZE/5); + } else if (ring_size < MIN_RING_SIZE) { + /* + * Yes. Raise the ring size to the minimum, but leave + * the snapshot length unchanged, so we show the + * callback no more data than specified by the + * snapshot length. + */ + ring_size = MIN_RING_SIZE; + } + + if (ioctl(handle->fd, MON_IOCT_RING_SIZE, ring_size) == -1) { + pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, + errno, "Can't set ring size from fd %d", handle->fd); + return -1; + } + return ring_size; +} + static int usb_mmap(pcap_t* handle) { struct pcap_usb_linux *handlep = handle->priv; - int len = ioctl(handle->fd, MON_IOCQ_RING_SIZE); - if (len < 0) + int len; + + /* + * Attempt to set the ring size as appropriate for the snapshot + * length, reducing the snapshot length if that'd make the ring + * bigger than the kernel supports. + */ + len = usb_set_ring_size(handle, (int)sizeof(pcap_usb_header_mmapped)); + if (len == -1) { + /* Failed. Fall back on non-memory-mapped access. */ return 0; + } handlep->mmapbuflen = len; handlep->mmapbuf = mmap(0, handlep->mmapbuflen, PROT_READ, MAP_SHARED, handle->fd, 0); - return handlep->mmapbuf != MAP_FAILED; + if (handlep->mmapbuf == MAP_FAILED) { + /* + * Failed. We don't treat that as a fatal error, we + * just try to fall back on non-memory-mapped access. + */ + return 0; + } + return 1; } #ifdef HAVE_LINUX_USBDEVICE_FS_H @@ -514,6 +599,7 @@ usb_activate(pcap_t* handle) { struct pcap_usb_linux *handlep = handle->priv; char full_path[USB_LINE_LEN]; + int ret; /* * Turn a negative snapshot value (invalid), a snapshot value of @@ -604,6 +690,7 @@ usb_activate(pcap_t* handle) /* try to use fast mmap access */ if (usb_mmap(handle)) { + /* We succeeded. */ handle->linktype = DLT_USB_LINUX_MMAPPED; handle->stats_op = usb_stats_linux_bin; handle->read_op = usb_read_linux_mmap; @@ -620,7 +707,19 @@ usb_activate(pcap_t* handle) return 0; } - /* can't mmap, use plain binary interface access */ + /* + * We failed; try plain binary interface access. + * + * Attempt to set the ring size as appropriate for + * the snapshot length, reducing the snapshot length + * if that'd make the ring bigger than the kernel + * supports. + */ + if (usb_set_ring_size(handle, (int)sizeof(pcap_usb_header)) == -1) { + /* Failed. */ + close(handle->fd); + return PCAP_ERROR; + } handle->stats_op = usb_stats_linux_bin; handle->read_op = usb_read_linux_bin; #ifdef HAVE_LINUX_USBDEVICE_FS_H @@ -646,38 +745,38 @@ usb_activate(pcap_t* handle) handle->fd = open(full_path, O_RDONLY, 0); } if (handle->fd < 0) { - /* - * Is the problem that we didn't have - * sufficient permission to open it? - */ - if (errno == EACCES) { + if (errno == ENOENT) + { /* - * Yes - return that error. + * The problem is that the file + * doesn't exist. Report that as + * "no such device". (That could + * mean "no such USB bus" or + * "monitoring not supported".) */ - return PCAP_ERROR_PERM_DENIED; + ret = PCAP_ERROR_NO_SUCH_DEVICE; } - - /* - * No - was the problem something other - * than "it doesn't exist"? - */ - if (errno != ENOENT) { + else if (errno == EACCES) + { /* - * Yes - return *that* error. + * The problem is that we don't + * have sufficient permission to + * open the file. Report that. */ - pcap_fmt_errmsg_for_errno(handle->errbuf, - PCAP_ERRBUF_SIZE, errno, - "Can't open USB bus file %s", - full_path); - return PCAP_ERROR; + ret = PCAP_ERROR_PERM_DENIED; } - - /* - * No. Report that as "no such device". - * (That could mean "no such USB bus" - * or "monitoring not supported".) - */ - return PCAP_ERROR_NO_SUCH_DEVICE; + else + { + /* + * Some other error. + */ + ret = PCAP_ERROR; + } + pcap_fmt_errmsg_for_errno(handle->errbuf, + PCAP_ERRBUF_SIZE, errno, + "Can't open USB bus file %s", + full_path); + return ret; } } @@ -923,8 +1022,8 @@ got: static int usb_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_) { - pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on " - "USB devices"); + pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, + "Packet injection is not supported on USB devices"); return (-1); } @@ -973,6 +1072,10 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats) } string[ret] = 0; + stats->ps_recv = handlep->packets_read; + stats->ps_drop = 0; /* unless we find text_lost */ + stats->ps_ifdrop = 0; + /* extract info on dropped urbs */ for (consumed=0; consumed < ret; ) { /* from the sscanf man page: @@ -989,18 +1092,16 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats) break; consumed += cnt; ptr += cnt; - if (strcmp(token, "nreaders") == 0) - ret = sscanf(ptr, "%d", &stats->ps_drop); + if (strcmp(token, "text_lost") == 0) + ntok = sscanf(ptr, "%d%n", &stats->ps_drop, &cnt); else - ret = sscanf(ptr, "%d", &dummy); - if (ntok != 1) + ntok = sscanf(ptr, "%d%n", &dummy, &cnt); + if ((ntok != 1) || (cnt < 0)) break; consumed += cnt; ptr += cnt; } - stats->ps_recv = handlep->packets_read; - stats->ps_ifdrop = 0; return 0; } @@ -1069,13 +1170,44 @@ usb_read_linux_bin(pcap_t *handle, int max_packets _U_, pcap_handler callback, u return -1; } - /* we can get less that than really captured from kernel, depending on - * snaplen, so adjust header accordingly */ + /* + * info.hdr->data_len is the number of bytes of isochronous + * descriptors (if any) plus the number of bytes of data + * provided. There are no isochronous descriptors here, + * because we're using the old 48-byte header. + * + * If info.hdr->data_flag is non-zero, there's no URB data; + * info.hdr->urb_len is the size of the buffer into which + * data is to be placed; it does not represent the amount + * of data transferred. If info.hdr->data_flag is zero, + * there is URB data, and info.hdr->urb_len is the number + * of bytes transmitted or received; it doesn't include + * isochronous descriptors. + * + * The kernel may give us more data than the snaplen; if it did, + * reduce the data length so that the total number of bytes we + * tell our client we have is not greater than the snaplen. + */ if (info.hdr->data_len < clen) clen = info.hdr->data_len; info.hdr->data_len = clen; - pkth.caplen = clen + sizeof(pcap_usb_header); - pkth.len = info.hdr->data_len + sizeof(pcap_usb_header); + pkth.caplen = sizeof(pcap_usb_header) + clen; + if (info.hdr->data_flag) { + /* + * No data; just base the on-the-wire length on + * info.hdr->data_len (so that it's >= the captured + * length). + */ + pkth.len = sizeof(pcap_usb_header) + info.hdr->data_len; + } else { + /* + * We got data; base the on-the-wire length on + * info.hdr->urb_len, so that it includes data + * discarded by the USB monitor device due to + * its buffer being too small. + */ + pkth.len = sizeof(pcap_usb_header) + info.hdr->urb_len; + } pkth.ts.tv_sec = info.hdr->ts_sec; pkth.ts.tv_usec = info.hdr->ts_usec; @@ -1102,12 +1234,12 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch struct mon_bin_mfetch fetch; int32_t vec[VEC_SIZE]; struct pcap_pkthdr pkth; - pcap_usb_header* hdr; + pcap_usb_header_mmapped* hdr; int nflush = 0; int packets = 0; u_int clen, max_clen; - max_clen = handle->snapshot - sizeof(pcap_usb_header); + max_clen = handle->snapshot - sizeof(pcap_usb_header_mmapped); for (;;) { int i, ret; @@ -1145,19 +1277,52 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch nflush = fetch.nfetch; for (i=0; immapbuf[vec[i]]; + hdr = (pcap_usb_header_mmapped*) &handlep->mmapbuf[vec[i]]; if (hdr->event_type == '@') continue; - /* we can get less that than really captured from kernel, depending on - * snaplen, so adjust header accordingly */ + /* + * hdr->data_len is the number of bytes of + * isochronous descriptors (if any) plus the + * number of bytes of data provided. + * + * If hdr->data_flag is non-zero, there's no + * URB data; hdr->urb_len is the size of the + * buffer into which data is to be placed; it does + * not represent the amount of data transferred. + * If hdr->data_flag is zero, there is URB data, + * and hdr->urb_len is the number of bytes + * transmitted or received; it doesn't include + * isochronous descriptors. + * + * The kernel may give us more data than the + * snaplen; if it did, reduce the data length + * so that the total number of bytes we + * tell our client we have is not greater than + * the snaplen. + */ clen = max_clen; if (hdr->data_len < clen) clen = hdr->data_len; - - /* get packet info from header*/ - pkth.caplen = clen + sizeof(pcap_usb_header_mmapped); - pkth.len = hdr->data_len + sizeof(pcap_usb_header_mmapped); + pkth.caplen = sizeof(pcap_usb_header_mmapped) + clen; + if (hdr->data_flag) { + /* + * No data; just base the on-the-wire length + * on hdr->data_len (so that it's >= the + * captured length). + */ + pkth.len = sizeof(pcap_usb_header_mmapped) + + hdr->data_len; + } else { + /* + * We got data; base the on-the-wire length + * on hdr->urb_len, so that it includes + * data discarded by the USB monitor device + * due to its buffer being too small. + */ + pkth.len = sizeof(pcap_usb_header_mmapped) + + (hdr->ndesc * sizeof (usb_isodesc)) + hdr->urb_len; + } pkth.ts.tv_sec = hdr->ts_sec; pkth.ts.tv_usec = hdr->ts_usec; diff --git a/libpcap/pcap.3pcap.in b/libpcap/pcap.3pcap.in index 4a222c7b6..80101403b 100644 --- a/libpcap/pcap.3pcap.in +++ b/libpcap/pcap.3pcap.in @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP 3PCAP "20 April 2018" +.TH PCAP 3PCAP "25 July 2018" .SH NAME pcap \- Packet Capture library .SH SYNOPSIS @@ -191,6 +191,10 @@ expires even if no packets have arrived. .IP The packet buffer timeout is set with .BR pcap_set_timeout (). +.IP "immediate mode" +In immediate mode, packets are always delivered as soon as they arrive, +with no buffering. Immediate mode is set with +.BR pcap_set_immediate_mode (). .IP "buffer size" Packets that arrive for a capture are stored in a buffer, so that they do not have to be read by the application as soon as they arrive. On @@ -416,6 +420,11 @@ set packet buffer timeout for a not-yet-activated .B pcap_t for live capture .TP +.BR pcap_set_immediate_mode (3PCAP) +set immediate mode for a not-yet-activated +.B pcap_t +for live capture +.TP .BR pcap_set_buffer_size (3PCAP) set buffer size for a not-yet-activated .B pcap_t @@ -632,9 +641,28 @@ or other routines a platform offers to wait for any of a set of descriptors to be ready to read. To obtain, for a handle, a descriptor that can be used in those routines, call .BR pcap_get_selectable_fd (). +If the routine indicates that data is +available to read on the descriptor, an attempt should be made to read +from the device. +.PP Not all handles have such a descriptor available; .BR pcap_get_selectable_fd () -will return \-1 if no such descriptor exists. In addition, for various +will return +.B PCAP_ERROR +if no such descriptor is available. If no such +descriptor is available, this may be because the device must be polled +periodically for packets; in that case, +.BR pcap_get_required_select_timeout () +will return a pointer to a +.B struct timeval +whose value can be used as a timeout in those routines. When the +routine returns, an attmept should be made to read packets from the +device. If +.BR pcap_get_required_select_timeout () +returns NULL, no such timeout is available, and those routines cannot be +used with the device. +.PP +In addition, for various reasons, one or more of those routines will not work properly with the descriptor; the documentation for .BR pcap_get_selectable_fd () @@ -693,6 +721,15 @@ that can be used in calls such as .BR select (2) and .BR poll (2) +.TP +.BR pcap_get_required_select_timeout (3PCAP) +if no descriptor usable with +.BR select (2) +and +.BR poll (2) +is available for the +.BR pcap_t , +attempt to get a timeout usable with those routines .RE .SS Filters In order to cause only certain packets to be returned when reading @@ -890,7 +927,7 @@ To get a string giving version information about libpcap, call .BR pcap_lib_version (3PCAP) get library version string .RE -.SH BACKWARDS COMPATIBILITY +.SH BACKWARD COMPATIBILITY .PP In versions of libpcap prior to 1.0, the .B pcap.h diff --git a/libpcap/pcap.c b/libpcap/pcap.c index 942c472a3..5c8b51a25 100644 --- a/libpcap/pcap.c +++ b/libpcap/pcap.c @@ -139,7 +139,7 @@ BOOL WINAPI DllMain( /* * Start WinSock. - * Exported in case some applications using WinPcap called it, + * Exported in case some applications using WinPcap/Npcap called it, * even though it wasn't exported. */ int @@ -186,76 +186,165 @@ pcap_wsockinit(void) PCAP_API char pcap_version[]; PCAP_API_DEF char pcap_version[] = PACKAGE_VERSION; -static int -pcap_not_initialized(pcap_t *pcap) +static void +pcap_set_not_initialized_message(pcap_t *pcap) { if (pcap->activated) { /* A module probably forgot to set the function pointer */ (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This operation isn't properly handled by that device"); - return (PCAP_ERROR); + return; } /* in case the caller doesn't check for PCAP_ERROR_NOT_ACTIVATED */ (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), "This handle hasn't been activated yet"); +} + +static int +pcap_read_not_initialized(pcap_t *pcap, int cnt _U_, pcap_handler callback _U_, + u_char *user _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_inject_not_initialized(pcap_t *pcap, const void * buf _U_, size_t size _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_setfilter_not_initialized(pcap_t *pcap, struct bpf_program *fp _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_setdirection_not_initialized(pcap_t *pcap, pcap_direction_t d _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_set_datalink_not_initialized(pcap_t *pcap, int dlt _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_getnonblock_not_initialized(pcap_t *pcap) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_stats_not_initialized(pcap_t *pcap, struct pcap_stat *ps _U_) +{ + pcap_set_not_initialized_message(pcap); /* this means 'not initialized' */ return (PCAP_ERROR_NOT_ACTIVATED); } #ifdef _WIN32 -static void * -pcap_not_initialized_ptr(pcap_t *pcap) +struct pcap_stat * +pcap_stats_ex_not_initialized(pcap_t *pcap, int *pcap_stat_size _U_) { - if (pcap->activated) { - /* A module probably forgot to set the function pointer */ - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This operation isn't properly handled by that device"); - return (NULL); - } - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This handle hasn't been activated yet"); + pcap_set_not_initialized_message(pcap); return (NULL); } +static int +pcap_setbuff_not_initialized(pcap_t *pcap, int dim _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_setmode_not_initialized(pcap_t *pcap, int mode _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_setmintocopy_not_initialized(pcap_t *pcap, int size _U_) +{ + pcap_set_not_initialized_message(pcap); + /* this means 'not initialized' */ + return (PCAP_ERROR_NOT_ACTIVATED); +} + static HANDLE pcap_getevent_not_initialized(pcap_t *pcap) { - if (pcap->activated) { - /* A module probably forgot to set the function pointer */ - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This operation isn't properly handled by that device"); - return (INVALID_HANDLE_VALUE); - } - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This handle hasn't been activated yet"); + pcap_set_not_initialized_message(pcap); return (INVALID_HANDLE_VALUE); } +static int +pcap_oid_get_request_not_initialized(pcap_t *pcap, bpf_u_int32 oid _U_, + void *data _U_, size_t *lenp _U_) +{ + pcap_set_not_initialized_message(pcap); + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_oid_set_request_not_initialized(pcap_t *pcap, bpf_u_int32 oid _U_, + const void *data _U_, size_t *lenp _U_) +{ + pcap_set_not_initialized_message(pcap); + return (PCAP_ERROR_NOT_ACTIVATED); +} + static u_int pcap_sendqueue_transmit_not_initialized(pcap_t *pcap, pcap_send_queue* queue, int sync) { - if (pcap->activated) { - /* A module probably forgot to set the function pointer */ - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This operation isn't properly handled by that device"); - return (0); - } - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This handle hasn't been activated yet"); + pcap_set_not_initialized_message(pcap); return (0); } +static int +pcap_setuserbuffer_not_initialized(pcap_t *pcap, int size _U_) +{ + pcap_set_not_initialized_message(pcap); + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_live_dump_not_initialized(pcap_t *pcap, char *filename _U_, int maxsize _U_, + int maxpacks _U_) +{ + pcap_set_not_initialized_message(pcap); + return (PCAP_ERROR_NOT_ACTIVATED); +} + +static int +pcap_live_dump_ended_not_initialized(pcap_t *pcap, int sync _U_) +{ + pcap_set_not_initialized_message(pcap); + return (PCAP_ERROR_NOT_ACTIVATED); +} + static PAirpcapHandle pcap_get_airpcap_handle_not_initialized(pcap_t *pcap) { - if (pcap->activated) { - /* A module probably forgot to set the function pointer */ - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This operation isn't properly handled by that device"); - return (NULL); - } - (void)pcap_snprintf(pcap->errbuf, sizeof(pcap->errbuf), - "This handle hasn't been activated yet"); + pcap_set_not_initialized_message(pcap); return (NULL); } #endif @@ -296,8 +385,17 @@ pcap_list_tstamp_types(pcap_t *p, int **tstamp_typesp) if (p->tstamp_type_count == 0) { /* * We don't support multiple time stamp types. + * That means the only type we support is PCAP_TSTAMP_HOST; + * set up a list containing only that type. */ - *tstamp_typesp = NULL; + *tstamp_typesp = (int*)malloc(sizeof(**tstamp_typesp)); + if (*tstamp_typesp == NULL) { + pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf), + errno, "malloc"); + return (PCAP_ERROR); + } + **tstamp_typesp = PCAP_TSTAMP_HOST; + return (1); } else { *tstamp_typesp = (int*)calloc(sizeof(**tstamp_typesp), p->tstamp_type_count); @@ -308,8 +406,8 @@ pcap_list_tstamp_types(pcap_t *p, int **tstamp_typesp) } (void)memcpy(*tstamp_typesp, p->tstamp_type_list, sizeof(**tstamp_typesp) * p->tstamp_type_count); + return (p->tstamp_type_count); } - return (p->tstamp_type_count); } /* @@ -659,7 +757,7 @@ get_if_description(const char *name) * Get the description for the interface. */ memset(&ifrdesc, 0, sizeof ifrdesc); - strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name); + pcap_strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name); s = socket(AF_INET, SOCK_DGRAM, 0); if (s >= 0) { #ifdef __FreeBSD__ @@ -710,7 +808,7 @@ get_if_description(const char *name) } #endif /* __FreeBSD__ */ close(s); - if (description != NULL && strlen(description) == 0) { + if (description != NULL && description[0] == '\0') { /* * Description is empty, so discard it. */ @@ -741,20 +839,13 @@ get_if_description(const char *name) * OK, it's a valid number that's not * bigger than INT_MAX. Construct * a description from it. + * (If that fails, we don't worry about + * it, we just return NULL.) */ - static const char descr_prefix[] = "USB bus number "; - size_t descr_size; - - /* - * Allow enough room for a 32-bit bus number. - * sizeof (descr_prefix) includes the - * terminating NUL. - */ - descr_size = sizeof (descr_prefix) + 10; - description = malloc(descr_size); - if (description != NULL) { - pcap_snprintf(description, descr_size, - "%s%ld", descr_prefix, busnum); + if (pcap_asprintf(&description, + "USB bus number %ld", busnum) == -1) { + /* Failed. */ + description = NULL; } } } @@ -1292,14 +1383,14 @@ pcap_lookupdev(char *errbuf) * on the list, there aren't any non-loopback devices, * so why not just supply it as the default device? */ - (void)strlcpy(errbuf, "no suitable device found", + (void)pcap_strlcpy(errbuf, "no suitable device found", PCAP_ERRBUF_SIZE); ret = NULL; } else { /* * Return the name of the first device on the list. */ - (void)strlcpy(device, alldevs->name, sizeof(device)); + (void)pcap_strlcpy(device, alldevs->name, sizeof(device)); ret = device; } @@ -1366,7 +1457,7 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, /* XXX Work around Linux kernel bug */ ifr.ifr_addr.sa_family = AF_INET; #endif - (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { if (errno == EADDRNOTAVAIL) { (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, @@ -1385,7 +1476,7 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp, /* XXX Work around Linux kernel bug */ ifr.ifr_addr.sa_family = AF_INET; #endif - (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)pcap_strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "SIOCGIFNETMASK: %s", device); @@ -1575,13 +1666,14 @@ pcap_parse_source(const char *source, char **schemep, char **userinfop, * the pathname. */ if (pcap_strcasecmp(scheme, "file") == 0) { - *schemep = scheme; *pathp = strdup(colonp + 3); if (*pathp == NULL) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc"); + free(scheme); return (-1); } + *schemep = scheme; return (0); } @@ -1684,7 +1776,12 @@ pcap_parse_source(const char *source, char **schemep, char **userinfop, * Treat verything up to the closing square * bracket as the IP-Literal; we don't worry * about whether it's a valid IPv6address or - * IPvFuture. + * IPvFuture (or an IPv4address, for that + * matter, just in case we get handed a + * URL with an IPv4 IP-Literal, of the sort + * that pcap_createsrcstr() used to generate, + * and that pcap_parsesrcstr(), in the original + * WinPcap code, accepted). */ bracketp = strchr(parsep, ']'); if (bracketp == NULL) { @@ -1805,9 +1902,9 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, switch (type) { case PCAP_SRC_FILE: - strlcpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_FILE_STRING, PCAP_BUF_SIZE); if (name != NULL && *name != '\0') { - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, @@ -1816,7 +1913,7 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, } case PCAP_SRC_IFREMOTE: - strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); if (host != NULL && *host != '\0') { if (strchr(host, ':') != NULL) { /* @@ -1824,18 +1921,18 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, * probably an IPv6 address, and needs to * be included in square brackets. */ - strlcat(source, "[", PCAP_BUF_SIZE); - strlcat(source, host, PCAP_BUF_SIZE); - strlcat(source, "]", PCAP_BUF_SIZE); + pcap_strlcat(source, "[", PCAP_BUF_SIZE); + pcap_strlcat(source, host, PCAP_BUF_SIZE); + pcap_strlcat(source, "]", PCAP_BUF_SIZE); } else - strlcat(source, host, PCAP_BUF_SIZE); + pcap_strlcat(source, host, PCAP_BUF_SIZE); if (port != NULL && *port != '\0') { - strlcat(source, ":", PCAP_BUF_SIZE); - strlcat(source, port, PCAP_BUF_SIZE); + pcap_strlcat(source, ":", PCAP_BUF_SIZE); + pcap_strlcat(source, port, PCAP_BUF_SIZE); } - strlcat(source, "/", PCAP_BUF_SIZE); + pcap_strlcat(source, "/", PCAP_BUF_SIZE); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The host name cannot be NULL."); @@ -1843,15 +1940,15 @@ pcap_createsrcstr(char *source, int type, const char *host, const char *port, } if (name != NULL && *name != '\0') - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); case PCAP_SRC_IFLOCAL: - strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); + pcap_strlcpy(source, PCAP_SRC_IF_STRING, PCAP_BUF_SIZE); if (name != NULL && *name != '\0') - strlcat(source, name, PCAP_BUF_SIZE); + pcap_strlcat(source, name, PCAP_BUF_SIZE); return (0); @@ -1890,7 +1987,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * Local device. */ if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFLOCAL; free(tmppath); @@ -1912,12 +2009,12 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, pcap_snprintf(host, PCAP_BUF_SIZE, "%s@%s", tmpuserinfo, tmphost); else - strlcpy(host, tmphost, PCAP_BUF_SIZE); + pcap_strlcpy(host, tmphost, PCAP_BUF_SIZE); } if (port && tmpport) - strlcpy(port, tmpport, PCAP_BUF_SIZE); + pcap_strlcpy(port, tmpport, PCAP_BUF_SIZE); if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFREMOTE; free(tmppath); @@ -1933,7 +2030,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * file:// */ if (name && tmppath) - strlcpy(name, tmppath, PCAP_BUF_SIZE); + pcap_strlcpy(name, tmppath, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_FILE; free(tmppath); @@ -1949,7 +2046,7 @@ pcap_parsesrcstr(const char *source, int *type, char *host, char *port, * as a local device. */ if (name) - strlcpy(name, source, PCAP_BUF_SIZE); + pcap_strlcpy(name, source, PCAP_BUF_SIZE); if (type) *type = PCAP_SRC_IFLOCAL; free(tmppath); @@ -1981,11 +2078,28 @@ pcap_create(const char *device, char *errbuf) else { #ifdef _WIN32 /* - * If the string appears to be little-endian UCS-2/UTF-16, - * convert it to ASCII. + * On Windows, for backwards compatibility reasons, + * pcap_lookupdev() returns a pointer to a sequence of + * pairs of UTF-16LE device names and local code page + * description strings. * - * XXX - to UTF-8 instead? Or report an error if any - * character isn't ASCII? + * This means that if a program uses pcap_lookupdev() + * to get a default device, and hands that to an API + * that opens devices, we'll get handed a UTF-16LE + * string, not a string in the local code page. + * + * To work around that, we check whether the string + * looks as if it might be a UTF-16LE strinh and, if + * so, convert it back to the local code page's + * extended ASCII. + * + * XXX - you *cannot* reliably detect whether a + * string is UTF-16LE or not; "a" could either + * be a one-character ASCII string or the first + * character of a UTF-16LE string. This particular + * version of this heuristic dates back to WinPcap + * 4.1.1; PacketOpenAdapter() does uses the same + * heuristic, with the exact same vulnerability. */ if (device[0] != '\0' && device[1] == '\0') { size_t length; @@ -2077,25 +2191,25 @@ initialize_ops(pcap_t *p) * an activated pcap_t to point to a routine that returns * a "this isn't activated" error. */ - p->read_op = (read_op_t)pcap_not_initialized; - p->inject_op = (inject_op_t)pcap_not_initialized; - p->setfilter_op = (setfilter_op_t)pcap_not_initialized; - p->setdirection_op = (setdirection_op_t)pcap_not_initialized; - p->set_datalink_op = (set_datalink_op_t)pcap_not_initialized; - p->getnonblock_op = (getnonblock_op_t)pcap_not_initialized; - p->stats_op = (stats_op_t)pcap_not_initialized; + p->read_op = pcap_read_not_initialized; + p->inject_op = pcap_inject_not_initialized; + p->setfilter_op = pcap_setfilter_not_initialized; + p->setdirection_op = pcap_setdirection_not_initialized; + p->set_datalink_op = pcap_set_datalink_not_initialized; + p->getnonblock_op = pcap_getnonblock_not_initialized; + p->stats_op = pcap_stats_not_initialized; #ifdef _WIN32 - p->stats_ex_op = (stats_ex_op_t)pcap_not_initialized_ptr; - p->setbuff_op = (setbuff_op_t)pcap_not_initialized; - p->setmode_op = (setmode_op_t)pcap_not_initialized; - p->setmintocopy_op = (setmintocopy_op_t)pcap_not_initialized; + p->stats_ex_op = pcap_stats_ex_not_initialized; + p->setbuff_op = pcap_setbuff_not_initialized; + p->setmode_op = pcap_setmode_not_initialized; + p->setmintocopy_op = pcap_setmintocopy_not_initialized; p->getevent_op = pcap_getevent_not_initialized; - p->oid_get_request_op = (oid_get_request_op_t)pcap_not_initialized; - p->oid_set_request_op = (oid_set_request_op_t)pcap_not_initialized; + p->oid_get_request_op = pcap_oid_get_request_not_initialized; + p->oid_set_request_op = pcap_oid_set_request_not_initialized; p->sendqueue_transmit_op = pcap_sendqueue_transmit_not_initialized; - p->setuserbuffer_op = (setuserbuffer_op_t)pcap_not_initialized; - p->live_dump_op = (live_dump_op_t)pcap_not_initialized; - p->live_dump_ended_op = (live_dump_ended_op_t)pcap_not_initialized; + p->setuserbuffer_op = pcap_setuserbuffer_not_initialized; + p->live_dump_op = pcap_live_dump_not_initialized; + p->live_dump_ended_op = pcap_live_dump_ended_not_initialized; p->get_airpcap_handle_op = pcap_get_airpcap_handle_not_initialized; #endif @@ -2133,7 +2247,7 @@ pcap_alloc_pcap_t(char *ebuf, size_t size) * require 8-byte alignment even on platforms with 32-bit * integers. */ -#define PCAP_T_ALIGNED_SIZE ((sizeof(pcap_t) + 7) & ~0x7) +#define PCAP_T_ALIGNED_SIZE ((sizeof(pcap_t) + 7U) & ~0x7U) chunk = malloc(PCAP_T_ALIGNED_SIZE + size); if (chunk == NULL) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, @@ -2460,6 +2574,16 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, char *er char name[PCAP_BUF_SIZE + 1]; int srctype; + /* + * A null device name is equivalent to the "any" device - + * which might not be supported on this platform, but + * this means that you'll get a "not supported" error + * rather than, say, a crash when we try to dereference + * the null pointer. + */ + if (device == NULL) + device = "any"; + /* * Retrofit - we have to make older applications compatible with * remote capture. @@ -2531,13 +2655,13 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, char *er return (p); fail: if (status == PCAP_ERROR) - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", device, - p->errbuf); + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %.*s", device, + PCAP_ERRBUF_SIZE - 3, p->errbuf); else if (status == PCAP_ERROR_NO_SUCH_DEVICE || status == PCAP_ERROR_PERM_DENIED || status == PCAP_ERROR_PROMISC_PERM_DENIED) - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", device, - pcap_statustostr(status), p->errbuf); + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%.*s)", device, + pcap_statustostr(status), PCAP_ERRBUF_SIZE - 6, p->errbuf); else pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", device, pcap_statustostr(status)); @@ -2850,7 +2974,7 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(FRELAY, "Frame Relay"), DLT_CHOICE(LOOP, "OpenBSD loopback"), DLT_CHOICE(ENC, "OpenBSD encapsulated IP"), - DLT_CHOICE(LINUX_SLL, "Linux cooked"), + DLT_CHOICE(LINUX_SLL, "Linux cooked v1"), DLT_CHOICE(LTALK, "Localtalk"), DLT_CHOICE(PFLOG, "OpenBSD pflog file"), DLT_CHOICE(PFSYNC, "Packet filter state syncing"), @@ -2884,7 +3008,7 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(GPF_T, "GPF-T"), DLT_CHOICE(GPF_F, "GPF-F"), DLT_CHOICE(JUNIPER_PIC_PEER, "Juniper PIC Peer"), - DLT_CHOICE(ERF_ETH, "Ethernet with Endace ERF header"), + DLT_CHOICE(ERF_ETH, "Ethernet with Endace ERF header"), DLT_CHOICE(ERF_POS, "Packet-over-SONET with Endace ERF header"), DLT_CHOICE(LINUX_LAPD, "Linux vISDN LAPD"), DLT_CHOICE(JUNIPER_ETHER, "Juniper Ethernet"), @@ -2908,10 +3032,11 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(SITA, "SITA pseudo-header"), DLT_CHOICE(ERF, "Endace ERF header"), DLT_CHOICE(RAIF1, "Ethernet with u10 Networks pseudo-header"), - DLT_CHOICE(IPMB, "IPMB"), + DLT_CHOICE(IPMB_KONTRON, "IPMB with Kontron pseudo-header"), DLT_CHOICE(JUNIPER_ST, "Juniper Secure Tunnel"), DLT_CHOICE(BLUETOOTH_HCI_H4_WITH_PHDR, "Bluetooth HCI UART transport layer plus pseudo-header"), DLT_CHOICE(AX25_KISS, "AX.25 with KISS header"), + DLT_CHOICE(IPMB_LINUX, "IPMB with Linux/Pigeon Point pseudo-header"), DLT_CHOICE(IEEE802_15_4_NONASK_PHY, "IEEE 802.15.4 with non-ASK PHY data"), DLT_CHOICE(MPLS, "MPLS with label as link-layer header"), DLT_CHOICE(LINUX_EVDEV, "Linux evdev events"), @@ -2968,6 +3093,7 @@ static struct dlt_choice dlt_choices[] = { DLT_CHOICE(DOCSIS31_XRA31, "Excentis XRA-31 DOCSIS 3.1 RF sniffer frames"), DLT_CHOICE(ETHERNET_MPACKET, "802.3br mPackets"), DLT_CHOICE(DISPLAYPORT_AUX, "DisplayPort AUX channel monitoring data"), + DLT_CHOICE(LINUX_SLL2, "Linux cooked v2"), DLT_CHOICE_SENTINEL }; @@ -3007,6 +3133,21 @@ pcap_datalink_val_to_description(int dlt) return (NULL); } +const char * +pcap_datalink_val_to_description_or_dlt(int dlt) +{ + static char unkbuf[40]; + const char *description; + + description = pcap_datalink_val_to_description(dlt); + if (description != NULL) { + return description; + } else { + (void)pcap_snprintf(unkbuf, sizeof(unkbuf), "DLT %u", dlt); + return unkbuf; + } +} + struct tstamp_type_choice { const char *name; const char *description; @@ -3159,7 +3300,7 @@ pcap_getnonblock(pcap_t *p, char *errbuf) * We copy the error message to errbuf, so callers * can find it in either place. */ - strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); } return (ret); } @@ -3203,7 +3344,7 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf) * We copy the error message to errbuf, so callers * can find it in either place. */ - strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, p->errbuf, PCAP_ERRBUF_SIZE); } return (ret); } @@ -3239,35 +3380,6 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock) } #endif -#ifdef _WIN32 -/* - * Generate a string for a Win32-specific error (i.e. an error generated when - * calling a Win32 API). - * For errors occurred during standard C calls, we still use pcap_strerror() - */ -void -pcap_win32_err_to_str(DWORD error, char *errbuf) -{ - size_t errlen; - char *p; - - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf, - PCAP_ERRBUF_SIZE, NULL); - - /* - * "FormatMessage()" "helpfully" sticks CR/LF at the end of the - * message. Get rid of it. - */ - errlen = strlen(errbuf); - if (errlen >= 2) { - errbuf[errlen - 1] = '\0'; - errbuf[errlen - 2] = '\0'; - } - p = strchr(errbuf, '\0'); - pcap_snprintf (p, PCAP_ERRBUF_SIZE+1-(p-errbuf), " (%lu)", error); -} -#endif - /* * Generate error strings for PCAP_ERROR_ and PCAP_WARNING_ values. */ @@ -3339,7 +3451,7 @@ pcap_strerror(int errnum) errno_t err = strerror_s(errbuf, PCAP_ERRBUF_SIZE, errnum); if (err != 0) /* err = 0 if successful */ - strlcpy(errbuf, "strerror_s() error", PCAP_ERRBUF_SIZE); + pcap_strlcpy(errbuf, "strerror_s() error", PCAP_ERRBUF_SIZE); return (errbuf); #else return (strerror(errnum)); @@ -3561,7 +3673,7 @@ pcap_do_addexit(pcap_t *p) /* * "atexit()" failed; let our caller know. */ - strlcpy(p->errbuf, "atexit failed", PCAP_ERRBUF_SIZE); + pcap_strlcpy(p->errbuf, "atexit failed", PCAP_ERRBUF_SIZE); return (0); } did_atexit = 1; diff --git a/libpcap/pcap/bpf.h b/libpcap/pcap/bpf.h index 1a953a9b7..9d748952a 100644 --- a/libpcap/pcap/bpf.h +++ b/libpcap/pcap/bpf.h @@ -238,16 +238,6 @@ struct bpf_insn { bpf_u_int32 k; }; -/* - * Auxiliary data, for use when interpreting a filter intended for the - * Linux kernel when the kernel rejects the filter (requiring us to - * run it in userland). It contains VLAN tag information. - */ -struct bpf_aux_data { - u_short vlan_tag_present; - u_short vlan_tag; -}; - /* * Macros for insn array initializers. */ @@ -256,7 +246,6 @@ struct bpf_aux_data { PCAP_API int bpf_validate(const struct bpf_insn *, int); PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); -extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *); /* * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). diff --git a/libpcap/pcap/compiler-tests.h b/libpcap/pcap/compiler-tests.h index 5e17853a7..ea5962c7b 100644 --- a/libpcap/pcap/compiler-tests.h +++ b/libpcap/pcap/compiler-tests.h @@ -160,4 +160,4 @@ (__HP_aCC >= ((major)*10000 + (minor)*100)) #endif -#endif /* lib_pcap_funcattrs_h */ +#endif /* lib_pcap_compiler_tests_h */ diff --git a/libpcap/pcap/dlt.h b/libpcap/pcap/dlt.h index 535fd50ae..8dacf0240 100644 --- a/libpcap/pcap/dlt.h +++ b/libpcap/pcap/dlt.h @@ -246,7 +246,7 @@ */ /* - * This is for Linux cooked sockets. + * Linux cooked sockets. */ #define DLT_LINUX_SLL 113 @@ -769,11 +769,20 @@ #define DLT_RAIF1 198 /* - * IPMB packet for IPMI, beginning with the I2C slave address, followed - * by the netFn and LUN, etc.. Requested by Chanthy Toeung - * . + * IPMB packet for IPMI, beginning with a 2-byte header, followed by + * the I2C slave address, followed by the netFn and LUN, etc.. + * Requested by Chanthy Toeung . + * + * XXX - this used to be called DLT_IPMB, back when we got the + * impression from the email thread requesting it that the packet + * had no extra 2-byte header. We've renamed it; if anybody used + * DLT_IPMB and assumed no 2-byte header, this will cause the compile + * to fail, at which point we'll have to figure out what to do about + * the two header types using the same DLT_/LINKTYPE_ value. If that + * doesn't happen, we'll assume nobody used it and that the redefinition + * is safe. */ -#define DLT_IPMB 199 +#define DLT_IPMB_KONTRON 199 /* * Juniper-private data link type, as per request from @@ -805,15 +814,34 @@ #define DLT_LAPD 203 /* - * Variants of various link-layer headers, with a one-byte direction - * pseudo-header prepended - zero means "received by this host", - * non-zero (any non-zero value) means "sent by this host" - as per - * Will Barker . + * PPP, with a one-byte direction pseudo-header prepended - zero means + * "received by this host", non-zero (any non-zero value) means "sent by + * this host" - as per Will Barker . */ -#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */ -#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ -#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */ -#define DLT_LAPB_WITH_DIR 207 /* LAPB */ +#define DLT_PPP_WITH_DIR 204 /* Don't confuse with DLT_PPP_WITH_DIRECTION */ + +/* + * Cisco HDLC, with a one-byte direction pseudo-header prepended - zero + * means "received by this host", non-zero (any non-zero value) means + * "sent by this host" - as per Will Barker . + */ +#define DLT_C_HDLC_WITH_DIR 205 + +/* + * Frame Relay, with a one-byte direction pseudo-header prepended - zero + * means "received by this host" (DCE -> DTE), non-zero (any non-zero + * value) means "sent by this host" (DTE -> DCE) - as per Will Barker + * . + */ +#define DLT_FRELAY_WITH_DIR 206 + +/* + * LAPB, with a one-byte direction pseudo-header prepended - zero means + * "received by this host" (DCE -> DTE), non-zero (any non-zero value) + * means "sent by this host" (DTE -> DCE)- as per Will Barker + * . + */ +#define DLT_LAPB_WITH_DIR 207 /* * 208 is reserved for an as-yet-unspecified proprietary link-layer @@ -1367,6 +1395,11 @@ */ #define DLT_DISPLAYPORT_AUX 275 +/* + * Linux cooked sockets v2. + */ +#define DLT_LINUX_SLL2 276 + /* * In case the code that includes this file (directly or indirectly) * has also included OS files that happen to define DLT_MATCHING_MAX, @@ -1377,7 +1410,7 @@ #ifdef DLT_MATCHING_MAX #undef DLT_MATCHING_MAX #endif -#define DLT_MATCHING_MAX 275 /* highest value in the "matching" range */ +#define DLT_MATCHING_MAX 276 /* highest value in the "matching" range */ /* * DLT and savefile link type values are split into a class and diff --git a/libpcap/pcap/funcattrs.h b/libpcap/pcap/funcattrs.h index a8b1932f4..e64da93aa 100644 --- a/libpcap/pcap/funcattrs.h +++ b/libpcap/pcap/funcattrs.h @@ -164,10 +164,11 @@ || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* - * Compiler with support for __attribute((noreturn)), or GCC 2.5 and - * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 - * and later (do any earlier versions of XL C support this?), or - * HP aCC A.06.10 and later. + * Compiler with support for __attribute((noreturn)), or GCC 2.5 or + * later, or some compiler asserting compatibility with GCC 2.5 or + * later, or Solaris Studio 12 (Sun C 5.9) or later, or IBM XL C 10.1 + * or later (do any earlier versions of XL C support this?), or HP aCC + * A.06.10 or later. */ #define PCAP_NORETURN __attribute((noreturn)) #define PCAP_NORETURN_DEF __attribute((noreturn)) @@ -193,7 +194,8 @@ || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) /* - * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1 + * Compiler with support for it, or GCC 2.3 or later, or some compiler + * asserting compatibility with GCC 2.3 or later, or IBM XL C 10.1 * and later (do any earlier versions of XL C support this?), * or HP aCC A.06.10 and later. */ @@ -216,7 +218,7 @@ || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) /* * Compiler that supports __has_attribute and __attribute__((deprecated)), - * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. + * or GCC 4.5 or later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. * * Those support __attribute__((deprecated(msg))) (we assume, perhaps * incorrectly, that anything that supports __has_attribute() is diff --git a/libpcap/pcap/pcap-inttypes.h b/libpcap/pcap/pcap-inttypes.h index af2c23c87..8b1eb8b9b 100644 --- a/libpcap/pcap/pcap-inttypes.h +++ b/libpcap/pcap/pcap-inttypes.h @@ -106,12 +106,23 @@ #define PRIu64 "llu" #endif #endif + + /* + * MSVC's support library doesn't support %zu to print a size_t until + * Visual Studio 2017, but supports %Iu earlier, so use that. + */ + #define PRIsize "Iu" #elif defined(__MINGW32__) || !defined(_WIN32) /* * Compiler is MinGW or target is UN*X or MS-DOS. Just use * . */ #include + + /* + * Assume the support library supports %zu; it's required by C99. + */ + #define PRIsize "zu" #endif #endif /* pcap/pcap-inttypes.h */ diff --git a/libpcap/pcap/pcap.h b/libpcap/pcap/pcap.h index bc87b3f30..90614dd01 100644 --- a/libpcap/pcap/pcap.h +++ b/libpcap/pcap/pcap.h @@ -84,6 +84,8 @@ #include #endif /* _WIN32/MSDOS/UN*X */ +#include /* for SOCKET, as the active-mode rpcap APIs use it */ + #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H #include #endif @@ -468,6 +470,7 @@ PCAP_API void pcap_free_datalinks(int *); PCAP_API int pcap_datalink_name_to_val(const char *); PCAP_API const char *pcap_datalink_val_to_name(int); PCAP_API const char *pcap_datalink_val_to_description(int); +PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int); PCAP_API int pcap_snapshot(pcap_t *); PCAP_API int pcap_is_swapped(pcap_t *); PCAP_API int pcap_major_version(pcap_t *); @@ -483,7 +486,28 @@ PCAP_API int pcap_fileno(pcap_t *); #endif PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); -PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); +#ifdef _WIN32 + PCAP_API pcap_dumper_t *pcap_dump_hopen(pcap_t *, intptr_t); + /* + * If we're building libpcap, this is an internal routine in sf-pcap.c, so + * we must not define it as a macro. + * + * If we're not building libpcap, given that the version of the C runtime + * with which libpcap was built might be different from the version + * of the C runtime with which an application using libpcap was built, + * and that a FILE structure may differ between the two versions of the + * C runtime, calls to _fileno() must use the version of _fileno() in + * the C runtime used to open the FILE *, not the version in the C + * runtime with which libpcap was built. (Maybe once the Universal CRT + * rules the world, this will cease to be a problem.) + */ + #ifndef BUILDING_PCAP + #define pcap_dump_fopen(p,f) \ + pcap_dump_hopen(p, _get_osfhandle(_fileno(f))) + #endif +#else /*_WIN32*/ + PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); +#endif /*_WIN32*/ PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *); PCAP_API FILE *pcap_dump_file(pcap_dumper_t *); PCAP_API long pcap_dump_ftell(pcap_dumper_t *); @@ -858,8 +882,8 @@ PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host, * For listing remote capture devices, pcap_findalldevs_ex() is currently * the only API available. */ -PCAP_API int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, - pcap_if_t **alldevs, char *errbuf); +PCAP_API int pcap_findalldevs_ex(const char *source, + struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf); /* * Sampling methods. @@ -937,27 +961,6 @@ PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p); /* Maximum length of an host name (needed for the RPCAP active mode) */ #define RPCAP_HOSTLIST_SIZE 1024 -/* - * Some minor differences between UN*X sockets and and Winsock sockets. - */ -#ifndef _WIN32 - /*! - * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's - * a file descriptor, and therefore a signed integer. - * We define SOCKET to be a signed integer on UN*X, so that it can - * be used on both platforms. - */ - #define SOCKET int - - /*! - * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET; - * in UN*X, it's -1. - * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on - * both platforms. - */ - #define INVALID_SOCKET -1 -#endif - PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf); diff --git a/libpcap/pcap/sll.h b/libpcap/pcap/sll.h index c4d08862d..392faae4d 100644 --- a/libpcap/pcap/sll.h +++ b/libpcap/pcap/sll.h @@ -74,27 +74,44 @@ #ifndef lib_pcap_sll_h #define lib_pcap_sll_h +#include + /* * A DLT_LINUX_SLL fake link-layer header. */ #define SLL_HDR_LEN 16 /* total header length */ #define SLL_ADDRLEN 8 /* length of address field */ -#include - struct sll_header { uint16_t sll_pkttype; /* packet type */ uint16_t sll_hatype; /* link-layer address type */ uint16_t sll_halen; /* link-layer address length */ - uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ + uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ uint16_t sll_protocol; /* protocol */ }; /* - * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the - * PACKET_ values on Linux, but are defined here so that they're - * available even on systems other than Linux, and so that they - * don't change even if the PACKET_ values change. + * A DLT_LINUX_SLL2 fake link-layer header. + */ +#define SLL2_HDR_LEN 20 /* total header length */ + +struct sll2_header { + uint16_t sll2_protocol; /* protocol */ + uint16_t sll2_reserved_mbz; /* reserved - must be zero */ + uint32_t sll2_if_index; /* 1-based interface index */ + uint16_t sll2_hatype; /* link-layer address type */ + uint8_t sll2_pkttype; /* packet type */ + uint8_t sll2_halen; /* link-layer address length */ + uint8_t sll2_addr[SLL_ADDRLEN]; /* link-layer address */ +}; + +/* + * The LINUX_SLL_ values for "sll_pkttype" and LINUX_SLL2_ values for + * "sll2_pkttype"; these correspond to the PACKET_ values on Linux, + * which are defined by a header under include/uapi in the current + * kernel source, and are thus not going to change on Linux. We + * define them here so that they're available even on systems other + * than Linux. */ #define LINUX_SLL_HOST 0 #define LINUX_SLL_BROADCAST 1 @@ -103,10 +120,11 @@ struct sll_header { #define LINUX_SLL_OUTGOING 4 /* - * The LINUX_SLL_ values for "sll_protocol"; these correspond to the - * ETH_P_ values on Linux, but are defined here so that they're - * available even on systems other than Linux. We assume, for now, - * that the ETH_P_ values won't change in Linux; if they do, then: + * The LINUX_SLL_ values for "sll_protocol" and LINUX_SLL2_ values for + * "sll2_protocol"; these correspond to the ETH_P_ values on Linux, but + * are defined here so that they're available even on systems other than + * Linux. We assume, for now, that the ETH_P_ values won't change in + * Linux; if they do, then: * * if we don't translate them in "pcap-linux.c", capture files * won't necessarily be readable if captured on a system that diff --git a/libpcap/pcap/socket.h b/libpcap/pcap/socket.h new file mode 100644 index 000000000..6f27cba12 --- /dev/null +++ b/libpcap/pcap/socket.h @@ -0,0 +1,93 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. 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. + */ + +#ifndef lib_pcap_socket_h +#define lib_pcap_socket_h + +/* + * Some minor differences between sockets on various platforms. + * We include whatever sockets are needed for Internet-protocol + * socket access on UN*X and Windows. + */ +#ifdef _WIN32 + /* Need windef.h for defines used in winsock2.h under MingW32 */ + #ifdef __MINGW32__ + #include + #endif + #include + #include + + /* + * Winsock doesn't have this UN*X type; it's used in the UN*X + * sockets API. + * + * XXX - do we need to worry about UN*Xes so old that *they* + * don't have it, either? + */ + typedef int socklen_t; + + /* + * Winsock doesn't have this POSIX type; it's used for the + * tv_usec value of struct timeval. + */ + typedef long suseconds_t; +#else /* _WIN32 */ + #include + #include + #include /* for struct addrinfo/getaddrinfo() */ + #include /* for sockaddr_in, in BSD at least */ + #include + + /*! + * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's + * a file descriptor, and therefore a signed integer. + * We define SOCKET to be a signed integer on UN*X, so that it can + * be used on both platforms. + */ + #ifndef SOCKET + #define SOCKET int + #endif + + /*! + * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET; + * in UN*X, it's -1. + * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on + * both platforms. + */ + #ifndef INVALID_SOCKET + #define INVALID_SOCKET -1 + #endif +#endif /* _WIN32 */ + +#endif /* lib_pcap_socket_h */ diff --git a/libpcap/pcap_activate.3pcap b/libpcap/pcap_activate.3pcap index ceb2aa74f..162a92933 100644 --- a/libpcap/pcap_activate.3pcap +++ b/libpcap/pcap_activate.3pcap @@ -50,15 +50,15 @@ promiscuous mode. .TP .B PCAP_WARNING_TSTAMP_TYPE_NOTSUP The time stamp type specified in a previous -.B pcap_set_tstamp_type() +.B pcap_set_tstamp_type(3PCAP) call isn't supported by the capture source (the time stamp type is left as the default), .TP .B PCAP_WARNING Another warning condition occurred; -.B pcap_geterr() +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display a message describing the warning @@ -115,7 +115,7 @@ Additional warning and error codes may be added in the future; a program should check for positive, negative, and zero return codes, and treat all positive return codes as warnings and all negative return codes as errors. -.B pcap_statustostr() +.B pcap_statustostr(3PCAP) can be called, with a warning or error code as an argument, to fetch a message describing the warning or error code. .SH SEE ALSO diff --git a/libpcap/pcap_breakloop.3pcap b/libpcap/pcap_breakloop.3pcap index 03b8d8d1a..cc000d2e0 100644 --- a/libpcap/pcap_breakloop.3pcap +++ b/libpcap/pcap_breakloop.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_BREAKLOOP 3PCAP "8 November 2017" +.TH PCAP_BREAKLOOP 3PCAP "25 July 2018" .SH NAME pcap_breakloop \- force a pcap_dispatch() or pcap_loop() call to return .SH SYNOPSIS @@ -33,12 +33,13 @@ void pcap_breakloop(pcap_t *); .SH DESCRIPTION .B pcap_breakloop() sets a flag that will force -.B pcap_dispatch() +.B pcap_dispatch(3PCAP) or -.B pcap_loop() +.B pcap_loop(3PCAP) to return rather than looping; they will return the number of packets -that have been processed so far, or \-2 if no packets have been -processed so far. +that have been processed so far, or +.B PCAP_ERROR_BREAK +if no packets have been processed so far. .PP This routine is safe to use inside a signal handler on UNIX or a console control handler on Windows, as it merely sets a flag that is checked @@ -60,7 +61,7 @@ packets arrive and the call completes. .PP .ft B Note also that, in a multi-threaded application, if one thread is -blocked in pcap_dispatch(), pcap_loop(), pcap_next(), or pcap_next_ex(), +blocked in pcap_dispatch(), pcap_loop(), pcap_next(3PCAP), or pcap_next_ex(3PCAP), a call to pcap_breakloop() in a different thread will not unblock that thread. .ft R @@ -99,12 +100,16 @@ or .B pcap_loop() after it is called; at most one more packet might be processed. .PP -If \-2 is returned from +If +.B PCAP_ERROR_BREAK +is returned from .B pcap_dispatch() or .BR pcap_loop() , the flag is cleared, so a subsequent call will resume reading packets. If a positive number is returned, the flag is not cleared, so a -subsequent call will return \-2 and clear the flag. +subsequent call will return +.B PCAP_ERROR_BREAK +and clear the flag. .SH SEE ALSO -pcap(3PCAP), pcap_loop(3PCAP), pcap_next_ex(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_can_set_rfmon.3pcap b/libpcap/pcap_can_set_rfmon.3pcap index eee004dd9..0baac7a64 100644 --- a/libpcap/pcap_can_set_rfmon.3pcap +++ b/libpcap/pcap_can_set_rfmon.3pcap @@ -54,9 +54,9 @@ The capture handle has already been activated. .TP .B PCAP_ERROR Another error occurred. -.B pcap_geterr() +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B \%pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display a message describing the error. @@ -64,7 +64,7 @@ as an argument to fetch or display a message describing the error. Additional error codes may be added in the future; a program should check for 0, 1, and negative, return codes, and treat all negative return codes as errors. -.B pcap_statustostr() +.B pcap_statustostr(3PCAP) can be called, with a warning or error code as an argument, to fetch a message describing the warning or error code. .SH SEE ALSO diff --git a/libpcap/pcap_compile.3pcap.in b/libpcap/pcap_compile.3pcap.in index 29ae8f8a8..824f52b32 100644 --- a/libpcap/pcap_compile.3pcap.in +++ b/libpcap/pcap_compile.3pcap.in @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_COMPILE 3PCAP "24 March 2017" +.TH PCAP_COMPILE 3PCAP "22 August 2018" .SH NAME pcap_compile \- compile a filter expression .SH SYNOPSIS @@ -52,7 +52,9 @@ captured; it is used only when checking for IPv4 broadcast addresses in the filter program. If the netmask of the network on which packets are being captured isn't known to the program, or if packets are being captured on the Linux "any" pseudo-interface that can capture on more -than one network, a value of PCAP_NETMASK_UNKNOWN can be supplied; tests +than one network, a value of +.B PCAP_NETMASK_UNKNOWN +can be supplied; tests for IPv4 broadcast addresses will fail to compile, but all other tests in the filter program will be OK. .LP @@ -67,14 +69,21 @@ in multiple threads in a single process without some form of mutual exclusion allowing only one thread to call it at any given time. .SH RETURN VALUE .B pcap_compile() -returns 0 on success and \-1 on failure. -If \-1 is returned, -.B pcap_geterr() +returns 0 on success and +.B PCAP_ERROR +on failure. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. +.SH BACKWARD COMPATIBILITY +.PP +The +.B PCAP_NETMASK_UNKNOWN +constant became available in libpcap release 1.1.0. .SH SEE ALSO pcap(3PCAP), pcap_setfilter(3PCAP), pcap_freecode(3PCAP), -pcap_geterr(3PCAP), pcap-filter(@MAN_MISC_INFO@) diff --git a/libpcap/pcap_create.3pcap b/libpcap/pcap_create.3pcap index 3040b3b20..5a15007bf 100644 --- a/libpcap/pcap_create.3pcap +++ b/libpcap/pcap_create.3pcap @@ -48,7 +48,7 @@ argument of "any" or can be used to capture packets from all interfaces. .PP The returned handle must be activated with -.B pcap_activate() +.B pcap_activate(3PCAP) before packets can be captured with it; options for the capture, such as promiscuous mode, can be set on the handle before activating it. @@ -69,4 +69,4 @@ is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. .SH SEE ALSO -pcap(3PCAP), pcap_activate(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_datalink.3pcap.in b/libpcap/pcap_datalink.3pcap.in index a32f15ec6..26203683e 100644 --- a/libpcap/pcap_datalink.3pcap.in +++ b/libpcap/pcap_datalink.3pcap.in @@ -37,9 +37,9 @@ specified by .IR p . .PP It must not be called on a pcap descriptor created by -.B pcap_create() +.B \%pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . +.BR \%pcap_activate(3PCAP) . .PP .I https://www.tcpdump.org/linktypes.html lists the values diff --git a/libpcap/pcap_datalink_name_to_val.3pcap b/libpcap/pcap_datalink_name_to_val.3pcap index e6419f25c..dd4688f0a 100644 --- a/libpcap/pcap_datalink_name_to_val.3pcap +++ b/libpcap/pcap_datalink_name_to_val.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_DATALINK_NAME_TO_VAL 3PCAP "12 October 2016" +.TH PCAP_DATALINK_NAME_TO_VAL 3PCAP "25 July 2018" .SH NAME pcap_datalink_name_to_val \- get the link-layer header type value corresponding to a header type name @@ -41,7 +41,9 @@ removed, to the corresponding link-layer header type value. The translation is case-insensitive. .SH RETURN VALUE .B pcap_datalink_name_to_val() -returns the type value on success and \-1 if the name is not a known +returns the type value on success and +.B PCAP_ERROR +if the name is not a known type name.. .SH SEE ALSO pcap(3PCAP) diff --git a/libpcap/pcap_datalink_val_to_name.3pcap b/libpcap/pcap_datalink_val_to_name.3pcap index fad350fd0..f42165fba 100644 --- a/libpcap/pcap_datalink_val_to_name.3pcap +++ b/libpcap/pcap_datalink_val_to_name.3pcap @@ -19,7 +19,8 @@ .\" .TH PCAP_DATALINK_VAL_TO_NAME 3PCAP "12 October 2016" .SH NAME -pcap_datalink_val_to_name, pcap_datalink_val_to_description \- get a +pcap_datalink_val_to_name, pcap_datalink_val_to_description, +pcap_datalink_val_to_description_or_dlt \- get a name or description for a link-layer header type value .SH SYNOPSIS .nf @@ -30,6 +31,7 @@ name or description for a link-layer header type value .ft B const char *pcap_datalink_val_to_name(int dlt); const char *pcap_datalink_val_to_description(int dlt); +const char *pcap_datalink_val_to_description_or_dlt(int dlt); .ft .fi .SH DESCRIPTION @@ -52,3 +54,13 @@ link-layer header type. is returned if the type value does not correspond to a known .B DLT_ value. +.PP +.B pcap_datalink_val_to_description_or_dlt() +translates a link-layer header type value to a short description of that +link-layer header type just like pcap_datalink_val_to_description. +If the type value does not correspond to a known +.B DLT_ +value, the string "DLT n" is returned, where n is the value of +the dlt argument. +.SH SEE ALSO +pcap(3PCAP) diff --git a/libpcap/pcap_dump.3pcap b/libpcap/pcap_dump.3pcap index 6402b4b45..7f201b7ce 100644 --- a/libpcap/pcap_dump.3pcap +++ b/libpcap/pcap_dump.3pcap @@ -35,11 +35,11 @@ u_char *sp); .SH DESCRIPTION .B pcap_dump() outputs a packet to the ``savefile'' opened with -.BR pcap_dump_open() . +.BR pcap_dump_open(3PCAP) . Note that its calling arguments are suitable for use with -.B pcap_dispatch() +.B pcap_dispatch(3PCAP) or -.BR pcap_loop() . +.BR pcap_loop(3PCAP) . If called directly, the .I user parameter is of type @@ -47,5 +47,4 @@ parameter is of type as returned by .BR pcap_dump_open() . .SH SEE ALSO -pcap(3PCAP), pcap_dump_open(3PCAP), pcap_dispatch(3PCAP), -pcap_loop(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_dump_file.3pcap b/libpcap/pcap_dump_file.3pcap index 8fea610a4..d2074312d 100644 --- a/libpcap/pcap_dump_file.3pcap +++ b/libpcap/pcap_dump_file.3pcap @@ -33,6 +33,6 @@ FILE *pcap_dump_file(pcap_dumper_t *p); .SH DESCRIPTION .B pcap_dump_file() returns the standard I/O stream of the ``savefile'' opened by -.BR pcap_dump_open() . +.BR pcap_dump_open(3PCAP) . .SH SEE ALSO pcap(3PCAP) diff --git a/libpcap/pcap_dump_flush.3pcap b/libpcap/pcap_dump_flush.3pcap index c8f110bb6..5d1747452 100644 --- a/libpcap/pcap_dump_flush.3pcap +++ b/libpcap/pcap_dump_flush.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_DUMP_FLUSH 3PCAP "3 January 2014" +.TH PCAP_DUMP_FLUSH 3PCAP "25 July 2018" .SH NAME pcap_dump_flush \- flush to a savefile packets dumped .SH SYNOPSIS @@ -34,10 +34,12 @@ int pcap_dump_flush(pcap_dumper_t *p); .B pcap_dump_flush() flushes the output buffer to the ``savefile,'' so that any packets written with -.B pcap_dump() +.B pcap_dump(3PCAP) but not yet written to the ``savefile'' will be written. .SH RETURN VALUE .B pcap_dump_flush() -returns 0 on success and \-1 on failure. +returns 0 on success and +.B PCAP_ERROR +on failure. .SH SEE ALSO -pcap(3PCAP), pcap_dump_open(3PCAP), pcap_dump(3PCAP) +pcap(3PCAP), pcap_dump_open(3PCAP) diff --git a/libpcap/pcap_dump_ftell.3pcap b/libpcap/pcap_dump_ftell.3pcap index ec621fb39..20cb995ea 100644 --- a/libpcap/pcap_dump_ftell.3pcap +++ b/libpcap/pcap_dump_ftell.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_DUMP_FTELL 3PCAP "29 September 2017" +.TH PCAP_DUMP_FTELL 3PCAP "25 July 2018" .SH NAME pcap_dump_ftell, pcap_dump_ftell64 \- get the current file offset for a savefile being written .SH SYNOPSIS @@ -36,11 +36,11 @@ int64_t pcap_dump_ftell64(pcap_dumper_t *p); .B pcap_dump_ftell() returns the current file position for the ``savefile'', representing the number of bytes written by -.B pcap_dump_open() +.B pcap_dump_open(3PCAP) and -.BR pcap_dump() . -\-1 is returned on error. -If the current file position does not fit in a +.BR pcap_dump(3PCAP) . +.B PCAP_ERROR +is returned on error. If the current file position does not fit in a .BR long , it will be truncated; this can happen on 32-bit UNIX-like systems with large file support and on Windows. @@ -52,6 +52,7 @@ so if file offsets that don't fit in a but that fit in a .B int64_t are supported, this will return the file offset without truncation. -\-1 is returned on error. +.B PCAP_ERROR +is returned on error. .SH SEE ALSO -pcap(3PCAP), pcap_dump_open(3PCAP), pcap_dump(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_dump_open.3pcap.in b/libpcap/pcap_dump_open.3pcap.in index 5b37b47c7..b86696f08 100644 --- a/libpcap/pcap_dump_open.3pcap.in +++ b/libpcap/pcap_dump_open.3pcap.in @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_DUMP_OPEN 3PCAP "22 June 2018" +.TH PCAP_DUMP_OPEN 3PCAP "22 August 2018" .SH NAME pcap_dump_open, pcap_dump_fopen \- open a file to which to write packets .SH SYNOPSIS @@ -50,26 +50,26 @@ for is called to write data to an existing open stream .IR fp ; this stream will be closed by a subsequent call to -.BR pcap_dump_close() . +.BR pcap_dump_close(3PCAP) . Note that on Windows, that stream should be opened in binary mode. .PP .I p is a capture or ``savefile'' handle returned by an earlier call to -.B pcap_create() +.B pcap_create(3PCAP) and activated by an earlier call to -.BR pcap_activate() , +.BR \%pcap_activate(3PCAP) , or returned by an earlier call to -.BR pcap_open_offline() , -.BR pcap_open_live() , +.BR \%pcap_open_offline(3PCAP) , +.BR pcap_open_live(3PCAP) , or -.BR pcap_open_dead() . +.BR pcap_open_dead(3PCAP) . The time stamp precision, link-layer type, and snapshot length from .I p are used as the link-layer type and snapshot length of the output file. .PP .B pcap_dump_open_append() is like -.B pcap_dump_open +.B pcap_dump_open() but does not create the file if it does not exist and, if it does already exist, and is a pcap file with the same byte order as the host opening the file, and has the same time stamp precision, link-layer @@ -80,19 +80,24 @@ it will write new packets at the end of the file. A pointer to a .B pcap_dumper_t structure to use in subsequent -.B pcap_dump() +.B pcap_dump(3PCAP) and -.B pcap_dump_close() +.B pcap_dump_close(3PCAP) calls is returned on success. .B NULL is returned on failure. If .B NULL is returned, -.B pcap_geterr(\fIp\fB) +.B pcap_geterr(3PCAP) can be used to get the error text. +.SH BACKWARD COMPATIBILITY +.PP +The +.B pcap_dump_open_append() +function became available in libpcap release 1.7.2. In previous +releases, there is no support for appending packets to an existing +savefile. .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), -\%pcap_open_offline(3PCAP), pcap_open_live(3PCAP), pcap_open_dead(3PCAP), -pcap_dump(3PCAP), pcap_dump_close(3PCAP), pcap_geterr(3PCAP), +pcap(3PCAP), \%pcap-savefile(@MAN_FILE_FORMATS@) diff --git a/libpcap/pcap_file.3pcap b/libpcap/pcap_file.3pcap index cd6b06bb8..981451ba5 100644 --- a/libpcap/pcap_file.3pcap +++ b/libpcap/pcap_file.3pcap @@ -34,13 +34,15 @@ FILE *pcap_file(pcap_t *p); .B pcap_file() returns the standard I/O stream of the ``savefile,'' if a ``savefile'' was opened with -.BR pcap_open_offline() , -or NULL, if a network device was opened with -.B pcap_create() +.BR pcap_open_offline(3PCAP) , +or +.BR NULL , +if a network device was opened with +.B pcap_create(3PCAP) and -.BR pcap_activate() , +.BR \%pcap_activate(3PCAP) , or with -.BR pcap_open_live() . +.BR pcap_open_live(3PCAP) . .PP Note that the Packet Capture library is usually built with large file support, so the standard I/O stream of the ``savefile'' might refer to @@ -50,8 +52,8 @@ should, if possible, use calls that support large files on the return value of .B pcap_file() or the value returned by -.B fileno() +.B fileno(3) when passed the return value of .BR pcap_file() . .SH SEE ALSO -pcap(3PCAP), pcap_open_offline(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_fileno.3pcap b/libpcap/pcap_fileno.3pcap index e8c9ac4d4..60ac12945 100644 --- a/libpcap/pcap_fileno.3pcap +++ b/libpcap/pcap_fileno.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_FILENO 3PCAP "7 April 2014" +.TH PCAP_FILENO 3PCAP "25 July 2018" .SH NAME pcap_fileno \- get the file descriptor for a live capture .SH SYNOPSIS @@ -35,32 +35,31 @@ If .I p refers to a network device that was opened for a live capture using a combination of -.B pcap_create() +.B pcap_create(3PCAP) and -.BR pcap_activate() , +.BR pcap_activate(3PCAP) , or using -.BR pcap_open_live() , +.BR pcap_open_live(3PCAP) , .B pcap_fileno() returns the file descriptor from which captured packets are read. .LP If .I p refers to a ``savefile'' that was opened using functions such as -.BR pcap_open_offline() +.BR pcap_open_offline(3PCAP) or -.BR pcap_fopen_offline() , +.BR pcap_fopen_offline(3PCAP) , a ``dead'' .B pcap_t opened using -.BR pcap_open_dead() , +.BR pcap_open_dead(3PCAP) , or a .B pcap_t that was created with .B pcap_create() but that has not yet been activated with .BR pcap_activate() , -it returns \-1. +it returns +.BR PCAP_ERROR . .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), -pcap_open_live(3PCAP), pcap_open_offline(3PCAP), -\%pcap_fopen_offline(3PCAP), pcap_open_dead(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_findalldevs.3pcap b/libpcap/pcap_findalldevs.3pcap index 14825ad17..712e255a0 100644 --- a/libpcap/pcap_findalldevs.3pcap +++ b/libpcap/pcap_findalldevs.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_FINDALLDEVS 3PCAP "29 April 2018" +.TH PCAP_FINDALLDEVS 3PCAP "22 August 2018" .SH NAME pcap_findalldevs, pcap_freealldevs \- get a list of capture devices, and free that list @@ -40,11 +40,11 @@ void pcap_freealldevs(pcap_if_t *alldevs); .SH DESCRIPTION .B pcap_findalldevs() constructs a list of network devices that can be opened with -.B pcap_create() +.B pcap_create(3PCAP) and -.B pcap_activate() +.B pcap_activate(3PCAP) or with -.BR pcap_open_live() . +.BR pcap_open_live(3PCAP) . (Note that there may be network devices that cannot be opened by the process calling .BR pcap_findalldevs() , @@ -194,21 +194,38 @@ for IPv6 addresses, it can be interpreted as if it pointed to a .BR "struct sockaddr_in6". .PP The list of devices must be freed with -.BR pcap_freealldevs() , +.BR pcap_freealldevs(3PCAP) , which frees the list pointed to by .IR alldevs . .SH RETURN VALUE .B pcap_findalldevs() -returns 0 on success and \-1 on failure; as indicated, finding no +returns 0 on success and +.B PCAP_ERROR +on failure; as indicated, finding no devices is considered success, rather than failure, so 0 will be -returned in that case. -If \-1 is returned, +returned in that case. If +.B PCAP_ERROR +is returned, .I errbuf is filled in with an appropriate error message. .I errbuf is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. +.SH BACKWARD COMPATIBILITY +.PP +The +.B PCAP_IF_UP +and +.B PCAP_IF_RUNNING +constants became available in libpcap release 1.6.1. The +.BR PCAP_IF_WIRELESS , +.BR PCAP_IF_CONNECTION_STATUS , +.BR PCAP_IF_CONNECTION_STATUS_UNKNOWN , +.BR PCAP_IF_CONNECTION_STATUS_CONNECTED , +.BR PCAP_IF_CONNECTION_STATUS_DISCONNECTED , +and +.B PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE +constants became available in libpcap release 1.9.0. .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), -pcap_open_live(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_freecode.3pcap b/libpcap/pcap_freecode.3pcap index fac4b3df2..4e71efa49 100644 --- a/libpcap/pcap_freecode.3pcap +++ b/libpcap/pcap_freecode.3pcap @@ -35,9 +35,9 @@ void pcap_freecode(struct bpf_program *); is used to free up allocated memory pointed to by a .I bpf_program struct generated by -.B pcap_compile() +.B pcap_compile(3PCAP) when that BPF program is no longer needed, for example after it has been made the filter program for a pcap structure by a call to -.BR pcap_setfilter() . +.BR pcap_setfilter(3PCAP) . .SH SEE ALSO -pcap(3PCAP), pcap_compile(3PCAP), pcap_setfilter(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_get_selectable_fd.3pcap b/libpcap/pcap_get_selectable_fd.3pcap index f1ddfe2dc..7f43db398 100644 --- a/libpcap/pcap_get_selectable_fd.3pcap +++ b/libpcap/pcap_get_selectable_fd.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_GET_SELECTABLE_FD 3PCAP "20 January 2018" +.TH PCAP_GET_SELECTABLE_FD 3PCAP "25 July 2018" .SH NAME pcap_get_selectable_fd \- get a file descriptor on which a select() can be done for a live capture @@ -36,32 +36,38 @@ int pcap_get_selectable_fd(pcap_t *p); returns, on UNIX, a file descriptor number for a file descriptor on which one can do a -.BR select() , -.BR poll() , -.BR epoll_wait() , +.BR select(2) , +.BR poll(2) , +.BR epoll_wait(2) , .BR kevent() , or other such call to wait for it to be possible to read packets without blocking, if such -a descriptor exists, or \-1, if no such descriptor exists. +a descriptor exists, or +.BR PCAP_ERROR , +if no such descriptor exists. .PP Some network devices opened with -.B pcap_create() +.B pcap_create(3PCAP) and -.BR pcap_activate() , +.BR pcap_activate(3PCAP) , or with -.BR pcap_open_live() , +.BR pcap_open_live(3PCAP) , do not support those calls (for example, regular network devices on -FreeBSD 4.3 and 4.4, and Endace DAG devices), so \-1 is returned for +FreeBSD 4.3 and 4.4, and Endace DAG devices), so +.B PCAP_ERROR +is returned for those devices. In that case, those calls must be given a timeout less than or equal to the timeout returned by -.B pcap_get_required_select_timeout() +.B pcap_get_required_select_timeout(3PCAP) for the device for which .B pcap_get_selectable_fd() -returned \-1, the device must be put in non-blocking mode with a call to -.BR pcap_setnonblock() , +returned +.BR PCAP_ERROR , +the device must be put in non-blocking mode with a call to +.BR \%pcap_setnonblock(3PCAP) , and an attempt must always be made to read packets from the device when the call returns. If -.B pcap_get_required_select_timeout() +.B \%pcap_get_required_select_timeout() returns .BR NULL , it is not possible to wait for packets to arrive on the device in an @@ -70,9 +76,9 @@ event loop. Note that a device on which a read can be done without blocking may, on some platforms, not have any packets to read if the packet buffer timeout has expired. A call to -.B pcap_dispatch() +.B pcap_dispatch(3PCAP) or -.B pcap_next_ex() +.B pcap_next_ex(3PCAP) will return 0 in this case, but will not block. .PP Note that in: @@ -138,8 +144,8 @@ work on that descriptor in Mac OS X 10.6 and later. .B pcap_get_selectable_fd() is not available on Windows. .SH RETURN VALUE -A selectable file descriptor is returned if one exists; otherwise, \-1 +A selectable file descriptor is returned if one exists; otherwise, +.B PCAP_ERROR is returned. .SH SEE ALSO -pcap(3PCAP), pcap_get_required_select_timeout(3PCAP), -pcap_setnonblock(3PCAP), select(2), poll(2), epoll_wait(2), kqueue(2) +pcap(3PCAP), kqueue(2) diff --git a/libpcap/pcap_get_tstamp_precision.3pcap.in b/libpcap/pcap_get_tstamp_precision.3pcap.in index 285e77095..2e72e0bac 100644 --- a/libpcap/pcap_get_tstamp_precision.3pcap.in +++ b/libpcap/pcap_get_tstamp_precision.3pcap.in @@ -46,6 +46,10 @@ or which indicates that pcap captures contains time stamps in microseconds or nanoseconds respectively. +.SH BACKWARD COMPATIBILITY +This function became available in libpcap release 1.5.1. In previous +releases, time stamps from a capture device or savefile are always given +in seconds and microseconds. .SH SEE ALSO pcap(3PCAP), pcap_set_tstamp_precision(3PCAP), diff --git a/libpcap/pcap_inject.3pcap b/libpcap/pcap_inject.3pcap index ff9792d20..92a926388 100644 --- a/libpcap/pcap_inject.3pcap +++ b/libpcap/pcap_inject.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_INJECT 3PCAP "3 January 2014" +.TH PCAP_INJECT 3PCAP "25 July 2018" .SH NAME pcap_inject, pcap_sendpacket \- transmit a packet .SH SYNOPSIS @@ -42,7 +42,7 @@ is the number of bytes in the packet. Note that, even if you successfully open the network interface, you might not have permission to send packets on it, or it might not support sending packets; as -.I pcap_open_live() +.B pcap_open_live(3PCAP) doesn't have a flag to indicate whether to open for capturing, sending, or capturing and sending, you cannot request an open that supports sending and be notified at open time whether sending will be possible. @@ -72,17 +72,23 @@ comes from OpenBSD; comes from WinPcap. Both are provided for compatibility.) .SH RETURN VALUE .B pcap_inject() -returns the number of bytes written on success and \-1 on failure. +returns the number of bytes written on success and +.B PCAP_ERROR +on failure. .PP .B pcap_sendpacket() -returns 0 on success and \-1 on failure. +returns 0 on success and +.B PCAP_ERROR +on failure. .PP -If \-1 is returned, -.B pcap_geterr() +If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_is_swapped.3pcap b/libpcap/pcap_is_swapped.3pcap index 36691d310..67f762fed 100644 --- a/libpcap/pcap_is_swapped.3pcap +++ b/libpcap/pcap_is_swapped.3pcap @@ -39,9 +39,9 @@ than the current system. For a live capture, it always returns false (0). .PP It must not be called on a pcap descriptor created by -.B pcap_create() +.B \%pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . +.BR \%pcap_activate(3PCAP) . .SH RETURN VALUE .B pcap_is_swapped() returns true (1) or false (0) on success and diff --git a/libpcap/pcap_list_datalinks.3pcap.in b/libpcap/pcap_list_datalinks.3pcap.in index 9f52b63bb..60ba478f7 100644 --- a/libpcap/pcap_list_datalinks.3pcap.in +++ b/libpcap/pcap_list_datalinks.3pcap.in @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_LIST_DATALINKS 3PCAP "8 March 2015" +.TH PCAP_LIST_DATALINKS 3PCAP "25 July 2018" .SH NAME pcap_list_datalinks, pcap_free_datalinks \- get a list of link-layer header types supported by a capture device, and free that list @@ -47,9 +47,9 @@ which frees the list of link-layer header types pointed to by .IR dlt_list . .LP It must not be called on a pcap descriptor created by -.B pcap_create() +.B \%pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . +.BR \%pcap_activate(3PCAP) . .SH RETURN VALUE .B pcap_list_datalinks() returns the number of link-layer header types in the array on success, @@ -57,17 +57,17 @@ returns the number of link-layer header types in the array on success, if called on a capture handle that has been created but not activated, and .B PCAP_ERROR -(\-1) on other errors. +on other errors. If .B PCAP_ERROR is returned, -.B pcap_geterr() +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B \%pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP), +pcap(3PCAP), pcap_datalink_val_to_name(3PCAP), pcap-linktype(@MAN_MISC_INFO@) diff --git a/libpcap/pcap_list_tstamp_types.3pcap.in b/libpcap/pcap_list_tstamp_types.3pcap.in index a139324f3..e2487f704 100644 --- a/libpcap/pcap_list_tstamp_types.3pcap.in +++ b/libpcap/pcap_list_tstamp_types.3pcap.in @@ -18,7 +18,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_LIST_TSTAMP_TYPES 3PCAP "22 August 2010" +.TH PCAP_LIST_TSTAMP_TYPES 3PCAP "22 August 2018" .SH NAME pcap_list_tstamp_types, pcap_free_tstamp_types \- get a list of time stamp types supported by a capture device, and free that list @@ -54,17 +54,28 @@ which frees the list pointed to by returns the number of time stamp types in the array on success and .B PCAP_ERROR on failure. -A return value of zero means that you cannot specify a time stamp type; -you are limited to the capture device's default time stamp type. +A return value of one means that the only time stamp type supported is +the one in the list, which is the capture device's default time stamp +type. A return value of zero means that the only time stamp type +supported is +.BR PCAP_TSTAMP_HOST , +which is the capture device's default time stamp type (only older +versions of libpcap will return that; newer versions will always return +one or more types). If .B PCAP_ERROR is returned, -.B pcap_geterr() +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. +.SH BACKWARD COMPATIBILITY +.PP +These functions became available in libpcap release 1.2.1. In previous +releases, the time stamp type cannot be set; only the default time stamp +type offered by a capture source is available. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP), pcap_tstamp_type_val_to_name(3PCAP), +pcap(3PCAP), pcap_tstamp_type_val_to_name(3PCAP), pcap-tstamp(@MAN_MISC_INFO@) diff --git a/libpcap/pcap_lookupdev.3pcap b/libpcap/pcap_lookupdev.3pcap index eb493ba7e..29f09e375 100644 --- a/libpcap/pcap_lookupdev.3pcap +++ b/libpcap/pcap_lookupdev.3pcap @@ -47,13 +47,13 @@ possible.) .B pcap_lookupdev() returns a pointer to a string giving the name of a network device suitable for use with -.B pcap_create() +.B pcap_create(3PCAP) and -.BR pcap_activate() , +.BR \%pcap_activate(3PCAP) , or with -.BR pcap_open_live() , +.BR pcap_open_live(3PCAP) , and with -.BR pcap_lookupnet() . +.BR pcap_lookupnet(3PCAP) . If there is an error, .B NULL is returned and @@ -64,8 +64,7 @@ is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), -pcap_open_live(3PCAP), pcap_lookupnet(3PCAP) +pcap(3PCAP) .SH BUGS The pointer returned by .B pcap_lookupdev() diff --git a/libpcap/pcap_lookupnet.3pcap b/libpcap/pcap_lookupnet.3pcap index c38ff3a8e..f60944531 100644 --- a/libpcap/pcap_lookupnet.3pcap +++ b/libpcap/pcap_lookupnet.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_LOOKUPNET 3PCAP "3 January 2014" +.TH PCAP_LOOKUPNET 3PCAP "25 July 2018" .SH NAME pcap_lookupnet \- find the IPv4 network number and netmask for a device .SH SYNOPSIS @@ -51,8 +51,11 @@ are pointers. .SH RETURN VALUE .B pcap_lookupnet() -returns 0 on success and \-1 on failure. -If \-1 is returned, +returns 0 on success and +.B PCAP_ERROR +on failure. If +.B PCAP_ERROR +is returned, .I errbuf is filled in with an appropriate error message. .I errbuf diff --git a/libpcap/pcap_loop.3pcap b/libpcap/pcap_loop.3pcap index 4679b46e0..0193714b8 100644 --- a/libpcap/pcap_loop.3pcap +++ b/libpcap/pcap_loop.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_LOOP 3PCAP "20 January 2017" +.TH PCAP_LOOP 3PCAP "25 July 2018" .SH NAME pcap_loop, pcap_dispatch \- process packets from a live capture or savefile .SH SYNOPSIS @@ -47,7 +47,7 @@ processes packets from a live capture or ``savefile'' until .I cnt packets are processed, the end of the ``savefile'' is reached when reading from a ``savefile'', -.B pcap_breakloop() +.B pcap_breakloop(3PCAP) is called, or an error occurs. It does .B not @@ -123,7 +123,7 @@ them. .PP The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the -.B pcap_datalink() +.B pcap_datalink(3PCAP) routine when handed the .B pcap_t value also passed to @@ -136,7 +136,7 @@ lists the values can return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and until -.B pcap_set_datalink() +.B pcap_set_datalink(3PCAP) is called; after a successful call to .BR pcap_set_datalink() , all subsequent packets will have a link-layer header of the type @@ -160,8 +160,11 @@ for Ethernet. returns 0 if .I cnt is exhausted or if, when reading from a ``savefile'', no more packets -are available. It returns \-1 if an error occurs or \-2 if the loop -terminated due to a call to +are available. It returns +.B PCAP_ERROR +if an error occurs or +.B PCAP_ERROR_BREAK +if the loop terminated due to a call to .B pcap_breakloop() before any packets were processed. It does @@ -177,23 +180,27 @@ platforms that support a packet buffer timeout that starts before any packets arrive, the timeout expires before any packets arrive, or if the file descriptor for the capture device is in non-blocking mode and no packets were available to be read) or if no more packets are available -in a ``savefile.'' It returns \-1 if an error occurs or \-2 if the loop -terminated due to a call to +in a ``savefile.'' It returns +.B PCAP_ERROR +if an error occurs or +.B PCAP_ERROR_BREAK +if the loop terminated due to a call to .B pcap_breakloop() before any packets were processed. .ft B If your application uses pcap_breakloop(), -make sure that you explicitly check for \-1 and \-2, rather than just -checking for a return value < 0. +make sure that you explicitly check for PCAP_ERROR and PCAP_ERROR_BREAK, +rather than just checking for a return value < 0. .ft R .PP -If \-1 is returned, -.B pcap_geterr() +If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP), pcap_breakloop(3PCAP), -pcap_datalink(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_next_ex.3pcap b/libpcap/pcap_next_ex.3pcap index 88e831435..f0eb82d1e 100644 --- a/libpcap/pcap_next_ex.3pcap +++ b/libpcap/pcap_next_ex.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_NEXT_EX 3PCAP "20 January 2017" +.TH PCAP_NEXT_EX 3PCAP "25 July 2018" .SH NAME pcap_next_ex, pcap_next \- read the next packet from a pcap_t .SH SYNOPSIS @@ -49,9 +49,9 @@ and the packet data are not to be freed by the caller, and are not guaranteed to be valid after the next call to .BR pcap_next_ex() , .BR pcap_next() , -.BR pcap_loop() , +.BR pcap_loop(3PCAP) , or -.BR pcap_dispatch() ; +.BR pcap_dispatch(3PCAP) ; if the code needs them to remain valid, it must make a copy of them. .PP .B pcap_next() @@ -78,7 +78,7 @@ is filled in with the appropriate values for the packet. .PP The bytes of data from the packet begin with a link-layer header. The format of the link-layer header is indicated by the return value of the -.B pcap_datalink() +.B pcap_datalink(PCAP) routine when handed the .B pcap_t value also passed to @@ -91,7 +91,7 @@ lists the values can return and describes the packet formats that correspond to those values. The value it returns will be valid for all packets received unless and until -.B pcap_set_datalink() +.B pcap_set_datalink(3PCAP) is called; after a successful call to .BR pcap_set_datalink() , all subsequent packets will have a link-layer header of the type @@ -114,12 +114,17 @@ for Ethernet. .B pcap_next_ex() returns 1 if the packet was read without problems, 0 if packets are being read from a live capture and the packet buffer timeout expired, -\-1 if an error occurred while reading the packet, and \-2 if packets +.B PCAP_ERROR +if an error occurred while reading the packet, and +.B PCAP_ERROR_BREAK +if packets are being read from a ``savefile'' and there are no more packets to read -from the savefile. If \-1 is returned, -.B pcap_geterr() +from the savefile. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. @@ -136,5 +141,4 @@ non-blocking mode and no packets were available to be read), or if no more packets are available in a ``savefile.'' Unfortunately, there is no way to determine whether an error occurred or not. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP), pcap_dispatch(3PCAP), -pcap_datalink(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_offline_filter.3pcap b/libpcap/pcap_offline_filter.3pcap index 08c0b66b3..724f8366b 100644 --- a/libpcap/pcap_offline_filter.3pcap +++ b/libpcap/pcap_offline_filter.3pcap @@ -39,7 +39,7 @@ checks whether a filter matches a packet. is a pointer to a .I bpf_program struct, usually the result of a call to -.BR pcap_compile() . +.BR pcap_compile(3PCAP) . .I h points to the .I pcap_pkthdr @@ -52,4 +52,4 @@ returns the return value of the filter program. This will be zero if the packet doesn't match the filter and non-zero if the packet matches the filter. .SH SEE ALSO -pcap(3PCAP), pcap_compile(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_open_dead.3pcap.in b/libpcap/pcap_open_dead.3pcap.in index 621e75b5b..97a97f3ac 100644 --- a/libpcap/pcap_open_dead.3pcap.in +++ b/libpcap/pcap_open_dead.3pcap.in @@ -43,10 +43,10 @@ are used for creating a structure to use when calling the other functions in libpcap. It is typically used when just using libpcap for compiling BPF code; it can also be used if using -.BR pcap_dump_open() , -.BR pcap_dump() , +.BR pcap_dump_open(3PCAP) , +.BR pcap_dump(3PCAP) , and -.B pcap_dump_close() +.B pcap_dump_close(3PCAP) to write a savefile if there is no .B pcap_t that supplies the packets to be written. @@ -73,7 +73,6 @@ seconds and microseconds, and .B PCAP_TSTAMP_PRECISION_NANO should be specified if the packets to be written have time stamps in seconds and nanoseconds. Its value does not affect -.BR pcap_compile() . +.BR pcap_compile(3PCAP) . .SH SEE ALSO -pcap(3PCAP), pcap_compile(3PCAP), pcap_dump_open(3PCAP), -\%pcap-linktype(@MAN_MISC_INFO@) +pcap(3PCAP), \%pcap-linktype(@MAN_MISC_INFO@) diff --git a/libpcap/pcap_open_live.3pcap b/libpcap/pcap_open_live.3pcap index 942d4fc3d..3286e294c 100644 --- a/libpcap/pcap_open_live.3pcap +++ b/libpcap/pcap_open_live.3pcap @@ -87,4 +87,4 @@ is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP) +pcap_create(3PCAP), pcap_activate(3PCAP) diff --git a/libpcap/pcap_open_offline.3pcap.in b/libpcap/pcap_open_offline.3pcap.in index d0cd1617e..2bfbbace2 100644 --- a/libpcap/pcap_open_offline.3pcap.in +++ b/libpcap/pcap_open_offline.3pcap.in @@ -81,7 +81,8 @@ or .B pcap_fopen_offline_with_tstamp_precision() to read dumped data from an existing open stream .IR fp . -.B pcap_fopen_offline_with_tstamp_precision() takes an additional +.B pcap_fopen_offline_with_tstamp_precision() +takes an additional .I precision argument as described above. Note that on Windows, that stream should be opened in binary mode. @@ -105,5 +106,11 @@ is filled in with an appropriate error message. is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. +.SH BACKWARD COMPATIBILITY +.B pcap_open_offline_with_tstamp_precision +and +.B pcap_fopen_offline_with_tstamp_precision +became available in libpcap release 1.5.1. In previous releases, time +stamps from a savefile are always given in seconds and microseconds. .SH SEE ALSO pcap(3PCAP), pcap-savefile(@MAN_FILE_FORMATS@) diff --git a/libpcap/pcap_set_datalink.3pcap b/libpcap/pcap_set_datalink.3pcap index 24d57a541..66cfdb1e7 100644 --- a/libpcap/pcap_set_datalink.3pcap +++ b/libpcap/pcap_set_datalink.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_SET_DATALINK 3PCAP "3 January 2014" +.TH PCAP_SET_DATALINK 3PCAP "25 July 2018" .SH NAME pcap_set_datalink \- set the link-layer header type to be used by a capture device @@ -38,14 +38,16 @@ to the type specified by .IR dlt . .SH RETURN VALUE .B pcap_set_datalink() -returns 0 on success and \-1 on failure. -If \-1 is returned, -.B pcap_geterr() +returns 0 on success and +.B PCAP_ERROR +on failure. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP), -pcap_datalink_name_to_val(3PCAP) +pcap(3PCAP), pcap_datalink_name_to_val(3PCAP) diff --git a/libpcap/pcap_set_immediate_mode.3pcap b/libpcap/pcap_set_immediate_mode.3pcap deleted file mode 100644 index b3ad24315..000000000 --- a/libpcap/pcap_set_immediate_mode.3pcap +++ /dev/null @@ -1,47 +0,0 @@ -.\" -.\" Copyright (c) 1994, 1996, 1997 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that: (1) source code distributions -.\" retain the above copyright notice and this paragraph in its entirety, (2) -.\" distributions including binary code include the above copyright notice and -.\" this paragraph in its entirety in the documentation or other materials -.\" provided with the distribution, and (3) all advertising materials mentioning -.\" features or use of this software display the following acknowledgement: -.\" ``This product includes software developed by the University of California, -.\" Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED -.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -.\" -.TH PCAP_SET_IMMEDIATE_MODE 3PCAP "5 December 2013" -.SH NAME -pcap_set_immediate_mode \- set immediate mode for a not-yet-activated capture -handle -.SH SYNOPSIS -.nf -.ft B -#include -.LP -.ft B -int pcap_set_immediate_mode(pcap_t *p, int immediate_mode); -.ft -.fi -.SH DESCRIPTION -.B pcap_set_immediate_mode() -sets whether immediate mode should be set on a capture handle when -the handle is activated. -If -.I immediate_mode -is non-zero, immediate mode will be set, otherwise it will not be set. -.SH RETURN VALUE -.B pcap_set_immediate_mode() -returns 0 on success or -.B PCAP_ERROR_ACTIVATED -if called on a capture handle that has been activated. -.SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP) diff --git a/libpcap/pcap_set_timeout.3pcap b/libpcap/pcap_set_timeout.3pcap index cacf603b6..e67b8132f 100644 --- a/libpcap/pcap_set_timeout.3pcap +++ b/libpcap/pcap_set_timeout.3pcap @@ -49,5 +49,5 @@ returns 0 on success or .B PCAP_ERROR_ACTIVATED if called on a capture handle that has been activated. .SH SEE ALSO -pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP), +pcap_create(3PCAP), pcap_activate(3PCAP), \%pcap_set_immediate_mode(3PCAP) diff --git a/libpcap/pcap_set_tstamp_precision.3pcap.in b/libpcap/pcap_set_tstamp_precision.3pcap.in index 57c4ea301..dc2b4b3d2 100644 --- a/libpcap/pcap_set_tstamp_precision.3pcap.in +++ b/libpcap/pcap_set_tstamp_precision.3pcap.in @@ -39,9 +39,9 @@ sets the precision of the time stamp desired for packets captured on the pcap descriptor to the type specified by .IR tstamp_precision . It must be called on a pcap descriptor created by -.B pcap_create() +.B pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . +.BR pcap_activate(3PCAP) . Two time stamp precisions are supported, microseconds and nanoseconds. One can use options .B PCAP_TSTAMP_PRECISION_MICRO and @@ -50,11 +50,16 @@ to request desired precision. By default, time stamps are in microseconds. .SH RETURN VALUE .B pcap_set_tstamp_precision() returns 0 on success if the specified time stamp precision is expected to be -supported by the operating system, +supported by the capture device, .B PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -if operating system does not support requested time stamp precision, +if the capture device does not support the requested time stamp +precision, .B PCAP_ERROR_ACTIVATED if called on a capture handle that has been activated. +.SH BACKWARD COMPATIBILITY +This function became available in libpcap release 1.5.1. In previous +releases, time stamps from a capture device or savefile are always given +in seconds and microseconds. .SH SEE ALSO pcap(3PCAP), pcap_get_tstamp_precision(3PCAP), diff --git a/libpcap/pcap_set_tstamp_type.3pcap.in b/libpcap/pcap_set_tstamp_type.3pcap.in index 7899da310..9833f46a3 100644 --- a/libpcap/pcap_set_tstamp_type.3pcap.in +++ b/libpcap/pcap_set_tstamp_type.3pcap.in @@ -18,7 +18,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_SET_TSTAMP_TYPE 3PCAP "5 December 2014" +.TH PCAP_SET_TSTAMP_TYPE 3PCAP "22 August 2018" .SH NAME pcap_set_tstamp_type \- set the time stamp type to be used by a capture device @@ -38,10 +38,10 @@ sets the type of time stamp desired for packets captured on the pcap descriptor to the type specified by .IR tstamp_type . It must be called on a pcap descriptor created by -.B pcap_create() +.B pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . -.B pcap_list_tstamp_types() +.BR pcap_activate(3PCAP) . +.B pcap_list_tstamp_types(3PCAP) will give a list of the time stamp types supported by a given capture device. See @@ -57,9 +57,14 @@ capture device, .B PCAP_ERROR_ACTIVATED if called on a capture handle that has been activated, and .B PCAP_ERROR_CANTSET_TSTAMP_TYPE -if the capture device doesn't support setting the time stamp type. +if the capture device doesn't support setting the time stamp type (only +older versions of libpcap will return that; newer versions will always +allow the time stamp type to be set to the default type). +.SH BACKWARD COMPATIBILITY +.PP +This function became available in libpcap release 1.2.1. In previous +releases, the time stamp type cannot be set; only the default time stamp +type offered by a capture source is available. .SH SEE ALSO pcap(3PCAP), -pcap_list_tstamp_types(3PCAP), -pcap_tstamp_type_name_to_val(3PCAP), -pcap-tstamp(@MAN_MISC_INFO@) +pcap_tstamp_type_name_to_val(3PCAP) diff --git a/libpcap/pcap_setdirection.3pcap b/libpcap/pcap_setdirection.3pcap index 11945f542..f174b98f9 100644 --- a/libpcap/pcap_setdirection.3pcap +++ b/libpcap/pcap_setdirection.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_SETDIRECTION 3PCAP "8 March 2015" +.TH PCAP_SETDIRECTION 3PCAP "25 July 2018" .SH NAME pcap_setdirection \- set the direction for which packets will be captured .SH SYNOPSIS @@ -57,13 +57,16 @@ support This operation is not supported if a ``savefile'' is being read. .SH RETURN VALUE .B pcap_setdirection() -returns 0 on success and \-1 on failure. -If \-1 is returned, -.B pcap_geterr() +returns 0 on success and +.B PCAP_ERROR +on failure. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_setfilter.3pcap b/libpcap/pcap_setfilter.3pcap index 6efd25398..872969398 100644 --- a/libpcap/pcap_setfilter.3pcap +++ b/libpcap/pcap_setfilter.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_SETFILTER 3PCAP "7 April 2014" +.TH PCAP_SETFILTER 3PCAP "25 July 2018" .SH NAME pcap_setfilter \- set the filter .SH SYNOPSIS @@ -37,16 +37,19 @@ is used to specify a filter program. is a pointer to a .I bpf_program struct, usually the result of a call to -.BR pcap_compile() . +.BR \%pcap_compile(3PCAP) . .SH RETURN VALUE .B pcap_setfilter() -returns 0 on success and \-1 on failure. -If \-1 is returned, -.B pcap_geterr() +returns 0 on success and +.B PCAP_ERROR +on failure. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_compile(3PCAP), pcap_geterr(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_setnonblock.3pcap b/libpcap/pcap_setnonblock.3pcap index 695912701..e8adebea0 100644 --- a/libpcap/pcap_setnonblock.3pcap +++ b/libpcap/pcap_setnonblock.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_SETNONBLOCK 3PCAP "18 October 2014" +.TH PCAP_SETNONBLOCK 3PCAP "25 July 2018" .SH NAME pcap_setnonblock, pcap_getnonblock \- set or get the state of non-blocking mode on a capture device @@ -43,25 +43,27 @@ puts a capture handle into ``non-blocking'' mode, or takes it out of ``non-blocking'' mode, depending on whether the .I nonblock argument is non-zero or zero. It has no effect on ``savefiles''. -If there is an error, \-1 is returned and +If there is an error, +.B PCAP_ERROR +is returned and .I errbuf is filled in with an appropriate error message; otherwise, 0 is returned. In ``non-blocking'' mode, an attempt to read from the capture descriptor with -.B pcap_dispatch() +.B pcap_dispatch(3PCAP) will, if no packets are currently available to be read, return 0 immediately rather than blocking waiting for packets to arrive. -.B pcap_loop() +.B pcap_loop(3PCAP) and -.B pcap_next() +.B pcap_next(3PCAP) will not work in ``non-blocking'' mode. .PP When first activated with -.B pcap_activate() +.B pcap_activate(3PCAP) or opened with -.B pcap_open_live() , +.B pcap_open_live(3PCAP) , a capture handle is not in ``non-blocking mode''; a call to .B pcap_setnonblock() is required in order to put it into ``non-blocking'' mode. @@ -69,7 +71,9 @@ is required in order to put it into ``non-blocking'' mode. .B pcap_getnonblock() returns the current ``non-blocking'' state of the capture descriptor; it always returns 0 on ``savefiles''. -If there is an error, \-1 is returned and +If there is an error, +.B PCAP_ERROR +is returned and .I errbuf is filled in with an appropriate error message. .PP @@ -78,4 +82,4 @@ is assumed to be able to hold at least .B PCAP_ERRBUF_SIZE chars. .SH SEE ALSO -pcap(3PCAP), pcap_loop(3PCAP), pcap_next_ex(3PCAP), pcap_geterr(3PCAP) +pcap(3PCAP), pcap_next_ex(3PCAP), pcap_geterr(3PCAP) diff --git a/libpcap/pcap_snapshot.3pcap b/libpcap/pcap_snapshot.3pcap index 7af8c33dc..ee54bb083 100644 --- a/libpcap/pcap_snapshot.3pcap +++ b/libpcap/pcap_snapshot.3pcap @@ -33,16 +33,16 @@ int pcap_snapshot(pcap_t *p); .SH DESCRIPTION .B pcap_snapshot() returns the snapshot length specified when -.B pcap_set_snapshot() +.B pcap_set_snaplen(3PCAP) or -.B pcap_open_live() +.B pcap_open_live(3PCAP) was called, for a live capture, or the snapshot length from the capture file, for a ``savefile''. .PP It must not be called on a pcap descriptor created by -.B pcap_create() +.B \%pcap_create(3PCAP) that has not yet been activated by -.BR pcap_activate() . +.BR \%pcap_activate(3PCAP) . .SH RETURN VALUE .B pcap_snapshot() returns the snapshot length on success and diff --git a/libpcap/pcap_stats.3pcap b/libpcap/pcap_stats.3pcap index 2dce4b501..465dada48 100644 --- a/libpcap/pcap_stats.3pcap +++ b/libpcap/pcap_stats.3pcap @@ -17,7 +17,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_STATS 3PCAP "3 January 2014" +.TH PCAP_STATS 3PCAP "25 July 2018" .SH NAME pcap_stats \- get capture statistics .SH SYNOPSIS @@ -83,15 +83,18 @@ statistic is unavailable, so it should not be treated as an indication that the interface did not drop any packets. .SH RETURN VALUE .B pcap_stats() -returns 0 on success and returns \-1 if there is an error or if +returns 0 on success and returns +.B PCAP_ERROR +if there is an error or if .I p -doesn't support packet statistics. -If \-1 is returned, -.B pcap_geterr() +doesn't support packet statistics. If +.B PCAP_ERROR +is returned, +.B pcap_geterr(3PCAP) or -.B pcap_perror() +.B pcap_perror(3PCAP) may be called with .I p as an argument to fetch or display the error text. .SH SEE ALSO -pcap(3PCAP), pcap_geterr(3PCAP) +pcap(3PCAP) diff --git a/libpcap/pcap_strerror.3pcap b/libpcap/pcap_strerror.3pcap index 7c7d53f5a..a5775f422 100644 --- a/libpcap/pcap_strerror.3pcap +++ b/libpcap/pcap_strerror.3pcap @@ -37,4 +37,4 @@ is provided in case isn't available. It returns an error message string corresponding to .IR error . .SH SEE ALSO -strerror(3) +pcap(3PCAP) diff --git a/libpcap/pcap_tstamp_type_name_to_val.3pcap b/libpcap/pcap_tstamp_type_name_to_val.3pcap index ac2e35dd7..fdcc6c6d8 100644 --- a/libpcap/pcap_tstamp_type_name_to_val.3pcap +++ b/libpcap/pcap_tstamp_type_name_to_val.3pcap @@ -18,7 +18,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_TSTAMP_TYPE_NAME_TO_VAL 3PCAP "5 December 2014" +.TH PCAP_TSTAMP_TYPE_NAME_TO_VAL 3PCAP "22 August 2018" .SH NAME pcap_tstamp_type_name_to_val \- get the time stamp type value corresponding to a time stamp type name @@ -41,5 +41,8 @@ value. The translation is case-insensitive. returns time stamp type value on success and .B PCAP_ERROR on failure. +.SH BACKWARD COMPATIBILITY +.PP +This function became available in libpcap release 1.2.1. .SH SEE ALSO pcap(3PCAP), pcap_tstamp_type_val_to_name(3PCAP) diff --git a/libpcap/pcap_tstamp_type_val_to_name.3pcap b/libpcap/pcap_tstamp_type_val_to_name.3pcap index 261554ec7..9374f489c 100644 --- a/libpcap/pcap_tstamp_type_val_to_name.3pcap +++ b/libpcap/pcap_tstamp_type_val_to_name.3pcap @@ -18,7 +18,7 @@ .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" -.TH PCAP_TSTAMP_TYPE_VAL_TO_NAME 3PCAP "12 December 2013" +.TH PCAP_TSTAMP_TYPE_VAL_TO_NAME 3PCAP "22 August 2018" .SH NAME pcap_tstamp_type_val_to_name, pcap_tstamp_type_val_to_description \- get a name or description for a time stamp type value @@ -45,5 +45,8 @@ translates a time stamp type value to a short description of that time stamp type. .B NULL is returned on failure. +.SH BACKWARD COMPATIBILITY +.PP +These functions became available in libpcap release 1.2.1. .SH SEE ALSO pcap(3PCAP), pcap_tstamp_type_name_to_val(3PCAP) diff --git a/libpcap/portability.h b/libpcap/portability.h index b36125421..543846e8b 100644 --- a/libpcap/portability.h +++ b/libpcap/portability.h @@ -38,6 +38,7 @@ * Helpers for portability between Windows and UN*X and between different * flavors of UN*X. */ +#include /* we declare varargs functions on some platforms */ #include "pcap/funcattrs.h" @@ -45,49 +46,45 @@ extern "C" { #endif -#ifndef HAVE_STRLCPY - /* - * Macro that does the same thing as strlcpy(). - */ - #if defined(_MSC_VER) || defined(__MINGW32__) - /* - * strncpy_s() is supported at least back to Visual - * Studio 2005. - */ - #define strlcpy(x, y, z) \ - strncpy_s((x), (z), (y), _TRUNCATE) - - #else - #define strlcpy(x, y, z) \ - (strncpy((x), (y), (z)), \ - ((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \ - (void) strlen((y))) - #endif +#ifdef HAVE_STRLCAT + #define pcap_strlcat strlcat +#else + #if defined(_MSC_VER) || defined(__MINGW32__) + /* + * strncat_s() is supported at least back to Visual + * Studio 2005. + */ + #define pcap_strlcat(x, y, z) \ + strncat_s((x), (z), (y), _TRUNCATE) + #else + /* + * Define it ourselves. + */ + extern size_t pcap_strlcat(char * restrict dst, const char * restrict src, size_t dstsize); + #endif #endif -#ifndef HAVE_STRLCAT - /* - * Macro that does the same thing as strlcat(). - */ - #if defined(_MSC_VER) || defined(__MINGW32__) - /* - * strncat_s() is supported at least back to Visual - * Studio 2005. - */ - #define strlcat(x, y, z) \ - strncat_s((x), (z), (y), _TRUNCATE) - #else - /* - * ANSI C says strncat() always null-terminates its first argument, - * so 1) we don't need to explicitly null-terminate the string - * ourselves and 2) we need to leave room for the null terminator. - */ - #define strlcat(x, y, z) \ - strncat((x), (y), (z) - strlen((x)) - 1) - #endif +#ifdef HAVE_STRLCPY + #define pcap_strlcpy strlcpy +#else + #if defined(_MSC_VER) || defined(__MINGW32__) + /* + * strncpy_s() is supported at least back to Visual + * Studio 2005. + */ + #define pcap_strlcpy(x, y, z) \ + strncpy_s((x), (z), (y), _TRUNCATE) + #else + /* + * Define it ourselves. + */ + extern size_t pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dstsize); + #endif #endif #ifdef _MSC_VER + #define isascii __isascii + /* * If has been included, and _DEBUG is defined, and * __STDC__ is zero, will define strdup() to call @@ -134,6 +131,23 @@ extern int pcap_snprintf(char *, size_t, PCAP_FORMAT_STRING(const char *), ...) extern int pcap_vsnprintf(char *, size_t, const char *, va_list ap); #endif +/* + * We also want asprintf(), for some cases where we use it to construct + * dynamically-allocated variable-length strings. + */ +#ifdef HAVE_ASPRINTF +#define pcap_asprintf asprintf +#else +extern int pcap_asprintf(char **, PCAP_FORMAT_STRING(const char *), ...) + PCAP_PRINTFLIKE(2, 3); +#endif + +#ifdef HAVE_VASPRINTF +#define pcap_vasprintf vasprintf +#else +extern int pcap_vasprintf(char **, const char *, va_list ap); +#endif + #ifdef HAVE_STRTOK_R #define pcap_strtok_r strtok_r #else @@ -146,7 +160,6 @@ extern int pcap_vsnprintf(char *, size_t, const char *, va_list ap); /* * Define it ourselves. */ - #define NEED_STRTOK_R extern char *pcap_strtok_r(char *, const char *, char **); #endif #endif /* HAVE_STRTOK_R */ diff --git a/libpcap/rpcap-protocol.h b/libpcap/rpcap-protocol.h index 83ebdc5b0..8ae8b62d1 100644 --- a/libpcap/rpcap-protocol.h +++ b/libpcap/rpcap-protocol.h @@ -63,80 +63,20 @@ * * Version negotiation is done as part of the authentication process: * - * The client sends an authentication request, with the version number - * in the request being the maximum version it supports. + * The client sends an authentication request, with a version number + * of 0. All servers must accept authentication requests with a version + * number of 0, even if they don't support version 0 for any other + * requests. * - * If the server supports that version, it attempts to authenticate the - * client, and replies as appropriate, with the version number in the - * reply being that version. + * The server attempts to authenticate the client. If that succeeds, + * older servers - which only support version 0 - will send an + * authentication reply with no payload. Newer servers - which might + * support other versions - will send an authentication reply with + * a payload giving the minimum and maximum versions it supports. * - * If the server doesn't support that version because it's too large, - * it replies with a RPCAP_MSG_ERROR message, with the maximum version - * they support as the version number in the reply, and with the error - * code being PCAP_ERR_WRONGVER. - * - * If the server doesn't support that version because it's too small, - * it replies with a RPCAP_MSG_ERROR message, with that version as - * the version number in the reply, and with the error code being - * PCAP_ERR_WRONGVER. - * - * If the client supports that version, it retries the authentication - * with that version and, if that fails for any reason, including - * PCAP_ERR_WRONGVER, fails. Otherwise, it fails, telling its caller - * that there's no version that both support. - * - * This requires that the set of versions supported by a client or - * server be a range of integers, with no gaps. Thus: - * - * the client's version set is [Cmin, Cmax], with Cmin <= Cmax; - * - * the server's version set is [Smin, Smax], with Smin <= Smax; - * - * the client sends Cmax as the version number in the initial - * authentication request; - * - * if the server doesn't support the version sent by the client, - * either Smax < Cmax or Smin > Cmax (because the client sent Cmax - * to the server, and the server doesn't support it); - * - * if Smax < Cmax: - * - * the server sends Smax as the version number in the RPCAP_MSG_ERROR/ - * PCAP_ERR_WRONGVER message - the client will accept this because - * Cmax != 0, as these numbers are unsigned, and this means that - * this isn't an old client that rejects all messages with a non-zero - * version number, it's a new client that accepts RPCAP_MSG_ERROR - * messages no matter what the version is; - * - * if Smax >= Cmin, both the client and the server can use it, and - * the client retries with Smax; - * - * if Smax < Cmin, there is no version the client and server can - * both support. - * - * if Smin > Cmax: - * - * the server sends Cmax as the version number in the RPCAP_MSG_ERROR/ - * PCAP_ERR_WRONGVER message - the client will accept this because - * Cmax is a valid client version number. - * - * the client will retry with Cmax, get the same version failure, - * and report that there is no version the client and server can - * both support (as the version sets are disjoint). - * - * Old negotiation-unaware clients just send version 0 and, if they - * get back PCAP_ERR_WRONGVER, treat it as a fatal error. This - * means they'll fail to talk to any server that can't handle - * version 0, which is the appropriate thing to do, as they can - * only use version 0. - * - * Old negotiation-unaware servers fail if they get a version other - * than 0, sending back PCAP_ERR_WRONGVER with version 0, which is - * the only version, and thus both the minimum and maximum version, - * they support. The client will either fail if it doesn't support - * version 0, or will retry with version 0 and succeed, so it will - * fail with servers that can't handle version 0 or will negotiate - * version 0 with servers that can handle version 0. + * The client attempts to find the largest version number that is + * in both its range of supported versions and the server's supported + * versions. If it fails, it gives up; otherwise, it uses that version. */ #define RPCAP_MIN_VERSION 0 #define RPCAP_MAX_VERSION 0 @@ -148,7 +88,8 @@ * comparison will always succeed. */ #if RPCAP_MIN_VERSION == 0 -#define RPCAP_VERSION_IS_SUPPORTED(v) ((v) <= RPCAP_MAX_VERSION) +#define RPCAP_VERSION_IS_SUPPORTED(v) \ + ((v) <= RPCAP_MAX_VERSION) #else #define RPCAP_VERSION_IS_SUPPORTED(v) \ ((v) >= RPCAP_MIN_VERSION && (v) <= RPCAP_MAX_VERSION) @@ -176,6 +117,12 @@ * for better alignment. * These structures have been created in order to be correctly aligned to * a 32-bit boundary, but be careful in any case. + * + * The layout of these structures MUST not be changed. If a packet + * format is different in different versions of the protocol, versions + * of the structure should be provided for all the different versions or + * version ranges (if more than one version of the protocol has the same + * layout) that we support. */ /* @@ -199,6 +146,19 @@ struct rpcap_header uint32 plen; /* Length of the payload of this RPCAP message */ }; +/* + * Format of data that may appear at the end of an authentication reply, + * giving the minimum and maximum versions of the protocol that the + * server supports. + * + * Older servers don't provide this; they support only version 0. + */ +struct rpcap_authreply +{ + uint8 minvers; /* Minimum version supported */ + uint8 maxvers; /* Maximum version supported */ +}; + /* Format of the message for the interface description (findalldevs command) */ struct rpcap_findalldevs_if { @@ -378,7 +338,12 @@ struct rpcap_sampling uint32 value; /* Parameter related to the sampling method */ }; -/* Messages field coding */ +/* + * Messages field coding. + * + * These values are used in messages sent over the network, and MUST + * not be changed. + */ #define RPCAP_MSG_IS_REPLY 0x080 /* Flag indicating a reply */ #define RPCAP_MSG_ERROR 1 /* Message that keeps an error notification */ @@ -410,24 +375,32 @@ struct rpcap_sampling #define RPCAP_UPDATEFILTER_BPF 1 /* This code tells us that the filter is encoded with the BPF/NPF syntax */ -/* Network error codes */ -#define PCAP_ERR_NETW 1 /* Network error */ -#define PCAP_ERR_INITTIMEOUT 2 /* The RPCAP initial timeout has expired */ -#define PCAP_ERR_AUTH 3 /* Generic authentication error */ -#define PCAP_ERR_FINDALLIF 4 /* Generic findalldevs error */ -#define PCAP_ERR_NOREMOTEIF 5 /* The findalldevs was ok, but the remote end had no interfaces to list */ -#define PCAP_ERR_OPEN 6 /* Generic pcap_open error */ -#define PCAP_ERR_UPDATEFILTER 7 /* Generic updatefilter error */ -#define PCAP_ERR_GETSTATS 8 /* Generic pcap_stats error */ -#define PCAP_ERR_READEX 9 /* Generic pcap_next_ex error */ -#define PCAP_ERR_HOSTNOAUTH 10 /* The host is not authorized to connect to this server */ -#define PCAP_ERR_REMOTEACCEPT 11 /* Generic pcap_remoteaccept error */ -#define PCAP_ERR_STARTCAPTURE 12 /* Generic pcap_startcapture error */ -#define PCAP_ERR_ENDCAPTURE 13 /* Generic pcap_endcapture error */ -#define PCAP_ERR_RUNTIMETIMEOUT 14 /* The RPCAP run-time timeout has expired */ -#define PCAP_ERR_SETSAMPLING 15 /* Error during the settings of sampling parameters */ -#define PCAP_ERR_WRONGMSG 16 /* The other end endpoint sent a message which has not been recognized */ -#define PCAP_ERR_WRONGVER 17 /* The other end endpoint has a version number that is not compatible with our */ +/* + * Network error codes. + * + * These values are used in messages sent over the network, and MUST + * not be changed. + */ +#define PCAP_ERR_NETW 1 /* Network error */ +#define PCAP_ERR_INITTIMEOUT 2 /* The RPCAP initial timeout has expired */ +#define PCAP_ERR_AUTH 3 /* Generic authentication error */ +#define PCAP_ERR_FINDALLIF 4 /* Generic findalldevs error */ +#define PCAP_ERR_NOREMOTEIF 5 /* The findalldevs was ok, but the remote end had no interfaces to list */ +#define PCAP_ERR_OPEN 6 /* Generic pcap_open error */ +#define PCAP_ERR_UPDATEFILTER 7 /* Generic updatefilter error */ +#define PCAP_ERR_GETSTATS 8 /* Generic pcap_stats error */ +#define PCAP_ERR_READEX 9 /* Generic pcap_next_ex error */ +#define PCAP_ERR_HOSTNOAUTH 10 /* The host is not authorized to connect to this server */ +#define PCAP_ERR_REMOTEACCEPT 11 /* Generic pcap_remoteaccept error */ +#define PCAP_ERR_STARTCAPTURE 12 /* Generic pcap_startcapture error */ +#define PCAP_ERR_ENDCAPTURE 13 /* Generic pcap_endcapture error */ +#define PCAP_ERR_RUNTIMETIMEOUT 14 /* The RPCAP run-time timeout has expired */ +#define PCAP_ERR_SETSAMPLING 15 /* Error during the settings of sampling parameters */ +#define PCAP_ERR_WRONGMSG 16 /* The other end endpoint sent a message which has not been recognized */ +#define PCAP_ERR_WRONGVER 17 /* The other end endpoint has a version number that is not compatible with our */ +#define PCAP_ERR_AUTH_FAILED 18 /* The user couldn't be authenticated */ +#define PCAP_ERR_TLS_REQUIRED 19 /* The server requires TLS to connect */ +#define PCAP_ERR_AUTH_TYPE_NOTSUP 20 /* The authentication type isn't supported */ /* * \brief Buffer used by socket functions to send-receive packets. diff --git a/libpcap/savefile.c b/libpcap/savefile.c index ec44ef4fe..5b1e14cf3 100644 --- a/libpcap/savefile.c +++ b/libpcap/savefile.c @@ -43,6 +43,7 @@ #include #include #include +#include /* for INT_MAX */ #include "pcap-int.h" @@ -52,12 +53,13 @@ #include "sf-pcap.h" #include "sf-pcapng.h" +#include "pcap-common.h" #ifdef _WIN32 /* * These aren't exported on Windows, because they would only work if both - * WinPcap and the code using it were to use the Universal CRT; otherwise, - * a FILE structure in WinPcap and a FILE structure in the code using it + * WinPcap/Npcap and the code using it were to use the Universal CRT; otherwise, + * a FILE structure in WinPcap/Npcap and a FILE structure in the code using it * could be different if they're using different versions of the C runtime. * * Instead, pcap/pcap.h defines them as macros that wrap the hopen versions, @@ -179,7 +181,7 @@ sf_oid_set_request(pcap_t *p, bpf_u_int32 oid _U_, const void *data _U_, static u_int sf_sendqueue_transmit(pcap_t *p, pcap_send_queue *queue, int sync) { - strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", PCAP_ERRBUF_SIZE); return (0); } @@ -218,7 +220,7 @@ sf_get_airpcap_handle(pcap_t *pcap) static int sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) { - strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", + pcap_strlcpy(p->errbuf, "Sending packets isn't supported on savefiles", PCAP_ERRBUF_SIZE); return (-1); } @@ -317,6 +319,7 @@ pcap_t* pcap_hopen_offline_with_tstamp_precision(intptr_t osfd, u_int precision, { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "_fdopen"); + _close(fd); return NULL; } @@ -331,7 +334,34 @@ pcap_t* pcap_hopen_offline(intptr_t osfd, char *errbuf) } #endif -static pcap_t *(*check_headers[])(bpf_u_int32, FILE *, u_int, char *, int *) = { +/* + * Given a link-layer header type and snapshot length, return a + * snapshot length to use when reading the file; it's guaranteed + * to be > 0 and <= INT_MAX. + * + * XXX - the only reason why we limit it to <= INT_MAX is so that + * it fits in p->snapshot, and the only reason that p->snapshot is + * signed is that pcap_snapshot() returns an int, not an unsigned int. + */ +bpf_u_int32 +pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen) +{ + if (snaplen == 0 || snaplen > INT_MAX) { + /* + * Bogus snapshot length; use the maximum for this + * link-layer type as a fallback. + * + * XXX - we don't clamp snapshot lengths that are + * <= INT_MAX but > max_snaplen_for_dlt(linktype), + * so a capture file could cause us to allocate + * a Really Big Buffer. + */ + snaplen = max_snaplen_for_dlt(linktype); + } + return snaplen; +} + +static pcap_t *(*check_headers[])(const uint8_t *, FILE *, u_int, char *, int *) = { pcap_check_header, pcap_ng_check_header }; @@ -346,7 +376,7 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision, char *errbuf) { register pcap_t *p; - bpf_u_int32 magic; + uint8_t magic[4]; size_t amt_read; u_int i; int err; @@ -358,16 +388,15 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision, * Windows Sniffer, and Microsoft Network Monitor) all have magic * numbers that are unique in their first 4 bytes. */ - amt_read = fread((char *)&magic, 1, sizeof(magic), fp); + amt_read = fread(&magic, 1, sizeof(magic), fp); if (amt_read != sizeof(magic)) { if (ferror(fp)) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "error reading dump file"); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %lu file header bytes, only got %lu", - (unsigned long)sizeof(magic), - (unsigned long)amt_read); + "truncated dump file; tried to read %" PRIsize " file header bytes, only got %" PRIsize, + sizeof(magic), amt_read); } return (NULL); } diff --git a/libpcap/scanner.c b/libpcap/scanner.c deleted file mode 100644 index 85ecd32ff..000000000 --- a/libpcap/scanner.c +++ /dev/null @@ -1,5463 +0,0 @@ -#line 2 "scanner.c" -/* Must come first for _LARGE_FILE_API on AIX. */ -#ifdef HAVE_CONFIG_H -#include -#endif - -/* - * Must come first to avoid warnings on Windows. - * - * Flex-generated scanners may only include if __STDC_VERSION__ - * is defined with a value >= 199901, meaning "full C99", and MSVC may not - * define it with that value, because it isn't 100% C99-compliant, even - * though it has an capable of defining everything the Flex - * scanner needs. - * - * We, however, will include it if we know we have an MSVC version that has - * it; this means that we may define the INTn_MAX and UINTn_MAX values in - * scanner.c, and then include , which may define them differently - * (same value, but different string of characters), causing compiler warnings. - * - * If we include it here, and they're defined, that'll prevent scanner.c - * from defining them. So we include , to get - * if we have it. - */ -#include - -#include "diag-control.h" - -#line 30 "scanner.c" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yyg->yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE pcap_restart(yyin ,yyscanner ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via pcap_restart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] - -void pcap_restart (FILE *input_file ,yyscan_t yyscanner ); -void pcap__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); -void pcap__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void pcap__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void pcap_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -void pcap_pop_buffer_state (yyscan_t yyscanner ); - -static void pcap_ensure_buffer_stack (yyscan_t yyscanner ); -static void pcap__load_buffer_state (yyscan_t yyscanner ); -static void pcap__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); - -#define YY_FLUSH_BUFFER pcap__flush_buffer(YY_CURRENT_BUFFER ,yyscanner) - -YY_BUFFER_STATE pcap__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner ); - -void *pcap_alloc (yy_size_t ,yyscan_t yyscanner ); -void *pcap_realloc (void *,yy_size_t ,yyscan_t yyscanner ); -void pcap_free (void * ,yyscan_t yyscanner ); - -#define yy_new_buffer pcap__create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - pcap_ensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - pcap__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - pcap_ensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - pcap__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define pcap_wrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -typedef int yy_state_type; - -#define yytext_ptr yytext_r - -static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); -static int yy_get_next_buffer (yyscan_t yyscanner ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif -static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 184 -#define YY_END_OF_BUFFER 185 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[1729] = - { 0, - 0, 0, 185, 182, 113, 113, 113, 114, 182, 114, - 114, 114, 183, 123, 123, 114, 114, 114, 114, 180, - 180, 182, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 114, 182, 117, 121, 67, 0, 180, 123, - 0, 180, 180, 180, 0, 125, 119, 116, 118, 115, - 120, 180, 181, 181, 180, 180, 180, 20, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - - 180, 7, 180, 34, 35, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 92, - 180, 68, 180, 180, 180, 180, 180, 180, 60, 180, - 180, 180, 180, 86, 180, 180, 180, 180, 180, 180, - 61, 180, 4, 180, 180, 180, 180, 180, 180, 180, - 68, 121, 180, 124, 124, 180, 123, 180, 0, 125, - 123, 125, 125, 125, 180, 180, 180, 67, 5, 180, - 81, 180, 180, 180, 180, 180, 180, 180, 55, 107, - 1, 0, 180, 21, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - - 180, 180, 36, 180, 180, 18, 43, 0, 180, 29, - 180, 25, 70, 180, 180, 79, 37, 180, 100, 180, - 180, 180, 180, 101, 180, 46, 69, 82, 106, 180, - 14, 180, 3, 180, 180, 180, 180, 180, 94, 180, - 180, 26, 180, 105, 180, 108, 38, 2, 180, 42, - 180, 9, 180, 10, 89, 180, 88, 180, 180, 0, - 180, 180, 124, 180, 180, 180, 180, 123, 0, 180, - 0, 126, 125, 125, 0, 125, 0, 125, 0, 125, - 0, 23, 180, 180, 180, 180, 64, 16, 41, 180, - 39, 180, 180, 180, 30, 180, 98, 180, 180, 180, - - 111, 180, 180, 104, 110, 45, 109, 112, 11, 180, - 12, 13, 180, 180, 180, 32, 78, 180, 62, 3, - 99, 47, 180, 180, 180, 74, 180, 180, 180, 180, - 48, 180, 180, 40, 180, 6, 180, 93, 180, 8, - 95, 180, 180, 0, 180, 53, 73, 15, 180, 124, - 124, 180, 124, 124, 124, 180, 123, 180, 0, 125, - 180, 0, 0, 125, 0, 125, 126, 125, 0, 0, - 0, 0, 125, 125, 125, 125, 125, 0, 180, 56, - 57, 58, 59, 180, 22, 180, 180, 180, 180, 31, - 180, 180, 180, 102, 103, 0, 19, 180, 180, 180, - - 87, 180, 33, 180, 80, 28, 27, 180, 180, 83, - 180, 180, 180, 50, 17, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 0, - 180, 180, 124, 180, 180, 180, 180, 124, 124, 180, - 123, 180, 0, 0, 125, 125, 125, 0, 0, 126, - 125, 125, 126, 125, 0, 0, 125, 125, 125, 125, - 125, 0, 0, 0, 0, 125, 125, 0, 125, 0, - 125, 0, 97, 180, 180, 180, 24, 180, 180, 77, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 0, - 180, 180, 180, 180, 180, 70, 180, 180, 180, 180, - - 180, 180, 180, 75, 76, 180, 96, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 124, 124, 180, 124, 124, 124, 124, 180, 123, - 180, 0, 125, 125, 0, 125, 0, 0, 125, 0, - 125, 126, 125, 0, 0, 0, 125, 125, 0, 125, - 126, 125, 0, 0, 0, 0, 0, 0, 0, 125, - 125, 125, 125, 125, 0, 180, 180, 180, 180, 52, - 63, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 71, 180, 180, 44, 84, 85, 180, 180, - - 180, 180, 54, 176, 179, 178, 172, 180, 174, 173, - 177, 180, 0, 180, 180, 124, 180, 180, 180, 124, - 180, 123, 180, 0, 0, 125, 125, 125, 125, 125, - 125, 0, 0, 126, 125, 125, 125, 0, 0, 125, - 125, 125, 125, 125, 0, 0, 0, 0, 0, 0, - 0, 125, 125, 125, 125, 125, 0, 0, 0, 0, - 0, 125, 125, 0, 125, 0, 125, 0, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 128, 127, 180, 180, 72, 180, 180, - - 180, 175, 171, 180, 180, 124, 124, 124, 124, 180, - 123, 180, 0, 125, 125, 0, 125, 125, 0, 125, - 0, 0, 125, 0, 125, 126, 125, 0, 0, 0, - 125, 125, 0, 125, 126, 125, 0, 0, 0, 0, - 0, 125, 125, 0, 125, 126, 125, 0, 125, 125, - 0, 0, 0, 0, 0, 0, 0, 125, 125, 125, - 125, 125, 0, 65, 180, 55, 133, 140, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 145, 144, 180, 66, - 49, 180, 180, 0, 180, 180, 180, 180, 180, 123, - - 180, 0, 0, 125, 125, 125, 125, 125, 125, 125, - 125, 125, 0, 0, 126, 125, 125, 125, 0, 0, - 125, 125, 125, 125, 125, 0, 0, 0, 0, 0, - 0, 0, 125, 125, 125, 125, 125, 0, 125, 125, - 0, 0, 0, 0, 0, 0, 0, 125, 125, 125, - 125, 125, 0, 0, 0, 0, 0, 0, 125, 125, - 0, 125, 0, 125, 0, 90, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 146, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 51, 122, 122, - 124, 124, 180, 123, 180, 0, 125, 125, 0, 125, - - 125, 0, 125, 125, 0, 125, 0, 122, 125, 0, - 125, 126, 125, 0, 0, 0, 125, 125, 0, 125, - 126, 125, 0, 0, 0, 0, 0, 125, 125, 0, - 125, 126, 125, 0, 0, 0, 0, 0, 0, 125, - 125, 0, 125, 126, 125, 0, 125, 125, 125, 0, - 0, 0, 0, 0, 0, 0, 125, 125, 125, 125, - 125, 0, 180, 180, 180, 180, 180, 180, 180, 180, - 138, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 91, 122, 122, 124, 180, 122, 122, 0, - 0, 125, 125, 125, 125, 125, 125, 125, 125, 125, - - 125, 125, 125, 0, 122, 126, 125, 125, 125, 0, - 0, 125, 125, 125, 125, 125, 0, 0, 0, 0, - 0, 0, 0, 125, 125, 125, 125, 125, 0, 125, - 125, 0, 0, 0, 0, 0, 0, 0, 125, 125, - 125, 125, 125, 0, 125, 125, 125, 0, 0, 0, - 0, 0, 0, 0, 125, 125, 125, 125, 125, 0, - 0, 0, 0, 0, 0, 125, 125, 0, 125, 0, - 125, 0, 180, 180, 180, 142, 180, 180, 180, 180, - 180, 180, 180, 130, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 124, 180, 123, 0, 125, 125, - - 0, 125, 125, 0, 125, 125, 0, 125, 125, 0, - 125, 0, 0, 0, 125, 0, 0, 125, 126, 125, - 0, 0, 0, 125, 125, 0, 125, 126, 125, 0, - 0, 0, 0, 0, 125, 125, 0, 125, 126, 125, - 0, 0, 0, 0, 0, 0, 125, 125, 0, 125, - 126, 125, 0, 0, 0, 0, 0, 0, 125, 125, - 0, 125, 126, 125, 0, 125, 125, 125, 0, 0, - 0, 0, 0, 0, 0, 125, 125, 125, 125, 125, - 0, 180, 180, 180, 180, 132, 180, 180, 180, 136, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - - 180, 180, 180, 122, 0, 0, 125, 125, 125, 125, - 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, - 125, 0, 0, 0, 126, 0, 0, 125, 0, 0, - 125, 125, 125, 0, 0, 0, 0, 0, 0, 0, - 125, 125, 125, 0, 125, 125, 0, 0, 0, 0, - 0, 0, 0, 125, 125, 125, 0, 125, 125, 125, - 0, 0, 0, 0, 0, 0, 0, 125, 125, 125, - 0, 125, 125, 125, 0, 0, 0, 0, 0, 0, - 0, 125, 125, 125, 0, 0, 0, 0, 0, 0, - 125, 125, 0, 125, 0, 125, 0, 129, 141, 143, - - 137, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 155, 180, 180, 180, 0, 0, 125, - 0, 125, 0, 125, 125, 0, 125, 125, 0, 125, - 125, 0, 125, 125, 0, 125, 0, 0, 0, 0, - 125, 125, 0, 125, 0, 0, 125, 125, 125, 0, - 0, 0, 0, 125, 125, 125, 0, 0, 0, 0, - 0, 125, 125, 125, 0, 0, 0, 0, 0, 125, - 125, 125, 0, 0, 0, 0, 0, 125, 125, 125, - 125, 125, 125, 0, 0, 0, 0, 0, 0, 0, - 125, 125, 125, 0, 180, 180, 180, 180, 180, 180, - - 147, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 0, 0, 0, 125, 125, 125, 125, 125, 125, - 0, 0, 0, 0, 125, 125, 0, 0, 0, 0, - 125, 125, 125, 0, 0, 0, 0, 0, 125, 125, - 125, 125, 0, 0, 0, 0, 0, 125, 125, 125, - 125, 0, 0, 0, 0, 0, 125, 125, 125, 125, - 0, 0, 0, 0, 0, 125, 0, 0, 0, 0, - 0, 125, 125, 125, 180, 180, 180, 139, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 125, 125, 125, 125, 125, 125, 125, 125, 0, - - 0, 0, 0, 125, 125, 0, 0, 125, 0, 0, - 0, 125, 0, 0, 0, 125, 0, 0, 0, 125, - 0, 0, 0, 125, 125, 125, 125, 0, 0, 0, - 0, 0, 125, 134, 180, 131, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 156, 180, 125, - 0, 0, 125, 125, 0, 125, 125, 125, 0, 125, - 125, 125, 0, 125, 125, 125, 0, 125, 125, 125, - 0, 0, 0, 0, 125, 135, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 152, 180, 125, 125, - 0, 0, 0, 0, 0, 0, 125, 125, 125, 0, - - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 151, 0, 125, 125, 125, 125, 125, 0, 167, - 180, 180, 180, 180, 180, 180, 180, 154, 180, 180, - 125, 125, 166, 180, 180, 180, 180, 180, 180, 153, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 165, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 180, 180, 180, 164, 180, 180, 180, - 180, 180, 170, 180, 180, 180, 180, 180, 180, 180, - 180, 180, 180, 157, 180, 180, 180, 180, 180, 150, - - 180, 180, 168, 180, 180, 180, 180, 180, 180, 148, - 180, 169, 180, 163, 180, 180, 180, 180, 158, 180, - 160, 180, 180, 162, 159, 149, 161, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 5, 1, 1, 6, 7, 8, 1, 9, - 9, 7, 7, 1, 10, 11, 7, 12, 13, 14, - 15, 16, 17, 18, 17, 17, 17, 19, 1, 20, - 21, 22, 1, 1, 23, 23, 23, 23, 23, 23, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 25, 24, 24, - 26, 27, 26, 7, 28, 1, 29, 30, 31, 32, - - 33, 34, 35, 36, 37, 24, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 24, 1, 53, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[54] = - { 0, - 1, 2, 2, 1, 2, 1, 1, 3, 2, 4, - 5, 6, 6, 6, 6, 6, 6, 6, 7, 3, - 3, 3, 8, 4, 9, 3, 1, 4, 8, 8, - 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 9, 4, 3 - } ; - -static yyconst flex_uint16_t yy_base[2189] = - { 0, - 0, 0, 5455, 53, 7856, 7856, 57, 5433, 64, 81, - 5445, 7856, 7856, 99, 30, 151, 46, 5430, 52, 168, - 210, 168, 160, 44, 125, 60, 31, 58, 132, 170, - 214, 217, 229, 59, 170, 222, 237, 243, 250, 5418, - 255, 5410, 5380, 300, 7856, 0, 7856, 316, 339, 363, - 5413, 387, 0, 394, 0, 428, 7856, 7856, 7856, 7856, - 7856, 296, 316, 0, 5386, 5383, 5397, 0, 5395, 5383, - 5396, 5378, 5366, 5360, 5361, 5362, 5360, 5344, 5352, 5337, - 5350, 5331, 116, 5341, 5312, 5297, 5295, 5299, 5305, 5294, - 5299, 5279, 5278, 56, 68, 5263, 5261, 80, 5265, 5259, - - 5267, 68, 166, 0, 0, 15, 122, 5255, 5264, 189, - 5238, 5236, 5219, 5222, 5212, 5219, 5209, 5208, 5214, 0, - 5212, 0, 5195, 5181, 5175, 5176, 5175, 5174, 128, 5185, - 5168, 5167, 5160, 159, 5147, 201, 5144, 38, 5137, 5149, - 0, 5133, 0, 5112, 5111, 5094, 5090, 5078, 5048, 5062, - 7856, 7856, 453, 477, 236, 518, 542, 566, 5071, 573, - 5078, 597, 248, 5054, 5029, 5034, 5025, 0, 0, 5030, - 0, 5038, 5033, 5022, 5006, 5007, 5004, 5005, 5012, 0, - 0, 5006, 4996, 0, 5008, 4988, 4976, 4990, 4989, 4992, - 4988, 4972, 4971, 4953, 4969, 4952, 4956, 4951, 4952, 4965, - - 4950, 4934, 0, 4939, 4933, 0, 0, 4937, 4927, 0, - 4938, 0, 4935, 4907, 4912, 0, 0, 4901, 0, 4909, - 4917, 244, 4899, 0, 4887, 4882, 0, 4877, 0, 4880, - 0, 4861, 4864, 4857, 4845, 4850, 4843, 4839, 0, 4837, - 4849, 0, 4838, 0, 4837, 0, 0, 0, 4819, 0, - 153, 156, 4830, 0, 0, 4821, 0, 4818, 4818, 637, - 4847, 660, 684, 4830, 691, 500, 281, 715, 4821, 739, - 4820, 4819, 747, 290, 4818, 4816, 507, 788, 811, 4815, - 0, 0, 4775, 350, 4778, 4783, 0, 0, 0, 4781, - 0, 4777, 4762, 4746, 0, 4746, 0, 4740, 4739, 4740, - - 0, 4722, 4721, 0, 0, 0, 0, 0, 614, 4728, - 0, 0, 4736, 4715, 4700, 0, 0, 4698, 0, 0, - 0, 0, 4713, 4704, 4710, 0, 4703, 4706, 4707, 4679, - 4675, 4667, 4639, 0, 4632, 0, 4607, 0, 275, 0, - 0, 4599, 4592, 817, 4585, 0, 0, 0, 856, 880, - 293, 921, 4610, 4608, 405, 944, 968, 992, 4598, 999, - 621, 4581, 4579, 1022, 770, 1046, 1069, 4562, 0, 4553, - 427, 428, 1093, 4552, 1117, 333, 4551, 4550, 4519, 0, - 0, 0, 0, 4491, 0, 4504, 4502, 4469, 4460, 0, - 4477, 4472, 4463, 0, 0, 1136, 293, 4453, 4420, 4437, - - 0, 4427, 0, 4429, 4422, 0, 0, 4420, 4394, 292, - 4393, 4411, 387, 4408, 0, 4390, 4382, 4394, 4368, 4362, - 4372, 4350, 4357, 4338, 4317, 4318, 4310, 4278, 4292, 1173, - 4310, 1196, 1220, 4305, 1227, 777, 285, 1251, 334, 1291, - 1314, 1338, 4294, 4293, 1346, 336, 4291, 4256, 4255, 4254, - 1387, 363, 4252, 4251, 515, 631, 1428, 4250, 1452, 364, - 4240, 4247, 4218, 840, 0, 371, 4214, 903, 1493, 1516, - 4212, 0, 0, 4184, 4200, 4149, 0, 4158, 4140, 0, - 4145, 4158, 4143, 4126, 4125, 380, 4109, 427, 4108, 1121, - 4106, 4095, 4082, 4067, 4076, 0, 4066, 4077, 4025, 4028, - - 4026, 4015, 4014, 0, 0, 4018, 0, 3981, 3973, 3986, - 3984, 3976, 3949, 3960, 3929, 3923, 3918, 3909, 3888, 3885, - 1541, 1565, 423, 1606, 3892, 3888, 633, 1630, 1654, 1661, - 1685, 3877, 1692, 1716, 1739, 3876, 3857, 3856, 1762, 910, - 1786, 1809, 3852, 0, 1274, 0, 461, 3837, 1281, 1833, - 1856, 3833, 0, 785, 824, 3820, 485, 853, 856, 1880, - 3810, 1904, 424, 3809, 3798, 529, 3762, 3765, 3739, 0, - 0, 3742, 3729, 3715, 3691, 3703, 3683, 3666, 3672, 3664, - 3643, 3632, 3633, 3619, 3601, 56, 504, 646, 3609, 3575, - 3584, 3582, 0, 3573, 3567, 0, 0, 0, 3580, 3552, - - 3533, 3519, 0, 0, 0, 0, 0, 3523, 0, 0, - 0, 3512, 1944, 3547, 1967, 1991, 3514, 1998, 325, 2022, - 2046, 2053, 2077, 3505, 3474, 2085, 452, 3434, 2126, 476, - 3393, 3386, 3385, 3365, 2167, 513, 3345, 918, 938, 2208, - 3344, 2232, 542, 3343, 3348, 1142, 1149, 3347, 3314, 1167, - 1169, 2273, 3305, 2297, 543, 3304, 3310, 1369, 0, 1376, - 0, 486, 3282, 1410, 2338, 2361, 3278, 0, 2384, 374, - 115, 389, 150, 672, 205, 610, 3235, 550, 403, 313, - 783, 553, 761, 522, 800, 451, 578, 893, 633, 829, - 571, 1108, 1112, 3231, 3228, 1123, 3206, 3189, 1130, 1128, - - 593, 3186, 3185, 2422, 2459, 2495, 2531, 634, 2555, 258, - 2563, 2587, 3194, 2594, 2618, 2641, 3193, 2665, 2688, 3191, - 3188, 3185, 2711, 1417, 2735, 2758, 3184, 0, 1475, 0, - 723, 3172, 1482, 2782, 2805, 3147, 0, 1588, 0, 1595, - 0, 724, 3146, 1927, 2829, 2852, 3135, 0, 661, 1934, - 3122, 1290, 1425, 3114, 3111, 1490, 1510, 2876, 3101, 2900, - 662, 3090, 3061, 636, 803, 653, 1290, 1427, 1492, 2095, - 1604, 708, 849, 937, 2122, 872, 1605, 1944, 804, 1187, - 1242, 2099, 936, 960, 1532, 2101, 874, 938, 1015, 962, - 1014, 2124, 2163, 2942, 1016, 2965, 1038, 2988, 2154, 3012, - - 3036, 3052, 3051, 3044, 686, 3049, 3085, 967, 3047, 3126, - 969, 3046, 3045, 3020, 3017, 3167, 970, 2967, 1541, 1733, - 3208, 2966, 3232, 1022, 2947, 2953, 2096, 2163, 2951, 2950, - 2164, 2182, 3273, 2909, 3297, 1042, 2908, 2915, 1043, 2255, - 2913, 2183, 2184, 2911, 2892, 2205, 2249, 3338, 2882, 3362, - 1045, 2881, 2886, 0, 2263, 0, 2320, 0, 756, 2857, - 2327, 3403, 3426, 2853, 0, 1061, 1062, 1087, 1111, 2337, - 1188, 1943, 1189, 1244, 2376, 1534, 2377, 2336, 1109, 1243, - 2402, 2013, 1306, 2096, 2378, 1446, 2375, 1245, 3451, 3474, - 3498, 1066, 3538, 3562, 3586, 2834, 3593, 3617, 3640, 2830, - - 3664, 3687, 2811, 3711, 3734, 2810, 2806, 2791, 3757, 2445, - 3781, 3804, 2789, 0, 2482, 0, 1008, 2787, 2502, 3828, - 3851, 2744, 0, 2509, 0, 2516, 0, 1153, 2741, 2523, - 3875, 3898, 2740, 0, 0, 2923, 0, 2930, 0, 1300, - 2718, 3067, 3922, 3945, 2717, 0, 0, 1198, 3074, 2724, - 2399, 2417, 2721, 2701, 2453, 2454, 3969, 2670, 3993, 1285, - 2649, 2655, 2401, 2438, 3083, 2398, 1558, 2457, 2940, 1708, - 3084, 1557, 1385, 1709, 1508, 1754, 1710, 1755, 1778, 3120, - 1779, 3118, 1801, 1803, 1825, 4035, 4059, 4068, 1826, 2646, - 2643, 4086, 1287, 2624, 4127, 1288, 2600, 4168, 1315, 2599, - - 4209, 1345, 2597, 2596, 2595, 4249, 4273, 1427, 2594, 2635, - 2682, 4314, 2572, 4338, 1429, 2571, 2578, 2938, 2942, 2577, - 2576, 3096, 3142, 4379, 2566, 4403, 1489, 2540, 2544, 1600, - 3156, 2542, 3151, 3164, 2541, 2540, 3183, 3184, 4444, 2531, - 4468, 1603, 2468, 2469, 0, 1605, 3255, 2438, 3203, 3205, - 2372, 2371, 3249, 3268, 4509, 2343, 4533, 1606, 2341, 2348, - 0, 3320, 0, 3327, 0, 1396, 2306, 3385, 4574, 4597, - 2299, 0, 3095, 3096, 3178, 1827, 3122, 2399, 1848, 3420, - 2959, 1849, 1850, 1872, 3248, 3380, 1874, 1896, 3490, 2014, - 3492, 1959, 2016, 3337, 4622, 4646, 4655, 2275, 4672, 4696, - - 4719, 2263, 4743, 4766, 2239, 4790, 4813, 2234, 4837, 4860, - 2198, 2194, 4884, 1630, 2192, 2145, 3523, 4925, 2144, 2107, - 0, 3530, 0, 1615, 2106, 4016, 4949, 2103, 2060, 0, - 4023, 0, 4075, 0, 1639, 2059, 4109, 4973, 2058, 2055, - 0, 0, 4116, 0, 4150, 0, 1669, 2000, 4157, 4997, - 1999, 1976, 0, 0, 4191, 0, 4198, 0, 1748, 1951, - 4232, 5021, 1945, 1913, 0, 0, 1660, 4239, 1917, 3335, - 3399, 1914, 1897, 3400, 3420, 5045, 1882, 5069, 1661, 1842, - 1846, 2102, 2177, 2200, 2289, 2103, 2612, 4283, 2226, 2473, - 4266, 2680, 4348, 4267, 4331, 3249, 3271, 4289, 4332, 3399, - - 2610, 2611, 4396, 5111, 1815, 5128, 5152, 1662, 1814, 5193, - 1689, 1811, 5234, 1736, 1795, 5275, 1879, 1791, 5316, 1880, - 1747, 1744, 4365, 5357, 1741, 1698, 0, 1697, 3634, 3681, - 5381, 1670, 1664, 1671, 3728, 4289, 1616, 1580, 4374, 4418, - 5405, 1568, 1565, 1552, 1938, 4432, 1527, 4441, 4478, 1508, - 1506, 4479, 4483, 5429, 1494, 1454, 1442, 0, 1940, 4497, - 1438, 4506, 4543, 1437, 1400, 4544, 4548, 5453, 1390, 1389, - 1363, 0, 1941, 4562, 1362, 4571, 4591, 83, 110, 4666, - 4667, 5477, 195, 198, 225, 0, 4907, 0, 4914, 0, - 2006, 307, 5092, 5501, 0, 348, 0, 2474, 2635, 2657, - - 2659, 2681, 3003, 5107, 5162, 4670, 2703, 4291, 4356, 2682, - 4376, 4923, 4443, 2728, 2729, 5108, 5163, 5525, 1943, 0, - 372, 5566, 0, 399, 5590, 0, 418, 5614, 0, 480, - 5638, 0, 520, 5662, 0, 544, 4671, 4713, 5686, 551, - 580, 582, 610, 604, 5180, 0, 2061, 624, 643, 5216, - 0, 5223, 0, 2062, 696, 697, 0, 5257, 0, 5264, - 0, 2109, 698, 720, 0, 5298, 0, 5305, 0, 2142, - 721, 749, 0, 5339, 0, 5346, 0, 2193, 750, 752, - 0, 1995, 5548, 762, 4760, 4807, 763, 798, 4854, 5086, - 5710, 793, 0, 804, 4508, 2751, 2752, 2774, 2775, 5146, - - 2776, 2799, 2822, 2823, 5720, 2845, 5703, 5722, 2846, 3270, - 3489, 5755, 820, 864, 0, 0, 0, 0, 0, 0, - 5555, 0, 2282, 880, 887, 0, 5127, 5354, 897, 930, - 0, 1997, 5739, 931, 5563, 5724, 934, 976, 0, 0, - 2024, 5778, 985, 5752, 5772, 1012, 1039, 0, 0, 2151, - 5792, 1063, 5787, 5788, 1102, 1103, 0, 0, 2181, 5802, - 1107, 5800, 5810, 1132, 1160, 0, 0, 5814, 0, 5828, - 0, 2347, 1176, 0, 5085, 3553, 2868, 2870, 3103, 5824, - 5827, 5837, 5838, 5839, 5826, 3379, 5843, 2892, 4573, 5736, - 2981, 0, 7856, 0, 0, 0, 0, 0, 0, 5845, - - 5847, 1190, 1235, 0, 7856, 5871, 0, 7856, 0, 5887, - 0, 7856, 0, 5894, 0, 7856, 0, 5901, 0, 7856, - 0, 5908, 0, 7856, 0, 2270, 5915, 1236, 5923, 5924, - 1237, 2414, 0, 2980, 5086, 2982, 3004, 5926, 5356, 5565, - 3201, 5849, 4287, 3005, 5927, 5106, 5850, 3006, 5928, 0, - 5927, 0, 2272, 5954, 1240, 0, 2273, 5964, 1264, 0, - 2338, 5971, 1306, 0, 2396, 5978, 1322, 0, 2531, 5985, - 1356, 0, 5992, 0, 7856, 3177, 6001, 3442, 3444, 3467, - 6002, 6004, 6005, 6008, 3491, 6006, 3378, 6007, 2532, 6007, - 1357, 0, 0, 0, 0, 0, 0, 2533, 6043, 1361, - - 6016, 6037, 5852, 6039, 3554, 6040, 3555, 3556, 6017, 6052, - 6056, 3419, 0, 0, 0, 0, 0, 0, 0, 3466, - 6059, 3611, 3658, 3705, 6060, 6062, 6063, 3468, 6065, 6066, - 0, 0, 3609, 3610, 3634, 3656, 6067, 3680, 6068, 3681, - 6073, 6082, 6092, 6095, 3727, 6101, 3728, 6103, 3749, 5102, - 3773, 3774, 3797, 6106, 6111, 6115, 3775, 6116, 6122, 3820, - 6123, 6126, 6128, 3822, 6114, 6142, 6148, 3844, 3845, 6152, - 6153, 6154, 6155, 3869, 3890, 6158, 3891, 6162, 3914, 6163, - 6167, 3915, 3916, 3938, 6169, 6177, 4737, 6191, 3939, 6182, - 6194, 6197, 6198, 3961, 6204, 6203, 6205, 3963, 6206, 3985, - - 4084, 6213, 3987, 6218, 6227, 4125, 4613, 6219, 4308, 4032, - 6228, 4033, 4615, 4085, 6238, 6229, 6240, 4784, 4166, 6239, - 4207, 6241, 6268, 4208, 4665, 4666, 4669, 7856, 6296, 6304, - 6308, 6311, 6314, 6317, 6320, 6323, 6326, 6329, 6332, 6335, - 6338, 6341, 6344, 6347, 6350, 6353, 6356, 6360, 6364, 6367, - 6370, 6373, 6376, 6379, 6382, 6385, 6388, 6392, 6396, 6399, - 6402, 6406, 6408, 6411, 6414, 6417, 6420, 6423, 6426, 6429, - 6432, 6436, 6438, 6441, 6445, 6450, 6454, 6457, 6461, 6464, - 6467, 6470, 6473, 6476, 6479, 6482, 6486, 6490, 6493, 6497, - 6501, 6506, 6510, 6512, 6516, 6519, 6523, 6526, 6529, 6533, - - 6535, 6538, 6541, 6544, 6547, 6550, 6553, 6556, 6559, 6562, - 6566, 6568, 6571, 6574, 6577, 6581, 6583, 6586, 6589, 6594, - 6598, 6603, 6607, 6609, 6613, 6616, 6620, 6625, 6629, 6632, - 6635, 6638, 6641, 6644, 6647, 6650, 6654, 6658, 6661, 6665, - 6669, 6674, 6678, 6680, 6684, 6687, 6691, 6694, 6699, 6703, - 6708, 6712, 6714, 6718, 6721, 6725, 6728, 6731, 6734, 6738, - 6740, 6743, 6748, 6752, 6755, 6758, 6761, 6764, 6767, 6770, - 6773, 6776, 6780, 6782, 6785, 6788, 6791, 6795, 6797, 6800, - 6803, 6806, 6809, 6813, 6815, 6818, 6821, 6824, 6829, 6833, - 6838, 6842, 6844, 6848, 6851, 6855, 6860, 6864, 6867, 6870, - - 6873, 6876, 6879, 6882, 6885, 6889, 6893, 6896, 6900, 6904, - 6909, 6913, 6915, 6919, 6922, 6926, 6929, 6934, 6938, 6943, - 6947, 6949, 6953, 6956, 6960, 6963, 6966, 6971, 6975, 6980, - 6984, 6986, 6990, 6993, 6997, 7000, 7003, 7006, 7010, 7012, - 7015, 7020, 7024, 7027, 7030, 7033, 7036, 7039, 7042, 7045, - 7048, 7051, 7054, 7057, 7061, 7063, 7066, 7069, 7072, 7075, - 7079, 7081, 7084, 7087, 7090, 7093, 7096, 7100, 7102, 7105, - 7108, 7111, 7114, 7117, 7121, 7123, 7126, 7129, 7132, 7135, - 7140, 7144, 7149, 7153, 7155, 7159, 7162, 7166, 7171, 7175, - 7178, 7181, 7184, 7187, 7190, 7193, 7196, 7199, 7202, 7206, - - 7210, 7213, 7217, 7221, 7226, 7230, 7232, 7236, 7239, 7243, - 7246, 7251, 7255, 7260, 7264, 7266, 7270, 7273, 7277, 7280, - 7283, 7288, 7292, 7297, 7301, 7303, 7307, 7310, 7314, 7317, - 7320, 7325, 7329, 7334, 7338, 7340, 7344, 7347, 7351, 7354, - 7357, 7360, 7364, 7366, 7369, 7372, 7377, 7381, 7384, 7387, - 7390, 7393, 7396, 7399, 7402, 7405, 7408, 7411, 7414, 7418, - 7422, 7425, 7428, 7432, 7435, 7438, 7442, 7444, 7447, 7450, - 7454, 7456, 7459, 7462, 7465, 7469, 7471, 7474, 7477, 7480, - 7484, 7486, 7489, 7492, 7495, 7499, 7501, 7504, 7507, 7512, - 7516, 7521, 7525, 7527, 7531, 7534, 7538, 7543, 7547, 7550, - - 7553, 7556, 7559, 7562, 7565, 7568, 7571, 7575, 7577, 7580, - 7584, 7589, 7593, 7594, 7597, 7602, 7606, 7611, 7615, 7616, - 7619, 7622, 7627, 7631, 7636, 7640, 7641, 7644, 7647, 7652, - 7656, 7661, 7665, 7666, 7669, 7672, 7677, 7681, 7686, 7690, - 7691, 7694, 7697, 7700, 7704, 7706, 7711, 7715, 7718, 7721, - 7724, 7727, 7730, 7733, 7737, 7742, 7746, 7747, 7750, 7753, - 7756, 7759, 7762, 7765, 7768, 7771, 7774, 7777, 7782, 7786, - 7789, 7792, 7795, 7799, 7803, 7807, 7811, 7815, 7818, 7821, - 7825, 7828, 7831, 7834, 7837, 7840, 7844, 7847 - } ; - -static yyconst flex_int16_t yy_def[2189] = - { 0, - 1728, 1, 1728, 1728, 1728, 1728, 1728, 1728, 1729, 1728, - 1728, 1728, 1728, 1728, 14, 1728, 1728, 1728, 1728, 14, - 20, 1730, 20, 20, 20, 20, 20, 20, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 1728, 1728, 1728, 1731, 1728, 21, 21, 20, - 1732, 50, 21, 21, 21, 1728, 1728, 1728, 1728, 1728, - 1728, 49, 1730, 1730, 52, 52, 52, 21, 21, 21, - 21, 52, 21, 21, 52, 21, 21, 21, 52, 21, - 21, 21, 21, 21, 52, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 1728, 1728, 21, 21, 154, 21, 21, 157, 1733, 1728, - 54, 1728, 162, 1734, 21, 21, 158, 21, 21, 21, - 158, 21, 21, 21, 21, 21, 21, 158, 21, 21, - 21, 21, 21, 21, 21, 158, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 262, 263, 158, 1735, 268, - 1736, 1737, 1728, 273, 1738, 1739, 1728, 1728, 1728, 1740, - 1741, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 350, 21, 263, 265, 263, 265, 265, 357, 1742, 1728, - 356, 1743, 1744, 1728, 1728, 1728, 1728, 1745, 1746, 1747, - 1748, 1748, 1728, 1749, 1728, 375, 1750, 1741, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 432, 433, 433, 438, 432, - 357, 441, 1751, 1752, 1728, 445, 1753, 1728, 1754, 1755, - 1728, 451, 1756, 1757, 1758, 1758, 1728, 1759, 1728, 459, - 1760, 1746, 1728, 1728, 1761, 1762, 1728, 1728, 1728, 1728, - 1763, 1764, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 522, 21, 433, 435, 433, 433, 528, 441, - 530, 1765, 1728, 1728, 1728, 1766, 1767, 1768, 1728, 1728, - 1728, 1728, 1769, 1770, 1728, 1771, 1772, 1728, 1728, 1728, - 1728, 1773, 1774, 1775, 1775, 1761, 1762, 1776, 1776, 1728, - 1777, 1728, 562, 1778, 1779, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 616, 616, - 620, 530, 622, 1780, 1781, 1728, 626, 1782, 1728, 629, - 1783, 1728, 1784, 1785, 1728, 635, 1786, 1787, 1787, 1728, - 1788, 1728, 642, 1789, 1790, 1791, 1791, 1792, 1793, 1794, - 1794, 1728, 1795, 1728, 654, 1796, 1797, 1728, 1798, 1728, - 1799, 1800, 1728, 1728, 1728, 1728, 1801, 1802, 623, 669, - 669, 669, 669, 669, 669, 669, 669, 669, 669, 669, - 669, 669, 669, 669, 669, 669, 669, 669, 669, 669, - 669, 669, 669, 669, 669, 669, 669, 669, 669, 669, - - 669, 669, 669, 669, 669, 669, 706, 706, 706, 669, - 706, 711, 1803, 1728, 1728, 1728, 1804, 1728, 1728, 1805, - 1806, 1807, 1728, 1728, 1728, 1728, 1808, 1809, 1728, 1810, - 1811, 1728, 1728, 1728, 1728, 1812, 1813, 1728, 1814, 1728, - 1815, 1816, 1728, 1728, 1728, 1728, 1817, 1818, 1819, 1728, - 1820, 1821, 1821, 1822, 1823, 1824, 1824, 1728, 1825, 1728, - 760, 1826, 1827, 1828, 1828, 1828, 1828, 1828, 1828, 1828, - 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, - 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, 1828, - 1828, 1828, 1828, 1828, 1828, 794, 1828, 794, 798, 798, - - 800, 1829, 1830, 1728, 804, 1831, 1728, 807, 1832, 1728, - 810, 1833, 1728, 1834, 1835, 1728, 816, 1836, 1837, 1837, - 1728, 1838, 1728, 823, 1839, 1840, 1841, 1841, 1842, 1843, - 1844, 1844, 1728, 1845, 1728, 835, 1846, 1847, 1848, 1728, - 1849, 1850, 1850, 1851, 1852, 1853, 1853, 1728, 1854, 1728, - 850, 1855, 1856, 1857, 1728, 1858, 1728, 1859, 1860, 1728, - 1728, 1728, 1728, 1861, 1862, 1863, 1863, 1863, 1863, 1863, - 1863, 1863, 1863, 1863, 1863, 1863, 1863, 1863, 1863, 1863, - 1863, 1863, 1863, 1863, 1863, 1863, 1863, 1863, 1863, 889, - 889, 891, 889, 889, 894, 1864, 1728, 1728, 1728, 1865, - - 1728, 1728, 1866, 1728, 1728, 1867, 1868, 1869, 1728, 1728, - 1728, 1728, 1870, 1871, 1728, 1872, 1873, 1728, 1728, 1728, - 1728, 1874, 1875, 1728, 1876, 1728, 1877, 1878, 1728, 1728, - 1728, 1728, 1879, 1880, 1881, 1728, 1882, 1728, 1883, 1884, - 1728, 1728, 1728, 1728, 1885, 1886, 1887, 1888, 1728, 1889, - 1890, 1890, 1891, 1892, 1893, 1893, 1728, 1894, 1728, 959, - 1895, 1896, 1897, 1897, 1897, 1897, 1897, 1897, 1897, 1897, - 1897, 1897, 1897, 1897, 1897, 1897, 1897, 1897, 1897, 1897, - 1897, 1897, 1897, 1897, 1897, 1897, 986, 1897, 1897, 1898, - 1899, 1728, 992, 1900, 1728, 995, 1901, 1728, 998, 1902, - - 1728, 1001, 1903, 1728, 1904, 1728, 1728, 1007, 1905, 1906, - 1906, 1728, 1907, 1728, 1014, 1908, 1909, 1910, 1910, 1911, - 1912, 1913, 1913, 1728, 1914, 1728, 1026, 1915, 1916, 1917, - 1728, 1918, 1919, 1919, 1920, 1921, 1922, 1922, 1728, 1923, - 1728, 1041, 1924, 1925, 1926, 1927, 1728, 1928, 1929, 1929, - 1930, 1931, 1932, 1932, 1728, 1933, 1728, 1057, 1934, 1935, - 1936, 1728, 1937, 1728, 1938, 1939, 1728, 1728, 1728, 1728, - 1940, 1941, 1942, 1942, 1942, 1942, 1942, 1942, 1942, 1942, - 1942, 1942, 1942, 1942, 1942, 1942, 1942, 1942, 1942, 1942, - 1942, 1942, 1942, 1942, 1942, 1095, 1942, 1943, 1728, 1728, - - 1728, 1944, 1728, 1728, 1945, 1728, 1728, 1946, 1728, 1728, - 1947, 1948, 1728, 1113, 1949, 1950, 1728, 1728, 1951, 1952, - 1953, 1728, 1954, 1955, 1728, 1728, 1728, 1956, 1957, 1958, - 1728, 1959, 1728, 1960, 1961, 1728, 1728, 1728, 1962, 1963, - 1964, 1965, 1728, 1966, 1728, 1967, 1968, 1728, 1728, 1728, - 1969, 1970, 1971, 1972, 1728, 1973, 1728, 1974, 1975, 1728, - 1728, 1728, 1976, 1977, 1978, 1979, 1980, 1728, 1981, 1982, - 1982, 1983, 1984, 1985, 1985, 1728, 1986, 1728, 1178, 1987, - 1988, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, - 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, - - 1989, 1989, 1989, 1989, 1990, 1728, 1728, 1207, 1991, 1728, - 1210, 1992, 1728, 1213, 1993, 1728, 1216, 1994, 1728, 1219, - 1995, 1728, 1728, 1728, 1996, 1997, 1998, 1999, 2000, 2000, - 1728, 2001, 2002, 2003, 2004, 2004, 2005, 2006, 2007, 2007, - 1728, 2008, 2009, 2010, 2011, 1728, 2012, 2013, 2013, 2014, - 2015, 2016, 2016, 1728, 2017, 2018, 2019, 2020, 2021, 1728, - 2022, 2023, 2023, 2024, 2025, 2026, 2026, 1728, 2027, 2028, - 2029, 2030, 2031, 1728, 2032, 2033, 2033, 2034, 2035, 2036, - 2036, 1728, 2037, 2038, 2039, 2040, 1728, 2041, 1728, 2042, - 2043, 1728, 1728, 1728, 2044, 2045, 2046, 2047, 2047, 2047, - - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 1728, 1318, 2048, - 2049, 1728, 2050, 2051, 1728, 2052, 2053, 1728, 2054, 2055, - 1728, 2056, 2057, 1728, 2058, 2059, 2060, 2060, 1728, 2061, - 2062, 2063, 2064, 2065, 1728, 2066, 2067, 1728, 2068, 1728, - 2069, 1728, 2070, 2071, 1728, 2072, 2073, 1728, 2074, 1728, - 2075, 2076, 1728, 2077, 2078, 1728, 2079, 1728, 2080, 2081, - 1728, 2082, 2083, 1728, 2084, 1728, 2085, 2086, 1728, 2087, - 2088, 2089, 1728, 2090, 2091, 2091, 2092, 2093, 2094, 2094, - 1728, 2095, 2096, 2097, 2098, 2098, 2098, 2098, 2098, 2098, - - 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, - 2098, 1728, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2106, - 1728, 2107, 2108, 1728, 2109, 2110, 2111, 2111, 2112, 2113, - 2114, 2115, 1728, 2116, 2117, 2117, 2118, 2119, 2120, 2121, - 2122, 1728, 2123, 2124, 2124, 2125, 2126, 2127, 2128, 2129, - 1728, 2130, 2131, 2131, 2132, 2133, 2134, 2135, 2136, 1728, - 2137, 2138, 2138, 2139, 2140, 2141, 2142, 1728, 2143, 1728, - 2144, 2145, 1728, 2146, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2148, 1728, 2149, 2150, 2151, 2152, 2153, 2154, 2155, - - 2155, 2156, 2157, 2158, 1728, 1728, 2159, 1728, 2160, 1728, - 2161, 1728, 2162, 1728, 2163, 1728, 2164, 1728, 2165, 1728, - 2166, 1728, 2167, 1728, 2142, 2168, 1728, 2143, 2169, 2169, - 2144, 2145, 2170, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2171, - 1728, 2172, 2173, 1728, 2159, 2160, 2174, 1728, 2161, 2162, - 2175, 1728, 2163, 2164, 2176, 1728, 2165, 2166, 2177, 1728, - 2167, 2178, 1728, 2179, 1728, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2180, 1728, - 2172, 2181, 2182, 2183, 2184, 2185, 2178, 2186, 1728, 2179, - - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2187, 2181, 2182, 2183, 2184, 2185, 2188, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2187, 2188, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, 2147, - 2147, 2147, 2147, 2147, 2147, 2147, 2147, 0, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728 - } ; - -static yyconst flex_uint16_t yy_nxt[7910] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, - 13, 14, 15, 15, 15, 15, 15, 15, 16, 17, - 18, 19, 20, 21, 21, 12, 22, 13, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 21, 32, 33, - 34, 35, 36, 21, 37, 38, 39, 40, 41, 42, - 21, 21, 43, 44, 53, 211, 44, 44, 44, 44, - 44, 212, 44, 44, 44, 57, 58, 44, 248, 44, - 44, 44, 60, 61, 72, 44, 83, 84, 249, 44, - 53, 44, 44, 44, 44, 206, 44, 44, 73, 85, - 44, 117, 79, 1157, 86, 74, 80, 686, 195, 44, - - 118, 196, 81, 687, 197, 82, 198, 44, 48, 49, - 50, 50, 50, 50, 50, 50, 50, 51, 207, 201, - 942, 52, 53, 54, 202, 182, 55, 52, 52, 52, - 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, - 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, - 53, 44, 183, 75, 44, 766, 44, 44, 184, 236, - 87, 53, 213, 76, 88, 344, 77, 214, 63, 56, - 78, 63, 237, 63, 63, 208, 89, 44, 62, 52, - 52, 52, 52, 52, 52, 52, 63, 242, 65, 345, - 66, 67, 53, 768, 63, 68, 53, 342, 119, 343, - - 69, 90, 209, 91, 70, 243, 71, 210, 92, 93, - 120, 94, 121, 1335, 122, 95, 453, 123, 53, 55, - 53, 53, 53, 53, 53, 53, 53, 53, 1728, 104, - 105, 217, 53, 770, 218, 1161, 219, 245, 53, 53, - 53, 53, 53, 53, 96, 106, 246, 97, 98, 107, - 99, 53, 100, 108, 101, 109, 102, 111, 124, 103, - 53, 112, 110, 125, 126, 129, 127, 128, 799, 130, - 113, 114, 1728, 134, 115, 324, 116, 131, 141, 135, - 142, 136, 132, 137, 133, 146, 53, 138, 325, 139, - 140, 53, 355, 147, 143, 53, 527, 148, 1728, 149, - - 44, 144, 490, 44, 53, 44, 44, 156, 156, 156, - 156, 156, 156, 156, 1728, 417, 63, 53, 44, 63, - 418, 63, 63, 491, 500, 1070, 44, 153, 153, 153, - 153, 153, 153, 153, 63, 53, 708, 501, 153, 492, - 1728, 775, 63, 53, 153, 153, 153, 153, 153, 153, - 154, 155, 155, 155, 155, 155, 155, 1728, 53, 53, - 1728, 156, 380, 381, 382, 383, 1295, 156, 156, 156, - 156, 156, 156, 49, 157, 157, 157, 157, 157, 157, - 157, 277, 384, 1728, 53, 158, 1728, 1728, 1728, 279, - 1413, 158, 158, 158, 158, 158, 158, 62, 158, 158, - - 158, 158, 158, 158, 158, 161, 161, 161, 161, 161, - 161, 161, 576, 1728, 1728, 437, 161, 1323, 504, 765, - 53, 577, 161, 161, 161, 161, 161, 161, 44, 265, - 767, 44, 505, 44, 44, 53, 1326, 464, 464, 162, - 163, 163, 163, 163, 163, 163, 44, 53, 1728, 53, - 164, 465, 1728, 774, 44, 265, 164, 164, 164, 164, - 164, 164, 260, 579, 261, 261, 261, 261, 261, 261, - 261, 365, 580, 53, 1728, 261, 1728, 465, 1728, 535, - 781, 261, 261, 261, 261, 261, 261, 262, 263, 263, - 263, 263, 263, 263, 263, 277, 468, 53, 1329, 264, - - 1728, 265, 1728, 1728, 470, 264, 264, 264, 264, 264, - 264, 352, 352, 352, 352, 352, 352, 352, 371, 372, - 372, 372, 372, 372, 372, 545, 1728, 265, 266, 264, - 264, 264, 264, 264, 264, 264, 688, 1728, 1332, 546, - 264, 380, 381, 382, 383, 689, 264, 264, 264, 264, - 264, 264, 267, 268, 268, 268, 268, 268, 268, 268, - 269, 779, 1335, 1728, 270, 546, 1728, 1728, 53, 1413, - 270, 270, 270, 270, 270, 270, 53, 270, 270, 270, - 270, 270, 270, 270, 273, 274, 274, 274, 274, 274, - 274, 275, 1728, 1728, 773, 276, 53, 777, 453, 53, - - 453, 276, 276, 276, 276, 276, 276, 277, 278, 278, - 278, 278, 278, 278, 278, 279, 782, 53, 786, 280, - 1223, 281, 453, 396, 53, 280, 280, 280, 280, 280, - 280, 397, 440, 440, 440, 440, 440, 440, 440, 53, - 793, 545, 1323, 619, 398, 55, 771, 281, 349, 349, - 349, 349, 349, 349, 349, 1728, 53, 435, 618, 349, - 399, 453, 55, 55, 784, 349, 349, 349, 349, 349, - 349, 350, 351, 351, 351, 351, 351, 351, 690, 53, - 55, 1728, 352, 435, 618, 854, 1728, 691, 352, 352, - 352, 352, 352, 352, 262, 353, 353, 353, 353, 353, - - 353, 353, 354, 354, 354, 354, 354, 354, 354, 769, - 1728, 854, 1728, 354, 1326, 453, 1329, 55, 53, 354, - 354, 354, 354, 354, 354, 356, 357, 357, 357, 357, - 357, 357, 357, 540, 549, 55, 1728, 358, 453, 1332, - 872, 716, 719, 358, 358, 358, 358, 358, 358, 361, - 358, 358, 358, 358, 358, 358, 358, 365, 366, 366, - 366, 366, 366, 366, 366, 367, 664, 453, 1335, 368, - 453, 369, 1287, 1289, 666, 368, 368, 368, 368, 368, - 368, 455, 456, 456, 456, 456, 456, 456, 524, 524, - 524, 524, 524, 524, 524, 658, 778, 369, 277, 373, - - 373, 373, 373, 373, 373, 373, 279, 53, 1068, 659, - 374, 1295, 55, 55, 1293, 776, 374, 374, 374, 374, - 374, 374, 375, 376, 376, 376, 376, 376, 376, 53, - 55, 55, 780, 377, 658, 659, 879, 866, 1493, 377, - 377, 377, 377, 377, 377, 421, 53, 422, 1728, 423, - 424, 554, 555, 555, 555, 555, 555, 555, 55, 425, - 785, 426, 427, 660, 428, 430, 660, 431, 431, 431, - 431, 431, 431, 431, 1728, 53, 55, 661, 431, 873, - 1728, 55, 1413, 55, 431, 431, 431, 431, 431, 431, - 432, 433, 433, 433, 433, 433, 433, 433, 1413, 55, - - 876, 55, 434, 661, 435, 453, 1728, 1345, 434, 434, - 434, 434, 434, 434, 558, 559, 559, 559, 559, 559, - 559, 638, 639, 639, 639, 639, 639, 639, 729, 783, - 435, 436, 434, 434, 434, 434, 434, 434, 434, 53, - 1117, 1350, 730, 434, 1352, 55, 55, 55, 729, 434, - 434, 434, 434, 434, 434, 438, 439, 439, 439, 439, - 439, 439, 1728, 55, 55, 55, 440, 874, 730, 55, - 883, 55, 440, 440, 440, 440, 440, 440, 267, 441, - 441, 441, 441, 441, 441, 441, 1126, 55, 1728, 55, - 442, 1728, 884, 1728, 1728, 1358, 442, 442, 442, 442, - - 442, 442, 53, 442, 442, 442, 442, 442, 442, 442, - 445, 446, 446, 446, 446, 446, 446, 1728, 724, 1728, - 1728, 447, 1360, 55, 55, 794, 899, 447, 447, 447, - 447, 447, 447, 451, 452, 452, 452, 452, 452, 452, - 453, 55, 55, 55, 454, 887, 1728, 55, 796, 1137, - 454, 454, 454, 454, 454, 454, 365, 457, 457, 457, - 457, 457, 457, 457, 367, 55, 1728, 935, 458, 1728, - 55, 55, 1728, 1366, 458, 458, 458, 458, 458, 458, - 459, 460, 460, 460, 460, 460, 460, 453, 55, 55, - 53, 461, 1728, 935, 963, 1728, 55, 461, 461, 461, - - 461, 461, 461, 277, 466, 466, 466, 466, 466, 466, - 466, 279, 1368, 1149, 55, 467, 53, 1374, 55, 964, - 55, 467, 467, 467, 467, 467, 467, 468, 469, 469, - 469, 469, 469, 469, 469, 470, 55, 975, 55, 471, - 787, 472, 1376, 965, 788, 471, 471, 471, 471, 471, - 471, 582, 738, 583, 53, 789, 584, 585, 53, 738, - 586, 587, 791, 733, 792, 588, 739, 472, 482, 53, - 1161, 902, 483, 1728, 53, 484, 53, 740, 485, 740, - 486, 487, 488, 489, 521, 521, 521, 521, 521, 521, - 521, 741, 739, 1728, 1295, 521, 55, 55, 55, 1728, - - 1421, 521, 521, 521, 521, 521, 521, 522, 523, 523, - 523, 523, 523, 523, 55, 55, 55, 741, 524, 1728, - 967, 969, 1061, 880, 524, 524, 524, 524, 524, 524, - 432, 525, 525, 525, 525, 525, 525, 525, 526, 526, - 526, 526, 526, 526, 526, 1223, 1468, 1470, 1061, 526, - 1506, 55, 55, 55, 55, 526, 526, 526, 526, 526, - 526, 437, 528, 528, 528, 528, 528, 528, 528, 55, - 55, 55, 55, 529, 1510, 265, 970, 976, 881, 529, - 529, 529, 529, 529, 529, 646, 647, 647, 647, 647, - 647, 647, 650, 651, 651, 651, 651, 651, 651, 55, - - 855, 265, 529, 529, 529, 529, 529, 529, 529, 1728, - 744, 1728, 1728, 529, 856, 55, 1514, 55, 905, 529, - 529, 529, 529, 529, 529, 530, 530, 530, 530, 530, - 530, 530, 1518, 55, 867, 1728, 531, 1728, 1728, 1728, - 856, 979, 531, 531, 531, 531, 531, 531, 53, 531, - 531, 531, 531, 531, 531, 531, 365, 534, 534, 534, - 534, 534, 534, 534, 535, 1728, 1522, 1551, 536, 1728, - 369, 1573, 1155, 1149, 536, 536, 536, 536, 536, 536, - 749, 750, 750, 750, 750, 750, 750, 752, 753, 753, - 753, 753, 753, 753, 55, 1728, 369, 540, 541, 541, - - 541, 541, 541, 541, 541, 542, 861, 453, 1332, 543, - 930, 544, 55, 1085, 863, 543, 543, 543, 543, 543, - 543, 756, 757, 757, 757, 757, 757, 757, 819, 820, - 820, 820, 820, 820, 820, 855, 55, 544, 365, 547, - 547, 547, 547, 547, 547, 547, 535, 1145, 1143, 1728, - 548, 1728, 1137, 1728, 55, 55, 548, 548, 548, 548, - 548, 548, 549, 550, 550, 550, 550, 550, 550, 550, - 551, 868, 453, 55, 552, 1728, 553, 1728, 982, 1728, - 552, 552, 552, 552, 552, 552, 827, 828, 828, 828, - 828, 828, 828, 831, 832, 832, 832, 832, 832, 832, - - 857, 55, 553, 468, 560, 560, 560, 560, 560, 560, - 560, 470, 1329, 1728, 858, 561, 919, 55, 1133, 55, - 857, 561, 561, 561, 561, 561, 561, 562, 563, 563, - 563, 563, 563, 563, 1728, 55, 869, 1131, 564, 1728, - 858, 55, 1087, 55, 564, 564, 564, 564, 564, 564, - 613, 915, 614, 614, 614, 614, 614, 614, 614, 55, - 1728, 55, 1126, 614, 972, 916, 55, 55, 885, 614, - 614, 614, 614, 614, 614, 615, 616, 616, 616, 616, - 616, 616, 616, 453, 55, 55, 1326, 617, 1078, 618, - 910, 916, 1084, 617, 617, 617, 617, 617, 617, 839, - - 840, 840, 840, 840, 840, 840, 842, 843, 843, 843, - 843, 843, 843, 55, 55, 618, 615, 617, 617, 617, - 617, 617, 617, 617, 1142, 910, 1122, 1728, 617, 1154, - 1728, 55, 55, 1101, 617, 617, 617, 617, 617, 617, - 437, 620, 620, 620, 620, 620, 620, 620, 871, 919, - 1142, 877, 621, 1728, 1728, 1154, 1728, 1104, 621, 621, - 621, 621, 621, 621, 53, 621, 621, 621, 621, 621, - 621, 621, 622, 622, 622, 622, 622, 622, 622, 930, - 1728, 1117, 453, 623, 1286, 1728, 1728, 1107, 1323, 623, - 623, 623, 623, 623, 623, 53, 623, 623, 623, 623, - - 623, 623, 623, 626, 627, 627, 627, 627, 627, 627, - 1286, 1728, 1728, 1728, 628, 453, 1225, 55, 55, 55, - 628, 628, 628, 628, 628, 628, 365, 457, 457, 457, - 457, 457, 457, 457, 535, 55, 55, 55, 458, 1728, - 1082, 1086, 1089, 915, 458, 458, 458, 458, 458, 458, - 629, 630, 630, 630, 630, 630, 630, 1728, 942, 1342, - 1728, 631, 1206, 55, 55, 1335, 1110, 631, 631, 631, - 631, 631, 631, 635, 636, 636, 636, 636, 636, 636, - 453, 55, 55, 1728, 637, 1090, 1728, 55, 55, 1088, - 637, 637, 637, 637, 637, 637, 540, 640, 640, 640, - - 640, 640, 640, 640, 542, 55, 55, 1091, 641, 1332, - 55, 1093, 55, 1329, 641, 641, 641, 641, 641, 641, - 642, 643, 643, 643, 643, 643, 643, 453, 55, 1326, - 55, 644, 1323, 1206, 55, 55, 55, 644, 644, 644, - 644, 644, 644, 549, 652, 652, 652, 652, 652, 652, - 652, 551, 55, 55, 55, 653, 1068, 55, 55, 55, - 1295, 653, 653, 653, 653, 653, 653, 654, 655, 655, - 655, 655, 655, 655, 453, 55, 55, 55, 656, 1187, - 1190, 55, 1191, 55, 656, 656, 656, 656, 656, 656, - 468, 662, 662, 662, 662, 662, 662, 662, 470, 55, - - 1070, 55, 663, 1728, 1728, 55, 1194, 861, 663, 663, - 663, 663, 663, 663, 664, 665, 665, 665, 665, 665, - 665, 665, 666, 55, 1064, 1195, 667, 1062, 668, 1728, - 1728, 1163, 667, 667, 667, 667, 667, 667, 846, 847, - 847, 847, 847, 847, 847, 750, 750, 750, 750, 750, - 750, 750, 55, 55, 668, 704, 704, 704, 704, 704, - 704, 704, 1357, 453, 1365, 1373, 704, 1728, 55, 1110, - 55, 55, 704, 704, 704, 704, 704, 704, 705, 705, - 705, 705, 705, 705, 705, 878, 55, 968, 1357, 705, - 1365, 1373, 1199, 1728, 1151, 705, 705, 705, 705, 705, - - 705, 615, 706, 706, 706, 706, 706, 706, 706, 707, - 707, 707, 707, 707, 707, 707, 1068, 453, 1107, 1467, - 707, 1509, 55, 55, 1070, 55, 707, 707, 707, 707, - 707, 707, 437, 709, 709, 709, 709, 709, 709, 709, - 55, 55, 1197, 55, 710, 1467, 1200, 1509, 1513, 978, - 710, 710, 710, 710, 710, 710, 53, 710, 710, 710, - 710, 710, 710, 710, 711, 711, 711, 711, 711, 711, - 711, 1117, 1126, 1139, 1513, 712, 453, 1104, 1128, 1323, - 1326, 712, 712, 712, 712, 712, 712, 53, 712, 712, - 712, 712, 712, 712, 712, 540, 715, 715, 715, 715, - - 715, 715, 715, 716, 55, 55, 924, 717, 55, 544, - 55, 55, 55, 717, 717, 717, 717, 717, 717, 1137, - 925, 453, 55, 55, 1101, 1119, 55, 1329, 55, 55, - 55, 55, 980, 55, 870, 544, 549, 718, 718, 718, - 718, 718, 718, 718, 719, 882, 925, 886, 720, 55, - 553, 55, 1149, 1298, 720, 720, 720, 720, 720, 720, - 1332, 875, 453, 1225, 888, 893, 893, 893, 893, 893, - 893, 893, 55, 924, 926, 1517, 553, 724, 725, 725, - 725, 725, 725, 725, 725, 726, 55, 1728, 927, 727, - 55, 728, 926, 936, 936, 727, 727, 727, 727, 727, - - 727, 1517, 341, 1161, 55, 1521, 1728, 937, 1728, 55, - 453, 1335, 1206, 1728, 927, 938, 1110, 728, 540, 731, - 731, 731, 731, 731, 731, 731, 716, 55, 1299, 939, - 732, 1521, 1728, 937, 1728, 55, 732, 732, 732, 732, - 732, 732, 733, 734, 734, 734, 734, 734, 734, 734, - 735, 1300, 1107, 55, 736, 939, 737, 1104, 1304, 938, - 736, 736, 736, 736, 736, 736, 840, 840, 840, 840, - 840, 840, 840, 1728, 948, 949, 949, 949, 949, 949, - 949, 1101, 737, 549, 742, 742, 742, 742, 742, 742, - 742, 719, 1223, 1206, 1572, 743, 1592, 1593, 55, 1728, - - 1413, 743, 743, 743, 743, 743, 743, 744, 745, 745, - 745, 745, 745, 745, 745, 746, 55, 1070, 1301, 747, - 1572, 748, 1592, 1593, 863, 747, 747, 747, 747, 747, - 747, 951, 952, 952, 952, 952, 952, 952, 955, 956, - 956, 956, 956, 956, 956, 55, 55, 748, 664, 758, - 758, 758, 758, 758, 758, 758, 666, 1293, 942, 1163, - 759, 1110, 1594, 55, 55, 1295, 759, 759, 759, 759, - 759, 759, 760, 761, 761, 761, 761, 761, 761, 966, - 974, 744, 938, 762, 55, 55, 55, 55, 1594, 762, - 762, 762, 762, 762, 762, 53, 53, 53, 53, 53, - - 53, 53, 55, 55, 55, 55, 53, 55, 55, 1062, - 55, 55, 53, 53, 53, 53, 53, 53, 971, 973, - 1595, 983, 981, 1063, 1293, 55, 55, 1062, 55, 55, - 764, 794, 1728, 795, 795, 795, 795, 795, 795, 795, - 977, 1728, 1077, 1073, 795, 1186, 1595, 55, 936, 1063, - 795, 795, 795, 795, 795, 795, 1010, 1011, 1011, 1011, - 1011, 1011, 1011, 1064, 1064, 55, 55, 1728, 53, 796, - 797, 797, 797, 797, 797, 797, 797, 1065, 1728, 930, - 1074, 797, 55, 55, 55, 1079, 1151, 797, 797, 797, - 797, 797, 797, 1018, 1019, 1019, 1019, 1019, 1019, 1019, - - 55, 55, 1080, 1065, 1728, 53, 706, 706, 706, 706, - 706, 706, 706, 1022, 1023, 1023, 1023, 1023, 1023, 1023, - 1030, 1031, 1031, 1031, 1031, 1031, 1031, 1033, 1034, 1034, - 1034, 1034, 1034, 1034, 1037, 1038, 1038, 1038, 1038, 1038, - 1038, 53, 707, 707, 707, 707, 707, 707, 707, 1107, - 733, 926, 924, 707, 919, 1596, 1613, 1619, 1139, 707, - 707, 707, 707, 707, 707, 798, 353, 353, 353, 353, - 353, 353, 353, 267, 800, 800, 800, 800, 800, 800, - 800, 1596, 1613, 1619, 1104, 801, 724, 915, 910, 1128, - 1101, 801, 801, 801, 801, 801, 801, 53, 801, 801, - - 801, 801, 801, 801, 801, 804, 805, 805, 805, 805, - 805, 805, 1119, 1006, 991, 1110, 806, 1107, 1104, 55, - 55, 55, 806, 806, 806, 806, 806, 806, 540, 640, - 640, 640, 640, 640, 640, 640, 716, 55, 55, 55, - 641, 1315, 1101, 1316, 55, 1122, 641, 641, 641, 641, - 641, 641, 807, 808, 808, 808, 808, 808, 808, 1123, - 1302, 1099, 55, 809, 991, 861, 55, 1070, 55, 809, - 809, 809, 809, 809, 809, 549, 652, 652, 652, 652, - 652, 652, 652, 719, 55, 1123, 55, 653, 863, 55, - 55, 55, 1122, 653, 653, 653, 653, 653, 653, 810, - - 811, 811, 811, 811, 811, 811, 1728, 55, 55, 55, - 812, 664, 55, 1395, 1404, 1306, 812, 812, 812, 812, - 812, 812, 816, 817, 817, 817, 817, 817, 817, 453, - 55, 857, 1728, 818, 855, 944, 905, 55, 55, 818, - 818, 818, 818, 818, 818, 724, 821, 821, 821, 821, - 821, 821, 821, 726, 1401, 55, 55, 822, 932, 902, - 55, 55, 921, 822, 822, 822, 822, 822, 822, 823, - 824, 824, 824, 824, 824, 824, 453, 1409, 55, 55, - 825, 1476, 1477, 55, 55, 55, 825, 825, 825, 825, - 825, 825, 733, 833, 833, 833, 833, 833, 833, 833, - - 735, 55, 55, 55, 834, 899, 1479, 912, 55, 1006, - 834, 834, 834, 834, 834, 834, 835, 836, 836, 836, - 836, 836, 836, 453, 991, 1478, 55, 837, 905, 902, - 1481, 55, 55, 837, 837, 837, 837, 837, 837, 744, - 848, 848, 848, 848, 848, 848, 848, 746, 899, 55, - 55, 849, 991, 1482, 55, 55, 1483, 849, 849, 849, - 849, 849, 849, 850, 851, 851, 851, 851, 851, 851, - 453, 863, 55, 55, 852, 666, 1486, 55, 1489, 55, - 852, 852, 852, 852, 852, 852, 664, 859, 859, 859, - 859, 859, 859, 859, 666, 55, 744, 55, 860, 944, - - 905, 55, 549, 1536, 860, 860, 860, 860, 860, 860, - 861, 862, 862, 862, 862, 862, 862, 862, 863, 55, - 1546, 740, 864, 738, 865, 733, 932, 902, 864, 864, - 864, 864, 864, 864, 1046, 1047, 1047, 1047, 1047, 1047, - 1047, 1049, 1050, 1050, 1050, 1050, 1050, 1050, 1131, 55, - 865, 55, 1131, 889, 889, 889, 889, 889, 889, 889, - 540, 729, 1132, 724, 889, 921, 1728, 55, 55, 55, - 889, 889, 889, 889, 889, 889, 890, 890, 890, 890, - 890, 890, 890, 1081, 899, 912, 55, 890, 1132, 55, - 55, 55, 1728, 890, 890, 890, 890, 890, 890, 891, - - 892, 892, 892, 892, 892, 892, 1189, 55, 55, 55, - 893, 1549, 55, 55, 55, 55, 893, 893, 893, 893, - 893, 893, 267, 894, 894, 894, 894, 894, 894, 894, - 55, 55, 55, 55, 895, 909, 1577, 1584, 815, 1396, - 895, 895, 895, 895, 895, 895, 53, 895, 895, 895, - 895, 895, 895, 895, 724, 898, 898, 898, 898, 898, - 898, 898, 899, 803, 905, 902, 900, 899, 728, 897, - 803, 664, 900, 900, 900, 900, 900, 900, 1053, 1054, - 1054, 1054, 1054, 1054, 1054, 949, 949, 949, 949, 949, - 949, 949, 55, 55, 728, 733, 901, 901, 901, 901, - - 901, 901, 901, 902, 55, 55, 1133, 903, 863, 737, - 55, 55, 55, 903, 903, 903, 903, 903, 903, 666, - 1134, 468, 55, 55, 660, 1075, 1076, 55, 1083, 55, - 55, 55, 658, 1182, 1183, 737, 744, 904, 904, 904, - 904, 904, 904, 904, 905, 55, 1134, 55, 906, 55, - 748, 1537, 1133, 746, 906, 906, 906, 906, 906, 906, - 1092, 1143, 1094, 1185, 719, 735, 1728, 1031, 1031, 1031, - 1031, 1031, 1031, 1031, 1143, 1144, 748, 910, 911, 911, - 911, 911, 911, 911, 911, 912, 55, 55, 1728, 913, - 716, 914, 1728, 1145, 1145, 913, 913, 913, 913, 913, - - 913, 1144, 726, 815, 55, 55, 803, 1146, 1728, 719, - 55, 716, 803, 1155, 1728, 1155, 1184, 914, 724, 917, - 917, 917, 917, 917, 917, 917, 899, 1156, 55, 1728, - 918, 53, 53, 1146, 1728, 53, 918, 918, 918, 918, - 918, 918, 919, 920, 920, 920, 920, 920, 920, 920, - 921, 1581, 790, 1156, 922, 1728, 923, 55, 55, 1157, - 922, 922, 922, 922, 922, 922, 1047, 1047, 1047, 1047, - 1047, 1047, 1047, 1158, 53, 55, 55, 53, 1157, 55, - 55, 772, 923, 733, 928, 928, 928, 928, 928, 928, - 928, 902, 1728, 1310, 1192, 929, 666, 55, 55, 1158, - - 470, 929, 929, 929, 929, 929, 929, 930, 931, 931, - 931, 931, 931, 931, 931, 932, 1311, 1490, 1728, 933, - 549, 934, 746, 719, 365, 933, 933, 933, 933, 933, - 933, 1167, 1168, 1168, 1168, 1168, 1168, 1168, 1170, 1171, - 1171, 1171, 1171, 1171, 1171, 1287, 55, 934, 744, 940, - 940, 940, 940, 940, 940, 940, 905, 545, 540, 1288, - 941, 735, 716, 726, 55, 1201, 941, 941, 941, 941, - 941, 941, 942, 943, 943, 943, 943, 943, 943, 943, - 944, 1202, 1203, 723, 945, 1288, 946, 55, 55, 55, - 945, 945, 945, 945, 945, 945, 1174, 1175, 1175, 1175, - - 1175, 1175, 1175, 634, 625, 55, 55, 55, 55, 1287, - 1289, 719, 946, 861, 957, 957, 957, 957, 957, 957, - 957, 863, 1193, 1728, 1290, 958, 55, 1544, 55, 55, - 1289, 958, 958, 958, 958, 958, 958, 959, 960, 960, - 960, 960, 960, 960, 1728, 1314, 55, 55, 961, 1728, - 1290, 55, 716, 55, 961, 961, 961, 961, 961, 961, - 55, 1188, 984, 984, 984, 984, 984, 984, 984, 55, - 1728, 55, 1602, 984, 1603, 55, 55, 55, 55, 984, - 984, 984, 984, 984, 984, 985, 985, 985, 985, 985, - 985, 985, 714, 55, 55, 55, 985, 1604, 55, 55, - - 55, 55, 985, 985, 985, 985, 985, 985, 619, 986, - 986, 986, 986, 986, 986, 986, 55, 55, 55, 55, - 987, 1610, 435, 625, 615, 1491, 987, 987, 987, 987, - 987, 987, 1196, 1198, 1229, 1230, 1230, 1230, 1230, 1230, - 1230, 1235, 1236, 1236, 1236, 1236, 1236, 1236, 435, 987, - 987, 987, 987, 987, 987, 987, 613, 703, 702, 701, - 987, 700, 55, 55, 55, 55, 987, 987, 987, 987, - 987, 987, 267, 988, 988, 988, 988, 988, 988, 988, - 55, 55, 55, 55, 989, 1624, 699, 1626, 1627, 1535, - 989, 989, 989, 989, 989, 989, 53, 989, 989, 989, - - 989, 989, 989, 989, 992, 993, 993, 993, 993, 993, - 993, 698, 697, 696, 695, 994, 694, 693, 55, 55, - 55, 994, 994, 994, 994, 994, 994, 724, 821, 821, - 821, 821, 821, 821, 821, 899, 55, 55, 55, 822, - 692, 685, 1642, 55, 1345, 822, 822, 822, 822, 822, - 822, 995, 996, 996, 996, 996, 996, 996, 1346, 1634, - 684, 55, 997, 683, 682, 55, 1643, 55, 997, 997, - 997, 997, 997, 997, 733, 833, 833, 833, 833, 833, - 833, 833, 902, 55, 1346, 55, 834, 681, 1644, 55, - 55, 1345, 834, 834, 834, 834, 834, 834, 998, 999, - - 999, 999, 999, 999, 999, 1728, 1635, 55, 55, 1000, - 680, 679, 1646, 678, 55, 1000, 1000, 1000, 1000, 1000, - 1000, 744, 848, 848, 848, 848, 848, 848, 848, 905, - 677, 1728, 55, 849, 676, 675, 55, 55, 1350, 849, - 849, 849, 849, 849, 849, 1001, 1002, 1002, 1002, 1002, - 1002, 1002, 1351, 1636, 55, 55, 1003, 1655, 55, 1657, - 674, 673, 1003, 1003, 1003, 1003, 1003, 1003, 1007, 1008, - 1008, 1008, 1008, 1008, 1008, 453, 55, 672, 1351, 1009, - 671, 1659, 55, 55, 55, 1009, 1009, 1009, 1009, 1009, - 1009, 910, 1012, 1012, 1012, 1012, 1012, 1012, 1012, 912, - - 55, 55, 55, 1013, 670, 1661, 55, 669, 468, 1013, - 1013, 1013, 1013, 1013, 1013, 1014, 1015, 1015, 1015, 1015, - 1015, 1015, 453, 1669, 55, 1662, 1016, 666, 470, 55, - 464, 55, 1016, 1016, 1016, 1016, 1016, 1016, 919, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 921, 55, 1663, 55, - 1025, 551, 1672, 55, 55, 535, 1025, 1025, 1025, 1025, - 1025, 1025, 1026, 1027, 1027, 1027, 1027, 1027, 1027, 453, - 542, 55, 55, 1028, 634, 625, 1680, 1681, 55, 1028, - 1028, 1028, 1028, 1028, 1028, 930, 1039, 1039, 1039, 1039, - 1039, 1039, 1039, 932, 535, 625, 55, 1040, 619, 55, - - 55, 1686, 619, 1040, 1040, 1040, 1040, 1040, 1040, 1041, - 1042, 1042, 1042, 1042, 1042, 1042, 453, 55, 55, 612, - 1043, 1687, 611, 55, 55, 55, 1043, 1043, 1043, 1043, - 1043, 1043, 942, 1055, 1055, 1055, 1055, 1055, 1055, 1055, - 944, 55, 55, 55, 1056, 1693, 1690, 55, 55, 610, - 1056, 1056, 1056, 1056, 1056, 1056, 1057, 1058, 1058, 1058, - 1058, 1058, 1058, 453, 609, 55, 55, 1059, 608, 607, - 55, 1700, 55, 1059, 1059, 1059, 1059, 1059, 1059, 861, - 1066, 1066, 1066, 1066, 1066, 1066, 1066, 863, 55, 1694, - 55, 1067, 606, 605, 55, 1708, 55, 1067, 1067, 1067, - - 1067, 1067, 1067, 1068, 1069, 1069, 1069, 1069, 1069, 1069, - 1069, 1070, 55, 604, 55, 1071, 603, 1072, 602, 338, - 239, 1071, 1071, 1071, 1071, 1071, 1071, 1239, 1240, 1240, - 1240, 1240, 1240, 1240, 1245, 1246, 1246, 1246, 1246, 1246, - 1246, 55, 55, 1072, 55, 619, 1095, 1095, 1095, 1095, - 1095, 1095, 1095, 601, 600, 599, 598, 1096, 597, 55, - 55, 596, 55, 1096, 1096, 1096, 1096, 1096, 1096, 53, - 1096, 1096, 1096, 1096, 1096, 1096, 1096, 55, 267, 1097, - 1097, 1097, 1097, 1097, 1097, 1097, 1248, 1249, 1249, 1249, - 1249, 1249, 1249, 55, 55, 55, 910, 1100, 1100, 1100, - - 1100, 1100, 1100, 1100, 1101, 595, 594, 593, 1102, 592, - 914, 55, 55, 591, 1102, 1102, 1102, 1102, 1102, 1102, - 1252, 1253, 1253, 1253, 1253, 1253, 1253, 1259, 1260, 1260, - 1260, 1260, 1260, 1260, 55, 1710, 914, 919, 1103, 1103, - 1103, 1103, 1103, 1103, 1103, 1104, 590, 589, 581, 1105, - 578, 923, 55, 575, 574, 1105, 1105, 1105, 1105, 1105, - 1105, 1262, 1263, 1263, 1263, 1263, 1263, 1263, 1266, 1267, - 1267, 1267, 1267, 1267, 1267, 55, 1714, 923, 930, 1106, - 1106, 1106, 1106, 1106, 1106, 1106, 1107, 573, 572, 571, - 1108, 570, 934, 55, 569, 568, 1108, 1108, 1108, 1108, - - 1108, 1108, 1273, 1274, 1274, 1274, 1274, 1274, 1274, 1276, - 1277, 1277, 1277, 1277, 1277, 1277, 55, 55, 934, 942, - 1109, 1109, 1109, 1109, 1109, 1109, 1109, 1110, 567, 566, - 470, 1111, 279, 946, 55, 55, 453, 1111, 1111, 1111, - 1111, 1111, 1111, 1280, 1281, 1281, 1281, 1281, 1281, 1281, - 1168, 1168, 1168, 1168, 1168, 1168, 1168, 365, 551, 946, - 1113, 1114, 1114, 1114, 1114, 1114, 1114, 1115, 535, 542, - 453, 1116, 539, 450, 444, 55, 55, 1116, 1116, 1116, - 1116, 1116, 1116, 1117, 1118, 1118, 1118, 1118, 1118, 1118, - 1118, 1119, 55, 55, 55, 1120, 55, 1121, 55, 1350, - - 55, 1120, 1120, 1120, 1120, 1120, 1120, 1308, 1305, 535, - 55, 533, 444, 1728, 55, 436, 55, 55, 55, 430, - 520, 1303, 519, 1121, 910, 1124, 1124, 1124, 1124, 1124, - 1124, 1124, 1101, 1312, 1583, 55, 1125, 1402, 1717, 1728, - 55, 55, 1125, 1125, 1125, 1125, 1125, 1125, 1126, 1127, - 1127, 1127, 1127, 1127, 1127, 1127, 1128, 55, 55, 55, - 1129, 518, 1130, 517, 516, 55, 1129, 1129, 1129, 1129, - 1129, 1129, 1309, 1313, 515, 55, 1337, 1338, 1338, 1338, - 1338, 1338, 1338, 55, 1352, 55, 1307, 514, 1130, 919, - 1135, 1135, 1135, 1135, 1135, 1135, 1135, 1104, 1353, 513, - - 1403, 1136, 512, 55, 511, 55, 510, 1136, 1136, 1136, - 1136, 1136, 1136, 1137, 1138, 1138, 1138, 1138, 1138, 1138, - 1138, 1139, 1405, 55, 1353, 1140, 509, 1141, 1352, 508, - 507, 1140, 1140, 1140, 1140, 1140, 1140, 1317, 506, 503, - 502, 499, 1728, 1246, 1246, 1246, 1246, 1246, 1246, 1246, - 498, 1358, 55, 1141, 930, 1147, 1147, 1147, 1147, 1147, - 1147, 1147, 1107, 497, 496, 1359, 1148, 495, 1728, 120, - 55, 494, 1148, 1148, 1148, 1148, 1148, 1148, 1149, 1150, - 1150, 1150, 1150, 1150, 1150, 1150, 1151, 1408, 1358, 1360, - 1152, 1359, 1153, 1360, 493, 481, 1152, 1152, 1152, 1152, - - 1152, 1152, 1728, 1361, 480, 479, 478, 1728, 1260, 1260, - 1260, 1260, 1260, 1260, 1260, 477, 1366, 55, 1153, 942, - 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1110, 1728, 1361, - 1367, 1160, 476, 1728, 475, 55, 474, 1160, 1160, 1160, - 1160, 1160, 1160, 1161, 1162, 1162, 1162, 1162, 1162, 1162, - 1162, 1163, 1475, 1366, 1368, 1164, 1367, 1165, 1368, 473, - 277, 1164, 1164, 1164, 1164, 1164, 1164, 1728, 1369, 470, - 279, 453, 1728, 1274, 1274, 1274, 1274, 1274, 1274, 1274, - 367, 1374, 55, 1165, 1068, 1176, 1176, 1176, 1176, 1176, - 1176, 1176, 1070, 1728, 1369, 1375, 1177, 450, 1728, 444, - - 55, 1374, 1177, 1177, 1177, 1177, 1177, 1177, 1178, 1179, - 1179, 1179, 1179, 1179, 1179, 1728, 444, 1547, 437, 1180, - 437, 1375, 55, 429, 55, 1180, 1180, 1180, 1180, 1180, - 1180, 55, 619, 1204, 1204, 1204, 1204, 1204, 1204, 1204, - 55, 1728, 55, 420, 989, 1715, 419, 1719, 416, 55, - 989, 989, 989, 989, 989, 989, 53, 989, 989, 989, - 989, 989, 989, 989, 55, 267, 1097, 1097, 1097, 1097, - 1097, 1097, 1097, 415, 55, 55, 1376, 1376, 55, 55, - 414, 1421, 55, 1207, 1208, 1208, 1208, 1208, 1208, 1208, - 1377, 1728, 55, 55, 1209, 1422, 55, 55, 1399, 413, - - 1209, 1209, 1209, 1209, 1209, 1209, 910, 1012, 1012, 1012, - 1012, 1012, 1012, 1012, 1101, 1400, 1377, 1728, 1013, 412, - 411, 1422, 410, 1421, 1013, 1013, 1013, 1013, 1013, 1013, - 1210, 1211, 1211, 1211, 1211, 1211, 1211, 1728, 409, 408, - 407, 1212, 406, 405, 404, 403, 55, 1212, 1212, 1212, - 1212, 1212, 1212, 919, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1104, 402, 1728, 55, 1025, 401, 400, 395, 394, - 1468, 1025, 1025, 1025, 1025, 1025, 1025, 1213, 1214, 1214, - 1214, 1214, 1214, 1214, 1469, 1698, 393, 392, 1215, 391, - 320, 390, 389, 55, 1215, 1215, 1215, 1215, 1215, 1215, - - 930, 1039, 1039, 1039, 1039, 1039, 1039, 1039, 1107, 388, - 1469, 55, 1040, 387, 386, 385, 379, 1468, 1040, 1040, - 1040, 1040, 1040, 1040, 1216, 1217, 1217, 1217, 1217, 1217, - 1217, 1728, 1723, 279, 367, 1218, 275, 364, 272, 360, - 266, 1218, 1218, 1218, 1218, 1218, 1218, 942, 1055, 1055, - 1055, 1055, 1055, 1055, 1055, 1110, 260, 1728, 143, 1056, - 348, 347, 346, 341, 1470, 1056, 1056, 1056, 1056, 1056, - 1056, 1219, 1220, 1220, 1220, 1220, 1220, 1220, 1471, 320, - 340, 339, 1221, 338, 337, 336, 335, 334, 1221, 1221, - 1221, 1221, 1221, 1221, 1223, 1224, 1224, 1224, 1224, 1224, - - 1224, 1224, 1225, 333, 1471, 332, 1226, 331, 1227, 330, - 329, 328, 1226, 1226, 1226, 1226, 1226, 1226, 1382, 1383, - 1383, 1383, 1383, 1383, 1383, 1385, 1386, 1386, 1386, 1386, - 1386, 1386, 55, 327, 1227, 1117, 1231, 1231, 1231, 1231, - 1231, 1231, 1231, 1119, 326, 323, 322, 1232, 321, 320, - 55, 1406, 319, 1232, 1232, 1232, 1232, 1232, 1232, 1126, - 1241, 1241, 1241, 1241, 1241, 1241, 1241, 1128, 1407, 318, - 317, 1242, 316, 315, 314, 313, 312, 1242, 1242, 1242, - 1242, 1242, 1242, 1137, 1254, 1254, 1254, 1254, 1254, 1254, - 1254, 1139, 311, 310, 309, 1255, 308, 307, 306, 305, - - 304, 1255, 1255, 1255, 1255, 1255, 1255, 1149, 1268, 1268, - 1268, 1268, 1268, 1268, 1268, 1151, 303, 302, 301, 1269, - 300, 299, 298, 297, 143, 1269, 1269, 1269, 1269, 1269, - 1269, 1161, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1163, - 296, 295, 294, 1283, 293, 292, 291, 290, 289, 1283, - 1283, 1283, 1283, 1283, 1283, 1068, 1291, 1291, 1291, 1291, - 1291, 1291, 1291, 1070, 288, 287, 286, 1292, 285, 284, - 283, 282, 279, 1292, 1292, 1292, 1292, 1292, 1292, 1293, - 1294, 1294, 1294, 1294, 1294, 1294, 1294, 1295, 267, 272, - 259, 1296, 258, 1297, 55, 55, 1470, 1296, 1296, 1296, - - 1296, 1296, 1296, 1389, 1390, 1390, 1390, 1390, 1390, 1390, - 1728, 55, 55, 55, 257, 55, 55, 55, 256, 1297, - 55, 619, 525, 525, 525, 525, 525, 525, 525, 55, - 255, 1534, 1576, 55, 55, 55, 1728, 1506, 55, 1318, - 1319, 1319, 1319, 1319, 1319, 1319, 1320, 1397, 1410, 1660, - 1321, 1507, 1586, 254, 253, 55, 1321, 1321, 1321, 1321, - 1321, 1321, 1117, 1322, 1322, 1322, 1322, 1322, 1322, 1322, - 1323, 55, 55, 55, 1324, 252, 1121, 1507, 251, 250, - 1324, 1324, 1324, 1324, 1324, 1324, 247, 1480, 244, 55, - 55, 1427, 1428, 1428, 1428, 1428, 1428, 1428, 241, 240, - - 1398, 1411, 1121, 1126, 1325, 1325, 1325, 1325, 1325, 1325, - 1325, 1326, 239, 238, 235, 1327, 234, 1130, 233, 232, - 231, 1327, 1327, 1327, 1327, 1327, 1327, 1432, 1433, 1433, - 1433, 1433, 1433, 1433, 1435, 1436, 1436, 1436, 1436, 1436, - 1436, 230, 229, 1130, 1137, 1328, 1328, 1328, 1328, 1328, - 1328, 1328, 1329, 228, 227, 226, 1330, 225, 1141, 224, - 223, 222, 1330, 1330, 1330, 1330, 1330, 1330, 1441, 1442, - 1442, 1442, 1442, 1442, 1442, 1444, 1445, 1445, 1445, 1445, - 1445, 1445, 221, 220, 1141, 1149, 1331, 1331, 1331, 1331, - 1331, 1331, 1331, 1332, 216, 215, 205, 1333, 204, 1153, - - 203, 200, 199, 1333, 1333, 1333, 1333, 1333, 1333, 1450, - 1451, 1451, 1451, 1451, 1451, 1451, 1453, 1454, 1454, 1454, - 1454, 1454, 1454, 194, 193, 1153, 1161, 1334, 1334, 1334, - 1334, 1334, 1334, 1334, 1335, 192, 191, 190, 1336, 189, - 1165, 188, 187, 186, 1336, 1336, 1336, 1336, 1336, 1336, - 1459, 1460, 1460, 1460, 1460, 1460, 1460, 1462, 1463, 1463, - 1463, 1463, 1463, 1463, 1506, 55, 1165, 1223, 1339, 1339, - 1339, 1339, 1339, 1339, 1339, 1225, 185, 181, 1728, 1340, - 180, 179, 178, 55, 177, 1340, 1340, 1340, 1340, 1340, - 1340, 1117, 1347, 1347, 1347, 1347, 1347, 1347, 1347, 1323, - - 176, 1579, 175, 1348, 1728, 174, 173, 172, 171, 1348, - 1348, 1348, 1348, 1348, 1348, 1126, 1354, 1354, 1354, 1354, - 1354, 1354, 1354, 1326, 170, 169, 168, 1355, 167, 166, - 165, 160, 151, 1355, 1355, 1355, 1355, 1355, 1355, 1137, - 1362, 1362, 1362, 1362, 1362, 1362, 1362, 1329, 150, 145, - 59, 1363, 47, 45, 1728, 1728, 1728, 1363, 1363, 1363, - 1363, 1363, 1363, 1149, 1370, 1370, 1370, 1370, 1370, 1370, - 1370, 1332, 1728, 1728, 1728, 1371, 1728, 1728, 1728, 1728, - 1728, 1371, 1371, 1371, 1371, 1371, 1371, 1161, 1378, 1378, - 1378, 1378, 1378, 1378, 1378, 1335, 1728, 1728, 1728, 1379, - - 1728, 1728, 1728, 1728, 1728, 1379, 1379, 1379, 1379, 1379, - 1379, 1293, 1391, 1391, 1391, 1391, 1391, 1391, 1391, 1295, - 1728, 1728, 1728, 1392, 1728, 1728, 1728, 1728, 1728, 1392, - 1392, 1392, 1392, 1392, 1392, 1223, 1412, 1412, 1412, 1412, - 1412, 1412, 1412, 1413, 1728, 1728, 1728, 1414, 1728, 1227, - 1728, 1728, 1728, 1414, 1414, 1414, 1414, 1414, 1414, 1383, - 1383, 1383, 1383, 1383, 1383, 1383, 1500, 1501, 1501, 1501, - 1501, 1501, 1501, 1510, 55, 1227, 1117, 1231, 1231, 1231, - 1231, 1231, 1231, 1231, 1323, 1728, 1728, 1511, 1232, 1728, - 1728, 1728, 55, 1728, 1232, 1232, 1232, 1232, 1232, 1232, - - 1126, 1241, 1241, 1241, 1241, 1241, 1241, 1241, 1326, 1728, - 1580, 1728, 1242, 1511, 1728, 1728, 1728, 1728, 1242, 1242, - 1242, 1242, 1242, 1242, 1137, 1254, 1254, 1254, 1254, 1254, - 1254, 1254, 1329, 1728, 1728, 1728, 1255, 1728, 1728, 1728, - 1728, 1728, 1255, 1255, 1255, 1255, 1255, 1255, 1149, 1268, - 1268, 1268, 1268, 1268, 1268, 1268, 1332, 1728, 1728, 1728, - 1269, 1728, 1728, 1728, 1728, 1728, 1269, 1269, 1269, 1269, - 1269, 1269, 1161, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - 1335, 1728, 1728, 1728, 1283, 1728, 1728, 1728, 1728, 1728, - 1283, 1283, 1283, 1283, 1283, 1283, 1223, 1423, 1423, 1423, - - 1423, 1423, 1423, 1423, 1413, 1728, 1728, 1728, 1424, 1728, - 1728, 1728, 55, 1728, 1424, 1424, 1424, 1424, 1424, 1424, - 1293, 1472, 1472, 1472, 1472, 1472, 1472, 1472, 1295, 55, - 55, 55, 1473, 1728, 1510, 1728, 1728, 1728, 1473, 1473, - 1473, 1473, 1473, 1473, 1487, 55, 1728, 55, 1728, 55, - 1433, 1433, 1433, 1433, 1433, 1433, 1433, 1728, 1484, 1728, - 1728, 1488, 1514, 55, 1485, 1223, 1339, 1339, 1339, 1339, - 1339, 1339, 1339, 1413, 1728, 1548, 1515, 1340, 1728, 1728, - 1728, 1728, 1514, 1340, 1340, 1340, 1340, 1340, 1340, 1442, - 1442, 1442, 1442, 1442, 1442, 1442, 1728, 1518, 1518, 1728, - - 1728, 1728, 1515, 1451, 1451, 1451, 1451, 1451, 1451, 1451, - 1522, 1519, 1728, 1460, 1460, 1460, 1460, 1460, 1460, 1460, - 1522, 1728, 1728, 1728, 1523, 1526, 1527, 1527, 1527, 1527, - 1527, 1527, 1728, 55, 1728, 55, 55, 1519, 1728, 1529, - 1530, 1530, 1530, 1530, 1530, 1530, 55, 55, 55, 1728, - 1523, 55, 55, 55, 55, 1551, 1728, 1551, 55, 55, - 1728, 55, 1538, 1539, 55, 55, 55, 1543, 1728, 1552, - 55, 1728, 1728, 1540, 1541, 1542, 55, 55, 1728, 55, - 1728, 1545, 1553, 1554, 1554, 1554, 1554, 1554, 1554, 1728, - 1728, 1728, 1728, 1622, 1582, 1552, 1587, 1728, 1557, 1558, - - 1558, 1558, 1558, 1558, 1558, 1561, 1562, 1562, 1562, 1562, - 1562, 1562, 1565, 1566, 1566, 1566, 1566, 1566, 1566, 1569, - 1570, 1570, 1570, 1570, 1570, 1570, 1527, 1527, 1527, 1527, - 1527, 1527, 1527, 1573, 1573, 55, 55, 55, 1589, 1590, - 1590, 1590, 1590, 1590, 1590, 1728, 1728, 1574, 1728, 1728, - 1728, 1728, 1728, 55, 55, 55, 1728, 1728, 1728, 1728, - 1728, 1728, 1578, 1585, 1588, 1554, 1554, 1554, 1554, 1554, - 1554, 1554, 1728, 1574, 1728, 1558, 1558, 1558, 1558, 1558, - 1558, 1558, 1562, 1562, 1562, 1562, 1562, 1562, 1562, 1566, - 1566, 1566, 1566, 1566, 1566, 1566, 1570, 1570, 1570, 1570, - - 1570, 1570, 1570, 1598, 1599, 1599, 1599, 1599, 1599, 1599, - 55, 55, 1728, 55, 55, 55, 55, 55, 1590, 1590, - 1590, 1590, 1590, 1590, 1590, 55, 55, 1728, 55, 55, - 1605, 55, 55, 55, 55, 55, 1728, 1728, 1728, 1728, - 1728, 1728, 1611, 55, 55, 1601, 55, 1606, 55, 55, - 1607, 1608, 1609, 1612, 1599, 1599, 1599, 1599, 1599, 1599, - 1599, 55, 1620, 1628, 55, 55, 55, 55, 55, 55, - 1728, 55, 55, 1621, 55, 55, 55, 55, 1728, 55, - 1623, 1625, 55, 55, 1728, 1728, 55, 55, 1629, 55, - 55, 55, 55, 55, 55, 55, 1647, 1630, 1637, 1728, - - 55, 55, 1638, 1645, 55, 1633, 1641, 1639, 1728, 55, - 55, 1640, 55, 1648, 1649, 55, 1650, 1651, 1728, 55, - 55, 1728, 55, 55, 55, 55, 1652, 1728, 55, 1728, - 55, 55, 55, 55, 1728, 55, 1653, 55, 55, 1654, - 1728, 55, 55, 55, 1658, 1656, 1666, 1665, 1728, 55, - 55, 55, 1664, 55, 1670, 55, 1675, 55, 1667, 1668, - 1677, 55, 55, 55, 55, 1728, 1671, 55, 1673, 55, - 1674, 55, 55, 1676, 1728, 55, 55, 1728, 55, 55, - 55, 55, 55, 1678, 1728, 55, 55, 1728, 1682, 55, - 55, 55, 1683, 1728, 55, 1679, 55, 1685, 1684, 1688, - - 55, 1728, 1689, 55, 55, 1691, 55, 55, 1728, 55, - 1695, 1692, 55, 55, 55, 55, 1728, 1728, 55, 1696, - 1697, 55, 55, 1728, 55, 55, 1701, 55, 55, 1699, - 55, 55, 55, 55, 1704, 1702, 55, 55, 55, 1728, - 55, 1706, 1709, 1703, 1705, 55, 55, 55, 55, 55, - 55, 1728, 1707, 1728, 55, 55, 55, 1711, 1728, 1728, - 1728, 1728, 1728, 1716, 1712, 55, 55, 55, 55, 1728, - 1728, 1728, 1713, 1728, 1718, 1721, 1722, 55, 1728, 1728, - 1726, 1727, 1728, 1720, 1728, 1724, 1728, 1725, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 55, 46, 1728, 1728, 1728, - - 1728, 46, 46, 46, 64, 1728, 64, 64, 64, 64, - 64, 64, 64, 152, 1728, 152, 159, 159, 159, 271, - 271, 271, 280, 280, 280, 359, 359, 359, 362, 362, - 362, 363, 363, 363, 370, 370, 370, 368, 368, 368, - 374, 374, 374, 378, 1728, 378, 443, 443, 443, 448, - 448, 448, 449, 449, 449, 458, 458, 458, 462, 1728, - 462, 463, 463, 463, 372, 372, 1728, 1728, 372, 467, - 467, 467, 471, 471, 471, 362, 362, 362, 532, 532, - 532, 536, 536, 536, 537, 537, 537, 538, 538, 538, - 370, 370, 370, 543, 543, 543, 456, 456, 1728, 1728, - - 456, 548, 548, 548, 552, 552, 552, 556, 1728, 556, - 557, 557, 557, 561, 561, 561, 565, 1728, 565, 624, - 624, 624, 458, 458, 458, 632, 632, 632, 633, 633, - 633, 641, 641, 641, 645, 1728, 645, 648, 1728, 648, - 649, 649, 649, 653, 653, 653, 657, 1728, 657, 555, - 555, 1728, 1728, 555, 559, 559, 1728, 1728, 559, 663, - 663, 663, 667, 667, 667, 565, 565, 1728, 565, 537, - 537, 537, 713, 713, 713, 717, 717, 717, 720, 720, - 720, 721, 721, 721, 722, 722, 722, 727, 727, 727, - 639, 639, 1728, 1728, 639, 732, 732, 732, 736, 736, - - 736, 645, 645, 1728, 645, 647, 647, 1728, 1728, 647, - 648, 648, 1728, 648, 649, 649, 651, 651, 1728, 1728, - 651, 743, 743, 743, 747, 747, 747, 657, 657, 1728, - 657, 751, 1728, 751, 754, 1728, 754, 755, 755, 755, - 759, 759, 759, 763, 1728, 763, 802, 802, 802, 641, - 641, 641, 653, 653, 653, 813, 813, 813, 814, 814, - 814, 822, 822, 822, 826, 1728, 826, 829, 1728, 829, - 830, 830, 830, 834, 834, 834, 838, 1728, 838, 841, - 1728, 841, 844, 1728, 844, 845, 845, 845, 849, 849, - 849, 853, 1728, 853, 750, 1728, 1728, 750, 751, 751, - - 1728, 751, 753, 753, 1728, 1728, 753, 754, 754, 1728, - 754, 755, 755, 757, 757, 1728, 1728, 757, 860, 860, - 860, 864, 864, 864, 763, 763, 1728, 763, 53, 53, - 53, 1728, 53, 53, 721, 721, 721, 896, 896, 896, - 900, 900, 900, 903, 903, 903, 906, 906, 906, 907, - 907, 907, 908, 908, 908, 913, 913, 913, 820, 820, - 1728, 1728, 820, 918, 918, 918, 922, 922, 922, 826, - 826, 1728, 826, 828, 828, 1728, 1728, 828, 829, 829, - 1728, 829, 830, 830, 832, 832, 1728, 1728, 832, 929, - 929, 929, 933, 933, 933, 838, 838, 1728, 838, 840, - - 1728, 1728, 840, 841, 841, 1728, 841, 843, 843, 1728, - 1728, 843, 844, 844, 1728, 844, 845, 845, 847, 847, - 1728, 1728, 847, 941, 941, 941, 945, 945, 945, 853, - 853, 1728, 853, 947, 1728, 947, 950, 1728, 950, 953, - 1728, 953, 954, 954, 954, 958, 958, 958, 962, 1728, - 962, 53, 53, 53, 1728, 53, 53, 990, 990, 990, - 822, 822, 822, 834, 834, 834, 849, 849, 849, 1004, - 1004, 1004, 1005, 1005, 1005, 1013, 1013, 1013, 1017, 1728, - 1017, 1020, 1728, 1020, 1021, 1021, 1021, 1025, 1025, 1025, - 1029, 1728, 1029, 1032, 1728, 1032, 1035, 1728, 1035, 1036, - - 1036, 1036, 1040, 1040, 1040, 1044, 1728, 1044, 1045, 1728, - 1045, 1048, 1728, 1048, 1051, 1728, 1051, 1052, 1052, 1052, - 1056, 1056, 1056, 1060, 1728, 1060, 947, 1728, 947, 949, - 1728, 1728, 949, 950, 950, 1728, 950, 952, 952, 1728, - 1728, 952, 953, 953, 1728, 953, 954, 954, 956, 956, - 1728, 1728, 956, 1067, 1067, 1067, 1071, 1071, 1071, 962, - 962, 1728, 962, 53, 53, 53, 1728, 53, 53, 907, - 907, 907, 1098, 1098, 1098, 1102, 1102, 1102, 1105, 1105, - 1105, 1108, 1108, 1108, 1111, 1111, 1111, 1112, 1112, 1112, - 1120, 1120, 1120, 1011, 1011, 1728, 1728, 1011, 1125, 1125, - - 1125, 1129, 1129, 1129, 1017, 1017, 1728, 1017, 1019, 1019, - 1728, 1728, 1019, 1020, 1020, 1728, 1020, 1021, 1021, 1023, - 1023, 1728, 1728, 1023, 1136, 1136, 1136, 1140, 1140, 1140, - 1029, 1029, 1728, 1029, 1031, 1728, 1728, 1031, 1032, 1032, - 1728, 1032, 1034, 1034, 1728, 1728, 1034, 1035, 1035, 1728, - 1035, 1036, 1036, 1038, 1038, 1728, 1728, 1038, 1148, 1148, - 1148, 1152, 1152, 1152, 1044, 1044, 1728, 1044, 1045, 1728, - 1045, 1047, 1728, 1728, 1047, 1048, 1048, 1728, 1048, 1050, - 1050, 1728, 1728, 1050, 1051, 1051, 1728, 1051, 1052, 1052, - 1054, 1054, 1728, 1728, 1054, 1160, 1160, 1160, 1164, 1164, - - 1164, 1060, 1060, 1728, 1060, 1166, 1728, 1166, 1169, 1728, - 1169, 1172, 1728, 1172, 1173, 1173, 1173, 1177, 1177, 1177, - 1181, 1728, 1181, 53, 53, 53, 1728, 53, 53, 1205, - 1205, 1205, 1013, 1013, 1013, 1025, 1025, 1025, 1040, 1040, - 1040, 1056, 1056, 1056, 1222, 1222, 1222, 1228, 1228, 1228, - 1226, 1226, 1226, 1233, 1233, 1233, 1232, 1232, 1232, 1234, - 1728, 1234, 1237, 1728, 1237, 1238, 1238, 1238, 1243, 1243, - 1243, 1242, 1242, 1242, 1244, 1728, 1244, 1247, 1728, 1247, - 1250, 1728, 1250, 1251, 1251, 1251, 1256, 1256, 1256, 1255, - 1255, 1255, 1257, 1728, 1257, 1258, 1728, 1258, 1261, 1728, - - 1261, 1264, 1728, 1264, 1265, 1265, 1265, 1270, 1270, 1270, - 1269, 1269, 1269, 1271, 1728, 1271, 1272, 1728, 1272, 1275, - 1728, 1275, 1278, 1728, 1278, 1279, 1279, 1279, 1284, 1284, - 1284, 1283, 1283, 1283, 1285, 1728, 1285, 1166, 1728, 1166, - 1168, 1728, 1728, 1168, 1169, 1169, 1728, 1169, 1171, 1171, - 1728, 1728, 1171, 1172, 1172, 1728, 1172, 1173, 1173, 1175, - 1175, 1728, 1728, 1175, 1292, 1292, 1292, 1296, 1296, 1296, - 1181, 1181, 1728, 1181, 53, 53, 53, 1728, 53, 53, - 1112, 1112, 1112, 1324, 1324, 1324, 1327, 1327, 1327, 1330, - 1330, 1330, 1333, 1333, 1333, 1336, 1336, 1336, 1341, 1341, - - 1341, 1340, 1340, 1340, 1343, 1728, 1343, 1344, 1344, 1344, - 1230, 1230, 1728, 1728, 1230, 1348, 1348, 1348, 1349, 1349, - 1349, 1234, 1234, 1728, 1234, 1236, 1236, 1728, 1728, 1236, - 1237, 1237, 1728, 1237, 1238, 1238, 1240, 1240, 1728, 1728, - 1240, 1355, 1355, 1355, 1356, 1356, 1356, 1244, 1244, 1728, - 1244, 1246, 1728, 1728, 1246, 1247, 1247, 1728, 1247, 1249, - 1249, 1728, 1728, 1249, 1250, 1250, 1728, 1250, 1251, 1251, - 1253, 1253, 1728, 1728, 1253, 1363, 1363, 1363, 1364, 1364, - 1364, 1257, 1257, 1728, 1257, 1258, 1728, 1258, 1260, 1728, - 1728, 1260, 1261, 1261, 1728, 1261, 1263, 1263, 1728, 1728, - - 1263, 1264, 1264, 1728, 1264, 1265, 1265, 1267, 1267, 1728, - 1728, 1267, 1371, 1371, 1371, 1372, 1372, 1372, 1271, 1271, - 1728, 1271, 1272, 1728, 1272, 1274, 1728, 1728, 1274, 1275, - 1275, 1728, 1275, 1277, 1277, 1728, 1728, 1277, 1278, 1278, - 1728, 1278, 1279, 1279, 1281, 1281, 1728, 1728, 1281, 1379, - 1379, 1379, 1380, 1380, 1380, 1285, 1285, 1728, 1285, 1381, - 1728, 1381, 1384, 1728, 1384, 1387, 1728, 1387, 1388, 1388, - 1388, 1393, 1728, 1393, 1392, 1392, 1392, 1394, 1728, 1394, - 53, 53, 53, 1728, 53, 53, 1415, 1728, 1415, 1414, - 1414, 1414, 1416, 1728, 1416, 1232, 1232, 1232, 1417, 1728, - - 1417, 1242, 1242, 1242, 1418, 1728, 1418, 1255, 1255, 1255, - 1419, 1728, 1419, 1269, 1269, 1269, 1420, 1728, 1420, 1283, - 1283, 1283, 1338, 1338, 1728, 1728, 1338, 1424, 1424, 1424, - 1425, 1425, 1425, 370, 370, 370, 1343, 1343, 1728, 1343, - 1426, 1426, 1426, 1429, 1728, 1429, 1430, 1430, 1430, 1431, - 1431, 1431, 1434, 1728, 1434, 1437, 1728, 1437, 1438, 1438, - 1438, 1439, 1439, 1439, 1440, 1728, 1440, 1443, 1728, 1443, - 1446, 1728, 1446, 1447, 1447, 1447, 1448, 1448, 1448, 1449, - 1728, 1449, 1452, 1728, 1452, 1455, 1728, 1455, 1456, 1456, - 1456, 1457, 1457, 1457, 1458, 1728, 1458, 1461, 1728, 1461, - - 1464, 1728, 1464, 1465, 1465, 1465, 1466, 1466, 1466, 1381, - 1728, 1381, 1383, 1728, 1728, 1383, 1384, 1384, 1728, 1384, - 1386, 1386, 1728, 1728, 1386, 1387, 1387, 1728, 1387, 1388, - 1388, 1390, 1390, 1728, 1728, 1390, 1473, 1473, 1473, 1474, - 1728, 1474, 1394, 1394, 1728, 1394, 53, 53, 53, 1728, - 53, 53, 1492, 1492, 1492, 1340, 1340, 1340, 1494, 1728, - 1494, 1495, 1728, 1495, 1496, 1728, 1496, 1497, 1728, 1497, - 1498, 1728, 1498, 1499, 1728, 1499, 1502, 1728, 1502, 1503, - 1503, 1503, 1504, 1504, 1504, 1505, 1728, 1505, 1428, 1428, - 1728, 1728, 1428, 1429, 1429, 1728, 1429, 1430, 1430, 1508, - - 1728, 1508, 1433, 1728, 1728, 1433, 1434, 1434, 1728, 1434, - 1436, 1436, 1728, 1728, 1436, 1437, 1437, 1728, 1437, 1438, - 1438, 1512, 1728, 1512, 1440, 1728, 1440, 1442, 1728, 1728, - 1442, 1443, 1443, 1728, 1443, 1445, 1445, 1728, 1728, 1445, - 1446, 1446, 1728, 1446, 1447, 1447, 1516, 1728, 1516, 1449, - 1728, 1449, 1451, 1728, 1728, 1451, 1452, 1452, 1728, 1452, - 1454, 1454, 1728, 1728, 1454, 1455, 1455, 1728, 1455, 1456, - 1456, 1520, 1728, 1520, 1458, 1728, 1458, 1460, 1728, 1728, - 1460, 1461, 1461, 1728, 1461, 1463, 1463, 1728, 1728, 1463, - 1464, 1464, 1728, 1464, 1465, 1465, 1524, 1728, 1524, 1525, - - 1728, 1525, 1528, 1728, 1528, 1531, 1728, 1531, 1532, 1532, - 1532, 1533, 1728, 1533, 53, 53, 53, 1728, 53, 53, - 1550, 1728, 1550, 1426, 1728, 1426, 1431, 1728, 1431, 1439, - 1728, 1439, 1448, 1728, 1448, 1457, 1728, 1457, 1466, 1728, - 1466, 1501, 1501, 1728, 1728, 1501, 1502, 1502, 1728, 1502, - 1503, 1503, 1493, 1728, 1493, 1555, 1728, 1555, 1556, 1728, - 1556, 1559, 1728, 1559, 1560, 1728, 1560, 1563, 1728, 1563, - 1564, 1728, 1564, 1567, 1728, 1567, 1568, 1728, 1568, 1571, - 1728, 1571, 1527, 1728, 1728, 1527, 1530, 1530, 1728, 1728, - 1530, 1575, 1728, 1575, 1504, 1728, 1504, 1591, 1728, 1591, - - 1554, 1728, 1728, 1554, 1558, 1728, 1728, 1558, 1562, 1728, - 1728, 1562, 1566, 1728, 1728, 1566, 1570, 1728, 1728, 1570, - 1597, 1728, 1597, 1600, 1728, 1600, 1590, 1728, 1728, 1590, - 1614, 1728, 1614, 1615, 1728, 1615, 1616, 1728, 1616, 1617, - 1728, 1617, 1618, 1728, 1618, 1599, 1728, 1728, 1599, 1631, - 1728, 1631, 1632, 1728, 1632, 3, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728 - } ; - -static yyconst flex_int16_t yy_chk[7910] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 4, 15, 106, 4, 7, 4, 4, - 7, 106, 7, 7, 9, 17, 17, 9, 138, 9, - 9, 4, 19, 19, 24, 7, 27, 27, 138, 4, - 15, 10, 9, 7, 10, 102, 10, 10, 24, 28, - 9, 34, 26, 1278, 28, 24, 26, 586, 94, 10, - - 34, 94, 26, 586, 95, 26, 95, 10, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 102, 98, - 1279, 14, 14, 14, 98, 83, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 16, 83, 25, 16, 671, 16, 16, 83, 129, - 29, 671, 107, 25, 29, 252, 25, 107, 22, 16, - 25, 22, 129, 22, 22, 103, 29, 16, 20, 20, - 20, 20, 20, 20, 20, 20, 22, 134, 23, 252, - 23, 23, 20, 673, 22, 23, 673, 251, 35, 251, - - 23, 30, 103, 30, 23, 134, 23, 103, 30, 30, - 35, 30, 35, 1283, 35, 30, 1284, 35, 20, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 32, - 32, 110, 21, 675, 110, 1285, 110, 136, 21, 21, - 21, 21, 21, 21, 31, 32, 136, 31, 31, 32, - 31, 675, 31, 32, 31, 32, 31, 33, 36, 31, - 155, 33, 32, 36, 36, 37, 36, 36, 710, 37, - 33, 33, 163, 38, 33, 222, 33, 37, 39, 38, - 39, 38, 37, 38, 37, 41, 155, 38, 222, 38, - 38, 267, 267, 41, 39, 437, 437, 41, 163, 41, - - 44, 39, 397, 44, 710, 44, 44, 62, 62, 62, - 62, 62, 62, 62, 274, 339, 63, 351, 44, 63, - 339, 63, 63, 397, 410, 1292, 44, 48, 48, 48, - 48, 48, 48, 48, 63, 619, 619, 410, 48, 397, - 274, 680, 63, 351, 48, 48, 48, 48, 48, 48, - 49, 49, 49, 49, 49, 49, 49, 376, 439, 680, - 446, 49, 284, 284, 284, 284, 1296, 49, 49, 49, - 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, - 50, 466, 284, 376, 439, 50, 446, 452, 460, 466, - 1321, 50, 50, 50, 50, 50, 50, 52, 52, 52, - - 52, 52, 52, 52, 52, 54, 54, 54, 54, 54, - 54, 54, 486, 452, 460, 355, 54, 1324, 413, 670, - 670, 486, 54, 54, 54, 54, 54, 54, 56, 355, - 672, 56, 413, 56, 56, 672, 1327, 371, 372, 56, - 56, 56, 56, 56, 56, 56, 56, 523, 563, 679, - 56, 371, 372, 679, 56, 355, 56, 56, 56, 56, - 56, 56, 153, 488, 153, 153, 153, 153, 153, 153, - 153, 547, 488, 523, 563, 153, 627, 371, 372, 547, - 686, 153, 153, 153, 153, 153, 153, 154, 154, 154, - 154, 154, 154, 154, 154, 557, 662, 686, 1330, 154, - - 630, 154, 627, 557, 662, 154, 154, 154, 154, 154, - 154, 266, 266, 266, 266, 266, 266, 266, 277, 277, - 277, 277, 277, 277, 277, 455, 630, 154, 156, 156, - 156, 156, 156, 156, 156, 156, 587, 636, 1333, 455, - 156, 566, 566, 566, 566, 587, 156, 156, 156, 156, - 156, 156, 157, 157, 157, 157, 157, 157, 157, 157, - 157, 684, 1336, 636, 157, 455, 643, 655, 684, 1340, - 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, - 158, 158, 158, 158, 160, 160, 160, 160, 160, 160, - 160, 160, 643, 655, 678, 160, 678, 682, 1341, 682, - - 1342, 160, 160, 160, 160, 160, 160, 162, 162, 162, - 162, 162, 162, 162, 162, 162, 687, 691, 691, 162, - 1343, 162, 1344, 309, 687, 162, 162, 162, 162, 162, - 162, 309, 361, 361, 361, 361, 361, 361, 361, 701, - 701, 456, 1348, 527, 309, 764, 676, 162, 260, 260, - 260, 260, 260, 260, 260, 456, 676, 527, 708, 260, - 309, 1349, 766, 764, 689, 260, 260, 260, 260, 260, - 260, 262, 262, 262, 262, 262, 262, 262, 588, 689, - 766, 456, 262, 527, 708, 749, 761, 588, 262, 262, - 262, 262, 262, 262, 263, 263, 263, 263, 263, 263, - - 263, 263, 265, 265, 265, 265, 265, 265, 265, 674, - 805, 749, 761, 265, 1355, 1356, 1363, 772, 674, 265, - 265, 265, 265, 265, 265, 268, 268, 268, 268, 268, - 268, 268, 268, 731, 742, 772, 805, 268, 1364, 1371, - 772, 731, 742, 268, 268, 268, 268, 268, 268, 270, - 270, 270, 270, 270, 270, 270, 270, 273, 273, 273, - 273, 273, 273, 273, 273, 273, 859, 1372, 1379, 273, - 1380, 273, 1384, 1387, 859, 273, 273, 273, 273, 273, - 273, 365, 365, 365, 365, 365, 365, 365, 436, 436, - 436, 436, 436, 436, 436, 554, 683, 273, 278, 278, - - 278, 278, 278, 278, 278, 278, 278, 683, 1388, 554, - 278, 1392, 765, 779, 1394, 681, 278, 278, 278, 278, - 278, 278, 279, 279, 279, 279, 279, 279, 279, 681, - 765, 779, 685, 279, 555, 554, 779, 765, 1413, 279, - 279, 279, 279, 279, 279, 344, 685, 344, 555, 344, - 344, 464, 464, 464, 464, 464, 464, 464, 773, 344, - 690, 344, 344, 558, 344, 349, 559, 349, 349, 349, - 349, 349, 349, 349, 555, 690, 773, 558, 349, 773, - 559, 776, 1414, 787, 349, 349, 349, 349, 349, 349, - 350, 350, 350, 350, 350, 350, 350, 350, 1424, 776, - - 776, 787, 350, 558, 350, 1425, 559, 1429, 350, 350, - 350, 350, 350, 350, 468, 468, 468, 468, 468, 468, - 468, 540, 540, 540, 540, 540, 540, 540, 638, 688, - 350, 352, 352, 352, 352, 352, 352, 352, 352, 688, - 1430, 1434, 638, 352, 1437, 783, 774, 788, 639, 352, - 352, 352, 352, 352, 352, 356, 356, 356, 356, 356, - 356, 356, 639, 783, 774, 788, 356, 774, 638, 784, - 783, 790, 356, 356, 356, 356, 356, 356, 357, 357, - 357, 357, 357, 357, 357, 357, 1438, 784, 639, 790, - 357, 808, 784, 811, 817, 1443, 357, 357, 357, 357, - - 357, 357, 358, 358, 358, 358, 358, 358, 358, 358, - 360, 360, 360, 360, 360, 360, 360, 808, 917, 811, - 817, 360, 1446, 791, 789, 795, 917, 360, 360, 360, - 360, 360, 360, 364, 364, 364, 364, 364, 364, 364, - 364, 791, 789, 795, 364, 789, 824, 797, 797, 1447, - 364, 364, 364, 364, 364, 364, 366, 366, 366, 366, - 366, 366, 366, 366, 366, 797, 836, 839, 366, 851, - 866, 867, 824, 1452, 366, 366, 366, 366, 366, 366, - 367, 367, 367, 367, 367, 367, 367, 367, 866, 867, - 892, 367, 836, 839, 867, 851, 868, 367, 367, 367, - - 367, 367, 367, 373, 373, 373, 373, 373, 373, 373, - 373, 373, 1455, 1456, 868, 373, 892, 1461, 879, 868, - 869, 373, 373, 373, 373, 373, 373, 375, 375, 375, - 375, 375, 375, 375, 375, 375, 879, 879, 869, 375, - 692, 375, 1464, 869, 693, 375, 375, 375, 375, 375, - 375, 490, 646, 490, 692, 696, 490, 490, 693, 647, - 490, 490, 699, 928, 700, 490, 646, 375, 396, 696, - 1465, 928, 396, 647, 700, 396, 699, 650, 396, 651, - 396, 396, 396, 396, 430, 430, 430, 430, 430, 430, - 430, 650, 646, 651, 1473, 430, 780, 871, 873, 647, - - 1502, 430, 430, 430, 430, 430, 430, 432, 432, 432, - 432, 432, 432, 432, 780, 871, 873, 650, 432, 651, - 871, 873, 948, 780, 432, 432, 432, 432, 432, 432, - 433, 433, 433, 433, 433, 433, 433, 433, 435, 435, - 435, 435, 435, 435, 435, 1503, 1528, 1531, 948, 435, - 1555, 781, 880, 874, 888, 435, 435, 435, 435, 435, - 435, 438, 438, 438, 438, 438, 438, 438, 438, 781, - 880, 874, 888, 438, 1559, 438, 874, 880, 781, 438, - 438, 438, 438, 438, 438, 545, 545, 545, 545, 545, - 545, 545, 549, 549, 549, 549, 549, 549, 549, 767, - - 752, 438, 440, 440, 440, 440, 440, 440, 440, 960, - 940, 993, 996, 440, 752, 883, 1563, 767, 940, 440, - 440, 440, 440, 440, 440, 441, 441, 441, 441, 441, - 441, 441, 1567, 883, 767, 960, 441, 993, 996, 999, - 752, 883, 441, 441, 441, 441, 441, 441, 442, 442, - 442, 442, 442, 442, 442, 442, 445, 445, 445, 445, - 445, 445, 445, 445, 445, 999, 1571, 1591, 445, 1002, - 445, 1600, 1275, 1271, 445, 445, 445, 445, 445, 445, - 658, 658, 658, 658, 658, 658, 658, 660, 660, 660, - 660, 660, 660, 660, 973, 1002, 445, 451, 451, 451, - - 451, 451, 451, 451, 451, 451, 1066, 1270, 1269, 451, - 1265, 451, 973, 973, 1066, 451, 451, 451, 451, 451, - 451, 664, 664, 664, 664, 664, 664, 664, 724, 724, - 724, 724, 724, 724, 724, 753, 768, 451, 457, 457, - 457, 457, 457, 457, 457, 457, 457, 1264, 1261, 753, - 457, 1008, 1257, 1015, 768, 886, 457, 457, 457, 457, - 457, 457, 459, 459, 459, 459, 459, 459, 459, 459, - 459, 768, 1256, 886, 459, 753, 459, 1008, 886, 1015, - 459, 459, 459, 459, 459, 459, 729, 729, 729, 729, - 729, 729, 729, 733, 733, 733, 733, 733, 733, 733, - - 756, 769, 459, 469, 469, 469, 469, 469, 469, 469, - 469, 469, 1255, 1027, 756, 469, 1251, 975, 1250, 769, - 757, 469, 469, 469, 469, 469, 469, 470, 470, 470, - 470, 470, 470, 470, 757, 975, 769, 1247, 470, 1027, - 756, 785, 975, 876, 470, 470, 470, 470, 470, 470, - 521, 819, 521, 521, 521, 521, 521, 521, 521, 785, - 757, 876, 1244, 521, 876, 819, 972, 967, 785, 521, - 521, 521, 521, 521, 521, 522, 522, 522, 522, 522, - 522, 522, 522, 1243, 972, 967, 1242, 522, 967, 522, - 1238, 819, 972, 522, 522, 522, 522, 522, 522, 738, - - 738, 738, 738, 738, 738, 738, 740, 740, 740, 740, - 740, 740, 740, 771, 777, 522, 524, 524, 524, 524, - 524, 524, 524, 524, 1030, 1124, 1237, 1042, 524, 1046, - 1058, 771, 777, 1124, 524, 524, 524, 524, 524, 524, - 528, 528, 528, 528, 528, 528, 528, 528, 771, 1135, - 1030, 777, 528, 1042, 1114, 1046, 1058, 1135, 528, 528, - 528, 528, 528, 528, 529, 529, 529, 529, 529, 529, - 529, 529, 530, 530, 530, 530, 530, 530, 530, 1147, - 1114, 1234, 1233, 530, 1167, 1179, 1208, 1147, 1232, 530, - 530, 530, 530, 530, 530, 531, 531, 531, 531, 531, - - 531, 531, 531, 533, 533, 533, 533, 533, 533, 533, - 1167, 1179, 1208, 1211, 533, 1228, 1226, 970, 974, 977, - 533, 533, 533, 533, 533, 533, 534, 534, 534, 534, - 534, 534, 534, 534, 534, 970, 974, 977, 534, 1211, - 970, 974, 977, 820, 534, 534, 534, 534, 534, 534, - 535, 535, 535, 535, 535, 535, 535, 820, 1159, 1225, - 1214, 535, 1222, 976, 978, 1221, 1159, 535, 535, 535, - 535, 535, 535, 539, 539, 539, 539, 539, 539, 539, - 539, 976, 978, 820, 539, 978, 1214, 979, 981, 976, - 539, 539, 539, 539, 539, 539, 541, 541, 541, 541, - - 541, 541, 541, 541, 541, 979, 981, 979, 541, 1218, - 983, 981, 984, 1215, 541, 541, 541, 541, 541, 541, - 542, 542, 542, 542, 542, 542, 542, 542, 983, 1212, - 984, 542, 1209, 1205, 985, 989, 1076, 542, 542, 542, - 542, 542, 542, 550, 550, 550, 550, 550, 550, 550, - 550, 550, 985, 989, 1076, 550, 1181, 1079, 1082, 1083, - 1180, 550, 550, 550, 550, 550, 550, 551, 551, 551, - 551, 551, 551, 551, 551, 1079, 1082, 1083, 551, 1079, - 1082, 1084, 1083, 1087, 551, 551, 551, 551, 551, 551, - 560, 560, 560, 560, 560, 560, 560, 560, 560, 1084, - - 1177, 1087, 560, 1217, 1220, 1088, 1087, 1173, 560, 560, - 560, 560, 560, 560, 562, 562, 562, 562, 562, 562, - 562, 562, 562, 1088, 1172, 1088, 562, 1169, 562, 1217, - 1220, 1164, 562, 562, 562, 562, 562, 562, 744, 744, - 744, 744, 744, 744, 744, 750, 750, 750, 750, 750, - 750, 750, 872, 778, 562, 613, 613, 613, 613, 613, - 613, 613, 1245, 1163, 1259, 1273, 613, 1319, 1092, 1160, - 872, 778, 613, 613, 613, 613, 613, 613, 615, 615, - 615, 615, 615, 615, 615, 778, 1092, 872, 1245, 615, - 1259, 1273, 1092, 1319, 1152, 615, 615, 615, 615, 615, - - 615, 616, 616, 616, 616, 616, 616, 616, 616, 618, - 618, 618, 618, 618, 618, 618, 1291, 1151, 1148, 1382, - 618, 1432, 882, 1090, 1291, 1093, 618, 618, 618, 618, - 618, 618, 620, 620, 620, 620, 620, 620, 620, 620, - 882, 1090, 1090, 1093, 620, 1382, 1093, 1432, 1441, 882, - 620, 620, 620, 620, 620, 620, 621, 621, 621, 621, - 621, 621, 621, 621, 622, 622, 622, 622, 622, 622, - 622, 1347, 1354, 1140, 1441, 622, 1139, 1136, 1129, 1347, - 1354, 622, 622, 622, 622, 622, 622, 623, 623, 623, - 623, 623, 623, 623, 623, 626, 626, 626, 626, 626, - - 626, 626, 626, 626, 770, 884, 827, 626, 782, 626, - 786, 1182, 1186, 626, 626, 626, 626, 626, 626, 1362, - 827, 1128, 770, 884, 1125, 1120, 782, 1362, 786, 1182, - 1186, 775, 884, 792, 770, 626, 629, 629, 629, 629, - 629, 629, 629, 629, 629, 782, 827, 786, 629, 775, - 629, 792, 1370, 1182, 629, 629, 629, 629, 629, 629, - 1370, 775, 1119, 1116, 792, 799, 799, 799, 799, 799, - 799, 799, 793, 828, 831, 1450, 629, 635, 635, 635, - 635, 635, 635, 635, 635, 635, 1183, 828, 831, 635, - 793, 635, 832, 842, 843, 635, 635, 635, 635, 635, - - 635, 1450, 793, 1378, 1183, 1459, 832, 842, 843, 1184, - 1115, 1378, 1112, 828, 831, 846, 1111, 635, 640, 640, - 640, 640, 640, 640, 640, 640, 640, 1184, 1183, 846, - 640, 1459, 832, 842, 843, 1189, 640, 640, 640, 640, - 640, 640, 642, 642, 642, 642, 642, 642, 642, 642, - 642, 1184, 1108, 1189, 642, 846, 642, 1105, 1189, 847, - 642, 642, 642, 642, 642, 642, 840, 840, 840, 840, - 840, 840, 840, 847, 855, 855, 855, 855, 855, 855, - 855, 1102, 642, 652, 652, 652, 652, 652, 652, 652, - 652, 652, 1423, 1098, 1526, 652, 1553, 1557, 1185, 847, - - 1423, 652, 652, 652, 652, 652, 652, 654, 654, 654, - 654, 654, 654, 654, 654, 654, 1185, 1071, 1185, 654, - 1526, 654, 1553, 1557, 1067, 654, 654, 654, 654, 654, - 654, 857, 857, 857, 857, 857, 857, 857, 861, 861, - 861, 861, 861, 861, 861, 878, 870, 654, 665, 665, - 665, 665, 665, 665, 665, 665, 665, 1472, 1060, 1059, - 665, 1056, 1561, 878, 870, 1472, 665, 665, 665, 665, - 665, 665, 666, 666, 666, 666, 666, 666, 666, 870, - 878, 1052, 1051, 666, 887, 875, 877, 885, 1561, 666, - 666, 666, 666, 666, 666, 669, 669, 669, 669, 669, - - 669, 669, 887, 875, 877, 885, 669, 966, 1078, 951, - 963, 881, 669, 669, 669, 669, 669, 669, 875, 877, - 1565, 887, 885, 951, 1532, 966, 1078, 952, 963, 881, - 669, 704, 1532, 704, 704, 704, 704, 704, 704, 704, - 881, 952, 966, 963, 704, 1078, 1565, 964, 1048, 951, - 704, 704, 704, 704, 704, 704, 910, 910, 910, 910, - 910, 910, 910, 955, 956, 964, 968, 952, 704, 705, - 705, 705, 705, 705, 705, 705, 705, 955, 956, 1044, - 964, 705, 1190, 1298, 968, 968, 1043, 705, 705, 705, - 705, 705, 705, 915, 915, 915, 915, 915, 915, 915, - - 1190, 1298, 968, 955, 956, 705, 706, 706, 706, 706, - 706, 706, 706, 919, 919, 919, 919, 919, 919, 919, - 924, 924, 924, 924, 924, 924, 924, 926, 926, 926, - 926, 926, 926, 926, 930, 930, 930, 930, 930, 930, - 930, 706, 707, 707, 707, 707, 707, 707, 707, 1040, - 1036, 1035, 1032, 707, 1029, 1569, 1589, 1598, 1028, 707, - 707, 707, 707, 707, 707, 709, 709, 709, 709, 709, - 709, 709, 709, 711, 711, 711, 711, 711, 711, 711, - 711, 1569, 1589, 1598, 1025, 711, 1021, 1020, 1017, 1016, - 1013, 711, 711, 711, 711, 711, 711, 712, 712, 712, - - 712, 712, 712, 712, 712, 714, 714, 714, 714, 714, - 714, 714, 1009, 1005, 1004, 1003, 714, 1000, 997, 1201, - 1202, 1187, 714, 714, 714, 714, 714, 714, 715, 715, - 715, 715, 715, 715, 715, 715, 715, 1201, 1202, 1187, - 715, 1201, 994, 1202, 1299, 1010, 715, 715, 715, 715, - 715, 715, 716, 716, 716, 716, 716, 716, 716, 1010, - 1187, 991, 1299, 716, 990, 962, 1300, 961, 1301, 716, - 716, 716, 716, 716, 716, 718, 718, 718, 718, 718, - 718, 718, 718, 718, 1300, 1010, 1301, 718, 958, 1192, - 1302, 1310, 1011, 718, 718, 718, 718, 718, 718, 719, - - 719, 719, 719, 719, 719, 719, 1011, 1192, 1302, 1310, - 719, 954, 1307, 1302, 1310, 1192, 719, 719, 719, 719, - 719, 719, 723, 723, 723, 723, 723, 723, 723, 723, - 1307, 953, 1011, 723, 950, 945, 941, 1314, 1315, 723, - 723, 723, 723, 723, 723, 725, 725, 725, 725, 725, - 725, 725, 725, 725, 1307, 1314, 1315, 725, 933, 929, - 1396, 1397, 922, 725, 725, 725, 725, 725, 725, 726, - 726, 726, 726, 726, 726, 726, 726, 1315, 1396, 1397, - 726, 1396, 1397, 1398, 1399, 1401, 726, 726, 726, 726, - 726, 726, 734, 734, 734, 734, 734, 734, 734, 734, - - 734, 1398, 1399, 1401, 734, 918, 1399, 913, 1402, 908, - 734, 734, 734, 734, 734, 734, 735, 735, 735, 735, - 735, 735, 735, 735, 907, 1398, 1402, 735, 906, 903, - 1402, 1403, 1404, 735, 735, 735, 735, 735, 735, 745, - 745, 745, 745, 745, 745, 745, 745, 745, 900, 1403, - 1404, 745, 896, 1403, 1406, 1409, 1404, 745, 745, 745, - 745, 745, 745, 746, 746, 746, 746, 746, 746, 746, - 746, 864, 1406, 1409, 746, 860, 1406, 1477, 1409, 1478, - 746, 746, 746, 746, 746, 746, 758, 758, 758, 758, - 758, 758, 758, 758, 758, 1477, 853, 1478, 758, 852, - - 849, 1488, 845, 1477, 758, 758, 758, 758, 758, 758, - 760, 760, 760, 760, 760, 760, 760, 760, 760, 1488, - 1488, 844, 760, 841, 760, 838, 837, 834, 760, 760, - 760, 760, 760, 760, 936, 936, 936, 936, 936, 936, - 936, 938, 938, 938, 938, 938, 938, 938, 1018, 969, - 760, 794, 1019, 794, 794, 794, 794, 794, 794, 794, - 830, 829, 1018, 826, 794, 825, 1019, 969, 1081, 794, - 794, 794, 794, 794, 794, 794, 796, 796, 796, 796, - 796, 796, 796, 969, 822, 818, 1081, 796, 1018, 1534, - 1491, 1536, 1019, 796, 796, 796, 796, 796, 796, 798, - - 798, 798, 798, 798, 798, 798, 1081, 1534, 1491, 1536, - 798, 1491, 1303, 1537, 1544, 1548, 798, 798, 798, 798, - 798, 798, 800, 800, 800, 800, 800, 800, 800, 800, - 1303, 1537, 1544, 1548, 800, 815, 1537, 1544, 814, 1303, - 800, 800, 800, 800, 800, 800, 801, 801, 801, 801, - 801, 801, 801, 801, 804, 804, 804, 804, 804, 804, - 804, 804, 804, 813, 812, 809, 804, 806, 804, 803, - 802, 763, 804, 804, 804, 804, 804, 804, 942, 942, - 942, 942, 942, 942, 942, 949, 949, 949, 949, 949, - 949, 949, 965, 971, 804, 807, 807, 807, 807, 807, - - 807, 807, 807, 807, 1073, 1074, 1022, 807, 762, 807, - 965, 971, 1479, 807, 807, 807, 807, 807, 807, 759, - 1022, 755, 1073, 1074, 754, 965, 965, 982, 971, 980, - 1479, 1077, 751, 1073, 1074, 807, 810, 810, 810, 810, - 810, 810, 810, 810, 810, 982, 1022, 980, 810, 1077, - 810, 1479, 1023, 747, 810, 810, 810, 810, 810, 810, - 980, 1033, 982, 1077, 743, 736, 1023, 1031, 1031, 1031, - 1031, 1031, 1031, 1031, 1034, 1033, 810, 816, 816, 816, - 816, 816, 816, 816, 816, 816, 1576, 1075, 1034, 816, - 732, 816, 1023, 1037, 1038, 816, 816, 816, 816, 816, - - 816, 1033, 727, 722, 1576, 1075, 721, 1037, 1038, 720, - 1541, 717, 713, 1049, 1034, 1050, 1075, 816, 821, 821, - 821, 821, 821, 821, 821, 821, 821, 1049, 1541, 1050, - 821, 703, 702, 1037, 1038, 698, 821, 821, 821, 821, - 821, 821, 823, 823, 823, 823, 823, 823, 823, 823, - 823, 1541, 697, 1049, 823, 1050, 823, 1085, 1196, 1053, - 823, 823, 823, 823, 823, 823, 1047, 1047, 1047, 1047, - 1047, 1047, 1047, 1053, 695, 1085, 1196, 694, 1054, 1410, - 1197, 677, 823, 833, 833, 833, 833, 833, 833, 833, - 833, 833, 1054, 1196, 1085, 833, 667, 1410, 1197, 1053, - - 663, 833, 833, 833, 833, 833, 833, 835, 835, 835, - 835, 835, 835, 835, 835, 835, 1197, 1410, 1054, 835, - 657, 835, 656, 653, 649, 835, 835, 835, 835, 835, - 835, 1062, 1062, 1062, 1062, 1062, 1062, 1062, 1064, 1064, - 1064, 1064, 1064, 1064, 1064, 1170, 1094, 835, 848, 848, - 848, 848, 848, 848, 848, 848, 848, 648, 645, 1170, - 848, 644, 641, 637, 1094, 1094, 848, 848, 848, 848, - 848, 848, 850, 850, 850, 850, 850, 850, 850, 850, - 850, 1094, 1094, 634, 850, 1170, 850, 1587, 1486, 1086, - 850, 850, 850, 850, 850, 850, 1068, 1068, 1068, 1068, - - 1068, 1068, 1068, 633, 632, 1587, 1486, 1086, 1200, 1171, - 1174, 631, 850, 862, 862, 862, 862, 862, 862, 862, - 862, 862, 1086, 1171, 1174, 862, 1200, 1486, 1612, 1080, - 1175, 862, 862, 862, 862, 862, 862, 863, 863, 863, - 863, 863, 863, 863, 1175, 1200, 1612, 1080, 863, 1171, - 1174, 1578, 628, 1579, 863, 863, 863, 863, 863, 863, - 889, 1080, 889, 889, 889, 889, 889, 889, 889, 1578, - 1175, 1579, 1578, 889, 1579, 1620, 1580, 1628, 889, 889, - 889, 889, 889, 889, 889, 890, 890, 890, 890, 890, - 890, 890, 625, 1620, 1580, 1628, 890, 1580, 1411, 1089, - - 1585, 1091, 890, 890, 890, 890, 890, 890, 891, 891, - 891, 891, 891, 891, 891, 891, 1411, 1089, 1585, 1091, - 891, 1585, 891, 624, 617, 1411, 891, 891, 891, 891, - 891, 891, 1089, 1091, 1117, 1117, 1117, 1117, 1117, 1117, - 1117, 1122, 1122, 1122, 1122, 1122, 1122, 1122, 891, 893, - 893, 893, 893, 893, 893, 893, 614, 612, 608, 602, - 893, 601, 1476, 1605, 1607, 1608, 893, 893, 893, 893, - 893, 893, 894, 894, 894, 894, 894, 894, 894, 894, - 1476, 1605, 1607, 1608, 894, 1605, 600, 1607, 1608, 1476, - 894, 894, 894, 894, 894, 894, 895, 895, 895, 895, - - 895, 895, 895, 895, 897, 897, 897, 897, 897, 897, - 897, 599, 595, 594, 592, 897, 591, 590, 1633, 1634, - 1622, 897, 897, 897, 897, 897, 897, 898, 898, 898, - 898, 898, 898, 898, 898, 898, 1633, 1634, 1622, 898, - 589, 585, 1634, 1635, 1229, 898, 898, 898, 898, 898, - 898, 899, 899, 899, 899, 899, 899, 899, 1229, 1622, - 584, 1635, 899, 583, 582, 1636, 1635, 1623, 899, 899, - 899, 899, 899, 899, 901, 901, 901, 901, 901, 901, - 901, 901, 901, 1636, 1229, 1623, 901, 581, 1636, 1638, - 1640, 1230, 901, 901, 901, 901, 901, 901, 902, 902, - - 902, 902, 902, 902, 902, 1230, 1623, 1638, 1640, 902, - 580, 579, 1638, 578, 1624, 902, 902, 902, 902, 902, - 902, 904, 904, 904, 904, 904, 904, 904, 904, 904, - 577, 1230, 1624, 904, 576, 575, 1645, 1647, 1235, 904, - 904, 904, 904, 904, 904, 905, 905, 905, 905, 905, - 905, 905, 1235, 1624, 1645, 1647, 905, 1645, 1649, 1647, - 574, 573, 905, 905, 905, 905, 905, 905, 909, 909, - 909, 909, 909, 909, 909, 909, 1649, 572, 1235, 909, - 569, 1649, 1651, 1652, 1657, 909, 909, 909, 909, 909, - 909, 911, 911, 911, 911, 911, 911, 911, 911, 911, - - 1651, 1652, 1657, 911, 568, 1651, 1653, 567, 565, 911, - 911, 911, 911, 911, 911, 912, 912, 912, 912, 912, - 912, 912, 912, 1657, 1653, 1652, 912, 564, 561, 1660, - 556, 1664, 912, 912, 912, 912, 912, 912, 920, 920, - 920, 920, 920, 920, 920, 920, 920, 1660, 1653, 1664, - 920, 552, 1660, 1668, 1669, 548, 920, 920, 920, 920, - 920, 920, 921, 921, 921, 921, 921, 921, 921, 921, - 543, 1668, 1669, 921, 538, 537, 1668, 1669, 1674, 921, - 921, 921, 921, 921, 921, 931, 931, 931, 931, 931, - 931, 931, 931, 931, 536, 532, 1674, 931, 526, 1675, - - 1677, 1674, 525, 931, 931, 931, 931, 931, 931, 932, - 932, 932, 932, 932, 932, 932, 932, 1675, 1677, 520, - 932, 1675, 519, 1679, 1682, 1683, 932, 932, 932, 932, - 932, 932, 943, 943, 943, 943, 943, 943, 943, 943, - 943, 1679, 1682, 1683, 943, 1682, 1679, 1684, 1689, 518, - 943, 943, 943, 943, 943, 943, 944, 944, 944, 944, - 944, 944, 944, 944, 517, 1684, 1689, 944, 516, 515, - 1694, 1689, 1698, 944, 944, 944, 944, 944, 944, 957, - 957, 957, 957, 957, 957, 957, 957, 957, 1694, 1684, - 1698, 957, 514, 513, 1700, 1698, 1703, 957, 957, 957, - - 957, 957, 957, 959, 959, 959, 959, 959, 959, 959, - 959, 959, 1700, 512, 1703, 959, 511, 959, 510, 509, - 508, 959, 959, 959, 959, 959, 959, 1126, 1126, 1126, - 1126, 1126, 1126, 1126, 1131, 1131, 1131, 1131, 1131, 1131, - 1131, 1710, 1712, 959, 986, 986, 986, 986, 986, 986, - 986, 986, 986, 506, 503, 502, 501, 986, 500, 1710, - 1712, 499, 986, 986, 986, 986, 986, 986, 986, 987, - 987, 987, 987, 987, 987, 987, 987, 988, 988, 988, - 988, 988, 988, 988, 988, 988, 1133, 1133, 1133, 1133, - 1133, 1133, 1133, 1701, 1714, 988, 992, 992, 992, 992, - - 992, 992, 992, 992, 992, 498, 497, 495, 992, 494, - 992, 1701, 1714, 493, 992, 992, 992, 992, 992, 992, - 1137, 1137, 1137, 1137, 1137, 1137, 1137, 1143, 1143, 1143, - 1143, 1143, 1143, 1143, 1706, 1701, 992, 995, 995, 995, - 995, 995, 995, 995, 995, 995, 492, 491, 489, 995, - 487, 995, 1706, 485, 484, 995, 995, 995, 995, 995, - 995, 1145, 1145, 1145, 1145, 1145, 1145, 1145, 1149, 1149, - 1149, 1149, 1149, 1149, 1149, 1719, 1706, 995, 998, 998, - 998, 998, 998, 998, 998, 998, 998, 483, 482, 481, - 998, 479, 998, 1719, 478, 476, 998, 998, 998, 998, - - 998, 998, 1155, 1155, 1155, 1155, 1155, 1155, 1155, 1157, - 1157, 1157, 1157, 1157, 1157, 1157, 1721, 1724, 998, 1001, - 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 475, 474, - 471, 1001, 467, 1001, 1721, 1724, 463, 1001, 1001, 1001, - 1001, 1001, 1001, 1161, 1161, 1161, 1161, 1161, 1161, 1161, - 1168, 1168, 1168, 1168, 1168, 1168, 1168, 462, 461, 1001, - 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 458, 454, - 453, 1006, 450, 449, 448, 1191, 1194, 1006, 1006, 1006, - 1006, 1006, 1006, 1007, 1007, 1007, 1007, 1007, 1007, 1007, - 1007, 1007, 1188, 1191, 1194, 1007, 1543, 1007, 1198, 1236, - - 1308, 1007, 1007, 1007, 1007, 1007, 1007, 1194, 1191, 447, - 1188, 444, 443, 1236, 1543, 434, 1198, 1709, 1308, 431, - 429, 1188, 428, 1007, 1012, 1012, 1012, 1012, 1012, 1012, - 1012, 1012, 1012, 1198, 1543, 1709, 1012, 1308, 1709, 1236, - 1195, 1199, 1012, 1012, 1012, 1012, 1012, 1012, 1014, 1014, - 1014, 1014, 1014, 1014, 1014, 1014, 1014, 1193, 1195, 1199, - 1014, 427, 1014, 426, 425, 1309, 1014, 1014, 1014, 1014, - 1014, 1014, 1195, 1199, 424, 1193, 1223, 1223, 1223, 1223, - 1223, 1223, 1223, 1309, 1239, 1311, 1193, 423, 1014, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1239, 422, - - 1309, 1024, 421, 1311, 420, 1203, 419, 1024, 1024, 1024, - 1024, 1024, 1024, 1026, 1026, 1026, 1026, 1026, 1026, 1026, - 1026, 1026, 1311, 1203, 1239, 1026, 418, 1026, 1240, 417, - 416, 1026, 1026, 1026, 1026, 1026, 1026, 1203, 414, 412, - 411, 409, 1240, 1246, 1246, 1246, 1246, 1246, 1246, 1246, - 408, 1248, 1313, 1026, 1039, 1039, 1039, 1039, 1039, 1039, - 1039, 1039, 1039, 405, 404, 1248, 1039, 402, 1240, 400, - 1313, 399, 1039, 1039, 1039, 1039, 1039, 1039, 1041, 1041, - 1041, 1041, 1041, 1041, 1041, 1041, 1041, 1313, 1249, 1252, - 1041, 1248, 1041, 1253, 398, 393, 1041, 1041, 1041, 1041, - - 1041, 1041, 1249, 1252, 392, 391, 389, 1253, 1260, 1260, - 1260, 1260, 1260, 1260, 1260, 388, 1262, 1395, 1041, 1055, - 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1055, 1249, 1252, - 1262, 1055, 387, 1253, 386, 1395, 384, 1055, 1055, 1055, - 1055, 1055, 1055, 1057, 1057, 1057, 1057, 1057, 1057, 1057, - 1057, 1057, 1395, 1263, 1266, 1057, 1262, 1057, 1267, 379, - 378, 1057, 1057, 1057, 1057, 1057, 1057, 1263, 1266, 377, - 374, 370, 1267, 1274, 1274, 1274, 1274, 1274, 1274, 1274, - 368, 1276, 1489, 1057, 1069, 1069, 1069, 1069, 1069, 1069, - 1069, 1069, 1069, 1263, 1266, 1276, 1069, 363, 1267, 362, - - 1489, 1277, 1069, 1069, 1069, 1069, 1069, 1069, 1070, 1070, - 1070, 1070, 1070, 1070, 1070, 1277, 359, 1489, 354, 1070, - 353, 1276, 1707, 345, 1713, 1070, 1070, 1070, 1070, 1070, - 1070, 1095, 1095, 1095, 1095, 1095, 1095, 1095, 1095, 1095, - 1707, 1277, 1713, 343, 1095, 1707, 342, 1713, 337, 1095, - 1095, 1095, 1095, 1095, 1095, 1095, 1096, 1096, 1096, 1096, - 1096, 1096, 1096, 1096, 1097, 1097, 1097, 1097, 1097, 1097, - 1097, 1097, 1097, 335, 1725, 1726, 1280, 1281, 1727, 1306, - 333, 1337, 1097, 1099, 1099, 1099, 1099, 1099, 1099, 1099, - 1280, 1281, 1725, 1726, 1099, 1337, 1727, 1306, 1306, 332, - - 1099, 1099, 1099, 1099, 1099, 1099, 1100, 1100, 1100, 1100, - 1100, 1100, 1100, 1100, 1100, 1306, 1280, 1281, 1100, 331, - 330, 1337, 329, 1338, 1100, 1100, 1100, 1100, 1100, 1100, - 1101, 1101, 1101, 1101, 1101, 1101, 1101, 1338, 328, 327, - 325, 1101, 324, 323, 318, 315, 1687, 1101, 1101, 1101, - 1101, 1101, 1101, 1103, 1103, 1103, 1103, 1103, 1103, 1103, - 1103, 1103, 314, 1338, 1687, 1103, 313, 310, 303, 302, - 1385, 1103, 1103, 1103, 1103, 1103, 1103, 1104, 1104, 1104, - 1104, 1104, 1104, 1104, 1385, 1687, 300, 299, 1104, 298, - 296, 294, 293, 1718, 1104, 1104, 1104, 1104, 1104, 1104, - - 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 292, - 1385, 1718, 1106, 290, 286, 285, 283, 1386, 1106, 1106, - 1106, 1106, 1106, 1106, 1107, 1107, 1107, 1107, 1107, 1107, - 1107, 1386, 1718, 280, 276, 1107, 275, 272, 271, 269, - 264, 1107, 1107, 1107, 1107, 1107, 1107, 1109, 1109, 1109, - 1109, 1109, 1109, 1109, 1109, 1109, 261, 1386, 259, 1109, - 258, 256, 253, 249, 1389, 1109, 1109, 1109, 1109, 1109, - 1109, 1110, 1110, 1110, 1110, 1110, 1110, 1110, 1389, 245, - 243, 241, 1110, 240, 238, 237, 236, 235, 1110, 1110, - 1110, 1110, 1110, 1110, 1113, 1113, 1113, 1113, 1113, 1113, - - 1113, 1113, 1113, 234, 1389, 233, 1113, 232, 1113, 230, - 228, 226, 1113, 1113, 1113, 1113, 1113, 1113, 1287, 1287, - 1287, 1287, 1287, 1287, 1287, 1289, 1289, 1289, 1289, 1289, - 1289, 1289, 1312, 225, 1113, 1118, 1118, 1118, 1118, 1118, - 1118, 1118, 1118, 1118, 223, 221, 220, 1118, 218, 215, - 1312, 1312, 214, 1118, 1118, 1118, 1118, 1118, 1118, 1127, - 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1312, 213, - 211, 1127, 209, 208, 205, 204, 202, 1127, 1127, 1127, - 1127, 1127, 1127, 1138, 1138, 1138, 1138, 1138, 1138, 1138, - 1138, 1138, 201, 200, 199, 1138, 198, 197, 196, 195, - - 194, 1138, 1138, 1138, 1138, 1138, 1138, 1150, 1150, 1150, - 1150, 1150, 1150, 1150, 1150, 1150, 193, 192, 191, 1150, - 190, 189, 188, 187, 186, 1150, 1150, 1150, 1150, 1150, - 1150, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, - 185, 183, 182, 1162, 179, 178, 177, 176, 175, 1162, - 1162, 1162, 1162, 1162, 1162, 1176, 1176, 1176, 1176, 1176, - 1176, 1176, 1176, 1176, 174, 173, 172, 1176, 170, 167, - 166, 165, 164, 1176, 1176, 1176, 1176, 1176, 1176, 1178, - 1178, 1178, 1178, 1178, 1178, 1178, 1178, 1178, 161, 159, - 150, 1178, 149, 1178, 1475, 1535, 1390, 1178, 1178, 1178, - - 1178, 1178, 1178, 1293, 1293, 1293, 1293, 1293, 1293, 1293, - 1390, 1650, 1475, 1535, 148, 1546, 1304, 1316, 147, 1178, - 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1650, - 146, 1475, 1535, 1546, 1304, 1316, 1390, 1427, 1204, 1206, - 1206, 1206, 1206, 1206, 1206, 1206, 1206, 1304, 1316, 1650, - 1206, 1427, 1546, 145, 144, 1400, 1206, 1206, 1206, 1206, - 1206, 1206, 1207, 1207, 1207, 1207, 1207, 1207, 1207, 1207, - 1207, 1305, 1317, 1400, 1207, 142, 1207, 1427, 140, 139, - 1207, 1207, 1207, 1207, 1207, 1207, 137, 1400, 135, 1305, - 1317, 1345, 1345, 1345, 1345, 1345, 1345, 1345, 133, 132, - - 1305, 1317, 1207, 1210, 1210, 1210, 1210, 1210, 1210, 1210, - 1210, 1210, 131, 130, 128, 1210, 127, 1210, 126, 125, - 124, 1210, 1210, 1210, 1210, 1210, 1210, 1350, 1350, 1350, - 1350, 1350, 1350, 1350, 1352, 1352, 1352, 1352, 1352, 1352, - 1352, 123, 121, 1210, 1213, 1213, 1213, 1213, 1213, 1213, - 1213, 1213, 1213, 119, 118, 117, 1213, 116, 1213, 115, - 114, 113, 1213, 1213, 1213, 1213, 1213, 1213, 1358, 1358, - 1358, 1358, 1358, 1358, 1358, 1360, 1360, 1360, 1360, 1360, - 1360, 1360, 112, 111, 1213, 1216, 1216, 1216, 1216, 1216, - 1216, 1216, 1216, 1216, 109, 108, 101, 1216, 100, 1216, - - 99, 97, 96, 1216, 1216, 1216, 1216, 1216, 1216, 1366, - 1366, 1366, 1366, 1366, 1366, 1366, 1368, 1368, 1368, 1368, - 1368, 1368, 1368, 93, 92, 1216, 1219, 1219, 1219, 1219, - 1219, 1219, 1219, 1219, 1219, 91, 90, 89, 1219, 88, - 1219, 87, 86, 85, 1219, 1219, 1219, 1219, 1219, 1219, - 1374, 1374, 1374, 1374, 1374, 1374, 1374, 1376, 1376, 1376, - 1376, 1376, 1376, 1376, 1428, 1539, 1219, 1224, 1224, 1224, - 1224, 1224, 1224, 1224, 1224, 1224, 84, 82, 1428, 1224, - 81, 80, 79, 1539, 78, 1224, 1224, 1224, 1224, 1224, - 1224, 1231, 1231, 1231, 1231, 1231, 1231, 1231, 1231, 1231, - - 77, 1539, 76, 1231, 1428, 75, 74, 73, 72, 1231, - 1231, 1231, 1231, 1231, 1231, 1241, 1241, 1241, 1241, 1241, - 1241, 1241, 1241, 1241, 71, 70, 69, 1241, 67, 66, - 65, 51, 43, 1241, 1241, 1241, 1241, 1241, 1241, 1254, - 1254, 1254, 1254, 1254, 1254, 1254, 1254, 1254, 42, 40, - 18, 1254, 11, 8, 3, 0, 0, 1254, 1254, 1254, - 1254, 1254, 1254, 1268, 1268, 1268, 1268, 1268, 1268, 1268, - 1268, 1268, 0, 0, 0, 1268, 0, 0, 0, 0, - 0, 1268, 1268, 1268, 1268, 1268, 1268, 1282, 1282, 1282, - 1282, 1282, 1282, 1282, 1282, 1282, 0, 0, 0, 1282, - - 0, 0, 0, 0, 0, 1282, 1282, 1282, 1282, 1282, - 1282, 1294, 1294, 1294, 1294, 1294, 1294, 1294, 1294, 1294, - 0, 0, 0, 1294, 0, 0, 0, 0, 0, 1294, - 1294, 1294, 1294, 1294, 1294, 1318, 1318, 1318, 1318, 1318, - 1318, 1318, 1318, 1318, 0, 0, 0, 1318, 0, 1318, - 0, 0, 0, 1318, 1318, 1318, 1318, 1318, 1318, 1383, - 1383, 1383, 1383, 1383, 1383, 1383, 1421, 1421, 1421, 1421, - 1421, 1421, 1421, 1435, 1540, 1318, 1322, 1322, 1322, 1322, - 1322, 1322, 1322, 1322, 1322, 0, 0, 1435, 1322, 0, - 0, 0, 1540, 0, 1322, 1322, 1322, 1322, 1322, 1322, - - 1325, 1325, 1325, 1325, 1325, 1325, 1325, 1325, 1325, 0, - 1540, 0, 1325, 1435, 0, 0, 0, 0, 1325, 1325, - 1325, 1325, 1325, 1325, 1328, 1328, 1328, 1328, 1328, 1328, - 1328, 1328, 1328, 0, 0, 0, 1328, 0, 0, 0, - 0, 0, 1328, 1328, 1328, 1328, 1328, 1328, 1331, 1331, - 1331, 1331, 1331, 1331, 1331, 1331, 1331, 0, 0, 0, - 1331, 0, 0, 0, 0, 0, 1331, 1331, 1331, 1331, - 1331, 1331, 1334, 1334, 1334, 1334, 1334, 1334, 1334, 1334, - 1334, 0, 0, 0, 1334, 0, 0, 0, 0, 0, - 1334, 1334, 1334, 1334, 1334, 1334, 1339, 1339, 1339, 1339, - - 1339, 1339, 1339, 1339, 1339, 0, 0, 0, 1339, 0, - 0, 0, 1407, 0, 1339, 1339, 1339, 1339, 1339, 1339, - 1391, 1391, 1391, 1391, 1391, 1391, 1391, 1391, 1391, 1405, - 1407, 1408, 1391, 0, 1436, 0, 0, 0, 1391, 1391, - 1391, 1391, 1391, 1391, 1407, 1490, 0, 1405, 1436, 1408, - 1433, 1433, 1433, 1433, 1433, 1433, 1433, 0, 1405, 0, - 0, 1408, 1444, 1490, 1405, 1412, 1412, 1412, 1412, 1412, - 1412, 1412, 1412, 1412, 1436, 1490, 1444, 1412, 0, 0, - 0, 0, 1445, 1412, 1412, 1412, 1412, 1412, 1412, 1442, - 1442, 1442, 1442, 1442, 1442, 1442, 1445, 1453, 1454, 0, - - 0, 0, 1444, 1451, 1451, 1451, 1451, 1451, 1451, 1451, - 1462, 1453, 1454, 1460, 1460, 1460, 1460, 1460, 1460, 1460, - 1463, 0, 1445, 0, 1462, 1468, 1468, 1468, 1468, 1468, - 1468, 1468, 0, 1480, 1463, 1485, 1481, 1453, 1454, 1470, - 1470, 1470, 1470, 1470, 1470, 1470, 1482, 1483, 1484, 0, - 1462, 1480, 1487, 1485, 1481, 1500, 0, 1501, 1542, 1547, - 1463, 1603, 1480, 1481, 1482, 1483, 1484, 1485, 0, 1500, - 1487, 1501, 0, 1482, 1483, 1484, 1542, 1547, 0, 1603, - 0, 1487, 1506, 1506, 1506, 1506, 1506, 1506, 1506, 0, - 0, 0, 0, 1603, 1542, 1500, 1547, 1501, 1510, 1510, - - 1510, 1510, 1510, 1510, 1510, 1514, 1514, 1514, 1514, 1514, - 1514, 1514, 1518, 1518, 1518, 1518, 1518, 1518, 1518, 1522, - 1522, 1522, 1522, 1522, 1522, 1522, 1527, 1527, 1527, 1527, - 1527, 1527, 1527, 1529, 1530, 1538, 1545, 1549, 1551, 1551, - 1551, 1551, 1551, 1551, 1551, 0, 0, 1529, 1530, 0, - 0, 0, 0, 1538, 1545, 1549, 0, 0, 0, 0, - 0, 0, 1538, 1545, 1549, 1554, 1554, 1554, 1554, 1554, - 1554, 1554, 0, 1529, 1530, 1558, 1558, 1558, 1558, 1558, - 1558, 1558, 1562, 1562, 1562, 1562, 1562, 1562, 1562, 1566, - 1566, 1566, 1566, 1566, 1566, 1566, 1570, 1570, 1570, 1570, - - 1570, 1570, 1570, 1573, 1573, 1573, 1573, 1573, 1573, 1573, - 1577, 1581, 0, 1582, 1583, 1586, 1588, 1584, 1590, 1590, - 1590, 1590, 1590, 1590, 1590, 1601, 1609, 0, 1577, 1581, - 1581, 1582, 1583, 1586, 1588, 1584, 0, 0, 0, 0, - 0, 0, 1586, 1601, 1609, 1577, 1602, 1581, 1604, 1606, - 1582, 1583, 1584, 1588, 1599, 1599, 1599, 1599, 1599, 1599, - 1599, 1610, 1601, 1609, 1602, 1611, 1604, 1606, 1621, 1625, - 0, 1626, 1627, 1602, 1629, 1630, 1637, 1639, 0, 1610, - 1604, 1606, 1641, 1611, 0, 0, 1621, 1625, 1610, 1626, - 1627, 1642, 1629, 1630, 1637, 1639, 1639, 1611, 1625, 0, - - 1641, 1643, 1626, 1637, 1644, 1621, 1630, 1627, 0, 1642, - 1646, 1629, 1648, 1639, 1639, 1654, 1641, 1641, 0, 1643, - 1655, 0, 1644, 1665, 1656, 1658, 1642, 0, 1646, 0, - 1648, 1659, 1661, 1654, 0, 1662, 1643, 1663, 1655, 1644, - 0, 1665, 1656, 1658, 1648, 1646, 1656, 1655, 0, 1659, - 1661, 1666, 1654, 1662, 1658, 1663, 1663, 1667, 1656, 1656, - 1665, 1670, 1671, 1672, 1673, 0, 1659, 1676, 1661, 1666, - 1662, 1678, 1680, 1663, 0, 1667, 1681, 0, 1685, 1670, - 1671, 1672, 1673, 1666, 0, 1676, 1686, 0, 1670, 1678, - 1680, 1690, 1671, 0, 1681, 1667, 1685, 1673, 1672, 1676, - - 1688, 0, 1678, 1691, 1686, 1680, 1692, 1693, 0, 1690, - 1685, 1681, 1696, 1695, 1697, 1699, 0, 0, 1688, 1686, - 1686, 1691, 1702, 0, 1692, 1693, 1690, 1704, 1708, 1688, - 1696, 1695, 1697, 1699, 1693, 1691, 1705, 1711, 1716, 0, - 1702, 1696, 1699, 1692, 1695, 1704, 1708, 1715, 1720, 1717, - 1722, 0, 1697, 0, 1705, 1711, 1716, 1702, 0, 0, - 0, 0, 0, 1708, 1704, 1715, 1720, 1717, 1722, 0, - 0, 0, 1705, 0, 1711, 1716, 1717, 1723, 0, 0, - 1723, 1723, 0, 1715, 0, 1720, 0, 1722, 0, 0, - 0, 0, 0, 0, 0, 1723, 1729, 0, 0, 0, - - 0, 1729, 1729, 1729, 1730, 0, 1730, 1730, 1730, 1730, - 1730, 1730, 1730, 1731, 0, 1731, 1732, 1732, 1732, 1733, - 1733, 1733, 1734, 1734, 1734, 1735, 1735, 1735, 1736, 1736, - 1736, 1737, 1737, 1737, 1738, 1738, 1738, 1739, 1739, 1739, - 1740, 1740, 1740, 1741, 0, 1741, 1742, 1742, 1742, 1743, - 1743, 1743, 1744, 1744, 1744, 1745, 1745, 1745, 1746, 0, - 1746, 1747, 1747, 1747, 1748, 1748, 0, 0, 1748, 1749, - 1749, 1749, 1750, 1750, 1750, 1751, 1751, 1751, 1752, 1752, - 1752, 1753, 1753, 1753, 1754, 1754, 1754, 1755, 1755, 1755, - 1756, 1756, 1756, 1757, 1757, 1757, 1758, 1758, 0, 0, - - 1758, 1759, 1759, 1759, 1760, 1760, 1760, 1761, 0, 1761, - 1762, 1762, 1762, 1763, 1763, 1763, 1764, 0, 1764, 1765, - 1765, 1765, 1766, 1766, 1766, 1767, 1767, 1767, 1768, 1768, - 1768, 1769, 1769, 1769, 1770, 0, 1770, 1771, 0, 1771, - 1772, 1772, 1772, 1773, 1773, 1773, 1774, 0, 1774, 1775, - 1775, 0, 0, 1775, 1776, 1776, 0, 0, 1776, 1777, - 1777, 1777, 1778, 1778, 1778, 1779, 1779, 0, 1779, 1780, - 1780, 1780, 1781, 1781, 1781, 1782, 1782, 1782, 1783, 1783, - 1783, 1784, 1784, 1784, 1785, 1785, 1785, 1786, 1786, 1786, - 1787, 1787, 0, 0, 1787, 1788, 1788, 1788, 1789, 1789, - - 1789, 1790, 1790, 0, 1790, 1791, 1791, 0, 0, 1791, - 1792, 1792, 0, 1792, 1793, 1793, 1794, 1794, 0, 0, - 1794, 1795, 1795, 1795, 1796, 1796, 1796, 1797, 1797, 0, - 1797, 1798, 0, 1798, 1799, 0, 1799, 1800, 1800, 1800, - 1801, 1801, 1801, 1802, 0, 1802, 1803, 1803, 1803, 1804, - 1804, 1804, 1805, 1805, 1805, 1806, 1806, 1806, 1807, 1807, - 1807, 1808, 1808, 1808, 1809, 0, 1809, 1810, 0, 1810, - 1811, 1811, 1811, 1812, 1812, 1812, 1813, 0, 1813, 1814, - 0, 1814, 1815, 0, 1815, 1816, 1816, 1816, 1817, 1817, - 1817, 1818, 0, 1818, 1819, 0, 0, 1819, 1820, 1820, - - 0, 1820, 1821, 1821, 0, 0, 1821, 1822, 1822, 0, - 1822, 1823, 1823, 1824, 1824, 0, 0, 1824, 1825, 1825, - 1825, 1826, 1826, 1826, 1827, 1827, 0, 1827, 1828, 1828, - 1828, 0, 1828, 1828, 1829, 1829, 1829, 1830, 1830, 1830, - 1831, 1831, 1831, 1832, 1832, 1832, 1833, 1833, 1833, 1834, - 1834, 1834, 1835, 1835, 1835, 1836, 1836, 1836, 1837, 1837, - 0, 0, 1837, 1838, 1838, 1838, 1839, 1839, 1839, 1840, - 1840, 0, 1840, 1841, 1841, 0, 0, 1841, 1842, 1842, - 0, 1842, 1843, 1843, 1844, 1844, 0, 0, 1844, 1845, - 1845, 1845, 1846, 1846, 1846, 1847, 1847, 0, 1847, 1848, - - 0, 0, 1848, 1849, 1849, 0, 1849, 1850, 1850, 0, - 0, 1850, 1851, 1851, 0, 1851, 1852, 1852, 1853, 1853, - 0, 0, 1853, 1854, 1854, 1854, 1855, 1855, 1855, 1856, - 1856, 0, 1856, 1857, 0, 1857, 1858, 0, 1858, 1859, - 0, 1859, 1860, 1860, 1860, 1861, 1861, 1861, 1862, 0, - 1862, 1863, 1863, 1863, 0, 1863, 1863, 1864, 1864, 1864, - 1865, 1865, 1865, 1866, 1866, 1866, 1867, 1867, 1867, 1868, - 1868, 1868, 1869, 1869, 1869, 1870, 1870, 1870, 1871, 0, - 1871, 1872, 0, 1872, 1873, 1873, 1873, 1874, 1874, 1874, - 1875, 0, 1875, 1876, 0, 1876, 1877, 0, 1877, 1878, - - 1878, 1878, 1879, 1879, 1879, 1880, 0, 1880, 1881, 0, - 1881, 1882, 0, 1882, 1883, 0, 1883, 1884, 1884, 1884, - 1885, 1885, 1885, 1886, 0, 1886, 1887, 0, 1887, 1888, - 0, 0, 1888, 1889, 1889, 0, 1889, 1890, 1890, 0, - 0, 1890, 1891, 1891, 0, 1891, 1892, 1892, 1893, 1893, - 0, 0, 1893, 1894, 1894, 1894, 1895, 1895, 1895, 1896, - 1896, 0, 1896, 1897, 1897, 1897, 0, 1897, 1897, 1898, - 1898, 1898, 1899, 1899, 1899, 1900, 1900, 1900, 1901, 1901, - 1901, 1902, 1902, 1902, 1903, 1903, 1903, 1904, 1904, 1904, - 1905, 1905, 1905, 1906, 1906, 0, 0, 1906, 1907, 1907, - - 1907, 1908, 1908, 1908, 1909, 1909, 0, 1909, 1910, 1910, - 0, 0, 1910, 1911, 1911, 0, 1911, 1912, 1912, 1913, - 1913, 0, 0, 1913, 1914, 1914, 1914, 1915, 1915, 1915, - 1916, 1916, 0, 1916, 1917, 0, 0, 1917, 1918, 1918, - 0, 1918, 1919, 1919, 0, 0, 1919, 1920, 1920, 0, - 1920, 1921, 1921, 1922, 1922, 0, 0, 1922, 1923, 1923, - 1923, 1924, 1924, 1924, 1925, 1925, 0, 1925, 1926, 0, - 1926, 1927, 0, 0, 1927, 1928, 1928, 0, 1928, 1929, - 1929, 0, 0, 1929, 1930, 1930, 0, 1930, 1931, 1931, - 1932, 1932, 0, 0, 1932, 1933, 1933, 1933, 1934, 1934, - - 1934, 1935, 1935, 0, 1935, 1936, 0, 1936, 1937, 0, - 1937, 1938, 0, 1938, 1939, 1939, 1939, 1940, 1940, 1940, - 1941, 0, 1941, 1942, 1942, 1942, 0, 1942, 1942, 1943, - 1943, 1943, 1944, 1944, 1944, 1945, 1945, 1945, 1946, 1946, - 1946, 1947, 1947, 1947, 1948, 1948, 1948, 1949, 1949, 1949, - 1950, 1950, 1950, 1951, 1951, 1951, 1952, 1952, 1952, 1953, - 0, 1953, 1954, 0, 1954, 1955, 1955, 1955, 1956, 1956, - 1956, 1957, 1957, 1957, 1958, 0, 1958, 1959, 0, 1959, - 1960, 0, 1960, 1961, 1961, 1961, 1962, 1962, 1962, 1963, - 1963, 1963, 1964, 0, 1964, 1965, 0, 1965, 1966, 0, - - 1966, 1967, 0, 1967, 1968, 1968, 1968, 1969, 1969, 1969, - 1970, 1970, 1970, 1971, 0, 1971, 1972, 0, 1972, 1973, - 0, 1973, 1974, 0, 1974, 1975, 1975, 1975, 1976, 1976, - 1976, 1977, 1977, 1977, 1978, 0, 1978, 1979, 0, 1979, - 1980, 0, 0, 1980, 1981, 1981, 0, 1981, 1982, 1982, - 0, 0, 1982, 1983, 1983, 0, 1983, 1984, 1984, 1985, - 1985, 0, 0, 1985, 1986, 1986, 1986, 1987, 1987, 1987, - 1988, 1988, 0, 1988, 1989, 1989, 1989, 0, 1989, 1989, - 1990, 1990, 1990, 1991, 1991, 1991, 1992, 1992, 1992, 1993, - 1993, 1993, 1994, 1994, 1994, 1995, 1995, 1995, 1996, 1996, - - 1996, 1997, 1997, 1997, 1998, 0, 1998, 1999, 1999, 1999, - 2000, 2000, 0, 0, 2000, 2001, 2001, 2001, 2002, 2002, - 2002, 2003, 2003, 0, 2003, 2004, 2004, 0, 0, 2004, - 2005, 2005, 0, 2005, 2006, 2006, 2007, 2007, 0, 0, - 2007, 2008, 2008, 2008, 2009, 2009, 2009, 2010, 2010, 0, - 2010, 2011, 0, 0, 2011, 2012, 2012, 0, 2012, 2013, - 2013, 0, 0, 2013, 2014, 2014, 0, 2014, 2015, 2015, - 2016, 2016, 0, 0, 2016, 2017, 2017, 2017, 2018, 2018, - 2018, 2019, 2019, 0, 2019, 2020, 0, 2020, 2021, 0, - 0, 2021, 2022, 2022, 0, 2022, 2023, 2023, 0, 0, - - 2023, 2024, 2024, 0, 2024, 2025, 2025, 2026, 2026, 0, - 0, 2026, 2027, 2027, 2027, 2028, 2028, 2028, 2029, 2029, - 0, 2029, 2030, 0, 2030, 2031, 0, 0, 2031, 2032, - 2032, 0, 2032, 2033, 2033, 0, 0, 2033, 2034, 2034, - 0, 2034, 2035, 2035, 2036, 2036, 0, 0, 2036, 2037, - 2037, 2037, 2038, 2038, 2038, 2039, 2039, 0, 2039, 2040, - 0, 2040, 2041, 0, 2041, 2042, 0, 2042, 2043, 2043, - 2043, 2044, 0, 2044, 2045, 2045, 2045, 2046, 0, 2046, - 2047, 2047, 2047, 0, 2047, 2047, 2048, 0, 2048, 2049, - 2049, 2049, 2050, 0, 2050, 2051, 2051, 2051, 2052, 0, - - 2052, 2053, 2053, 2053, 2054, 0, 2054, 2055, 2055, 2055, - 2056, 0, 2056, 2057, 2057, 2057, 2058, 0, 2058, 2059, - 2059, 2059, 2060, 2060, 0, 0, 2060, 2061, 2061, 2061, - 2062, 2062, 2062, 2063, 2063, 2063, 2064, 2064, 0, 2064, - 2065, 2065, 2065, 2066, 0, 2066, 2067, 2067, 2067, 2068, - 2068, 2068, 2069, 0, 2069, 2070, 0, 2070, 2071, 2071, - 2071, 2072, 2072, 2072, 2073, 0, 2073, 2074, 0, 2074, - 2075, 0, 2075, 2076, 2076, 2076, 2077, 2077, 2077, 2078, - 0, 2078, 2079, 0, 2079, 2080, 0, 2080, 2081, 2081, - 2081, 2082, 2082, 2082, 2083, 0, 2083, 2084, 0, 2084, - - 2085, 0, 2085, 2086, 2086, 2086, 2087, 2087, 2087, 2088, - 0, 2088, 2089, 0, 0, 2089, 2090, 2090, 0, 2090, - 2091, 2091, 0, 0, 2091, 2092, 2092, 0, 2092, 2093, - 2093, 2094, 2094, 0, 0, 2094, 2095, 2095, 2095, 2096, - 0, 2096, 2097, 2097, 0, 2097, 2098, 2098, 2098, 0, - 2098, 2098, 2099, 2099, 2099, 2100, 2100, 2100, 2101, 0, - 2101, 2102, 0, 2102, 2103, 0, 2103, 2104, 0, 2104, - 2105, 0, 2105, 2106, 0, 2106, 2107, 0, 2107, 2108, - 2108, 2108, 2109, 2109, 2109, 2110, 0, 2110, 2111, 2111, - 0, 0, 2111, 2112, 2112, 0, 2112, 2113, 2113, 2114, - - 0, 2114, 2115, 0, 0, 2115, 2116, 2116, 0, 2116, - 2117, 2117, 0, 0, 2117, 2118, 2118, 0, 2118, 2119, - 2119, 2120, 0, 2120, 2121, 0, 2121, 2122, 0, 0, - 2122, 2123, 2123, 0, 2123, 2124, 2124, 0, 0, 2124, - 2125, 2125, 0, 2125, 2126, 2126, 2127, 0, 2127, 2128, - 0, 2128, 2129, 0, 0, 2129, 2130, 2130, 0, 2130, - 2131, 2131, 0, 0, 2131, 2132, 2132, 0, 2132, 2133, - 2133, 2134, 0, 2134, 2135, 0, 2135, 2136, 0, 0, - 2136, 2137, 2137, 0, 2137, 2138, 2138, 0, 0, 2138, - 2139, 2139, 0, 2139, 2140, 2140, 2141, 0, 2141, 2142, - - 0, 2142, 2143, 0, 2143, 2144, 0, 2144, 2145, 2145, - 2145, 2146, 0, 2146, 2147, 2147, 2147, 0, 2147, 2147, - 2148, 0, 2148, 2149, 0, 2149, 2150, 0, 2150, 2151, - 0, 2151, 2152, 0, 2152, 2153, 0, 2153, 2154, 0, - 2154, 2155, 2155, 0, 0, 2155, 2156, 2156, 0, 2156, - 2157, 2157, 2158, 0, 2158, 2159, 0, 2159, 2160, 0, - 2160, 2161, 0, 2161, 2162, 0, 2162, 2163, 0, 2163, - 2164, 0, 2164, 2165, 0, 2165, 2166, 0, 2166, 2167, - 0, 2167, 2168, 0, 0, 2168, 2169, 2169, 0, 0, - 2169, 2170, 0, 2170, 2171, 0, 2171, 2172, 0, 2172, - - 2173, 0, 0, 2173, 2174, 0, 0, 2174, 2175, 0, - 0, 2175, 2176, 0, 0, 2176, 2177, 0, 0, 2177, - 2178, 0, 2178, 2179, 0, 2179, 2180, 0, 0, 2180, - 2181, 0, 2181, 2182, 0, 2182, 2183, 0, 2183, 2184, - 0, 2184, 2185, 0, 2185, 2186, 0, 0, 2186, 2187, - 0, 2187, 2188, 0, 2188, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, - - 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728, 1728 - } ; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -#line 1 "scanner.l" - -/* - * We want a reentrant scanner. - */ -/* - * And we need to pass the compiler state to the scanner. - */ -/* - * We don't use input, so don't generate code for it. - */ -#define YY_NO_INPUT 1 -/* - * We don't use unput, so don't generate code for it. - */ -/* - * We don't read from the terminal. - */ -/* - * We want to stop processing when we get to the end of the input. - */ -/* - * We want to generate code that can be used by a reentrant parser - * generated by Bison or Berkeley YACC. - */ -#line 67 "scanner.l" -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that: (1) source code distributions - * retain the above copyright notice and this paragraph in its entirety, (2) - * distributions including binary code include the above copyright notice and - * this paragraph in its entirety in the documentation or other materials - * provided with the distribution, and (3) all advertising materials mentioning - * features or use of this software display the following acknowledgement: - * ``This product includes software developed by the University of California, - * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#include -#include - -#include "pcap-int.h" - -#include "gencode.h" - -#include "grammar.h" - -/* - * Earlier versions of Flex don't declare these, so we declare them - * ourselves to squelch warnings. - */ -int pcap_get_column(yyscan_t); -void pcap_set_column(int, yyscan_t); - -#ifdef INET6 - -#ifdef _WIN32 -#include -#include -/* - * To quote the MSDN page for getaddrinfo() at - * - * https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520(v=vs.85).aspx - * - * "Support for getaddrinfo on Windows 2000 and older versions - * The getaddrinfo function was added to the Ws2_32.dll on Windows XP and - * later. To execute an application that uses this function on earlier - * versions of Windows, then you need to include the Ws2tcpip.h and - * Wspiapi.h files. When the Wspiapi.h include file is added, the - * getaddrinfo function is defined to the WspiapiGetAddrInfo inline - * function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo - * function is implemented in such a way that if the Ws2_32.dll or the - * Wship6.dll (the file containing getaddrinfo in the IPv6 Technology - * Preview for Windows 2000) does not include getaddrinfo, then a - * version of getaddrinfo is implemented inline based on code in the - * Wspiapi.h header file. This inline code will be used on older Windows - * platforms that do not natively support the getaddrinfo function." - * - * We use getaddrinfo(), so we include Wspiapi.h here. - */ -#include -#else /* _WIN32 */ -#include /* for "struct sockaddr" in "struct addrinfo" */ -#include /* for "struct addrinfo" */ -#endif /* _WIN32 */ - -/* Workaround for AIX 4.3 */ -#if !defined(AI_NUMERICHOST) -#define AI_NUMERICHOST 0x04 -#endif - -#endif /*INET6*/ - -#include -#include "grammar.h" - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -static int stoi(char *); -static inline int xdtoi(int); - -/* - * Disable diagnostics in the code generated by Flex. - */ -DIAG_OFF_FLEX - -#line 2997 "scanner.c" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#define YY_EXTRA_TYPE compiler_state_t * - -/* Holds the entire state of the reentrant scanner. */ -struct yyguts_t - { - - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; - - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - yy_size_t yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; - - int yylineno_r; - int yy_flex_debug_r; - - char *yytext_r; - int yy_more_flag; - int yy_more_len; - - YYSTYPE * yylval_r; - - }; /* end struct yyguts_t */ - -static int yy_init_globals (yyscan_t yyscanner ); - - /* This must go here because YYSTYPE and YYLTYPE are included - * from bison output in section 1.*/ - # define yylval yyg->yylval_r - -int pcap_lex_init (yyscan_t* scanner); - -int pcap_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int pcap_lex_destroy (yyscan_t yyscanner ); - -int pcap_get_debug (yyscan_t yyscanner ); - -void pcap_set_debug (int debug_flag ,yyscan_t yyscanner ); - -YY_EXTRA_TYPE pcap_get_extra (yyscan_t yyscanner ); - -void pcap_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); - -FILE *pcap_get_in (yyscan_t yyscanner ); - -void pcap_set_in (FILE * _in_str ,yyscan_t yyscanner ); - -FILE *pcap_get_out (yyscan_t yyscanner ); - -void pcap_set_out (FILE * _out_str ,yyscan_t yyscanner ); - -yy_size_t pcap_get_leng (yyscan_t yyscanner ); - -char *pcap_get_text (yyscan_t yyscanner ); - -int pcap_get_lineno (yyscan_t yyscanner ); - -void pcap_set_lineno (int _line_number ,yyscan_t yyscanner ); - -int pcap_get_column (yyscan_t yyscanner ); - -void pcap_set_column (int _column_no ,yyscan_t yyscanner ); - -YYSTYPE * pcap_get_lval (yyscan_t yyscanner ); - -void pcap_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int pcap_wrap (yyscan_t yyscanner ); -#else -extern int pcap_wrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (yyscan_t yyscanner ); -#else -static int input (yyscan_t yyscanner ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int pcap_lex \ - (YYSTYPE * yylval_param ,yyscan_t yyscanner); - -#define YY_DECL int pcap_lex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yylval = yylval_param; - - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - pcap_ensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - pcap__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } - - pcap__load_buffer_state(yyscanner ); - } - - { -#line 254 "scanner.l" - -#line 3270 "scanner.c" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yyg->yy_start; -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1729 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_current_state != 1728 ); - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yyg->yy_hold_char; - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 255 "scanner.l" -return DST; - YY_BREAK -case 2: -YY_RULE_SETUP -#line 256 "scanner.l" -return SRC; - YY_BREAK -case 3: -YY_RULE_SETUP -#line 258 "scanner.l" -return LINK; - YY_BREAK -case 4: -YY_RULE_SETUP -#line 259 "scanner.l" -return LINK; - YY_BREAK -case 5: -YY_RULE_SETUP -#line 260 "scanner.l" -return ARP; - YY_BREAK -case 6: -YY_RULE_SETUP -#line 261 "scanner.l" -return RARP; - YY_BREAK -case 7: -YY_RULE_SETUP -#line 262 "scanner.l" -return IP; - YY_BREAK -case 8: -YY_RULE_SETUP -#line 263 "scanner.l" -return SCTP; - YY_BREAK -case 9: -YY_RULE_SETUP -#line 264 "scanner.l" -return TCP; - YY_BREAK -case 10: -YY_RULE_SETUP -#line 265 "scanner.l" -return UDP; - YY_BREAK -case 11: -YY_RULE_SETUP -#line 266 "scanner.l" -return ICMP; - YY_BREAK -case 12: -YY_RULE_SETUP -#line 267 "scanner.l" -return IGMP; - YY_BREAK -case 13: -YY_RULE_SETUP -#line 268 "scanner.l" -return IGRP; - YY_BREAK -case 14: -YY_RULE_SETUP -#line 269 "scanner.l" -return PIM; - YY_BREAK -case 15: -YY_RULE_SETUP -#line 270 "scanner.l" -return VRRP; - YY_BREAK -case 16: -YY_RULE_SETUP -#line 271 "scanner.l" -return CARP; - YY_BREAK -case 17: -YY_RULE_SETUP -#line 272 "scanner.l" -return RADIO; - YY_BREAK -case 18: -YY_RULE_SETUP -#line 274 "scanner.l" -return IPV6; - YY_BREAK -case 19: -YY_RULE_SETUP -#line 275 "scanner.l" -return ICMPV6; - YY_BREAK -case 20: -YY_RULE_SETUP -#line 276 "scanner.l" -return AH; - YY_BREAK -case 21: -YY_RULE_SETUP -#line 277 "scanner.l" -return ESP; - YY_BREAK -case 22: -YY_RULE_SETUP -#line 279 "scanner.l" -return ATALK; - YY_BREAK -case 23: -YY_RULE_SETUP -#line 280 "scanner.l" -return AARP; - YY_BREAK -case 24: -YY_RULE_SETUP -#line 281 "scanner.l" -return DECNET; - YY_BREAK -case 25: -YY_RULE_SETUP -#line 282 "scanner.l" -return LAT; - YY_BREAK -case 26: -YY_RULE_SETUP -#line 283 "scanner.l" -return SCA; - YY_BREAK -case 27: -YY_RULE_SETUP -#line 284 "scanner.l" -return MOPRC; - YY_BREAK -case 28: -YY_RULE_SETUP -#line 285 "scanner.l" -return MOPDL; - YY_BREAK -case 29: -YY_RULE_SETUP -#line 287 "scanner.l" -return ISO; - YY_BREAK -case 30: -YY_RULE_SETUP -#line 288 "scanner.l" -return ESIS; - YY_BREAK -case 31: -YY_RULE_SETUP -#line 289 "scanner.l" -return ESIS; - YY_BREAK -case 32: -YY_RULE_SETUP -#line 290 "scanner.l" -return ISIS; - YY_BREAK -case 33: -YY_RULE_SETUP -#line 291 "scanner.l" -return ISIS; - YY_BREAK -case 34: -YY_RULE_SETUP -#line 292 "scanner.l" -return L1; - YY_BREAK -case 35: -YY_RULE_SETUP -#line 293 "scanner.l" -return L2; - YY_BREAK -case 36: -YY_RULE_SETUP -#line 294 "scanner.l" -return IIH; - YY_BREAK -case 37: -YY_RULE_SETUP -#line 295 "scanner.l" -return LSP; - YY_BREAK -case 38: -YY_RULE_SETUP -#line 296 "scanner.l" -return SNP; - YY_BREAK -case 39: -YY_RULE_SETUP -#line 297 "scanner.l" -return CSNP; - YY_BREAK -case 40: -YY_RULE_SETUP -#line 298 "scanner.l" -return PSNP; - YY_BREAK -case 41: -YY_RULE_SETUP -#line 300 "scanner.l" -return CLNP; - YY_BREAK -case 42: -YY_RULE_SETUP -#line 302 "scanner.l" -return STP; - YY_BREAK -case 43: -YY_RULE_SETUP -#line 304 "scanner.l" -return IPX; - YY_BREAK -case 44: -YY_RULE_SETUP -#line 306 "scanner.l" -return NETBEUI; - YY_BREAK -case 45: -YY_RULE_SETUP -#line 308 "scanner.l" -return HOST; - YY_BREAK -case 46: -YY_RULE_SETUP -#line 309 "scanner.l" -return NET; - YY_BREAK -case 47: -YY_RULE_SETUP -#line 310 "scanner.l" -return NETMASK; - YY_BREAK -case 48: -YY_RULE_SETUP -#line 311 "scanner.l" -return PORT; - YY_BREAK -case 49: -YY_RULE_SETUP -#line 312 "scanner.l" -return PORTRANGE; - YY_BREAK -case 50: -YY_RULE_SETUP -#line 313 "scanner.l" -return PROTO; - YY_BREAK -case 51: -YY_RULE_SETUP -#line 314 "scanner.l" -{ -#ifdef NO_PROTOCHAIN - bpf_error(yyextra, "%s not supported", yytext); -#else - return PROTOCHAIN; -#endif - } - YY_BREAK -case 52: -YY_RULE_SETUP -#line 322 "scanner.l" -return GATEWAY; - YY_BREAK -case 53: -YY_RULE_SETUP -#line 324 "scanner.l" -return TYPE; - YY_BREAK -case 54: -YY_RULE_SETUP -#line 325 "scanner.l" -return SUBTYPE; - YY_BREAK -case 55: -YY_RULE_SETUP -#line 326 "scanner.l" -return DIR; - YY_BREAK -case 56: -YY_RULE_SETUP -#line 327 "scanner.l" -return ADDR1; - YY_BREAK -case 57: -YY_RULE_SETUP -#line 328 "scanner.l" -return ADDR2; - YY_BREAK -case 58: -YY_RULE_SETUP -#line 329 "scanner.l" -return ADDR3; - YY_BREAK -case 59: -YY_RULE_SETUP -#line 330 "scanner.l" -return ADDR4; - YY_BREAK -case 60: -YY_RULE_SETUP -#line 331 "scanner.l" -return RA; - YY_BREAK -case 61: -YY_RULE_SETUP -#line 332 "scanner.l" -return TA; - YY_BREAK -case 62: -YY_RULE_SETUP -#line 334 "scanner.l" -return LESS; - YY_BREAK -case 63: -YY_RULE_SETUP -#line 335 "scanner.l" -return GREATER; - YY_BREAK -case 64: -YY_RULE_SETUP -#line 336 "scanner.l" -return CBYTE; - YY_BREAK -case 65: -YY_RULE_SETUP -#line 337 "scanner.l" -return TK_BROADCAST; - YY_BREAK -case 66: -YY_RULE_SETUP -#line 338 "scanner.l" -return TK_MULTICAST; - YY_BREAK -case 67: -YY_RULE_SETUP -#line 340 "scanner.l" -return AND; - YY_BREAK -case 68: -YY_RULE_SETUP -#line 341 "scanner.l" -return OR; - YY_BREAK -case 69: -YY_RULE_SETUP -#line 342 "scanner.l" -return '!'; - YY_BREAK -case 70: -YY_RULE_SETUP -#line 344 "scanner.l" -return LEN; - YY_BREAK -case 71: -YY_RULE_SETUP -#line 345 "scanner.l" -return INBOUND; - YY_BREAK -case 72: -YY_RULE_SETUP -#line 346 "scanner.l" -return OUTBOUND; - YY_BREAK -case 73: -YY_RULE_SETUP -#line 348 "scanner.l" -return VLAN; - YY_BREAK -case 74: -YY_RULE_SETUP -#line 349 "scanner.l" -return MPLS; - YY_BREAK -case 75: -YY_RULE_SETUP -#line 350 "scanner.l" -return PPPOED; - YY_BREAK -case 76: -YY_RULE_SETUP -#line 351 "scanner.l" -return PPPOES; - YY_BREAK -case 77: -YY_RULE_SETUP -#line 352 "scanner.l" -return GENEVE; - YY_BREAK -case 78: -YY_RULE_SETUP -#line 354 "scanner.l" -return LANE; - YY_BREAK -case 79: -YY_RULE_SETUP -#line 355 "scanner.l" -return LLC; - YY_BREAK -case 80: -YY_RULE_SETUP -#line 356 "scanner.l" -return METAC; - YY_BREAK -case 81: -YY_RULE_SETUP -#line 357 "scanner.l" -return BCC; - YY_BREAK -case 82: -YY_RULE_SETUP -#line 358 "scanner.l" -return OAM; - YY_BREAK -case 83: -YY_RULE_SETUP -#line 359 "scanner.l" -return OAMF4; - YY_BREAK -case 84: -YY_RULE_SETUP -#line 360 "scanner.l" -return OAMF4EC; - YY_BREAK -case 85: -YY_RULE_SETUP -#line 361 "scanner.l" -return OAMF4SC; - YY_BREAK -case 86: -YY_RULE_SETUP -#line 362 "scanner.l" -return SC; - YY_BREAK -case 87: -YY_RULE_SETUP -#line 363 "scanner.l" -return ILMIC; - YY_BREAK -case 88: -YY_RULE_SETUP -#line 364 "scanner.l" -return VPI; - YY_BREAK -case 89: -YY_RULE_SETUP -#line 365 "scanner.l" -return VCI; - YY_BREAK -case 90: -YY_RULE_SETUP -#line 366 "scanner.l" -return CONNECTMSG; - YY_BREAK -case 91: -YY_RULE_SETUP -#line 367 "scanner.l" -return METACONNECT; - YY_BREAK -case 92: -YY_RULE_SETUP -#line 369 "scanner.l" -return PF_IFNAME; - YY_BREAK -case 93: -YY_RULE_SETUP -#line 370 "scanner.l" -return PF_RSET; - YY_BREAK -case 94: -YY_RULE_SETUP -#line 371 "scanner.l" -return PF_RNR; - YY_BREAK -case 95: -YY_RULE_SETUP -#line 372 "scanner.l" -return PF_SRNR; - YY_BREAK -case 96: -YY_RULE_SETUP -#line 373 "scanner.l" -return PF_REASON; - YY_BREAK -case 97: -YY_RULE_SETUP -#line 374 "scanner.l" -return PF_ACTION; - YY_BREAK -case 98: -YY_RULE_SETUP -#line 376 "scanner.l" -return FISU; - YY_BREAK -case 99: -YY_RULE_SETUP -#line 377 "scanner.l" -return LSSU; - YY_BREAK -case 100: -YY_RULE_SETUP -#line 378 "scanner.l" -return LSSU; - YY_BREAK -case 101: -YY_RULE_SETUP -#line 379 "scanner.l" -return MSU; - YY_BREAK -case 102: -YY_RULE_SETUP -#line 380 "scanner.l" -return HFISU; - YY_BREAK -case 103: -YY_RULE_SETUP -#line 381 "scanner.l" -return HLSSU; - YY_BREAK -case 104: -YY_RULE_SETUP -#line 382 "scanner.l" -return HMSU; - YY_BREAK -case 105: -YY_RULE_SETUP -#line 383 "scanner.l" -return SIO; - YY_BREAK -case 106: -YY_RULE_SETUP -#line 384 "scanner.l" -return OPC; - YY_BREAK -case 107: -YY_RULE_SETUP -#line 385 "scanner.l" -return DPC; - YY_BREAK -case 108: -YY_RULE_SETUP -#line 386 "scanner.l" -return SLS; - YY_BREAK -case 109: -YY_RULE_SETUP -#line 387 "scanner.l" -return HSIO; - YY_BREAK -case 110: -YY_RULE_SETUP -#line 388 "scanner.l" -return HOPC; - YY_BREAK -case 111: -YY_RULE_SETUP -#line 389 "scanner.l" -return HDPC; - YY_BREAK -case 112: -YY_RULE_SETUP -#line 390 "scanner.l" -return HSLS; - YY_BREAK -case 113: -/* rule 113 can match eol */ -YY_RULE_SETUP -#line 392 "scanner.l" -; - YY_BREAK -case 114: -YY_RULE_SETUP -#line 393 "scanner.l" -return yytext[0]; - YY_BREAK -case 115: -YY_RULE_SETUP -#line 394 "scanner.l" -return GEQ; - YY_BREAK -case 116: -YY_RULE_SETUP -#line 395 "scanner.l" -return LEQ; - YY_BREAK -case 117: -YY_RULE_SETUP -#line 396 "scanner.l" -return NEQ; - YY_BREAK -case 118: -YY_RULE_SETUP -#line 397 "scanner.l" -return '='; - YY_BREAK -case 119: -YY_RULE_SETUP -#line 398 "scanner.l" -return LSH; - YY_BREAK -case 120: -YY_RULE_SETUP -#line 399 "scanner.l" -return RSH; - YY_BREAK -case 121: -YY_RULE_SETUP -#line 400 "scanner.l" -{ yylval->e = pcap_ether_aton(((char *)yytext)+1); - if (yylval->e == NULL) - bpf_error(yyextra, "malloc"); - return AID; } - YY_BREAK -case 122: -YY_RULE_SETUP -#line 404 "scanner.l" -{ yylval->e = pcap_ether_aton((char *)yytext); - if (yylval->e == NULL) - bpf_error(yyextra, "malloc"); - return EID; } - YY_BREAK -case 123: -YY_RULE_SETUP -#line 408 "scanner.l" -{ yylval->i = stoi((char *)yytext); return NUM; } - YY_BREAK -case 124: -YY_RULE_SETUP -#line 409 "scanner.l" -{ - yylval->s = sdup(yyextra, (char *)yytext); return HID; } - YY_BREAK -case 125: -YY_RULE_SETUP -#line 411 "scanner.l" -{ -#ifdef INET6 - struct addrinfo hints, *res; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET6; - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(yytext, NULL, &hints, &res)) - bpf_error(yyextra, "bogus IPv6 address %s", yytext); - else { - freeaddrinfo(res); - yylval->s = sdup(yyextra, (char *)yytext); return HID6; - } -#else - bpf_error(yyextra, "IPv6 address %s not supported", yytext); -#endif /*INET6*/ - } - YY_BREAK -case 126: -YY_RULE_SETUP -#line 427 "scanner.l" -{ bpf_error(yyextra, "bogus ethernet address %s", yytext); } - YY_BREAK -case 127: -YY_RULE_SETUP -#line 428 "scanner.l" -{ yylval->i = 0; return NUM; } - YY_BREAK -case 128: -YY_RULE_SETUP -#line 429 "scanner.l" -{ yylval->i = 1; return NUM; } - YY_BREAK -case 129: -YY_RULE_SETUP -#line 430 "scanner.l" -{ yylval->i = 0; return NUM; } - YY_BREAK -case 130: -YY_RULE_SETUP -#line 431 "scanner.l" -{ yylval->i = 3; return NUM; } - YY_BREAK -case 131: -YY_RULE_SETUP -#line 432 "scanner.l" -{ yylval->i = 4; return NUM; } - YY_BREAK -case 132: -YY_RULE_SETUP -#line 433 "scanner.l" -{ yylval->i = 5; return NUM; } - YY_BREAK -case 133: -YY_RULE_SETUP -#line 434 "scanner.l" -{ yylval->i = 8; return NUM; } - YY_BREAK -case 134: -YY_RULE_SETUP -#line 435 "scanner.l" -{ yylval->i = 9; return NUM; } - YY_BREAK -case 135: -YY_RULE_SETUP -#line 436 "scanner.l" -{ yylval->i = 10; return NUM; } - YY_BREAK -case 136: -YY_RULE_SETUP -#line 437 "scanner.l" -{ yylval->i = 11; return NUM; } - YY_BREAK -case 137: -YY_RULE_SETUP -#line 438 "scanner.l" -{ yylval->i = 12; return NUM; } - YY_BREAK -case 138: -YY_RULE_SETUP -#line 439 "scanner.l" -{ yylval->i = 13; return NUM; } - YY_BREAK -case 139: -YY_RULE_SETUP -#line 440 "scanner.l" -{ yylval->i = 14; return NUM; } - YY_BREAK -case 140: -YY_RULE_SETUP -#line 441 "scanner.l" -{ yylval->i = 15; return NUM; } - YY_BREAK -case 141: -YY_RULE_SETUP -#line 442 "scanner.l" -{ yylval->i = 16; return NUM; } - YY_BREAK -case 142: -YY_RULE_SETUP -#line 443 "scanner.l" -{ yylval->i = 17; return NUM; } - YY_BREAK -case 143: -YY_RULE_SETUP -#line 444 "scanner.l" -{ yylval->i = 18; return NUM; } - YY_BREAK -case 144: -YY_RULE_SETUP -#line 446 "scanner.l" -{ yylval->i = 0; return NUM; } - YY_BREAK -case 145: -YY_RULE_SETUP -#line 447 "scanner.l" -{ yylval->i = 1; return NUM; } - YY_BREAK -case 146: -YY_RULE_SETUP -#line 449 "scanner.l" -{ yylval->i = 128; return NUM; } - YY_BREAK -case 147: -YY_RULE_SETUP -#line 450 "scanner.l" -{ yylval->i = 129; return NUM; } - YY_BREAK -case 148: -YY_RULE_SETUP -#line 451 "scanner.l" -{ yylval->i = 130; return NUM; } - YY_BREAK -case 149: -YY_RULE_SETUP -#line 452 "scanner.l" -{ yylval->i = 131; return NUM; } - YY_BREAK -case 150: -YY_RULE_SETUP -#line 453 "scanner.l" -{ yylval->i = 132; return NUM; } - YY_BREAK -case 151: -YY_RULE_SETUP -#line 454 "scanner.l" -{ yylval->i = 133; return NUM; } - YY_BREAK -case 152: -YY_RULE_SETUP -#line 455 "scanner.l" -{ yylval->i = 134; return NUM; } - YY_BREAK -case 153: -YY_RULE_SETUP -#line 456 "scanner.l" -{ yylval->i = 135; return NUM; } - YY_BREAK -case 154: -YY_RULE_SETUP -#line 457 "scanner.l" -{ yylval->i = 136; return NUM; } - YY_BREAK -case 155: -YY_RULE_SETUP -#line 458 "scanner.l" -{ yylval->i = 137; return NUM; } - YY_BREAK -case 156: -YY_RULE_SETUP -#line 459 "scanner.l" -{ yylval->i = 138; return NUM; } - YY_BREAK -case 157: -YY_RULE_SETUP -#line 460 "scanner.l" -{ yylval->i = 139; return NUM; } - YY_BREAK -case 158: -YY_RULE_SETUP -#line 461 "scanner.l" -{ yylval->i = 140; return NUM; } - YY_BREAK -case 159: -YY_RULE_SETUP -#line 462 "scanner.l" -{ yylval->i = 141; return NUM; } - YY_BREAK -case 160: -YY_RULE_SETUP -#line 463 "scanner.l" -{ yylval->i = 142; return NUM; } - YY_BREAK -case 161: -YY_RULE_SETUP -#line 464 "scanner.l" -{ yylval->i = 143; return NUM; } - YY_BREAK -case 162: -YY_RULE_SETUP -#line 465 "scanner.l" -{ yylval->i = 144; return NUM; } - YY_BREAK -case 163: -YY_RULE_SETUP -#line 466 "scanner.l" -{ yylval->i = 145; return NUM; } - YY_BREAK -case 164: -YY_RULE_SETUP -#line 467 "scanner.l" -{ yylval->i = 146; return NUM; } - YY_BREAK -case 165: -YY_RULE_SETUP -#line 468 "scanner.l" -{ yylval->i = 147; return NUM; } - YY_BREAK -case 166: -YY_RULE_SETUP -#line 469 "scanner.l" -{ yylval->i = 148; return NUM; } - YY_BREAK -case 167: -YY_RULE_SETUP -#line 470 "scanner.l" -{ yylval->i = 149; return NUM; } - YY_BREAK -case 168: -YY_RULE_SETUP -#line 471 "scanner.l" -{ yylval->i = 151; return NUM; } - YY_BREAK -case 169: -YY_RULE_SETUP -#line 472 "scanner.l" -{ yylval->i = 152; return NUM; } - YY_BREAK -case 170: -YY_RULE_SETUP -#line 473 "scanner.l" -{ yylval->i = 153; return NUM; } - YY_BREAK -case 171: -YY_RULE_SETUP -#line 475 "scanner.l" -{ yylval->i = 13; return NUM; } - YY_BREAK -case 172: -YY_RULE_SETUP -#line 476 "scanner.l" -{ yylval->i = 0x01; return NUM; } - YY_BREAK -case 173: -YY_RULE_SETUP -#line 477 "scanner.l" -{ yylval->i = 0x02; return NUM; } - YY_BREAK -case 174: -YY_RULE_SETUP -#line 478 "scanner.l" -{ yylval->i = 0x04; return NUM; } - YY_BREAK -case 175: -YY_RULE_SETUP -#line 479 "scanner.l" -{ yylval->i = 0x08; return NUM; } - YY_BREAK -case 176: -YY_RULE_SETUP -#line 480 "scanner.l" -{ yylval->i = 0x10; return NUM; } - YY_BREAK -case 177: -YY_RULE_SETUP -#line 481 "scanner.l" -{ yylval->i = 0x20; return NUM; } - YY_BREAK -case 178: -YY_RULE_SETUP -#line 482 "scanner.l" -{ yylval->i = 0x40; return NUM; } - YY_BREAK -case 179: -YY_RULE_SETUP -#line 483 "scanner.l" -{ yylval->i = 0x80; return NUM; } - YY_BREAK -case 180: -YY_RULE_SETUP -#line 484 "scanner.l" -{ - yylval->s = sdup(yyextra, (char *)yytext); return ID; } - YY_BREAK -case 181: -YY_RULE_SETUP -#line 486 "scanner.l" -{ yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; } - YY_BREAK -case 182: -YY_RULE_SETUP -#line 487 "scanner.l" -{ - bpf_error(yyextra, "illegal token: %s", yytext); } - YY_BREAK -case 183: -YY_RULE_SETUP -#line 489 "scanner.l" -{ bpf_error(yyextra, "illegal char '%c'", *yytext); } - YY_BREAK -case 184: -YY_RULE_SETUP -#line 490 "scanner.l" -ECHO; - YY_BREAK -#line 4274 "scanner.c" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * pcap_lex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( pcap_wrap(yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of pcap_lex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - yy_size_t number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - pcap_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - pcap_restart(yyin ,yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) pcap_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) -{ - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1729 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) -{ - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - char *yy_cp = yyg->yy_c_buf_p; - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 1729 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 1728); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) -#else - static int input (yyscan_t yyscanner) -#endif - -{ - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr; - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - pcap_restart(yyin ,yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( pcap_wrap(yyscanner ) ) - return EOF; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(yyscanner); -#else - return input(yyscanner); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * @param yyscanner The scanner object. - * @note This function does not reset the start condition to @c INITIAL . - */ - void pcap_restart (FILE * input_file , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! YY_CURRENT_BUFFER ){ - pcap_ensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - pcap__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } - - pcap__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); - pcap__load_buffer_state(yyscanner ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * @param yyscanner The scanner object. - */ - void pcap__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* TODO. We should be able to replace this entire function body - * with - * pcap_pop_buffer_state(); - * pcap_push_buffer_state(new_buffer); - */ - pcap_ensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - pcap__load_buffer_state(yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (pcap_wrap()) processing, but the only time this flag - * is looked at is after pcap_wrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; -} - -static void pcap__load_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * @param yyscanner The scanner object. - * @return the allocated buffer state. - */ - YY_BUFFER_STATE pcap__create_buffer (FILE * file, int size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) pcap_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in pcap__create_buffer()" ); - - b->yy_buf_size = (yy_size_t)size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) pcap_alloc(b->yy_buf_size + 2 ,yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in pcap__create_buffer()" ); - - b->yy_is_our_buffer = 1; - - pcap__init_buffer(b,file ,yyscanner); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with pcap__create_buffer() - * @param yyscanner The scanner object. - */ - void pcap__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - pcap_free((void *) b->yy_ch_buf ,yyscanner ); - - pcap_free((void *) b ,yyscanner ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a pcap_restart() or at EOF. - */ - static void pcap__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) - -{ - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - pcap__flush_buffer(b ,yyscanner); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then pcap__init_buffer was _probably_ - * called from pcap_restart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * @param yyscanner The scanner object. - */ - void pcap__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - pcap__load_buffer_state(yyscanner ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * @param yyscanner The scanner object. - */ -void pcap_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - pcap_ensure_buffer_stack(yyscanner); - - /* This block is copied from pcap__switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from pcap__switch_to_buffer. */ - pcap__load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * @param yyscanner The scanner object. - */ -void pcap_pop_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - pcap__delete_buffer(YY_CURRENT_BUFFER ,yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - pcap__load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void pcap_ensure_buffer_stack (yyscan_t yyscanner) -{ - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (!yyg->yy_buffer_stack) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)pcap_alloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in pcap_ensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)pcap_realloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in pcap_ensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE pcap__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) pcap_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in pcap__scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - pcap__switch_to_buffer(b ,yyscanner ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to pcap_lex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * pcap__scan_bytes() instead. - */ -YY_BUFFER_STATE pcap__scan_string (yyconst char * yystr , yyscan_t yyscanner) -{ - - return pcap__scan_bytes(yystr,strlen(yystr) ,yyscanner); -} - -/** Setup the input buffer state to scan the given bytes. The next call to pcap_lex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE pcap__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - yy_size_t i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) pcap_alloc(n ,yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in pcap__scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = pcap__scan_buffer(buf,n ,yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in pcap__scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the user-defined data for this scanner. - * @param yyscanner The scanner object. - */ -YY_EXTRA_TYPE pcap_get_extra (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; -} - -/** Get the current line number. - * @param yyscanner The scanner object. - */ -int pcap_get_lineno (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; -} - -/** Get the current column number. - * @param yyscanner The scanner object. - */ -int pcap_get_column (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; -} - -/** Get the input stream. - * @param yyscanner The scanner object. - */ -FILE *pcap_get_in (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; -} - -/** Get the output stream. - * @param yyscanner The scanner object. - */ -FILE *pcap_get_out (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; -} - -/** Get the length of the current token. - * @param yyscanner The scanner object. - */ -yy_size_t pcap_get_leng (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; -} - -/** Get the current token. - * @param yyscanner The scanner object. - */ - -char *pcap_get_text (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; -} - -/** Set the user-defined data. This data is never touched by the scanner. - * @param user_defined The data to be associated with this scanner. - * @param yyscanner The scanner object. - */ -void pcap_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; -} - -/** Set the current line number. - * @param _line_number line number - * @param yyscanner The scanner object. - */ -void pcap_set_lineno (int _line_number , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "pcap_set_lineno called with no buffer" ); - - yylineno = _line_number; -} - -/** Set the current column. - * @param _column_no column number - * @param yyscanner The scanner object. - */ -void pcap_set_column (int _column_no , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "pcap_set_column called with no buffer" ); - - yycolumn = _column_no; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * @param yyscanner The scanner object. - * @see pcap__switch_to_buffer - */ -void pcap_set_in (FILE * _in_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; -} - -void pcap_set_out (FILE * _out_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; -} - -int pcap_get_debug (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; -} - -void pcap_set_debug (int _bdebug , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; -} - -/* Accessor methods for yylval and yylloc */ - -YYSTYPE * pcap_get_lval (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yylval; -} - -void pcap_set_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yylval = yylval_param; -} - -/* User-visible API */ - -/* pcap_lex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. - */ - -int pcap_lex_init(yyscan_t* ptr_yy_globals) - -{ - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) pcap_alloc ( sizeof( struct yyguts_t ), NULL ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - return yy_init_globals ( *ptr_yy_globals ); -} - -/* pcap_lex_init_extra has the same functionality as pcap_lex_init, but follows the - * convention of taking the scanner as the last argument. Note however, that - * this is a *pointer* to a scanner, as it will be allocated by this call (and - * is the reason, too, why this function also must handle its own declaration). - * The user defined value in the first argument will be available to pcap_alloc in - * the yyextra field. - */ - -int pcap_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) - -{ - struct yyguts_t dummy_yyguts; - - pcap_set_extra (yy_user_defined, &dummy_yyguts); - - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) pcap_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - pcap_set_extra (yy_user_defined, *ptr_yy_globals); - - return yy_init_globals ( *ptr_yy_globals ); -} - -static int yy_init_globals (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from pcap_lex_destroy(), so don't allocate here. - */ - - yyg->yy_buffer_stack = 0; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = (char *) 0; - yyg->yy_init = 0; - yyg->yy_start = 0; - - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * pcap_lex_init() - */ - return 0; -} - -/* pcap_lex_destroy is for both reentrant and non-reentrant scanners. */ -int pcap_lex_destroy (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - pcap__delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - pcap_pop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - pcap_free(yyg->yy_buffer_stack ,yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - pcap_free(yyg->yy_start_stack ,yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * pcap_lex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - pcap_free ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *pcap_alloc (yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return (void *) malloc( size ); -} - -void *pcap_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void pcap_free (void * ptr , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see pcap_realloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 490 "scanner.l" - - - -/* - * Turn diagnostics back on, so we check the code that we've written. - */ -DIAG_ON_FLEX - -/* Hex digit to integer. */ -static inline int -xdtoi(int c) -{ - if (isdigit(c)) - return c - '0'; - else if (islower(c)) - return c - 'a' + 10; - else - return c - 'A' + 10; -} - -/* - * Convert string to integer. Just like atoi(), but checks for - * preceding 0x or 0 and uses hex or octal instead of decimal. - */ -static int -stoi(char *s) -{ - int base = 10; - int n = 0; - - if (*s == '0') { - if (s[1] == 'x' || s[1] == 'X') { - s += 2; - base = 16; - } - else { - base = 8; - s += 1; - } - } - while (*s) - n = n * base + xdtoi(*s++); - - return n; -} - diff --git a/libpcap/scanner.h b/libpcap/scanner.h deleted file mode 100644 index 4ba390794..000000000 --- a/libpcap/scanner.h +++ /dev/null @@ -1,383 +0,0 @@ -#ifndef pcap_HEADER_H -#define pcap_HEADER_H 1 -#define pcap_IN_HEADER 1 - -#line 6 "scanner.h" -/* Must come first for _LARGE_FILE_API on AIX. */ -#ifdef HAVE_CONFIG_H -#include -#endif - -/* - * Must come first to avoid warnings on Windows. - * - * Flex-generated scanners may only include if __STDC_VERSION__ - * is defined with a value >= 199901, meaning "full C99", and MSVC may not - * define it with that value, because it isn't 100% C99-compliant, even - * though it has an capable of defining everything the Flex - * scanner needs. - * - * We, however, will include it if we know we have an MSVC version that has - * it; this means that we may define the INTn_MAX and UINTn_MAX values in - * scanner.c, and then include , which may define them differently - * (same value, but different string of characters), causing compiler warnings. - * - * If we include it here, and they're defined, that'll prevent scanner.c - * from defining them. So we include , to get - * if we have it. - */ -#include - -#include "diag-control.h" - -#line 34 "scanner.h" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void pcap_restart (FILE *input_file ,yyscan_t yyscanner ); -void pcap__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); -void pcap__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void pcap__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void pcap_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -void pcap_pop_buffer_state (yyscan_t yyscanner ); - -YY_BUFFER_STATE pcap__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE pcap__scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner ); - -void *pcap_alloc (yy_size_t ,yyscan_t yyscanner ); -void *pcap_realloc (void *,yy_size_t ,yyscan_t yyscanner ); -void pcap_free (void * ,yyscan_t yyscanner ); - -/* Begin user sect3 */ - -#define pcap_wrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -#define yytext_ptr yytext_r - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#define YY_EXTRA_TYPE compiler_state_t * - -int pcap_lex_init (yyscan_t* scanner); - -int pcap_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int pcap_lex_destroy (yyscan_t yyscanner ); - -int pcap_get_debug (yyscan_t yyscanner ); - -void pcap_set_debug (int debug_flag ,yyscan_t yyscanner ); - -YY_EXTRA_TYPE pcap_get_extra (yyscan_t yyscanner ); - -void pcap_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); - -FILE *pcap_get_in (yyscan_t yyscanner ); - -void pcap_set_in (FILE * _in_str ,yyscan_t yyscanner ); - -FILE *pcap_get_out (yyscan_t yyscanner ); - -void pcap_set_out (FILE * _out_str ,yyscan_t yyscanner ); - -yy_size_t pcap_get_leng (yyscan_t yyscanner ); - -char *pcap_get_text (yyscan_t yyscanner ); - -int pcap_get_lineno (yyscan_t yyscanner ); - -void pcap_set_lineno (int _line_number ,yyscan_t yyscanner ); - -int pcap_get_column (yyscan_t yyscanner ); - -void pcap_set_column (int _column_no ,yyscan_t yyscanner ); - -YYSTYPE * pcap_get_lval (yyscan_t yyscanner ); - -void pcap_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int pcap_wrap (yyscan_t yyscanner ); -#else -extern int pcap_wrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int pcap_lex \ - (YYSTYPE * yylval_param ,yyscan_t yyscanner); - -#define YY_DECL int pcap_lex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#line 490 "scanner.l" - - -#line 382 "scanner.h" -#undef pcap_IN_HEADER -#endif /* pcap_HEADER_H */ diff --git a/libpcap/scanner.l b/libpcap/scanner.l index e0890b43b..effcf815d 100644 --- a/libpcap/scanner.l +++ b/libpcap/scanner.l @@ -311,13 +311,7 @@ mask return NETMASK; port return PORT; portrange return PORTRANGE; proto return PROTO; -protochain { -#ifdef NO_PROTOCHAIN - bpf_error(yyextra, "%s not supported", yytext); -#else - return PROTOCHAIN; -#endif - } +protochain return PROTOCHAIN; gateway return GATEWAY; @@ -397,14 +391,8 @@ hsls return HSLS; "==" return '='; "<<" return LSH; ">>" return RSH; -${B} { yylval->e = pcap_ether_aton(((char *)yytext)+1); - if (yylval->e == NULL) - bpf_error(yyextra, "malloc"); - return AID; } -{MAC} { yylval->e = pcap_ether_aton((char *)yytext); - if (yylval->e == NULL) - bpf_error(yyextra, "malloc"); - return EID; } +${B} { yylval->s = sdup(yyextra, yytext); return AID; } +{MAC} { yylval->s = sdup(yyextra, yytext); return EID; } {N} { yylval->i = stoi((char *)yytext); return NUM; } ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) { yylval->s = sdup(yyextra, (char *)yytext); return HID; } @@ -414,17 +402,20 @@ ${B} { yylval->e = pcap_ether_aton(((char *)yytext)+1); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(yytext, NULL, &hints, &res)) - bpf_error(yyextra, "bogus IPv6 address %s", yytext); - else { + if (getaddrinfo(yytext, NULL, &hints, &res)) { + bpf_set_error(yyextra, "bogus IPv6 address %s", yytext); + yylval->s = NULL; + } else { freeaddrinfo(res); - yylval->s = sdup(yyextra, (char *)yytext); return HID6; + yylval->s = sdup(yyextra, (char *)yytext); } #else - bpf_error(yyextra, "IPv6 address %s not supported", yytext); + bpf_set_error(yyextra, "IPv6 address %s not supported", yytext); + yylval->s = NULL; #endif /*INET6*/ + return HID6; } -{B}:+({B}:+)+ { bpf_error(yyextra, "bogus ethernet address %s", yytext); } +{B}:+({B}:+)+ { bpf_set_error(yyextra, "bogus ethernet address %s", yytext); yylval->s = NULL; return EID; } icmptype { yylval->i = 0; return NUM; } icmpcode { yylval->i = 1; return NUM; } icmp-echoreply { yylval->i = 0; return NUM; } @@ -484,9 +475,7 @@ tcp-cwr { yylval->i = 0x80; return NUM; } [A-Za-z0-9]([-_.A-Za-z0-9]*[.A-Za-z0-9])? { yylval->s = sdup(yyextra, (char *)yytext); return ID; } "\\"[^ !()\n\t]+ { yylval->s = sdup(yyextra, (char *)yytext + 1); return ID; } -[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { - bpf_error(yyextra, "illegal token: %s", yytext); } -. { bpf_error(yyextra, "illegal char '%c'", *yytext); } +. { return LEX_ERROR; } %% /* diff --git a/libpcap/sf-pcap.c b/libpcap/sf-pcap.c index 96cb30801..60c73a899 100644 --- a/libpcap/sf-pcap.c +++ b/libpcap/sf-pcap.c @@ -43,6 +43,7 @@ #include #include #include +#include /* for INT_MAX */ #include "pcap-int.h" @@ -109,6 +110,20 @@ static int pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **datap); +#ifdef _WIN32 +/* + * This isn't exported on Windows, because it would only work if both + * libpcap and the code using it were using the same C runtime; otherwise they + * would be using different definitions of a FILE structure. + * + * Instead we define this as a macro in pcap/pcap.h that wraps the hopen + * version that we do export, passing it a raw OS HANDLE, as defined by the + * Win32 / Win64 ABI, obtained from the _fileno() and _get_osfhandle() + * functions of the appropriate CRT. + */ +static pcap_dumper_t *pcap_dump_fopen(pcap_t *p, FILE *f); +#endif /* _WIN32 */ + /* * Private data for reading pcap savefiles. */ @@ -135,9 +150,10 @@ struct pcap_sf { * relevant information from the header. */ pcap_t * -pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, +pcap_check_header(const uint8_t *magic, FILE *fp, u_int precision, char *errbuf, int *err) { + bpf_u_int32 magic_int; struct pcap_file_header hdr; size_t amt_read; pcap_t *p; @@ -154,11 +170,14 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, * number for a pcap savefile, or for a byte-swapped pcap * savefile. */ - if (magic != TCPDUMP_MAGIC && magic != KUZNETZOV_TCPDUMP_MAGIC && - magic != NSEC_TCPDUMP_MAGIC) { - magic = SWAPLONG(magic); - if (magic != TCPDUMP_MAGIC && magic != KUZNETZOV_TCPDUMP_MAGIC && - magic != NSEC_TCPDUMP_MAGIC) + memcpy(&magic_int, magic, sizeof(magic_int)); + if (magic_int != TCPDUMP_MAGIC && + magic_int != KUZNETZOV_TCPDUMP_MAGIC && + magic_int != NSEC_TCPDUMP_MAGIC) { + magic_int = SWAPLONG(magic_int); + if (magic_int != TCPDUMP_MAGIC && + magic_int != KUZNETZOV_TCPDUMP_MAGIC && + magic_int != NSEC_TCPDUMP_MAGIC) return (NULL); /* nope */ swapped = 1; } @@ -167,7 +186,7 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, * They are. Put the magic number in the header, and read * the rest of the header. */ - hdr.magic = magic; + hdr.magic = magic_int; amt_read = fread(((char *)&hdr) + sizeof hdr.magic, 1, sizeof(hdr) - sizeof(hdr.magic), fp); if (amt_read != sizeof(hdr) - sizeof(hdr.magic)) { @@ -176,9 +195,8 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, errno, "error reading dump file"); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %lu file header bytes, only got %lu", - (unsigned long)sizeof(hdr), - (unsigned long)amt_read); + "truncated dump file; tried to read %" PRIsize " file header bytes, only got %" PRIsize, + sizeof(hdr), amt_read); } *err = 1; return (NULL); @@ -232,20 +250,9 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, p->version_major = hdr.version_major; p->version_minor = hdr.version_minor; p->tzoff = hdr.thiszone; - p->snapshot = hdr.snaplen; - if (p->snapshot <= 0) { - /* - * Bogus snapshot length; use the maximum for this - * link-layer type as a fallback. - * - * XXX - the only reason why snapshot is signed is - * that pcap_snapshot() returns an int, not an - * unsigned int. - */ - p->snapshot = max_snaplen_for_dlt(hdr.linktype); - } p->linktype = linktype_to_dlt(LT_LINKTYPE(hdr.linktype)); p->linktype_ext = LT_LINKTYPE_EXT(hdr.linktype); + p->snapshot = pcap_adjust_snapshot(p->linktype, hdr.snaplen); p->next_packet_op = pcap_next_packet; @@ -260,7 +267,7 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, switch (precision) { case PCAP_TSTAMP_PRECISION_MICRO: - if (magic == NSEC_TCPDUMP_MAGIC) { + if (magic_int == NSEC_TCPDUMP_MAGIC) { /* * The file has nanoseconds, the user * wants microseconds; scale the @@ -277,7 +284,7 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, break; case PCAP_TSTAMP_PRECISION_NANO: - if (magic == NSEC_TCPDUMP_MAGIC) { + if (magic_int == NSEC_TCPDUMP_MAGIC) { /* * The file has nanoseconds, the * user wants nanoseconds; nothing to do. @@ -331,7 +338,7 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, break; } - if (magic == KUZNETZOV_TCPDUMP_MAGIC) { + if (magic_int == KUZNETZOV_TCPDUMP_MAGIC) { /* * XXX - the patch that's in some versions of libpcap * changes the packet header but not the magic number, @@ -371,8 +378,14 @@ pcap_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, * length will be misleading if you use it to figure * out why a capture doesn't have all the packet data, * but there's not much we can do to avoid that. + * + * But don't grow the snapshot length past the + * maximum value of an int. */ - p->snapshot += 14; + if (p->snapshot <= INT_MAX - 14) + p->snapshot += 14; + else + p->snapshot = INT_MAX; } } else ps->hdrsize = sizeof(struct pcap_sf_pkthdr); @@ -450,9 +463,8 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) } else { if (amt_read != 0) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %lu header bytes, only got %lu", - (unsigned long)ps->hdrsize, - (unsigned long)amt_read); + "truncated dump file; tried to read %" PRIsize " header bytes, only got %" PRIsize, + ps->hdrsize, amt_read); return (-1); } /* EOF */ @@ -611,8 +623,8 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) * the read finished. */ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %lu", - p->snapshot, (unsigned long)amt_read); + "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + p->snapshot, amt_read); } return (-1); } @@ -635,8 +647,8 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) "error reading dump file"); } else { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %lu", - hdr->caplen, (unsigned long)bytes_read); + "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + hdr->caplen, bytes_read); } return (-1); } @@ -649,6 +661,9 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) */ hdr->caplen = p->snapshot; } else { + /* + * The packet is within the snapshot length for this file. + */ if (hdr->caplen > p->bufsize) { /* * Grow the buffer to the next power of 2, or @@ -684,8 +699,8 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) "error reading dump file"); } else { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %lu", - hdr->caplen, (unsigned long)amt_read); + "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + hdr->caplen, amt_read); } return (-1); } @@ -817,9 +832,42 @@ pcap_dump_open(pcap_t *p, const char *fname) return (pcap_setup_dump(p, linktype, f, fname)); } +#ifdef _WIN32 +/* + * Initialize so that sf_write() will output to a stream wrapping the given raw + * OS file HANDLE. + */ +pcap_dumper_t * +pcap_dump_hopen(pcap_t *p, intptr_t osfd) +{ + int fd; + FILE *file; + + fd = _open_osfhandle(osfd, _O_APPEND); + if (fd < 0) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "_open_osfhandle"); + return NULL; + } + + file = _fdopen(fd, "wb"); + if (file == NULL) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "_fdopen"); + _close(fd); + return NULL; + } + + return pcap_dump_fopen(p, file); +} +#endif /* _WIN32 */ + /* * Initialize so that sf_write() will output to the given stream. */ +#ifdef _WIN32 +static +#endif /* _WIN32 */ pcap_dumper_t * pcap_dump_fopen(pcap_t *p, FILE *f) { @@ -862,11 +910,19 @@ pcap_dump_open_append(pcap_t *p, const char *fname) return (pcap_setup_dump(p, linktype, stdout, "standard output")); /* + * "a" will cause the file *not* to be truncated if it exists + * but will cause it to be created if it doesn't. It will + * also cause all writes to be done at the end of the file, + * but will allow reads to be done anywhere in the file. This + * is what we need, because we need to read from the beginning + * of the file to see if it already has a header and packets + * or if it doesn't. + * * "b" is supported as of C90, so *all* UN*Xes should support it, * even though it does nothing. It's required on Windows, as the * file is a binary file and must be read in binary mode. */ - f = fopen(fname, "rb+"); + f = fopen(fname, "ab+"); if (f == NULL) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "%s", fname); @@ -875,18 +931,33 @@ pcap_dump_open_append(pcap_t *p, const char *fname) /* * Try to read a pcap header. + * + * We do not assume that the file will be positioned at the + * beginning immediately after we've opened it - we seek to + * the beginning. ISO C says it's implementation-defined + * whether the file position indicator is at the beginning + * or the end of the file after an append-mode open, and + * it wasn't obvious from the Single UNIX Specification + * or the Microsoft documentation how that works on SUS- + * compliant systems or on Windows. */ + if (fseek(f, 0, SEEK_SET) == -1) { + pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, + errno, "Can't seek to the beginning of %s", fname); + (void)fclose(f); + return (NULL); + } amt_read = fread(&ph, 1, sizeof (ph), f); if (amt_read != sizeof (ph)) { if (ferror(f)) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "%s", fname); - fclose(f); + (void)fclose(f); return (NULL); } else if (feof(f) && amt_read > 0) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: truncated pcap file header", fname); - fclose(f); + (void)fclose(f); return (NULL); } } @@ -922,7 +993,7 @@ pcap_dump_open_append(pcap_t *p, const char *fname) if (p->opt.tstamp_precision != PCAP_TSTAMP_PRECISION_MICRO) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different time stamp precision, cannot append to file", fname); - fclose(f); + (void)fclose(f); return (NULL); } break; @@ -931,7 +1002,7 @@ pcap_dump_open_append(pcap_t *p, const char *fname) if (p->opt.tstamp_precision != PCAP_TSTAMP_PRECISION_NANO) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different time stamp precision, cannot append to file", fname); - fclose(f); + (void)fclose(f); return (NULL); } break; @@ -940,7 +1011,7 @@ pcap_dump_open_append(pcap_t *p, const char *fname) case SWAPLONG(NSEC_TCPDUMP_MAGIC): pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different byte order, cannot append to file", fname); - fclose(f); + (void)fclose(f); return (NULL); case KUZNETZOV_TCPDUMP_MAGIC: @@ -949,13 +1020,13 @@ pcap_dump_open_append(pcap_t *p, const char *fname) case SWAPLONG(NAVTEL_TCPDUMP_MAGIC): pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: not a pcap file to which we can append", fname); - fclose(f); + (void)fclose(f); return (NULL); default: pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: not a pcap file", fname); - fclose(f); + (void)fclose(f); return (NULL); } @@ -967,19 +1038,19 @@ pcap_dump_open_append(pcap_t *p, const char *fname) pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: version is %u.%u, cannot append to file", fname, ph.version_major, ph.version_minor); - fclose(f); + (void)fclose(f); return (NULL); } if ((bpf_u_int32)linktype != ph.linktype) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different linktype, cannot append to file", fname); - fclose(f); + (void)fclose(f); return (NULL); } if ((bpf_u_int32)p->snapshot != ph.snaplen) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: different snaplen, cannot append to file", fname); - fclose(f); + (void)fclose(f); return (NULL); } } else { @@ -996,10 +1067,14 @@ pcap_dump_open_append(pcap_t *p, const char *fname) /* * Start writing at the end of the file. + * + * XXX - this shouldn't be necessary, given that we're opening + * the file in append mode, and ISO C specifies that all writes + * are done at the end of the file in that mode. */ if (fseek(f, 0, SEEK_END) == -1) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, - errno, "Can't seek to end of %s", fname); + errno, "Can't seek to the end of %s", fname); (void)fclose(f); return (NULL); } diff --git a/libpcap/sf-pcap.h b/libpcap/sf-pcap.h index e9c7eafa6..bc7150f4f 100644 --- a/libpcap/sf-pcap.h +++ b/libpcap/sf-pcap.h @@ -31,7 +31,7 @@ #ifndef sf_pcap_h #define sf_pcap_h -extern pcap_t *pcap_check_header(bpf_u_int32 magic, FILE *fp, +extern pcap_t *pcap_check_header(const uint8_t *magic, FILE *fp, u_int precision, char *errbuf, int *err); #endif diff --git a/libpcap/sf-pcapng.c b/libpcap/sf-pcapng.c index 8c8e93ecc..afaeb0566 100644 --- a/libpcap/sf-pcapng.c +++ b/libpcap/sf-pcapng.c @@ -85,7 +85,7 @@ struct option_header { * Section Header Block. */ #define BT_SHB 0x0A0D0D0A - +#define BT_SHB_INSANE_MAX 1024U*1024U*1U /* 1MB should be enough */ struct section_header_block { bpf_u_int32 byte_order_magic; u_short major_version; @@ -231,16 +231,21 @@ struct pcap_ng_sf { }; /* - * Maximum block size for a given maximum snapshot length; we calculate - * this based - * - * We define it as the size of an EPB with a max_snaplen-sized - * packet and 128KB of options. + * The maximum block size we start with; we use an arbitrary value of + * 16 MiB. */ -#define MAX_BLOCKSIZE(max_snaplen) (sizeof (struct block_header) + \ - sizeof (struct enhanced_packet_block) + \ - (max_snaplen) + 131072 + \ - sizeof (struct block_trailer)) +#define INITIAL_MAX_BLOCKSIZE (16*1024*1024) + +/* + * Maximum block size for a given maximum snapshot length; we define it + * as the size of an EPB with a max_snaplen-sized packet and 128KB of + * options. + */ +#define MAX_BLOCKSIZE_FOR_SNAPLEN(max_snaplen) \ + (sizeof (struct block_header) + \ + sizeof (struct enhanced_packet_block) + \ + (max_snaplen) + 131072 + \ + sizeof (struct block_trailer)) static void pcap_ng_cleanup(pcap_t *p); static int pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, @@ -261,9 +266,8 @@ read_bytes(FILE *fp, void *buf, size_t bytes_to_read, int fail_on_eof, if (amt_read == 0 && !fail_on_eof) return (0); /* EOF */ pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %lu bytes, only got %lu", - (unsigned long)bytes_to_read, - (unsigned long)amt_read); + "truncated pcapng dump file; tried to read %" PRIsize " bytes, only got %" PRIsize, + bytes_to_read, amt_read); } return (-1); } @@ -276,6 +280,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) struct pcap_ng_sf *ps; int status; struct block_header bhdr; + struct block_trailer *btrlr; u_char *bdata; size_t data_remaining; @@ -290,20 +295,6 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) bhdr.total_length = SWAPLONG(bhdr.total_length); } - /* - * Is this block "too big"? - * - * We choose 16MB as "too big", for now, so that we handle - * "reasonably" large buffers but don't chew up all the - * memory if we read a malformed file. - */ - if (bhdr.total_length > 16*1024*1024) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "pcapng block size %u > maximum %u", - bhdr.total_length, 16*1024*1024); - return (-1); - } - /* * Is this block "too small" - i.e., is it shorter than a block * header plus a block trailer? @@ -311,9 +302,22 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) if (bhdr.total_length < sizeof(struct block_header) + sizeof(struct block_trailer)) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "block in pcapng dump file has a length of %u < %lu", + "block in pcapng dump file has a length of %u < %" PRIsize, bhdr.total_length, - (unsigned long)(sizeof(struct block_header) + sizeof(struct block_trailer))); + sizeof(struct block_header) + sizeof(struct block_trailer)); + return (-1); + } + + /* + * Is the block total length a multiple of 4? + */ + if ((bhdr.total_length % 4) != 0) { + /* + * No. Report that as an error. + */ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "block in pcapng dump file has a length of %u that is not a multiple of 4" PRIsize, + bhdr.total_length); return (-1); } @@ -322,12 +326,13 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) */ if (p->bufsize < bhdr.total_length) { /* - * No - make it big enough, unless it's too big. + * No - make it big enough, unless it's too big, in + * which case we fail. */ void *bigger_buffer; if (bhdr.total_length > ps->max_blocksize) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "block is larger than maximum block size %u", + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "pcapng block size %u > maximum %u", bhdr.total_length, ps->max_blocksize); return (-1); } @@ -349,6 +354,26 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) if (read_bytes(fp, bdata, data_remaining, 1, errbuf) == -1) return (-1); + /* + * Get the block size from the trailer. + */ + btrlr = (struct block_trailer *)(bdata + data_remaining - sizeof (struct block_trailer)); + if (p->swapped) + btrlr->total_length = SWAPLONG(btrlr->total_length); + + /* + * Is the total length from the trailer the same as the total + * length from the header? + */ + if (bhdr.total_length != btrlr->total_length) { + /* + * No. + */ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "block total length in header and trailer don't match"); + return (-1); + } + /* * Initialize the cursor. */ @@ -736,9 +761,10 @@ add_interface(pcap_t *p, struct block_cursor *cursor, char *errbuf) * relevant information from the header. */ pcap_t * -pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, - int *err) +pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision, + char *errbuf, int *err) { + bpf_u_int32 magic_int; size_t amt_read; bpf_u_int32 total_length; bpf_u_int32 byte_order_magic; @@ -760,7 +786,8 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, * Check whether the first 4 bytes of the file are the block * type for a pcapng savefile. */ - if (magic != BT_SHB) { + memcpy(&magic_int, magic, sizeof(magic_int)); + if (magic_int != BT_SHB) { /* * XXX - check whether this looks like what the block * type would be after being munged by mapping between @@ -829,11 +856,14 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, /* * Check the sanity of the total length. */ - if (total_length < sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer)) { + if (total_length < sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer) || + (total_length > BT_SHB_INSANE_MAX)) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "Section Header Block in pcapng dump file has a length of %u < %lu", + "Section Header Block in pcapng dump file has invalid length %" PRIsize " < _%u_ < %u (BT_SHB_INSANE_MAX)", + sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer), total_length, - (unsigned long)(sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer))); + BT_SHB_INSANE_MAX); + *err = 1; return (NULL); } @@ -885,10 +915,10 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, * leaving room for some options. * * If we find a bigger block, we reallocate the buffer, up to - * the maximum size. We start out with a maximum size based - * on a maximum snapshot length of MAXIMUM_SNAPLEN; if we see - * any link-layer header types with a larger maximum snapshot - * length, we boost the maximum. + * the maximum size. We start out with a maximum size of + * INITIAL_MAX_BLOCKSIZE; if we see any link-layer header types + * with a maximum snapshot that results in a larger maximum + * block length, we boost the maximum. */ p->bufsize = 2048; if (p->bufsize < total_length) @@ -900,7 +930,7 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, *err = 1; return (NULL); } - ps->max_blocksize = MAX_BLOCKSIZE(MAXIMUM_SNAPLEN); + ps->max_blocksize = INITIAL_MAX_BLOCKSIZE; /* * Copy the stuff we've read to the buffer, and read the rest @@ -908,12 +938,12 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, */ bhdrp = (struct block_header *)p->buffer; shbp = (struct section_header_block *)((u_char *)p->buffer + sizeof(struct block_header)); - bhdrp->block_type = magic; + bhdrp->block_type = magic_int; bhdrp->total_length = total_length; shbp->byte_order_magic = byte_order_magic; if (read_bytes(fp, - (u_char *)p->buffer + (sizeof(magic) + sizeof(total_length) + sizeof(byte_order_magic)), - total_length - (sizeof(magic) + sizeof(total_length) + sizeof(byte_order_magic)), + (u_char *)p->buffer + (sizeof(magic_int) + sizeof(total_length) + sizeof(byte_order_magic)), + total_length - (sizeof(magic_int) + sizeof(total_length) + sizeof(byte_order_magic)), 1, errbuf) == -1) goto fail; @@ -1010,19 +1040,8 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, done: p->tzoff = 0; /* XXX - not used in pcap */ - p->snapshot = idbp->snaplen; - if (p->snapshot <= 0) { - /* - * Bogus snapshot length; use the maximum for this - * link-layer type as a fallback. - * - * XXX - the only reason why snapshot is signed is - * that pcap_snapshot() returns an int, not an - * unsigned int. - */ - p->snapshot = max_snaplen_for_dlt(idbp->linktype); - } p->linktype = linktype_to_dlt(idbp->linktype); + p->snapshot = pcap_adjust_snapshot(p->linktype, idbp->snaplen); p->linktype_ext = 0; /* @@ -1030,8 +1049,8 @@ done: * snapshot length for this DLT_ is bigger than the current * maximum block size, increase the maximum. */ - if (MAX_BLOCKSIZE(max_snaplen_for_dlt(p->linktype)) > ps->max_blocksize) - ps->max_blocksize = MAX_BLOCKSIZE(max_snaplen_for_dlt(p->linktype)); + if (MAX_BLOCKSIZE_FOR_SNAPLEN(max_snaplen_for_dlt(p->linktype)) > ps->max_blocksize) + ps->max_blocksize = MAX_BLOCKSIZE_FOR_SNAPLEN(max_snaplen_for_dlt(p->linktype)); p->next_packet_op = pcap_ng_next_packet; p->cleanup_op = pcap_ng_cleanup; @@ -1217,7 +1236,13 @@ pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) idbp->linktype); return (-1); } - if ((bpf_u_int32)p->snapshot != idbp->snaplen) { + + /* + * Check against the *adjusted* value of this IDB's + * snapshot length. + */ + if ((bpf_u_int32)p->snapshot != + pcap_adjust_snapshot(p->linktype, idbp->snaplen)) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "an interface has a snapshot length %u different from the type of the first interface", idbp->snaplen); diff --git a/libpcap/sf-pcapng.h b/libpcap/sf-pcapng.h index d99b0d4e4..835082a50 100644 --- a/libpcap/sf-pcapng.h +++ b/libpcap/sf-pcapng.h @@ -26,7 +26,7 @@ #ifndef sf_pcapng_h #define sf_pcapng_h -extern pcap_t *pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, +extern pcap_t *pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision, char *errbuf, int *err); #endif diff --git a/libpcap/sockutils.c b/libpcap/sockutils.c index ef3fe7649..d3e94649d 100644 --- a/libpcap/sockutils.c +++ b/libpcap/sockutils.c @@ -130,44 +130,15 @@ static int sock_ismcastaddr(const struct sockaddr *saddr); */ void sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen) { + if (errbuf == NULL) + return; + #ifdef _WIN32 - int retval; - char message[SOCK_ERRBUF_SIZE]; /* We're forcing "ANSI" */ - - if (errbuf == NULL) - return; - - retval = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_MAX_WIDTH_MASK, - NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - message, sizeof(message) / sizeof(TCHAR), NULL); - - if (retval == 0) - { - if ((caller) && (*caller)) - pcap_snprintf(errbuf, errbuflen, "%sUnable to get the exact error message", caller); - else - pcap_snprintf(errbuf, errbuflen, "Unable to get the exact error message"); - } - else - { - if ((caller) && (*caller)) - pcap_snprintf(errbuf, errbuflen, "%s%s (code %d)", caller, message, errcode); - else - pcap_snprintf(errbuf, errbuflen, "%s (code %d)", message, errcode); - } + pcap_fmt_errmsg_for_win32_err(errbuf, errbuflen, errcode, + "%s", caller); #else - char *message; - - if (errbuf == NULL) - return; - - message = strerror(errcode); - - if ((caller) && (*caller)) - pcap_snprintf(errbuf, errbuflen, "%s%s (code %d)", caller, message, errcode); - else - pcap_snprintf(errbuf, errbuflen, "%s (code %d)", message, errcode); + pcap_fmt_errmsg_for_errno(errbuf, errbuflen, errcode, + "%s", caller); #endif } @@ -180,7 +151,7 @@ void sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen) * * \param caller: a pointer to a user-allocated string which contains a message that has * to be printed *before* the true error message. It could be, for example, 'this error - * comes from the recv() call at line 31'. It may be NULL. + * comes from the recv() call at line 31'. * * \param errbuf: a pointer to an user-allocated buffer that will contain the complete * error message. This buffer has to be at least 'errbuflen' in length. @@ -194,31 +165,30 @@ void sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen) void sock_geterror(const char *caller, char *errbuf, int errbuflen) { #ifdef _WIN32 - if (errbuf == NULL) - return; sock_fmterror(caller, GetLastError(), errbuf, errbuflen); #else - if (errbuf == NULL) - return; sock_fmterror(caller, errno, errbuf, errbuflen); #endif } /* - * \brief It initializes sockets. + * \brief This function initializes the socket mechanism if it hasn't + * already been initialized or reinitializes it after it has been + * cleaned up. * - * This function is pretty useless on UNIX, since socket initialization is not required. - * However it is required on Win32. In UNIX, this function appears to be completely empty. + * On UN*Xes, it doesn't need to do anything; on Windows, it needs to + * initialize Winsock. * - * \param errbuf: a pointer to an user-allocated buffer that will contain the complete - * error message. This buffer has to be at least 'errbuflen' in length. - * It can be NULL; in this case the error cannot be printed. + * \param errbuf: a pointer to an user-allocated buffer that will contain + * the complete error message. This buffer has to be at least 'errbuflen' + * in length. It can be NULL; in this case no error message is supplied. * - * \param errbuflen: length of the buffer that will contains the error. The error message cannot be - * larger than 'errbuflen - 1' because the last char is reserved for the string terminator. + * \param errbuflen: length of the buffer that will contains the error. + * The error message cannot be larger than 'errbuflen - 1' because the + * last char is reserved for the string terminator. * - * \return '0' if everything is fine, '-1' if some errors occurred. The error message is returned - * in the 'errbuf' variable. + * \return '0' if everything is fine, '-1' if some errors occurred. The + * error message is returned in the buffer pointed to by 'errbuf' variable. */ #ifdef _WIN32 int sock_init(char *errbuf, int errbuflen) @@ -240,18 +210,24 @@ int sock_init(char *errbuf, int errbuflen) } sockcount++; + return 0; +} #else int sock_init(char *errbuf _U_, int errbuflen _U_) { -#endif + /* + * Nothing to do on UN*Xes. + */ return 0; } +#endif /* - * \brief It deallocates sockets. + * \brief This function cleans up the socket mechanism if we have no + * sockets left open. * - * This function is pretty useless on UNIX, since socket deallocation is not required. - * However it is required on Win32. In UNIX, this function appears to be completely empty. + * On UN*Xes, it doesn't need to do anything; on Windows, it needs + * to clean up Winsock. * * \return No error values. */ @@ -327,7 +303,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, sock = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol); if (sock == INVALID_SOCKET) { - sock_geterror("socket(): ", errbuf, errbuflen); + sock_geterror("socket()", errbuf, errbuflen); return INVALID_SOCKET; } @@ -350,6 +326,16 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, /* This is a server socket */ if (server) { + /* + * Allow a new server to bind the socket after the old one + * exited, even if lingering sockets are still present. + * + * Don't treat an error as a failure. + */ + int optval = 1; + (void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + (char *)&optval, sizeof (optval)); + #if defined(IPV6_V6ONLY) || defined(IPV6_BINDV6ONLY) /* * Force the use of IPv6-only addresses. @@ -399,7 +385,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, /* WARNING: if the address is a mcast one, I should place the proper Win32 code here */ if (bind(sock, addrinfo->ai_addr, (int) addrinfo->ai_addrlen) != 0) { - sock_geterror("bind(): ", errbuf, errbuflen); + sock_geterror("bind()", errbuf, errbuflen); closesocket(sock); return INVALID_SOCKET; } @@ -407,7 +393,7 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, if (addrinfo->ai_socktype == SOCK_STREAM) if (listen(sock, nconn) == -1) { - sock_geterror("listen(): ", errbuf, errbuflen); + sock_geterror("listen()", errbuf, errbuflen); closesocket(sock); return INVALID_SOCKET; } @@ -444,13 +430,14 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, * We have to retrieve the error message before any other socket call completes, otherwise * the error message is lost */ - sock_geterror(NULL, SocketErrorMessage, sizeof(SocketErrorMessage)); + sock_geterror("Connect to socket failed", + SocketErrorMessage, sizeof(SocketErrorMessage)); /* Returns the numeric address of the host that triggered the error */ sock_getascii_addrport((struct sockaddr_storage *) tempaddrinfo->ai_addr, TmpBuffer, sizeof(TmpBuffer), NULL, 0, NI_NUMERICHOST, TmpBuffer, sizeof(TmpBuffer)); pcap_snprintf(errbufptr, bufspaceleft, - "Is the server properly installed on %s? connect() failed: %s", TmpBuffer, SocketErrorMessage); + "Is the server properly installed on %s? %s", TmpBuffer, SocketErrorMessage); /* In case more then one 'connect' fails, we manage to keep all the error messages */ msglen = strlen(errbufptr); @@ -508,7 +495,7 @@ int sock_close(SOCKET sock, char *errbuf, int errbuflen) */ if (shutdown(sock, SHUT_WR)) { - sock_geterror("shutdown(): ", errbuf, errbuflen); + sock_geterror("shutdown()", errbuf, errbuflen); /* close the socket anyway */ closesocket(sock); return -1; @@ -518,6 +505,157 @@ int sock_close(SOCKET sock, char *errbuf, int errbuflen) return 0; } +/* + * gai_errstring() has some problems: + * + * 1) on Windows, Microsoft explicitly says it's not thread-safe; + * 2) on UN*X, the Single UNIX Specification doesn't say it *is* + * thread-safe, so an implementation might use a static buffer + * for unknown error codes; + * 3) the error message for the most likely error, EAI_NONAME, is + * truly horrible on several platforms ("nodename nor servname + * provided, or not known"? It's typically going to be "not + * known", not "oopsie, I passed null pointers for the host name + * and service name", not to mention they forgot the "neither"); + * + * so we roll our own. + */ +static void +get_gai_errstring(char *errbuf, int errbuflen, const char *prefix, int err, + const char *hostname, const char *portname) +{ + char hostport[PCAP_ERRBUF_SIZE]; + + if (hostname != NULL && portname != NULL) + pcap_snprintf(hostport, PCAP_ERRBUF_SIZE, "%s:%s", + hostname, portname); + else if (hostname != NULL) + pcap_snprintf(hostport, PCAP_ERRBUF_SIZE, "%s", + hostname); + else if (portname != NULL) + pcap_snprintf(hostport, PCAP_ERRBUF_SIZE, ":%s", + portname); + else + pcap_snprintf(hostport, PCAP_ERRBUF_SIZE, ""); + switch (err) + { +#ifdef EAI_ADDRFAMILY + case EAI_ADDRFAMILY: + pcap_snprintf(errbuf, errbuflen, + "%sAddress family for %s not supported", + prefix, hostport); + break; +#endif + + case EAI_AGAIN: + pcap_snprintf(errbuf, errbuflen, + "%s%s could not be resolved at this time", + prefix, hostport); + break; + + case EAI_BADFLAGS: + pcap_snprintf(errbuf, errbuflen, + "%sThe ai_flags parameter for looking up %s had an invalid value", + prefix, hostport); + break; + + case EAI_FAIL: + pcap_snprintf(errbuf, errbuflen, + "%sA non-recoverable error occurred when attempting to resolve %s", + prefix, hostport); + break; + + case EAI_FAMILY: + pcap_snprintf(errbuf, errbuflen, + "%sThe address family for looking up %s was not recognized", + prefix, hostport); + break; + + case EAI_MEMORY: + pcap_snprintf(errbuf, errbuflen, + "%sOut of memory trying to allocate storage when looking up %s", + prefix, hostport); + break; + + /* + * RFC 2553 had both EAI_NODATA and EAI_NONAME. + * + * RFC 3493 has only EAI_NONAME. + * + * Some implementations define EAI_NODATA and EAI_NONAME + * to the same value, others don't. If EAI_NODATA is + * defined and isn't the same as EAI_NONAME, we handle + * EAI_NODATA. + */ +#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME + case EAI_NODATA: + pcap_snprintf(errbuf, errbuflen, + "%sNo address associated with %s", + prefix, hostport); + break; +#endif + + case EAI_NONAME: + pcap_snprintf(errbuf, errbuflen, + "%sThe host name %s couldn't be resolved", + prefix, hostport); + break; + + case EAI_SERVICE: + pcap_snprintf(errbuf, errbuflen, + "%sThe service value specified when looking up %s as not recognized for the socket type", + prefix, hostport); + break; + + case EAI_SOCKTYPE: + pcap_snprintf(errbuf, errbuflen, + "%sThe socket type specified when looking up %s as not recognized", + prefix, hostport); + break; + +#ifdef EAI_SYSTEM + case EAI_SYSTEM: + /* + * Assumed to be UN*X. + */ + pcap_snprintf(errbuf, errbuflen, + "%sAn error occurred when looking up %s: %s", + prefix, hostport, pcap_strerror(errno)); + break; +#endif + +#ifdef EAI_BADHINTS + case EAI_BADHINTS: + pcap_snprintf(errbuf, errbuflen, + "%sInvalid value for hints when looking up %s", + prefix, hostport); + break; +#endif + +#ifdef EAI_PROTOCOL + case EAI_PROTOCOL: + pcap_snprintf(errbuf, errbuflen, + "%sResolved protocol when looking up %s is unknown", + prefix, hostport); + break; +#endif + +#ifdef EAI_OVERFLOW + case EAI_OVERFLOW: + pcap_snprintf(errbuf, errbuflen, + "%sArgument buffer overflow when looking up %s", + prefix, hostport); + break; +#endif + + default: + pcap_snprintf(errbuf, errbuflen, + "%sgetaddrinfo() error %d when looking up %s", + prefix, err, hostport); + break; + } +} + /* * \brief Checks that the address, port and flags given are valids and it returns an 'addrinfo' structure. * @@ -564,17 +702,10 @@ int sock_initaddress(const char *host, const char *port, retval = getaddrinfo(host, port, hints, addrinfo); if (retval != 0) { - /* - * if the getaddrinfo() fails, you have to use gai_strerror(), instead of using the standard - * error routines (errno) in UNIX; Winsock suggests using the GetLastError() instead. - */ if (errbuf) { -#ifdef _WIN32 - sock_geterror("getaddrinfo(): ", errbuf, errbuflen); -#else - pcap_snprintf(errbuf, errbuflen, "getaddrinfo() %s", gai_strerror(retval)); -#endif + get_gai_errstring(errbuf, errbuflen, "", retval, + host, port); } return -1; } @@ -655,7 +786,7 @@ int sock_send(SOCKET sock, const char *buffer, size_t size, if (errbuf) { pcap_snprintf(errbuf, errbuflen, - "Can't send more than %u bytes with sock_recv", + "Can't send more than %u bytes with sock_send", INT_MAX); } return -1; @@ -697,7 +828,7 @@ int sock_send(SOCKET sock, const char *buffer, size_t size, */ return -2; } - sock_fmterror("send(): ", errcode, errbuf, errbuflen); + sock_fmterror("send()", errcode, errbuf, errbuflen); #else errcode = errno; if (errcode == ECONNRESET || errcode == EPIPE) @@ -709,7 +840,7 @@ int sock_send(SOCKET sock, const char *buffer, size_t size, */ return -2; } - sock_fmterror("send(): ", errcode, errbuf, errbuflen); + sock_fmterror("send()", errcode, errbuf, errbuflen); #endif return -1; } @@ -848,7 +979,6 @@ int sock_recv(SOCKET sock, void *buffer, size_t size, int flags, if (size == 0) { - SOCK_DEBUG_MESSAGE("I have been requested to read zero bytes"); return 0; } if (size > INT_MAX) @@ -878,7 +1008,7 @@ int sock_recv(SOCKET sock, void *buffer, size_t size, int flags, if (errno == EINTR) return -3; #endif - sock_geterror("recv(): ", errbuf, errbuflen); + sock_geterror("recv()", errbuf, errbuflen); return -1; } @@ -939,7 +1069,6 @@ int sock_recv_dgram(SOCKET sock, void *buffer, size_t size, if (size == 0) { - SOCK_DEBUG_MESSAGE("I have been requested to read zero bytes"); return 0; } if (size > INT_MAX) @@ -975,7 +1104,7 @@ int sock_recv_dgram(SOCKET sock, void *buffer, size_t size, * supplied to us, the excess data is discarded, * and we'll report an error. */ - sock_geterror("recv(): ", errbuf, errbuflen); + sock_geterror("recv()", errbuf, errbuflen); return -1; } #else /* _WIN32 */ @@ -1008,7 +1137,7 @@ int sock_recv_dgram(SOCKET sock, void *buffer, size_t size, { if (errno == EINTR) return -3; - sock_geterror("recv(): ", errbuf, errbuflen); + sock_geterror("recv()", errbuf, errbuflen); return -1; } #ifdef HAVE_STRUCT_MSGHDR_MSG_FLAGS @@ -1095,8 +1224,6 @@ int sock_discard(SOCKET sock, int size, char *errbuf, int errbuflen) return -1; } - SOCK_DEBUG_MESSAGE("I'm currently discarding data\n"); - return 0; } @@ -1137,6 +1264,7 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage struct addrinfo *addrinfo, *ai_next; char *temphostlist; char *lasts; + int getaddrinfo_failed = 0; /* * The problem is that strtok modifies the original variable by putting '0' at the end of each token @@ -1164,13 +1292,19 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - retval = getaddrinfo(token, "0", &hints, &addrinfo); + retval = getaddrinfo(token, NULL, &hints, &addrinfo); if (retval != 0) { if (errbuf) - pcap_snprintf(errbuf, errbuflen, "getaddrinfo() %s", gai_strerror(retval)); + get_gai_errstring(errbuf, errbuflen, + "Allowed host list error: ", + retval, token, NULL); - SOCK_DEBUG_MESSAGE(errbuf); + /* + * Note that at least one call to getaddrinfo() + * failed. + */ + getaddrinfo_failed = 1; /* Get next token */ token = pcap_strtok_r(NULL, sep, &lasts); @@ -1208,11 +1342,25 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage addrinfo = NULL; } - if (errbuf) - pcap_snprintf(errbuf, errbuflen, "The host is not in the allowed host list. Connection refused."); - free(temphostlist); - return -1; + + if (getaddrinfo_failed) { + /* + * At least one getaddrinfo() call failed; + * treat that as an error, so rpcapd knows + * that it should log it locally as well + * as telling the client about it. + */ + return -2; + } else { + /* + * All getaddrinfo() calls succeeded, but + * the host wasn't in the list. + */ + if (errbuf) + pcap_snprintf(errbuf, errbuflen, "The host is not in the allowed host list. Connection refused."); + return -1; + } } /* No hostlist, so we have to return 'empty list' */ @@ -1311,7 +1459,7 @@ int sock_getmyinfo(SOCKET sock, char *address, int addrlen, char *port, int port if (getsockname(sock, (struct sockaddr *) &mysockaddr, &sockaddrlen) == -1) { - sock_geterror("getsockname(): ", errbuf, errbuflen); + sock_geterror("getsockname()", errbuf, errbuflen); return 0; } @@ -1389,7 +1537,7 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres (memcmp(&((struct sockaddr_in6 *) sockaddr)->sin6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(struct in6_addr)) == 0)) { if (address) - strlcpy(address, SOCKET_NAME_NULL_DAD, addrlen); + pcap_strlcpy(address, SOCKET_NAME_NULL_DAD, addrlen); return retval; } } @@ -1399,19 +1547,19 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres /* If the user wants to receive an error message */ if (errbuf) { - sock_geterror("getnameinfo(): ", errbuf, errbuflen); + sock_geterror("getnameinfo()", errbuf, errbuflen); errbuf[errbuflen - 1] = 0; } if (address) { - strlcpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen); + pcap_strlcpy(address, SOCKET_NO_NAME_AVAILABLE, addrlen); address[addrlen - 1] = 0; } if (port) { - strlcpy(port, SOCKET_NO_PORT_AVAILABLE, portlen); + pcap_strlcpy(port, SOCKET_NO_PORT_AVAILABLE, portlen); port[portlen - 1] = 0; } diff --git a/libpcap/sockutils.h b/libpcap/sockutils.h index 1df1ef7bb..8a45b3df4 100644 --- a/libpcap/sockutils.h +++ b/libpcap/sockutils.h @@ -37,54 +37,11 @@ #pragma once #endif -#ifdef _WIN32 - /* Need windef.h for defines used in winsock2.h under MingW32 */ - #ifdef __MINGW32__ - #include - #endif - #include - #include +#include "pcap/socket.h" - /* - * Winsock doesn't have this UN*X type; it's used in the UN*X - * sockets API. - * - * XXX - do we need to worry about UN*Xes so old that *they* - * don't have it, either? - */ - typedef int socklen_t; -#else +#ifndef _WIN32 /* UN*X */ - #include - #include /* for memset() */ - #include - #include - #include /* DNS lookup */ #include /* close() */ - #include /* errno() */ - #include /* for sockaddr_in, in BSD at least */ - #include - #include - - /*! - * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's - * a file descriptor, and therefore a signed integer. - * We define SOCKET to be a signed integer on UN*X, so that it can - * be used on both platforms. - */ - #ifndef SOCKET - #define SOCKET int - #endif - - /*! - * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET; - * in UN*X, it's -1. - * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on - * both platforms. - */ - #ifndef INVALID_SOCKET - #define INVALID_SOCKET -1 - #endif /*! * \brief In Winsock, the close() call cannot be used on a socket; @@ -122,35 +79,6 @@ int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD, * \{ */ -/* - * \brief DEBUG facility: it prints an error message on the screen (stderr) - * - * This macro prints the error on the standard error stream (stderr); - * if we are working in debug mode (i.e. there is no NDEBUG defined) and we are in - * Microsoft Visual C++, the error message will appear on the MSVC console as well. - * - * When NDEBUG is defined, this macro is empty. - * - * \param msg: the message you want to print. - * - * \param expr: 'false' if you want to abort the program, 'true' it you want - * to print the message and continue. - * - * \return No return values. - */ -#ifdef NDEBUG - #define SOCK_DEBUG_MESSAGE(msg) ((void)0) -#else - #if (defined(_WIN32) && defined(_MSC_VER)) - #include /* for _CrtDbgReport */ - /* Use MessageBox(NULL, msg, "warning", MB_OK)' instead of the other calls if you want to debug a Win32 service */ - /* Remember to activate the 'allow service to interact with desktop' flag of the service */ - #define SOCK_DEBUG_MESSAGE(msg) { _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%s\n", msg); fprintf(stderr, "%s\n", msg); } - #else - #define SOCK_DEBUG_MESSAGE(msg) { fprintf(stderr, "%s\n", msg); } - #endif -#endif - /**************************************************** * * * Exported functions / definitions *