1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-13 19:29:04 +00:00

libdnet stripped and integrated, ARP ping scan starting to work pretty well

This commit is contained in:
fyodor
2005-04-30 05:12:29 +00:00
parent 3922128b12
commit 4d2beed7c3
106 changed files with 65969 additions and 23 deletions

View File

@@ -74,7 +74,8 @@ o Changed from CVS to Subversion source control system (which
o Added 'leet ASCII art to the confugrator! ARTIST NOTE: If you o Added 'leet ASCII art to the confugrator! ARTIST NOTE: If you
think the ASCII art sucks, feel free to send me alternatives. Note think the ASCII art sucks, feel free to send me alternatives. Note
that only people compiling the UNIX source code get the ASCII art. that only people compiling the UNIX source code get the ASCII
art. (ASCII artist unknown).
Nmap 3.81 Nmap 3.81

View File

@@ -18,6 +18,7 @@ CXX = @CXX@
CCOPT = CCOPT =
LIBPCAPDIR = @libpcapdir@ LIBPCAPDIR = @libpcapdir@
LIBPCREDIR = @LIBPCREDIR@ LIBPCREDIR = @LIBPCREDIR@
LIBDNETDIR = @LIBDNETDIR@
INCLS = -I$(LIBPCAPDIR) INCLS = -I$(LIBPCAPDIR)
DEFS = @DEFS@ -DNMAP_VERSION=\"$(NMAP_VERSION)\" -DNMAP_NAME=\"$(NMAP_NAME)\" -DNMAP_URL=\"$(NMAP_URL)\" -DNMAP_PLATFORM=\"$(NMAP_PLATFORM)\" -DNMAPDATADIR=\"$(nmapdatadir)\" DEFS = @DEFS@ -DNMAP_VERSION=\"$(NMAP_VERSION)\" -DNMAP_NAME=\"$(NMAP_NAME)\" -DNMAP_URL=\"$(NMAP_URL)\" -DNMAP_PLATFORM=\"$(NMAP_PLATFORM)\" -DNMAPDATADIR=\"$(nmapdatadir)\"
# For mtrace debugging -- see MTRACE define in main.cc for instructions # For mtrace debugging -- see MTRACE define in main.cc for instructions
@@ -29,7 +30,7 @@ CPPFLAGS = @CPPFLAGS@
# CFLAGS = $(DEFS) $(INCLS) # CFLAGS = $(DEFS) $(INCLS)
STATIC = STATIC =
LDFLAGS = @LDFLAGS@ $(STATIC) LDFLAGS = @LDFLAGS@ $(STATIC)
LIBS = @LIBNBASE_LIBS@ @LIBNSOCK_LIBS@ @LIBPCRE_LIBS@ @LIBPCAP_LIBS@ @OPENSSL_LIBS@ @LIBS@ LIBS = @LIBNBASE_LIBS@ @LIBNSOCK_LIBS@ @LIBPCRE_LIBS@ @LIBPCAP_LIBS@ @OPENSSL_LIBS@ @LIBDNET_LIBS@ @LIBS@
# LIBS = -lefence @LIBS@ # LIBS = -lefence @LIBS@
# LIBS = -lrmalloc @LIBS@ # LIBS = -lrmalloc @LIBS@
SHTOOL = ./shtool SHTOOL = ./shtool
@@ -59,7 +60,7 @@ export DEPS = nmap.h nmap_amigaos.h nmap_error.h targets.h idle_scan.h osscan.h
all: $(TARGET) $(TARGETNMAPFE) all: $(TARGET) $(TARGETNMAPFE)
$(TARGET): $(DEPS) @PCAP_DEPENDS@ @PCRE_DEPENDS@ $(NBASEDIR)/libnbase.a $(NSOCKDIR)/src/libnsock.a $(OBJS) $(TARGET): $(DEPS) @PCAP_DEPENDS@ @PCRE_DEPENDS@ @LIBDNET_DEPENDS@ $(NBASEDIR)/libnbase.a $(NSOCKDIR)/src/libnsock.a $(OBJS)
@echo Compiling nmap @echo Compiling nmap
rm -f $@ rm -f $@
$(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
@@ -71,6 +72,9 @@ FORCE:
$(LIBPCREDIR)/libpcre.a: $(LIBPCREDIR)/Makefile FORCE $(LIBPCREDIR)/libpcre.a: $(LIBPCREDIR)/Makefile FORCE
@echo Compiling libpcre; cd $(LIBPCREDIR) && $(MAKE) @echo Compiling libpcre; cd $(LIBPCREDIR) && $(MAKE)
$(LIBDNETDIR)/src/.libs/libdnet.a: $(LIBDNETDIR)/Makefile FORCE
@echo Compiling libdnet; cd $(LIBDNETDIR) && $(MAKE)
$(LIBPCAPDIR)/libpcap.a: $(LIBPCAPDIR)/Makefile FORCE $(LIBPCAPDIR)/libpcap.a: $(LIBPCAPDIR)/Makefile FORCE
@echo Compiling libpcap; cd $(LIBPCAPDIR) && $(MAKE) @echo Compiling libpcap; cd $(LIBPCAPDIR) && $(MAKE)
@@ -101,7 +105,7 @@ distro:
web: web:
cd scripts && $(MAKE) web cd scripts && $(MAKE) web
clean: @PCAP_CLEAN@ @PCRE_CLEAN@ nmapfe_clean nsock_clean nbase_clean my_clean clean: @PCAP_CLEAN@ @PCRE_CLEAN@ @DNET_CLEAN@ nmapfe_clean nsock_clean nbase_clean my_clean
my_clean: my_clean:
rm -f $(OBJS) $(TARGET) config.cache rm -f $(OBJS) $(TARGET) config.cache
@@ -109,6 +113,8 @@ pcap_clean:
-cd $(LIBPCAPDIR) && $(MAKE) clean -cd $(LIBPCAPDIR) && $(MAKE) clean
pcre_clean: pcre_clean:
-cd $(LIBPCREDIR) && $(MAKE) clean -cd $(LIBPCREDIR) && $(MAKE) clean
dnet_clean
-cd $(LIBDNETDIR) && $(MAKE) clean
nmapfe_clean: nmapfe_clean:
-cd nmapfe && $(MAKE) clean -cd nmapfe && $(MAKE) clean
nbase_clean: nbase_clean:
@@ -119,8 +125,11 @@ pcap_dist_clean:
-cd $(LIBPCAPDIR) && $(MAKE) distclean -cd $(LIBPCAPDIR) && $(MAKE) distclean
pcre_dist_clean: pcre_dist_clean:
-cd $(LIBPCREDIR) && $(MAKE) distclean -cd $(LIBPCREDIR) && $(MAKE) distclean
dnet_dist_clean:
-cd $(LIBDNETDIR) && $(MAKE) distclean
distclean: my_clean my_distclean @PCAP_DIST_CLEAN@ @PCRE_DIST_CLEAN@ @DNET_DIST_CLEAN@
distclean: my_clean my_distclean @PCAP_DIST_CLEAN@ @PCRE_DIST_CLEAN@
my_distclean: my_distclean:
rm -f Makefile Makefile.bak config.h stamp-h stamp-h.in \ rm -f Makefile Makefile.bak config.h stamp-h stamp-h.in \
config.cache config.log config.status config.cache config.log config.status

55
configure vendored
View File

@@ -310,8 +310,9 @@ ac_includes_default="\
#endif" #endif"
ac_subdirs_all="$ac_subdirs_all libpcre" ac_subdirs_all="$ac_subdirs_all libpcre"
ac_subdirs_all="$ac_subdirs_all libdnet-stripped"
ac_subdirs_all="$ac_subdirs_all $nmap_cfg_subdirs" ac_subdirs_all="$ac_subdirs_all $nmap_cfg_subdirs"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS libpcapdir pcredir CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CXXPROG COMPAT_OBJS COMPAT_SRCS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CPP EGREP TARGETNMAPFE INSTALLNMAPFE OPENSSL_LIBS PCAP_DEPENDS PCAP_CLEAN PCAP_DIST_CLEAN LIBPCAP_LIBS subdirs LIBPCRE_LIBS LIBPCREDIR PCRE_DEPENDS PCRE_CLEAN PCRE_DIST_CLEAN NBASEDIR LIBNBASE_LIBS NSOCKDIR LIBNSOCK_LIBS GTK_CONFIG LIBOBJS LTLIBOBJS' ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS libpcapdir pcredir CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CXXPROG COMPAT_OBJS COMPAT_SRCS build build_cpu build_vendor build_os host host_cpu host_vendor host_os CPP EGREP TARGETNMAPFE INSTALLNMAPFE OPENSSL_LIBS PCAP_DEPENDS PCAP_CLEAN PCAP_DIST_CLEAN LIBPCAP_LIBS subdirs LIBPCRE_LIBS LIBPCREDIR PCRE_DEPENDS PCRE_CLEAN PCRE_DIST_CLEAN LIBDNET_LIBS LIBDNETDIR DNET_DEPENDS DNET_CLEAN DNET_DIST_CLEAN NBASEDIR LIBNBASE_LIBS NSOCKDIR LIBNSOCK_LIBS GTK_CONFIG LIBOBJS LTLIBOBJS'
ac_subst_files='' ac_subst_files=''
# Initialize some variables set by options. # Initialize some variables set by options.
@@ -859,6 +860,7 @@ Optional Packages:
--with-openssl=DIR Use optional openssl libs and includes from DIR/lib/ and DIR/include/openssl/) --with-openssl=DIR Use optional openssl libs and includes from DIR/lib/ and DIR/include/openssl/)
--with-libpcap=DIR Look for pcap in DIR/include and DIR/libs --with-libpcap=DIR Look for pcap in DIR/include and DIR/libs
--with-libpcre=DIR Use an existing (compiled) pcre lib from DIR/include and DIR/lib. Specify --with-libpcre=included to always use the version included with Nmap --with-libpcre=DIR Use an existing (compiled) pcre lib from DIR/include and DIR/lib. Specify --with-libpcre=included to always use the version included with Nmap
--with-libdnet=DIR Use an existing (compiled) dnet lib from DIR/include and DIR/lib.
--with-libnbase=DIR Look for nbase include/libs in DIR --with-libnbase=DIR Look for nbase include/libs in DIR
--with-libnsock=DIR Compile and link to libnsock in DIR --with-libnsock=DIR Compile and link to libnsock in DIR
@@ -6308,6 +6310,52 @@ fi
have_dnet=no
requested_included_dnet=no
LIBDNETDIR=libdnet-stripped
# First we test whether they specified libdnet explicitly
# Check whether --with-libdnet or --without-libdnet was given.
if test "${with_libdnet+set}" = set; then
withval="$with_libdnet"
case "$with_libdnet" in
yes)
;;
included)
;;
*)
CXXFLAGS="-I$with_libdnet/include $CXXFLAGS"
LDFLAGS="-L$with_libdnet/lib $LDFLAGS"
have_dnet=yes
;;
esac
fi;
# If they didn't provide location, we use the included one
if test $have_dnet != yes ; then
subdirs="$subdirs libdnet-stripped "
CXXFLAGS="-I$LIBDNETDIR/include $CXXFLAGS"
LIBDNET_LIBS="$LIBDNETDIR/src/.libs/libdnet.a"
DNET_DEPENDS="$LIBDNETDIR/libdnet.a"
DNET_CLEAN="dnet_clean"
DNET_DIST_CLEAN="dnet_dist_clean"
else
LIBDNET_LIBS="-ldnet"
DNET_DEPENDS=""
DNET_CLEAN=""
DNET_DIST_CLEAN=""
fi
echo "$as_me:$LINENO: checking struct ip" >&5 echo "$as_me:$LINENO: checking struct ip" >&5
@@ -8329,6 +8377,11 @@ s,@LIBPCREDIR@,$LIBPCREDIR,;t t
s,@PCRE_DEPENDS@,$PCRE_DEPENDS,;t t s,@PCRE_DEPENDS@,$PCRE_DEPENDS,;t t
s,@PCRE_CLEAN@,$PCRE_CLEAN,;t t s,@PCRE_CLEAN@,$PCRE_CLEAN,;t t
s,@PCRE_DIST_CLEAN@,$PCRE_DIST_CLEAN,;t t s,@PCRE_DIST_CLEAN@,$PCRE_DIST_CLEAN,;t t
s,@LIBDNET_LIBS@,$LIBDNET_LIBS,;t t
s,@LIBDNETDIR@,$LIBDNETDIR,;t t
s,@DNET_DEPENDS@,$DNET_DEPENDS,;t t
s,@DNET_CLEAN@,$DNET_CLEAN,;t t
s,@DNET_DIST_CLEAN@,$DNET_DIST_CLEAN,;t t
s,@NBASEDIR@,$NBASEDIR,;t t s,@NBASEDIR@,$NBASEDIR,;t t
s,@LIBNBASE_LIBS@,$LIBNBASE_LIBS,;t t s,@LIBNBASE_LIBS@,$LIBNBASE_LIBS,;t t
s,@NSOCKDIR@,$NSOCKDIR,;t t s,@NSOCKDIR@,$NSOCKDIR,;t t

View File

@@ -440,6 +440,46 @@ AC_SUBST(PCRE_DEPENDS)
AC_SUBST(PCRE_CLEAN) AC_SUBST(PCRE_CLEAN)
AC_SUBST(PCRE_DIST_CLEAN) AC_SUBST(PCRE_DIST_CLEAN)
have_dnet=no
requested_included_dnet=no
LIBDNETDIR=libdnet-stripped
# First we test whether they specified libdnet explicitly
AC_ARG_WITH(libdnet,
[ --with-libdnet=DIR Use an existing (compiled) dnet lib from DIR/include and DIR/lib.],
[ case "$with_libdnet" in
yes)
;;
included)
;;
*)
CXXFLAGS="-I$with_libdnet/include $CXXFLAGS"
LDFLAGS="-L$with_libdnet/lib $LDFLAGS"
have_dnet=yes
;;
esac]
)
# If they didn't provide location, we use the included one
if test $have_dnet != yes ; then
AC_CONFIG_SUBDIRS( libdnet-stripped )
CXXFLAGS="-I$LIBDNETDIR/include $CXXFLAGS"
LIBDNET_LIBS="$LIBDNETDIR/src/.libs/libdnet.a"
DNET_DEPENDS="$LIBDNETDIR/libdnet.a"
DNET_CLEAN="dnet_clean"
DNET_DIST_CLEAN="dnet_dist_clean"
else
LIBDNET_LIBS="-ldnet"
DNET_DEPENDS=""
DNET_CLEAN=""
DNET_DIST_CLEAN=""
fi
AC_SUBST(LIBDNET_LIBS)
AC_SUBST(LIBDNETDIR)
AC_SUBST(DNET_DEPENDS)
AC_SUBST(DNET_CLEAN)
AC_SUBST(DNET_DIST_CLEAN)
dnl AC_HEADER_TIME dnl AC_HEADER_TIME

View File

@@ -10,5 +10,5 @@
(__ ' /x / x _/ ( \___' \ / (__ ' /x / x _/ ( \___' \ /
, x / ( ' . / . / | \ / , x / ( ' . / . / | \ /
/ / _/ / + / \/ / / _/ / + / \/
' (__/ / (artist unknown) \ ' (__/ / \
NMAP IS A POWERFUL TOOL -- USE CAREFULLY AND REPONSIBLY NMAP IS A POWERFUL TOOL -- USE CAREFULLY AND REPONSIBLY

59
libdnet-stripped/INSTALL Normal file
View File

@@ -0,0 +1,59 @@
*BSD, MacOS X, Linux
--------------------
./configure && make
Solaris, IRIX, BSD/OS, HP-UX, Tru64
-----------------------------------
For firewall support, install Darren Reed's IP Filter package:
http://coombs.anu.edu.au/~avalon/
For tunnel support on Solaris, install the Universal TUN/TAP Driver:
http://vtun.sourceforge.net/tun/
Unixware, AIX
-------------
These ports are incomplete. If anyone can set me up with legitimate
root access to these platforms, it would be most appreciated. :-)
Windows 2000/XP
---------------
For raw Ethernet sending, install the WinPcap driver and DLLs, and
extract their developer pack to a build directory:
http://winpcap.polito.it/install/default.htm
# XXX - unsupported for now
# For tunnel interface support, install the OpenVPN "TAP-Win32 Virtual
# Ethernet Adapter" component (their Windows installer will let you
# install it alone):
#
# http://openvpn.sourceforge.net/
For firewall support, install HSC's PktFilter service:
http://www.hsc.fr/ressources/outils/pktfilter/index.html.en
Most Windows developers should just use the libdnet developer's pack
(with MinGW and MSVC++ libraries) instead of building it themselves.
But for those who really want to know...
To build a MinGW native library (under Cygwin+MinGW):
./configure && make
To build a Microsoft Visual C++ native library and Python module
(again, under Cygwin+MinGW):
./configure
cd python && C:/Python23/python.exe setup.py build
cd ../src && lib /out:dnet.lib *.obj
# $Id: INSTALL,v 1.4 2005/02/15 07:38:19 dugsong Exp $

28
libdnet-stripped/LICENSE Normal file
View File

@@ -0,0 +1,28 @@
Copyright (c) 2000-2004 Dug Song <dugsong@monkey.org>
All rights reserved, all wrongs reversed.
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. The names of the authors and copyright holders may not be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.

652
libdnet-stripped/Makefile Normal file
View File

@@ -0,0 +1,652 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
srcdir = .
top_srcdir = .
pkgdatadir = $(datadir)/libdnet
pkglibdir = $(libdir)/libdnet
pkgincludedir = $(includedir)/libdnet
top_builddir = .
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/dnet-config.in \
$(top_srcdir)/Makefile.am.common $(top_srcdir)/configure \
INSTALL THANKS TODO acconfig.h config/config.guess \
config/config.sub config/install-sh config/ltmain.sh \
config/missing config/mkinstalldirs
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno configure.status.lineno
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES = dnet-config
am__installdirs = "$(DESTDIR)$(bindir)"
binSCRIPT_INSTALL = $(INSTALL_SCRIPT)
SCRIPTS = $(bin_SCRIPTS)
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-exec-recursive install-info-recursive \
install-recursive installcheck-recursive installdirs-recursive \
pdf-recursive ps-recursive uninstall-info-recursive \
uninstall-recursive
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
{ test ! -d $(distdir) \
|| { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
&& rm -fr $(distdir); }; }
DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
ACLOCAL = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
AMTAR = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoconf
AUTOHEADER = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoheader
AUTOMAKE = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CFLAGS = -g -O2 -Wall
CHECKINC =
CHECKLIB =
CPP = gcc -E
CPPFLAGS =
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=none
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = grep -E
EXEEXT =
F77 = g77
FFLAGS = -g -O2
HAVE_CHECK_FALSE =
HAVE_CHECK_TRUE = #
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
LDFLAGS =
LIBOBJS = strlcat$U.o strlcpy$U.o arp-ioctl$U.o eth-linux$U.o fw-ipchains$U.o intf$U.o ip$U.o route-linux$U.o tun-linux$U.o
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LN_S = ln -s
LTLIBOBJS = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
MAINT = #
MAINTAINER_MODE_FALSE =
MAINTAINER_MODE_TRUE = #
MAKEINFO = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run makeinfo
OBJEXT = o
PACKAGE = libdnet
PACKAGE_BUGREPORT =
PACKAGE_NAME =
PACKAGE_STRING =
PACKAGE_TARNAME =
PACKAGE_VERSION =
PATH_SEPARATOR = :
PYTHON =
PYTHON_FALSE =
PYTHON_TRUE = #
RANLIB = ranlib
SET_MAKE =
SHELL = /bin/sh
STRIP = strip
TCLINC =
TCLLIB =
TCL_FALSE =
TCL_TRUE = #
VERSION = 1.10
ac_aux_dir = config
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_CXX = g++
ac_ct_F77 = g77
ac_ct_RANLIB = ranlib
ac_ct_STRIP = strip
am__fastdepCC_FALSE =
am__fastdepCC_TRUE = #
am__fastdepCXX_FALSE =
am__fastdepCXX_TRUE = #
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = x86_64-unknown-linux-gnu
build_alias =
build_cpu = x86_64
build_os = linux-gnu
build_vendor = unknown
datadir = ${prefix}/share
exec_prefix = ${prefix}
host = x86_64-unknown-linux-gnu
host_alias =
host_cpu = x86_64
host_os = linux-gnu
host_vendor = unknown
includedir = ${prefix}/include
infodir = ${prefix}/info
install_sh = /home/fyodor/nmap/libdnet-stripped/config/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
sysconfdir = ${prefix}/etc
target_alias =
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
SUBDIRS = include src
bin_SCRIPTS = dnet-config
EXTRA_DIST = LICENSE Makefile.am.common acconfig.h
CLEANFILES = dnet-config
AUX_DIST = $(ac_aux_dir)/acinclude.m4 \
$(ac_aux_dir)/config.guess \
$(ac_aux_dir)/config.sub \
$(ac_aux_dir)/install-sh \
$(ac_aux_dir)/ltmain.sh \
$(ac_aux_dir)/missing \
$(ac_aux_dir)/mkinstalldirs
all: all-recursive
.SUFFIXES:
am--refresh:
@:
$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
echo ' cd $(srcdir) && $(AUTOMAKE) --foreign '; \
cd $(srcdir) && $(AUTOMAKE) --foreign \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
echo ' $(SHELL) ./config.status'; \
$(SHELL) ./config.status;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) ./config.status --recheck
$(top_srcdir)/configure: # $(am__configure_deps)
cd $(srcdir) && $(AUTOCONF)
$(ACLOCAL_M4): # $(am__aclocal_m4_deps)
cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
dnet-config: $(top_builddir)/config.status $(srcdir)/dnet-config.in
cd $(top_builddir) && $(SHELL) ./config.status $@
install-binSCRIPTS: $(bin_SCRIPTS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_SCRIPTS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
if test -f $$d$$p; then \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " $(binSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(binSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(bindir)/$$f"; \
else :; fi; \
done
uninstall-binSCRIPTS:
@$(NORMAL_UNINSTALL)
@list='$(bin_SCRIPTS)'; for p in $$list; do \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
empty_fix=.; \
else \
include_option=--include; \
empty_fix=; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test ! -f $$subdir/TAGS || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(am__remove_distdir)
mkdir $(distdir)
$(mkdir_p) $(distdir)/. $(distdir)/config
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(mkdir_p) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
distdir) \
|| exit 1; \
fi; \
done
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$(top_distdir)" distdir="$(distdir)" \
dist-hook
-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r $(distdir)
dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
dist-bzip2: distdir
tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
$(am__remove_distdir)
dist-tarZ: distdir
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__remove_distdir)
dist-shar: distdir
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__remove_distdir)
dist-zip: distdir
-rm -f $(distdir).zip
zip -rq $(distdir).zip $(distdir)
$(am__remove_distdir)
dist dist-all: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
distcheck: dist
case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
*.zip*) \
unzip $(distdir).zip ;;\
esac
chmod -R a-w $(distdir); chmod a+w $(distdir)
mkdir $(distdir)/_build
mkdir $(distdir)/_inst
chmod a-w $(distdir)
dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& cd $(distdir)/_build \
&& ../configure --srcdir=.. --prefix="$$dc_install_base" \
$(DISTCHECK_CONFIGURE_FLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
distuninstallcheck \
&& chmod -R a-w "$$dc_install_base" \
&& ({ \
(cd ../.. && umask 077 && mkdir "$$dc_destdir") \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
} || { rm -rf "$$dc_destdir"; exit 1; }) \
&& rm -rf "$$dc_destdir" \
&& $(MAKE) $(AM_MAKEFLAGS) dist \
&& rm -rf $(DIST_ARCHIVES) \
&& $(MAKE) $(AM_MAKEFLAGS) distcleancheck
$(am__remove_distdir)
@(echo "$(distdir) archives ready for distribution: "; \
list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
sed -e '1{h;s/./=/g;p;x;}' -e '$${p;x;}'
distuninstallcheck:
@cd $(distuninstallcheck_dir) \
&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
|| { echo "ERROR: files left after uninstall:" ; \
if test -n "$(DESTDIR)"; then \
echo " (check DESTDIR support)"; \
fi ; \
$(distuninstallcheck_listfiles) ; \
exit 1; } >&2
distcleancheck: distclean
@if test '$(srcdir)' = . ; then \
echo "ERROR: distcleancheck can only run from a VPATH build" ; \
exit 1 ; \
fi
@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
|| { echo "ERROR: files left in build directory after distclean:" ; \
$(distcleancheck_listfiles) ; \
exit 1; } >&2
check-am: all-am
check: check-recursive
all-am: Makefile $(SCRIPTS)
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(bindir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-libtool \
distclean-tags
dvi: dvi-recursive
dvi-am:
html: html-recursive
info: info-recursive
info-am:
install-data-am:
install-exec-am: install-binSCRIPTS
install-info: install-info-recursive
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am: uninstall-binSCRIPTS uninstall-info-am
uninstall-info: uninstall-info-recursive
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am am--refresh check \
check-am clean clean-generic clean-libtool clean-recursive \
ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \
dist-hook dist-shar dist-tarZ dist-zip distcheck distclean \
distclean-generic distclean-libtool distclean-recursive \
distclean-tags distcleancheck distdir distuninstallcheck dvi \
dvi-am html html-am info info-am install install-am \
install-binSCRIPTS install-data install-data-am install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
installdirs-am maintainer-clean maintainer-clean-generic \
maintainer-clean-recursive mostlyclean mostlyclean-generic \
mostlyclean-libtool mostlyclean-recursive pdf pdf-am ps ps-am \
tags tags-recursive uninstall uninstall-am \
uninstall-binSCRIPTS uninstall-info-am
dist-hook:
(cd $(distdir) && mkdir $(ac_aux_dir))
for file in $(AUX_DIST); do \
cp $$file $(distdir)/$$file; \
done
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,25 @@
## $Id: Makefile.am,v 1.7 2004/01/03 08:52:22 dugsong Exp $
include $(top_srcdir)/Makefile.am.common
SUBDIRS = include src
bin_SCRIPTS = dnet-config
EXTRA_DIST = LICENSE Makefile.am.common acconfig.h
CLEANFILES = dnet-config
AUX_DIST = $(ac_aux_dir)/acinclude.m4 \
$(ac_aux_dir)/config.guess \
$(ac_aux_dir)/config.sub \
$(ac_aux_dir)/install-sh \
$(ac_aux_dir)/ltmain.sh \
$(ac_aux_dir)/missing \
$(ac_aux_dir)/mkinstalldirs
dist-hook:
(cd $(distdir) && mkdir $(ac_aux_dir))
for file in $(AUX_DIST); do \
cp $$file $(distdir)/$$file; \
done

View File

@@ -0,0 +1,7 @@
## $Id: Makefile.am.common,v 1.2 2002/12/02 04:05:25 dugsong Exp $
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~

View File

@@ -0,0 +1,652 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = .
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/dnet-config.in \
$(top_srcdir)/Makefile.am.common $(top_srcdir)/configure \
INSTALL THANKS TODO acconfig.h config/config.guess \
config/config.sub config/install-sh config/ltmain.sh \
config/missing config/mkinstalldirs
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno configure.status.lineno
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES = dnet-config
am__installdirs = "$(DESTDIR)$(bindir)"
binSCRIPT_INSTALL = $(INSTALL_SCRIPT)
SCRIPTS = $(bin_SCRIPTS)
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-exec-recursive install-info-recursive \
install-recursive installcheck-recursive installdirs-recursive \
pdf-recursive ps-recursive uninstall-info-recursive \
uninstall-recursive
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
{ test ! -d $(distdir) \
|| { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
&& rm -fr $(distdir); }; }
DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CHECKINC = @CHECKINC@
CHECKLIB = @CHECKLIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
HAVE_CHECK_FALSE = @HAVE_CHECK_FALSE@
HAVE_CHECK_TRUE = @HAVE_CHECK_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PYTHON = @PYTHON@
PYTHON_FALSE = @PYTHON_FALSE@
PYTHON_TRUE = @PYTHON_TRUE@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TCLINC = @TCLINC@
TCLLIB = @TCLLIB@
TCL_FALSE = @TCL_FALSE@
TCL_TRUE = @TCL_TRUE@
VERSION = @VERSION@
ac_aux_dir = @ac_aux_dir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
SUBDIRS = include src
bin_SCRIPTS = dnet-config
EXTRA_DIST = LICENSE Makefile.am.common acconfig.h
CLEANFILES = dnet-config
AUX_DIST = $(ac_aux_dir)/acinclude.m4 \
$(ac_aux_dir)/config.guess \
$(ac_aux_dir)/config.sub \
$(ac_aux_dir)/install-sh \
$(ac_aux_dir)/ltmain.sh \
$(ac_aux_dir)/missing \
$(ac_aux_dir)/mkinstalldirs
all: all-recursive
.SUFFIXES:
am--refresh:
@:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
echo ' cd $(srcdir) && $(AUTOMAKE) --foreign '; \
cd $(srcdir) && $(AUTOMAKE) --foreign \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
echo ' $(SHELL) ./config.status'; \
$(SHELL) ./config.status;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) ./config.status --recheck
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(srcdir) && $(AUTOCONF)
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
dnet-config: $(top_builddir)/config.status $(srcdir)/dnet-config.in
cd $(top_builddir) && $(SHELL) ./config.status $@
install-binSCRIPTS: $(bin_SCRIPTS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_SCRIPTS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
if test -f $$d$$p; then \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " $(binSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(binSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(bindir)/$$f"; \
else :; fi; \
done
uninstall-binSCRIPTS:
@$(NORMAL_UNINSTALL)
@list='$(bin_SCRIPTS)'; for p in $$list; do \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
empty_fix=.; \
else \
include_option=--include; \
empty_fix=; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test ! -f $$subdir/TAGS || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(am__remove_distdir)
mkdir $(distdir)
$(mkdir_p) $(distdir)/. $(distdir)/config
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(mkdir_p) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
distdir) \
|| exit 1; \
fi; \
done
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$(top_distdir)" distdir="$(distdir)" \
dist-hook
-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r $(distdir)
dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
dist-bzip2: distdir
tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
$(am__remove_distdir)
dist-tarZ: distdir
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__remove_distdir)
dist-shar: distdir
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__remove_distdir)
dist-zip: distdir
-rm -f $(distdir).zip
zip -rq $(distdir).zip $(distdir)
$(am__remove_distdir)
dist dist-all: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
distcheck: dist
case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \
GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
*.zip*) \
unzip $(distdir).zip ;;\
esac
chmod -R a-w $(distdir); chmod a+w $(distdir)
mkdir $(distdir)/_build
mkdir $(distdir)/_inst
chmod a-w $(distdir)
dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& cd $(distdir)/_build \
&& ../configure --srcdir=.. --prefix="$$dc_install_base" \
$(DISTCHECK_CONFIGURE_FLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
distuninstallcheck \
&& chmod -R a-w "$$dc_install_base" \
&& ({ \
(cd ../.. && umask 077 && mkdir "$$dc_destdir") \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
} || { rm -rf "$$dc_destdir"; exit 1; }) \
&& rm -rf "$$dc_destdir" \
&& $(MAKE) $(AM_MAKEFLAGS) dist \
&& rm -rf $(DIST_ARCHIVES) \
&& $(MAKE) $(AM_MAKEFLAGS) distcleancheck
$(am__remove_distdir)
@(echo "$(distdir) archives ready for distribution: "; \
list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
sed -e '1{h;s/./=/g;p;x;}' -e '$${p;x;}'
distuninstallcheck:
@cd $(distuninstallcheck_dir) \
&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
|| { echo "ERROR: files left after uninstall:" ; \
if test -n "$(DESTDIR)"; then \
echo " (check DESTDIR support)"; \
fi ; \
$(distuninstallcheck_listfiles) ; \
exit 1; } >&2
distcleancheck: distclean
@if test '$(srcdir)' = . ; then \
echo "ERROR: distcleancheck can only run from a VPATH build" ; \
exit 1 ; \
fi
@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
|| { echo "ERROR: files left in build directory after distclean:" ; \
$(distcleancheck_listfiles) ; \
exit 1; } >&2
check-am: all-am
check: check-recursive
all-am: Makefile $(SCRIPTS)
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(bindir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-libtool \
distclean-tags
dvi: dvi-recursive
dvi-am:
html: html-recursive
info: info-recursive
info-am:
install-data-am:
install-exec-am: install-binSCRIPTS
install-info: install-info-recursive
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am: uninstall-binSCRIPTS uninstall-info-am
uninstall-info: uninstall-info-recursive
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am am--refresh check \
check-am clean clean-generic clean-libtool clean-recursive \
ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \
dist-hook dist-shar dist-tarZ dist-zip distcheck distclean \
distclean-generic distclean-libtool distclean-recursive \
distclean-tags distcleancheck distdir distuninstallcheck dvi \
dvi-am html html-am info info-am install install-am \
install-binSCRIPTS install-data install-data-am install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
installdirs-am maintainer-clean maintainer-clean-generic \
maintainer-clean-recursive mostlyclean mostlyclean-generic \
mostlyclean-libtool mostlyclean-recursive pdf pdf-am ps ps-am \
tags tags-recursive uninstall uninstall-am \
uninstall-binSCRIPTS uninstall-info-am
dist-hook:
(cd $(distdir) && mkdir $(ac_aux_dir))
for file in $(AUX_DIST); do \
cp $$file $(distdir)/$$file; \
done
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,21 @@
$Id$
This is Dug Song's excellent Libdnet networking library version 1.10.
It has been stripped down for inclusion within Nmap as follows:
o Removed the following directories:
python, test, man
o Removed all filenames from EXTRA_libdnet_la_SOURCES sources, as
they aren't needed with GNU automake 1.9.2
o Removed files in now-removed dires that were reference from
configure.in:318
o Ran "aclocal -I . -I config" to regenerate aclocal.m4 with my newer
aclocal.
o Replaced config.guess config.sub and missing in config dir with
versions from Autoconf 2.59.
o Added this NMAP_MODIFICATIONS file.

13
libdnet-stripped/README Normal file
View File

@@ -0,0 +1,13 @@
libdnet
-------
libdnet provides a simplified, portable interface to several low-level
networking routines, including network address manipulation, kernel
arp(4) cache and route(4) table lookup and manipulation, network
firewalling, network interface lookup and manipulation, IP tunnelling,
and raw IP packet and Ethernet frame transmission.
WWW: http://libdnet.sourceforge.net/
$Id: README,v 1.2 2005/02/14 21:00:17 dugsong Exp $

106
libdnet-stripped/THANKS Normal file
View File

@@ -0,0 +1,106 @@
# $Id: THANKS,v 1.10 2005/02/17 02:58:11 dugsong Exp $
many thanks to all the folks who have contributed to libdnet:
Thamer Al-Harbash <tmh@whitefang.com>
excellent bug reports and fearless beta-testing
Marc Bevand <bevand_m@epita.fr>
RFC 768 UDP zero-checksum fix
Michael Coulter <mjc@bitz.ca>
OpenBSD pfioc_pooladdr fix, pf rule deletion bug report
Michael A. Davis <mike@datanerds.net>
win32 code cleanup
Scott Dawson <sdawson@arbor.net>
interface alias fix
Ben Fleis <ben@monkey.org>
constification and code cleanup
Mike Frantzen <frantzen@w4g.org>
dnet hex test module fix
Markus Friedl <markus@openbsd.org>
BSD/OS testing and autoconf fixes
Tangy Gnat <tanggnat@bahamut.synacklabs.net>
missing queue.h
Loren Gorden <loren.gordon@videotron.ca>
many thorough, detailed bug reports and fixes
Eric Jackson <shinobi@monkey.org>
OpenBSD-alpha testing
Juan <juan@foxpaw.com>
plugged BPF fd leak on failure
K2 <k2@ktwo.ca>
HP-UX, OSF1, UnixWare, Solaris x86, Slackware, etc. access
Kirby Kuehl <kkuehl@gmail.com>
win32 and OpenBSD updates
David Lee <david.lee@teracruz.com>
addr_btos() bugfixes
Kuk-hyeon Lee <errai@inzen.com>
C++ support fixes
Robert Lowe <robert.h.lowe@lawrence.edu>
Tru64 access, and allowing me to crash his machine
Dominic Marks <dom@cus.org.uk>
FreeBSD 5 ipfw port fixes
Jose Nazario <jose@biocserver.cwru.edu>
IRIX access, and allowing me to crash his machine
Nergal <nergal@7bulls.com>
TCP sequence number handling fixes
Peter C. Norton <spacey@lenin.nu>
Linux port fixes
plaguez <dube0866@eurobretagne.fr>
for convincing me to write this, and suffering my bad French
NN Poster <nnposter@users.sourceforge.net>
RPM spec file
Niels Provos <provos@monkey.org>
many bugfixes and much encouragement
Andrew Reiter <arr@watson.org>
help with ipfw braindeath
John S <sjohns@users.sourceforge.net>
VPATH build bug report
Federico Sacerdoti <fds@sdsc.edu>
dotted-quad IPv4 netmask support in addr_pton()
Mike Schiffman <mike@infonexus.com>
inspiration via libnet
Matt Smart <smart@monkey.org>
caught pastos
Matt Sommers <mms@arbor.net>
BSD/OS testing
Mike Stolarchuk <mts@off.to>
enlightening discussion of *ntoa optimizations
Greg Taleck <taleck@oz.net>
OpenBSD pf bug reporting
Christophe Ternat <christophe.ternat@rstpacket.org>
route-bsd.c fork() bug report
xs <xs@nitric.net>
NetBSD testing

79
libdnet-stripped/TODO Normal file
View File

@@ -0,0 +1,79 @@
ipfw2 on FreeBSD/5 (5.1 has pf)
optimize port wildcard rules for each firewall type - e.g. using ipf
FR_NONE, pf PF_OP_NONE, etc.
ipchains sleazy exec
audit addr_ntos() for non-zero'd host bits
make *_loop() prevent modification within loop, or modify only
post-iteration
prefix everything with dnet_*, maybe new API with common dnet_t handle?
more documentation and example code
ip-cooked.c: use RTM_RESOLVE for ip_lookup_mac() (GetBestInterface()?)
add a way to enable ip forwarding?
finish IPv6 support everywhere (fw, route, ip6, win32, etc.)
reimplement win32 fw (lost with laptop hd crash!@#$%)
NAT, ipsec interface?
maybe Checkpoint FW-1 support, via OPSEC (hrr)
--------+------+-----+-----+----+----+------+-------+-----+
| addr | arp | eth | fw | ip | intf | route | tun |
--------+------+-----+-----+----+----+------+-------+-----+
openbsd | | | | | | | | |
--------+------+-----+-----+----+----+------+-------+-----+
freebsd | | | | 1 | | | | ? |
--------+------+-----+-----+----+----+------+-------+-----+
netbsd | | | | | | | | ? |
--------+------+-----+-----+----+----+------+-------+-----+
linux | | | | | | | | |
--------+------+-----+-----+----+----+------+-------+-----+
solaris | | | | 7 | | | | ? |
--------+------+-----+-----+----+----+------+-------+-----+
macosx | | | | | | | | ? |
--------+------+-----+-----+----+----+------+-------+-----+
irix | | | | 7 | | | | - |
--------+------+-----+-----+----+----+------+-------+-----+
bsdi | | | | 7 | | | | - |
--------+------+-----+-----+----+----+------+-------+-----+
tru64 | | | | 7 | | | | - |
--------+------+-----+-----+----+----+------+-------+-----+
hp-ux | | | | 7 | | 3 | | - |
--------+------+-----+-----+----+----+------+-------+-----+
win32 | | | | | | 3 | | - |
--------+------+-----+-----+----+----+------+-------+-----+
unixware| | - | 2 | - | - | | 4 | - |
--------+------+-----+-----+----+----+------+-------+-----+
aix | | 5 | - | - | - | | 6 | - |
--------+------+-----+-----+----+----+------+-------+-----+
= works, tested 1 = ipfw support, but no ipfw2
? = untested 2 = eth_send doesn't work
- = unimplemented 3 = intf_set doesn't work
4 = route_loop only works
5 = arp_show doesn't work
6 = route_loop doesn't work
7 = IP Filter should work, but untested
arp-{bsd,ioctl} both b0rked on unixware
eth_send() doesn't allow src mac spoofing on MacOS X (no
BIOCSHDRCMPLT) without patch (http://slagheap.net/etherspoof/),
also b0rked on BSD/OS, says markus. not possible on Tru64?
no support for ICMP code in ipfw, therefore none in fw-ipfw.c
need reliable, legit HP-UX, Unixware, and AIX accounts with root
access to finish the ports to those platforms. i'd be happy to port to
other platforms also, given similar (temporary) access.
$Id: TODO,v 1.25 2005/02/14 21:56:59 dugsong Exp $

View File

@@ -0,0 +1,32 @@
@BOTTOM@
#include <sys/types.h>
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
# include <windows.h>
#endif
#ifdef __svr4__
# define BSD_COMP 1
#endif
#if defined(__osf__) && !defined(_SOCKADDR_LEN)
# define _SOCKADDR_LEN 1
#endif
#ifndef HAVE_INET_PTON
int inet_pton(int, const char *, void *);
#endif
#ifndef HAVE_STRLCAT
int strlcat(char *, const char *, int);
#endif
#ifndef HAVE_STRLCPY
int strlcpy(char *, const char *, int);
#endif
#ifndef HAVE_STRSEP
char *strsep(char **, const char *);
#endif

7010
libdnet-stripped/aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,319 @@
dnl
dnl Check for 4.4 BSD sa_len member in sockaddr struct
dnl
dnl usage: AC_DNET_SOCKADDR_SA_LEN
dnl results: HAVE_SOCKADDR_SA_LEN (defined)
dnl
AC_DEFUN(AC_DNET_SOCKADDR_SA_LEN,
[AC_MSG_CHECKING(for sa_len in sockaddr struct)
AC_CACHE_VAL(ac_cv_dnet_sockaddr_has_sa_len,
AC_TRY_COMPILE([
# ifndef _SOCKADDR_LEN
# define _SOCKADDR_LEN 1
# endif
# include <sys/types.h>
# include <sys/socket.h>],
[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
ac_cv_dnet_sockaddr_has_sa_len=yes,
ac_cv_dnet_sockaddr_has_sa_len=no))
AC_MSG_RESULT($ac_cv_dnet_sockaddr_has_sa_len)
if test $ac_cv_dnet_sockaddr_has_sa_len = yes ; then
AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
[Define if sockaddr struct has sa_len.])
fi])
dnl
dnl Check for sockaddr_in6 struct in <netinet/in.h>
dnl
dnl usage: AC_DNET_SOCKADDR_IN6
dnl results: HAVE_SOCKADDR_IN6
dnl
AC_DEFUN(AC_DNET_SOCKADDR_IN6,
[AC_MSG_CHECKING(for sockaddr_in6 struct in <netinet/in.h>)
AC_CACHE_VAL(ac_cv_dnet_netinet_in_h_has_sockaddr_in6,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>
# include <netinet/in.h>],
[struct sockaddr_in6 sin6; sin6.sin6_family = AF_INET6;],
ac_cv_dnet_netinet_in_h_has_sockaddr_in6=yes,
ac_cv_dnet_netinet_in_h_has_sockaddr_in6=no))
AC_MSG_RESULT($ac_cv_dnet_netinet_in_h_has_sockaddr_in6)
if test $ac_cv_dnet_netinet_in_h_has_sockaddr_in6 = yes ; then
AC_DEFINE(HAVE_SOCKADDR_IN6, 1,
[Define if <netinet/in.h> has sockaddr_in6 struct.])
fi])
dnl
dnl Check for arp_dev member in arpreq struct
dnl
dnl usage: AC_DNET_ARPREQ_ARP_DEV
dnl results: HAVE_ARPREQ_ARP_DEV (defined)
dnl
AC_DEFUN(AC_DNET_ARPREQ_ARP_DEV,
[AC_MSG_CHECKING(for arp_dev in arpreq struct)
AC_CACHE_VAL(ac_cv_dnet_arpreq_has_arp_dev,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>
# include <net/if_arp.h>],
[void *p = ((struct arpreq *)0)->arp_dev],
ac_cv_dnet_arpreq_has_arp_dev=yes,
ac_cv_dnet_arpreq_has_arp_dev=no))
AC_MSG_RESULT($ac_cv_dnet_arpreq_has_arp_dev)
if test $ac_cv_dnet_arpreq_has_arp_dev = yes ; then
AC_DEFINE(HAVE_ARPREQ_ARP_DEV, 1,
[Define if arpreq struct has arp_dev.])
fi])
dnl
dnl Check for rt_msghdr struct in <net/route.h>
dnl
dnl usage: AC_DNET_ROUTE_RT_MSGHDR
dnl results: HAVE_ROUTE_RT_MSGHDR
dnl
AC_DEFUN(AC_DNET_ROUTE_RT_MSGHDR,
[AC_MSG_CHECKING(for rt_msghdr struct in <net/route.h>)
AC_CACHE_VAL(ac_cv_dnet_route_h_has_rt_msghdr,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>
# include <net/if.h>
# include <net/route.h>],
[struct rt_msghdr rtm; rtm.rtm_msglen = 0;],
ac_cv_dnet_route_h_has_rt_msghdr=yes,
ac_cv_dnet_route_h_has_rt_msghdr=no))
AC_MSG_RESULT($ac_cv_dnet_route_h_has_rt_msghdr)
if test $ac_cv_dnet_route_h_has_rt_msghdr = yes ; then
AC_DEFINE(HAVE_ROUTE_RT_MSGHDR, 1,
[Define if <net/route.h> has rt_msghdr struct.])
fi])
dnl
dnl Check for the Berkeley Packet Filter
dnl
dnl usage: AC_DNET_BSD_BPF
dnl results: HAVE_BSD_BPF
dnl
AC_DEFUN(AC_DNET_BSD_BPF,
[AC_MSG_CHECKING(for Berkeley Packet Filter)
AC_CACHE_VAL(ac_cv_dnet_bsd_bpf,
if test -c /dev/bpf0 ; then
ac_cv_dnet_bsd_bpf=yes
else
ac_cv_dnet_bsd_bpf=no
fi)
AC_MSG_RESULT($ac_cv_dnet_bsd_bpf)
if test $ac_cv_dnet_bsd_bpf = yes ; then
AC_DEFINE(HAVE_BSD_BPF, 1,
[Define if you have the Berkeley Packet Filter.])
fi])
dnl
dnl Check for the Linux /proc filesystem
dnl
dnl usage: AC_DNET_LINUX_PROCFS
dnl results: HAVE_LINUX_PROCFS
dnl
AC_DEFUN(AC_DNET_LINUX_PROCFS,
[AC_MSG_CHECKING(for Linux proc filesystem)
AC_CACHE_VAL(ac_cv_dnet_linux_procfs,
if test "x`cat /proc/sys/kernel/ostype 2>&-`" = "xLinux" ; then
ac_cv_dnet_linux_procfs=yes
else
ac_cv_dnet_linux_procfs=no
fi)
AC_MSG_RESULT($ac_cv_dnet_linux_procfs)
if test $ac_cv_dnet_linux_procfs = yes ; then
AC_DEFINE(HAVE_LINUX_PROCFS, 1,
[Define if you have the Linux /proc filesystem.])
fi])
dnl
dnl Check for Linux PF_PACKET sockets
dnl
dnl usage: AC_DNET_LINUX_PF_PACKET
dnl results: HAVE_LINUX_PF_PACKET
dnl
AC_DEFUN(AC_DNET_LINUX_PF_PACKET,
[AC_MSG_CHECKING(for Linux PF_PACKET sockets)
AC_CACHE_VAL(ac_cv_dnet_linux_pf_packet,
if test -f /usr/include/netpacket/packet.h ; then
ac_cv_dnet_linux_pf_packet=yes
else
ac_cv_dnet_linux_pf_packet=no
fi)
AC_MSG_RESULT($ac_cv_dnet_linux_pf_packet)
if test $ac_cv_dnet_linux_pf_packet = yes ; then
AC_DEFINE(HAVE_LINUX_PF_PACKET, 1,
[Define if you have Linux PF_PACKET sockets.])
fi])
dnl
dnl Check for SNMP MIB2 STREAMS (Solaris only?)
dnl
dnl usage: AC_DNET_STREAMS_MIB2
dnl results: HAVE_STREAMS_MIB2
dnl
AC_DEFUN(AC_DNET_STREAMS_MIB2,
[AC_MSG_CHECKING(for SNMP MIB2 STREAMS)
AC_CACHE_VAL(ac_cv_dnet_streams_mib2,
if test -f /usr/include/inet/mib2.h -a -c /dev/ip ; then
ac_cv_dnet_streams_mib2=yes
else
ac_cv_dnet_streams_mib2=no
fi)
AC_MSG_RESULT($ac_cv_dnet_streams_mib2)
if test $ac_cv_dnet_streams_mib2 = yes ; then
AC_DEFINE(HAVE_STREAMS_MIB2, 1,
[Define if you have SNMP MIB2 STREAMS.])
fi])
dnl
dnl Check for route(7) STREAMS (UnixWare only?)
dnl
dnl usage: AC_DNET_STREAMS_ROUTE
dnl results: HAVE_STREAMS_ROUTE
dnl
AC_DEFUN(AC_DNET_STREAMS_ROUTE,
[AC_MSG_CHECKING(for route(7) STREAMS)
AC_CACHE_VAL(ac_cv_dnet_streams_route,
if grep RTSTR_SEND /usr/include/net/route.h >/dev/null 2>&1 ; then
ac_cv_dnet_streams_route=yes
else
ac_cv_dnet_streams_route=no
fi)
AC_MSG_RESULT($ac_cv_dnet_streams_route)
if test $ac_cv_dnet_streams_route = yes ; then
AC_DEFINE(HAVE_STREAMS_ROUTE, 1,
[Define if you have route(7) STREAMS.])
fi])
dnl
dnl Check for arp(7) ioctls
dnl
dnl usage: AC_DNET_IOCTL_ARP
dnl results: HAVE_IOCTL_ARP
dnl
AC_DEFUN(AC_DNET_IOCTL_ARP,
[AC_MSG_CHECKING(for arp(7) ioctls)
AC_CACHE_VAL(ac_cv_dnet_ioctl_arp,
AC_EGREP_CPP(werd, [
# include <sys/types.h>
# define BSD_COMP
# include <sys/ioctl.h>
# ifdef SIOCGARP
werd
# endif],
ac_cv_dnet_ioctl_arp=yes,
ac_cv_dnet_ioctl_arp=no))
case "$host_os" in
irix*)
ac_cv_dnet_ioctl_arp=no ;;
esac
AC_MSG_RESULT($ac_cv_dnet_ioctl_arp)
if test $ac_cv_dnet_ioctl_arp = yes ; then
AC_DEFINE(HAVE_IOCTL_ARP, 1,
[Define if you have arp(7) ioctls.])
fi])
dnl
dnl Check for raw IP sockets ip_{len,off} host byte ordering
dnl
dnl usage: AC_DNET_RAWIP_HOST_OFFLEN
dnl results: HAVE_RAWIP_HOST_OFFLEN
dnl
AC_DEFUN(AC_DNET_RAWIP_HOST_OFFLEN,
[AC_MSG_CHECKING([for raw IP sockets ip_{len,off} host byte ordering])
AC_CACHE_VAL(ac_cv_dnet_rawip_host_offlen, [
case "$host_os" in
*openbsd*)
ac_cv_dnet_rawip_host_offlen=no ;;
*bsd*|*osf*|*unixware*)
ac_cv_dnet_rawip_host_offlen=yes ;;
*)
ac_cv_dnet_rawip_host_offlen=no ;;
esac])
AC_MSG_RESULT($ac_cv_dnet_rawip_host_offlen)
if test $ac_cv_dnet_rawip_host_offlen = yes ; then
AC_DEFINE(HAVE_RAWIP_HOST_OFFLEN, 1,
[Define if raw IP sockets require host byte ordering for ip_off, ip_len.])
fi])
dnl
dnl Check for cooked raw IP sockets
dnl
dnl usage: AC_DNET_RAWIP_COOKED
dnl results: HAVE_RAWIP_COOKED
dnl
AC_DEFUN(AC_DNET_RAWIP_COOKED,
[AC_MSG_CHECKING(for cooked raw IP sockets)
AC_CACHE_VAL(ac_cv_dnet_rawip_cooked, [
case "$host_os" in
solaris*|irix*)
ac_cv_dnet_rawip_cooked=yes ;;
*)
ac_cv_dnet_rawip_cooked=no ;;
esac])
AC_MSG_RESULT($ac_cv_dnet_rawip_cooked)
if test $ac_cv_dnet_rawip_cooked = yes ; then
AC_DEFINE(HAVE_RAWIP_COOKED, 1,
[Define if you have cooked raw IP sockets.])
fi])
dnl
dnl AC_LBL_LIBRARY_NET
dnl
dnl This test is for network applications that need socket() and
dnl gethostbyname() -ish functions. Under Solaris, those applications
dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
dnl with "-lnsl" but should *not* link with "-lsocket" because
dnl libsocket.a breaks a number of things (for instance:
dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
dnl versions of IRIX).
dnl
dnl Unfortunately, many application developers are not aware of this,
dnl and mistakenly write tests that cause -lsocket to be used under
dnl IRIX. It is also easy to write tests that cause -lnsl to be used
dnl under operating systems where neither are necessary (or useful),
dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
dnl
dnl This test exists so that every application developer does not test
dnl this in a different, and subtly broken fashion.
dnl It has been argued that this test should be broken up into two
dnl seperate tests, one for the resolver libraries, and one for the
dnl libraries necessary for using Sockets API. Unfortunately, the two
dnl are carefully intertwined and allowing the autoconf user to use
dnl them independantly potentially results in unfortunate ordering
dnl dependancies -- as such, such component macros would have to
dnl carefully use indirection and be aware if the other components were
dnl executed. Since other autoconf macros do not go to this trouble,
dnl and almost no applications use sockets without the resolver, this
dnl complexity has not been implemented.
dnl
dnl The check for libresolv is in case you are attempting to link
dnl statically and happen to have a libresolv.a lying around (and no
dnl libnsl.a).
dnl
AC_DEFUN(AC_LBL_LIBRARY_NET, [
# Most operating systems have gethostbyname() in the default searched
# libraries (i.e. libc):
AC_CHECK_FUNC(gethostbyname, ,
# Some OSes (eg. Solaris) place it in libnsl:
AC_CHECK_LIB(nsl, gethostbyname, ,
# Some strange OSes (SINIX) have it in libsocket:
AC_CHECK_LIB(socket, gethostbyname, ,
# Unfortunately libsocket sometimes depends on libnsl.
# AC_CHECK_LIB's API is essentially broken so the
# following ugliness is necessary:
AC_CHECK_LIB(socket, gethostbyname,
LIBS="-lsocket -lnsl $LIBS",
AC_CHECK_LIB(resolv, gethostbyname),
-lnsl))))
AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
-lnsl)))
# DLPI needs putmsg under HPUX so test for -lstr while we're at it
AC_CHECK_LIB(str, putmsg)
])

1410
libdnet-stripped/config/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

1510
libdnet-stripped/config/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,295 @@
#!/bin/sh
# install - install a program, script, or datafile
scriptversion=2003-09-24.23
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=
transform_arg=
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=
chgrpcmd=
stripcmd=
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=
dst=
dir_arg=
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
or: $0 -d DIR1 DIR2...
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
In the second, create the directory path DIR.
Options:
-b=TRANSFORMBASENAME
-c copy source (using $cpprog) instead of moving (using $mvprog).
-d create directories instead of installing files.
-g GROUP $chgrp installed files to GROUP.
-m MODE $chmod installed files to MODE.
-o USER $chown installed files to USER.
-s strip installed files (using $stripprog).
-t=TRANSFORM
--help display this help and exit.
--version display version info and exit.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
"
while test -n "$1"; do
case $1 in
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
-c) instcmd=$cpprog
shift
continue;;
-d) dir_arg=true
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
--help) echo "$usage"; exit 0;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-s) stripcmd=$stripprog
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
--version) echo "$0 $scriptversion"; exit 0;;
*) if test -z "$src"; then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if test -z "$src"; then
echo "$0: no input file specified." >&2
exit 1
fi
# Protect names starting with `-'.
case $src in
-*) src=./$src ;;
esac
if test -n "$dir_arg"; then
dst=$src
src=
if test -d "$dst"; then
instcmd=:
chmodcmd=
else
instcmd=$mkdirprog
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dst"; then
echo "$0: no destination specified." >&2
exit 1
fi
# Protect names starting with `-'.
case $dst in
-*) dst=./$dst ;;
esac
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
dst=$dst/`basename "$src"`
fi
fi
# This sed command emulates the dirname command.
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# Skip lots of stat calls in the usual case.
if test ! -d "$dstdir"; then
defaultIFS='
'
IFS="${IFS-$defaultIFS}"
oIFS=$IFS
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS=$oIFS
pathcomp=
while test $# -ne 0 ; do
pathcomp=$pathcomp$1
shift
test -d "$pathcomp" || $mkdirprog "$pathcomp"
pathcomp=$pathcomp/
done
fi
if test -n "$dir_arg"; then
$doit $instcmd "$dst" \
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
else
# If we're going to rename the final executable, determine the name now.
if test -z "$transformarg"; then
dstfile=`basename "$dst"`
else
dstfile=`basename "$dst" $transformbasename \
| sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename.
test -z "$dstfile" && dstfile=`basename "$dst"`
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
trap '(exit $?); exit' 1 2 13 15
# Move or copy the file name to the temp name
$doit $instcmd "$src" "$dsttmp" &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
# Now remove or move aside any old file at destination location. We
# try this two ways since rm can't unlink itself on some systems and
# the destination file might be busy for other reasons. In this case,
# the final cleanup might fail but the new file should still install
# successfully.
{
if test -f "$dstdir/$dstfile"; then
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
|| {
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
(exit 1); exit
}
else
:
fi
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
fi &&
# The final little trick to "correctly" pass the exit status to the exit trap.
{
(exit 0); exit
}
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

File diff suppressed because it is too large Load Diff

360
libdnet-stripped/config/missing Executable file
View File

@@ -0,0 +1,360 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
scriptversion=2003-09-02.23
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003
# Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# 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 2, 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
run=:
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
else
configure_ac=configure.in
fi
msg="missing on your system"
case "$1" in
--run)
# Try to run requested program, and just exit if it succeeds.
run=
shift
"$@" && exit 0
# Exit code 63 means version mismatch. This often happens
# when the user try to use an ancient version of a tool on
# a file that requires a minimum version. In this case we
# we should proceed has if the program had been absent, or
# if --run hadn't been passed.
if test $? = 63; then
run=:
msg="probably too old"
fi
;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case "$1" in
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
Send bug reports to <bug-automake@gnu.org>."
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing $scriptversion (GNU Automake)"
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
aclocal*)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case "$f" in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake*)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
autom4te)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
You can get \`$1' as part of \`Autoconf' from any GNU
archive site."
file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo "#! /bin/sh"
echo "# Created by GNU Automake missing as a replacement of"
echo "# $ $@"
echo "exit 0"
chmod +x $file
exit 1
fi
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if [ ! -f y.tab.h ]; then
echo >y.tab.h
fi
if [ ! -f y.tab.c ]; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if [ ! -f lex.yy.c ]; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
help2man)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
fi
if [ -f "$file" ]; then
touch $file
else
test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page"
exit 1
fi
;;
makeinfo)
if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
# We have makeinfo, but it failed.
exit 1
fi
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
fi
touch $file
;;
tar)
shift
if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run"
exit 1
fi
# We have already tried tar in the generic part.
# Look for gnutar/gtar before invocation to avoid ugly error
# messages.
if (gnutar --version > /dev/null 2>&1); then
gnutar "$@" && exit 0
fi
if (gtar --version > /dev/null 2>&1); then
gtar "$@" && exit 0
fi
firstarg="$1"
if shift; then
case "$firstarg" in
*o*)
firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" "$@" && exit 0
;;
esac
case "$firstarg" in
*h*)
firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" "$@" && exit 0
;;
esac
fi
echo 1>&2 "\
WARNING: I can't seem to be able to run \`tar' with the given arguments.
You may want to install GNU tar or Free paxutils, or check the
command line arguments."
exit 1
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@@ -0,0 +1,137 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain.
scriptversion=2003-09-26.19
errstatus=0
dirmode=""
usage="\
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
Create each directory DIR (with mode MODE, if specified), including all
leading file name components.
"
# process command line arguments
while test $# -gt 0 ; do
case $1 in
-h | --help | --h*) # -h for help
echo "$usage"
exit 0
;;
-m) # -m PERM arg
shift
test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
dirmode=$1
shift
;;
--version)
echo "$0 $scriptversion"
exit 0
;;
--) # stop option processing
shift
break
;;
-*) # unknown option
echo "$usage" 1>&2
exit 1
;;
*) # first non-opt arg
break
;;
esac
done
for file
do
if test -d "$file"; then
shift
else
break
fi
done
case $# in
0) exit 0 ;;
esac
case $dirmode in
'')
if mkdir -p -- . 2>/dev/null; then
echo "mkdir -p -- $*"
exec mkdir -p -- "$@"
else
# On NextStep and OpenStep, the `mkdir' command does not
# recognize any option. It will interpret all options as
# directories to create, and then abort because `.' already
# exists.
test -d ./-p && rmdir ./-p
test -d ./-- && rmdir ./--
fi
;;
*)
if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
echo "mkdir -m $dirmode -p -- $*"
exec mkdir -m "$dirmode" -p -- "$@"
else
# Clean up after NextStep and OpenStep mkdir.
for d in ./-m ./-p ./-- "./$dirmode";
do
test -d $d && rmdir $d
done
fi
;;
esac
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case $pathcomp in
-*) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp"
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
else
if test ! -z "$dirmode"; then
echo "chmod $dirmode $pathcomp"
lasterr=""
chmod "$dirmode" "$pathcomp" || lasterr=$?
if test ! -z "$lasterr"; then
errstatus=$lasterr
fi
fi
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

24305
libdnet-stripped/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,320 @@
dnl
dnl configure.in
dnl
dnl Copyright (c) 2000 Dug Song <dugsong@monkey.org>
dnl
dnl $Id: configure.in,v 1.64 2005/02/25 23:05:09 dugsong Exp $
AC_INIT(include/dnet.h)
AC_CONFIG_AUX_DIR(config)
AC_SUBST(ac_aux_dir)
AM_INIT_AUTOMAKE(libdnet, 1.10)
AM_CONFIG_HEADER(include/config.h)
dnl XXX - stop the insanity!@#$
AM_MAINTAINER_MODE
dnl Check for system type.
dnl XXX - we do this to qualify our later feature checks, since some
dnl systems claim to support multiple features, but are quite b0rked.
AC_CANONICAL_HOST
dnl Initialize prefix.
if test "$prefix" = "NONE"; then
prefix="/usr/local"
fi
dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_LIBTOOL_DLOPEN
AM_PROG_LIBTOOL
dnl Checks for Python.
dnl XXX - use AM_PATH_PYTHON after automake upgrade
AC_MSG_CHECKING(for Python)
AC_ARG_WITH(python,
[ --with-python=DIR build Python module (using python in DIR)],
[ case "$withval" in
yes)
AC_MSG_RESULT(yes)
PYTHON="python"
;;
no)
AC_MSG_RESULT(no)
;;
*)
AC_MSG_RESULT($withval)
for subdir in . bin; do
if test -x $withval/$subdir/python; then
owd=`pwd`
if cd $withval/$subdir; then withval=`pwd`; cd $owd; fi
PYTHON="$withval/python"
break
fi
done
if test "x$PYTHON" = "x"; then
AC_ERROR(python not found in $withval)
fi
;;
esac
])
AC_SUBST(PYTHON)
AC_SUBST(TCLINC)
AC_SUBST(TCLLIB)
AM_CONDITIONAL(PYTHON, [test "x$PYTHON" != "x"])
AM_CONDITIONAL(TCL, [test "x$TCLINC" != "x"])
dnl XXX - stupid IRIX cpp
if test -r /usr/include/sgidefs.h ; then
CPPFLAGS="$CPPFLAGS -D__sgi"
fi
dnl XXX - we need MingW32 under Cygwin for win32
AC_CYGWIN
if test "$CYGWIN" = yes ; then
if test -d /usr/include/mingw ; then
CPPFLAGS="$CPPFLAGS -mno-cygwin"
CFLAGS="$CFLAGS -mno-cygwin"
AC_DEFINE(WIN32_LEAN_AND_MEAN, 1,
[Define for faster code generation.])
AC_CHECK_LIB(ws2_32, main)
AC_CHECK_LIB(iphlpapi, main)
AC_DEFINE(snprintf, _snprintf,
[Use MingW32's internal snprintf])
else
AC_MSG_ERROR([need MingW32 package to build under Cygwin])
fi
AC_MSG_CHECKING(for WinPcap developer's pack)
AC_ARG_WITH(wpdpack,
[ --with-wpdpack=DIR use WinPcap developer's pack in DIR],
[ AC_MSG_RESULT($withval)
if test -f $withval/include/packet32.h -a -f $withval/lib/packet.lib; then
owd=`pwd`
if cd $withval; then withval=`pwd`; cd $owd; fi
CFLAGS="$CFLAGS -I$withval/include"
LIBS="$LIBS -L$withval/lib -lpacket"
else
AC_MSG_ERROR(packet32.h or packet.lib not found in $withval)
fi ],
[ for dir in ${prefix} ${HOME}/WPdpack ; do
if test -f ${dir}/include/packet32.h -a -f ${dir}/lib/packet.lib; then
CFLAGS="$CFLAGS -I${dir}/include"
LIBS="$LIBS -L${dir}/lib -lpacket"
have_pcap=yes
break;
fi
done
if test "$have_pcap" != yes; then
AC_MSG_ERROR(WinPcap developer's pack not found)
fi
AC_MSG_RESULT(yes) ])
fi
dnl Checks for libraries.
if test "$CYGWIN" != yes ; then
AC_LBL_LIBRARY_NET
AC_CHECK_LIB(nm, open_mib)
fi
dnl Checks for Check.
AC_MSG_CHECKING(for Check)
AC_ARG_WITH(check,
[ --with-check=DIR use Check (http://check.sf.net) in DIR],
[ case "$withval" in
yes|no)
AC_MSG_RESULT(no)
;;
*)
AC_MSG_RESULT($withval)
if test -f $withval/include/check.h -a -f $withval/lib/libcheck.a; then
owd=`pwd`
if cd $withval; then withval=`pwd`; cd $owd; fi
CHECKINC="-I$withval/include"
CHECKLIB="-L$withval/lib -lcheck"
elif test -f $withval/src/check.h -a -f $withval/src/libcheck.a; then
owd=`pwd`
if cd $withval; then withval=`pwd`; cd $owd; fi
CHECKINC="-I$withval/src"
CHECKLIB="-L$withval/src -lcheck"
else
AC_ERROR(check.h or libcheck.a not found in $withval)
fi
;;
esac ],
[ if test -f ${prefix}/include/check.h -a -f ${prefix}/lib/libcheck.a; then
CHECKINC="-I${prefix}/include"
CHECKLIB="-L${prefix}/lib -lcheck"
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
])
AC_SUBST(CHECKINC)
AC_SUBST(CHECKLIB)
AM_CONDITIONAL(HAVE_CHECK, test "x$CHECKLIB" != "x")
dnl Checks for header files.
AC_HEADER_STDC
if test "$CYGWIN" = yes ; then
AC_CHECK_HEADERS(Iphlpapi.h winsock2.h)
else
AC_CHECK_HEADERS(fcntl.h unistd.h)
AC_CHECK_HEADERS(sys/bufmod.h sys/dlpi.h sys/dlpihdr.h sys/dlpi_ext.h \
sys/ioctl.h sys/mib.h sys/ndd_var.h sys/socket.h sys/sockio.h \
sys/sysctl.h sys/time.h)
AC_CHECK_HEADERS(net/bpf.h net/if.h net/if_var.h \
net/if_arp.h net/if_dl.h net/pfilt.h \
net/pfvar.h net/radix.h net/raw.h net/route.h netinet/in_var.h \
net/if_tun.h linux/if_tun.h netinet/ip_fw.h linux/ip_fw.h \
linux/ip_fwchains.h linux/netfilter_ipv4/ipchains_core.h)
AC_CHECK_HEADERS(ip_fil_compat.h netinet/ip_fil_compat.h ip_compat.h \
netinet/ip_compat.h ip_fil.h netinet/ip_fil.h)
AC_CHECK_HEADERS(hpsecurity.h stropts.h)
fi
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_DNET_SOCKADDR_IN6
if test "$ac_cv_header_sys_socket_h" = yes ; then
AC_DNET_SOCKADDR_SA_LEN
fi
if test "$ac_cv_header_net_if_arp_h" = yes ; then
AC_DNET_ARPREQ_ARP_DEV
fi
if test "$ac_cv_header_net_route_h" = yes ; then
AC_DNET_ROUTE_RT_MSGHDR
fi
AC_PROG_GCC_TRADITIONAL
if test "$GCC" = yes ; then
CFLAGS="$CFLAGS -Wall"
fi
dnl Checks for library functions.
AC_FUNC_MEMCMP
AC_REPLACE_FUNCS(err strlcat strlcpy strsep)
dnl Checks for other system-specific jonks.
if test "$CYGWIN" != yes ; then
AC_DNET_BSD_BPF
AC_DNET_LINUX_PROCFS
AC_DNET_LINUX_PF_PACKET
AC_DNET_STREAMS_MIB2
AC_DNET_STREAMS_ROUTE
AC_DNET_IOCTL_ARP
AC_DNET_RAWIP_HOST_OFFLEN
AC_DNET_RAWIP_COOKED
fi
dnl Check for arp interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([arp-win32])
elif test "$ac_cv_dnet_ioctl_arp" = yes ; then
AC_LIBOBJ([arp-ioctl])
elif test "$ac_cv_dnet_route_h_has_rt_msghdr" = yes ; then
AC_LIBOBJ([arp-bsd])
else
AC_LIBOBJ([arp-none])
fi
dnl Check for Ethernet interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([eth-win32])
elif test "$ac_cv_header_net_pfilt_h" = yes ; then
AC_LIBOBJ([eth-pfilt])
elif test "$ac_cv_dnet_bsd_bpf" = yes ; then
AC_LIBOBJ([eth-bsd])
elif test "$ac_cv_dnet_linux_pf_packet" = yes ; then
AC_LIBOBJ([eth-linux])
elif test "$ac_cv_header_net_raw_h" = yes ; then
AC_LIBOBJ([eth-snoop])
elif test "$ac_cv_header_sys_ndd_var_h" = yes ; then
AC_LIBOBJ([eth-ndd])
elif test "$ac_cv_header_sys_dlpi_h" = yes || \
test "$ac_cv_header_sys_dlpihdr_h" = yes ; then
AC_LIBOBJ([eth-dlpi])
else
AC_LIBOBJ([eth-none])
fi
dnl Check for firewall interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([fw-pktfilter])
elif test "$ac_cv_header_net_pfvar_h" = yes ; then
AC_LIBOBJ([fw-pf])
elif test "$ac_cv_header_netinet_ip_fw_h" = yes ; then
dnl XXX - ipfw2 support later...
case "$host_os" in
*freebsd5*)
AC_LIBOBJ([fw-none]) ;;
*)
AC_LIBOBJ([fw-ipfw]) ;;
esac
elif test "$ac_cv_header_netinet_ip_fil_h" = yes ; then
AC_LIBOBJ([fw-ipf])
elif test "$ac_cv_header_linux_ip_fw_h" = yes ; then
AC_LIBOBJ([fw-ipchains])
elif test "$ac_cv_header_linux_ip_fwchains_h" = yes ; then
AC_LIBOBJ([fw-ipchains])
elif test "$ac_cv_header_linux_netfilter_ipv4_ipchains_core_h" = yes ; then
AC_LIBOBJ([fw-ipchains])
else
AC_LIBOBJ([fw-none])
fi
dnl Check for network interface interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([intf-win32])
else
AC_LIBOBJ([intf])
fi
dnl Check for raw IP interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([ip-win32])
elif test "$ac_cv_dnet_rawip_cooked" = yes ; then
AC_LIBOBJ([ip-cooked])
else
AC_LIBOBJ([ip])
fi
dnl Check for routing interface.
if test "$ac_cv_header_Iphlpapi_h" = yes ; then
AC_LIBOBJ([route-win32])
elif test "$ac_cv_dnet_route_h_has_rt_msghdr" = yes ; then
AC_LIBOBJ([route-bsd])
elif test "$ac_cv_dnet_linux_procfs" = yes ; then
AC_LIBOBJ([route-linux])
elif test "$ac_cv_header_hpsecurity_h" = yes ; then
AC_LIBOBJ([route-hpux])
else
AC_LIBOBJ([route-none])
fi
dnl Check for tun interface.
if test "$ac_cv_header_linux_if_tun_h" = yes ; then
AC_LIBOBJ([tun-linux])
elif test "$ac_cv_header_net_if_tun_h" = yes ; then
if test "$ac_cv_header_stropts_h" = yes ; then
AC_LIBOBJ([tun-solaris])
else
AC_LIBOBJ([tun-bsd])
fi
elif test -f "/dev/tun0" ; then
AC_LIBOBJ([tun-bsd])
else
AC_LIBOBJ([tun-none])
fi
dnl Generate LTLIBOBJS for libtool.
Xsed="sed -e s/^X//"
LTLIBOBJS=`echo X"$LIBOBJS"|\
[$Xsed -e "s,\.[^.]* ,.lo ,g;s,\.[^.]*$,.lo,"]`
AC_SUBST(LTLIBOBJS)
AC_OUTPUT([Makefile dnet-config include/Makefile include/dnet/Makefile
src/Makefile],
[chmod 755 dnet-config])

View File

@@ -0,0 +1,54 @@
#!/bin/sh
#
# $Id: dnet-config.in,v 1.1 2001/10/19 01:29:00 dugsong Exp $
prefix=@prefix@
exec_prefix=@prefix@
usage()
{
cat <<EOF
Usage: dnet-config [OPTIONS]
Options:
[--version]
[--libs]
[--cflags]
EOF
exit $1
}
if test $# -eq 0; then
usage 1 1>&2
fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--version)
echo @VERSION@
;;
--cflags)
echo_cflags=yes
;;
--libs)
echo_libs=yes
;;
*)
usage 1 1>&2
;;
esac
shift
done
if test "$echo_cflags" = "yes"; then
echo -I@includedir@
fi
if test "$echo_libs" = "yes"; then
echo -L@libdir@ -ldnet @LIBS@
fi

View File

@@ -0,0 +1,531 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# include/Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
srcdir = .
top_srcdir = ..
pkgdatadir = $(datadir)/libdnet
pkglibdir = $(libdir)/libdnet
pkgincludedir = $(includedir)/libdnet
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(top_srcdir)/Makefile.am.common
subdir = include
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-exec-recursive install-info-recursive \
install-recursive installcheck-recursive installdirs-recursive \
pdf-recursive ps-recursive uninstall-info-recursive \
uninstall-recursive
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(includedir)"
includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
AMTAR = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoconf
AUTOHEADER = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoheader
AUTOMAKE = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CFLAGS = -g -O2 -Wall
CHECKINC =
CHECKLIB =
CPP = gcc -E
CPPFLAGS =
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=none
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = grep -E
EXEEXT =
F77 = g77
FFLAGS = -g -O2
HAVE_CHECK_FALSE =
HAVE_CHECK_TRUE = #
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
LDFLAGS =
LIBOBJS = strlcat$U.o strlcpy$U.o arp-ioctl$U.o eth-linux$U.o fw-ipchains$U.o intf$U.o ip$U.o route-linux$U.o tun-linux$U.o
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LN_S = ln -s
LTLIBOBJS = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
MAINT = #
MAINTAINER_MODE_FALSE =
MAINTAINER_MODE_TRUE = #
MAKEINFO = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run makeinfo
OBJEXT = o
PACKAGE = libdnet
PACKAGE_BUGREPORT =
PACKAGE_NAME =
PACKAGE_STRING =
PACKAGE_TARNAME =
PACKAGE_VERSION =
PATH_SEPARATOR = :
PYTHON =
PYTHON_FALSE =
PYTHON_TRUE = #
RANLIB = ranlib
SET_MAKE =
SHELL = /bin/sh
STRIP = strip
TCLINC =
TCLLIB =
TCL_FALSE =
TCL_TRUE = #
VERSION = 1.10
ac_aux_dir = config
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_CXX = g++
ac_ct_F77 = g77
ac_ct_RANLIB = ranlib
ac_ct_STRIP = strip
am__fastdepCC_FALSE =
am__fastdepCC_TRUE = #
am__fastdepCXX_FALSE =
am__fastdepCXX_TRUE = #
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = x86_64-unknown-linux-gnu
build_alias =
build_cpu = x86_64
build_os = linux-gnu
build_vendor = unknown
datadir = ${prefix}/share
exec_prefix = ${prefix}
host = x86_64-unknown-linux-gnu
host_alias =
host_cpu = x86_64
host_os = linux-gnu
host_vendor = unknown
includedir = ${prefix}/include
infodir = ${prefix}/info
install_sh = /home/fyodor/nmap/libdnet-stripped/config/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
sysconfdir = ${prefix}/etc
target_alias =
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
include_HEADERS = dnet.h
SUBDIRS = dnet
EXTRA_DIST = err.h queue.h
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
.SUFFIXES:
$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign include/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: # $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): # $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
config.h: stamp-h1
@if test ! -f $@; then \
rm -f stamp-h1; \
$(MAKE) stamp-h1; \
else :; fi
stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status include/config.h
$(srcdir)/config.h.in: # $(am__configure_deps) $(top_srcdir)/acconfig.h
cd $(top_srcdir) && $(AUTOHEADER)
rm -f stamp-h1
touch $@
distclean-hdr:
-rm -f config.h stamp-h1
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
@list='$(include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
$(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
rm -f "$(DESTDIR)$(includedir)/$$f"; \
done
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
empty_fix=.; \
else \
include_option=--include; \
empty_fix=; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test ! -f $$subdir/TAGS || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(mkdir_p) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
distdir) \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-recursive
all-am: Makefile $(HEADERS) config.h
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-recursive
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-hdr \
distclean-libtool distclean-tags
dvi: dvi-recursive
dvi-am:
html: html-recursive
info: info-recursive
info-am:
install-data-am: install-includeHEADERS
install-exec-am:
install-info: install-info-recursive
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am: uninstall-includeHEADERS uninstall-info-am
uninstall-info: uninstall-info-recursive
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
clean clean-generic clean-libtool clean-recursive ctags \
ctags-recursive distclean distclean-generic distclean-hdr \
distclean-libtool distclean-recursive distclean-tags distdir \
dvi dvi-am html html-am info info-am install install-am \
install-data install-data-am install-exec install-exec-am \
install-includeHEADERS install-info install-info-am \
install-man install-strip installcheck installcheck-am \
installdirs installdirs-am maintainer-clean \
maintainer-clean-generic maintainer-clean-recursive \
mostlyclean mostlyclean-generic mostlyclean-libtool \
mostlyclean-recursive pdf pdf-am ps ps-am tags tags-recursive \
uninstall uninstall-am uninstall-includeHEADERS \
uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,9 @@
## $Id: Makefile.am,v 1.2 2002/02/20 19:05:08 dugsong Exp $
include $(top_srcdir)/Makefile.am.common
include_HEADERS = dnet.h
SUBDIRS = dnet
EXTRA_DIST = err.h queue.h

View File

@@ -0,0 +1,531 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(top_srcdir)/Makefile.am.common
subdir = include
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES =
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-exec-recursive install-info-recursive \
install-recursive installcheck-recursive installdirs-recursive \
pdf-recursive ps-recursive uninstall-info-recursive \
uninstall-recursive
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(includedir)"
includeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CHECKINC = @CHECKINC@
CHECKLIB = @CHECKLIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
HAVE_CHECK_FALSE = @HAVE_CHECK_FALSE@
HAVE_CHECK_TRUE = @HAVE_CHECK_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PYTHON = @PYTHON@
PYTHON_FALSE = @PYTHON_FALSE@
PYTHON_TRUE = @PYTHON_TRUE@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TCLINC = @TCLINC@
TCLLIB = @TCLLIB@
TCL_FALSE = @TCL_FALSE@
TCL_TRUE = @TCL_TRUE@
VERSION = @VERSION@
ac_aux_dir = @ac_aux_dir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
include_HEADERS = dnet.h
SUBDIRS = dnet
EXTRA_DIST = err.h queue.h
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign include/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
config.h: stamp-h1
@if test ! -f $@; then \
rm -f stamp-h1; \
$(MAKE) stamp-h1; \
else :; fi
stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status include/config.h
$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(top_srcdir)/acconfig.h
cd $(top_srcdir) && $(AUTOHEADER)
rm -f stamp-h1
touch $@
distclean-hdr:
-rm -f config.h stamp-h1
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
@list='$(include_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
$(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
rm -f "$(DESTDIR)$(includedir)/$$f"; \
done
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
empty_fix=.; \
else \
include_option=--include; \
empty_fix=; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test ! -f $$subdir/TAGS || \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d "$(distdir)/$$subdir" \
|| $(mkdir_p) "$(distdir)/$$subdir" \
|| exit 1; \
distdir=`$(am__cd) $(distdir) && pwd`; \
top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$$top_distdir" \
distdir="$$distdir/$$subdir" \
distdir) \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-recursive
all-am: Makefile $(HEADERS) config.h
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-recursive
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-hdr \
distclean-libtool distclean-tags
dvi: dvi-recursive
dvi-am:
html: html-recursive
info: info-recursive
info-am:
install-data-am: install-includeHEADERS
install-exec-am:
install-info: install-info-recursive
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am: uninstall-includeHEADERS uninstall-info-am
uninstall-info: uninstall-info-recursive
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
clean clean-generic clean-libtool clean-recursive ctags \
ctags-recursive distclean distclean-generic distclean-hdr \
distclean-libtool distclean-recursive distclean-tags distdir \
dvi dvi-am html html-am info info-am install install-am \
install-data install-data-am install-exec install-exec-am \
install-includeHEADERS install-info install-info-am \
install-man install-strip installcheck installcheck-am \
installdirs installdirs-am maintainer-clean \
maintainer-clean-generic maintainer-clean-recursive \
mostlyclean mostlyclean-generic mostlyclean-libtool \
mostlyclean-recursive pdf pdf-am ps ps-am tags tags-recursive \
uninstall uninstall-am uninstall-includeHEADERS \
uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,278 @@
/* include/config.h. Generated by configure. */
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define if arpreq struct has arp_dev. */
#define HAVE_ARPREQ_ARP_DEV 1
/* Define if you have the Berkeley Packet Filter. */
/* #undef HAVE_BSD_BPF */
/* Define if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define if you have the `err' function. */
#define HAVE_ERR 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <hpsecurity.h> header file. */
/* #undef HAVE_HPSECURITY_H */
/* Define if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define if you have arp(7) ioctls. */
#define HAVE_IOCTL_ARP 1
/* Define if you have the <Iphlpapi.h> header file. */
/* #undef HAVE_IPHLPAPI_H */
/* Define if you have the <ip_compat.h> header file. */
/* #undef HAVE_IP_COMPAT_H */
/* Define if you have the <ip_fil_compat.h> header file. */
/* #undef HAVE_IP_FIL_COMPAT_H */
/* Define if you have the <ip_fil.h> header file. */
/* #undef HAVE_IP_FIL_H */
/* Define if you have the `iphlpapi' library (-liphlpapi). */
/* #undef HAVE_LIBIPHLPAPI */
/* Define if you have the `nm' library (-lnm). */
/* #undef HAVE_LIBNM */
/* Define if you have the `nsl' library (-lnsl). */
/* #undef HAVE_LIBNSL */
/* Define if you have the `resolv' library (-lresolv). */
/* #undef HAVE_LIBRESOLV */
/* Define if you have the `socket' library (-lsocket). */
/* #undef HAVE_LIBSOCKET */
/* Define if you have the `str' library (-lstr). */
/* #undef HAVE_LIBSTR */
/* Define if you have the `ws2_32' library (-lws2_32). */
/* #undef HAVE_LIBWS2_32 */
/* Define if you have the <linux/if_tun.h> header file. */
#define HAVE_LINUX_IF_TUN_H 1
/* Define if you have the <linux/ip_fwchains.h> header file. */
/* #undef HAVE_LINUX_IP_FWCHAINS_H */
/* Define if you have the <linux/ip_fw.h> header file. */
/* #undef HAVE_LINUX_IP_FW_H */
/* Define if you have the <linux/netfilter_ipv4/ipchains_core.h> header file.
*/
#define HAVE_LINUX_NETFILTER_IPV4_IPCHAINS_CORE_H 1
/* Define if you have Linux PF_PACKET sockets. */
#define HAVE_LINUX_PF_PACKET 1
/* Define if you have the Linux /proc filesystem. */
#define HAVE_LINUX_PROCFS 1
/* Define if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define if you have the <netinet/in_var.h> header file. */
/* #undef HAVE_NETINET_IN_VAR_H */
/* Define if you have the <netinet/ip_compat.h> header file. */
/* #undef HAVE_NETINET_IP_COMPAT_H */
/* Define if you have the <netinet/ip_fil_compat.h> header file. */
/* #undef HAVE_NETINET_IP_FIL_COMPAT_H */
/* Define if you have the <netinet/ip_fil.h> header file. */
/* #undef HAVE_NETINET_IP_FIL_H */
/* Define if you have the <netinet/ip_fw.h> header file. */
/* #undef HAVE_NETINET_IP_FW_H */
/* Define if you have the <net/bpf.h> header file. */
/* #undef HAVE_NET_BPF_H */
/* Define if you have the <net/if_arp.h> header file. */
#define HAVE_NET_IF_ARP_H 1
/* Define if you have the <net/if_dl.h> header file. */
/* #undef HAVE_NET_IF_DL_H */
/* Define if you have the <net/if.h> header file. */
#define HAVE_NET_IF_H 1
/* Define if you have the <net/if_tun.h> header file. */
/* #undef HAVE_NET_IF_TUN_H */
/* Define if you have the <net/if_var.h> header file. */
/* #undef HAVE_NET_IF_VAR_H */
/* Define if you have the <net/pfilt.h> header file. */
/* #undef HAVE_NET_PFILT_H */
/* Define if you have the <net/pfvar.h> header file. */
/* #undef HAVE_NET_PFVAR_H */
/* Define if you have the <net/radix.h> header file. */
/* #undef HAVE_NET_RADIX_H */
/* Define if you have the <net/raw.h> header file. */
/* #undef HAVE_NET_RAW_H */
/* Define if you have the <net/route.h> header file. */
#define HAVE_NET_ROUTE_H 1
/* Define if you have cooked raw IP sockets. */
/* #undef HAVE_RAWIP_COOKED */
/* Define if raw IP sockets require host byte ordering for ip_off, ip_len. */
/* #undef HAVE_RAWIP_HOST_OFFLEN */
/* Define if <net/route.h> has rt_msghdr struct. */
/* #undef HAVE_ROUTE_RT_MSGHDR */
/* Define if <netinet/in.h> has sockaddr_in6 struct. */
#define HAVE_SOCKADDR_IN6 1
/* Define if sockaddr struct has sa_len. */
/* #undef HAVE_SOCKADDR_SA_LEN */
/* Define if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define if you have SNMP MIB2 STREAMS. */
/* #undef HAVE_STREAMS_MIB2 */
/* Define if you have route(7) STREAMS. */
/* #undef HAVE_STREAMS_ROUTE */
/* Define if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define if you have the `strlcat' function. */
/* #undef HAVE_STRLCAT */
/* Define if you have the `strlcpy' function. */
/* #undef HAVE_STRLCPY */
/* Define if you have the <stropts.h> header file. */
#define HAVE_STROPTS_H 1
/* Define if you have the `strsep' function. */
#define HAVE_STRSEP 1
/* Define if you have the <sys/bufmod.h> header file. */
/* #undef HAVE_SYS_BUFMOD_H */
/* Define if you have the <sys/dlpihdr.h> header file. */
/* #undef HAVE_SYS_DLPIHDR_H */
/* Define if you have the <sys/dlpi_ext.h> header file. */
/* #undef HAVE_SYS_DLPI_EXT_H */
/* Define if you have the <sys/dlpi.h> header file. */
/* #undef HAVE_SYS_DLPI_H */
/* Define if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define if you have the <sys/mib.h> header file. */
/* #undef HAVE_SYS_MIB_H */
/* Define if you have the <sys/ndd_var.h> header file. */
/* #undef HAVE_SYS_NDD_VAR_H */
/* Define if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define if you have the <sys/sockio.h> header file. */
/* #undef HAVE_SYS_SOCKIO_H */
/* Define if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define if you have the <sys/sysctl.h> header file. */
#define HAVE_SYS_SYSCTL_H 1
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define if you have the <winsock2.h> header file. */
/* #undef HAVE_WINSOCK2_H */
/* Name of package */
#define PACKAGE "libdnet"
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
#define VERSION "1.10"
/* Define for faster code generation. */
/* #undef WIN32_LEAN_AND_MEAN */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
/* #undef inline */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
/* Define to `unsigned' if <sys/types.h> does not define. */
/* #undef size_t */
/* Use MingW32's internal snprintf */
/* #undef snprintf */
#include <sys/types.h>
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
# include <windows.h>
#endif
#ifdef __svr4__
# define BSD_COMP 1
#endif
#if defined(__osf__) && !defined(_SOCKADDR_LEN)
# define _SOCKADDR_LEN 1
#endif
#ifndef HAVE_INET_PTON
int inet_pton(int, const char *, void *);
#endif
#ifndef HAVE_STRLCAT
int strlcat(char *, const char *, int);
#endif
#ifndef HAVE_STRLCPY
int strlcpy(char *, const char *, int);
#endif
#ifndef HAVE_STRSEP
char *strsep(char **, const char *);
#endif

View File

@@ -0,0 +1,277 @@
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define if arpreq struct has arp_dev. */
#undef HAVE_ARPREQ_ARP_DEV
/* Define if you have the Berkeley Packet Filter. */
#undef HAVE_BSD_BPF
/* Define if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define if you have the `err' function. */
#undef HAVE_ERR
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <hpsecurity.h> header file. */
#undef HAVE_HPSECURITY_H
/* Define if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define if you have arp(7) ioctls. */
#undef HAVE_IOCTL_ARP
/* Define if you have the <Iphlpapi.h> header file. */
#undef HAVE_IPHLPAPI_H
/* Define if you have the <ip_compat.h> header file. */
#undef HAVE_IP_COMPAT_H
/* Define if you have the <ip_fil_compat.h> header file. */
#undef HAVE_IP_FIL_COMPAT_H
/* Define if you have the <ip_fil.h> header file. */
#undef HAVE_IP_FIL_H
/* Define if you have the `iphlpapi' library (-liphlpapi). */
#undef HAVE_LIBIPHLPAPI
/* Define if you have the `nm' library (-lnm). */
#undef HAVE_LIBNM
/* Define if you have the `nsl' library (-lnsl). */
#undef HAVE_LIBNSL
/* Define if you have the `resolv' library (-lresolv). */
#undef HAVE_LIBRESOLV
/* Define if you have the `socket' library (-lsocket). */
#undef HAVE_LIBSOCKET
/* Define if you have the `str' library (-lstr). */
#undef HAVE_LIBSTR
/* Define if you have the `ws2_32' library (-lws2_32). */
#undef HAVE_LIBWS2_32
/* Define if you have the <linux/if_tun.h> header file. */
#undef HAVE_LINUX_IF_TUN_H
/* Define if you have the <linux/ip_fwchains.h> header file. */
#undef HAVE_LINUX_IP_FWCHAINS_H
/* Define if you have the <linux/ip_fw.h> header file. */
#undef HAVE_LINUX_IP_FW_H
/* Define if you have the <linux/netfilter_ipv4/ipchains_core.h> header file.
*/
#undef HAVE_LINUX_NETFILTER_IPV4_IPCHAINS_CORE_H
/* Define if you have Linux PF_PACKET sockets. */
#undef HAVE_LINUX_PF_PACKET
/* Define if you have the Linux /proc filesystem. */
#undef HAVE_LINUX_PROCFS
/* Define if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define if you have the <netinet/in_var.h> header file. */
#undef HAVE_NETINET_IN_VAR_H
/* Define if you have the <netinet/ip_compat.h> header file. */
#undef HAVE_NETINET_IP_COMPAT_H
/* Define if you have the <netinet/ip_fil_compat.h> header file. */
#undef HAVE_NETINET_IP_FIL_COMPAT_H
/* Define if you have the <netinet/ip_fil.h> header file. */
#undef HAVE_NETINET_IP_FIL_H
/* Define if you have the <netinet/ip_fw.h> header file. */
#undef HAVE_NETINET_IP_FW_H
/* Define if you have the <net/bpf.h> header file. */
#undef HAVE_NET_BPF_H
/* Define if you have the <net/if_arp.h> header file. */
#undef HAVE_NET_IF_ARP_H
/* Define if you have the <net/if_dl.h> header file. */
#undef HAVE_NET_IF_DL_H
/* Define if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define if you have the <net/if_tun.h> header file. */
#undef HAVE_NET_IF_TUN_H
/* Define if you have the <net/if_var.h> header file. */
#undef HAVE_NET_IF_VAR_H
/* Define if you have the <net/pfilt.h> header file. */
#undef HAVE_NET_PFILT_H
/* Define if you have the <net/pfvar.h> header file. */
#undef HAVE_NET_PFVAR_H
/* Define if you have the <net/radix.h> header file. */
#undef HAVE_NET_RADIX_H
/* Define if you have the <net/raw.h> header file. */
#undef HAVE_NET_RAW_H
/* Define if you have the <net/route.h> header file. */
#undef HAVE_NET_ROUTE_H
/* Define if you have cooked raw IP sockets. */
#undef HAVE_RAWIP_COOKED
/* Define if raw IP sockets require host byte ordering for ip_off, ip_len. */
#undef HAVE_RAWIP_HOST_OFFLEN
/* Define if <net/route.h> has rt_msghdr struct. */
#undef HAVE_ROUTE_RT_MSGHDR
/* Define if <netinet/in.h> has sockaddr_in6 struct. */
#undef HAVE_SOCKADDR_IN6
/* Define if sockaddr struct has sa_len. */
#undef HAVE_SOCKADDR_SA_LEN
/* Define if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define if you have SNMP MIB2 STREAMS. */
#undef HAVE_STREAMS_MIB2
/* Define if you have route(7) STREAMS. */
#undef HAVE_STREAMS_ROUTE
/* Define if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the `strlcat' function. */
#undef HAVE_STRLCAT
/* Define if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define if you have the <stropts.h> header file. */
#undef HAVE_STROPTS_H
/* Define if you have the `strsep' function. */
#undef HAVE_STRSEP
/* Define if you have the <sys/bufmod.h> header file. */
#undef HAVE_SYS_BUFMOD_H
/* Define if you have the <sys/dlpihdr.h> header file. */
#undef HAVE_SYS_DLPIHDR_H
/* Define if you have the <sys/dlpi_ext.h> header file. */
#undef HAVE_SYS_DLPI_EXT_H
/* Define if you have the <sys/dlpi.h> header file. */
#undef HAVE_SYS_DLPI_H
/* Define if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define if you have the <sys/mib.h> header file. */
#undef HAVE_SYS_MIB_H
/* Define if you have the <sys/ndd_var.h> header file. */
#undef HAVE_SYS_NDD_VAR_H
/* Define if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/sysctl.h> header file. */
#undef HAVE_SYS_SYSCTL_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define if you have the <winsock2.h> header file. */
#undef HAVE_WINSOCK2_H
/* Name of package */
#undef PACKAGE
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Version number of package */
#undef VERSION
/* Define for faster code generation. */
#undef WIN32_LEAN_AND_MEAN
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
#undef inline
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t
/* Use MingW32's internal snprintf */
#undef snprintf
#include <sys/types.h>
#ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
# include <windows.h>
#endif
#ifdef __svr4__
# define BSD_COMP 1
#endif
#if defined(__osf__) && !defined(_SOCKADDR_LEN)
# define _SOCKADDR_LEN 1
#endif
#ifndef HAVE_INET_PTON
int inet_pton(int, const char *, void *);
#endif
#ifndef HAVE_STRLCAT
int strlcat(char *, const char *, int);
#endif
#ifndef HAVE_STRLCPY
int strlcpy(char *, const char *, int);
#endif
#ifndef HAVE_STRSEP
char *strsep(char **, const char *);
#endif

View File

@@ -0,0 +1,31 @@
/*
* dnet.h
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: dnet.h,v 1.6 2004/09/10 03:10:01 dugsong Exp $
*/
#ifndef DNET_H
#define DNET_H
#include <dnet/os.h>
#include <dnet/eth.h>
#include <dnet/ip.h>
#include <dnet/ip6.h>
#include <dnet/addr.h>
#include <dnet/arp.h>
#include <dnet/icmp.h>
#include <dnet/tcp.h>
#include <dnet/udp.h>
#include <dnet/intf.h>
#include <dnet/route.h>
#include <dnet/fw.h>
#include <dnet/tun.h>
#include <dnet/blob.h>
#include <dnet/rand.h>
#endif /* DNET_H */

View File

@@ -0,0 +1,413 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# include/dnet/Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
srcdir = .
top_srcdir = ../..
pkgdatadir = $(datadir)/libdnet
pkglibdir = $(libdir)/libdnet
pkgincludedir = $(includedir)/libdnet
top_builddir = ../..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
DIST_COMMON = $(dnetinclude_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(top_srcdir)/Makefile.am.common
subdir = include/dnet
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(dnetincludedir)"
dnetincludeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(dnetinclude_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
AMTAR = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoconf
AUTOHEADER = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoheader
AUTOMAKE = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CFLAGS = -g -O2 -Wall
CHECKINC =
CHECKLIB =
CPP = gcc -E
CPPFLAGS =
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=none
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = grep -E
EXEEXT =
F77 = g77
FFLAGS = -g -O2
HAVE_CHECK_FALSE =
HAVE_CHECK_TRUE = #
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
LDFLAGS =
LIBOBJS = strlcat$U.o strlcpy$U.o arp-ioctl$U.o eth-linux$U.o fw-ipchains$U.o intf$U.o ip$U.o route-linux$U.o tun-linux$U.o
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LN_S = ln -s
LTLIBOBJS = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
MAINT = #
MAINTAINER_MODE_FALSE =
MAINTAINER_MODE_TRUE = #
MAKEINFO = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run makeinfo
OBJEXT = o
PACKAGE = libdnet
PACKAGE_BUGREPORT =
PACKAGE_NAME =
PACKAGE_STRING =
PACKAGE_TARNAME =
PACKAGE_VERSION =
PATH_SEPARATOR = :
PYTHON =
PYTHON_FALSE =
PYTHON_TRUE = #
RANLIB = ranlib
SET_MAKE =
SHELL = /bin/sh
STRIP = strip
TCLINC =
TCLLIB =
TCL_FALSE =
TCL_TRUE = #
VERSION = 1.10
ac_aux_dir = config
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_CXX = g++
ac_ct_F77 = g77
ac_ct_RANLIB = ranlib
ac_ct_STRIP = strip
am__fastdepCC_FALSE =
am__fastdepCC_TRUE = #
am__fastdepCXX_FALSE =
am__fastdepCXX_TRUE = #
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = x86_64-unknown-linux-gnu
build_alias =
build_cpu = x86_64
build_os = linux-gnu
build_vendor = unknown
datadir = ${prefix}/share
exec_prefix = ${prefix}
host = x86_64-unknown-linux-gnu
host_alias =
host_cpu = x86_64
host_os = linux-gnu
host_vendor = unknown
includedir = ${prefix}/include
infodir = ${prefix}/info
install_sh = /home/fyodor/nmap/libdnet-stripped/config/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
sysconfdir = ${prefix}/etc
target_alias =
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
dnetincludedir = $(includedir)/dnet
dnetinclude_HEADERS = addr.h arp.h blob.h eth.h fw.h icmp.h intf.h ip.h \
ip6.h os.h rand.h route.h tcp.h tun.h udp.h
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/dnet/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign include/dnet/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: # $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): # $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
install-dnetincludeHEADERS: $(dnetinclude_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(dnetincludedir)" || $(mkdir_p) "$(DESTDIR)$(dnetincludedir)"
@list='$(dnetinclude_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(dnetincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(dnetincludedir)/$$f'"; \
$(dnetincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(dnetincludedir)/$$f"; \
done
uninstall-dnetincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(dnetinclude_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(dnetincludedir)/$$f'"; \
rm -f "$(DESTDIR)$(dnetincludedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/../..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(dnetincludedir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-libtool \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-dnetincludeHEADERS
install-exec-am:
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-dnetincludeHEADERS uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool ctags distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dnetincludeHEADERS install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-dnetincludeHEADERS \
uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,8 @@
## $Id: Makefile.am,v 1.5 2004/09/10 02:35:51 dugsong Exp $
include $(top_srcdir)/Makefile.am.common
dnetincludedir = $(includedir)/dnet
dnetinclude_HEADERS = addr.h arp.h blob.h eth.h fw.h icmp.h intf.h ip.h \
ip6.h os.h rand.h route.h tcp.h tun.h udp.h

View File

@@ -0,0 +1,413 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
DIST_COMMON = $(dnetinclude_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(top_srcdir)/Makefile.am.common
subdir = include/dnet
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
depcomp =
am__depfiles_maybe =
SOURCES =
DIST_SOURCES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(dnetincludedir)"
dnetincludeHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(dnetinclude_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CHECKINC = @CHECKINC@
CHECKLIB = @CHECKLIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
HAVE_CHECK_FALSE = @HAVE_CHECK_FALSE@
HAVE_CHECK_TRUE = @HAVE_CHECK_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PYTHON = @PYTHON@
PYTHON_FALSE = @PYTHON_FALSE@
PYTHON_TRUE = @PYTHON_TRUE@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TCLINC = @TCLINC@
TCLLIB = @TCLLIB@
TCL_FALSE = @TCL_FALSE@
TCL_TRUE = @TCL_TRUE@
VERSION = @VERSION@
ac_aux_dir = @ac_aux_dir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
dnetincludedir = $(includedir)/dnet
dnetinclude_HEADERS = addr.h arp.h blob.h eth.h fw.h icmp.h intf.h ip.h \
ip6.h os.h rand.h route.h tcp.h tun.h udp.h
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/dnet/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign include/dnet/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
install-dnetincludeHEADERS: $(dnetinclude_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(dnetincludedir)" || $(mkdir_p) "$(DESTDIR)$(dnetincludedir)"
@list='$(dnetinclude_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(dnetincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(dnetincludedir)/$$f'"; \
$(dnetincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(dnetincludedir)/$$f"; \
done
uninstall-dnetincludeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(dnetinclude_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(dnetincludedir)/$$f'"; \
rm -f "$(DESTDIR)$(dnetincludedir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/../..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(dnetincludedir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-libtool \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-dnetincludeHEADERS
install-exec-am:
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-dnetincludeHEADERS uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool ctags distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dnetincludeHEADERS install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-dnetincludeHEADERS \
uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,67 @@
/*
* addr.h
*
* Network address operations.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: addr.h,v 1.12 2003/02/27 03:44:55 dugsong Exp $
*/
#ifndef DNET_ADDR_H
#define DNET_ADDR_H
#define ADDR_TYPE_NONE 0 /* No address set */
#define ADDR_TYPE_ETH 1 /* Ethernet */
#define ADDR_TYPE_IP 2 /* Internet Protocol v4 */
#define ADDR_TYPE_IP6 3 /* Internet Protocol v6 */
struct addr {
uint16_t addr_type;
uint16_t addr_bits;
union {
eth_addr_t __eth;
ip_addr_t __ip;
ip6_addr_t __ip6;
uint8_t __data8[16];
uint16_t __data16[8];
uint32_t __data32[4];
} __addr_u;
};
#define addr_eth __addr_u.__eth
#define addr_ip __addr_u.__ip
#define addr_ip6 __addr_u.__ip6
#define addr_data8 __addr_u.__data8
#define addr_data16 __addr_u.__data16
#define addr_data32 __addr_u.__data32
#define addr_pack(addr, type, bits, data, len) do { \
(addr)->addr_type = type; \
(addr)->addr_bits = bits; \
memmove((addr)->addr_data8, (char *)data, len); \
} while (0)
__BEGIN_DECLS
int addr_cmp(const struct addr *a, const struct addr *b);
int addr_bcast(const struct addr *a, struct addr *b);
int addr_net(const struct addr *a, struct addr *b);
char *addr_ntop(const struct addr *src, char *dst, size_t size);
int addr_pton(const char *src, struct addr *dst);
char *addr_ntoa(const struct addr *a);
#define addr_aton addr_pton
int addr_ntos(const struct addr *a, struct sockaddr *sa);
int addr_ston(const struct sockaddr *sa, struct addr *a);
int addr_btos(uint16_t bits, struct sockaddr *sa);
int addr_stob(const struct sockaddr *sa, uint16_t *bits);
int addr_btom(uint16_t bits, void *mask, size_t size);
int addr_mtob(const void *mask, size_t size, uint16_t *bits);
__END_DECLS
#endif /* DNET_ADDR_H */

View File

@@ -0,0 +1,103 @@
/*
* arp.h
*
* Address Resolution Protocol.
* RFC 826
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: arp.h,v 1.12 2003/03/16 17:39:17 dugsong Exp $
*/
#ifndef DNET_ARP_H
#define DNET_ARP_H
#define ARP_HDR_LEN 8 /* base ARP header length */
#define ARP_ETHIP_LEN 20 /* base ARP message length */
#ifndef __GNUC__
# define __attribute__(x)
# pragma pack(1)
#endif
/*
* ARP header
*/
struct arp_hdr {
uint16_t ar_hrd; /* format of hardware address */
uint16_t ar_pro; /* format of protocol address */
uint8_t ar_hln; /* length of hardware address (ETH_ADDR_LEN) */
uint8_t ar_pln; /* length of protocol address (IP_ADDR_LEN) */
uint16_t ar_op; /* operation */
};
/*
* Hardware address format
*/
#define ARP_HRD_ETH 0x0001 /* ethernet hardware */
#define ARP_HRD_IEEE802 0x0006 /* IEEE 802 hardware */
/*
* Protocol address format
*/
#define ARP_PRO_IP 0x0800 /* IP protocol */
/*
* ARP operation
*/
#define ARP_OP_REQUEST 1 /* request to resolve ha given pa */
#define ARP_OP_REPLY 2 /* response giving hardware address */
#define ARP_OP_REVREQUEST 3 /* request to resolve pa given ha */
#define ARP_OP_REVREPLY 4 /* response giving protocol address */
/*
* Ethernet/IP ARP message
*/
struct arp_ethip {
uint8_t ar_sha[ETH_ADDR_LEN]; /* sender hardware address */
uint8_t ar_spa[IP_ADDR_LEN]; /* sender protocol address */
uint8_t ar_tha[ETH_ADDR_LEN]; /* target hardware address */
uint8_t ar_tpa[IP_ADDR_LEN]; /* target protocol address */
};
/*
* ARP cache entry
*/
struct arp_entry {
struct addr arp_pa; /* protocol address */
struct addr arp_ha; /* hardware address */
};
#ifndef __GNUC__
# pragma pack()
#endif
#define arp_pack_hdr_ethip(hdr, op, sha, spa, tha, tpa) do { \
struct arp_hdr *pack_arp_p = (struct arp_hdr *)(hdr); \
struct arp_ethip *pack_ethip_p = (struct arp_ethip *) \
((uint8_t *)(hdr) + ARP_HDR_LEN); \
pack_arp_p->ar_hrd = htons(ARP_HRD_ETH); \
pack_arp_p->ar_pro = htons(ARP_PRO_IP); \
pack_arp_p->ar_hln = ETH_ADDR_LEN; \
pack_arp_p->ar_pln = IP_ADDR_LEN; \
pack_arp_p->ar_op = htons(op); \
memmove(pack_ethip_p->ar_sha, &(sha), ETH_ADDR_LEN); \
memmove(pack_ethip_p->ar_spa, &(spa), IP_ADDR_LEN); \
memmove(pack_ethip_p->ar_tha, &(tha), ETH_ADDR_LEN); \
memmove(pack_ethip_p->ar_tpa, &(tpa), IP_ADDR_LEN); \
} while (0)
typedef struct arp_handle arp_t;
typedef int (*arp_handler)(const struct arp_entry *entry, void *arg);
__BEGIN_DECLS
arp_t *arp_open(void);
int arp_add(arp_t *arp, const struct arp_entry *entry);
int arp_delete(arp_t *arp, const struct arp_entry *entry);
int arp_get(arp_t *arp, struct arp_entry *entry);
int arp_loop(arp_t *arp, arp_handler callback, void *arg);
arp_t *arp_close(arp_t *arp);
__END_DECLS
#endif /* DNET_ARP_H */

View File

@@ -0,0 +1,56 @@
/*
* blob.h
*
* Binary blob handling.
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: blob.h,v 1.2 2002/04/05 03:06:44 dugsong Exp $
*/
#ifndef DNET_BLOB_H
#define DNET_BLOB_H
typedef struct blob {
u_char *base; /* start of data */
int off; /* offset into data */
int end; /* end of data */
int size; /* size of allocation */
} blob_t;
__BEGIN_DECLS
blob_t *blob_new(void);
int blob_read(blob_t *b, void *buf, int len);
int blob_write(blob_t *b, const void *buf, int len);
int blob_seek(blob_t *b, int off, int whence);
#define blob_skip(b, l) blob_seek(b, l, SEEK_CUR)
#define blob_rewind(b) blob_seek(b, 0, SEEK_SET)
#define blob_offset(b) ((b)->off)
#define blob_left(b) ((b)->end - (b)->off)
int blob_index(blob_t *b, const void *buf, int len);
int blob_rindex(blob_t *b, const void *buf, int len);
int blob_pack(blob_t *b, const char *fmt, ...);
int blob_unpack(blob_t *b, const char *fmt, ...);
int blob_insert(blob_t *b, const void *buf, int len);
int blob_delete(blob_t *b, void *buf, int len);
int blob_print(blob_t *b, char *style, int len);
blob_t *blob_free(blob_t *b);
int blob_register_alloc(size_t size, void *(*bmalloc)(size_t),
void (*bfree)(void *), void *(*brealloc)(void *, size_t));
#ifdef va_start
typedef int (*blob_fmt_cb)(int pack, int len, blob_t *b, va_list *arg);
int blob_register_pack(char c, blob_fmt_cb fmt_cb);
#endif
__END_DECLS
#endif /* DNET_BLOB_H */

View File

@@ -0,0 +1,77 @@
/*
* eth.h
*
* Ethernet.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: eth.h,v 1.16 2005/01/25 21:29:12 dugsong Exp $
*/
#ifndef DNET_ETH_H
#define DNET_ETH_H
#define ETH_ADDR_LEN 6
#define ETH_ADDR_BITS 48
#define ETH_TYPE_LEN 2
#define ETH_CRC_LEN 4
#define ETH_HDR_LEN 14
#define ETH_LEN_MIN 64 /* minimum frame length with CRC */
#define ETH_LEN_MAX 1518 /* maximum frame length with CRC */
#define ETH_MTU (ETH_LEN_MAX - ETH_HDR_LEN - ETH_CRC_LEN)
#define ETH_MIN (ETH_LEN_MIN - ETH_HDR_LEN - ETH_CRC_LEN)
typedef struct eth_addr {
uint8_t data[ETH_ADDR_LEN];
} eth_addr_t;
struct eth_hdr {
eth_addr_t eth_dst; /* destination address */
eth_addr_t eth_src; /* source address */
uint16_t eth_type; /* payload type */
};
/*
* Ethernet payload types - http://standards.ieee.org/regauth/ethertype
*/
#define ETH_TYPE_PUP 0x0200 /* PUP protocol */
#define ETH_TYPE_IP 0x0800 /* IP protocol */
#define ETH_TYPE_ARP 0x0806 /* address resolution protocol */
#define ETH_TYPE_REVARP 0x8035 /* reverse addr resolution protocol */
#define ETH_TYPE_8021Q 0x8100 /* IEEE 802.1Q VLAN tagging */
#define ETH_TYPE_IPV6 0x86DD /* IPv6 protocol */
#define ETH_TYPE_MPLS 0x8847 /* MPLS */
#define ETH_TYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */
#define ETH_TYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
#define ETH_TYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
#define ETH_TYPE_LOOPBACK 0x9000 /* used to test interfaces */
#define ETH_IS_MULTICAST(ea) (*(ea) & 0x01) /* is address mcast/bcast? */
#define ETH_ADDR_BROADCAST "\xff\xff\xff\xff\xff\xff"
#define eth_pack_hdr(h, dst, src, type) do { \
struct eth_hdr *eth_pack_p = (struct eth_hdr *)(h); \
memmove(&eth_pack_p->eth_dst, &(dst), ETH_ADDR_LEN); \
memmove(&eth_pack_p->eth_src, &(src), ETH_ADDR_LEN); \
eth_pack_p->eth_type = htons(type); \
} while (0)
typedef struct eth_handle eth_t;
__BEGIN_DECLS
eth_t *eth_open(const char *device);
int eth_get(eth_t *e, eth_addr_t *ea);
int eth_set(eth_t *e, const eth_addr_t *ea);
ssize_t eth_send(eth_t *e, const void *buf, size_t len);
eth_t *eth_close(eth_t *e);
char *eth_ntop(const eth_addr_t *eth, char *dst, size_t len);
int eth_pton(const char *src, eth_addr_t *dst);
char *eth_ntoa(const eth_addr_t *eth);
#define eth_aton eth_pton
__END_DECLS
#endif /* DNET_ETH_H */

View File

@@ -0,0 +1,54 @@
/*
* fw.h
*
* Network firewalling operations.
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: fw.h,v 1.13 2002/12/14 04:02:36 dugsong Exp $
*/
#ifndef DNET_FW_H
#define DNET_FW_H
struct fw_rule {
char fw_device[INTF_NAME_LEN]; /* interface name */
uint8_t fw_op; /* operation */
uint8_t fw_dir; /* direction */
uint8_t fw_proto; /* IP protocol */
struct addr fw_src; /* src address / net */
struct addr fw_dst; /* dst address / net */
uint16_t fw_sport[2]; /* range / ICMP type */
uint16_t fw_dport[2]; /* range / ICMP code */
};
#define FW_OP_ALLOW 1
#define FW_OP_BLOCK 2
#define FW_DIR_IN 1
#define FW_DIR_OUT 2
#define fw_pack_rule(rule, dev, op, dir, p, s, d, sp1, sp2, dp1, dp2) \
do { \
strlcpy((rule)->fw_device, dev, sizeof((rule)->fw_device)); \
(rule)->fw_op = op; (rule)->fw_dir = dir; \
(rule)->fw_proto = p; \
memmove(&(rule)->fw_src, &(s), sizeof((rule)->fw_src)); \
memmove(&(rule)->fw_dst, &(d), sizeof((rule)->fw_dst)); \
(rule)->fw_sport[0] = sp1; (rule)->fw_sport[1] = sp2; \
(rule)->fw_dport[0] = dp1; (rule)->fw_dport[1] = dp2; \
} while (0)
typedef struct fw_handle fw_t;
typedef int (*fw_handler)(const struct fw_rule *rule, void *arg);
__BEGIN_DECLS
fw_t *fw_open(void);
int fw_add(fw_t *f, const struct fw_rule *rule);
int fw_delete(fw_t *f, const struct fw_rule *rule);
int fw_loop(fw_t *f, fw_handler callback, void *arg);
fw_t *fw_close(fw_t *f);
__END_DECLS
#endif /* DNET_FW_H */

View File

@@ -0,0 +1,265 @@
/*
* icmp.h
*
* Internet Control Message Protocol.
* RFC 792, 950, 1256, 1393, 1475, 2002, 2521
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: icmp.h,v 1.14 2003/03/16 17:39:17 dugsong Exp $
*/
#ifndef DNET_ICMP_H
#define DNET_ICMP_H
#define ICMP_HDR_LEN 4 /* base ICMP header length */
#define ICMP_LEN_MIN 8 /* minimum ICMP message size, with header */
#ifndef __GNUC__
# define __attribute__(x)
# pragma pack(1)
#endif
/*
* ICMP header
*/
struct icmp_hdr {
uint8_t icmp_type; /* type of message, see below */
uint8_t icmp_code; /* type sub code */
uint16_t icmp_cksum; /* ones complement cksum of struct */
};
/*
* Types (icmp_type) and codes (icmp_code) -
* http://www.iana.org/assignments/icmp-parameters
*/
#define ICMP_CODE_NONE 0 /* for types without codes */
#define ICMP_ECHOREPLY 0 /* echo reply */
#define ICMP_UNREACH 3 /* dest unreachable, codes: */
#define ICMP_UNREACH_NET 0 /* bad net */
#define ICMP_UNREACH_HOST 1 /* bad host */
#define ICMP_UNREACH_PROTO 2 /* bad protocol */
#define ICMP_UNREACH_PORT 3 /* bad port */
#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
#define ICMP_UNREACH_NET_PROHIB 9 /* for crypto devs */
#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */
#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
#define ICMP_UNREACH_FILTER_PROHIB 13 /* prohibited access */
#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* precedence error */
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */
#define ICMP_SRCQUENCH 4 /* packet lost, slow down */
#define ICMP_REDIRECT 5 /* shorter route, codes: */
#define ICMP_REDIRECT_NET 0 /* for network */
#define ICMP_REDIRECT_HOST 1 /* for host */
#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
#define ICMP_ALTHOSTADDR 6 /* alternate host address */
#define ICMP_ECHO 8 /* echo service */
#define ICMP_RTRADVERT 9 /* router advertise, codes: */
#define ICMP_RTRADVERT_NORMAL 0 /* normal */
#define ICMP_RTRADVERT_NOROUTE_COMMON 16 /* selective routing */
#define ICMP_RTRSOLICIT 10 /* router solicitation */
#define ICMP_TIMEXCEED 11 /* time exceeded, code: */
#define ICMP_TIMEXCEED_INTRANS 0 /* ttl==0 in transit */
#define ICMP_TIMEXCEED_REASS 1 /* ttl==0 in reass */
#define ICMP_PARAMPROB 12 /* ip header bad */
#define ICMP_PARAMPROB_ERRATPTR 0 /* req. opt. absent */
#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
#define ICMP_PARAMPROB_LENGTH 2 /* bad length */
#define ICMP_TSTAMP 13 /* timestamp request */
#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
#define ICMP_INFO 15 /* information request */
#define ICMP_INFOREPLY 16 /* information reply */
#define ICMP_MASK 17 /* address mask request */
#define ICMP_MASKREPLY 18 /* address mask reply */
#define ICMP_TRACEROUTE 30 /* traceroute */
#define ICMP_DATACONVERR 31 /* data conversion error */
#define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */
#define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */
#define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */
#define ICMP_MOBILE_REG 35 /* mobile registration req */
#define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */
#define ICMP_DNS 37 /* domain name request */
#define ICMP_DNSREPLY 38 /* domain name reply */
#define ICMP_SKIP 39 /* SKIP */
#define ICMP_PHOTURIS 40 /* Photuris */
#define ICMP_PHOTURIS_UNKNOWN_INDEX 0 /* unknown sec index */
#define ICMP_PHOTURIS_AUTH_FAILED 1 /* auth failed */
#define ICMP_PHOTURIS_DECOMPRESS_FAILED 2 /* decompress failed */
#define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */
#define ICMP_PHOTURIS_NEED_AUTHN 4 /* no authentication */
#define ICMP_PHOTURIS_NEED_AUTHZ 5 /* no authorization */
#define ICMP_TYPE_MAX 40
#define ICMP_INFOTYPE(type) \
((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
(type) == ICMP_RTRADVERT || (type) == ICMP_RTRSOLICIT || \
(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
(type) == ICMP_INFO || (type) == ICMP_INFOREPLY || \
(type) == ICMP_MASK || (type) == ICMP_MASKREPLY)
/*
* Echo message data
*/
struct icmp_msg_echo {
uint16_t icmp_id;
uint16_t icmp_seq;
uint8_t icmp_data __flexarr; /* optional data */
};
/*
* Fragmentation-needed (unreachable) message data
*/
struct icmp_msg_needfrag {
uint16_t icmp_void; /* must be zero */
uint16_t icmp_mtu; /* MTU of next-hop network */
uint8_t icmp_ip __flexarr; /* IP hdr + 8 bytes of pkt */
};
/*
* Unreachable, source quench, redirect, time exceeded,
* parameter problem message data
*/
struct icmp_msg_quote {
uint32_t icmp_void; /* must be zero */
#define icmp_gwaddr icmp_void /* router IP address to use */
#define icmp_pptr icmp_void /* ptr to bad octet field */
uint8_t icmp_ip __flexarr; /* IP hdr + 8 bytes of pkt */
};
/*
* Router advertisement message data, RFC 1256
*/
struct icmp_msg_rtradvert {
uint8_t icmp_num_addrs; /* # of address / pref pairs */
uint8_t icmp_wpa; /* words / address == 2 */
uint16_t icmp_lifetime; /* route lifetime in seconds */
struct icmp_msg_rtr_data {
uint32_t icmp_void;
#define icmp_gwaddr icmp_void /* router IP address */
uint32_t icmp_pref; /* router preference (usu 0) */
} icmp_rtr __flexarr; /* variable # of routers */
};
#define ICMP_RTR_PREF_NODEFAULT 0x80000000 /* do not use as default gw */
/*
* Timestamp message data
*/
struct icmp_msg_tstamp {
uint32_t icmp_id; /* identifier */
uint32_t icmp_seq; /* sequence number */
uint32_t icmp_ts_orig; /* originate timestamp */
uint32_t icmp_ts_rx; /* receive timestamp */
uint32_t icmp_ts_tx; /* transmit timestamp */
};
/*
* Address mask message data, RFC 950
*/
struct icmp_msg_mask {
uint32_t icmp_id; /* identifier */
uint32_t icmp_seq; /* sequence number */
uint32_t icmp_mask; /* address mask */
};
/*
* Traceroute message data, RFC 1393, RFC 1812
*/
struct icmp_msg_traceroute {
uint16_t icmp_id; /* identifier */
uint16_t icmp_void; /* unused */
uint16_t icmp_ohc; /* outbound hop count */
uint16_t icmp_rhc; /* return hop count */
uint32_t icmp_speed; /* link speed, bytes/sec */
uint32_t icmp_mtu; /* MTU in bytes */
};
/*
* Domain name reply message data, RFC 1788
*/
struct icmp_msg_dnsreply {
uint16_t icmp_id; /* identifier */
uint16_t icmp_seq; /* sequence number */
uint32_t icmp_ttl; /* time-to-live */
uint8_t icmp_names __flexarr; /* variable number of names */
};
/*
* Generic identifier, sequence number data
*/
struct icmp_msg_idseq {
uint16_t icmp_id;
uint16_t icmp_seq;
};
/*
* ICMP message union
*/
union icmp_msg {
struct icmp_msg_echo echo; /* ICMP_ECHO{REPLY} */
struct icmp_msg_quote unreach; /* ICMP_UNREACH */
struct icmp_msg_needfrag needfrag; /* ICMP_UNREACH_NEEDFRAG */
struct icmp_msg_quote srcquench; /* ICMP_SRCQUENCH */
struct icmp_msg_quote redirect; /* ICMP_REDIRECT (set to 0) */
uint32_t rtrsolicit; /* ICMP_RTRSOLICIT */
struct icmp_msg_rtradvert rtradvert; /* ICMP_RTRADVERT */
struct icmp_msg_quote timexceed; /* ICMP_TIMEXCEED */
struct icmp_msg_quote paramprob; /* ICMP_PARAMPROB */
struct icmp_msg_tstamp tstamp; /* ICMP_TSTAMP{REPLY} */
struct icmp_msg_idseq info; /* ICMP_INFO{REPLY} */
struct icmp_msg_mask mask; /* ICMP_MASK{REPLY} */
struct icmp_msg_traceroute traceroute; /* ICMP_TRACEROUTE */
struct icmp_msg_idseq dns; /* ICMP_DNS */
struct icmp_msg_dnsreply dnsreply; /* ICMP_DNSREPLY */
};
#ifndef __GNUC__
# pragma pack()
#endif
#define icmp_pack_hdr(hdr, type, code) do { \
struct icmp_hdr *icmp_pack_p = (struct icmp_hdr *)(hdr); \
icmp_pack_p->icmp_type = type; icmp_pack_p->icmp_code = code; \
} while (0)
#define icmp_pack_hdr_echo(hdr, type, code, id, seq, data, len) do { \
struct icmp_msg_echo *echo_pack_p = (struct icmp_msg_echo *) \
((uint8_t *)(hdr) + ICMP_HDR_LEN); \
icmp_pack_hdr(hdr, type, code); \
echo_pack_p->icmp_id = htons(id); \
echo_pack_p->icmp_seq = htons(seq); \
memmove(echo_pack_p->icmp_data, data, len); \
} while (0)
#define icmp_pack_hdr_quote(hdr, type, code, word, pkt, len) do { \
struct icmp_msg_quote *quote_pack_p = (struct icmp_msg_quote *) \
((uint8_t *)(hdr) + ICMP_HDR_LEN); \
icmp_pack_hdr(hdr, type, code); \
quote_pack_p->icmp_void = htonl(word); \
memmove(quote_pack_p->icmp_ip, pkt, len); \
} while (0)
#define icmp_pack_hdr_mask(hdr, type, code, id, seq, mask) do { \
struct icmp_msg_mask *mask_pack_p = (struct icmp_msg_mask *) \
((uint8_t *)(hdr) + ICMP_HDR_LEN); \
icmp_pack_hdr(hdr, type, code); \
mask_pack_p->icmp_id = htons(id); \
mask_pack_p->icmp_seq = htons(seq); \
mask_pack_p->icmp_mask = htonl(mask); \
} while (0)
#define icmp_pack_hdr_needfrag(hdr, type, code, mtu, pkt, len) do { \
struct icmp_msg_needfrag *frag_pack_p = \
(struct icmp_msg_needfrag *)((uint8_t *)(hdr) + ICMP_HDR_LEN); \
icmp_pack_hdr(hdr, type, code); \
frag_pack_p->icmp_void = 0; \
frag_pack_p->icmp_mtu = htons(mtu); \
memmove(frag_pack_p->icmp_ip, pkt, len); \
} while (0)
#endif /* DNET_ICMP_H */

View File

@@ -0,0 +1,68 @@
/*
* intf.c
*
* Network interface operations.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: intf.h,v 1.16 2004/01/13 07:41:09 dugsong Exp $
*/
#ifndef DNET_INTF_H
#define DNET_INTF_H
/*
* Interface entry
*/
#define INTF_NAME_LEN 16
struct intf_entry {
u_int intf_len; /* length of entry */
char intf_name[INTF_NAME_LEN]; /* interface name */
u_short intf_type; /* interface type (r/o) */
u_short intf_flags; /* interface flags */
u_int intf_mtu; /* interface MTU */
struct addr intf_addr; /* interface address */
struct addr intf_dst_addr; /* point-to-point dst */
struct addr intf_link_addr; /* link-layer address */
u_int intf_alias_num; /* number of aliases */
struct addr intf_alias_addrs __flexarr; /* array of aliases */
};
/*
* MIB-II interface types - http://www.iana.org/assignments/ianaiftype-mib
*/
#define INTF_TYPE_OTHER 1 /* other */
#define INTF_TYPE_ETH 6 /* Ethernet */
#define INTF_TYPE_TOKENRING 9 /* Token Ring */
#define INTF_TYPE_FDDI 15 /* FDDI */
#define INTF_TYPE_PPP 23 /* Point-to-Point Protocol */
#define INTF_TYPE_LOOPBACK 24 /* software loopback */
#define INTF_TYPE_SLIP 28 /* Serial Line Interface Protocol */
#define INTF_TYPE_TUN 53 /* proprietary virtual/internal */
/*
* Interface flags
*/
#define INTF_FLAG_UP 0x01 /* enable interface */
#define INTF_FLAG_LOOPBACK 0x02 /* is a loopback net (r/o) */
#define INTF_FLAG_POINTOPOINT 0x04 /* point-to-point link (r/o) */
#define INTF_FLAG_NOARP 0x08 /* disable ARP */
#define INTF_FLAG_BROADCAST 0x10 /* supports broadcast (r/o) */
#define INTF_FLAG_MULTICAST 0x20 /* supports multicast (r/o) */
typedef struct intf_handle intf_t;
typedef int (*intf_handler)(const struct intf_entry *entry, void *arg);
__BEGIN_DECLS
intf_t *intf_open(void);
int intf_get(intf_t *i, struct intf_entry *entry);
int intf_get_src(intf_t *i, struct intf_entry *entry, struct addr *src);
int intf_get_dst(intf_t *i, struct intf_entry *entry, struct addr *dst);
int intf_set(intf_t *i, const struct intf_entry *entry);
int intf_loop(intf_t *i, intf_handler callback, void *arg);
intf_t *intf_close(intf_t *i);
__END_DECLS
#endif /* DNET_INTF_H */

View File

@@ -0,0 +1,432 @@
/*
* ip.h
*
* Internet Protocol (RFC 791).
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: ip.h,v 1.25 2005/02/16 22:02:45 dugsong Exp $
*/
#ifndef DNET_IP_H
#define DNET_IP_H
#define IP_ADDR_LEN 4 /* IP address length */
#define IP_ADDR_BITS 32 /* IP address bits */
#define IP_HDR_LEN 20 /* base IP header length */
#define IP_OPT_LEN 2 /* base IP option length */
#define IP_OPT_LEN_MAX 40
#define IP_HDR_LEN_MAX (IP_HDR_LEN + IP_OPT_LEN_MAX)
#define IP_LEN_MAX 65535
#define IP_LEN_MIN IP_HDR_LEN
typedef uint32_t ip_addr_t;
#ifndef __GNUC__
# define __attribute__(x)
# pragma pack(1)
#endif
/*
* IP header, without options
*/
struct ip_hdr {
#if DNET_BYTESEX == DNET_BIG_ENDIAN
uint8_t ip_v:4, /* version */
ip_hl:4; /* header length (incl any options) */
#elif DNET_BYTESEX == DNET_LIL_ENDIAN
uint8_t ip_hl:4,
ip_v:4;
#else
# error "need to include <dnet.h>"
#endif
uint8_t ip_tos; /* type of service */
uint16_t ip_len; /* total length (incl header) */
uint16_t ip_id; /* identification */
uint16_t ip_off; /* fragment offset and flags */
uint8_t ip_ttl; /* time to live */
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
ip_addr_t ip_src; /* source address */
ip_addr_t ip_dst; /* destination address */
};
/*
* Type of service (ip_tos), RFC 1349 ("obsoleted by RFC 2474")
*/
#define IP_TOS_DEFAULT 0x00 /* default */
#define IP_TOS_LOWDELAY 0x10 /* low delay */
#define IP_TOS_THROUGHPUT 0x08 /* high throughput */
#define IP_TOS_RELIABILITY 0x04 /* high reliability */
#define IP_TOS_LOWCOST 0x02 /* low monetary cost - XXX */
#define IP_TOS_ECT 0x02 /* ECN-capable transport */
#define IP_TOS_CE 0x01 /* congestion experienced */
/*
* IP precedence (high 3 bits of ip_tos), hopefully unused
*/
#define IP_TOS_PREC_ROUTINE 0x00
#define IP_TOS_PREC_PRIORITY 0x20
#define IP_TOS_PREC_IMMEDIATE 0x40
#define IP_TOS_PREC_FLASH 0x60
#define IP_TOS_PREC_FLASHOVERRIDE 0x80
#define IP_TOS_PREC_CRITIC_ECP 0xa0
#define IP_TOS_PREC_INTERNETCONTROL 0xc0
#define IP_TOS_PREC_NETCONTROL 0xe0
/*
* Fragmentation flags (ip_off)
*/
#define IP_RF 0x8000 /* reserved */
#define IP_DF 0x4000 /* don't fragment */
#define IP_MF 0x2000 /* more fragments (not last frag) */
#define IP_OFFMASK 0x1fff /* mask for fragment offset */
/*
* Time-to-live (ip_ttl), seconds
*/
#define IP_TTL_DEFAULT 64 /* default ttl, RFC 1122, RFC 1340 */
#define IP_TTL_MAX 255 /* maximum ttl */
/*
* Protocol (ip_p) - http://www.iana.org/assignments/protocol-numbers
*/
#define IP_PROTO_IP 0 /* dummy for IP */
#define IP_PROTO_HOPOPTS IP_PROTO_IP /* IPv6 hop-by-hop options */
#define IP_PROTO_ICMP 1 /* ICMP */
#define IP_PROTO_IGMP 2 /* IGMP */
#define IP_PROTO_GGP 3 /* gateway-gateway protocol */
#define IP_PROTO_IPIP 4 /* IP in IP */
#define IP_PROTO_ST 5 /* ST datagram mode */
#define IP_PROTO_TCP 6 /* TCP */
#define IP_PROTO_CBT 7 /* CBT */
#define IP_PROTO_EGP 8 /* exterior gateway protocol */
#define IP_PROTO_IGP 9 /* interior gateway protocol */
#define IP_PROTO_BBNRCC 10 /* BBN RCC monitoring */
#define IP_PROTO_NVP 11 /* Network Voice Protocol */
#define IP_PROTO_PUP 12 /* PARC universal packet */
#define IP_PROTO_ARGUS 13 /* ARGUS */
#define IP_PROTO_EMCON 14 /* EMCON */
#define IP_PROTO_XNET 15 /* Cross Net Debugger */
#define IP_PROTO_CHAOS 16 /* Chaos */
#define IP_PROTO_UDP 17 /* UDP */
#define IP_PROTO_MUX 18 /* multiplexing */
#define IP_PROTO_DCNMEAS 19 /* DCN measurement */
#define IP_PROTO_HMP 20 /* Host Monitoring Protocol */
#define IP_PROTO_PRM 21 /* Packet Radio Measurement */
#define IP_PROTO_IDP 22 /* Xerox NS IDP */
#define IP_PROTO_TRUNK1 23 /* Trunk-1 */
#define IP_PROTO_TRUNK2 24 /* Trunk-2 */
#define IP_PROTO_LEAF1 25 /* Leaf-1 */
#define IP_PROTO_LEAF2 26 /* Leaf-2 */
#define IP_PROTO_RDP 27 /* "Reliable Datagram" proto */
#define IP_PROTO_IRTP 28 /* Inet Reliable Transaction */
#define IP_PROTO_TP 29 /* ISO TP class 4 */
#define IP_PROTO_NETBLT 30 /* Bulk Data Transfer */
#define IP_PROTO_MFPNSP 31 /* MFE Network Services */
#define IP_PROTO_MERITINP 32 /* Merit Internodal Protocol */
#define IP_PROTO_SEP 33 /* Sequential Exchange proto */
#define IP_PROTO_3PC 34 /* Third Party Connect proto */
#define IP_PROTO_IDPR 35 /* Interdomain Policy Route */
#define IP_PROTO_XTP 36 /* Xpress Transfer Protocol */
#define IP_PROTO_DDP 37 /* Datagram Delivery Proto */
#define IP_PROTO_CMTP 38 /* IDPR Ctrl Message Trans */
#define IP_PROTO_TPPP 39 /* TP++ Transport Protocol */
#define IP_PROTO_IL 40 /* IL Transport Protocol */
#define IP_PROTO_IPV6 41 /* IPv6 */
#define IP_PROTO_SDRP 42 /* Source Demand Routing */
#define IP_PROTO_ROUTING 43 /* IPv6 routing header */
#define IP_PROTO_FRAGMENT 44 /* IPv6 fragmentation header */
#define IP_PROTO_RSVP 46 /* Reservation protocol */
#define IP_PROTO_GRE 47 /* General Routing Encap */
#define IP_PROTO_MHRP 48 /* Mobile Host Routing */
#define IP_PROTO_ENA 49 /* ENA */
#define IP_PROTO_ESP 50 /* Encap Security Payload */
#define IP_PROTO_AH 51 /* Authentication Header */
#define IP_PROTO_INLSP 52 /* Integated Net Layer Sec */
#define IP_PROTO_SWIPE 53 /* SWIPE */
#define IP_PROTO_NARP 54 /* NBMA Address Resolution */
#define IP_PROTO_MOBILE 55 /* Mobile IP, RFC 2004 */
#define IP_PROTO_TLSP 56 /* Transport Layer Security */
#define IP_PROTO_SKIP 57 /* SKIP */
#define IP_PROTO_ICMPV6 58 /* ICMP for IPv6 */
#define IP_PROTO_NONE 59 /* IPv6 no next header */
#define IP_PROTO_DSTOPTS 60 /* IPv6 destination options */
#define IP_PROTO_ANYHOST 61 /* any host internal proto */
#define IP_PROTO_CFTP 62 /* CFTP */
#define IP_PROTO_ANYNET 63 /* any local network */
#define IP_PROTO_EXPAK 64 /* SATNET and Backroom EXPAK */
#define IP_PROTO_KRYPTOLAN 65 /* Kryptolan */
#define IP_PROTO_RVD 66 /* MIT Remote Virtual Disk */
#define IP_PROTO_IPPC 67 /* Inet Pluribus Packet Core */
#define IP_PROTO_DISTFS 68 /* any distributed fs */
#define IP_PROTO_SATMON 69 /* SATNET Monitoring */
#define IP_PROTO_VISA 70 /* VISA Protocol */
#define IP_PROTO_IPCV 71 /* Inet Packet Core Utility */
#define IP_PROTO_CPNX 72 /* Comp Proto Net Executive */
#define IP_PROTO_CPHB 73 /* Comp Protocol Heart Beat */
#define IP_PROTO_WSN 74 /* Wang Span Network */
#define IP_PROTO_PVP 75 /* Packet Video Protocol */
#define IP_PROTO_BRSATMON 76 /* Backroom SATNET Monitor */
#define IP_PROTO_SUNND 77 /* SUN ND Protocol */
#define IP_PROTO_WBMON 78 /* WIDEBAND Monitoring */
#define IP_PROTO_WBEXPAK 79 /* WIDEBAND EXPAK */
#define IP_PROTO_EON 80 /* ISO CNLP */
#define IP_PROTO_VMTP 81 /* Versatile Msg Transport*/
#define IP_PROTO_SVMTP 82 /* Secure VMTP */
#define IP_PROTO_VINES 83 /* VINES */
#define IP_PROTO_TTP 84 /* TTP */
#define IP_PROTO_NSFIGP 85 /* NSFNET-IGP */
#define IP_PROTO_DGP 86 /* Dissimilar Gateway Proto */
#define IP_PROTO_TCF 87 /* TCF */
#define IP_PROTO_EIGRP 88 /* EIGRP */
#define IP_PROTO_OSPF 89 /* Open Shortest Path First */
#define IP_PROTO_SPRITERPC 90 /* Sprite RPC Protocol */
#define IP_PROTO_LARP 91 /* Locus Address Resolution */
#define IP_PROTO_MTP 92 /* Multicast Transport Proto */
#define IP_PROTO_AX25 93 /* AX.25 Frames */
#define IP_PROTO_IPIPENCAP 94 /* yet-another IP encap */
#define IP_PROTO_MICP 95 /* Mobile Internet Ctrl */
#define IP_PROTO_SCCSP 96 /* Semaphore Comm Sec Proto */
#define IP_PROTO_ETHERIP 97 /* Ethernet in IPv4 */
#define IP_PROTO_ENCAP 98 /* encapsulation header */
#define IP_PROTO_ANYENC 99 /* private encryption scheme */
#define IP_PROTO_GMTP 100 /* GMTP */
#define IP_PROTO_IFMP 101 /* Ipsilon Flow Mgmt Proto */
#define IP_PROTO_PNNI 102 /* PNNI over IP */
#define IP_PROTO_PIM 103 /* Protocol Indep Multicast */
#define IP_PROTO_ARIS 104 /* ARIS */
#define IP_PROTO_SCPS 105 /* SCPS */
#define IP_PROTO_QNX 106 /* QNX */
#define IP_PROTO_AN 107 /* Active Networks */
#define IP_PROTO_IPCOMP 108 /* IP Payload Compression */
#define IP_PROTO_SNP 109 /* Sitara Networks Protocol */
#define IP_PROTO_COMPAQPEER 110 /* Compaq Peer Protocol */
#define IP_PROTO_IPXIP 111 /* IPX in IP */
#define IP_PROTO_VRRP 112 /* Virtual Router Redundancy */
#define IP_PROTO_PGM 113 /* PGM Reliable Transport */
#define IP_PROTO_ANY0HOP 114 /* 0-hop protocol */
#define IP_PROTO_L2TP 115 /* Layer 2 Tunneling Proto */
#define IP_PROTO_DDX 116 /* D-II Data Exchange (DDX) */
#define IP_PROTO_IATP 117 /* Interactive Agent Xfer */
#define IP_PROTO_STP 118 /* Schedule Transfer Proto */
#define IP_PROTO_SRP 119 /* SpectraLink Radio Proto */
#define IP_PROTO_UTI 120 /* UTI */
#define IP_PROTO_SMP 121 /* Simple Message Protocol */
#define IP_PROTO_SM 122 /* SM */
#define IP_PROTO_PTP 123 /* Performance Transparency */
#define IP_PROTO_ISIS 124 /* ISIS over IPv4 */
#define IP_PROTO_FIRE 125 /* FIRE */
#define IP_PROTO_CRTP 126 /* Combat Radio Transport */
#define IP_PROTO_CRUDP 127 /* Combat Radio UDP */
#define IP_PROTO_SSCOPMCE 128 /* SSCOPMCE */
#define IP_PROTO_IPLT 129 /* IPLT */
#define IP_PROTO_SPS 130 /* Secure Packet Shield */
#define IP_PROTO_PIPE 131 /* Private IP Encap in IP */
#define IP_PROTO_SCTP 132 /* Stream Ctrl Transmission */
#define IP_PROTO_FC 133 /* Fibre Channel */
#define IP_PROTO_RSVPIGN 134 /* RSVP-E2E-IGNORE */
#define IP_PROTO_RAW 255 /* Raw IP packets */
#define IP_PROTO_RESERVED IP_PROTO_RAW /* Reserved */
#define IP_PROTO_MAX 255
/*
* Option types (opt_type) - http://www.iana.org/assignments/ip-parameters
*/
#define IP_OPT_CONTROL 0x00 /* control */
#define IP_OPT_DEBMEAS 0x40 /* debugging & measurement */
#define IP_OPT_COPY 0x80 /* copy into all fragments */
#define IP_OPT_RESERVED1 0x20
#define IP_OPT_RESERVED2 0x60
#define IP_OPT_EOL 0 /* end of option list */
#define IP_OPT_NOP 1 /* no operation */
#define IP_OPT_SEC (2|IP_OPT_COPY) /* DoD basic security */
#define IP_OPT_LSRR (3|IP_OPT_COPY) /* loose source route */
#define IP_OPT_TS (4|IP_OPT_DEBMEAS) /* timestamp */
#define IP_OPT_ESEC (5|IP_OPT_COPY) /* DoD extended security */
#define IP_OPT_CIPSO (6|IP_OPT_COPY) /* commercial security */
#define IP_OPT_RR 7 /* record route */
#define IP_OPT_SATID (8|IP_OPT_COPY) /* stream ID (obsolete) */
#define IP_OPT_SSRR (9|IP_OPT_COPY) /* strict source route */
#define IP_OPT_ZSU 10 /* experimental measurement */
#define IP_OPT_MTUP 11 /* MTU probe */
#define IP_OPT_MTUR 12 /* MTU reply */
#define IP_OPT_FINN (13|IP_OPT_COPY|IP_OPT_DEBMEAS) /* exp flow control */
#define IP_OPT_VISA (14|IP_OPT_COPY) /* exp access control */
#define IP_OPT_ENCODE 15 /* ??? */
#define IP_OPT_IMITD (16|IP_OPT_COPY) /* IMI traffic descriptor */
#define IP_OPT_EIP (17|IP_OPT_COPY) /* extended IP, RFC 1385 */
#define IP_OPT_TR (18|IP_OPT_DEBMEAS) /* traceroute */
#define IP_OPT_ADDEXT (19|IP_OPT_COPY) /* IPv7 ext addr, RFC 1475 */
#define IP_OPT_RTRALT (20|IP_OPT_COPY) /* router alert, RFC 2113 */
#define IP_OPT_SDB (21|IP_OPT_COPY) /* directed bcast, RFC 1770 */
#define IP_OPT_NSAPA (22|IP_OPT_COPY) /* NSAP addresses */
#define IP_OPT_DPS (23|IP_OPT_COPY) /* dynamic packet state */
#define IP_OPT_UMP (24|IP_OPT_COPY) /* upstream multicast */
#define IP_OPT_MAX 25
#define IP_OPT_COPIED(o) ((o) & 0x80)
#define IP_OPT_CLASS(o) ((o) & 0x60)
#define IP_OPT_NUMBER(o) ((o) & 0x1f)
#define IP_OPT_TYPEONLY(o) ((o) == IP_OPT_EOL || (o) == IP_OPT_NOP)
/*
* Security option data - RFC 791, 3.1
*/
struct ip_opt_data_sec {
uint16_t s; /* security */
uint16_t c; /* compartments */
uint16_t h; /* handling restrictions */
uint8_t tcc[3]; /* transmission control code */
} __attribute__((__packed__));
#define IP_OPT_SEC_UNCLASS 0x0000 /* unclassified */
#define IP_OPT_SEC_CONFID 0xf135 /* confidential */
#define IP_OPT_SEC_EFTO 0x789a /* EFTO */
#define IP_OPT_SEC_MMMM 0xbc4d /* MMMM */
#define IP_OPT_SEC_PROG 0x5e26 /* PROG */
#define IP_OPT_SEC_RESTR 0xaf13 /* restricted */
#define IP_OPT_SEC_SECRET 0xd788 /* secret */
#define IP_OPT_SEC_TOPSECRET 0x6bc5 /* top secret */
/*
* {Loose Source, Record, Strict Source} Route option data - RFC 791, 3.1
*/
struct ip_opt_data_rr {
uint8_t ptr; /* from start of option, >= 4 */
uint32_t iplist __flexarr; /* list of IP addresses */
} __attribute__((__packed__));
/*
* Timestamp option data - RFC 791, 3.1
*/
struct ip_opt_data_ts {
uint8_t ptr; /* from start of option, >= 5 */
#if DNET_BYTESEX == DNET_BIG_ENDIAN
uint8_t oflw:4, /* number of IPs skipped */
flg:4; /* address[ / timestamp] flag */
#elif DNET_BYTESEX == DNET_LIL_ENDIAN
uint8_t flg:4,
oflw:4;
#endif
uint32_t ipts __flexarr; /* IP address [/ timestamp] pairs */
} __attribute__((__packed__));
#define IP_OPT_TS_TSONLY 0 /* timestamps only */
#define IP_OPT_TS_TSADDR 1 /* IP address / timestamp pairs */
#define IP_OPT_TS_PRESPEC 3 /* IP address / zero timestamp pairs */
/*
* Traceroute option data - RFC 1393, 2.2
*/
struct ip_opt_data_tr {
uint16_t id; /* ID number */
uint16_t ohc; /* outbound hop count */
uint16_t rhc; /* return hop count */
uint32_t origip; /* originator IP address */
} __attribute__((__packed__));
/*
* IP option (following IP header)
*/
struct ip_opt {
uint8_t opt_type; /* option type */
uint8_t opt_len; /* option length >= IP_OPT_LEN */
union ip_opt_data {
struct ip_opt_data_sec sec; /* IP_OPT_SEC */
struct ip_opt_data_rr rr; /* IP_OPT_{L,S}RR */
struct ip_opt_data_ts ts; /* IP_OPT_TS */
uint16_t satid; /* IP_OPT_SATID */
uint16_t mtu; /* IP_OPT_MTU{P,R} */
struct ip_opt_data_tr tr; /* IP_OPT_TR */
uint32_t addext[2]; /* IP_OPT_ADDEXT */
uint16_t rtralt; /* IP_OPT_RTRALT */
uint32_t sdb[9]; /* IP_OPT_SDB */
uint8_t data8[IP_OPT_LEN_MAX - IP_OPT_LEN];
} opt_data;
} __attribute__((__packed__));
#ifndef __GNUC__
# pragma pack()
#endif
/*
* Classful addressing
*/
#define IP_CLASSA(i) (((uint32_t)(i) & htonl(0x80000000)) == \
htonl(0x00000000))
#define IP_CLASSA_NET (htonl(0xff000000))
#define IP_CLASSA_NSHIFT 24
#define IP_CLASSA_HOST (htonl(0x00ffffff))
#define IP_CLASSA_MAX 128
#define IP_CLASSB(i) (((uint32_t)(i) & htonl(0xc0000000)) == \
htonl(0x80000000))
#define IP_CLASSB_NET (htonl(0xffff0000))
#define IP_CLASSB_NSHIFT 16
#define IP_CLASSB_HOST (htonl(0x0000ffff))
#define IP_CLASSB_MAX 65536
#define IP_CLASSC(i) (((uint32_t)(i) & htonl(0xe0000000)) == \
htonl(0xc0000000))
#define IP_CLASSC_NET (htonl(0xffffff00))
#define IP_CLASSC_NSHIFT 8
#define IP_CLASSC_HOST (htonl(0x000000ff))
#define IP_CLASSD(i) (((uint32_t)(i) & htonl(0xf0000000)) == \
htonl(0xe0000000))
/* These ones aren't really net and host fields, but routing needn't know. */
#define IP_CLASSD_NET (htonl(0xf0000000))
#define IP_CLASSD_NSHIFT 28
#define IP_CLASSD_HOST (htonl(0x0fffffff))
#define IP_MULTICAST(i) IP_CLASSD(i)
#define IP_EXPERIMENTAL(i) (((uint32_t)(i) & htonl(0xf0000000)) == \
htonl(0xf0000000))
#define IP_BADCLASS(i) (((uint32_t)(i) & htonl(0xf0000000)) == \
htonl(0xf0000000))
#define IP_LOCAL_GROUP(i) (((uint32_t)(i) & htonl(0xffffff00)) == \
htonl(0xe0000000))
/*
* Reserved addresses
*/
#define IP_ADDR_ANY (htonl(0x00000000)) /* 0.0.0.0 */
#define IP_ADDR_BROADCAST (htonl(0xffffffff)) /* 255.255.255.255 */
#define IP_ADDR_LOOPBACK (htonl(0x7f000001)) /* 127.0.0.1 */
#define IP_ADDR_MCAST_ALL (htonl(0xe0000001)) /* 224.0.0.1 */
#define IP_ADDR_MCAST_LOCAL (htonl(0xe00000ff)) /* 224.0.0.255 */
#define ip_pack_hdr(hdr, tos, len, id, off, ttl, p, src, dst) do { \
struct ip_hdr *ip_pack_p = (struct ip_hdr *)(hdr); \
ip_pack_p->ip_v = 4; ip_pack_p->ip_hl = 5; \
ip_pack_p->ip_tos = tos; ip_pack_p->ip_len = htons(len); \
ip_pack_p->ip_id = htons(id); ip_pack_p->ip_off = htons(off); \
ip_pack_p->ip_ttl = ttl; ip_pack_p->ip_p = p; \
ip_pack_p->ip_src = src; ip_pack_p->ip_dst = dst; \
} while (0)
typedef struct ip_handle ip_t;
__BEGIN_DECLS
ip_t *ip_open(void);
ssize_t ip_send(ip_t *i, const void *buf, size_t len);
ip_t *ip_close(ip_t *i);
char *ip_ntop(const ip_addr_t *ip, char *dst, size_t len);
int ip_pton(const char *src, ip_addr_t *dst);
char *ip_ntoa(const ip_addr_t *ip);
#define ip_aton ip_pton
ssize_t ip_add_option(void *buf, size_t len,
int proto, const void *optbuf, size_t optlen);
void ip_checksum(void *buf, size_t len);
int ip_cksum_add(const void *buf, size_t len, int cksum);
#define ip_cksum_carry(x) \
(x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
__END_DECLS
#endif /* DNET_IP_H */

View File

@@ -0,0 +1,183 @@
/*
* ip6.h
*
* Internet Protocol, Version 6 (RFC 2460).
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: ip6.h,v 1.6 2004/02/23 10:01:15 dugsong Exp $
*/
#ifndef DNET_IP6_H
#define DNET_IP6_H
#define IP6_ADDR_LEN 16
#define IP6_ADDR_BITS 128
#define IP6_HDR_LEN 40 /* IPv6 header length */
#define IP6_LEN_MIN IP6_HDR_LEN
#define IP6_LEN_MAX 65535 /* non-jumbo payload */
#define IP6_MTU_MIN 1280 /* minimum MTU (1024 + 256) */
typedef struct ip6_addr {
uint8_t data[IP6_ADDR_LEN];
} ip6_addr_t;
#ifndef __GNUC__
# define __attribute__(x)
# pragma pack(1)
#endif
/*
* IPv6 header
*/
struct ip6_hdr {
union {
struct ip6_hdr_ctl {
uint32_t ip6_un1_flow; /* 20 bits of flow ID */
uint16_t ip6_un1_plen; /* payload length */
uint8_t ip6_un1_nxt; /* next header */
uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
} ip6_ctlun;
ip6_addr_t ip6_src;
ip6_addr_t ip6_dst;
} __attribute__((__packed__));
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt /* IP_PROTO_* */
#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
#define IP6_VERSION 0x60
#define IP6_VERSION_MASK 0xf0 /* ip6_vfc version */
#if DNET_BYTESEX == DNET_BIG_ENDIAN
#define IP6_FLOWINFO_MASK 0x0fffffff /* ip6_flow info (28 bits) */
#define IP6_FLOWLABEL_MASK 0x000fffff /* ip6_flow label (20 bits) */
#elif DNET_BYTESEX == DNET_LIL_ENDIAN
#define IP6_FLOWINFO_MASK 0xffffff0f /* ip6_flow info (28 bits) */
#define IP6_FLOWLABEL_MASK 0xffff0f00 /* ip6_flow label (20 bits) */
#endif
/*
* Hop limit (ip6_hlim)
*/
#define IP6_HLIM_DEFAULT 64
#define IP6_HLIM_MAX 255
/*
* Preferred extension header order from RFC 2460, 4.1:
*
* IP_PROTO_IPV6, IP_PROTO_HOPOPTS, IP_PROTO_DSTOPTS, IP_PROTO_ROUTING,
* IP_PROTO_FRAGMENT, IP_PROTO_AH, IP_PROTO_ESP, IP_PROTO_DSTOPTS, IP_PROTO_*
*/
/*
* Routing header data (IP_PROTO_ROUTING)
*/
struct ip6_ext_data_routing {
uint8_t type; /* routing type */
uint8_t segleft; /* segments left */
/* followed by routing type specific data */
} __attribute__((__packed__));
struct ip6_ext_data_routing0 {
uint8_t type; /* always zero */
uint8_t segleft; /* segments left */
uint8_t reserved; /* reserved field */
uint8_t slmap[3]; /* strict/loose bit map */
ip6_addr_t addr[1]; /* up to 23 addresses */
} __attribute__((__packed__));
/*
* Fragment header data (IP_PROTO_FRAGMENT)
*/
struct ip6_ext_data_fragment {
uint16_t offlg; /* offset, reserved, and flag */
uint32_t ident; /* identification */
} __attribute__((__packed__));
/*
* Fragmentation offset, reserved, and flags (offlg)
*/
#if DNET_BYTESEX == DNET_BIG_ENDIAN
#define IP6_OFF_MASK 0xfff8 /* mask out offset from offlg */
#define IP6_RESERVED_MASK 0x0006 /* reserved bits in offlg */
#define IP6_MORE_FRAG 0x0001 /* more-fragments flag */
#elif DNET_BYTESEX == DNET_LIL_ENDIAN
#define IP6_OFF_MASK 0xf8ff /* mask out offset from offlg */
#define IP6_RESERVED_MASK 0x0600 /* reserved bits in offlg */
#define IP6_MORE_FRAG 0x0100 /* more-fragments flag */
#endif
/*
* Option types, for IP_PROTO_HOPOPTS, IP_PROTO_DSTOPTS headers
*/
#define IP6_OPT_PAD1 0x00 /* 00 0 00000 */
#define IP6_OPT_PADN 0x01 /* 00 0 00001 */
#define IP6_OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
#define IP6_OPT_JUMBO_LEN 6
#define IP6_OPT_RTALERT 0x05 /* 00 0 00101 */
#define IP6_OPT_RTALERT_LEN 4
#define IP6_OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
#define IP6_OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
#define IP6_OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
#define IP6_OPT_LEN_MIN 2
#define IP6_OPT_TYPE(o) ((o) & 0xC0) /* high 2 bits of opt_type */
#define IP6_OPT_TYPE_SKIP 0x00 /* continue processing on failure */
#define IP6_OPT_TYPE_DISCARD 0x40 /* discard packet on failure */
#define IP6_OPT_TYPE_FORCEICMP 0x80 /* discard and send ICMP on failure */
#define IP6_OPT_TYPE_ICMP 0xC0 /* ...only if non-multicast dst */
#define IP6_OPT_MUTABLE 0x20 /* option data may change en route */
/*
* Extension header (chained via {ip6,ext}_nxt, following IPv6 header)
*/
struct ip6_ext_hdr {
uint8_t ext_nxt; /* next header */
uint8_t ext_len; /* following length in units of 8 octets */
union {
struct ip6_ext_data_routing routing;
struct ip6_ext_data_fragment fragment;
} ext_data;
} __attribute__((__packed__));
#ifndef __GNUC__
# pragma pack()
#endif
/*
* Reserved addresses
*/
#define IP6_ADDR_UNSPEC \
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
#define IP6_ADDR_LOOPBACK \
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
#define ip6_pack_hdr(hdr, fc, fl, plen, nxt, hlim, src, dst) do { \
struct ip6_hdr *ip6 = (struct ip6_hdr *)(hdr); \
ip6->ip6_flow = htonl(((uint32_t)(fc) << 28) & \
(IP6_FLOWLABEL_MASK | (fl))); \
ip6->ip6_vfc = (IP6_VERSION | ((fc) >> 4)); \
ip6->ip6_plen = htons((plen)); \
ip6->ip6_nxt = (nxt); ip6->ip6_hlim = (hlim); \
memmove(&ip6->ip6_src, &(src), IP6_ADDR_LEN); \
memmove(&ip6->ip6_dst, &(dst), IP6_ADDR_LEN); \
} while (0);
__BEGIN_DECLS
char *ip6_ntop(const ip6_addr_t *ip6, char *dst, size_t size);
int ip6_pton(const char *src, ip6_addr_t *dst);
char *ip6_ntoa(const ip6_addr_t *ip6);
#define ip6_aton ip6_pton
void ip6_checksum(void *buf, size_t len);
__END_DECLS
#endif /* DNET_IP6_H */

View File

@@ -0,0 +1,130 @@
/*
* os.h
*
* Sleazy OS-specific defines.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: os.h,v 1.12 2005/02/15 05:31:00 dugsong Exp $
*/
#ifndef DNET_OS_H
#define DNET_OS_H
#ifdef _WIN32
# include <winsock2.h>
# include <windows.h>
/* XXX */
# undef IP_OPT_LSRR
# undef IP_OPT_TS
# undef IP_OPT_RR
# undef IP_OPT_SSRR
typedef u_char uint8_t;
typedef u_short uint16_t;
typedef u_int uint32_t;
# ifndef __CYGWIN__
typedef long ssize_t;
# endif
#else
# include <sys/param.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
# ifdef __bsdi__
# include <machine/types.h>
typedef u_int8_t uint8_t;
typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t;
typedef u_int64_t uint64_t;
# else
# include <inttypes.h>
# endif
#endif
#define DNET_LIL_ENDIAN 1234
#define DNET_BIG_ENDIAN 4321
/* BSD and IRIX */
#ifdef BYTE_ORDER
#if BYTE_ORDER == LITTLE_ENDIAN
# define DNET_BYTESEX DNET_LIL_ENDIAN
#elif BYTE_ORDER == BIG_ENDIAN
# define DNET_BYTESEX DNET_BIG_ENDIAN
#endif
#endif
/* Linux */
#ifdef __BYTE_ORDER
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define DNET_BYTESEX DNET_LIL_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
# define DNET_BYTESEX DNET_BIG_ENDIAN
#endif
#endif
/* Solaris */
#if defined(_BIT_FIELDS_LTOH)
# define DNET_BYTESEX DNET_LIL_ENDIAN
#elif defined (_BIT_FIELDS_HTOL)
# define DNET_BYTESEX DNET_BIG_ENDIAN
#endif
/* Win32 - XXX */
#ifdef _WIN32
# define DNET_BYTESEX DNET_LIL_ENDIAN
#endif
/* Nastiness from old BIND code. */
#ifndef DNET_BYTESEX
# if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
defined(__alpha__) || defined(__alpha)
# define DNET_BYTESEX DNET_LIL_ENDIAN
# elif defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
defined(apollo) || defined(__convex__) || defined(_CRAY) || \
defined(__hppa) || defined(__hp9000) || \
defined(__hp9000s300) || defined(__hp9000s700) || defined(__ia64) || \
defined (BIT_ZERO_ON_LEFT) || defined(m68k)
# define DNET_BYTESEX DNET_BIG_ENDIAN
# else
# error "bytesex unknown"
# endif
#endif
/* C++ support. */
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS } /* extern "C" */
#else
# define __BEGIN_DECLS
# define __END_DECLS
#endif
/* Support for flexible arrays. */
#undef __flexarr
#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97))
/* GCC 2.97 supports C99 flexible array members. */
# define __flexarr []
#else
# ifdef __GNUC__
# define __flexarr [0]
# else
# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define __flexarr []
# elif defined(_WIN32)
/* MS VC++ */
# define __flexarr []
# else
/* Some other non-C99 compiler. Approximate with [1]. */
# define __flexarr [1]
# endif
# endif
#endif
#endif /* DNET_OS_H */

View File

@@ -0,0 +1,33 @@
/*
* rand.h
*
* Pseudo-random number generation, based on OpenBSD arc4random().
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
* Copyright (c) 1996 David Mazieres <dm@lcs.mit.edu>
*
* $Id: rand.h,v 1.4 2002/04/07 19:01:25 dugsong Exp $
*/
#ifndef DNET_RAND_H
#define DNET_RAND_H
typedef struct rand_handle rand_t;
__BEGIN_DECLS
rand_t *rand_open(void);
int rand_get(rand_t *r, void *buf, size_t len);
int rand_set(rand_t *r, const void *seed, size_t len);
int rand_add(rand_t *r, const void *buf, size_t len);
uint8_t rand_uint8(rand_t *r);
uint16_t rand_uint16(rand_t *r);
uint32_t rand_uint32(rand_t *r);
int rand_shuffle(rand_t *r, void *base, size_t nmemb, size_t size);
rand_t *rand_close(rand_t *r);
__END_DECLS
#endif /* DNET_RAND_H */

View File

@@ -0,0 +1,35 @@
/*
* route.c
*
* Kernel route table operations.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: route.h,v 1.6 2002/02/04 04:02:22 dugsong Exp $
*/
#ifndef DNET_ROUTE_H
#define DNET_ROUTE_H
/*
* Routing table entry
*/
struct route_entry {
struct addr route_dst; /* destination address */
struct addr route_gw; /* gateway address */
};
typedef struct route_handle route_t;
typedef int (*route_handler)(const struct route_entry *entry, void *arg);
__BEGIN_DECLS
route_t *route_open(void);
int route_add(route_t *r, const struct route_entry *entry);
int route_delete(route_t *r, const struct route_entry *entry);
int route_get(route_t *r, struct route_entry *entry);
int route_loop(route_t *r, route_handler callback, void *arg);
route_t *route_close(route_t *r);
__END_DECLS
#endif /* DNET_ROUTE_H */

View File

@@ -0,0 +1,158 @@
/*
* tcp.h
*
* Transmission Control Protocol (RFC 793).
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: tcp.h,v 1.17 2004/02/23 10:02:11 dugsong Exp $
*/
#ifndef DNET_TCP_H
#define DNET_TCP_H
#define TCP_HDR_LEN 20 /* base TCP header length */
#define TCP_OPT_LEN 2 /* base TCP option length */
#define TCP_OPT_LEN_MAX 40
#define TCP_HDR_LEN_MAX (TCP_HDR_LEN + TCP_OPT_LEN_MAX)
#ifndef __GNUC__
# define __attribute__(x)
# pragma pack(1)
#endif
/*
* TCP header, without options
*/
struct tcp_hdr {
uint16_t th_sport; /* source port */
uint16_t th_dport; /* destination port */
uint32_t th_seq; /* sequence number */
uint32_t th_ack; /* acknowledgment number */
#if DNET_BYTESEX == DNET_BIG_ENDIAN
uint8_t th_off:4, /* data offset */
th_x2:4; /* (unused) */
#elif DNET_BYTESEX == DNET_LIL_ENDIAN
uint8_t th_x2:4,
th_off:4;
#else
# error "need to include <dnet.h>"
#endif
uint8_t th_flags; /* control flags */
uint16_t th_win; /* window */
uint16_t th_sum; /* checksum */
uint16_t th_urp; /* urgent pointer */
};
/*
* TCP control flags (th_flags)
*/
#define TH_FIN 0x01 /* end of data */
#define TH_SYN 0x02 /* synchronize sequence numbers */
#define TH_RST 0x04 /* reset connection */
#define TH_PUSH 0x08 /* push */
#define TH_ACK 0x10 /* acknowledgment number set */
#define TH_URG 0x20 /* urgent pointer set */
#define TH_ECE 0x40 /* ECN echo, RFC 3168 */
#define TH_CWR 0x80 /* congestion window reduced */
#define TCP_PORT_MAX 65535 /* maximum port */
#define TCP_WIN_MAX 65535 /* maximum (unscaled) window */
/*
* Sequence number comparison macros
*/
#define TCP_SEQ_LT(a,b) ((int)((a)-(b)) < 0)
#define TCP_SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
#define TCP_SEQ_GT(a,b) ((int)((a)-(b)) > 0)
#define TCP_SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
/*
* TCP FSM states
*/
#define TCP_STATE_CLOSED 0 /* closed */
#define TCP_STATE_LISTEN 1 /* listening from connection */
#define TCP_STATE_SYN_SENT 2 /* active, have sent SYN */
#define TCP_STATE_SYN_RECEIVED 3 /* have sent and received SYN */
#define TCP_STATE_ESTABLISHED 4 /* established */
#define TCP_STATE_CLOSE_WAIT 5 /* rcvd FIN, waiting for close */
#define TCP_STATE_FIN_WAIT_1 6 /* have closed, sent FIN */
#define TCP_STATE_CLOSING 7 /* closed xchd FIN, await FIN-ACK */
#define TCP_STATE_LAST_ACK 8 /* had FIN and close, await FIN-ACK */
#define TCP_STATE_FIN_WAIT_2 9 /* have closed, FIN is acked */
#define TCP_STATE_TIME_WAIT 10 /* in 2*MSL quiet wait after close */
#define TCP_STATE_MAX 11
/*
* Options (opt_type) - http://www.iana.org/assignments/tcp-parameters
*/
#define TCP_OPT_EOL 0 /* end of option list */
#define TCP_OPT_NOP 1 /* no operation */
#define TCP_OPT_MSS 2 /* maximum segment size */
#define TCP_OPT_WSCALE 3 /* window scale factor, RFC 1072 */
#define TCP_OPT_SACKOK 4 /* SACK permitted, RFC 2018 */
#define TCP_OPT_SACK 5 /* SACK, RFC 2018 */
#define TCP_OPT_ECHO 6 /* echo (obsolete), RFC 1072 */
#define TCP_OPT_ECHOREPLY 7 /* echo reply (obsolete), RFC 1072 */
#define TCP_OPT_TIMESTAMP 8 /* timestamp, RFC 1323 */
#define TCP_OPT_POCONN 9 /* partial order conn, RFC 1693 */
#define TCP_OPT_POSVC 10 /* partial order service, RFC 1693 */
#define TCP_OPT_CC 11 /* connection count, RFC 1644 */
#define TCP_OPT_CCNEW 12 /* CC.NEW, RFC 1644 */
#define TCP_OPT_CCECHO 13 /* CC.ECHO, RFC 1644 */
#define TCP_OPT_ALTSUM 14 /* alt checksum request, RFC 1146 */
#define TCP_OPT_ALTSUMDATA 15 /* alt checksum data, RFC 1146 */
#define TCP_OPT_SKEETER 16 /* Skeeter */
#define TCP_OPT_BUBBA 17 /* Bubba */
#define TCP_OPT_TRAILSUM 18 /* trailer checksum */
#define TCP_OPT_MD5 19 /* MD5 signature, RFC 2385 */
#define TCP_OPT_SCPS 20 /* SCPS capabilities */
#define TCP_OPT_SNACK 21 /* selective negative acks */
#define TCP_OPT_REC 22 /* record boundaries */
#define TCP_OPT_CORRUPT 23 /* corruption experienced */
#define TCP_OPT_SNAP 24 /* SNAP */
#define TCP_OPT_TCPCOMP 26 /* TCP compression filter */
#define TCP_OPT_MAX 27
#define TCP_OPT_TYPEONLY(type) \
((type) == TCP_OPT_EOL || (type) == TCP_OPT_NOP)
/*
* TCP option (following TCP header)
*/
struct tcp_opt {
uint8_t opt_type; /* option type */
uint8_t opt_len; /* option length >= TCP_OPT_LEN */
union tcp_opt_data {
uint16_t mss; /* TCP_OPT_MSS */
uint8_t wscale; /* TCP_OPT_WSCALE */
uint16_t sack[19]; /* TCP_OPT_SACK */
uint32_t echo; /* TCP_OPT_ECHO{REPLY} */
uint32_t timestamp[2]; /* TCP_OPT_TIMESTAMP */
uint32_t cc; /* TCP_OPT_CC{NEW,ECHO} */
uint8_t cksum; /* TCP_OPT_ALTSUM */
uint8_t md5[16]; /* TCP_OPT_MD5 */
uint8_t data8[TCP_OPT_LEN_MAX - TCP_OPT_LEN];
} opt_data;
} __attribute__((__packed__));
#ifndef __GNUC__
# pragma pack()
#endif
#define tcp_pack_hdr(hdr, sport, dport, seq, ack, flags, win, urp) do { \
struct tcp_hdr *tcp_pack_p = (struct tcp_hdr *)(hdr); \
tcp_pack_p->th_sport = htons(sport); \
tcp_pack_p->th_dport = htons(dport); \
tcp_pack_p->th_seq = htonl(seq); \
tcp_pack_p->th_ack = htonl(ack); \
tcp_pack_p->th_x2 = 0; tcp_pack_p->th_off = 5; \
tcp_pack_p->th_flags = flags; \
tcp_pack_p->th_win = htons(win); \
tcp_pack_p->th_urp = htons(urp); \
} while (0)
#endif /* DNET_TCP_H */

View File

@@ -0,0 +1,25 @@
/*
* tun.h
*
* Network tunnel device.
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: tun.h,v 1.2 2005/01/25 21:29:12 dugsong Exp $
*/
#ifndef DNET_TUN_H
#define DNET_TUN_H
typedef struct tun tun_t;
__BEGIN_DECLS
tun_t *tun_open(struct addr *src, struct addr *dst, int mtu);
int tun_fileno(tun_t *tun);
const char *tun_name(tun_t *tun);
ssize_t tun_send(tun_t *tun, const void *buf, size_t size);
ssize_t tun_recv(tun_t *tun, void *buf, size_t size);
tun_t *tun_close(tun_t *tun);
__END_DECLS
#endif /* DNET_TUN_H */

View File

@@ -0,0 +1,32 @@
/*
* udp.h
*
* User Datagram Protocol (RFC 768).
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: udp.h,v 1.8 2002/04/02 05:05:39 dugsong Exp $
*/
#ifndef DNET_UDP_H
#define DNET_UDP_H
#define UDP_HDR_LEN 8
struct udp_hdr {
uint16_t uh_sport; /* source port */
uint16_t uh_dport; /* destination port */
uint16_t uh_ulen; /* udp length (including header) */
uint16_t uh_sum; /* udp checksum */
};
#define UDP_PORT_MAX 65535
#define udp_pack_hdr(hdr, sport, dport, ulen) do { \
struct udp_hdr *udp_pack_p = (struct udp_hdr *)(hdr); \
udp_pack_p->uh_sport = htons(sport); \
udp_pack_p->uh_dport = htons(dport); \
udp_pack_p->uh_ulen = htons(ulen); \
} while (0)
#endif /* DNET_UDP_H */

View File

@@ -0,0 +1,50 @@
/*
* err.h
*
* Adapted from OpenBSD libc *err* *warn* code.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* Copyright (c) 1993
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)err.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _ERR_H_
#define _ERR_H_
void err(int eval, const char *fmt, ...);
void warn(const char *fmt, ...);
void errx(int eval, const char *fmt, ...);
void warnx(const char *fmt, ...);
#endif /* !_ERR_H_ */

View File

@@ -0,0 +1,503 @@
/* $OpenBSD: queue.h,v 1.22 2001/06/23 04:39:35 angelos Exp $ */
/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
/*
* Copyright (c) 1991, 1993
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
*
* A singly-linked list is headed by a single forward pointer. The elements
* are singly linked for minimum space and pointer manipulation overhead at
* the expense of O(n) removal for arbitrary elements. New elements can be
* added to the list after an existing element or at the head of the list.
* Elements being removed from the head of the list should use the explicit
* macro for this purpose for optimum efficiency. A singly-linked list may
* only be traversed in the forward direction. Singly-linked lists are ideal
* for applications with large datasets and few or no removals or for
* implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_END(head) NULL
#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
for((var) = SLIST_FIRST(head); \
(var) != SLIST_END(head); \
(var) = SLIST_NEXT(var, field))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) { \
SLIST_FIRST(head) = SLIST_END(head); \
}
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = (head)->slh_first; \
while( curelm->field.sle_next != (elm) ) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
} while (0)
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List access methods
*/
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_END(head) NULL
#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_FOREACH(var, head, field) \
for((var) = LIST_FIRST(head); \
(var)!= LIST_END(head); \
(var) = LIST_NEXT(var, field))
/*
* List functions.
*/
#define LIST_INIT(head) do { \
LIST_FIRST(head) = LIST_END(head); \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (0)
#define LIST_REMOVE(elm, field) do { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
} while (0)
#define LIST_REPLACE(elm, elm2, field) do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
&(elm2)->field.le_next; \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
} while (0)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue access methods.
*/
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_END(head) NULL
#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define SIMPLEQ_FOREACH(var, head, field) \
for((var) = SIMPLEQ_FIRST(head); \
(var) != SIMPLEQ_END(head); \
(var) = SIMPLEQ_NEXT(var, field))
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (0)
#define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
/*
* Tail queue definitions.
*/
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
#define TAILQ_ENTRY(type) \
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}
/*
* tail queue access methods
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) NULL
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
/* XXX */
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_EMPTY(head) \
(TAILQ_FIRST(head) == TAILQ_END(head))
#define TAILQ_FOREACH(var, head, field) \
for((var) = TAILQ_FIRST(head); \
(var) != TAILQ_END(head); \
(var) = TAILQ_NEXT(var, field))
#define TAILQ_FOREACH_REVERSE(var, head, field, headname) \
for((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head); \
(var) = TAILQ_PREV(var, headname, field))
/*
* Tail queue functions.
*/
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) do { \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
(elm2)->field.tqe_next->field.tqe_prev = \
&(elm2)->field.tqe_next; \
else \
(head)->tqh_last = &(elm2)->field.tqe_next; \
(elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
*(elm2)->field.tqe_prev = (elm2); \
} while (0)
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue access methods
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_END(head) ((void *)(head))
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
(CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
#define CIRCLEQ_FOREACH(var, head, field) \
for((var) = CIRCLEQ_FIRST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_NEXT(var, field))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for((var) = CIRCLEQ_LAST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_PREV(var, field))
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = CIRCLEQ_END(head); \
(head)->cqh_last = CIRCLEQ_END(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
if ((head)->cqh_last == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.cqe_next = CIRCLEQ_END(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
} while (0)
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
CIRCLEQ_END(head)) \
(head).cqh_last = (elm2); \
else \
(elm2)->field.cqe_next->field.cqe_prev = (elm2); \
if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
CIRCLEQ_END(head)) \
(head).cqh_first = (elm2); \
else \
(elm2)->field.cqe_prev->field.cqe_next = (elm2); \
} while (0)
#endif /* !_SYS_QUEUE_H_ */

View File

@@ -0,0 +1 @@
timestamp

View File

@@ -0,0 +1 @@
timestamp for include/config.h

7360
libdnet-stripped/libtool Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,467 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# src/Makefile. Generated from Makefile.in by configure.
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
srcdir = .
top_srcdir = ..
pkgdatadir = $(datadir)/libdnet
pkglibdir = $(libdir)/libdnet
pkgincludedir = $(includedir)/libdnet
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = x86_64-unknown-linux-gnu
host_triplet = x86_64-unknown-linux-gnu
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(top_srcdir)/Makefile.am.common arp-bsd.c arp-ioctl.c \
arp-none.c arp-win32.c err.c eth-bsd.c eth-dlpi.c eth-linux.c \
eth-ndd.c eth-none.c eth-pfilt.c eth-snoop.c eth-win32.c \
fw-ipchains.c fw-ipf.c fw-ipfw.c fw-none.c fw-pf.c \
fw-pktfilter.c intf-win32.c intf.c ip-cooked.c ip-win32.c ip.c \
memcmp.c route-bsd.c route-hpux.c route-linux.c route-none.c \
route-win32.c strlcat.c strlcpy.c strsep.c tun-bsd.c \
tun-linux.c tun-none.c tun-solaris.c
subdir = src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libdnet_la_DEPENDENCIES = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
am_libdnet_la_OBJECTS = addr-util.lo addr.lo blob.lo ip-util.lo ip6.lo \
rand.lo
libdnet_la_OBJECTS = $(am_libdnet_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
depcomp =
am__depfiles_maybe =
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
DIST_SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run aclocal-1.9
AMDEP_FALSE = #
AMDEP_TRUE =
AMTAR = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run tar
AR = ar
AUTOCONF = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoconf
AUTOHEADER = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run autoheader
AUTOMAKE = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run automake-1.9
AWK = gawk
CC = gcc
CCDEPMODE = depmode=none
CFLAGS = -g -O2 -Wall
CHECKINC =
CHECKLIB =
CPP = gcc -E
CPPFLAGS =
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=none
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
EGREP = grep -E
EXEEXT =
F77 = g77
FFLAGS = -g -O2
HAVE_CHECK_FALSE =
HAVE_CHECK_TRUE = #
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
LDFLAGS =
LIBOBJS = strlcat$U.o strlcpy$U.o arp-ioctl$U.o eth-linux$U.o fw-ipchains$U.o intf$U.o ip$U.o route-linux$U.o tun-linux$U.o
LIBS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LN_S = ln -s
LTLIBOBJS = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
MAINT = #
MAINTAINER_MODE_FALSE =
MAINTAINER_MODE_TRUE = #
MAKEINFO = ${SHELL} /home/fyodor/nmap/libdnet-stripped/config/missing --run makeinfo
OBJEXT = o
PACKAGE = libdnet
PACKAGE_BUGREPORT =
PACKAGE_NAME =
PACKAGE_STRING =
PACKAGE_TARNAME =
PACKAGE_VERSION =
PATH_SEPARATOR = :
PYTHON =
PYTHON_FALSE =
PYTHON_TRUE = #
RANLIB = ranlib
SET_MAKE =
SHELL = /bin/sh
STRIP = strip
TCLINC =
TCLLIB =
TCL_FALSE =
TCL_TRUE = #
VERSION = 1.10
ac_aux_dir = config
ac_ct_AR = ar
ac_ct_CC = gcc
ac_ct_CXX = g++
ac_ct_F77 = g77
ac_ct_RANLIB = ranlib
ac_ct_STRIP = strip
am__fastdepCC_FALSE =
am__fastdepCC_TRUE = #
am__fastdepCXX_FALSE =
am__fastdepCXX_TRUE = #
am__include = include
am__leading_dot = .
am__quote =
am__tar = ${AMTAR} chof - "$$tardir"
am__untar = ${AMTAR} xf -
bindir = ${exec_prefix}/bin
build = x86_64-unknown-linux-gnu
build_alias =
build_cpu = x86_64
build_os = linux-gnu
build_vendor = unknown
datadir = ${prefix}/share
exec_prefix = ${prefix}
host = x86_64-unknown-linux-gnu
host_alias =
host_cpu = x86_64
host_os = linux-gnu
host_vendor = unknown
includedir = ${prefix}/include
infodir = ${prefix}/info
install_sh = /home/fyodor/nmap/libdnet-stripped/config/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
mkdir_p = mkdir -p --
oldincludedir = /usr/include
prefix = /usr/local
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
sysconfdir = ${prefix}/etc
target_alias =
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
lib_LTLIBRARIES = libdnet.la
libdnet_la_SOURCES = addr-util.c addr.c blob.c ip-util.c ip6.c rand.c
EXTRA_libdnet_la_SOURCES =
libdnet_la_LIBADD = strlcat$U.lo strlcpy$U.lo arp-ioctl$U.lo eth-linux$U.lo fw-ipchains$U.lo intf$U.lo ip$U.lo route-linux$U.lo tun-linux$U.lo
libdnet_la_LDFLAGS = -version-info 1:0:0
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: # $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): # $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libdnet.la: $(libdnet_la_OBJECTS) $(libdnet_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libdnet_la_LDFLAGS) $(libdnet_la_OBJECTS) $(libdnet_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
.c.o:
$(COMPILE) -c $<
.c.obj:
$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES)
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-exec-am: install-libLTLIBRARIES
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-exec \
install-exec-am install-info install-info-am \
install-libLTLIBRARIES install-man install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-info-am \
uninstall-libLTLIBRARIES
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,13 @@
## $Id: Makefile.am,v 1.16 2005/02/10 17:06:36 dugsong Exp $
include $(top_srcdir)/Makefile.am.common
lib_LTLIBRARIES = libdnet.la
libdnet_la_SOURCES = addr-util.c addr.c blob.c ip-util.c ip6.c rand.c
EXTRA_libdnet_la_SOURCES =
libdnet_la_LIBADD = @LTLIBOBJS@
libdnet_la_LDFLAGS = -version-info 1:0:0

View File

@@ -0,0 +1,467 @@
# Makefile.in generated by automake 1.9.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(top_srcdir)/Makefile.am.common arp-bsd.c arp-ioctl.c \
arp-none.c arp-win32.c err.c eth-bsd.c eth-dlpi.c eth-linux.c \
eth-ndd.c eth-none.c eth-pfilt.c eth-snoop.c eth-win32.c \
fw-ipchains.c fw-ipf.c fw-ipfw.c fw-none.c fw-pf.c \
fw-pktfilter.c intf-win32.c intf.c ip-cooked.c ip-win32.c ip.c \
memcmp.c route-bsd.c route-hpux.c route-linux.c route-none.c \
route-win32.c strlcat.c strlcpy.c strsep.c tun-bsd.c \
tun-linux.c tun-none.c tun-solaris.c
subdir = src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/config/acinclude.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libdnet_la_DEPENDENCIES = @LTLIBOBJS@
am_libdnet_la_OBJECTS = addr-util.lo addr.lo blob.lo ip-util.lo ip6.lo \
rand.lo
libdnet_la_OBJECTS = $(am_libdnet_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
depcomp =
am__depfiles_maybe =
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link --tag=CC $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
DIST_SOURCES = $(libdnet_la_SOURCES) $(EXTRA_libdnet_la_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CHECKINC = @CHECKINC@
CHECKLIB = @CHECKLIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
HAVE_CHECK_FALSE = @HAVE_CHECK_FALSE@
HAVE_CHECK_TRUE = @HAVE_CHECK_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PYTHON = @PYTHON@
PYTHON_FALSE = @PYTHON_FALSE@
PYTHON_TRUE = @PYTHON_TRUE@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TCLINC = @TCLINC@
TCLLIB = @TCLLIB@
TCL_FALSE = @TCL_FALSE@
TCL_TRUE = @TCL_TRUE@
VERSION = @VERSION@
ac_aux_dir = @ac_aux_dir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
AUTOMAKE_OPTIONS = foreign no-dependencies
INCLUDES = -I$(top_srcdir)/include
DISTCLEANFILES = *~
lib_LTLIBRARIES = libdnet.la
libdnet_la_SOURCES = addr-util.c addr.c blob.c ip-util.c ip6.c rand.c
EXTRA_libdnet_la_SOURCES =
libdnet_la_LIBADD = @LTLIBOBJS@
libdnet_la_LDFLAGS = -version-info 1:0:0
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/Makefile.am.common $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
if test -f $$p; then \
f=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
else :; fi; \
done
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
p=$(am__strip_dir) \
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libdnet.la: $(libdnet_la_OBJECTS) $(libdnet_la_DEPENDENCIES)
$(LINK) -rpath $(libdir) $(libdnet_la_LDFLAGS) $(libdnet_la_OBJECTS) $(libdnet_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
.c.o:
$(COMPILE) -c $<
.c.obj:
$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
-rm -f libtool
uninstall-info-am:
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
$(mkdir_p) $(distdir)/..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES)
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am:
install-exec-am: install-libLTLIBRARIES
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libLTLIBRARIES clean-libtool ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-exec \
install-exec-am install-info install-info-am \
install-libLTLIBRARIES install-man install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-info-am \
uninstall-libLTLIBRARIES
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,292 @@
/*
* addr-util.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: addr-util.c,v 1.4 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
static const char *octet2dec[] = {
"0", "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", "121", "122", "123", "124", "125", "126", "127",
"128", "129", "130", "131", "132", "133", "134", "135", "136",
"137", "138", "139", "140", "141", "142", "143", "144", "145",
"146", "147", "148", "149", "150", "151", "152", "153", "154",
"155", "156", "157", "158", "159", "160", "161", "162", "163",
"164", "165", "166", "167", "168", "169", "170", "171", "172",
"173", "174", "175", "176", "177", "178", "179", "180", "181",
"182", "183", "184", "185", "186", "187", "188", "189", "190",
"191", "192", "193", "194", "195", "196", "197", "198", "199",
"200", "201", "202", "203", "204", "205", "206", "207", "208",
"209", "210", "211", "212", "213", "214", "215", "216", "217",
"218", "219", "220", "221", "222", "223", "224", "225", "226",
"227", "228", "229", "230", "231", "232", "233", "234", "235",
"236", "237", "238", "239", "240", "241", "242", "243", "244",
"245", "246", "247", "248", "249", "250", "251", "252", "253",
"254", "255"
};
static const char *octet2hex[] = {
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a",
"0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b",
"2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36",
"37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41",
"42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c",
"4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57",
"58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62",
"63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d",
"6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78",
"79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83",
"84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e",
"8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
"9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4",
"a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af",
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba",
"bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5",
"c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0",
"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db",
"dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6",
"e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1",
"f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc",
"fd", "fe", "ff"
};
char *
eth_ntop(const eth_addr_t *eth, char *dst, size_t len)
{
const char *x;
char *p = dst;
int i;
if (len < 18)
return (NULL);
for (i = 0; i < ETH_ADDR_LEN; i++) {
for (x = octet2hex[eth->data[i]]; (*p = *x) != '\0'; x++, p++)
;
*p++ = ':';
}
p[-1] = '\0';
return (dst);
}
char *
eth_ntoa(const eth_addr_t *eth)
{
struct addr a;
addr_pack(&a, ADDR_TYPE_ETH, ETH_ADDR_BITS, eth->data, ETH_ADDR_LEN);
return (addr_ntoa(&a));
}
int
eth_pton(const char *p, eth_addr_t *eth)
{
char *ep;
long l;
int i;
for (i = 0; i < ETH_ADDR_LEN; i++) {
l = strtol(p, &ep, 16);
if (ep == p || l < 0 || l > 0xff ||
(i < ETH_ADDR_LEN - 1 && *ep != ':'))
break;
eth->data[i] = (u_char)l;
p = ep + 1;
}
return ((i == ETH_ADDR_LEN && *ep == '\0') ? 0 : -1);
}
char *
ip_ntop(const ip_addr_t *ip, char *dst, size_t len)
{
const char *d;
char *p = dst;
u_char *data = (u_char *)ip;
int i;
if (len < 16)
return (NULL);
for (i = 0; i < IP_ADDR_LEN; i++) {
for (d = octet2dec[data[i]]; (*p = *d) != '\0'; d++, p++)
;
*p++ = '.';
}
p[-1] = '\0';
return (dst);
}
char *
ip_ntoa(const ip_addr_t *ip)
{
struct addr a;
addr_pack(&a, ADDR_TYPE_IP, IP_ADDR_BITS, ip, IP_ADDR_LEN);
return (addr_ntoa(&a));
}
int
ip_pton(const char *p, ip_addr_t *ip)
{
u_char *data = (u_char *)ip;
char *ep;
long l;
int i;
for (i = 0; i < IP_ADDR_LEN; i++) {
l = strtol(p, &ep, 10);
if (ep == p || l < 0 || l > 0xff ||
(i < IP_ADDR_LEN - 1 && *ep != '.'))
break;
data[i] = (u_char)l;
p = ep + 1;
}
return ((i == IP_ADDR_LEN && *ep == '\0') ? 0 : -1);
}
char *
ip6_ntop(const ip6_addr_t *ip6, char *dst, size_t len)
{
struct { int base, len; } best, cur;
char *p = dst;
int i;
if (len < 46)
return (NULL);
best.base = cur.base = -1;
/*
* Algorithm borrowed from Vixie's inet_pton6()
*/
for (i = 0; i < IP6_ADDR_LEN; i += 2) {
if (*((uint16_t *)&ip6->data[i]) == 0) {
if (cur.base == -1) {
cur.base = i;
cur.len = 0;
} else
cur.len += 2;
} else {
if (cur.base != -1) {
if (best.base == -1 || cur.len > best.len)
best = cur;
cur.base = -1;
}
}
}
if (cur.base != -1 && (best.base == -1 || cur.len > best.len))
best = cur;
if (best.base != -1 && best.len < 2)
best.base = -1;
if (best.base == 0)
*p++ = ':';
for (i = 0; i < IP6_ADDR_LEN; i += 2) {
if (i == best.base) {
*p++ = ':';
i += best.len;
} else if (i == 12 && best.base == 0 &&
(best.len == 10 || (best.len == 8 &&
*((uint16_t *)&ip6->data[10]) == 0xffff))) {
if (ip_ntop((ip_addr_t *)&ip6->data[12], p,
len - (p - dst)) == NULL)
return (NULL);
return (dst);
} else p += sprintf(p, "%x:",
ntohs(*((uint16_t *)&ip6->data[i])));
}
if (best.base + 2 + best.len == IP6_ADDR_LEN) {
*p = '\0';
} else
p[-1] = '\0';
return (dst);
}
char *
ip6_ntoa(const ip6_addr_t *ip6)
{
struct addr a;
addr_pack(&a, ADDR_TYPE_IP6, IP6_ADDR_BITS, ip6->data, IP6_ADDR_LEN);
return (addr_ntoa(&a));
}
int
ip6_pton(const char *p, ip6_addr_t *ip6)
{
uint16_t data[8], *u = (uint16_t *)ip6->data;
int i, j, n, z = -1;
char *ep;
long l;
if (*p == ':')
p++;
for (n = 0; n < 8; n++) {
l = strtol(p, &ep, 16);
if (ep == p) {
if (ep[0] == ':' && z == -1) {
z = n;
p++;
} else if (ep[0] == '\0') {
break;
} else {
return (-1);
}
} else if (ep[0] == '.' && n <= 6) {
if (ip_pton(p, (ip_addr_t *)(data + n)) < 0)
return (-1);
n += 2;
ep = ""; /* XXX */
break;
} else if (l >= 0 && l <= 0xffff) {
data[n] = htons((uint16_t)l);
if (ep[0] == '\0') {
n++;
break;
} else if (ep[0] != ':' || ep[1] == '\0')
return (-1);
p = ep + 1;
} else
return (-1);
}
if (n == 0 || *ep != '\0' || (z == -1 && n != 8))
return (-1);
for (i = 0; i < z; i++) {
u[i] = data[i];
}
while (i < 8 - (n - z - 1)) {
u[i++] = 0;
}
for (j = z + 1; i < 8; i++, j++) {
u[i] = data[j];
}
return (0);
}

455
libdnet-stripped/src/addr.c Normal file
View File

@@ -0,0 +1,455 @@
/*
* addr.c
*
* Network address operations.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: addr.c,v 1.33 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#ifdef HAVE_NET_IF_H
# include <sys/socket.h>
# include <net/if.h>
#endif
#ifdef HAVE_NET_IF_DL_H
# include <net/if_dl.h>
#endif
#ifdef HAVE_NET_RAW_H
# include <net/raw.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif
union sockunion {
#ifdef HAVE_NET_IF_DL_H
struct sockaddr_dl sdl;
#endif
struct sockaddr_in sin;
#ifdef HAVE_SOCKADDR_IN6
struct sockaddr_in6 sin6;
#endif
struct sockaddr sa;
#ifdef AF_RAW
struct sockaddr_raw sr;
#endif
};
int
addr_cmp(const struct addr *a, const struct addr *b)
{
int i, j, k;
/* XXX */
if ((i = a->addr_type - b->addr_type) != 0)
return (i);
/* XXX - 10.0.0.1 is "smaller" than 10.0.0.0/8? */
if ((i = a->addr_bits - b->addr_bits) != 0)
return (i);
j = b->addr_bits / 8;
for (i = 0; i < j; i++) {
if ((k = a->addr_data8[i] - b->addr_data8[i]) != 0)
return (k);
}
if ((k = b->addr_bits % 8) == 0)
return (0);
k = ~0 << (8 - k);
i = b->addr_data8[j] & k;
j = a->addr_data8[j] & k;
return (j - i);
}
int
addr_net(const struct addr *a, struct addr *b)
{
uint32_t mask;
int i, j;
if (a->addr_type == ADDR_TYPE_IP) {
addr_btom(a->addr_bits, &mask, IP_ADDR_LEN);
b->addr_type = ADDR_TYPE_IP;
b->addr_bits = IP_ADDR_BITS;
b->addr_ip = a->addr_ip & mask;
} else if (a->addr_type == ADDR_TYPE_ETH) {
memcpy(b, a, sizeof(*b));
if (a->addr_data8[0] & 0x1)
memset(b->addr_data8 + 3, 0, 3);
b->addr_bits = ETH_ADDR_BITS;
} else if (a->addr_type == ADDR_TYPE_IP6) {
b->addr_type = ADDR_TYPE_IP6;
b->addr_bits = IP6_ADDR_BITS;
memset(&b->addr_ip6, 0, IP6_ADDR_LEN);
switch ((i = a->addr_bits / 32)) {
case 4: b->addr_data32[3] = a->addr_data32[3];
case 3: b->addr_data32[2] = a->addr_data32[2];
case 2: b->addr_data32[1] = a->addr_data32[1];
case 1: b->addr_data32[0] = a->addr_data32[0];
}
if ((j = a->addr_bits % 32) > 0) {
addr_btom(j, &mask, sizeof(mask));
b->addr_data32[i] = a->addr_data32[i] & mask;
}
} else
return (-1);
return (0);
}
int
addr_bcast(const struct addr *a, struct addr *b)
{
struct addr mask;
if (a->addr_type == ADDR_TYPE_IP) {
addr_btom(a->addr_bits, &mask.addr_ip, IP_ADDR_LEN);
b->addr_type = ADDR_TYPE_IP;
b->addr_bits = IP_ADDR_BITS;
b->addr_ip = (a->addr_ip & mask.addr_ip) |
(~0L & ~mask.addr_ip);
} else if (a->addr_type == ADDR_TYPE_ETH) {
b->addr_type = ADDR_TYPE_ETH;
b->addr_bits = ETH_ADDR_BITS;
memcpy(&b->addr_eth, ETH_ADDR_BROADCAST, ETH_ADDR_LEN);
} else {
/* XXX - no broadcast addresses in IPv6 */
errno = EINVAL;
return (-1);
}
return (0);
}
char *
addr_ntop(const struct addr *src, char *dst, size_t size)
{
if (src->addr_type == ADDR_TYPE_IP && size >= 20) {
if (ip_ntop(&src->addr_ip, dst, size) != NULL) {
if (src->addr_bits != IP_ADDR_BITS)
sprintf(dst + strlen(dst), "/%d",
src->addr_bits);
return (dst);
}
} else if (src->addr_type == ADDR_TYPE_IP6 && size >= 42) {
if (ip6_ntop(&src->addr_ip6, dst, size) != NULL) {
if (src->addr_bits != IP6_ADDR_BITS)
sprintf(dst + strlen(dst), "/%d",
src->addr_bits);
return (dst);
}
} else if (src->addr_type == ADDR_TYPE_ETH && size >= 18) {
if (src->addr_bits == ETH_ADDR_BITS)
return (eth_ntop(&src->addr_eth, dst, size));
}
errno = EINVAL;
return (NULL);
}
int
addr_pton(const char *src, struct addr *dst)
{
struct hostent *hp;
char *ep, tmp[300];
long bits = -1;
int i;
for (i = 0; i < (int)sizeof(tmp) - 1; i++) {
if (src[i] == '/') {
tmp[i] = '\0';
if (strchr(&src[i + 1], '.')) {
uint32_t m;
uint16_t b;
/* XXX - mask is specified like /255.0.0.0 */
if (ip_pton(&src[i + 1], &m) != 0) {
errno = EINVAL;
return (-1);
}
addr_mtob(&m, sizeof(m), &b);
bits = b;
} else {
bits = strtol(&src[i + 1], &ep, 10);
if (ep == src || *ep != '\0' || bits < 0) {
errno = EINVAL;
return (-1);
}
}
break;
} else if ((tmp[i] = src[i]) == '\0')
break;
}
if (ip_pton(tmp, &dst->addr_ip) == 0) {
dst->addr_type = ADDR_TYPE_IP;
dst->addr_bits = IP_ADDR_BITS;
} else if (eth_pton(tmp, &dst->addr_eth) == 0) {
dst->addr_type = ADDR_TYPE_ETH;
dst->addr_bits = ETH_ADDR_BITS;
} else if (ip6_pton(tmp, &dst->addr_ip6) == 0) {
dst->addr_type = ADDR_TYPE_IP6;
dst->addr_bits = IP6_ADDR_BITS;
} else if ((hp = gethostbyname(tmp)) != NULL) {
memcpy(&dst->addr_ip, hp->h_addr, IP_ADDR_LEN);
dst->addr_type = ADDR_TYPE_IP;
dst->addr_bits = IP_ADDR_BITS;
} else {
errno = EINVAL;
return (-1);
}
if (bits >= 0) {
if (bits > dst->addr_bits) {
errno = EINVAL;
return (-1);
}
dst->addr_bits = (uint16_t)bits;
}
return (0);
}
char *
addr_ntoa(const struct addr *a)
{
static char *p, buf[BUFSIZ];
char *q = NULL;
if (p == NULL || p > buf + sizeof(buf) - 64 /* XXX */)
p = buf;
if (addr_ntop(a, p, (buf + sizeof(buf)) - p) != NULL) {
q = p;
p += strlen(p) + 1;
}
return (q);
}
int
addr_ntos(const struct addr *a, struct sockaddr *sa)
{
union sockunion *so = (union sockunion *)sa;
switch (a->addr_type) {
case ADDR_TYPE_ETH:
#ifdef HAVE_NET_IF_DL_H
memset(&so->sdl, 0, sizeof(so->sdl));
#ifdef HAVE_SOCKADDR_SA_LEN
so->sdl.sdl_len = sizeof(so->sdl);
#endif
so->sdl.sdl_family = AF_LINK;
so->sdl.sdl_alen = ETH_ADDR_LEN;
memcpy(LLADDR(&so->sdl), &a->addr_eth, ETH_ADDR_LEN);
#else
memset(sa, 0, sizeof(*sa));
sa->sa_family = AF_UNSPEC;
memcpy(sa->sa_data, &a->addr_eth, ETH_ADDR_LEN);
#endif
break;
#ifdef HAVE_SOCKADDR_IN6
case ADDR_TYPE_IP6:
memset(&so->sin6, 0, sizeof(so->sin6));
#ifdef HAVE_SOCKADDR_SA_LEN
so->sin6.sin6_len = sizeof(so->sin6);
#endif
so->sin6.sin6_family = AF_INET6;
memcpy(&so->sin6.sin6_addr, &a->addr_ip6, IP6_ADDR_LEN);
break;
#endif
case ADDR_TYPE_IP:
memset(&so->sin, 0, sizeof(so->sin));
#ifdef HAVE_SOCKADDR_SA_LEN
so->sin.sin_len = sizeof(so->sin);
#endif
so->sin.sin_family = AF_INET;
so->sin.sin_addr.s_addr = a->addr_ip;
break;
default:
errno = EINVAL;
return (-1);
}
return (0);
}
int
addr_ston(const struct sockaddr *sa, struct addr *a)
{
union sockunion *so = (union sockunion *)sa;
memset(a, 0, sizeof(*a));
switch (sa->sa_family) {
#ifdef HAVE_NET_IF_DL_H
case AF_LINK:
if (so->sdl.sdl_alen != ETH_ADDR_LEN) {
errno = EINVAL;
return (-1);
}
a->addr_type = ADDR_TYPE_ETH;
a->addr_bits = ETH_ADDR_BITS;
memcpy(&a->addr_eth, LLADDR(&so->sdl), ETH_ADDR_LEN);
break;
#endif
case AF_UNSPEC:
case ARP_HRD_ETH: /* XXX- Linux arp(7) */
a->addr_type = ADDR_TYPE_ETH;
a->addr_bits = ETH_ADDR_BITS;
memcpy(&a->addr_eth, sa->sa_data, ETH_ADDR_LEN);
break;
#ifdef AF_RAW
case AF_RAW: /* XXX - IRIX raw(7f) */
a->addr_type = ADDR_TYPE_ETH;
a->addr_bits = ETH_ADDR_BITS;
memcpy(&a->addr_eth, so->sr.sr_addr, ETH_ADDR_LEN);
break;
#endif
#ifdef HAVE_SOCKADDR_IN6
case AF_INET6:
a->addr_type = ADDR_TYPE_IP6;
a->addr_bits = IP6_ADDR_BITS;
memcpy(&a->addr_ip6, &so->sin6.sin6_addr, IP6_ADDR_LEN);
break;
#endif
case AF_INET:
a->addr_type = ADDR_TYPE_IP;
a->addr_bits = IP_ADDR_BITS;
a->addr_ip = so->sin.sin_addr.s_addr;
break;
default:
errno = EINVAL;
return (-1);
}
return (0);
}
int
addr_btos(uint16_t bits, struct sockaddr *sa)
{
union sockunion *so = (union sockunion *)sa;
#ifdef HAVE_SOCKADDR_IN6
if (bits > IP_ADDR_BITS && bits <= IP6_ADDR_BITS) {
memset(&so->sin6, 0, sizeof(so->sin6));
#ifdef HAVE_SOCKADDR_SA_LEN
so->sin6.sin6_len = IP6_ADDR_LEN + (bits / 8) + (bits % 8);
#endif
so->sin6.sin6_family = AF_INET6;
return (addr_btom(bits, &so->sin6.sin6_addr, IP6_ADDR_LEN));
} else
#endif
if (bits <= IP_ADDR_BITS) {
memset(&so->sin, 0, sizeof(so->sin));
#ifdef HAVE_SOCKADDR_SA_LEN
so->sin.sin_len = IP_ADDR_LEN + (bits / 8) + (bits % 8);
#endif
so->sin.sin_family = AF_INET;
return (addr_btom(bits, &so->sin.sin_addr, IP_ADDR_LEN));
}
errno = EINVAL;
return (-1);
}
int
addr_stob(const struct sockaddr *sa, uint16_t *bits)
{
union sockunion *so = (union sockunion *)sa;
int i, j, len;
uint16_t n;
u_char *p;
#ifdef HAVE_SOCKADDR_IN6
if (sa->sa_family == AF_INET6) {
len = IP6_ADDR_LEN;
p = (u_char *)&so->sin6.sin6_addr;
} else
#endif
{
#ifdef HAVE_SOCKADDR_SA_LEN
if ((len = sa->sa_len - IP_ADDR_LEN) > IP_ADDR_LEN)
#endif
len = IP_ADDR_LEN;
p = (u_char *)&so->sin.sin_addr.s_addr;
}
for (n = i = 0; i < len; i++, n += 8) {
if (p[i] != 0xff)
break;
}
if (i != len && p[i]) {
for (j = 7; j > 0; j--, n++) {
if ((p[i] & (1 << j)) == 0)
break;
}
}
*bits = n;
return (0);
}
int
addr_btom(uint16_t bits, void *mask, size_t size)
{
int net, host;
u_char *p;
if (size == IP_ADDR_LEN) {
if (bits > IP_ADDR_BITS) {
errno = EINVAL;
return (-1);
}
*(uint32_t *)mask = bits ?
htonl(~0 << (IP_ADDR_BITS - bits)) : 0;
} else {
if (size * 8 < bits) {
errno = EINVAL;
return (-1);
}
p = (u_char *)mask;
if ((net = bits / 8) > 0)
memset(p, 0xff, net);
if ((host = bits % 8) > 0) {
p[net] = 0xff << (8 - host);
memset(&p[net + 1], 0, size - net - 1);
} else
memset(&p[net], 0, size - net);
}
return (0);
}
int
addr_mtob(const void *mask, size_t size, uint16_t *bits)
{
uint16_t n;
u_char *p;
int i, j;
p = (u_char *)mask;
for (n = i = 0; i < (int)size; i++, n += 8) {
if (p[i] != 0xff)
break;
}
if (i != (int)size && p[i]) {
for (j = 7; j > 0; j--, n++) {
if ((p[i] & (1 << j)) == 0)
break;
}
}
*bits = n;
return (0);
}

View File

@@ -0,0 +1,323 @@
/*
* arp-bsd.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: arp-bsd.c,v 1.14 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
#ifdef HAVE_STREAMS_ROUTE
#include <sys/stream.h>
#include <sys/stropts.h>
#endif
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct arp_handle {
int fd;
int seq;
};
struct arpmsg {
struct rt_msghdr rtm;
u_char addrs[256];
};
arp_t *
arp_open(void)
{
arp_t *arp;
if ((arp = calloc(1, sizeof(*arp))) != NULL) {
#ifdef HAVE_STREAMS_ROUTE
if ((arp->fd = open("/dev/route", O_RDWR, 0)) < 0)
#else
if ((arp->fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
#endif
return (arp_close(arp));
}
return (arp);
}
static int
arp_msg(arp_t *arp, struct arpmsg *msg)
{
struct arpmsg smsg;
int len, i = 0;
pid_t pid;
msg->rtm.rtm_version = RTM_VERSION;
msg->rtm.rtm_seq = ++arp->seq;
memcpy(&smsg, msg, sizeof(smsg));
#ifdef HAVE_STREAMS_ROUTE
return (ioctl(arp->fd, RTSTR_SEND, &msg->rtm));
#else
if (write(arp->fd, &smsg, smsg.rtm.rtm_msglen) < 0) {
if (errno != ESRCH || msg->rtm.rtm_type != RTM_DELETE)
return (-1);
}
pid = getpid();
/* XXX - should we only read RTM_GET responses here? */
while ((len = read(arp->fd, msg, sizeof(*msg))) > 0) {
if (len < (int)sizeof(msg->rtm))
return (-1);
if (msg->rtm.rtm_pid == pid) {
if (msg->rtm.rtm_seq == arp->seq)
break;
continue;
} else if ((i++ % 2) == 0)
continue;
/* Repeat request. */
if (write(arp->fd, &smsg, smsg.rtm.rtm_msglen) < 0) {
if (errno != ESRCH || msg->rtm.rtm_type != RTM_DELETE)
return (-1);
}
}
if (len < 0)
return (-1);
return (0);
#endif
}
int
arp_add(arp_t *arp, const struct arp_entry *entry)
{
struct arpmsg msg;
struct sockaddr_in *sin;
struct sockaddr *sa;
int index, type;
if (entry->arp_pa.addr_type != ADDR_TYPE_IP ||
entry->arp_ha.addr_type != ADDR_TYPE_ETH) {
errno = EAFNOSUPPORT;
return (-1);
}
sin = (struct sockaddr_in *)msg.addrs;
sa = (struct sockaddr *)(sin + 1);
if (addr_ntos(&entry->arp_pa, (struct sockaddr *)sin) < 0)
return (-1);
memset(&msg.rtm, 0, sizeof(msg.rtm));
msg.rtm.rtm_type = RTM_GET;
msg.rtm.rtm_addrs = RTA_DST;
msg.rtm.rtm_msglen = sizeof(msg.rtm) + sizeof(*sin);
if (arp_msg(arp, &msg) < 0)
return (-1);
if (msg.rtm.rtm_msglen < (int)sizeof(msg.rtm) +
sizeof(*sin) + sizeof(*sa)) {
errno = EADDRNOTAVAIL;
return (-1);
}
if (sin->sin_addr.s_addr == entry->arp_pa.addr_ip) {
if ((msg.rtm.rtm_flags & RTF_LLINFO) == 0 ||
(msg.rtm.rtm_flags & RTF_GATEWAY) != 0) {
errno = EADDRINUSE;
return (-1);
}
}
if (sa->sa_family != AF_LINK) {
errno = EADDRNOTAVAIL;
return (-1);
} else {
index = ((struct sockaddr_dl *)sa)->sdl_index;
type = ((struct sockaddr_dl *)sa)->sdl_type;
}
if (addr_ntos(&entry->arp_pa, (struct sockaddr *)sin) < 0 ||
addr_ntos(&entry->arp_ha, sa) < 0)
return (-1);
((struct sockaddr_dl *)sa)->sdl_index = index;
((struct sockaddr_dl *)sa)->sdl_type = type;
memset(&msg.rtm, 0, sizeof(msg.rtm));
msg.rtm.rtm_type = RTM_ADD;
msg.rtm.rtm_addrs = RTA_DST | RTA_GATEWAY;
msg.rtm.rtm_inits = RTV_EXPIRE;
msg.rtm.rtm_flags = RTF_HOST | RTF_STATIC;
#ifdef HAVE_SOCKADDR_SA_LEN
msg.rtm.rtm_msglen = sizeof(msg.rtm) + sin->sin_len + sa->sa_len;
#else
msg.rtm.rtm_msglen = sizeof(msg.rtm) + sizeof(*sin) + sizeof(*sa);
#endif
return (arp_msg(arp, &msg));
}
int
arp_delete(arp_t *arp, const struct arp_entry *entry)
{
struct arpmsg msg;
struct sockaddr_in *sin;
struct sockaddr *sa;
if (entry->arp_pa.addr_type != ADDR_TYPE_IP) {
errno = EAFNOSUPPORT;
return (-1);
}
sin = (struct sockaddr_in *)msg.addrs;
sa = (struct sockaddr *)(sin + 1);
if (addr_ntos(&entry->arp_pa, (struct sockaddr *)sin) < 0)
return (-1);
memset(&msg.rtm, 0, sizeof(msg.rtm));
msg.rtm.rtm_type = RTM_GET;
msg.rtm.rtm_addrs = RTA_DST;
msg.rtm.rtm_msglen = sizeof(msg.rtm) + sizeof(*sin);
if (arp_msg(arp, &msg) < 0)
return (-1);
if (msg.rtm.rtm_msglen < (int)sizeof(msg.rtm) +
sizeof(*sin) + sizeof(*sa)) {
errno = ESRCH;
return (-1);
}
if (sin->sin_addr.s_addr == entry->arp_pa.addr_ip) {
if ((msg.rtm.rtm_flags & RTF_LLINFO) == 0 ||
(msg.rtm.rtm_flags & RTF_GATEWAY) != 0) {
errno = EADDRINUSE;
return (-1);
}
}
if (sa->sa_family != AF_LINK) {
errno = ESRCH;
return (-1);
}
msg.rtm.rtm_type = RTM_DELETE;
return (arp_msg(arp, &msg));
}
int
arp_get(arp_t *arp, struct arp_entry *entry)
{
struct arpmsg msg;
struct sockaddr_in *sin;
struct sockaddr *sa;
if (entry->arp_pa.addr_type != ADDR_TYPE_IP) {
errno = EAFNOSUPPORT;
return (-1);
}
sin = (struct sockaddr_in *)msg.addrs;
sa = (struct sockaddr *)(sin + 1);
if (addr_ntos(&entry->arp_pa, (struct sockaddr *)sin) < 0)
return (-1);
memset(&msg.rtm, 0, sizeof(msg.rtm));
msg.rtm.rtm_type = RTM_GET;
msg.rtm.rtm_addrs = RTA_DST;
msg.rtm.rtm_flags = RTF_LLINFO;
msg.rtm.rtm_msglen = sizeof(msg.rtm) + sizeof(*sin);
if (arp_msg(arp, &msg) < 0)
return (-1);
if (msg.rtm.rtm_msglen < (int)sizeof(msg.rtm) +
sizeof(*sin) + sizeof(*sa) ||
sin->sin_addr.s_addr != entry->arp_pa.addr_ip ||
sa->sa_family != AF_LINK) {
errno = ESRCH;
return (-1);
}
if (addr_ston(sa, &entry->arp_ha) < 0)
return (-1);
return (0);
}
#ifdef HAVE_SYS_SYSCTL_H
int
arp_loop(arp_t *arp, arp_handler callback, void *arg)
{
struct arp_entry entry;
struct rt_msghdr *rtm;
struct sockaddr_in *sin;
struct sockaddr *sa;
char *buf, *lim, *next;
size_t len;
int ret, mib[6] = { CTL_NET, PF_ROUTE, 0, AF_INET,
NET_RT_FLAGS, RTF_LLINFO };
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return (-1);
if (len == 0)
return (0);
if ((buf = malloc(len)) == NULL)
return (-1);
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
free(buf);
return (-1);
}
lim = buf + len;
ret = 0;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sin = (struct sockaddr_in *)(rtm + 1);
sa = (struct sockaddr *)(sin + 1);
if (addr_ston((struct sockaddr *)sin, &entry.arp_pa) < 0 ||
addr_ston(sa, &entry.arp_ha) < 0)
continue;
if ((ret = callback(&entry, arg)) != 0)
break;
}
free(buf);
return (ret);
}
#else
int
arp_loop(arp_t *arp, arp_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
#endif
arp_t *
arp_close(arp_t *arp)
{
if (arp != NULL) {
if (arp->fd >= 0)
close(arp->fd);
free(arp);
}
return (NULL);
}

View File

@@ -0,0 +1,489 @@
/*
* arp-ioctl.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: arp-ioctl.c,v 1.25 2005/02/09 22:31:00 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifdef HAVE_STREAMS_MIB2
# include <sys/sockio.h>
# include <sys/stream.h>
# include <sys/tihdr.h>
# include <sys/tiuser.h>
# include <inet/common.h>
# include <inet/mib2.h>
# include <inet/ip.h>
# undef IP_ADDR_LEN
#elif defined(HAVE_SYS_MIB_H)
# include <sys/mib.h>
#endif
#include <net/if.h>
#include <net/if_arp.h>
#ifdef HAVE_STREAMS_MIB2
# include <netinet/in.h>
# include <stropts.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
#ifdef HAVE_LINUX_PROCFS
#define PROC_ARP_FILE "/proc/net/arp"
#endif
struct arp_handle {
int fd;
#ifdef HAVE_ARPREQ_ARP_DEV
intf_t *intf;
#endif
};
arp_t *
arp_open(void)
{
arp_t *a;
if ((a = calloc(1, sizeof(*a))) != NULL) {
#ifdef HAVE_STREAMS_MIB2
if ((a->fd = open(IP_DEV_NAME, O_RDWR)) < 0)
#elif defined(HAVE_STREAMS_ROUTE)
if ((a->fd = open("/dev/route", O_WRONLY, 0)) < 0)
#else
if ((a->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
#endif
return (arp_close(a));
#ifdef HAVE_ARPREQ_ARP_DEV
if ((a->intf = intf_open()) == NULL)
return (arp_close(a));
#endif
}
return (a);
}
#ifdef HAVE_ARPREQ_ARP_DEV
static int
_arp_set_dev(const struct intf_entry *entry, void *arg)
{
struct arpreq *ar = (struct arpreq *)arg;
struct addr dst;
uint32_t mask;
if (entry->intf_type == INTF_TYPE_ETH &&
entry->intf_addr.addr_type == ADDR_TYPE_IP) {
addr_btom(entry->intf_addr.addr_bits, &mask, IP_ADDR_LEN);
addr_ston((struct sockaddr *)&ar->arp_pa, &dst);
if ((entry->intf_addr.addr_ip & mask) ==
(dst.addr_ip & mask)) {
strlcpy(ar->arp_dev, entry->intf_name,
sizeof(ar->arp_dev));
return (1);
}
}
return (0);
}
#endif
int
arp_add(arp_t *a, const struct arp_entry *entry)
{
struct arpreq ar;
memset(&ar, 0, sizeof(ar));
if (addr_ntos(&entry->arp_pa, &ar.arp_pa) < 0)
return (-1);
/* XXX - see arp(7) for details... */
#ifdef __linux__
if (addr_ntos(&entry->arp_ha, &ar.arp_ha) < 0)
return (-1);
ar.arp_ha.sa_family = ARP_HRD_ETH;
#else
/* XXX - Solaris, HP-UX, IRIX, other Mentat stacks? */
ar.arp_ha.sa_family = AF_UNSPEC;
memcpy(ar.arp_ha.sa_data, &entry->arp_ha.addr_eth, ETH_ADDR_LEN);
#endif
#ifdef HAVE_ARPREQ_ARP_DEV
if (intf_loop(a->intf, _arp_set_dev, &ar) != 1) {
errno = ESRCH;
return (-1);
}
#endif
ar.arp_flags = ATF_PERM | ATF_COM;
#ifdef hpux
/* XXX - screwy extended arpreq struct */
{
struct sockaddr_in *sin;
ar.arp_hw_addr_len = ETH_ADDR_LEN;
sin = (struct sockaddr_in *)&ar.arp_pa_mask;
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = IP_ADDR_BROADCAST;
}
#endif
if (ioctl(a->fd, SIOCSARP, &ar) < 0)
return (-1);
#ifdef HAVE_STREAMS_MIB2
/* XXX - force entry into ipNetToMediaTable. */
{
struct sockaddr_in sin;
int fd;
addr_ntos(&entry->arp_pa, (struct sockaddr *)&sin);
sin.sin_port = htons(666);
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (-1);
if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
close(fd);
return (-1);
}
write(fd, NULL, 0);
close(fd);
}
#endif
return (0);
}
int
arp_delete(arp_t *a, const struct arp_entry *entry)
{
struct arpreq ar;
memset(&ar, 0, sizeof(ar));
if (addr_ntos(&entry->arp_pa, &ar.arp_pa) < 0)
return (-1);
if (ioctl(a->fd, SIOCDARP, &ar) < 0)
return (-1);
return (0);
}
int
arp_get(arp_t *a, struct arp_entry *entry)
{
struct arpreq ar;
memset(&ar, 0, sizeof(ar));
if (addr_ntos(&entry->arp_pa, &ar.arp_pa) < 0)
return (-1);
#ifdef HAVE_ARPREQ_ARP_DEV
if (intf_loop(a->intf, _arp_set_dev, &ar) != 1) {
errno = ESRCH;
return (-1);
}
#endif
if (ioctl(a->fd, SIOCGARP, &ar) < 0)
return (-1);
if ((ar.arp_flags & ATF_COM) == 0) {
errno = ESRCH;
return (-1);
}
return (addr_ston(&ar.arp_ha, &entry->arp_ha));
}
#ifdef HAVE_LINUX_PROCFS
int
arp_loop(arp_t *a, arp_handler callback, void *arg)
{
FILE *fp;
struct arp_entry entry;
char buf[BUFSIZ], ipbuf[100], macbuf[100], maskbuf[100], devbuf[100];
int i, type, flags, ret;
if ((fp = fopen(PROC_ARP_FILE, "r")) == NULL)
return (-1);
ret = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
i = sscanf(buf, "%s 0x%x 0x%x %100s %100s %100s\n",
ipbuf, &type, &flags, macbuf, maskbuf, devbuf);
if (i < 4 || (flags & ATF_COM) == 0)
continue;
if (addr_aton(ipbuf, &entry.arp_pa) == 0 &&
addr_aton(macbuf, &entry.arp_ha) == 0) {
if ((ret = callback(&entry, arg)) != 0)
break;
}
}
if (ferror(fp)) {
fclose(fp);
return (-1);
}
fclose(fp);
return (ret);
}
#elif defined (HAVE_STREAMS_MIB2)
int
arp_loop(arp_t *r, arp_handler callback, void *arg)
{
struct arp_entry entry;
struct strbuf msg;
struct T_optmgmt_req *tor;
struct T_optmgmt_ack *toa;
struct T_error_ack *tea;
struct opthdr *opt;
mib2_ipNetToMediaEntry_t *arp, *arpend;
u_char buf[8192];
int flags, rc, atable, ret;
tor = (struct T_optmgmt_req *)buf;
toa = (struct T_optmgmt_ack *)buf;
tea = (struct T_error_ack *)buf;
tor->PRIM_type = T_OPTMGMT_REQ;
tor->OPT_offset = sizeof(*tor);
tor->OPT_length = sizeof(*opt);
tor->MGMT_flags = T_CURRENT;
opt = (struct opthdr *)(tor + 1);
opt->level = MIB2_IP;
opt->name = opt->len = 0;
msg.maxlen = sizeof(buf);
msg.len = sizeof(*tor) + sizeof(*opt);
msg.buf = buf;
if (putmsg(r->fd, &msg, NULL, 0) < 0)
return (-1);
opt = (struct opthdr *)(toa + 1);
msg.maxlen = sizeof(buf);
for (;;) {
flags = 0;
if ((rc = getmsg(r->fd, &msg, NULL, &flags)) < 0)
return (-1);
/* See if we're finished. */
if (rc == 0 &&
msg.len >= sizeof(*toa) &&
toa->PRIM_type == T_OPTMGMT_ACK &&
toa->MGMT_flags == T_SUCCESS && opt->len == 0)
break;
if (msg.len >= sizeof(*tea) && tea->PRIM_type == T_ERROR_ACK)
return (-1);
if (rc != MOREDATA || msg.len < (int)sizeof(*toa) ||
toa->PRIM_type != T_OPTMGMT_ACK ||
toa->MGMT_flags != T_SUCCESS)
return (-1);
atable = (opt->level == MIB2_IP && opt->name == MIB2_IP_22);
msg.maxlen = sizeof(buf) - (sizeof(buf) % sizeof(*arp));
msg.len = 0;
flags = 0;
do {
rc = getmsg(r->fd, NULL, &msg, &flags);
if (rc != 0 && rc != MOREDATA)
return (-1);
if (!atable)
continue;
arp = (mib2_ipNetToMediaEntry_t *)msg.buf;
arpend = (mib2_ipNetToMediaEntry_t *)
(msg.buf + msg.len);
entry.arp_pa.addr_type = ADDR_TYPE_IP;
entry.arp_pa.addr_bits = IP_ADDR_BITS;
entry.arp_ha.addr_type = ADDR_TYPE_ETH;
entry.arp_ha.addr_bits = ETH_ADDR_BITS;
for ( ; arp < arpend; arp++) {
entry.arp_pa.addr_ip =
arp->ipNetToMediaNetAddress;
memcpy(&entry.arp_ha.addr_eth,
arp->ipNetToMediaPhysAddress.o_bytes,
ETH_ADDR_LEN);
if ((ret = callback(&entry, arg)) != 0)
return (ret);
}
} while (rc == MOREDATA);
}
return (0);
}
#elif defined(HAVE_SYS_MIB_H)
#define MAX_ARPENTRIES 512 /* XXX */
int
arp_loop(arp_t *r, arp_handler callback, void *arg)
{
struct nmparms nm;
struct arp_entry entry;
mib_ipNetToMediaEnt arpentries[MAX_ARPENTRIES];
int fd, i, n, ret;
if ((fd = open_mib("/dev/ip", O_RDWR, 0 /* XXX */, 0)) < 0)
return (-1);
nm.objid = ID_ipNetToMediaTable;
nm.buffer = arpentries;
n = sizeof(arpentries);
nm.len = &n;
if (get_mib_info(fd, &nm) < 0) {
close_mib(fd);
return (-1);
}
close_mib(fd);
entry.arp_pa.addr_type = ADDR_TYPE_IP;
entry.arp_pa.addr_bits = IP_ADDR_BITS;
entry.arp_ha.addr_type = ADDR_TYPE_ETH;
entry.arp_ha.addr_bits = ETH_ADDR_BITS;
n /= sizeof(*arpentries);
ret = 0;
for (i = 0; i < n; i++) {
if (arpentries[i].Type == INTM_INVALID ||
arpentries[i].PhysAddr.o_length != ETH_ADDR_LEN)
continue;
entry.arp_pa.addr_ip = arpentries[i].NetAddr;
memcpy(&entry.arp_ha.addr_eth, arpentries[i].PhysAddr.o_bytes,
ETH_ADDR_LEN);
if ((ret = callback(&entry, arg)) != 0)
break;
}
return (ret);
}
#elif defined(HAVE_NET_RADIX_H)
/* XXX - Tru64, others? */
#include <netinet/if_ether.h>
#include <nlist.h>
static int
_kread(int fd, void *addr, void *buf, int len)
{
if (lseek(fd, (off_t)addr, SEEK_SET) == (off_t)-1L)
return (-1);
return (read(fd, buf, len) == len ? 0 : -1);
}
static int
_radix_walk(int fd, struct radix_node *rn, arp_handler callback, void *arg)
{
struct radix_node rnode;
struct rtentry rt;
struct sockaddr_in sin;
struct arptab at;
struct arp_entry entry;
int ret = 0;
again:
_kread(fd, rn, &rnode, sizeof(rnode));
if (rnode.rn_b < 0) {
if (!(rnode.rn_flags & RNF_ROOT)) {
_kread(fd, rn, &rt, sizeof(rt));
_kread(fd, rt_key(&rt), &sin, sizeof(sin));
addr_ston((struct sockaddr *)&sin, &entry.arp_pa);
_kread(fd, rt.rt_llinfo, &at, sizeof(at));
if (at.at_flags & ATF_COM) {
addr_pack(&entry.arp_ha, ADDR_TYPE_ETH,
ETH_ADDR_BITS, at.at_hwaddr, ETH_ADDR_LEN);
if ((ret = callback(&entry, arg)) != 0)
return (ret);
}
}
if ((rn = rnode.rn_dupedkey))
goto again;
} else {
rn = rnode.rn_r;
if ((ret = _radix_walk(fd, rnode.rn_l, callback, arg)) != 0)
return (ret);
if ((ret = _radix_walk(fd, rn, callback, arg)) != 0)
return (ret);
}
return (ret);
}
int
arp_loop(arp_t *r, arp_handler callback, void *arg)
{
struct ifnet *ifp, ifnet;
struct ifnet_arp_cache_head ifarp;
struct radix_node_head *head;
struct nlist nl[2];
int fd, ret = 0;
memset(nl, 0, sizeof(nl));
nl[0].n_name = "ifnet";
if (knlist(nl) < 0 || nl[0].n_type == 0 ||
(fd = open("/dev/kmem", O_RDONLY, 0)) < 0)
return (-1);
for (ifp = (struct ifnet *)nl[0].n_value;
ifp != NULL; ifp = ifnet.if_next) {
_kread(fd, ifp, &ifnet, sizeof(ifnet));
if (ifnet.if_arp_cache_head != NULL) {
_kread(fd, ifnet.if_arp_cache_head,
&ifarp, sizeof(ifarp));
/* XXX - only ever one rnh, only ever AF_INET. */
if ((ret = _radix_walk(fd, ifarp.arp_cache_head.rnh_treetop,
callback, arg)) != 0)
break;
}
}
close(fd);
return (ret);
}
#else
int
arp_loop(arp_t *a, arp_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
#endif
arp_t *
arp_close(arp_t *a)
{
if (a != NULL) {
if (a->fd >= 0)
close(a->fd);
#ifdef HAVE_ARPREQ_ARP_DEV
if (a->intf != NULL)
intf_close(a->intf);
#endif
free(a);
}
return (NULL);
}

View File

@@ -0,0 +1,58 @@
/*
* arp-none.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: arp-none.c,v 1.5 2002/02/02 04:15:57 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "dnet.h"
arp_t *
arp_open(void)
{
errno = ENOSYS;
return (NULL);
}
int
arp_add(arp_t *a, const struct arp_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
arp_delete(arp_t *a, const struct arp_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
arp_get(arp_t *a, struct arp_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
arp_loop(arp_t *a, arp_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
arp_t *
arp_close(arp_t *a)
{
return (NULL);
}

View File

@@ -0,0 +1,141 @@
/*
* arp-win32.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: arp-win32.c,v 1.12 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
struct arp_handle {
MIB_IPNETTABLE *iptable;
};
arp_t *
arp_open(void)
{
return (calloc(1, sizeof(arp_t)));
}
int
arp_add(arp_t *arp, const struct arp_entry *entry)
{
MIB_IPFORWARDROW ipfrow;
MIB_IPNETROW iprow;
if (GetBestRoute(entry->arp_pa.addr_ip,
IP_ADDR_ANY, &ipfrow) != NO_ERROR)
return (-1);
iprow.dwIndex = ipfrow.dwForwardIfIndex;
iprow.dwPhysAddrLen = ETH_ADDR_LEN;
memcpy(iprow.bPhysAddr, &entry->arp_ha.addr_eth, ETH_ADDR_LEN);
iprow.dwAddr = entry->arp_pa.addr_ip;
iprow.dwType = 4; /* XXX - static */
if (CreateIpNetEntry(&iprow) != NO_ERROR)
return (-1);
return (0);
}
int
arp_delete(arp_t *arp, const struct arp_entry *entry)
{
MIB_IPFORWARDROW ipfrow;
MIB_IPNETROW iprow;
if (GetBestRoute(entry->arp_pa.addr_ip,
IP_ADDR_ANY, &ipfrow) != NO_ERROR)
return (-1);
memset(&iprow, 0, sizeof(iprow));
iprow.dwIndex = ipfrow.dwForwardIfIndex;
iprow.dwAddr = entry->arp_pa.addr_ip;
if (DeleteIpNetEntry(&iprow) != NO_ERROR) {
errno = ENXIO;
return (-1);
}
return (0);
}
static int
_arp_get_entry(const struct arp_entry *entry, void *arg)
{
struct arp_entry *e = (struct arp_entry *)arg;
if (addr_cmp(&entry->arp_pa, &e->arp_pa) == 0) {
memcpy(&e->arp_ha, &entry->arp_ha, sizeof(e->arp_ha));
return (1);
}
return (0);
}
int
arp_get(arp_t *arp, struct arp_entry *entry)
{
if (arp_loop(arp, _arp_get_entry, entry) != 1) {
errno = ENXIO;
SetLastError(ERROR_NO_DATA);
return (-1);
}
return (0);
}
int
arp_loop(arp_t *arp, arp_handler callback, void *arg)
{
struct arp_entry entry;
ULONG len;
int i, ret;
for (len = sizeof(arp->iptable[0]); ; ) {
if (arp->iptable)
free(arp->iptable);
arp->iptable = malloc(len);
ret = GetIpNetTable(arp->iptable, &len, FALSE);
if (ret == NO_ERROR)
break;
else if (ret != ERROR_INSUFFICIENT_BUFFER)
return (-1);
}
entry.arp_pa.addr_type = ADDR_TYPE_IP;
entry.arp_pa.addr_bits = IP_ADDR_BITS;
entry.arp_ha.addr_type = ADDR_TYPE_ETH;
entry.arp_ha.addr_bits = ETH_ADDR_BITS;
for (i = 0; i < (int)arp->iptable->dwNumEntries; i++) {
if (arp->iptable->table[i].dwPhysAddrLen != ETH_ADDR_LEN)
continue;
entry.arp_pa.addr_ip = arp->iptable->table[i].dwAddr;
memcpy(&entry.arp_ha.addr_eth,
arp->iptable->table[i].bPhysAddr, ETH_ADDR_LEN);
if ((ret = (*callback)(&entry, arg)) != 0)
return (ret);
}
return (0);
}
arp_t *
arp_close(arp_t *arp)
{
if (arp != NULL) {
if (arp->iptable != NULL)
free(arp->iptable);
free(arp);
}
return (NULL);
}

456
libdnet-stripped/src/blob.c Normal file
View File

@@ -0,0 +1,456 @@
/*
* blob.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: blob.c,v 1.4 2002/08/20 05:18:49 dugsong Exp $
*/
#include "config.h"
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
static void *(*bl_malloc)(size_t) = malloc;
static void *(*bl_realloc)(void *, size_t) = realloc;
static void (*bl_free)(void *) = free;
static int bl_size = BUFSIZ;
static int fmt_D(int, int, blob_t *, va_list *);
static int fmt_H(int, int, blob_t *, va_list *);
static int fmt_b(int, int, blob_t *, va_list *);
static int fmt_c(int, int, blob_t *, va_list *);
static int fmt_d(int, int, blob_t *, va_list *);
static int fmt_h(int, int, blob_t *, va_list *);
static int fmt_s(int, int, blob_t *, va_list *);
static void print_hexl(blob_t *);
static blob_fmt_cb blob_ascii_fmt[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, fmt_D, NULL, NULL, NULL,
fmt_H, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, fmt_b, fmt_c, fmt_d, NULL, NULL, NULL,
fmt_h, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, fmt_s, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
struct blob_printer {
char *name;
void (*print)(blob_t *);
} blob_printers[] = {
{ "hexl", print_hexl },
{ NULL, NULL },
};
blob_t *
blob_new(void)
{
blob_t *b;
if ((b = bl_malloc(sizeof(*b))) != NULL) {
b->off = b->end = 0;
b->size = bl_size;
if ((b->base = bl_malloc(b->size)) == NULL) {
bl_free(b);
b = NULL;
}
}
return (b);
}
static int
blob_reserve(blob_t *b, int len)
{
void *p;
int nsize;
if (b->size < b->end + len) {
if (b->size == 0)
return (-1);
if ((nsize = b->end + len) > bl_size)
nsize = ((nsize / bl_size) + 1) * bl_size;
if ((p = bl_realloc(b->base, nsize)) == NULL)
return (-1);
b->base = p;
b->size = nsize;
}
b->end += len;
return (0);
}
int
blob_read(blob_t *b, void *buf, int len)
{
if (b->end - b->off < len)
len = b->end - b->off;
memcpy(buf, b->base + b->off, len);
b->off += len;
return (len);
}
int
blob_write(blob_t *b, const void *buf, int len)
{
if (b->off + len <= b->end ||
blob_reserve(b, b->off + len - b->end) == 0) {
memcpy(b->base + b->off, (u_char *)buf, len);
b->off += len;
return (len);
}
return (-1);
}
int
blob_insert(blob_t *b, const void *buf, int len)
{
if (blob_reserve(b, len) == 0 && b->size) {
if (b->end - b->off > 0)
memmove(b->base + b->off, b->base + b->off + len,
b->end - b->off);
memcpy(b->base + b->off, buf, len);
b->off += len;
return (len);
}
return (-1);
}
int
blob_delete(blob_t *b, void *buf, int len)
{
if (b->off + len <= b->end && b->size) {
if (buf != NULL)
memcpy(buf, b->base + b->off, len);
memmove(b->base + b->off, b->base + b->off + len,
b->end - (b->off + len));
b->end -= len;
return (len);
}
return (-1);
}
static int
blob_fmt(blob_t *b, int pack, const char *fmt, va_list *ap)
{
blob_fmt_cb fmt_cb;
char *p;
int len;
for (p = (char *)fmt; *p != '\0'; p++) {
if (*p == '%') {
p++;
if (isdigit((int)*p)) {
len = strtol(p, &p, 10);
} else if (*p == '*') {
len = va_arg(*ap, int);
p++;
} else
len = 0;
if ((fmt_cb = blob_ascii_fmt[(int)*p]) == NULL)
return (-1);
if ((*fmt_cb)(pack, len, b, ap) < 0)
return (-1);
} else {
if (pack) {
if (b->off + 1 < b->end ||
blob_reserve(b, b->off + 1 - b->end) == 0)
b->base[b->off++] = *p;
else
return (-1);
} else {
if (b->base[b->off++] != *p)
return (-1);
}
}
}
return (0);
}
int
blob_pack(blob_t *b, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
return (blob_fmt(b, 1, fmt, &ap));
}
int
blob_unpack(blob_t *b, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
return (blob_fmt(b, 0, fmt, &ap));
}
int
blob_seek(blob_t *b, int off, int whence)
{
if (whence == SEEK_CUR)
off += b->off;
else if (whence == SEEK_END)
off += b->end;
if (off < 0 || off > b->end)
return (-1);
return ((b->off = off));
}
int
blob_index(blob_t *b, const void *buf, int len)
{
int i;
for (i = b->off; i <= b->end - len; i++) {
if (memcmp(b->base + i, buf, len) == 0)
return (i);
}
return (-1);
}
int
blob_rindex(blob_t *b, const void *buf, int len)
{
int i;
for (i = b->end - len; i >= 0; i--) {
if (memcmp(b->base + i, buf, len) == 0)
return (i);
}
return (-1);
}
int
blob_print(blob_t *b, char *style, int len)
{
struct blob_printer *bp;
for (bp = blob_printers; bp->name != NULL; bp++) {
if (strcmp(bp->name, style) == 0)
bp->print(b);
}
return (0);
}
int
blob_sprint(blob_t *b, char *style, int len, char *dst, int size)
{
return (0);
}
blob_t *
blob_free(blob_t *b)
{
if (b->size)
bl_free(b->base);
bl_free(b);
return (NULL);
}
int
blob_register_alloc(size_t size, void *(bmalloc)(size_t),
void (*bfree)(void *), void *(*brealloc)(void *, size_t))
{
bl_size = size;
if (bmalloc != NULL)
bl_malloc = bmalloc;
if (bfree != NULL)
bl_free = bfree;
if (brealloc != NULL)
bl_realloc = brealloc;
return (0);
}
int
blob_register_pack(char c, blob_fmt_cb fmt_cb)
{
if (blob_ascii_fmt[(int)c] == NULL) {
blob_ascii_fmt[(int)c] = fmt_cb;
return (0);
}
return (-1);
}
static int
fmt_D(int pack, int len, blob_t *b, va_list *ap)
{
if (len) return (-1);
if (pack) {
uint32_t n = va_arg(*ap, uint32_t);
n = htonl(n);
if (blob_write(b, &n, sizeof(n)) < 0)
return (-1);
} else {
uint32_t *n = va_arg(*ap, uint32_t *);
if (blob_read(b, n, sizeof(*n)) != sizeof(*n))
return (-1);
*n = ntohl(*n);
}
return (0);
}
static int
fmt_H(int pack, int len, blob_t *b, va_list *ap)
{
if (len) return (-1);
if (pack) {
uint16_t n = va_arg(*ap, int);
n = htons(n);
if (blob_write(b, &n, sizeof(n)) < 0)
return (-1);
} else {
uint16_t *n = va_arg(*ap, uint16_t *);
if (blob_read(b, n, sizeof(*n)) != sizeof(*n))
return (-1);
*n = ntohs(*n);
}
return (0);
}
static int
fmt_b(int pack, int len, blob_t *b, va_list *ap)
{
void *p = va_arg(*ap, void *);
if (len <= 0) return (-1);
if (pack)
return (blob_write(b, p, len));
else
return (blob_read(b, p, len));
}
static int
fmt_c(int pack, int len, blob_t *b, va_list *ap)
{
if (len) return (-1);
if (pack) {
uint8_t n = va_arg(*ap, int);
return (blob_write(b, &n, sizeof(n)));
} else {
uint8_t *n = va_arg(*ap, uint8_t *);
return (blob_read(b, n, sizeof(*n)));
}
}
static int
fmt_d(int pack, int len, blob_t *b, va_list *ap)
{
if (len) return (-1);
if (pack) {
uint32_t n = va_arg(*ap, uint32_t);
return (blob_write(b, &n, sizeof(n)));
} else {
uint32_t *n = va_arg(*ap, uint32_t *);
return (blob_read(b, n, sizeof(*n)));
}
}
static int
fmt_h(int pack, int len, blob_t *b, va_list *ap)
{
if (len) return (-1);
if (pack) {
uint16_t n = va_arg(*ap, int);
return (blob_write(b, &n, sizeof(n)));
} else {
uint16_t *n = va_arg(*ap, uint16_t *);
return (blob_read(b, n, sizeof(*n)));
}
}
static int
fmt_s(int pack, int len, blob_t *b, va_list *ap)
{
char *p = va_arg(*ap, char *);
char c = '\0';
int i, end;
if (pack) {
if (len > 0) {
if ((c = p[len - 1]) != '\0')
p[len - 1] = '\0';
} else
len = strlen(p) + 1;
if (blob_write(b, p, len) > 0) {
if (c != '\0')
p[len - 1] = c;
return (len);
}
} else {
if (len <= 0) return (-1);
if ((end = b->end - b->off) < len)
end = len;
for (i = 0; i < end; i++) {
if ((p[i] = b->base[b->off + i]) == '\0') {
b->off += i + 1;
return (i);
}
}
}
return (-1);
}
static void
print_hexl(blob_t *b)
{
u_int i, j, jm, len;
u_char *p;
int c;
p = b->base + b->off;
len = b->end - b->off;
printf("\n");
for (i = 0; i < len; i += 0x10) {
printf(" %04x: ", (u_int)(i + b->off));
jm = len - i;
jm = jm > 16 ? 16 : jm;
for (j = 0; j < jm; j++) {
printf((j % 2) ? "%02x " : "%02x", (u_int)p[i + j]);
}
for (; j < 16; j++) {
printf((j % 2) ? " " : " ");
}
printf(" ");
for (j = 0; j < jm; j++) {
c = p[i + j];
printf("%c", isprint(c) ? c : '.');
}
printf("\n");
}
}

110
libdnet-stripped/src/err.c Normal file
View File

@@ -0,0 +1,110 @@
/*
* err.c
*
* Adapted from OpenBSD libc *err* *warn* code.
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* Copyright (c) 1993
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
void
err(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt != NULL) {
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, ": ");
}
va_end(ap);
#ifdef _WIN32
(void)fprintf(stderr, "error %lu\n", GetLastError());
#else
(void)fprintf(stderr, "%s\n", strerror(errno));
#endif
exit(eval);
}
void
warn(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt != NULL) {
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, ": ");
}
va_end(ap);
#ifdef _WIN32
(void)fprintf(stderr, "error %lu\n", GetLastError());
#else
(void)fprintf(stderr, "%s\n", strerror(errno));
#endif
}
void
errx(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt != NULL)
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, "\n");
va_end(ap);
exit(eval);
}
void
warnx(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (fmt != NULL)
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, "\n");
va_end(ap);
}

View File

@@ -0,0 +1,168 @@
/*
* eth-bsd.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: eth-bsd.c,v 1.10 2005/01/25 21:30:39 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_ROUTE_RT_MSGHDR)
#include <sys/sysctl.h>
#include <net/route.h>
#include <net/if_dl.h>
#endif
#include <net/bpf.h>
#include <net/if.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct eth_handle {
int fd;
char device[16];
};
eth_t *
eth_open(const char *device)
{
struct ifreq ifr;
char file[32];
eth_t *e;
int i;
if ((e = calloc(1, sizeof(*e))) != NULL) {
for (i = 0; i < 32; i++) {
snprintf(file, sizeof(file), "/dev/bpf%d", i);
e->fd = open(file, O_WRONLY);
if (e->fd != -1 || errno != EBUSY)
break;
}
if (e->fd < 0)
return (eth_close(e));
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(e->fd, BIOCSETIF, (char *)&ifr) < 0)
return (eth_close(e));
#ifdef BIOCSHDRCMPLT
i = 1;
if (ioctl(e->fd, BIOCSHDRCMPLT, &i) < 0)
return (eth_close(e));
#endif
strlcpy(e->device, device, sizeof(e->device));
}
return (e);
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
return (write(e->fd, buf, len));
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
free(e);
}
return (NULL);
}
#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_ROUTE_RT_MSGHDR)
int
eth_get(eth_t *e, eth_addr_t *ea)
{
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
struct addr ha;
u_char *p, *buf;
size_t len;
int mib[] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0 };
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return (-1);
if ((buf = malloc(len)) == NULL)
return (-1);
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
free(buf);
return (-1);
}
for (p = buf; p < buf + len; p += ifm->ifm_msglen) {
ifm = (struct if_msghdr *)p;
sdl = (struct sockaddr_dl *)(ifm + 1);
if (ifm->ifm_type != RTM_IFINFO ||
(ifm->ifm_addrs & RTA_IFP) == 0)
continue;
if (sdl->sdl_family != AF_LINK || sdl->sdl_nlen == 0 ||
memcmp(sdl->sdl_data, e->device, sdl->sdl_nlen) != 0)
continue;
if (addr_ston((struct sockaddr *)sdl, &ha) == 0)
break;
}
free(buf);
if (p >= buf + len) {
errno = ESRCH;
return (-1);
}
memcpy(ea, &ha.addr_eth, sizeof(*ea));
return (0);
}
#else
int
eth_get(eth_t *e, eth_addr_t *ea)
{
errno = ENOSYS;
return (-1);
}
#endif
#if defined(SIOCSIFLLADDR)
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
struct ifreq ifr;
struct addr ha;
ha.addr_type = ADDR_TYPE_ETH;
ha.addr_bits = ETH_ADDR_BITS;
memcpy(&ha.addr_eth, ea, ETH_ADDR_LEN);
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, e->device, sizeof(ifr.ifr_name));
addr_ntos(&ha, &ifr.ifr_addr);
return (ioctl(e->fd, SIOCSIFLLADDR, &ifr));
}
#else
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
errno = ENOSYS;
return (-1);
}
#endif

View File

@@ -0,0 +1,287 @@
/*
* eth-dlpi.c
*
* Based on Neal Nuckolls' 1992 "How to Use DLPI" paper.
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: eth-dlpi.c,v 1.19 2005/02/10 16:48:36 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#ifdef HAVE_SYS_BUFMOD_H
#include <sys/bufmod.h>
#endif
#ifdef HAVE_SYS_DLPI_H
#include <sys/dlpi.h>
#elif defined(HAVE_SYS_DLPIHDR_H)
#include <sys/dlpihdr.h>
#endif
#ifdef HAVE_SYS_DLPI_EXT_H
#include <sys/dlpi_ext.h>
#endif
#include <sys/stream.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stropts.h>
#include <unistd.h>
#include "dnet.h"
#ifndef INFTIM
#define INFTIM -1
#endif
struct eth_handle {
int fd;
int sap_len;
};
static int
dlpi_msg(int fd, union DL_primitives *dlp, int rlen, int flags,
int ack, int alen, int size)
{
struct strbuf ctl;
ctl.maxlen = 0;
ctl.len = rlen;
ctl.buf = (caddr_t)dlp;
if (putmsg(fd, &ctl, NULL, flags) < 0)
return (-1);
ctl.maxlen = size;
ctl.len = 0;
flags = 0;
if (getmsg(fd, &ctl, NULL, &flags) < 0)
return (-1);
if (dlp->dl_primitive != ack || ctl.len < alen)
return (-1);
return (0);
}
#if defined(DLIOCRAW) || defined(HAVE_SYS_DLPIHDR_H)
static int
strioctl(int fd, int cmd, int len, char *dp)
{
struct strioctl str;
str.ic_cmd = cmd;
str.ic_timout = INFTIM;
str.ic_len = len;
str.ic_dp = dp;
if (ioctl(fd, I_STR, &str) < 0)
return (-1);
return (str.ic_len);
}
#endif
#ifdef HAVE_SYS_DLPIHDR_H
/* XXX - OSF1 is nuts */
#define ND_GET ('N' << 8 + 0)
static int
eth_match_ppa(eth_t *e, const char *device)
{
char *p, dev[16], buf[256];
int len, ppa;
strlcpy(buf, "dl_ifnames", sizeof(buf));
if ((len = strioctl(e->fd, ND_GET, sizeof(buf), buf)) < 0)
return (-1);
for (p = buf; p < buf + len; p += strlen(p) + 1) {
ppa = -1;
if (sscanf(p, "%s (PPA %d)\n", dev, &ppa) != 2)
break;
if (strcmp(dev, device) == 0)
break;
}
return (ppa);
}
#endif
eth_t *
eth_open(const char *device)
{
union DL_primitives *dlp;
uint32_t buf[8192];
char *p, dev[16];
eth_t *e;
int ppa;
if ((e = calloc(1, sizeof(*e))) == NULL)
return (NULL);
#ifdef HAVE_SYS_DLPIHDR_H
if ((e->fd = open("/dev/streams/dlb", O_RDWR)) < 0)
return (eth_close(e));
if ((ppa = eth_match_ppa(e, device)) < 0) {
errno = ESRCH;
return (eth_close(e));
}
#else
e->fd = -1;
snprintf(dev, sizeof(dev), "/dev/%s", device);
if ((p = strpbrk(dev, "0123456789")) == NULL) {
errno = EINVAL;
return (eth_close(e));
}
ppa = atoi(p);
*p = '\0';
if ((e->fd = open(dev, O_RDWR)) < 0) {
snprintf(dev, sizeof(dev), "/dev/%s", device);
if ((e->fd = open(dev, O_RDWR)) < 0)
return (eth_close(e));
}
#endif
dlp = (union DL_primitives *)buf;
dlp->info_req.dl_primitive = DL_INFO_REQ;
if (dlpi_msg(e->fd, dlp, DL_INFO_REQ_SIZE, RS_HIPRI,
DL_INFO_ACK, DL_INFO_ACK_SIZE, sizeof(buf)) < 0)
return (eth_close(e));
e->sap_len = dlp->info_ack.dl_sap_length;
if (dlp->info_ack.dl_provider_style == DL_STYLE2) {
dlp->attach_req.dl_primitive = DL_ATTACH_REQ;
dlp->attach_req.dl_ppa = ppa;
if (dlpi_msg(e->fd, dlp, DL_ATTACH_REQ_SIZE, 0,
DL_OK_ACK, DL_OK_ACK_SIZE, sizeof(buf)) < 0)
return (eth_close(e));
}
memset(&dlp->bind_req, 0, DL_BIND_REQ_SIZE);
dlp->bind_req.dl_primitive = DL_BIND_REQ;
#ifdef DL_HP_RAWDLS
dlp->bind_req.dl_sap = 24; /* from HP-UX DLPI programmers guide */
dlp->bind_req.dl_service_mode = DL_HP_RAWDLS;
#else
dlp->bind_req.dl_sap = DL_ETHER;
dlp->bind_req.dl_service_mode = DL_CLDLS;
#endif
if (dlpi_msg(e->fd, dlp, DL_BIND_REQ_SIZE, 0,
DL_BIND_ACK, DL_BIND_ACK_SIZE, sizeof(buf)) < 0)
return (eth_close(e));
#ifdef DLIOCRAW
if (strioctl(e->fd, DLIOCRAW, 0, NULL) < 0)
return (eth_close(e));
#endif
return (e);
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
#if defined(DLIOCRAW)
return (write(e->fd, buf, len));
#else
union DL_primitives *dlp;
struct strbuf ctl, data;
struct eth_hdr *eth;
uint32_t ctlbuf[8192];
u_char sap[4] = { 0, 0, 0, 0 };
int dlen;
dlp = (union DL_primitives *)ctlbuf;
#ifdef DL_HP_RAWDATA_REQ
dlp->dl_primitive = DL_HP_RAWDATA_REQ;
dlen = DL_HP_RAWDATA_REQ_SIZE;
#else
dlp->unitdata_req.dl_primitive = DL_UNITDATA_REQ;
dlp->unitdata_req.dl_dest_addr_length = ETH_ADDR_LEN;
dlp->unitdata_req.dl_dest_addr_offset = DL_UNITDATA_REQ_SIZE;
dlp->unitdata_req.dl_priority.dl_min =
dlp->unitdata_req.dl_priority.dl_max = 0;
dlen = DL_UNITDATA_REQ_SIZE;
#endif
eth = (struct eth_hdr *)buf;
*(uint16_t *)sap = ntohs(eth->eth_type);
/* XXX - DLSAP setup logic from ISC DHCP */
ctl.maxlen = 0;
ctl.len = dlen + ETH_ADDR_LEN + abs(e->sap_len);
ctl.buf = (char *)ctlbuf;
if (e->sap_len >= 0) {
memcpy(ctlbuf + dlen, sap, e->sap_len);
memcpy(ctlbuf + dlen + e->sap_len,
eth->eth_dst.data, ETH_ADDR_LEN);
} else {
memcpy(ctlbuf + dlen, eth->eth_dst.data, ETH_ADDR_LEN);
memcpy(ctlbuf + dlen + ETH_ADDR_LEN, sap, abs(e->sap_len));
}
data.maxlen = 0;
data.len = len;
data.buf = (char *)buf;
if (putmsg(e->fd, &ctl, &data, 0) < 0)
return (-1);
return (len);
#endif
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
free(e);
}
return (NULL);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
union DL_primitives *dlp;
u_char buf[2048];
dlp = (union DL_primitives *)buf;
dlp->physaddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
dlp->physaddr_req.dl_addr_type = DL_CURR_PHYS_ADDR;
if (dlpi_msg(e->fd, dlp, DL_PHYS_ADDR_REQ_SIZE, 0,
DL_PHYS_ADDR_ACK, DL_PHYS_ADDR_ACK_SIZE, sizeof(buf)) < 0)
return (-1);
memcpy(ea, buf + dlp->physaddr_ack.dl_addr_offset, sizeof(*ea));
return (0);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
union DL_primitives *dlp;
u_char buf[2048];
dlp = (union DL_primitives *)buf;
dlp->set_physaddr_req.dl_primitive = DL_SET_PHYS_ADDR_REQ;
dlp->set_physaddr_req.dl_addr_length = ETH_ADDR_LEN;
dlp->set_physaddr_req.dl_addr_offset = DL_SET_PHYS_ADDR_REQ_SIZE;
memcpy(buf + DL_SET_PHYS_ADDR_REQ_SIZE, ea, sizeof(*ea));
return (dlpi_msg(e->fd, dlp, DL_SET_PHYS_ADDR_REQ_SIZE + ETH_ADDR_LEN,
0, DL_OK_ACK, DL_OK_ACK_SIZE, sizeof(buf)));
}

View File

@@ -0,0 +1,118 @@
/*
* eth-linux.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: eth-linux.c,v 1.8 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <features.h>
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h>
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#endif /* __GLIBC__ */
#include <netinet/in.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct eth_handle {
int fd;
struct ifreq ifr;
struct sockaddr_ll sll;
};
eth_t *
eth_open(const char *device)
{
eth_t *e;
int n;
if ((e = calloc(1, sizeof(*e))) != NULL) {
if ((e->fd = socket(PF_PACKET, SOCK_RAW,
htons(ETH_P_ALL))) < 0)
return (eth_close(e));
#ifdef SO_BROADCAST
n = 1;
if (setsockopt(e->fd, SOL_SOCKET, SO_BROADCAST, &n,
sizeof(n)) < 0)
return (eth_close(e));
#endif
strlcpy(e->ifr.ifr_name, device, sizeof(e->ifr.ifr_name));
if (ioctl(e->fd, SIOCGIFINDEX, &e->ifr) < 0)
return (eth_close(e));
e->sll.sll_family = AF_PACKET;
e->sll.sll_ifindex = e->ifr.ifr_ifindex;
}
return (e);
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
struct eth_hdr *eth = (struct eth_hdr *)buf;
e->sll.sll_protocol = eth->eth_type;
return (sendto(e->fd, buf, len, 0, (struct sockaddr *)&e->sll,
sizeof(e->sll)));
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
free(e);
}
return (NULL);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
struct addr ha;
if (ioctl(e->fd, SIOCGIFHWADDR, &e->ifr) < 0)
return (-1);
if (addr_ston(&e->ifr.ifr_hwaddr, &ha) < 0)
return (-1);
memcpy(ea, &ha.addr_eth, sizeof(*ea));
return (0);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
struct addr ha;
ha.addr_type = ADDR_TYPE_ETH;
ha.addr_bits = ETH_ADDR_BITS;
memcpy(&ha.addr_eth, ea, ETH_ADDR_LEN);
addr_ntos(&ha, &e->ifr.ifr_hwaddr);
return (ioctl(e->fd, SIOCSIFHWADDR, &e->ifr));
}

View File

@@ -0,0 +1,117 @@
/*
* eth-ndd.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: eth-ndd.c,v 1.7 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ndd_var.h>
#include <sys/kinfo.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct eth_handle {
char device[16];
int fd;
};
eth_t *
eth_open(const char *device)
{
struct sockaddr_ndd_8022 sa;
eth_t *e;
if ((e = calloc(1, sizeof(*e))) == NULL)
return (NULL);
if ((e->fd = socket(AF_NDD, SOCK_DGRAM, NDD_PROT_ETHER)) < 0)
return (eth_close(e));
sa.sndd_8022_family = AF_NDD;
sa.sndd_8022_len = sizeof(sa);
sa.sndd_8022_filtertype = NS_ETHERTYPE;
sa.sndd_8022_ethertype = ETH_TYPE_IP;
sa.sndd_8022_filterlen = sizeof(struct ns_8022);
strlcpy(sa.sndd_8022_nddname, device, sizeof(sa.sndd_8022_nddname));
if (bind(e->fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
return (eth_close(e));
if (connect(e->fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
return (eth_close(e));
/* XXX - SO_BROADCAST needed? */
return (e);
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
return (write(e->fd, buf, len));
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
free(e);
}
return (NULL);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
struct kinfo_ndd *nddp;
int size;
void *end;
if ((size = getkerninfo(KINFO_NDD, 0, 0, 0)) == 0) {
errno = ENOENT;
return (-1);
} else if (size < 0)
return (-1);
if ((nddp = malloc(size)) == NULL)
return (-1);
if (getkerninfo(KINFO_NDD, nddp, &size, 0) < 0) {
free(nddp);
return (-1);
}
for (end = (void *)nddp + size; (void *)nddp < end; nddp++) {
if (strcmp(nddp->ndd_alias, e->device) == 0 ||
strcmp(nddp->ndd_name, e->device) == 0) {
memcpy(ea, nddp->ndd_addr, sizeof(*ea));
}
}
free(nddp);
if ((void *)nddp >= end) {
errno = ESRCH;
return (-1);
}
return (0);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
errno = ENOSYS;
return (-1);
}

View File

@@ -0,0 +1,51 @@
/*
* eth-none.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: eth-none.c,v 1.6 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "dnet.h"
eth_t *
eth_open(const char *device)
{
errno = ENOSYS;
return (NULL);
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
errno = ENOSYS;
return (-1);
}
eth_t *
eth_close(eth_t *e)
{
return (NULL);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
errno = ENOSYS;
return (-1);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
errno = ENOSYS;
return (-1);
}

View File

@@ -0,0 +1,87 @@
/*
* eth-pfilt.c
*
* XXX - requires 'cd dev && ./MAKEDEV pfilt' if not already configured...
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: eth-pfilt.c,v 1.1 2005/02/10 17:06:36 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/pfilt.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct eth_handle {
int fd;
int sock;
char device[16];
};
eth_t *
eth_open(const char *device)
{
struct eth_handle *e;
int fd;
if ((e = calloc(1, sizeof(*e))) != NULL) {
strlcpy(e->device, device, sizeof(e->device));
if ((e->fd = pfopen(e->device, O_WRONLY)) < 0 ||
(e->sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
e = eth_close(e);
}
return (e);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
struct ifdevea ifd;
strlcpy(ifd.ifr_name, e->device, sizeof(ifd.ifr_name));
if (ioctl(e->sock, SIOCRPHYSADDR, &ifd) < 0)
return (-1);
memcpy(ea, ifd.current_pa, ETH_ADDR_LEN);
return (0);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
struct ifdevea ifd;
strlcpy(ifd.ifr_name, e->device, sizeof(ifd.ifr_name));
memcpy(ifd.current_pa, ea, ETH_ADDR_LEN);
return (ioctl(e->sock, SIOCSPHYSADDR, &ifd));
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
return (write(e->fd, buf, len));
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
if (e->sock >= 0)
close(e->sock);
free(e);
}
return (NULL);
}

View File

@@ -0,0 +1,109 @@
/*
* eth-snoop.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: eth-snoop.c,v 1.9 2005/01/30 06:01:57 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/raw.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "dnet.h"
struct eth_handle {
int fd;
struct ifreq ifr;
};
eth_t *
eth_open(const char *device)
{
struct sockaddr_raw sr;
eth_t *e;
int n;
if ((e = calloc(1, sizeof(*e))) == NULL)
return (NULL);
if ((e->fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP)) < 0)
return (eth_close(e));
memset(&sr, 0, sizeof(sr));
sr.sr_family = AF_RAW;
strlcpy(sr.sr_ifname, device, sizeof(sr.sr_ifname));
if (bind(e->fd, (struct sockaddr *)&sr, sizeof(sr)) < 0)
return (eth_close(e));
n = 60000;
if (setsockopt(e->fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) < 0)
return (eth_close(e));
strlcpy(e->ifr.ifr_name, device, sizeof(e->ifr.ifr_name));
return (e);
}
int
eth_get(eth_t *e, eth_addr_t *ea)
{
struct addr ha;
if (ioctl(e->fd, SIOCGIFADDR, &e->ifr) < 0)
return (-1);
if (addr_ston(&e->ifr.ifr_addr, &ha) < 0)
return (-1);
if (ha.addr_type != ADDR_TYPE_ETH) {
errno = EINVAL;
return (-1);
}
memcpy(ea, &ha.addr_eth, sizeof(*ea));
return (0);
}
int
eth_set(eth_t *e, const eth_addr_t *ea)
{
struct addr ha;
ha.addr_type = ADDR_TYPE_ETH;
ha.addr_bits = ETH_ADDR_BITS;
memcpy(&ha.addr_eth, ea, ETH_ADDR_LEN);
if (addr_ntos(&ha, &e->ifr.ifr_addr) < 0)
return (-1);
return (ioctl(e->fd, SIOCSIFADDR, &e->ifr));
}
ssize_t
eth_send(eth_t *e, const void *buf, size_t len)
{
return (write(e->fd, buf, len));
}
eth_t *
eth_close(eth_t *e)
{
if (e != NULL) {
if (e->fd >= 0)
close(e->fd);
free(e);
}
return (NULL);
}

View File

@@ -0,0 +1,166 @@
/*
* eth-win32.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: eth-win32.c,v 1.11 2005/02/15 06:37:06 dugsong Exp $
*/
#include "config.h"
/* XXX - VC++ 6.0 bogosity */
#define sockaddr_storage sockaddr
#include <Packet32.h>
#undef sockaddr_storage
#include <Ntddndis.h>
#include <errno.h>
#include <stdlib.h>
#include "dnet.h"
struct eth_handle {
LPADAPTER lpa;
LPPACKET pkt;
};
struct adapter {
char name[64];
char *desc;
};
/* XXX */
extern const char *intf_get_desc(intf_t *intf, const char *device);
eth_t *
eth_open(const char *device)
{
eth_t *eth;
struct adapter alist[16];
WCHAR *name, wbuf[2048];
ULONG wlen;
char *desc, *namea;
int i, j, alen;
OSVERSIONINFO osvi;
intf_t *intf;
if ((intf = intf_open()) == NULL)
return (NULL);
device = intf_get_desc(intf, device);
intf_close(intf);
if (device == NULL)
return (NULL);
alen = sizeof(alist) / sizeof(alist[0]);
wlen = sizeof(wbuf) / sizeof(wbuf[0]);
PacketGetAdapterNames((char *)wbuf, &wlen);
/* Determine Windows version */
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
(osvi.dwMajorVersion >= 4)) {
for (name = wbuf, i = 0; *name != '\0' && i < alen; i++) {
wcstombs(alist[i].name, name, sizeof(alist[0].name));
while (*name++ != '\0')
;
}
for (desc = (char *)name + 2, j = 0; *desc != '\0' && j < alen;
j++) {
alist[j].desc = desc;
while (*desc++ != '\0')
;
}
} else {
for (namea = (char *)wbuf, i = 0; *namea != '\0' && i < alen;
i++) {
strlcpy(alist[i].name, namea, sizeof(alist[0].name));
while (*namea++ != '\0')
;
}
for (desc = namea + 1, j = 0; *desc != '\0' && j < alen; j++) {
alist[j].desc = desc;
while (*desc++ != '\0')
;
}
}
for (i = 0; i < j; i++) {
if (strcmp(device, alist[i].desc) == 0)
break;
}
if (i == j)
return (NULL);
if ((eth = calloc(1, sizeof(*eth))) == NULL)
return (NULL);
if ((eth->lpa = PacketOpenAdapter(alist[i].name)) == NULL ||
eth->lpa->hFile == INVALID_HANDLE_VALUE)
return (eth_close(eth));
PacketSetBuff(eth->lpa, 512000);
if ((eth->pkt = PacketAllocatePacket()) == NULL)
return (eth_close(eth));
return (eth);
}
ssize_t
eth_send(eth_t *eth, const void *buf, size_t len)
{
PacketInitPacket(eth->pkt, (void *)buf, len);
PacketSendPacket(eth->lpa, eth->pkt, TRUE);
return (len);
}
eth_t *
eth_close(eth_t *eth)
{
if (eth != NULL) {
if (eth->pkt != NULL)
PacketFreePacket(eth->pkt);
if (eth->lpa != NULL)
PacketCloseAdapter(eth->lpa);
free(eth);
}
return (NULL);
}
int
eth_get(eth_t *eth, eth_addr_t *ea)
{
PACKET_OID_DATA *data;
u_char buf[512];
data = (PACKET_OID_DATA *)buf;
data->Oid = OID_802_3_CURRENT_ADDRESS;
data->Length = ETH_ADDR_LEN;
if (PacketRequest(eth->lpa, FALSE, data) == TRUE) {
memcpy(ea, data->Data, ETH_ADDR_LEN);
return (0);
}
return (-1);
}
int
eth_set(eth_t *eth, const eth_addr_t *ea)
{
PACKET_OID_DATA *data;
u_char buf[512];
data = (PACKET_OID_DATA *)buf;
data->Oid = OID_802_3_CURRENT_ADDRESS;
memcpy(data->Data, ea, ETH_ADDR_LEN);
data->Length = ETH_ADDR_LEN;
if (PacketRequest(eth->lpa, TRUE, data) == TRUE)
return (0);
return (-1);
}

View File

@@ -0,0 +1,227 @@
/*
* fw-ipchains.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: fw-ipchains.c,v 1.8 2004/05/05 21:25:20 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#undef __USE_BSD
#include <netinet/ip_icmp.h>
#include <linux/if.h>
#ifdef HAVE_LINUX_IP_FW_H
#include <linux/ip_fw.h>
#elif defined(HAVE_LINUX_IP_FWCHAINS_H)
#include <linux/ip_fwchains.h>
#elif defined(HAVE_LINUX_NETFILTER_IPV4_IPCHAINS_CORE_H)
#include <linux/netfilter_ipv4/ipchains_core.h>
#endif
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
#define PROC_IPCHAINS_FILE "/proc/net/ip_fwchains"
struct fw_handle {
int fd;
};
static void
fr_to_fwc(const struct fw_rule *fr, struct ip_fwchange *fwc)
{
memset(fwc, 0, sizeof(*fwc));
strlcpy(fwc->fwc_rule.ipfw.fw_vianame, fr->fw_device, IFNAMSIZ);
if (fr->fw_op == FW_OP_ALLOW)
strlcpy(fwc->fwc_rule.label, IP_FW_LABEL_ACCEPT,
sizeof(fwc->fwc_rule.label));
else
strlcpy(fwc->fwc_rule.label, IP_FW_LABEL_BLOCK,
sizeof(fwc->fwc_rule.label));
if (fr->fw_dir == FW_DIR_IN)
strlcpy(fwc->fwc_label, IP_FW_LABEL_INPUT,
sizeof(fwc->fwc_label));
else
strlcpy(fwc->fwc_label, IP_FW_LABEL_OUTPUT,
sizeof(fwc->fwc_label));
fwc->fwc_rule.ipfw.fw_proto = fr->fw_proto;
fwc->fwc_rule.ipfw.fw_src.s_addr = fr->fw_src.addr_ip;
fwc->fwc_rule.ipfw.fw_dst.s_addr = fr->fw_dst.addr_ip;
addr_btom(fr->fw_src.addr_bits, &fwc->fwc_rule.ipfw.fw_smsk.s_addr,
IP_ADDR_LEN);
addr_btom(fr->fw_dst.addr_bits, &fwc->fwc_rule.ipfw.fw_dmsk.s_addr,
IP_ADDR_LEN);
/* XXX - ICMP? */
fwc->fwc_rule.ipfw.fw_spts[0] = fr->fw_sport[0];
fwc->fwc_rule.ipfw.fw_spts[1] = fr->fw_sport[1];
fwc->fwc_rule.ipfw.fw_dpts[0] = fr->fw_dport[0];
fwc->fwc_rule.ipfw.fw_dpts[1] = fr->fw_dport[1];
}
static void
fwc_to_fr(const struct ip_fwchange *fwc, struct fw_rule *fr)
{
memset(fr, 0, sizeof(*fr));
strlcpy(fr->fw_device, fwc->fwc_rule.ipfw.fw_vianame,
sizeof(fr->fw_device));
if (strcmp(fwc->fwc_rule.label, IP_FW_LABEL_ACCEPT) == 0)
fr->fw_op = FW_OP_ALLOW;
else
fr->fw_op = FW_OP_BLOCK;
if (strcmp(fwc->fwc_label, IP_FW_LABEL_INPUT) == 0)
fr->fw_dir = FW_DIR_IN;
else
fr->fw_dir = FW_DIR_OUT;
fr->fw_proto = fwc->fwc_rule.ipfw.fw_proto;
fr->fw_src.addr_type = fr->fw_dst.addr_type = ADDR_TYPE_IP;
fr->fw_src.addr_ip = fwc->fwc_rule.ipfw.fw_src.s_addr;
fr->fw_dst.addr_ip = fwc->fwc_rule.ipfw.fw_dst.s_addr;
addr_mtob(&fwc->fwc_rule.ipfw.fw_smsk.s_addr, IP_ADDR_LEN,
&fr->fw_src.addr_bits);
addr_mtob(&fwc->fwc_rule.ipfw.fw_dmsk.s_addr, IP_ADDR_LEN,
&fr->fw_dst.addr_bits);
/* XXX - ICMP? */
fr->fw_sport[0] = fwc->fwc_rule.ipfw.fw_spts[0];
fr->fw_sport[1] = fwc->fwc_rule.ipfw.fw_spts[1];
fr->fw_dport[0] = fwc->fwc_rule.ipfw.fw_dpts[0];
fr->fw_dport[1] = fwc->fwc_rule.ipfw.fw_dpts[1];
}
fw_t *
fw_open(void)
{
fw_t *fw;
if ((fw = calloc(1, sizeof(*fw))) != NULL) {
if ((fw->fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
return (fw_close(fw));
}
return (fw);
}
int
fw_add(fw_t *fw, const struct fw_rule *rule)
{
struct ip_fwchange fwc;
fr_to_fwc(rule, &fwc);
return (setsockopt(fw->fd, IPPROTO_IP, IP_FW_APPEND,
&fwc, sizeof(fwc)));
}
int
fw_delete(fw_t *fw, const struct fw_rule *rule)
{
struct ip_fwchange fwc;
fr_to_fwc(rule, &fwc);
return (setsockopt(fw->fd, IPPROTO_IP, IP_FW_DELETE,
&fwc, sizeof(fwc)));
}
int
fw_loop(fw_t *fw, fw_handler callback, void *arg)
{
FILE *fp;
struct ip_fwchange fwc;
struct fw_rule fr;
char buf[BUFSIZ];
u_int phi, plo, bhi, blo, tand, txor;
int ret;
if ((fp = fopen(PROC_IPCHAINS_FILE, "r")) == NULL)
return (-1);
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (sscanf(buf,
"%8s %X/%X->%X/%X %s %hX %hX %hu %u %u %u %u "
"%hu-%hu %hu-%hu A%X X%X %hX %u %hu %s\n",
fwc.fwc_label,
&fwc.fwc_rule.ipfw.fw_src.s_addr,
&fwc.fwc_rule.ipfw.fw_smsk.s_addr,
&fwc.fwc_rule.ipfw.fw_dst.s_addr,
&fwc.fwc_rule.ipfw.fw_dmsk.s_addr,
fwc.fwc_rule.ipfw.fw_vianame,
&fwc.fwc_rule.ipfw.fw_flg,
&fwc.fwc_rule.ipfw.fw_invflg,
&fwc.fwc_rule.ipfw.fw_proto,
&phi, &plo, &bhi, &blo,
&fwc.fwc_rule.ipfw.fw_spts[0],
&fwc.fwc_rule.ipfw.fw_spts[1],
&fwc.fwc_rule.ipfw.fw_dpts[0],
&fwc.fwc_rule.ipfw.fw_dpts[1],
&tand, &txor,
&fwc.fwc_rule.ipfw.fw_redirpt,
&fwc.fwc_rule.ipfw.fw_mark,
&fwc.fwc_rule.ipfw.fw_outputsize,
fwc.fwc_rule.label) != 23)
break;
if (strcmp(fwc.fwc_rule.label, IP_FW_LABEL_ACCEPT) != 0 &&
strcmp(fwc.fwc_rule.label, IP_FW_LABEL_BLOCK) != 0 &&
strcmp(fwc.fwc_rule.label, IP_FW_LABEL_REJECT) != 0)
continue;
if (strcmp(fwc.fwc_label, IP_FW_LABEL_INPUT) != 0 &&
strcmp(fwc.fwc_label, IP_FW_LABEL_OUTPUT) != 0)
continue;
if (strcmp(fwc.fwc_rule.label, "-") == 0)
(fwc.fwc_rule.label)[0] = '\0';
if (strcmp(fwc.fwc_rule.ipfw.fw_vianame, "-") == 0)
(fwc.fwc_rule.ipfw.fw_vianame)[0] = '\0';
fwc.fwc_rule.ipfw.fw_src.s_addr =
htonl(fwc.fwc_rule.ipfw.fw_src.s_addr);
fwc.fwc_rule.ipfw.fw_dst.s_addr =
htonl(fwc.fwc_rule.ipfw.fw_dst.s_addr);
fwc.fwc_rule.ipfw.fw_smsk.s_addr =
htonl(fwc.fwc_rule.ipfw.fw_smsk.s_addr);
fwc.fwc_rule.ipfw.fw_dmsk.s_addr =
htonl(fwc.fwc_rule.ipfw.fw_dmsk.s_addr);
fwc_to_fr(&fwc, &fr);
if ((ret = callback(&fr, arg)) != 0) {
fclose(fp);
return (ret);
}
}
fclose(fp);
return (0);
}
fw_t *
fw_close(fw_t *fw)
{
if (fw != NULL) {
if (fw->fd >= 0)
close(fw->fd);
free(fw);
}
return (NULL);
}

View File

@@ -0,0 +1,281 @@
/*
* fw-ipf.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: fw-ipf.c,v 1.18 2005/02/16 21:42:53 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#define _NETINET_IP6_H_ /* XXX */
#include <netinet/in.h>
#define ip_t ipf_ip_t
#ifdef HAVE_NETINET_IP_FIL_COMPAT_H
# include <netinet/ip_fil_compat.h>
#else
# include <netinet/ip_compat.h>
#endif
#include <netinet/ip_fil.h>
#undef ip_t
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define KMEM_NAME "/dev/kmem"
#include "dnet.h"
#if !defined(fi_saddr) && !defined(fi_daddr)
# define fi_saddr fi_src.s_addr
# define fi_daddr fi_dst.s_addr
#endif
struct fw_handle {
int fd;
int kfd;
};
static void
rule_to_ipf(const struct fw_rule *rule, struct frentry *fr)
{
memset(fr, 0, sizeof(*fr));
if (*rule->fw_device != '\0') {
strlcpy(fr->fr_ifname, rule->fw_device, IFNAMSIZ);
strlcpy(fr->fr_oifname, rule->fw_device, IFNAMSIZ);
}
if (rule->fw_op == FW_OP_ALLOW)
fr->fr_flags |= FR_PASS;
else
fr->fr_flags |= FR_BLOCK;
if (rule->fw_dir == FW_DIR_IN)
fr->fr_flags |= FR_INQUE;
else
fr->fr_flags |= FR_OUTQUE;
fr->fr_ip.fi_p = rule->fw_proto;
fr->fr_ip.fi_saddr = rule->fw_src.addr_ip;
fr->fr_ip.fi_daddr = rule->fw_dst.addr_ip;
addr_btom(rule->fw_src.addr_bits, &fr->fr_mip.fi_saddr, IP_ADDR_LEN);
addr_btom(rule->fw_dst.addr_bits, &fr->fr_mip.fi_daddr, IP_ADDR_LEN);
switch (rule->fw_proto) {
case IPPROTO_ICMP:
fr->fr_icmpm = rule->fw_sport[1] << 8 |
(rule->fw_dport[1] & 0xff);
fr->fr_icmp = rule->fw_sport[0] << 8 |
(rule->fw_dport[0] & 0xff);
break;
case IPPROTO_TCP:
case IPPROTO_UDP:
fr->fr_sport = rule->fw_sport[0];
if (rule->fw_sport[0] != rule->fw_sport[1]) {
fr->fr_scmp = FR_INRANGE;
fr->fr_stop = rule->fw_sport[1];
} else
fr->fr_scmp = FR_EQUAL;
fr->fr_dport = rule->fw_dport[0];
if (rule->fw_dport[0] != rule->fw_dport[1]) {
fr->fr_dcmp = FR_INRANGE;
fr->fr_dtop = rule->fw_dport[1];
} else
fr->fr_dcmp = FR_EQUAL;
break;
}
}
static void
ipf_ports_to_rule(uint8_t cmp, uint16_t port, uint16_t top, uint16_t *range)
{
switch (cmp) {
case FR_EQUAL:
range[0] = range[1] = port;
break;
case FR_NEQUAL:
range[0] = port - 1;
range[1] = port + 1;
break;
case FR_LESST:
range[0] = 0;
range[1] = port - 1;
break;
case FR_GREATERT:
range[0] = port + 1;
range[1] = TCP_PORT_MAX;
break;
case FR_LESSTE:
range[0] = 0;
range[1] = port;
break;
case FR_GREATERTE:
range[0] = port;
range[1] = TCP_PORT_MAX;
break;
case FR_OUTRANGE:
range[0] = port;
range[1] = top;
break;
case FR_INRANGE:
range[0] = port;
range[1] = top;
break;
default:
range[0] = 0;
range[1] = TCP_PORT_MAX;
}
}
static void
ipf_to_rule(const struct frentry *fr, struct fw_rule *rule)
{
memset(rule, 0, sizeof(*rule));
strlcpy(rule->fw_device, fr->fr_ifname, sizeof(rule->fw_device));
rule->fw_op = (fr->fr_flags & FR_PASS) ? FW_OP_ALLOW : FW_OP_BLOCK;
rule->fw_dir = (fr->fr_flags & FR_INQUE) ? FW_DIR_IN : FW_DIR_OUT;
rule->fw_proto = fr->fr_ip.fi_p;
rule->fw_src.addr_type = rule->fw_dst.addr_type = ADDR_TYPE_IP;
rule->fw_src.addr_ip = fr->fr_ip.fi_saddr;
rule->fw_dst.addr_ip = fr->fr_ip.fi_daddr;
addr_mtob(&fr->fr_mip.fi_saddr, IP_ADDR_LEN,
&rule->fw_src.addr_bits);
addr_mtob(&fr->fr_mip.fi_daddr, IP_ADDR_LEN,
&rule->fw_dst.addr_bits);
switch (rule->fw_proto) {
case IPPROTO_ICMP:
rule->fw_sport[0] = ntohs(fr->fr_icmp & fr->fr_icmpm) >> 8;
rule->fw_sport[1] = ntohs(fr->fr_icmpm) >> 8;
rule->fw_dport[0] = ntohs(fr->fr_icmp & fr->fr_icmpm) & 0xff;
rule->fw_dport[1] = ntohs(fr->fr_icmpm) & 0xff;
break;
case IPPROTO_TCP:
case IPPROTO_UDP:
ipf_ports_to_rule(fr->fr_scmp, fr->fr_sport,
fr->fr_stop, rule->fw_sport);
ipf_ports_to_rule(fr->fr_dcmp, fr->fr_dport,
fr->fr_dtop, rule->fw_dport);
break;
}
}
fw_t *
fw_open(void)
{
fw_t *fw;
if ((fw = calloc(1, sizeof(*fw))) != NULL) {
fw->fd = fw->kfd = -1;
if ((fw->fd = open(IPL_NAME, O_RDWR, 0)) < 0)
return (fw_close(fw));
if ((fw->kfd = open(KMEM_NAME, O_RDONLY)) < 0)
return (fw_close(fw));
}
return (fw);
}
int
fw_add(fw_t *fw, const struct fw_rule *rule)
{
struct frentry fr;
assert(fw != NULL && rule != NULL);
rule_to_ipf(rule, &fr);
return (ioctl(fw->fd, SIOCADDFR, &fr));
}
int
fw_delete(fw_t *fw, const struct fw_rule *rule)
{
struct frentry fr;
assert(fw != NULL && rule != NULL);
rule_to_ipf(rule, &fr);
return (ioctl(fw->fd, SIOCDELFR, &fr));
}
static int
fw_kcopy(fw_t *fw, u_char *buf, off_t pos, size_t n)
{
int i;
if (lseek(fw->kfd, pos, 0) < 0)
return (-1);
while ((i = read(fw->kfd, buf, n)) < n) {
if (i <= 0)
return (-1);
buf += i;
n -= i;
}
return (0);
}
int
fw_loop(fw_t *fw, fw_handler callback, void *arg)
{
struct friostat fio;
struct friostat *fiop = &fio;
struct frentry *frp, fr;
struct fw_rule rule;
int ret;
memset(&fio, 0, sizeof(fio));
#ifdef __OpenBSD__
if (ioctl(fw->fd, SIOCGETFS, fiop) < 0)
#else
if (ioctl(fw->fd, SIOCGETFS, &fiop) < 0) /* XXX - darren! */
#endif
return (-1);
for (frp = fio.f_fout[(int)fio.f_active]; frp != NULL;
frp = fr.fr_next) {
if (fw_kcopy(fw, (u_char *)&fr, (u_long)frp, sizeof(fr)) < 0)
return (-1);
ipf_to_rule(&fr, &rule);
if ((ret = callback(&rule, arg)) != 0)
return (ret);
}
for (frp = fio.f_fin[(int)fio.f_active]; frp != NULL;
frp = fr.fr_next) {
if (fw_kcopy(fw, (u_char *)&fr, (u_long)frp, sizeof(fr)) < 0)
return (-1);
ipf_to_rule(&fr, &rule);
if ((ret = callback(&rule, arg)) != 0)
return (ret);
}
return (0);
}
fw_t *
fw_close(fw_t *fw)
{
if (fw != NULL) {
if (fw->fd >= 0)
close(fw->fd);
if (fw->kfd >= 0)
close(fw->kfd);
free(fw);
}
return (NULL);
}

View File

@@ -0,0 +1,324 @@
/*
* fw-ipfw.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: fw-ipfw.c,v 1.16 2004/01/14 04:52:10 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip_fw.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct fw_handle {
int fd;
};
static void
fr_to_ipfw_device(const char *device, char *name, short *unit)
{
char *p;
p = strpbrk(device, "0123456789");
*unit = atoi(p);
strlcpy(name, device, p - device + 1);
}
static void
fr_to_ipfw(const struct fw_rule *fr, struct ip_fw *ipfw)
{
int i;
memset(ipfw, 0, sizeof(*ipfw));
if (fr->fw_dir == FW_DIR_IN) {
if (*fr->fw_device != '\0') {
fr_to_ipfw_device(fr->fw_device,
ipfw->fw_in_if.fu_via_if.name,
&ipfw->fw_in_if.fu_via_if.unit);
ipfw->fw_flg |= IP_FW_F_IIFNAME;
}
ipfw->fw_flg |= IP_FW_F_IN;
} else {
if (*fr->fw_device != '\0') {
fr_to_ipfw_device(fr->fw_device,
ipfw->fw_out_if.fu_via_if.name,
&ipfw->fw_out_if.fu_via_if.unit);
ipfw->fw_flg |= IP_FW_F_OIFNAME;
}
ipfw->fw_flg |= IP_FW_F_OUT;
}
if (fr->fw_op == FW_OP_ALLOW)
ipfw->fw_flg |= IP_FW_F_ACCEPT;
else
ipfw->fw_flg |= IP_FW_F_DENY;
ipfw->fw_prot = fr->fw_proto;
ipfw->fw_src.s_addr = fr->fw_src.addr_ip;
ipfw->fw_dst.s_addr = fr->fw_dst.addr_ip;
addr_btom(fr->fw_src.addr_bits, &ipfw->fw_smsk.s_addr, IP_ADDR_LEN);
addr_btom(fr->fw_dst.addr_bits, &ipfw->fw_dmsk.s_addr, IP_ADDR_LEN);
switch (fr->fw_proto) {
case IP_PROTO_TCP:
case IP_PROTO_UDP:
i = 0;
if (fr->fw_sport[0] != fr->fw_sport[1]) {
ipfw->fw_flg |= IP_FW_F_SRNG;
ipfw->fw_uar.fw_pts[i++] = fr->fw_sport[0];
ipfw->fw_uar.fw_pts[i++] = fr->fw_sport[1];
IP_FW_SETNSRCP(ipfw, 2);
} else if (fr->fw_sport[0] > 0) {
ipfw->fw_uar.fw_pts[i++] = fr->fw_sport[0];
IP_FW_SETNSRCP(ipfw, 1);
}
if (fr->fw_dport[0] != fr->fw_dport[1]) {
ipfw->fw_flg |= IP_FW_F_DRNG;
ipfw->fw_uar.fw_pts[i++] = fr->fw_dport[0];
ipfw->fw_uar.fw_pts[i++] = fr->fw_dport[1];
IP_FW_SETNDSTP(ipfw, 2);
} else if (fr->fw_dport[0] > 0) {
ipfw->fw_uar.fw_pts[i++] = fr->fw_dport[0];
IP_FW_SETNDSTP(ipfw, 1);
}
break;
case IP_PROTO_ICMP:
if (fr->fw_sport[1]) {
ipfw->fw_uar.fw_icmptypes[fr->fw_sport[0] / 32] |=
1 << (fr->fw_sport[0] % 32);
ipfw->fw_flg |= IP_FW_F_ICMPBIT;
}
/* XXX - no support for ICMP code. */
break;
}
}
static void
ipfw_to_fr(const struct ip_fw *ipfw, struct fw_rule *fr)
{
int i;
memset(fr, 0, sizeof(*fr));
if ((ipfw->fw_flg & IP_FW_F_IN) && *ipfw->fw_in_if.fu_via_if.name)
snprintf(fr->fw_device, sizeof(fr->fw_device), "%s%d",
ipfw->fw_in_if.fu_via_if.name,
ipfw->fw_in_if.fu_via_if.unit);
else if ((ipfw->fw_flg & IP_FW_F_OUT) &&
*ipfw->fw_out_if.fu_via_if.name)
snprintf(fr->fw_device, sizeof(fr->fw_device), "%s%d",
ipfw->fw_out_if.fu_via_if.name,
ipfw->fw_out_if.fu_via_if.unit);
fr->fw_op = (ipfw->fw_flg & IP_FW_F_ACCEPT) ?
FW_OP_ALLOW : FW_OP_BLOCK;
fr->fw_dir = (ipfw->fw_flg & IP_FW_F_IN) ? FW_DIR_IN : FW_DIR_OUT;
fr->fw_proto = ipfw->fw_prot;
fr->fw_src.addr_type = fr->fw_dst.addr_type = ADDR_TYPE_IP;
fr->fw_src.addr_ip = ipfw->fw_src.s_addr;
fr->fw_dst.addr_ip = ipfw->fw_dst.s_addr;
addr_mtob(&ipfw->fw_smsk.s_addr, IP_ADDR_LEN, &fr->fw_src.addr_bits);
addr_mtob(&ipfw->fw_dmsk.s_addr, IP_ADDR_LEN, &fr->fw_dst.addr_bits);
switch (fr->fw_proto) {
case IP_PROTO_TCP:
case IP_PROTO_UDP:
if ((ipfw->fw_flg & IP_FW_F_SRNG) &&
IP_FW_GETNSRCP(ipfw) == 2) {
fr->fw_sport[0] = ipfw->fw_uar.fw_pts[0];
fr->fw_sport[1] = ipfw->fw_uar.fw_pts[1];
} else if (IP_FW_GETNSRCP(ipfw) == 1) {
fr->fw_sport[0] = fr->fw_sport[1] =
ipfw->fw_uar.fw_pts[0];
} else if (IP_FW_GETNSRCP(ipfw) == 0) {
fr->fw_sport[0] = 0;
fr->fw_sport[1] = TCP_PORT_MAX;
}
if ((ipfw->fw_flg & IP_FW_F_DRNG) &&
IP_FW_GETNDSTP(ipfw) == 2) {
i = IP_FW_GETNSRCP(ipfw);
fr->fw_dport[0] = ipfw->fw_uar.fw_pts[i];
fr->fw_dport[1] = ipfw->fw_uar.fw_pts[i + 1];
} else if (IP_FW_GETNDSTP(ipfw) == 1) {
i = IP_FW_GETNSRCP(ipfw);
fr->fw_dport[0] = fr->fw_dport[1] =
ipfw->fw_uar.fw_pts[i];
} else if (IP_FW_GETNDSTP(ipfw) == 0) {
fr->fw_dport[0] = 0;
fr->fw_dport[1] = TCP_PORT_MAX;
}
break;
case IP_PROTO_ICMP:
if (ipfw->fw_flg & IP_FW_F_ICMPBIT) {
for (i = 0; i < IP_FW_ICMPTYPES_DIM * 32; i++) {
if (ipfw->fw_uar.fw_icmptypes[i / 32] &
(1U << (i % 32))) {
fr->fw_sport[0] = i;
fr->fw_sport[1] = 0xff;
break;
}
}
}
/* XXX - no support for ICMP code. */
break;
}
}
fw_t *
fw_open(void)
{
fw_t *fw;
if ((fw = calloc(1, sizeof(*fw))) != NULL) {
if ((fw->fd = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0)
return (fw_close(fw));
}
return (fw);
}
int
fw_add(fw_t *fw, const struct fw_rule *rule)
{
struct ip_fw ipfw;
assert(fw != NULL && rule != NULL);
fr_to_ipfw(rule, &ipfw);
return (setsockopt(fw->fd, IPPROTO_IP, IP_FW_ADD,
&ipfw, sizeof(ipfw)));
}
static int
fw_cmp(const struct fw_rule *a, const struct fw_rule *b)
{
if (strcmp(a->fw_device, b->fw_device) != 0 || a->fw_op != b->fw_op ||
a->fw_dir != b->fw_dir || a->fw_proto != b->fw_proto ||
addr_cmp(&a->fw_src, &b->fw_src) != 0 ||
addr_cmp(&a->fw_dst, &b->fw_dst) != 0 ||
memcmp(a->fw_sport, b->fw_sport, sizeof(a->fw_sport)) != 0 ||
memcmp(a->fw_dport, b->fw_dport, sizeof(a->fw_dport)) != 0)
return (-1);
return (0);
}
int
fw_delete(fw_t *fw, const struct fw_rule *rule)
{
struct ip_fw *ipfw;
struct fw_rule fr;
int nbytes, nalloc, ret;
u_char *buf, *new;
assert(rule != NULL);
nbytes = nalloc = sizeof(*ipfw);
if ((buf = malloc(nbytes)) == NULL)
return (-1);
while (nbytes >= nalloc) {
nalloc = nalloc * 2 + 200;
nbytes = nalloc;
if ((new = realloc(buf, nbytes)) == NULL) {
if (buf)
free(buf);
return (-1);
}
buf = new;
if (getsockopt(fw->fd, IPPROTO_IP, IP_FW_GET,
buf, &nbytes) < 0) {
free(buf);
return (-1);
}
}
ret = -1;
/* XXX - 65535 is the fixed ipfw default rule. */
for (ipfw = (struct ip_fw *)buf; ipfw->fw_number < 65535; ipfw++) {
ipfw_to_fr(ipfw, &fr);
if (fw_cmp(&fr, rule) == 0) {
if (setsockopt(fw->fd, IPPROTO_IP, IP_FW_DEL,
ipfw, sizeof(*ipfw)) < 0)
ret = -2;
else
ret = 0;
break;
}
}
free(buf);
if (ret < 0) {
if (ret == -1)
errno = ESRCH;
return (-1);
}
return (0);
}
int
fw_loop(fw_t *fw, fw_handler callback, void *arg)
{
struct ip_fw *ipfw;
struct fw_rule fr;
int i, cnt, nbytes, nalloc, ret;
u_char *buf, *new;
nbytes = nalloc = sizeof(*ipfw);
if ((buf = malloc(nbytes)) == NULL)
return (-1);
while (nbytes >= nalloc) {
nalloc = nalloc * 2 + 200;
nbytes = nalloc;
if ((new = realloc(buf, nbytes)) == NULL) {
if (buf)
free(buf);
return (-1);
}
buf = new;
if (getsockopt(fw->fd, IPPROTO_IP, IP_FW_GET,
buf, &nbytes) < 0) {
free(buf);
return (-1);
}
}
cnt = nbytes / sizeof(*ipfw);
ipfw = (struct ip_fw *)buf;
ret = 0;
for (i = 0; i < cnt; i++) {
ipfw_to_fr(&ipfw[i], &fr);
if ((ret = callback(&fr, arg)) != 0)
break;
}
free(buf);
return (ret);
}
fw_t *
fw_close(fw_t *fw)
{
if (fw != NULL) {
if (fw->fd >= 0)
close(fw->fd);
free(fw);
}
return (NULL);
}

View File

@@ -0,0 +1,49 @@
/*
* fw-none.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: fw-none.c,v 1.4 2002/01/20 21:23:28 dugsong Exp $
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "dnet.h"
fw_t *
fw_open(void)
{
errno = ENOSYS;
return (NULL);
}
int
fw_add(fw_t *f, const struct fw_rule *rule)
{
errno = ENOSYS;
return (-1);
}
int
fw_delete(fw_t *f, const struct fw_rule *rule)
{
errno = ENOSYS;
return (-1);
}
int
fw_loop(fw_t *f, fw_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
fw_t *
fw_close(fw_t *f)
{
return (NULL);
}

View File

@@ -0,0 +1,315 @@
/*
* fw-pf.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: fw-pf.c,v 1.20 2005/02/14 20:43:32 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/pfvar.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
/*
* XXX - cope with moving pf API
*/
#if defined(DIOCRCLRTABLES)
/* XXX - can't isolate the following change:
* $OpenBSD: pfvar.h,v 1.112 2002/12/17 12:30:13 mcbride Exp $
* so i'll take 1.119's DIOCRCLRTABLES - 12 days of pf unsupported.
*/
# define HAVE_PF_CHANGE_GET_TICKET 1
/* OpenBSD 3.3+ - 3.6 */
/* $OpenBSD: pfvar.h,v 1.197 2004/06/14 20:53:27 cedric Exp $ */
/* $OpenBSD: pfvar.h,v 1.130 2003/01/09 10:40:45 cedric Exp $ */
/* $OpenBSD: pfvar.h,v 1.127 2003/01/05 22:14:23 dhartmei Exp $ */
# define PFRA_ADDR(ra) (ra)->addr.v.a.addr.v4.s_addr
# define PFRA_MASK(ra) (ra)->addr.v.a.mask.v4.s_addr
# define pfioc_changerule pfioc_rule
# define oldrule rule
# define newrule rule
#elif defined(DIOCBEGINADDRS)
/* $OpenBSD: pfvar.h,v 1.102 2002/11/23 05:16:58 mcbride Exp $ */
# define PFRA_ADDR(ra) (ra)->addr.addr.v4.s_addr
# define PFRA_MASK(ra) (ra)->addr.mask.v4.s_addr
#elif defined(PFRULE_FRAGMENT)
/* OpenBSD 3.2 */
/* $OpenBSD: pfvar.h,v 1.68 2002/04/24 18:10:25 dhartmei Exp $ */
# define PFRA_ADDR(ra) (ra)->addr.addr.v4.s_addr
# define PFRA_MASK(ra) (ra)->mask.v4.s_addr
#elif defined (PF_AEQ)
/* OpenBSD 3.1 */
/* $OpenBSD: pfvar.h,v 1.51 2001/09/15 03:54:40 frantzen Exp $ */
# define PFRA_ADDR(ra) (ra)->addr.v4.s_addr
# define PFRA_MASK(ra) (ra)->mask.v4.s_addr
#else
/* OpenBSD 3.0 */
# define PFRA_ADDR(ra) (ra)->addr
# define PFRA_ADDR(ra) (ra)->mask
#endif
struct fw_handle {
int fd;
};
static void
fr_to_pr(const struct fw_rule *fr, struct pf_rule *pr)
{
memset(pr, 0, sizeof(*pr));
strlcpy(pr->ifname, fr->fw_device, sizeof(pr->ifname));
pr->action = (fr->fw_op == FW_OP_ALLOW) ? PF_PASS : PF_DROP;
pr->direction = (fr->fw_dir == FW_DIR_IN) ? PF_IN : PF_OUT;
pr->proto = fr->fw_proto;
pr->af = AF_INET;
PFRA_ADDR(&pr->src) = fr->fw_src.addr_ip;
addr_btom(fr->fw_src.addr_bits, &(PFRA_MASK(&pr->src)), IP_ADDR_LEN);
PFRA_ADDR(&pr->dst) = fr->fw_dst.addr_ip;
addr_btom(fr->fw_dst.addr_bits, &(PFRA_MASK(&pr->dst)), IP_ADDR_LEN);
switch (fr->fw_proto) {
case IP_PROTO_ICMP:
if (fr->fw_sport[1])
pr->type = (u_char)(fr->fw_sport[0] &
fr->fw_sport[1]) + 1;
if (fr->fw_dport[1])
pr->code = (u_char)(fr->fw_dport[0] &
fr->fw_dport[1]) + 1;
break;
case IP_PROTO_TCP:
case IP_PROTO_UDP:
pr->src.port[0] = htons(fr->fw_sport[0]);
pr->src.port[1] = htons(fr->fw_sport[1]);
if (pr->src.port[0] == pr->src.port[1]) {
pr->src.port_op = PF_OP_EQ;
} else
pr->src.port_op = PF_OP_IRG;
pr->dst.port[0] = htons(fr->fw_dport[0]);
pr->dst.port[1] = htons(fr->fw_dport[1]);
if (pr->dst.port[0] == pr->dst.port[1]) {
pr->dst.port_op = PF_OP_EQ;
} else
pr->dst.port_op = PF_OP_IRG;
break;
}
}
static int
pr_to_fr(const struct pf_rule *pr, struct fw_rule *fr)
{
memset(fr, 0, sizeof(*fr));
strlcpy(fr->fw_device, pr->ifname, sizeof(fr->fw_device));
if (pr->action == PF_DROP)
fr->fw_op = FW_OP_BLOCK;
else if (pr->action == PF_PASS)
fr->fw_op = FW_OP_ALLOW;
else
return (-1);
fr->fw_dir = pr->direction == PF_IN ? FW_DIR_IN : FW_DIR_OUT;
fr->fw_proto = pr->proto;
if (pr->af != AF_INET)
return (-1);
fr->fw_src.addr_type = ADDR_TYPE_IP;
addr_mtob(&(PFRA_MASK(&pr->src)), IP_ADDR_LEN, &fr->fw_src.addr_bits);
fr->fw_src.addr_ip = PFRA_ADDR(&pr->src);
fr->fw_dst.addr_type = ADDR_TYPE_IP;
addr_mtob(&(PFRA_MASK(&pr->dst)), IP_ADDR_LEN, &fr->fw_dst.addr_bits);
fr->fw_dst.addr_ip = PFRA_ADDR(&pr->dst);
switch (fr->fw_proto) {
case IP_PROTO_ICMP:
if (pr->type) {
fr->fw_sport[0] = pr->type - 1;
fr->fw_sport[1] = 0xff;
}
if (pr->code) {
fr->fw_dport[0] = pr->code - 1;
fr->fw_dport[1] = 0xff;
}
break;
case IP_PROTO_TCP:
case IP_PROTO_UDP:
fr->fw_sport[0] = ntohs(pr->src.port[0]);
fr->fw_sport[1] = ntohs(pr->src.port[1]);
if (pr->src.port_op == PF_OP_EQ)
fr->fw_sport[1] = fr->fw_sport[0];
fr->fw_dport[0] = ntohs(pr->dst.port[0]);
fr->fw_dport[1] = ntohs(pr->dst.port[1]);
if (pr->dst.port_op == PF_OP_EQ)
fr->fw_dport[1] = fr->fw_dport[0];
}
return (0);
}
#ifdef HAVE_PF_CHANGE_GET_TICKET
static int
_fw_cmp(const struct fw_rule *a, const struct fw_rule *b)
{
if (strcmp(a->fw_device, b->fw_device) != 0 || a->fw_op != b->fw_op ||
a->fw_dir != b->fw_dir || a->fw_proto != b->fw_proto ||
addr_cmp(&a->fw_src, &b->fw_src) != 0 ||
addr_cmp(&a->fw_dst, &b->fw_dst) != 0 ||
memcmp(a->fw_sport, b->fw_sport, sizeof(a->fw_sport)) != 0 ||
memcmp(a->fw_dport, b->fw_dport, sizeof(a->fw_dport)) != 0)
return (-1);
return (0);
}
#endif
fw_t *
fw_open(void)
{
fw_t *fw;
if ((fw = calloc(1, sizeof(*fw))) != NULL) {
if ((fw->fd = open("/dev/pf", O_RDWR)) < 0)
return (fw_close(fw));
}
return (fw);
}
int
fw_add(fw_t *fw, const struct fw_rule *rule)
{
struct pfioc_changerule pcr;
assert(fw != NULL && rule != NULL);
memset(&pcr, 0, sizeof(pcr));
#ifdef HAVE_PF_CHANGE_GET_TICKET
{
struct fw_rule fr;
if (ioctl(fw->fd, DIOCGETRULES, &pcr) < 0)
return (-1);
while ((int)--pcr.nr >= 0) {
if (ioctl(fw->fd, DIOCGETRULE, &pcr) == 0 &&
pr_to_fr(&pcr.rule, &fr) == 0) {
if (_fw_cmp(rule, &fr) == 0) {
errno = EEXIST;
return (-1);
}
}
}
}
#endif
#ifdef DIOCBEGINADDRS
{
struct pfioc_pooladdr ppa;
if (ioctl(fw->fd, DIOCBEGINADDRS, &ppa) < 0)
return (-1);
pcr.pool_ticket = ppa.ticket;
}
#endif
pcr.action = PF_CHANGE_ADD_TAIL;
fr_to_pr(rule, &pcr.newrule);
return (ioctl(fw->fd, DIOCCHANGERULE, &pcr));
}
int
fw_delete(fw_t *fw, const struct fw_rule *rule)
{
struct pfioc_changerule pcr;
assert(fw != NULL && rule != NULL);
memset(&pcr, 0, sizeof(pcr));
#ifdef HAVE_PF_CHANGE_GET_TICKET
{
struct fw_rule fr;
int found = 0;
if (ioctl(fw->fd, DIOCGETRULES, &pcr) < 0)
return (-1);
while ((int)--pcr.nr >= 0) {
if (ioctl(fw->fd, DIOCGETRULE, &pcr) == 0 &&
pr_to_fr(&pcr.rule, &fr) == 0) {
if (_fw_cmp(rule, &fr) == 0) {
found = 1;
break;
}
}
}
if (!found) {
errno = ENOENT;
return (-1);
}
}
#endif
#ifdef DIOCBEGINADDRS
{
struct pfioc_pooladdr ppa;
if (ioctl(fw->fd, DIOCBEGINADDRS, &ppa) < 0)
return (-1);
pcr.pool_ticket = ppa.ticket;
}
#endif
pcr.action = PF_CHANGE_REMOVE;
fr_to_pr(rule, &pcr.oldrule);
return (ioctl(fw->fd, DIOCCHANGERULE, &pcr));
}
int
fw_loop(fw_t *fw, fw_handler callback, void *arg)
{
struct pfioc_rule pr;
struct fw_rule fr;
uint32_t n, max;
int ret = 0;
memset(&pr, 0, sizeof(pr));
if (ioctl(fw->fd, DIOCGETRULES, &pr) < 0)
return (-1);
for (n = 0, max = pr.nr; n < max; n++) {
pr.nr = n;
if ((ret = ioctl(fw->fd, DIOCGETRULE, &pr)) < 0)
break;
if (pr_to_fr(&pr.rule, &fr) < 0)
continue;
if ((ret = callback(&fr, arg)) != 0)
break;
}
return (ret);
}
fw_t *
fw_close(fw_t *fw)
{
if (fw != NULL) {
if (fw->fd >= 0)
close(fw->fd);
free(fw);
}
return (NULL);
}

View File

@@ -0,0 +1,444 @@
/*
* fw-pktfilter.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
* Copyright (c) 2001 Jean-Baptiste Marchand, Herv<72> Schauer Consultants.
*
* $Id: fw-pktfilter.c,v 1.4 2005/02/15 06:37:06 dugsong Exp $
*/
#include "config.h"
#include <iphlpapi.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
#define PKTFILTER_PIPE "\\\\.\\pipe\\PktFltPipe"
#define MAX_RULE_LENGTH 256
#define FILTER_FAILURE 0 /* filter had a syntax error */
#define FILTER_SUCCESS 1 /* filter was correctly added */
#define FILTER_MESSAGE 2 /* informative message returned to the client */
char *icmp_types[] = {
"echorep", /* 0: echo reply */
"", /* 1: unused */
"", /* 2: unused */
"unreach", /* 3: destination unreachable */
"squench", /* 4: source quench */
"redir", /* 5: redirect */
"", /* 6: unused */
"", /* 7: unused */
"echo", /* 8: echo request */
"router_adv", /* 9: router advertisement */
"router_sol", /* 10: router solicitation */
"timex", /* 11: time exceeded */
"paramprob", /* 12: parameter problem */
"timest", /* 13: timestamp request */
"timestrep", /* 14: timestamp reply */
"inforeq", /* 15: information request */
"inforep", /* 16: information reply */
"maskreq", /* 17: address mask request */
"maskrep", /* 18: address mask reply */
NULL
};
struct fw_handle {
IP_ADAPTER_INFO *ifinfo;
/* XXX - rules cache for delete lookup? */
};
static int
parse_addr(char *p, struct addr *a)
{
if (strcmp(p, "any") == 0)
return (addr_aton("0.0.0.0/0", a));
return (addr_aton(p, a));
}
static int
parse_portspec(char *str, uint16_t *ports)
{
char *p = strsep(&str, " ");
if (p[0] == '=') {
ports[0] = ports[1] = atoi(strsep(&str, " "));
} else if (p[0] == '<') {
ports[1] = atoi(strsep(&str, " "));
if (p[1] != '=') ports[1]--;
} else if (p[0] == '>') {
ports[1] = TCP_PORT_MAX;
ports[0] = atoi(strsep(&str, " "));
if (p[1] != '=') ports[0]++;
} else if (p[0] != '\0') {
if (strcmp(strsep(&str, " "), "><") != 0)
return (-1);
ports[0] = atoi(p) + 1;
ports[1] = atoi(strsep(&str, " ")) - 1;
}
return (0);
}
static int
parse_icmpspec(char *str, uint16_t *type, uint16_t *code)
{
char *p, *e;
int i;
p = strsep(&str, " ");
for (i = 0; icmp_types[i] && strcmp(p, icmp_types[i]); i++)
;
if (icmp_types[i] == NULL) {
i = strtol(p, &e, 10);
if (*e != '\0')
return (-1);
}
type[0] = i;
type[1] = 0xff;
p = strsep(&str, " ");
if (p != NULL && strcmp(p, "code")) {
p = strsep(&str, " ");
i = strtol(p, &e, 10);
if (*e != '\0')
return (-1);
code[0] = i;
code[1] = 0xff;
}
return (0);
}
/*
<op> <dir> on <device> all
<op> <dir> on <device> proto <proto> all
<op> <dir> on <device> proto <proto> from <src> [ports] to <dst> [ports]
<op> <dir> on <device> proto icmp all [icmp-type <type> [code <code>]]
<op> <dir> on <device> proto icmp from <src> to <dst> [icmp-type <type> [code <code>]]
*/
static int
parse_rule(char *str, struct fw_rule *rule)
{
char *p, *q;
memset(rule, 0, sizeof(*rule));
/* action */
p = strsep(&str, " ");
if (strcmp(p, "block") == 0)
rule->fw_op = FW_OP_BLOCK;
else if (strcmp(p, "pass") == 0)
rule->fw_op = FW_OP_ALLOW;
else return (-1);
/* direction */
p = strsep(&str, " ");
if (strcmp(p, "in") == 0)
rule->fw_dir = FW_DIR_IN;
else if (strcmp(p, "out") == 0)
rule->fw_dir = FW_DIR_OUT;
else return (-1);
/* device */
if (strcmp(strsep(&str, " "), "on") != 0)
return (-1);
p = strsep(&str, " ");
/* XXX - handle bug in pktfltsrv.c */
if ((q = strstr(p, "proto")) != NULL)
*q = '\0';
if (strcmp(p, "all") != 0)
strlcpy(rule->fw_device, p, sizeof(rule->fw_device));
/* proto */
p = strsep(&str, " ");
/* XXX - handle bug in pktfltsrv.c */
if (strcmp(p, "proto") == 0)
p = strsep(&str, " ");
/* XXX - handle default rules */
if (strcmp(p, "all") == 0)
return (0);
if (strcmp(p, "icmp") == 0)
rule->fw_proto = IP_PROTO_ICMP;
else if (strcmp(p, "tcp") == 0)
rule->fw_proto = IP_PROTO_TCP;
else if (strcmp(p, "udp") == 0)
rule->fw_proto = IP_PROTO_UDP;
else rule->fw_proto = atoi(p);
/* source */
p = strsep(&str, " ");
if (strcmp(p, "all") == 0)
return (0);
if (strcmp(p, "from") != 0)
goto icmp_type_code;
p = strsep(&str, " ");
if (parse_addr(p, &rule->fw_src) < 0)
return (-1);
/* source port */
p = strsep(&str, " ");
if (strcmp(p, "port") == 0) {
if ((p = strstr(str, " to ")) == NULL)
return (-1);
*p++ = '\0';
if (parse_portspec(str, rule->fw_sport) < 0)
return (-1);
str = p + 3;
} else if (strcmp(p, "to") != 0)
return (-1);
/* destination */
p = strsep(&str, " ");
if (parse_addr(p, &rule->fw_dst) < 0)
return (-1);
/* destination port */
p = strsep(&str, " ");
if (strcmp(p, "port") == 0)
return (parse_portspec(str, rule->fw_dport));
icmp_type_code:
/* icmp-type, code */
if (strcmp(p, "icmp-type") == 0) {
if (parse_icmpspec(str, rule->fw_sport, rule->fw_dport) < 0)
return (-1);
}
return (0);
}
static int
format_rule(const struct fw_rule *rule, char *buf, int len)
{
char tmp[128];
strlcpy(buf, (rule->fw_op == FW_OP_ALLOW) ? "pass " : "block ", len);
strlcat(buf, (rule->fw_dir == FW_DIR_IN) ? "in " : "out ", len);
snprintf(tmp, sizeof(tmp), "on %s ", rule->fw_device);
strlcat(buf, tmp, len);
if (rule->fw_proto != 0) {
snprintf(tmp, sizeof(tmp), "proto %d ", rule->fw_proto);
strlcat(buf, tmp, len);
}
/* source */
if (rule->fw_src.addr_type != ADDR_TYPE_NONE) {
snprintf(tmp, sizeof(tmp), "from %s ",
addr_ntoa(&rule->fw_src));
strlcat(buf, tmp, len);
} else
strlcat(buf, "from any ", len);
/* sport */
if (rule->fw_proto == IP_PROTO_TCP || rule->fw_proto == IP_PROTO_UDP) {
if (rule->fw_sport[0] == rule->fw_sport[1])
snprintf(tmp, sizeof(tmp), "port = %d ",
rule->fw_sport[0]);
else
snprintf(tmp, sizeof(tmp), "port %d >< %d ",
rule->fw_sport[0] - 1, rule->fw_sport[1] + 1);
strlcat(buf, tmp, len);
}
/* destination */
if (rule->fw_dst.addr_type != ADDR_TYPE_NONE) {
snprintf(tmp, sizeof(tmp), "to %s ",
addr_ntoa(&rule->fw_dst));
strlcat(buf, tmp, len);
} else
strlcat(buf, "to any ", len);
/* dport */
if (rule->fw_proto == IP_PROTO_TCP || rule->fw_proto == IP_PROTO_UDP) {
if (rule->fw_dport[0] == rule->fw_dport[1])
snprintf(tmp, sizeof(tmp), "port = %d",
rule->fw_dport[0]);
else
snprintf(tmp, sizeof(tmp), "port %d >< %d",
rule->fw_dport[0] - 1, rule->fw_dport[1] + 1);
strlcat(buf, tmp, len);
} else if (rule->fw_proto == IP_PROTO_ICMP) {
if (rule->fw_sport[1]) {
snprintf(tmp, sizeof(tmp), "icmp-type %d",
rule->fw_sport[0]);
strlcat(buf, tmp, len);
if (rule->fw_dport[1]) {
snprintf(tmp, sizeof(tmp), " code %d",
rule->fw_dport[0]);
strlcat(buf, tmp, len);
}
}
}
return (strlen(buf));
}
static char *
call_pipe(const char *msg, int len)
{
HANDLE *pipe;
DWORD i;
char *p, *reply, status;
if (!WaitNamedPipe(PKTFILTER_PIPE, NMPWAIT_USE_DEFAULT_WAIT) ||
(pipe = CreateFile(PKTFILTER_PIPE, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) {
return (NULL);
}
reply = NULL;
if (WriteFile(pipe, msg, len, &i, NULL)) {
if (ReadFile(pipe, &status, sizeof(status), &i, NULL)) {
if (status == FILTER_FAILURE) {
ReadFile(pipe, &status, sizeof(status),
&i, NULL);
} else if (status == FILTER_MESSAGE) {
/* get msg length */
if (ReadFile(pipe, &len, 4, &i, NULL)) {
/* get msg */
p = reply = calloc(1, len + 1);
if (!ReadFile(pipe, reply, len,
&i, NULL)) {
free(reply);
reply = NULL;
}
}
} else if (status == FILTER_SUCCESS)
reply = strdup(""); /* XXX */
}
}
CloseHandle(pipe);
return (reply);
}
fw_t *
fw_open(void)
{
fw_t *f;
IP_ADAPTER_INFO *ifinfo;
ULONG size;
if ((f = calloc(1, sizeof(*f))) == NULL)
return (NULL);
size = sizeof(*f->ifinfo);
f->ifinfo = malloc(size);
if (GetAdaptersInfo(f->ifinfo, &size) != ERROR_SUCCESS) {
free(f->ifinfo);
f->ifinfo = malloc(size);
GetAdaptersInfo(f->ifinfo, &size);
}
/* XXX - normalize interface names. */
for (ifinfo = f->ifinfo; ifinfo != NULL; ifinfo = ifinfo->Next) {
char *fmt;
if (ifinfo->Type == MIB_IF_TYPE_ETHERNET)
fmt = "eth";
else if (ifinfo->Type == MIB_IF_TYPE_PPP)
fmt = "ppp";
else if (ifinfo->Type == MIB_IF_TYPE_SLIP)
fmt = "sl";
else if (ifinfo->Type == MIB_IF_TYPE_LOOPBACK)
fmt = "lo";
else if (ifinfo->Type == MIB_IF_TYPE_TOKENRING)
fmt = "tr";
else if (ifinfo->Type == MIB_IF_TYPE_FDDI)
fmt = "fd";
else
fmt = "if";
sprintf(ifinfo->AdapterName, "%s%lu", fmt, ifinfo->ComboIndex);
}
return (f);
}
int
fw_add(fw_t *f, const struct fw_rule *rule)
{
char *p, buf[MAX_RULE_LENGTH];
int len;
len = format_rule(rule, buf, sizeof(buf));
if ((p = call_pipe(buf, len)) == NULL)
return (-1);
free(p);
return (0);
}
int
fw_delete(fw_t *f, const struct fw_rule *rule)
{
struct fw_rule tmp;
char *p, *line, *msg, cmd[128], buf[MAX_RULE_LENGTH];
int n, ruleno, len;
format_rule(rule, buf, sizeof(buf));
len = snprintf(cmd, sizeof(cmd), "List on %s", rule->fw_device);
if ((msg = call_pipe(cmd, len)) == NULL)
return (-1);
for (ruleno = 0, p = msg; (line = strsep(&p, "\r\n")) != NULL; ) {
if (strncmp(line, "rule ", 5) == 0) {
line += 5;
n = atoi(strsep(&line, ":"));
if (parse_rule(line + 1, &tmp) == 0 &&
memcmp(&tmp, rule, sizeof(tmp)) == 0) {
ruleno = n;
break;
}
}
}
free(msg);
if (ruleno == 0) {
errno = ENXIO;
SetLastError(ERROR_NO_DATA);
return (-1);
}
len = snprintf(cmd, sizeof(cmd), "delete %d on %s",
ruleno, rule->fw_device);
if ((p = call_pipe(cmd, len)) == NULL)
return (-1);
free(p);
return (0);
}
int
fw_loop(fw_t *f, fw_handler callback, void *arg)
{
struct fw_rule rule;
IP_ADAPTER_INFO *ifinfo;
char *p, *line, *msg, buf[MAX_RULE_LENGTH];
int len, ret;
for (ret = 0, ifinfo = f->ifinfo; ret == 0 && ifinfo != NULL;
ifinfo = ifinfo->Next) {
len = snprintf(buf, sizeof(buf), "list on %s",
ifinfo->AdapterName);
if ((msg = call_pipe(buf, len)) == NULL)
return (-1);
/* parse msg */
for (p = msg; (line = strsep(&p, "\r\n")) != NULL; ) {
if (*line == '\0' || *line == '#' || isspace(*line))
continue;
if (parse_rule(line, &rule) == 0) {
if ((ret = callback(&rule, arg)) != 0)
break;
}
}
free(msg);
}
return (ret);
}
fw_t *
fw_close(fw_t *f)
{
if (f != NULL) {
free(f->ifinfo);
free(f);
}
return (NULL);
}

View File

@@ -0,0 +1,375 @@
/*
* intf-win32.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: intf-win32.c,v 1.24 2005/02/15 06:37:06 dugsong Exp $
*/
#include "config.h"
#include <iphlpapi.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
struct ifcombo {
DWORD *idx;
int cnt;
int max;
};
#define MIB_IF_TYPE_MAX 32 /* XXX - ipifcons.h */
struct intf_handle {
struct ifcombo ifcombo[MIB_IF_TYPE_MAX];
MIB_IFTABLE *iftable;
MIB_IPADDRTABLE *iptable;
};
static char *
_ifcombo_name(int type)
{
char *name = "net"; /* XXX */
if (type == MIB_IF_TYPE_ETHERNET) {
name = "eth";
} else if (type == MIB_IF_TYPE_TOKENRING) {
name = "tr";
} else if (type == MIB_IF_TYPE_FDDI) {
name = "fddi";
} else if (type == MIB_IF_TYPE_PPP) {
name = "ppp";
} else if (type == MIB_IF_TYPE_LOOPBACK) {
name = "lo";
} else if (type == MIB_IF_TYPE_SLIP) {
name = "sl";
}
return (name);
}
static int
_ifcombo_type(const char *device)
{
int type = INTF_TYPE_OTHER;
if (strncmp(device, "eth", 3) == 0) {
type = INTF_TYPE_ETH;
} else if (strncmp(device, "tr", 2) == 0) {
type = INTF_TYPE_TOKENRING;
} else if (strncmp(device, "fd", 2) == 0) {
type = INTF_TYPE_FDDI;
} else if (strncmp(device, "ppp", 3) == 0) {
type = INTF_TYPE_PPP;
} else if (strncmp(device, "lo", 2) == 0) {
type = INTF_TYPE_LOOPBACK;
} else if (strncmp(device, "sl", 2) == 0) {
type = INTF_TYPE_SLIP;
}
return (type);
}
static void
_ifcombo_add(struct ifcombo *ifc, DWORD idx)
{
if (ifc->cnt == ifc->max) {
if (ifc->idx) {
ifc->max *= 2;
ifc->idx = realloc(ifc->idx,
sizeof(ifc->idx[0] * ifc->max));
} else {
ifc->max = 8;
ifc->idx = malloc(sizeof(ifc->idx[0] * ifc->max));
}
}
ifc->idx[ifc->cnt++] = idx;
}
static void
_ifrow_to_entry(intf_t *intf, MIB_IFROW *ifrow, struct intf_entry *entry)
{
struct addr *ap, *lap;
int i;
memset(entry, 0, sizeof(*entry));
for (i = 0; i < intf->ifcombo[ifrow->dwType].cnt; i++) {
if (intf->ifcombo[ifrow->dwType].idx[i] == ifrow->dwIndex)
break;
}
/* XXX - dwType matches MIB-II ifType. */
snprintf(entry->intf_name, sizeof(entry->intf_name), "%s%lu",
_ifcombo_name(ifrow->dwType), i);
entry->intf_type = (uint16_t)ifrow->dwType;
/* Get interface flags. */
entry->intf_flags = 0;
if (ifrow->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP)
entry->intf_flags |= INTF_FLAG_UP;
if (ifrow->dwType == MIB_IF_TYPE_LOOPBACK)
entry->intf_flags |= INTF_FLAG_LOOPBACK;
else
entry->intf_flags |= INTF_FLAG_MULTICAST;
/* Get interface MTU. */
entry->intf_mtu = ifrow->dwMtu;
/* Get hardware address. */
if (ifrow->dwPhysAddrLen == ETH_ADDR_LEN) {
entry->intf_link_addr.addr_type = ADDR_TYPE_ETH;
entry->intf_link_addr.addr_bits = ETH_ADDR_BITS;
memcpy(&entry->intf_link_addr.addr_eth, ifrow->bPhysAddr,
ETH_ADDR_LEN);
}
/* Get addresses. */
ap = entry->intf_alias_addrs;
lap = ap + ((entry->intf_len - sizeof(*entry)) /
sizeof(entry->intf_alias_addrs[0]));
for (i = 0; i < (int)intf->iptable->dwNumEntries; i++) {
if (intf->iptable->table[i].dwIndex == ifrow->dwIndex &&
intf->iptable->table[i].dwAddr != 0) {
if (entry->intf_addr.addr_type == ADDR_TYPE_NONE) {
/* Set primary address if unset. */
entry->intf_addr.addr_type = ADDR_TYPE_IP;
entry->intf_addr.addr_ip =
intf->iptable->table[i].dwAddr;
addr_mtob(&intf->iptable->table[i].dwMask,
IP_ADDR_LEN, &entry->intf_addr.addr_bits);
} else if (ap < lap) {
/* Set aliases. */
ap->addr_type = ADDR_TYPE_IP;
ap->addr_ip = intf->iptable->table[i].dwAddr;
addr_mtob(&intf->iptable->table[i].dwMask,
IP_ADDR_LEN, &ap->addr_bits);
ap++, entry->intf_alias_num++;
}
}
}
entry->intf_len = (u_char *)ap - (u_char *)entry;
}
static int
_refresh_tables(intf_t *intf)
{
MIB_IFROW *ifrow;
ULONG len;
u_int i, ret;
/* Get interface table. */
for (len = sizeof(intf->iftable[0]); ; ) {
if (intf->iftable)
free(intf->iftable);
intf->iftable = malloc(len);
ret = GetIfTable(intf->iftable, &len, FALSE);
if (ret == NO_ERROR)
break;
else if (ret != ERROR_INSUFFICIENT_BUFFER)
return (-1);
}
/* Get IP address table. */
for (len = sizeof(intf->iptable[0]); ; ) {
if (intf->iptable)
free(intf->iptable);
intf->iptable = malloc(len);
ret = GetIpAddrTable(intf->iptable, &len, FALSE);
if (ret == NO_ERROR)
break;
else if (ret != ERROR_INSUFFICIENT_BUFFER)
return (-1);
}
/*
* Map "unfriendly" win32 interface indices to ours.
* XXX - like IP_ADAPTER_INFO ComboIndex
*/
for (i = 0; i < intf->iftable->dwNumEntries; i++) {
ifrow = &intf->iftable->table[i];
if (ifrow->dwType < MIB_IF_TYPE_MAX) {
_ifcombo_add(&intf->ifcombo[ifrow->dwType],
ifrow->dwIndex);
} else
return (-1);
}
return (0);
}
static int
_find_ifindex(intf_t *intf, const char *device)
{
char *p = (char *)device;
int n, type = _ifcombo_type(device);
while (isalpha(*p)) p++;
n = atoi(p);
return (intf->ifcombo[type].idx[n]);
}
intf_t *
intf_open(void)
{
return (calloc(1, sizeof(intf_t)));
}
int
intf_get(intf_t *intf, struct intf_entry *entry)
{
MIB_IFROW ifrow;
if (_refresh_tables(intf) < 0)
return (-1);
ifrow.dwIndex = _find_ifindex(intf, entry->intf_name);
if (GetIfEntry(&ifrow) != NO_ERROR)
return (-1);
_ifrow_to_entry(intf, &ifrow, entry);
return (0);
}
/* XXX - gross hack required by eth-win32:eth_open() */
const char *
intf_get_desc(intf_t *intf, const char *name)
{
static char desc[MAXLEN_IFDESCR + 1];
MIB_IFROW ifrow;
if (_refresh_tables(intf) < 0)
return (NULL);
ifrow.dwIndex = _find_ifindex(intf, name);
if (GetIfEntry(&ifrow) != NO_ERROR)
return (NULL);
strlcpy(desc, ifrow.bDescr, sizeof(desc));
return (desc);
}
int
intf_get_src(intf_t *intf, struct intf_entry *entry, struct addr *src)
{
MIB_IFROW ifrow;
MIB_IPADDRROW *iprow;
int i;
if (src->addr_type != ADDR_TYPE_IP) {
errno = EINVAL;
return (-1);
}
if (_refresh_tables(intf) < 0)
return (-1);
for (i = 0; i < (int)intf->iptable->dwNumEntries; i++) {
iprow = &intf->iptable->table[i];
if (iprow->dwAddr == src->addr_ip) {
ifrow.dwIndex = iprow->dwIndex;
if (GetIfEntry(&ifrow) != NO_ERROR)
return (-1);
_ifrow_to_entry(intf, &ifrow, entry);
return (0);
}
}
errno = ENXIO;
return (-1);
}
int
intf_get_dst(intf_t *intf, struct intf_entry *entry, struct addr *dst)
{
MIB_IFROW ifrow;
if (dst->addr_type != ADDR_TYPE_IP) {
errno = EINVAL;
return (-1);
}
if (GetBestInterface(dst->addr_ip, &ifrow.dwIndex) != NO_ERROR)
return (-1);
if (GetIfEntry(&ifrow) != NO_ERROR)
return (-1);
if (_refresh_tables(intf) < 0)
return (-1);
_ifrow_to_entry(intf, &ifrow, entry);
return (0);
}
int
intf_set(intf_t *intf, const struct intf_entry *entry)
{
/*
* XXX - could set interface up/down via SetIfEntry(),
* but what about the rest of the configuration? :-(
* {Add,Delete}IPAddress for 2000/XP only
*/
#if 0
/* Set interface address. XXX - 2000/XP only? */
if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
ULONG ctx = 0, inst = 0;
UINT ip, mask;
memcpy(&ip, &entry->intf_addr.addr_ip, IP_ADDR_LEN);
addr_btom(entry->intf_addr.addr_bits, &mask, IP_ADDR_LEN);
if (AddIPAddress(ip, mask,
_find_ifindex(intf, entry->intf_name),
&ctx, &inst) != NO_ERROR) {
return (-1);
}
return (0);
}
#endif
errno = ENOSYS;
SetLastError(ERROR_NOT_SUPPORTED);
return (-1);
}
int
intf_loop(intf_t *intf, intf_handler callback, void *arg)
{
struct intf_entry *entry;
u_char ebuf[1024];
int i, ret = 0;
if (_refresh_tables(intf) < 0)
return (-1);
entry = (struct intf_entry *)ebuf;
for (i = 0; i < (int)intf->iftable->dwNumEntries; i++) {
entry->intf_len = sizeof(ebuf);
_ifrow_to_entry(intf, &intf->iftable->table[i], entry);
if ((ret = (*callback)(entry, arg)) != 0)
break;
}
return (ret);
}
intf_t *
intf_close(intf_t *intf)
{
int i;
if (intf != NULL) {
for (i = 0; i < MIB_IF_TYPE_MAX; i++) {
if (intf->ifcombo[i].idx)
free(intf->ifcombo[i].idx);
}
if (intf->iftable)
free(intf->iftable);
if (intf->iptable)
free(intf->iptable);
free(intf);
}
return (NULL);
}

714
libdnet-stripped/src/intf.c Normal file
View File

@@ -0,0 +1,714 @@
/*
* intf.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: intf.c,v 1.55 2005/02/10 16:57:35 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
/* XXX - AIX */
#ifndef IP_MULTICAST
# define IP_MULTICAST
#endif
#include <net/if.h>
#ifdef HAVE_NET_IF_VAR_H
# include <net/if_var.h>
#endif
#undef IP_MULTICAST
/* XXX - IPv6 ioctls */
#ifdef HAVE_NETINET_IN_VAR_H
# include <netinet/in.h>
# include <netinet/in_var.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
/* XXX - Tru64 */
#if defined(SIOCRIPMTU) && defined(SIOCSIPMTU)
# define SIOCGIFMTU SIOCRIPMTU
# define SIOCSIFMTU SIOCSIPMTU
#endif
/* XXX - HP-UX */
#if defined(SIOCADDIFADDR) && defined(SIOCDELIFADDR)
# define SIOCAIFADDR SIOCADDIFADDR
# define SIOCDIFADDR SIOCDELIFADDR
#endif
/* XXX - HP-UX, Solaris */
#if !defined(ifr_mtu) && defined(ifr_metric)
# define ifr_mtu ifr_metric
#endif
#ifdef HAVE_SOCKADDR_SA_LEN
# define NEXTIFR(i) ((struct ifreq *)((u_char *)&i->ifr_addr + \
(i->ifr_addr.sa_len ? i->ifr_addr.sa_len : \
sizeof(i->ifr_addr))))
#else
# define NEXTIFR(i) (i + 1)
#endif
/* XXX - superset of ifreq, for portable SIOC{A,D}IFADDR */
struct dnet_ifaliasreq {
char ifra_name[IFNAMSIZ];
struct sockaddr ifra_addr;
struct sockaddr ifra_brdaddr;
struct sockaddr ifra_mask;
int ifra_cookie; /* XXX - IRIX!@#$ */
};
struct intf_handle {
int fd;
int fd6;
struct ifconf ifc;
u_char ifcbuf[4192];
};
static int
intf_flags_to_iff(u_short flags, int iff)
{
if (flags & INTF_FLAG_UP)
iff |= IFF_UP;
else
iff &= ~IFF_UP;
if (flags & INTF_FLAG_NOARP)
iff |= IFF_NOARP;
else
iff &= ~IFF_NOARP;
return (iff);
}
static u_int
intf_iff_to_flags(int iff)
{
u_int n = 0;
if (iff & IFF_UP)
n |= INTF_FLAG_UP;
if (iff & IFF_LOOPBACK)
n |= INTF_FLAG_LOOPBACK;
if (iff & IFF_POINTOPOINT)
n |= INTF_FLAG_POINTOPOINT;
if (iff & IFF_NOARP)
n |= INTF_FLAG_NOARP;
if (iff & IFF_BROADCAST)
n |= INTF_FLAG_BROADCAST;
if (iff & IFF_MULTICAST)
n |= INTF_FLAG_MULTICAST;
return (n);
}
intf_t *
intf_open(void)
{
intf_t *intf;
if ((intf = calloc(1, sizeof(*intf))) != NULL) {
intf->fd = intf->fd6 = -1;
if ((intf->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (intf_close(intf));
#ifdef SIOCGIFNETMASK_IN6
if ((intf->fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
# ifdef EPROTONOSUPPORT
if (errno != EPROTONOSUPPORT)
# endif
return (intf_close(intf));
}
#endif
}
return (intf);
}
static int
_intf_delete_addrs(intf_t *intf, struct intf_entry *entry)
{
#if defined(SIOCDIFADDR)
struct dnet_ifaliasreq ifra;
memset(&ifra, 0, sizeof(ifra));
strlcpy(ifra.ifra_name, entry->intf_name, sizeof(ifra.ifra_name));
if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
addr_ntos(&entry->intf_addr, &ifra.ifra_addr);
ioctl(intf->fd, SIOCDIFADDR, &ifra);
}
if (entry->intf_dst_addr.addr_type == ADDR_TYPE_IP) {
addr_ntos(&entry->intf_dst_addr, &ifra.ifra_addr);
ioctl(intf->fd, SIOCDIFADDR, &ifra);
}
#elif defined(SIOCLIFREMOVEIF)
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, entry->intf_name, sizeof(ifr.ifr_name));
/* XXX - overloading Solaris lifreq with ifreq */
ioctl(intf->fd, SIOCLIFREMOVEIF, &ifr);
#endif
return (0);
}
static int
_intf_delete_aliases(intf_t *intf, struct intf_entry *entry)
{
int i;
#if defined(SIOCDIFADDR) && !defined(__linux__) /* XXX - see Linux below */
struct dnet_ifaliasreq ifra;
memset(&ifra, 0, sizeof(ifra));
strlcpy(ifra.ifra_name, entry->intf_name, sizeof(ifra.ifra_name));
for (i = 0; i < (int)entry->intf_alias_num; i++) {
addr_ntos(&entry->intf_alias_addrs[i], &ifra.ifra_addr);
ioctl(intf->fd, SIOCDIFADDR, &ifra);
}
#else
struct ifreq ifr;
for (i = 0; i < entry->intf_alias_num; i++) {
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s:%d",
entry->intf_name, i + 1);
# ifdef SIOCLIFREMOVEIF
/* XXX - overloading Solaris lifreq with ifreq */
ioctl(intf->fd, SIOCLIFREMOVEIF, &ifr);
# else
/* XXX - only need to set interface down on Linux */
ifr.ifr_flags = 0;
ioctl(intf->fd, SIOCSIFFLAGS, &ifr);
# endif
}
#endif
return (0);
}
static int
_intf_add_aliases(intf_t *intf, const struct intf_entry *entry)
{
int i;
#ifdef SIOCAIFADDR
struct dnet_ifaliasreq ifra;
struct addr bcast;
memset(&ifra, 0, sizeof(ifra));
strlcpy(ifra.ifra_name, entry->intf_name, sizeof(ifra.ifra_name));
for (i = 0; i < (int)entry->intf_alias_num; i++) {
if (entry->intf_alias_addrs[i].addr_type != ADDR_TYPE_IP)
continue;
if (addr_ntos(&entry->intf_alias_addrs[i],
&ifra.ifra_addr) < 0)
return (-1);
addr_bcast(&entry->intf_alias_addrs[i], &bcast);
addr_ntos(&bcast, &ifra.ifra_brdaddr);
addr_btos(entry->intf_alias_addrs[i].addr_bits,
&ifra.ifra_mask);
if (ioctl(intf->fd, SIOCAIFADDR, &ifra) < 0)
return (-1);
}
#else
struct ifreq ifr;
int n = 1;
for (i = 0; i < entry->intf_alias_num; i++) {
if (entry->intf_alias_addrs[i].addr_type != ADDR_TYPE_IP)
continue;
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s:%d",
entry->intf_name, n++);
# ifdef SIOCLIFADDIF
if (ioctl(intf->fd, SIOCLIFADDIF, &ifr) < 0)
return (-1);
# endif
if (addr_ntos(&entry->intf_alias_addrs[i], &ifr.ifr_addr) < 0)
return (-1);
if (ioctl(intf->fd, SIOCSIFADDR, &ifr) < 0)
return (-1);
}
strlcpy(ifr.ifr_name, entry->intf_name, sizeof(ifr.ifr_name));
#endif
return (0);
}
int
intf_set(intf_t *intf, const struct intf_entry *entry)
{
struct ifreq ifr;
struct intf_entry *orig;
struct addr bcast;
u_char buf[BUFSIZ];
orig = (struct intf_entry *)buf;
orig->intf_len = sizeof(buf);
strcpy(orig->intf_name, entry->intf_name);
if (intf_get(intf, orig) < 0)
return (-1);
/* Delete any existing aliases. */
if (_intf_delete_aliases(intf, orig) < 0)
return (-1);
/* Delete any existing addrs. */
if (_intf_delete_addrs(intf, orig) < 0)
return (-1);
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, entry->intf_name, sizeof(ifr.ifr_name));
/* Set interface MTU. */
if (entry->intf_mtu != 0) {
ifr.ifr_mtu = entry->intf_mtu;
if (ioctl(intf->fd, SIOCSIFMTU, &ifr) < 0)
return (-1);
}
/* Set interface address. */
if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
#ifdef BSD
/* XXX - why must this happen before SIOCSIFADDR? */
if (addr_btos(entry->intf_addr.addr_bits,
&ifr.ifr_addr) == 0) {
if (ioctl(intf->fd, SIOCSIFNETMASK, &ifr) < 0)
return (-1);
}
#endif
if (addr_ntos(&entry->intf_addr, &ifr.ifr_addr) < 0)
return (-1);
if (ioctl(intf->fd, SIOCSIFADDR, &ifr) < 0 && errno != EEXIST)
return (-1);
if (addr_btos(entry->intf_addr.addr_bits, &ifr.ifr_addr) == 0
#ifdef __linux__
&& entry->intf_addr.addr_ip != 0
#endif
) {
if (ioctl(intf->fd, SIOCSIFNETMASK, &ifr) < 0)
return (-1);
}
if (addr_bcast(&entry->intf_addr, &bcast) == 0) {
if (addr_ntos(&bcast, &ifr.ifr_broadaddr) == 0) {
/* XXX - ignore error from non-broadcast ifs */
ioctl(intf->fd, SIOCSIFBRDADDR, &ifr);
}
}
}
/* Set link-level address. */
if (entry->intf_link_addr.addr_type == ADDR_TYPE_ETH &&
addr_cmp(&entry->intf_link_addr, &orig->intf_link_addr) != 0) {
#if defined(SIOCSIFHWADDR)
if (addr_ntos(&entry->intf_link_addr, &ifr.ifr_hwaddr) < 0)
return (-1);
if (ioctl(intf->fd, SIOCSIFHWADDR, &ifr) < 0)
return (-1);
#elif defined (SIOCSIFLLADDR)
memcpy(ifr.ifr_addr.sa_data, &entry->intf_link_addr.addr_eth,
ETH_ADDR_LEN);
ifr.ifr_addr.sa_len = ETH_ADDR_LEN;
if (ioctl(intf->fd, SIOCSIFLLADDR, &ifr) < 0)
return (-1);
#else
eth_t *eth;
if ((eth = eth_open(entry->intf_name)) == NULL)
return (-1);
if (eth_set(eth, &entry->intf_link_addr.addr_eth) < 0) {
eth_close(eth);
return (-1);
}
eth_close(eth);
#endif
}
/* Set point-to-point destination. */
if (entry->intf_dst_addr.addr_type == ADDR_TYPE_IP) {
if (addr_ntos(&entry->intf_dst_addr, &ifr.ifr_dstaddr) < 0)
return (-1);
if (ioctl(intf->fd, SIOCSIFDSTADDR, &ifr) < 0 &&
errno != EEXIST)
return (-1);
}
/* Add aliases. */
if (_intf_add_aliases(intf, entry) < 0)
return (-1);
/* Set interface flags. */
if (ioctl(intf->fd, SIOCGIFFLAGS, &ifr) < 0)
return (-1);
ifr.ifr_flags = intf_flags_to_iff(entry->intf_flags, ifr.ifr_flags);
if (ioctl(intf->fd, SIOCSIFFLAGS, &ifr) < 0)
return (-1);
return (0);
}
/* XXX - this is total crap. how to do this without walking ifnet? */
static void
_intf_set_type(struct intf_entry *entry)
{
if ((entry->intf_flags & INTF_FLAG_BROADCAST) != 0)
entry->intf_type = INTF_TYPE_ETH;
else if ((entry->intf_flags & INTF_FLAG_POINTOPOINT) != 0)
entry->intf_type = INTF_TYPE_TUN;
else if ((entry->intf_flags & INTF_FLAG_LOOPBACK) != 0)
entry->intf_type = INTF_TYPE_LOOPBACK;
else
entry->intf_type = INTF_TYPE_OTHER;
}
static int
_intf_get_noalias(intf_t *intf, struct intf_entry *entry)
{
struct ifreq ifr;
strlcpy(ifr.ifr_name, entry->intf_name, sizeof(ifr.ifr_name));
/* Get interface flags. */
if (ioctl(intf->fd, SIOCGIFFLAGS, &ifr) < 0)
return (-1);
entry->intf_flags = intf_iff_to_flags(ifr.ifr_flags);
_intf_set_type(entry);
/* Get interface MTU. */
if (ioctl(intf->fd, SIOCGIFMTU, &ifr) < 0)
return (-1);
entry->intf_mtu = ifr.ifr_mtu;
entry->intf_addr.addr_type = entry->intf_dst_addr.addr_type =
entry->intf_link_addr.addr_type = ADDR_TYPE_NONE;
/* Get primary interface address. */
if (ioctl(intf->fd, SIOCGIFADDR, &ifr) == 0) {
addr_ston(&ifr.ifr_addr, &entry->intf_addr);
if (ioctl(intf->fd, SIOCGIFNETMASK, &ifr) < 0)
return (-1);
addr_stob(&ifr.ifr_addr, &entry->intf_addr.addr_bits);
}
/* Get other addresses. */
if (entry->intf_type == INTF_TYPE_TUN) {
if (ioctl(intf->fd, SIOCGIFDSTADDR, &ifr) == 0) {
if (addr_ston(&ifr.ifr_addr,
&entry->intf_dst_addr) < 0)
return (-1);
}
} else if (entry->intf_type == INTF_TYPE_ETH) {
#if defined(SIOCGIFHWADDR)
if (ioctl(intf->fd, SIOCGIFHWADDR, &ifr) < 0)
return (-1);
if (addr_ston(&ifr.ifr_addr, &entry->intf_link_addr) < 0)
return (-1);
#elif defined(SIOCRPHYSADDR)
/* Tru64 */
struct ifdevea *ifd = (struct ifdevea *)&ifr; /* XXX */
if (ioctl(intf->fd, SIOCRPHYSADDR, ifd) < 0)
return (-1);
addr_pack(&entry->intf_link_addr, ADDR_TYPE_ETH, ETH_ADDR_BITS,
ifd->current_pa, ETH_ADDR_LEN);
#else
eth_t *eth;
if ((eth = eth_open(entry->intf_name)) != NULL) {
if (!eth_get(eth, &entry->intf_link_addr.addr_eth)) {
entry->intf_link_addr.addr_type =
ADDR_TYPE_ETH;
entry->intf_link_addr.addr_bits =
ETH_ADDR_BITS;
}
eth_close(eth);
}
#endif
}
return (0);
}
#ifdef SIOCLIFADDR
/* XXX - aliases on IRIX don't show up in SIOCGIFCONF */
static int
_intf_get_aliases(intf_t *intf, struct intf_entry *entry)
{
struct dnet_ifaliasreq ifra;
struct addr *ap, *lap;
strlcpy(ifra.ifra_name, entry->intf_name, sizeof(ifra.ifra_name));
addr_ntos(&entry->intf_addr, &ifra.ifra_addr);
addr_btos(entry->intf_addr.addr_bits, &ifra.ifra_mask);
memset(&ifra.ifra_brdaddr, 0, sizeof(ifra.ifra_brdaddr));
ifra.ifra_cookie = 1;
ap = entry->intf_alias_addrs;
lap = (struct addr *)((u_char *)entry + entry->intf_len);
while (ioctl(intf->fd, SIOCLIFADDR, &ifra) == 0 &&
ifra.ifra_cookie > 0 && (ap + 1) < lap) {
if (addr_ston(&ifra.ifra_addr, ap) < 0)
break;
ap++, entry->intf_alias_num++;
}
entry->intf_len = (u_char *)ap - (u_char *)entry;
return (0);
}
#else
static int
_intf_get_aliases(intf_t *intf, struct intf_entry *entry)
{
struct ifreq *ifr, *lifr;
struct addr *ap, *lap;
char *p;
if (intf->ifc.ifc_len < (int)sizeof(*ifr)) {
errno = EINVAL;
return (-1);
}
entry->intf_alias_num = 0;
ap = entry->intf_alias_addrs;
lifr = (struct ifreq *)intf->ifc.ifc_buf +
(intf->ifc.ifc_len / sizeof(*lifr));
lap = (struct addr *)((u_char *)entry + entry->intf_len);
/* Get addresses for this interface. */
for (ifr = intf->ifc.ifc_req; ifr < lifr && (ap + 1) < lap;
ifr = NEXTIFR(ifr)) {
/* XXX - Linux, Solaris ifaliases */
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
if (strcmp(ifr->ifr_name, entry->intf_name) != 0)
continue;
if (addr_ston(&ifr->ifr_addr, ap) < 0)
continue;
/* XXX */
if (ap->addr_type == ADDR_TYPE_ETH) {
memcpy(&entry->intf_link_addr, ap, sizeof(*ap));
continue;
} else if (ap->addr_type == ADDR_TYPE_IP) {
if (ap->addr_ip == entry->intf_addr.addr_ip ||
ap->addr_ip == entry->intf_dst_addr.addr_ip)
continue;
}
#ifdef SIOCGIFNETMASK_IN6
else if (ap->addr_type == ADDR_TYPE_IP6 && intf->fd6 != -1) {
struct in6_ifreq ifr6;
/* XXX - sizeof(ifr) < sizeof(ifr6) */
memcpy(&ifr6, ifr, sizeof(ifr6));
if (ioctl(intf->fd6, SIOCGIFNETMASK_IN6, &ifr6) == 0) {
addr_stob((struct sockaddr *)&ifr6.ifr_addr,
&ap->addr_bits);
}
else perror("SIOCGIFNETMASK_IN6");
}
#endif
ap++, entry->intf_alias_num++;
}
entry->intf_len = (u_char *)ap - (u_char *)entry;
return (0);
}
#endif /* SIOCLIFADDR */
int
intf_get(intf_t *intf, struct intf_entry *entry)
{
if (_intf_get_noalias(intf, entry) < 0)
return (-1);
#ifndef SIOCLIFADDR
intf->ifc.ifc_buf = (caddr_t)intf->ifcbuf;
intf->ifc.ifc_len = sizeof(intf->ifcbuf);
if (ioctl(intf->fd, SIOCGIFCONF, &intf->ifc) < 0)
return (-1);
#endif
return (_intf_get_aliases(intf, entry));
}
static int
_match_intf_src(const struct intf_entry *entry, void *arg)
{
struct intf_entry *save = (struct intf_entry *)arg;
if (entry->intf_addr.addr_type == ADDR_TYPE_IP &&
entry->intf_addr.addr_ip == save->intf_addr.addr_ip) {
/* XXX - truncated result if entry is too small. */
if (save->intf_len < entry->intf_len)
memcpy(save, entry, save->intf_len);
else
memcpy(save, entry, entry->intf_len);
return (1);
}
return (0);
}
int
intf_get_src(intf_t *intf, struct intf_entry *entry, struct addr *src)
{
memcpy(&entry->intf_addr, src, sizeof(*src));
if (intf_loop(intf, _match_intf_src, entry) != 1) {
errno = ENXIO;
return (-1);
}
return (0);
}
int
intf_get_dst(intf_t *intf, struct intf_entry *entry, struct addr *dst)
{
struct sockaddr_in sin;
int n;
if (dst->addr_type != ADDR_TYPE_IP) {
errno = EINVAL;
return (-1);
}
addr_ntos(dst, (struct sockaddr *)&sin);
sin.sin_port = htons(666);
if (connect(intf->fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
return (-1);
n = sizeof(sin);
if (getsockname(intf->fd, (struct sockaddr *)&sin, &n) < 0)
return (-1);
addr_ston((struct sockaddr *)&sin, &entry->intf_addr);
if (intf_loop(intf, _match_intf_src, entry) != 1)
return (-1);
return (0);
}
#ifdef HAVE_LINUX_PROCFS
#define PROC_DEV_FILE "/proc/net/dev"
int
intf_loop(intf_t *intf, intf_handler callback, void *arg)
{
FILE *fp;
struct intf_entry *entry;
char *p, buf[BUFSIZ], ebuf[BUFSIZ];
int ret;
entry = (struct intf_entry *)ebuf;
if ((fp = fopen(PROC_DEV_FILE, "r")) == NULL)
return (-1);
intf->ifc.ifc_buf = (caddr_t)intf->ifcbuf;
intf->ifc.ifc_len = sizeof(intf->ifcbuf);
if (ioctl(intf->fd, SIOCGIFCONF, &intf->ifc) < 0)
return (-1);
ret = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
if ((p = strchr(buf, ':')) == NULL)
continue;
*p = '\0';
for (p = buf; *p == ' '; p++)
;
memset(ebuf, 0, sizeof(ebuf));
strlcpy(entry->intf_name, p, sizeof(entry->intf_name));
entry->intf_len = sizeof(ebuf);
if (_intf_get_noalias(intf, entry) < 0) {
ret = -1;
break;
}
if (_intf_get_aliases(intf, entry) < 0) {
ret = -1;
break;
}
if ((ret = (*callback)(entry, arg)) != 0)
break;
}
if (ferror(fp))
ret = -1;
fclose(fp);
return (ret);
}
#else
int
intf_loop(intf_t *intf, intf_handler callback, void *arg)
{
struct intf_entry *entry;
struct ifreq *ifr, *lifr, *pifr;
char *p, ebuf[BUFSIZ];
int ret;
entry = (struct intf_entry *)ebuf;
intf->ifc.ifc_buf = (caddr_t)intf->ifcbuf;
intf->ifc.ifc_len = sizeof(intf->ifcbuf);
if (ioctl(intf->fd, SIOCGIFCONF, &intf->ifc) < 0)
return (-1);
pifr = NULL;
lifr = (struct ifreq *)&intf->ifc.ifc_buf[intf->ifc.ifc_len];
for (ifr = intf->ifc.ifc_req; ifr < lifr; ifr = NEXTIFR(ifr)) {
/* XXX - Linux, Solaris ifaliases */
if ((p = strchr(ifr->ifr_name, ':')) != NULL)
*p = '\0';
if (pifr != NULL && strcmp(ifr->ifr_name, pifr->ifr_name) == 0)
continue;
memset(ebuf, 0, sizeof(ebuf));
strlcpy(entry->intf_name, ifr->ifr_name,
sizeof(entry->intf_name));
entry->intf_len = sizeof(ebuf);
if (_intf_get_noalias(intf, entry) < 0)
return (-1);
if (_intf_get_aliases(intf, entry) < 0)
return (-1);
if ((ret = (*callback)(entry, arg)) != 0)
return (ret);
pifr = ifr;
}
return (0);
}
#endif /* !HAVE_LINUX_PROCFS */
intf_t *
intf_close(intf_t *intf)
{
if (intf != NULL) {
if (intf->fd >= 0)
close(intf->fd);
if (intf->fd6 >= 0)
close(intf->fd6);
free(intf);
}
return (NULL);
}

View File

@@ -0,0 +1,246 @@
/*
* ip-cooked.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: ip-cooked.c,v 1.17 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#ifndef _WIN32
#include <netinet/in.h>
#include <unistd.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
#include "queue.h"
struct ip_intf {
eth_t *eth;
char name[INTF_NAME_LEN];
struct addr ha;
struct addr pa;
int mtu;
LIST_ENTRY(ip_intf) next;
};
struct ip_handle {
arp_t *arp;
intf_t *intf;
route_t *route;
int fd;
struct sockaddr_in sin;
LIST_HEAD(, ip_intf) ip_intf_list;
};
static int
_add_ip_intf(const struct intf_entry *entry, void *arg)
{
ip_t *ip = (ip_t *)arg;
struct ip_intf *ipi;
if (entry->intf_type == INTF_TYPE_ETH &&
(entry->intf_flags & INTF_FLAG_UP) != 0 &&
entry->intf_mtu >= ETH_LEN_MIN &&
entry->intf_addr.addr_type == ADDR_TYPE_IP &&
entry->intf_link_addr.addr_type == ADDR_TYPE_ETH) {
if ((ipi = calloc(1, sizeof(*ipi))) == NULL)
return (-1);
strlcpy(ipi->name, entry->intf_name, sizeof(ipi->name));
memcpy(&ipi->ha, &entry->intf_link_addr, sizeof(ipi->ha));
memcpy(&ipi->pa, &entry->intf_addr, sizeof(ipi->pa));
ipi->mtu = entry->intf_mtu;
LIST_INSERT_HEAD(&ip->ip_intf_list, ipi, next);
}
return (0);
}
ip_t *
ip_open(void)
{
ip_t *ip;
if ((ip = calloc(1, sizeof(*ip))) != NULL) {
ip->fd = -1;
if ((ip->arp = arp_open()) == NULL ||
(ip->intf = intf_open()) == NULL ||
(ip->route = route_open()) == NULL)
return (ip_close(ip));
if ((ip->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (ip_close(ip));
memset(&ip->sin, 0, sizeof(ip->sin));
ip->sin.sin_family = AF_INET;
ip->sin.sin_port = htons(666);
LIST_INIT(&ip->ip_intf_list);
if (intf_loop(ip->intf, _add_ip_intf, ip) != 0)
return (ip_close(ip));
}
return (ip);
}
static struct ip_intf *
_lookup_ip_intf(ip_t *ip, ip_addr_t dst)
{
struct ip_intf *ipi;
int n;
ip->sin.sin_addr.s_addr = dst;
n = sizeof(ip->sin);
if (connect(ip->fd, (struct sockaddr *)&ip->sin, n) < 0)
return (NULL);
if (getsockname(ip->fd, (struct sockaddr *)&ip->sin, &n) < 0)
return (NULL);
LIST_FOREACH(ipi, &ip->ip_intf_list, next) {
if (ipi->pa.addr_ip == ip->sin.sin_addr.s_addr) {
if (ipi->eth == NULL) {
if ((ipi->eth = eth_open(ipi->name)) == NULL)
return (NULL);
}
if (ipi != LIST_FIRST(&ip->ip_intf_list)) {
LIST_REMOVE(ipi, next);
LIST_INSERT_HEAD(&ip->ip_intf_list, ipi, next);
}
return (ipi);
}
}
return (NULL);
}
static void
_request_arp(struct ip_intf *ipi, struct addr *dst)
{
u_char frame[ETH_HDR_LEN + ARP_HDR_LEN + ARP_ETHIP_LEN];
eth_pack_hdr(frame, ETH_ADDR_BROADCAST, ipi->ha.addr_eth,
ETH_TYPE_ARP);
arp_pack_hdr_ethip(frame + ETH_HDR_LEN, ARP_OP_REQUEST,
ipi->ha.addr_eth, ipi->pa.addr_ip, ETH_ADDR_BROADCAST,
dst->addr_ip);
eth_send(ipi->eth, frame, sizeof(frame));
}
ssize_t
ip_send(ip_t *ip, const void *buf, size_t len)
{
struct ip_hdr *iph;
struct ip_intf *ipi;
struct arp_entry arpent;
struct route_entry rtent;
u_char frame[ETH_LEN_MAX];
int i, usec;
iph = (struct ip_hdr *)buf;
if ((ipi = _lookup_ip_intf(ip, iph->ip_dst)) == NULL) {
errno = EHOSTUNREACH;
return (-1);
}
arpent.arp_pa.addr_type = ADDR_TYPE_IP;
arpent.arp_pa.addr_bits = IP_ADDR_BITS;
arpent.arp_pa.addr_ip = iph->ip_dst;
memcpy(&rtent.route_dst, &arpent.arp_pa, sizeof(rtent.route_dst));
for (i = 0, usec = 10; i < 3; i++, usec *= 100) {
if (arp_get(ip->arp, &arpent) == 0)
break;
if (route_get(ip->route, &rtent) == 0 &&
rtent.route_gw.addr_ip != ipi->pa.addr_ip) {
memcpy(&arpent.arp_pa, &rtent.route_gw,
sizeof(arpent.arp_pa));
if (arp_get(ip->arp, &arpent) == 0)
break;
}
_request_arp(ipi, &arpent.arp_pa);
usleep(usec);
}
if (i == 3)
memset(&arpent.arp_ha.addr_eth, 0xff, ETH_ADDR_LEN);
eth_pack_hdr(frame, arpent.arp_ha.addr_eth,
ipi->ha.addr_eth, ETH_TYPE_IP);
if (len > ipi->mtu) {
u_char *p, *start, *end, *ip_data;
int ip_hl, fraglen;
ip_hl = iph->ip_hl << 2;
fraglen = ipi->mtu - ip_hl;
iph = (struct ip_hdr *)(frame + ETH_HDR_LEN);
memcpy(iph, buf, ip_hl);
ip_data = (u_char *)iph + ip_hl;
start = (u_char *)buf + ip_hl;
end = (u_char *)buf + len;
for (p = start; p < end; ) {
memcpy(ip_data, p, fraglen);
iph->ip_len = htons(ip_hl + fraglen);
iph->ip_off = htons(((p + fraglen < end) ? IP_MF : 0) |
((p - start) >> 3));
ip_checksum(iph, ip_hl + fraglen);
i = ETH_HDR_LEN + ip_hl + fraglen;
if (eth_send(ipi->eth, frame, i) != i)
return (-1);
p += fraglen;
if (end - p < fraglen)
fraglen = end - p;
}
return (len);
}
memcpy(frame + ETH_HDR_LEN, buf, len);
i = ETH_HDR_LEN + len;
if (eth_send(ipi->eth, frame, i) != i)
return (-1);
return (len);
}
ip_t *
ip_close(ip_t *ip)
{
struct ip_intf *ipi, *nxt;
if (ip != NULL) {
for (ipi = LIST_FIRST(&ip->ip_intf_list);
ipi != LIST_END(&ip->ip_intf_list); ipi = nxt) {
nxt = LIST_NEXT(ipi, next);
if (ipi->eth != NULL)
eth_close(ipi->eth);
free(ipi);
}
if (ip->fd >= 0)
close(ip->fd);
if (ip->route != NULL)
route_close(ip->route);
if (ip->intf != NULL)
intf_close(ip->intf);
if (ip->arp != NULL)
arp_close(ip->arp);
free(ip);
}
return (NULL);
}

View File

@@ -0,0 +1,182 @@
/*
* ip-util.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: ip-util.c,v 1.9 2005/02/17 02:55:56 dugsong Exp $
*/
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
ssize_t
ip_add_option(void *buf, size_t len, int proto,
const void *optbuf, size_t optlen)
{
struct ip_hdr *ip;
struct tcp_hdr *tcp = NULL;
u_char *p;
int hl, datalen, padlen;
if (proto != IP_PROTO_IP && proto != IP_PROTO_TCP) {
errno = EINVAL;
return (-1);
}
ip = (struct ip_hdr *)buf;
hl = ip->ip_hl << 2;
p = (u_char *)buf + hl;
if (proto == IP_PROTO_TCP) {
tcp = (struct tcp_hdr *)p;
hl = tcp->th_off << 2;
p = (u_char *)tcp + hl;
}
datalen = ntohs(ip->ip_len) - (p - (u_char *)buf);
/* Compute padding to next word boundary. */
if ((padlen = 4 - (optlen % 4)) == 4)
padlen = 0;
/* XXX - IP_HDR_LEN_MAX == TCP_HDR_LEN_MAX */
if (hl + optlen + padlen > IP_HDR_LEN_MAX ||
ntohs(ip->ip_len) + optlen + padlen > len) {
errno = EINVAL;
return (-1);
}
/* XXX - IP_OPT_TYPEONLY() == TCP_OPT_TYPEONLY */
if (IP_OPT_TYPEONLY(((struct ip_opt *)optbuf)->opt_type))
optlen = 1;
/* Shift any existing data. */
if (datalen) {
memmove(p + optlen + padlen, p, datalen);
}
/* XXX - IP_OPT_NOP == TCP_OPT_NOP */
if (padlen) {
memset(p, IP_OPT_NOP, padlen);
p += padlen;
}
memmove(p, optbuf, optlen);
p += optlen;
optlen += padlen;
if (proto == IP_PROTO_IP)
ip->ip_hl = (p - (u_char *)ip) >> 2;
else if (proto == IP_PROTO_TCP)
tcp->th_off = (p - (u_char *)tcp) >> 2;
ip->ip_len = htons(ntohs(ip->ip_len) + optlen);
return (optlen);
}
void
ip_checksum(void *buf, size_t len)
{
struct ip_hdr *ip;
int hl, off, sum;
if (len < IP_HDR_LEN)
return;
ip = (struct ip_hdr *)buf;
hl = ip->ip_hl << 2;
ip->ip_sum = 0;
sum = ip_cksum_add(ip, hl, 0);
ip->ip_sum = ip_cksum_carry(sum);
off = htons(ip->ip_off);
if ((off & IP_OFFMASK) != 0 || (off & IP_MF) != 0)
return;
len -= hl;
if (ip->ip_p == IP_PROTO_TCP) {
struct tcp_hdr *tcp = (struct tcp_hdr *)((u_char *)ip + hl);
if (len >= TCP_HDR_LEN) {
tcp->th_sum = 0;
sum = ip_cksum_add(tcp, len, 0) +
htons(ip->ip_p + len);
sum = ip_cksum_add(&ip->ip_src, 8, sum);
tcp->th_sum = ip_cksum_carry(sum);
}
} else if (ip->ip_p == IP_PROTO_UDP) {
struct udp_hdr *udp = (struct udp_hdr *)((u_char *)ip + hl);
if (len >= UDP_HDR_LEN) {
udp->uh_sum = 0;
sum = ip_cksum_add(udp, len, 0) +
htons(ip->ip_p + len);
sum = ip_cksum_add(&ip->ip_src, 8, sum);
udp->uh_sum = ip_cksum_carry(sum);
if (!udp->uh_sum)
udp->uh_sum = 0xffff; /* RFC 768 */
}
} else if (ip->ip_p == IP_PROTO_ICMP || ip->ip_p == IP_PROTO_IGMP) {
struct icmp_hdr *icmp = (struct icmp_hdr *)((u_char *)ip + hl);
if (len >= ICMP_HDR_LEN) {
icmp->icmp_cksum = 0;
sum = ip_cksum_add(icmp, len, 0);
icmp->icmp_cksum = ip_cksum_carry(sum);
}
}
}
int
ip_cksum_add(const void *buf, size_t len, int cksum)
{
uint16_t *sp = (uint16_t *)buf;
int n, sn;
sn = len / 2;
n = (sn + 15) / 16;
/* XXX - unroll loop using Duff's device. */
switch (sn % 16) {
case 0: do {
cksum += *sp++;
case 15:
cksum += *sp++;
case 14:
cksum += *sp++;
case 13:
cksum += *sp++;
case 12:
cksum += *sp++;
case 11:
cksum += *sp++;
case 10:
cksum += *sp++;
case 9:
cksum += *sp++;
case 8:
cksum += *sp++;
case 7:
cksum += *sp++;
case 6:
cksum += *sp++;
case 5:
cksum += *sp++;
case 4:
cksum += *sp++;
case 3:
cksum += *sp++;
case 2:
cksum += *sp++;
case 1:
cksum += *sp++;
} while (--n > 0);
}
if (len & 1)
cksum += htons(*(u_char *)sp << 8);
return (cksum);
}

View File

@@ -0,0 +1,75 @@
/*
* ip-win32.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: ip-win32.c,v 1.5 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#include <ws2tcpip.h>
#include <errno.h>
#include <stdlib.h>
#include "dnet.h"
struct ip_handle {
WSADATA wsdata;
SOCKET fd;
struct sockaddr_in sin;
};
ip_t *
ip_open(void)
{
BOOL on;
ip_t *ip;
if ((ip = calloc(1, sizeof(*ip))) != NULL) {
if (WSAStartup(MAKEWORD(2, 2), &ip->wsdata) != 0) {
free(ip);
return (NULL);
}
if ((ip->fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) ==
INVALID_SOCKET)
return (ip_close(ip));
on = TRUE;
if (setsockopt(ip->fd, IPPROTO_IP, IP_HDRINCL,
(const char *)&on, sizeof(on)) == SOCKET_ERROR) {
SetLastError(ERROR_NETWORK_ACCESS_DENIED);
return (ip_close(ip));
}
ip->sin.sin_family = AF_INET;
ip->sin.sin_port = htons(666);
}
return (ip);
}
ssize_t
ip_send(ip_t *ip, const void *buf, size_t len)
{
struct ip_hdr *hdr = (struct ip_hdr *)buf;
ip->sin.sin_addr.s_addr = hdr->ip_src;
if ((len = sendto(ip->fd, (const char *)buf, len, 0,
(struct sockaddr *)&ip->sin, sizeof(ip->sin))) != SOCKET_ERROR)
return (len);
return (-1);
}
ip_t *
ip_close(ip_t *ip)
{
if (ip != NULL) {
WSACleanup();
if (ip->fd != INVALID_SOCKET)
closesocket(ip->fd);
free(ip);
}
return (NULL);
}

103
libdnet-stripped/src/ip.c Normal file
View File

@@ -0,0 +1,103 @@
/*
* ip.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: ip.c,v 1.29 2005/01/25 21:30:40 dugsong Exp $
*/
#include "config.h"
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct ip_handle {
int fd;
};
ip_t *
ip_open(void)
{
ip_t *i;
int n, len;
if ((i = calloc(1, sizeof(*i))) == NULL)
return (NULL);
if ((i->fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
return (ip_close(i));
#ifdef IP_HDRINCL
n = 1;
if (setsockopt(i->fd, IPPROTO_IP, IP_HDRINCL, &n, sizeof(n)) < 0)
return (ip_close(i));
#endif
#ifdef SO_SNDBUF
len = sizeof(n);
if (getsockopt(i->fd, SOL_SOCKET, SO_SNDBUF, &n, &len) < 0)
return (ip_close(i));
for (n += 128; n < 1048576; n += 128) {
if (setsockopt(i->fd, SOL_SOCKET, SO_SNDBUF, &n, len) < 0) {
if (errno == ENOBUFS)
break;
return (ip_close(i));
}
}
#endif
#ifdef SO_BROADCAST
n = 1;
if (setsockopt(i->fd, SOL_SOCKET, SO_BROADCAST, &n, sizeof(n)) < 0)
return (ip_close(i));
#endif
return (i);
}
ssize_t
ip_send(ip_t *i, const void *buf, size_t len)
{
struct ip_hdr *ip;
struct sockaddr_in sin;
ip = (struct ip_hdr *)buf;
memset(&sin, 0, sizeof(sin));
#ifdef HAVE_SOCKADDR_SA_LEN
sin.sin_len = sizeof(sin);
#endif
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = ip->ip_dst;
#ifdef HAVE_RAWIP_HOST_OFFLEN
ip->ip_len = ntohs(ip->ip_len);
ip->ip_off = ntohs(ip->ip_off);
len = sendto(i->fd, buf, len, 0,
(struct sockaddr *)&sin, sizeof(sin));
ip->ip_len = htons(ip->ip_len);
ip->ip_off = htons(ip->ip_off);
return (len);
#else
return (sendto(i->fd, buf, len, 0,
(struct sockaddr *)&sin, sizeof(sin)));
#endif
}
ip_t *
ip_close(ip_t *i)
{
if (i != NULL) {
if (i->fd >= 0)
close(i->fd);
free(i);
}
return (NULL);
}

View File

@@ -0,0 +1,72 @@
/*
* ip6.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: ip6.c,v 1.2 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include "dnet.h"
#define IP6_IS_EXT(n) \
((n) == IP_PROTO_HOPOPTS || (n) == IP_PROTO_DSTOPTS || \
(n) == IP_PROTO_ROUTING || (n) == IP_PROTO_FRAGMENT)
void
ip6_checksum(void *buf, size_t len)
{
struct ip6_hdr *ip6 = (struct ip6_hdr *)buf;
struct ip6_ext_hdr *ext;
u_char *p, nxt;
int i, sum;
nxt = ip6->ip6_nxt;
for (i = IP6_HDR_LEN; IP6_IS_EXT(nxt); i += (ext->ext_len + 1) << 3) {
if (i >= (int)len) return;
ext = (struct ip6_ext_hdr *)((u_char *)buf + i);
nxt = ext->ext_nxt;
}
p = (u_char *)buf + i;
len -= i;
if (nxt == IP_PROTO_TCP) {
struct tcp_hdr *tcp = (struct tcp_hdr *)p;
if (len >= TCP_HDR_LEN) {
tcp->th_sum = 0;
sum = ip_cksum_add(tcp, len, 0) + htons(nxt + len);
sum = ip_cksum_add(&ip6->ip6_src, 32, sum);
tcp->th_sum = ip_cksum_carry(sum);
}
} else if (nxt == IP_PROTO_UDP) {
struct udp_hdr *udp = (struct udp_hdr *)p;
if (len >= UDP_HDR_LEN) {
udp->uh_sum = 0;
sum = ip_cksum_add(udp, len, 0) + htons(nxt + len);
sum = ip_cksum_add(&ip6->ip6_src, 32, sum);
if ((udp->uh_sum = ip_cksum_carry(sum)) == 0)
udp->uh_sum = 0xffff;
}
} else if (nxt == IP_PROTO_ICMPV6) {
struct icmp_hdr *icmp = (struct icmp_hdr *)p;
if (len >= ICMP_HDR_LEN) {
icmp->icmp_cksum = 0;
sum = ip_cksum_add(icmp, len, 0) + htons(nxt + len);
sum = ip_cksum_add(&ip6->ip6_src, 32, sum);
icmp->icmp_cksum = ip_cksum_carry(sum);
}
} else if (nxt == IP_PROTO_ICMP || nxt == IP_PROTO_IGMP) {
struct icmp_hdr *icmp = (struct icmp_hdr *)p;
if (len >= ICMP_HDR_LEN) {
icmp->icmp_cksum = 0;
sum = ip_cksum_add(icmp, len, 0);
icmp->icmp_cksum = ip_cksum_carry(sum);
}
}
}

View File

@@ -0,0 +1,60 @@
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo Exp $";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
/*
* Compare memory regions.
*/
int
memcmp(s1, s2, n)
const void *s1, *s2;
size_t n;
{
if (n != 0) {
register const unsigned char *p1 = s1, *p2 = s2;
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
return (0);
}

211
libdnet-stripped/src/rand.c Normal file
View File

@@ -0,0 +1,211 @@
/*
* rand.c
*
* Pseudorandom number generation, based on OpenBSD arc4random().
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
* Copyright (c) 1996 David Mazieres <dm@lcs.mit.edu>
*
* $Id: rand.c,v 1.15 2005/02/15 06:37:07 dugsong Exp $
*/
#include "config.h"
#ifdef _WIN32
/* XXX */
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0400
# include <wincrypt.h>
# define inline __inline
#else
# include <sys/types.h>
# include <sys/time.h>
# include <unistd.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
struct rand_handle {
uint8_t i;
uint8_t j;
uint8_t s[256];
u_char *tmp;
int tmplen;
};
static inline void
rand_init(rand_t *rand)
{
int i;
for (i = 0; i < 256; i++)
rand->s[i] = i;
rand->i = rand->j = 0;
}
static inline void
rand_addrandom(rand_t *rand, u_char *buf, int len)
{
int i;
uint8_t si;
rand->i--;
for (i = 0; i < 256; i++) {
rand->i = (rand->i + 1);
si = rand->s[rand->i];
rand->j = (rand->j + si + buf[i % len]);
rand->s[rand->i] = rand->s[rand->j];
rand->s[rand->j] = si;
}
rand->j = rand->i;
}
rand_t *
rand_open(void)
{
rand_t *r;
u_char seed[256];
#ifdef _WIN32
HCRYPTPROV hcrypt = 0;
CryptAcquireContext(&hcrypt, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT);
CryptGenRandom(hcrypt, sizeof(seed), seed);
CryptReleaseContext(hcrypt, 0);
#else
struct timeval *tv = (struct timeval *)seed;
int fd;
if ((fd = open("/dev/arandom", O_RDONLY)) != -1 ||
(fd = open("/dev/urandom", O_RDONLY)) != -1) {
read(fd, seed + sizeof(*tv), sizeof(seed) - sizeof(*tv));
close(fd);
}
gettimeofday(tv, NULL);
#endif
if ((r = malloc(sizeof(*r))) != NULL) {
rand_init(r);
rand_addrandom(r, seed, 128);
rand_addrandom(r, seed + 128, 128);
r->tmp = NULL;
r->tmplen = 0;
}
return (r);
}
static uint8_t
rand_getbyte(rand_t *r)
{
uint8_t si, sj;
r->i = (r->i + 1);
si = r->s[r->i];
r->j = (r->j + si);
sj = r->s[r->j];
r->s[r->i] = sj;
r->s[r->j] = si;
return (r->s[(si + sj) & 0xff]);
}
int
rand_get(rand_t *r, void *buf, size_t len)
{
u_char *p;
u_int i;
for (p = buf, i = 0; i < len; i++) {
p[i] = rand_getbyte(r);
}
return (0);
}
int
rand_set(rand_t *r, const void *buf, size_t len)
{
rand_init(r);
rand_addrandom(r, (u_char *)buf, len);
rand_addrandom(r, (u_char *)buf, len);
return (0);
}
int
rand_add(rand_t *r, const void *buf, size_t len)
{
rand_addrandom(r, (u_char *)buf, len);
return (0);
}
uint8_t
rand_uint8(rand_t *r)
{
return (rand_getbyte(r));
}
uint16_t
rand_uint16(rand_t *r)
{
uint16_t val;
val = rand_getbyte(r) << 8;
val |= rand_getbyte(r);
return (val);
}
uint32_t
rand_uint32(rand_t *r)
{
uint32_t val;
val = rand_getbyte(r) << 24;
val |= rand_getbyte(r) << 16;
val |= rand_getbyte(r) << 8;
val |= rand_getbyte(r);
return (val);
}
int
rand_shuffle(rand_t *r, void *base, size_t nmemb, size_t size)
{
u_char *save, *src, *dst, *start = (u_char *)base;
u_int i, j;
if (nmemb < 2)
return (0);
if ((u_int)r->tmplen < size) {
if (r->tmp == NULL) {
if ((save = malloc(size)) == NULL)
return (-1);
} else if ((save = realloc(r->tmp, size)) == NULL)
return (-1);
r->tmp = save;
r->tmplen = size;
} else
save = r->tmp;
for (i = 0; i < nmemb; i++) {
if ((j = rand_uint32(r) % (nmemb - 1)) != i) {
src = start + (size * i);
dst = start + (size * j);
memcpy(save, dst, size);
memcpy(dst, src, size);
memcpy(src, save, size);
}
}
return (0);
}
rand_t *
rand_close(rand_t *r)
{
if (r != NULL) {
if (r->tmp != NULL)
free(r->tmp);
free(r);
}
return (NULL);
}

View File

@@ -0,0 +1,508 @@
/*
* route-bsd.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
* Copyright (c) 1999 Masaki Hirabaru <masaki@merit.edu>
*
* $Id: route-bsd.c,v 1.22 2005/02/10 05:18:38 dugsong Exp $
*/
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
#ifdef HAVE_STREAMS_MIB2
#include <sys/stream.h>
#include <sys/tihdr.h>
#include <sys/tiuser.h>
#include <inet/common.h>
#include <inet/mib2.h>
#include <inet/ip.h>
#undef IP_ADDR_LEN
#include <stropts.h>
#elif defined(HAVE_STREAMS_ROUTE)
#include <sys/stream.h>
#include <sys/stropts.h>
#endif
#define route_t oroute_t /* XXX - unixware */
#include <net/route.h>
#undef route_t
#include <netinet/in.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#ifdef HAVE_SOCKADDR_SA_LEN
#define NEXTSA(s) \
((struct sockaddr *)((u_char *)(s) + ROUNDUP((s)->sa_len)))
#else
#define NEXTSA(s) \
((struct sockaddr *)((u_char *)(s) + ROUNDUP(sizeof(*(s)))))
#endif
struct route_handle {
int fd;
int seq;
#ifdef HAVE_STREAMS_MIB2
int ip_fd;
#endif
};
#ifdef DEBUG
static void
route_msg_print(struct rt_msghdr *rtm)
{
printf("v: %d type: 0x%x flags: 0x%x addrs: 0x%x pid: %d seq: %d\n",
rtm->rtm_version, rtm->rtm_type, rtm->rtm_flags,
rtm->rtm_addrs, rtm->rtm_pid, rtm->rtm_seq);
}
#endif
static int
route_msg(route_t *r, int type, struct addr *dst, struct addr *gw)
{
struct addr net;
struct rt_msghdr *rtm;
struct sockaddr *sa;
u_char buf[BUFSIZ];
pid_t pid;
int len;
memset(buf, 0, sizeof(buf));
rtm = (struct rt_msghdr *)buf;
rtm->rtm_version = RTM_VERSION;
if ((rtm->rtm_type = type) != RTM_DELETE)
rtm->rtm_flags = RTF_UP;
rtm->rtm_addrs = RTA_DST;
rtm->rtm_seq = ++r->seq;
/* Destination */
sa = (struct sockaddr *)(rtm + 1);
if (addr_net(dst, &net) < 0 || addr_ntos(&net, sa) < 0)
return (-1);
sa = NEXTSA(sa);
/* Gateway */
if (gw != NULL && type != RTM_GET) {
rtm->rtm_flags |= RTF_GATEWAY;
rtm->rtm_addrs |= RTA_GATEWAY;
if (addr_ntos(gw, sa) < 0)
return (-1);
sa = NEXTSA(sa);
}
/* Netmask */
if (dst->addr_ip == IP_ADDR_ANY || dst->addr_bits < IP_ADDR_BITS) {
rtm->rtm_addrs |= RTA_NETMASK;
if (addr_btos(dst->addr_bits, sa) < 0)
return (-1);
sa = NEXTSA(sa);
} else
rtm->rtm_flags |= RTF_HOST;
rtm->rtm_msglen = (u_char *)sa - buf;
#ifdef DEBUG
route_msg_print(rtm);
#endif
#ifdef HAVE_STREAMS_ROUTE
if (ioctl(r->fd, RTSTR_SEND, rtm) < 0)
return (-1);
#else
if (write(r->fd, buf, rtm->rtm_msglen) < 0)
return (-1);
pid = getpid();
while (type == RTM_GET && (len = read(r->fd, buf, sizeof(buf))) > 0) {
if (len < (int)sizeof(*rtm)) {
return (-1);
}
if (rtm->rtm_type == type && rtm->rtm_pid == pid &&
rtm->rtm_seq == r->seq) {
if (rtm->rtm_errno) {
errno = rtm->rtm_errno;
return (-1);
}
break;
}
}
#endif
if (type == RTM_GET && (rtm->rtm_addrs & (RTA_DST|RTA_GATEWAY)) ==
(RTA_DST|RTA_GATEWAY)) {
sa = (struct sockaddr *)(rtm + 1);
sa = NEXTSA(sa);
if (addr_ston(sa, gw) < 0 || gw->addr_type != ADDR_TYPE_IP) {
errno = ESRCH;
return (-1);
}
}
return (0);
}
route_t *
route_open(void)
{
route_t *r;
if ((r = calloc(1, sizeof(*r))) != NULL) {
r->fd = -1;
#ifdef HAVE_STREAMS_MIB2
if ((r->ip_fd = open(IP_DEV_NAME, O_RDWR)) < 0)
return (route_close(r));
#endif
#ifdef HAVE_STREAMS_ROUTE
if ((r->fd = open("/dev/route", O_RDWR, 0)) < 0)
#else
if ((r->fd = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0)
#endif
return (route_close(r));
}
return (r);
}
int
route_add(route_t *r, const struct route_entry *entry)
{
struct route_entry rtent;
memcpy(&rtent, entry, sizeof(rtent));
if (route_msg(r, RTM_ADD, &rtent.route_dst, &rtent.route_gw) < 0)
return (-1);
return (0);
}
int
route_delete(route_t *r, const struct route_entry *entry)
{
struct route_entry rtent;
memcpy(&rtent, entry, sizeof(rtent));
if (route_get(r, &rtent) < 0)
return (-1);
if (route_msg(r, RTM_DELETE, &rtent.route_dst, &rtent.route_gw) < 0)
return (-1);
return (0);
}
int
route_get(route_t *r, struct route_entry *entry)
{
if (route_msg(r, RTM_GET, &entry->route_dst, &entry->route_gw) < 0)
return (-1);
return (0);
}
#if defined(HAVE_SYS_SYSCTL_H) || defined(HAVE_STREAMS_ROUTE)
int
route_loop(route_t *r, route_handler callback, void *arg)
{
struct rt_msghdr *rtm;
struct route_entry entry;
struct sockaddr *sa;
char *buf, *lim, *next;
int ret;
#ifdef HAVE_SYS_SYSCTL_H
int mib[6] = { CTL_NET, PF_ROUTE, 0, 0 /* XXX */, NET_RT_DUMP, 0 };
size_t len;
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return (-1);
if (len == 0)
return (0);
if ((buf = malloc(len)) == NULL)
return (-1);
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
free(buf);
return (-1);
}
lim = buf + len;
next = buf;
#else /* HAVE_STREAMS_ROUTE */
struct rt_giarg giarg, *gp;
memset(&giarg, 0, sizeof(giarg));
giarg.gi_op = KINFO_RT_DUMP;
if (ioctl(r->fd, RTSTR_GETROUTE, &giarg) < 0)
return (-1);
if ((buf = malloc(giarg.gi_size)) == NULL)
return (-1);
gp = (struct rt_giarg *)buf;
gp->gi_size = giarg.gi_size;
gp->gi_op = KINFO_RT_DUMP;
gp->gi_where = buf;
gp->gi_arg = RTF_UP | RTF_GATEWAY;
if (ioctl(r->fd, RTSTR_GETROUTE, buf) < 0) {
free(buf);
return (-1);
}
lim = buf + gp->gi_size;
next = buf + sizeof(giarg);
#endif
for (ret = 0; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sa = (struct sockaddr *)(rtm + 1);
if (addr_ston(sa, &entry.route_dst) < 0 ||
(rtm->rtm_addrs & RTA_GATEWAY) == 0)
continue;
sa = NEXTSA(sa);
if (addr_ston(sa, &entry.route_gw) < 0)
continue;
if (entry.route_dst.addr_type != entry.route_gw.addr_type ||
(entry.route_dst.addr_type != ADDR_TYPE_IP &&
entry.route_dst.addr_type != ADDR_TYPE_IP6))
continue;
if (rtm->rtm_addrs & RTA_NETMASK) {
sa = NEXTSA(sa);
if (addr_stob(sa, &entry.route_dst.addr_bits) < 0)
continue;
}
if ((ret = callback(&entry, arg)) != 0)
break;
}
free(buf);
return (ret);
}
#elif defined(HAVE_STREAMS_MIB2)
#ifdef IRE_DEFAULT /* This means Solaris 5.6 */
/* I'm not sure if they are compatible, though -- masaki */
#define IRE_ROUTE IRE_CACHE
#define IRE_ROUTE_REDIRECT IRE_HOST_REDIRECT
#endif /* IRE_DEFAULT */
int
route_loop(route_t *r, route_handler callback, void *arg)
{
struct route_entry entry;
struct sockaddr_in sin;
struct strbuf msg;
struct T_optmgmt_req *tor;
struct T_optmgmt_ack *toa;
struct T_error_ack *tea;
struct opthdr *opt;
mib2_ipRouteEntry_t *rt, *rtend;
u_char buf[8192];
int flags, rc, rtable, ret;
tor = (struct T_optmgmt_req *)buf;
toa = (struct T_optmgmt_ack *)buf;
tea = (struct T_error_ack *)buf;
tor->PRIM_type = T_OPTMGMT_REQ;
tor->OPT_offset = sizeof(*tor);
tor->OPT_length = sizeof(*opt);
tor->MGMT_flags = T_CURRENT;
opt = (struct opthdr *)(tor + 1);
opt->level = MIB2_IP;
opt->name = opt->len = 0;
msg.maxlen = sizeof(buf);
msg.len = sizeof(*tor) + sizeof(*opt);
msg.buf = buf;
if (putmsg(r->ip_fd, &msg, NULL, 0) < 0)
return (-1);
opt = (struct opthdr *)(toa + 1);
msg.maxlen = sizeof(buf);
for (;;) {
flags = 0;
if ((rc = getmsg(r->ip_fd, &msg, NULL, &flags)) < 0)
return (-1);
/* See if we're finished. */
if (rc == 0 &&
msg.len >= sizeof(*toa) &&
toa->PRIM_type == T_OPTMGMT_ACK &&
toa->MGMT_flags == T_SUCCESS && opt->len == 0)
break;
if (msg.len >= sizeof(*tea) && tea->PRIM_type == T_ERROR_ACK)
return (-1);
if (rc != MOREDATA || msg.len < (int)sizeof(*toa) ||
toa->PRIM_type != T_OPTMGMT_ACK ||
toa->MGMT_flags != T_SUCCESS)
return (-1);
rtable = (opt->level == MIB2_IP && opt->name == MIB2_IP_21);
msg.maxlen = sizeof(buf) - (sizeof(buf) % sizeof(*rt));
msg.len = 0;
flags = 0;
do {
rc = getmsg(r->ip_fd, NULL, &msg, &flags);
if (rc != 0 && rc != MOREDATA)
return (-1);
if (!rtable)
continue;
rt = (mib2_ipRouteEntry_t *)msg.buf;
rtend = (mib2_ipRouteEntry_t *)(msg.buf + msg.len);
sin.sin_family = AF_INET;
for ( ; rt < rtend; rt++) {
if ((rt->ipRouteInfo.re_ire_type &
(IRE_BROADCAST|IRE_ROUTE_REDIRECT|
IRE_LOCAL|IRE_ROUTE)) != 0 ||
rt->ipRouteNextHop == IP_ADDR_ANY)
continue;
sin.sin_addr.s_addr = rt->ipRouteNextHop;
addr_ston((struct sockaddr *)&sin,
&entry.route_gw);
sin.sin_addr.s_addr = rt->ipRouteDest;
addr_ston((struct sockaddr *)&sin,
&entry.route_dst);
sin.sin_addr.s_addr = rt->ipRouteMask;
addr_stob((struct sockaddr *)&sin,
&entry.route_dst.addr_bits);
if ((ret = callback(&entry, arg)) != 0)
return (ret);
}
} while (rc == MOREDATA);
}
return (0);
}
#elif defined(HAVE_NET_RADIX_H)
/* XXX - Tru64, others? */
#include <nlist.h>
static int
_kread(int fd, void *addr, void *buf, int len)
{
if (lseek(fd, (off_t)addr, SEEK_SET) == (off_t)-1L)
return (-1);
return (read(fd, buf, len) == len ? 0 : -1);
}
static int
_radix_walk(int fd, struct radix_node *rn, route_handler callback, void *arg)
{
struct radix_node rnode;
struct rtentry rt;
struct sockaddr_in sin;
struct route_entry entry;
int ret = 0;
again:
_kread(fd, rn, &rnode, sizeof(rnode));
if (rnode.rn_b < 0) {
if (!(rnode.rn_flags & RNF_ROOT)) {
_kread(fd, rn, &rt, sizeof(rt));
_kread(fd, rt_key(&rt), &sin, sizeof(sin));
addr_ston((struct sockaddr *)&sin, &entry.route_dst);
if (!(rt.rt_flags & RTF_HOST)) {
_kread(fd, rt_mask(&rt), &sin, sizeof(sin));
addr_stob((struct sockaddr *)&sin,
&entry.route_dst.addr_bits);
}
_kread(fd, rt.rt_gateway, &sin, sizeof(sin));
addr_ston((struct sockaddr *)&sin, &entry.route_gw);
if ((ret = callback(&entry, arg)) != 0)
return (ret);
}
if ((rn = rnode.rn_dupedkey))
goto again;
} else {
rn = rnode.rn_r;
if ((ret = _radix_walk(fd, rnode.rn_l, callback, arg)) != 0)
return (ret);
if ((ret = _radix_walk(fd, rn, callback, arg)) != 0)
return (ret);
}
return (ret);
}
int
route_loop(route_t *r, route_handler callback, void *arg)
{
struct radix_node_head *rnh, head;
struct nlist nl[2];
int fd, ret = 0;
memset(nl, 0, sizeof(nl));
nl[0].n_name = "radix_node_head";
if (knlist(nl) < 0 || nl[0].n_type == 0 ||
(fd = open("/dev/kmem", O_RDONLY, 0)) < 0)
return (-1);
for (_kread(fd, (void *)nl[0].n_value, &rnh, sizeof(rnh));
rnh != NULL; rnh = head.rnh_next) {
_kread(fd, rnh, &head, sizeof(head));
/* XXX - only IPv4 for now... */
if (head.rnh_af == AF_INET) {
if ((ret = _radix_walk(fd, head.rnh_treetop,
callback, arg)) != 0)
break;
}
}
close(fd);
return (ret);
}
#else
int
route_loop(route_t *r, route_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
#endif
route_t *
route_close(route_t *r)
{
if (r != NULL) {
#ifdef HAVE_STREAMS_MIB2
if (r->ip_fd >= 0)
close(r->ip_fd);
#endif
if (r->fd >= 0)
close(r->fd);
free(r);
}
return (NULL);
}

View File

@@ -0,0 +1,180 @@
/*
* route-hpux.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: route-hpux.c,v 1.11 2004/01/14 04:52:11 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mib.h>
#include <sys/socket.h>
#include <net/route.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
#define ADDR_ISHOST(a) (((a)->addr_type == ADDR_TYPE_IP && \
(a)->addr_bits == IP_ADDR_BITS) || \
((a)->addr_type == ADDR_TYPE_IP6 && \
(a)->addr_bits == IP6_ADDR_BITS))
struct route_handle {
int fd;
};
route_t *
route_open(void)
{
route_t *r;
if ((r = calloc(1, sizeof(*r))) != NULL) {
if ((r->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (route_close(r));
}
return (r);
}
int
route_add(route_t *r, const struct route_entry *entry)
{
struct rtentry rt;
struct addr dst;
memset(&rt, 0, sizeof(rt));
rt.rt_flags = RTF_UP | RTF_GATEWAY;
if (ADDR_ISHOST(&entry->route_dst)) {
rt.rt_flags |= RTF_HOST;
memcpy(&dst, &entry->route_dst, sizeof(dst));
} else
addr_net(&entry->route_dst, &dst);
if (addr_ntos(&dst, &rt.rt_dst) < 0 ||
addr_ntos(&entry->route_gw, &rt.rt_gateway) < 0 ||
addr_btom(entry->route_dst.addr_bits, &rt.rt_subnetmask,
IP_ADDR_LEN) < 0)
return (-1);
return (ioctl(r->fd, SIOCADDRT, &rt));
}
int
route_delete(route_t *r, const struct route_entry *entry)
{
struct rtentry rt;
struct addr dst;
memset(&rt, 0, sizeof(rt));
rt.rt_flags = RTF_UP;
if (ADDR_ISHOST(&entry->route_dst)) {
rt.rt_flags |= RTF_HOST;
memcpy(&dst, &entry->route_dst, sizeof(dst));
} else
addr_net(&entry->route_dst, &dst);
if (addr_ntos(&dst, &rt.rt_dst) < 0 ||
addr_btom(entry->route_dst.addr_bits, &rt.rt_subnetmask,
IP_ADDR_LEN) < 0)
return (-1);
return (ioctl(r->fd, SIOCDELRT, &rt));
}
int
route_get(route_t *r, struct route_entry *entry)
{
struct rtreq rtr;
memset(&rtr, 0, sizeof(rtr));
/* XXX - gross hack for default route */
if (entry->route_dst.addr_ip == IP_ADDR_ANY) {
rtr.rtr_destaddr = htonl(0x60060606);
rtr.rtr_subnetmask = 0xffffffff;
} else {
memcpy(&rtr.rtr_destaddr, &entry->route_dst.addr_ip,
IP_ADDR_LEN);
if (entry->route_dst.addr_bits < IP_ADDR_BITS)
addr_btom(entry->route_dst.addr_bits,
&rtr.rtr_subnetmask, IP_ADDR_LEN);
}
if (ioctl(r->fd, SIOCGRTENTRY, &rtr) < 0)
return (-1);
if (rtr.rtr_gwayaddr == 0) {
errno = ESRCH;
return (-1);
}
entry->route_gw.addr_type = ADDR_TYPE_IP;
entry->route_gw.addr_bits = IP_ADDR_BITS;
memcpy(&entry->route_gw.addr_ip, &rtr.rtr_gwayaddr, IP_ADDR_LEN);
return (0);
}
#define MAX_RTENTRIES 256 /* XXX */
int
route_loop(route_t *r, route_handler callback, void *arg)
{
struct nmparms nm;
struct route_entry entry;
mib_ipRouteEnt rtentries[MAX_RTENTRIES];
int fd, i, n, ret;
if ((fd = open_mib("/dev/ip", O_RDWR, 0 /* XXX */, 0)) < 0)
return (-1);
nm.objid = ID_ipRouteTable;
nm.buffer = rtentries;
n = sizeof(rtentries);
nm.len = &n;
if (get_mib_info(fd, &nm) < 0) {
close_mib(fd);
return (-1);
}
close_mib(fd);
entry.route_dst.addr_type = entry.route_gw.addr_type = ADDR_TYPE_IP;
entry.route_dst.addr_bits = entry.route_gw.addr_bits = IP_ADDR_BITS;
n /= sizeof(*rtentries);
ret = 0;
for (i = 0; i < n; i++) {
if (rtentries[i].Type != NMDIRECT &&
rtentries[i].Type != NMREMOTE)
continue;
entry.route_dst.addr_ip = rtentries[i].Dest;
addr_mtob(&rtentries[i].Mask, IP_ADDR_LEN,
&entry.route_dst.addr_bits);
entry.route_gw.addr_ip = rtentries[i].NextHop;
if ((ret = callback(&entry, arg)) != 0)
break;
}
return (ret);
}
route_t *
route_close(route_t *r)
{
if (r != NULL) {
if (r->fd >= 0)
close(r->fd);
free(r);
}
return (NULL);
}

View File

@@ -0,0 +1,258 @@
/*
* route-linux.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: route-linux.c,v 1.15 2005/01/23 07:36:54 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <net/route.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
#define ADDR_ISHOST(a) (((a)->addr_type == ADDR_TYPE_IP && \
(a)->addr_bits == IP_ADDR_BITS) || \
((a)->addr_type == ADDR_TYPE_IP6 && \
(a)->addr_bits == IP6_ADDR_BITS))
#define PROC_ROUTE_FILE "/proc/net/route"
struct route_handle {
int fd;
int nlfd;
};
route_t *
route_open(void)
{
struct sockaddr_nl snl;
route_t *r;
if ((r = calloc(1, sizeof(*r))) != NULL) {
r->fd = r->nlfd = -1;
if ((r->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return (route_close(r));
if ((r->nlfd = socket(AF_NETLINK, SOCK_RAW,
NETLINK_ROUTE)) < 0)
return (route_close(r));
memset(&snl, 0, sizeof(snl));
snl.nl_family = AF_NETLINK;
if (bind(r->nlfd, (struct sockaddr *)&snl, sizeof(snl)) < 0)
return (route_close(r));
}
return (r);
}
int
route_add(route_t *r, const struct route_entry *entry)
{
struct rtentry rt;
struct addr dst;
memset(&rt, 0, sizeof(rt));
rt.rt_flags = RTF_UP | RTF_GATEWAY;
if (ADDR_ISHOST(&entry->route_dst)) {
rt.rt_flags |= RTF_HOST;
memcpy(&dst, &entry->route_dst, sizeof(dst));
} else
addr_net(&entry->route_dst, &dst);
if (addr_ntos(&dst, &rt.rt_dst) < 0 ||
addr_ntos(&entry->route_gw, &rt.rt_gateway) < 0 ||
addr_btos(entry->route_dst.addr_bits, &rt.rt_genmask) < 0)
return (-1);
return (ioctl(r->fd, SIOCADDRT, &rt));
}
int
route_delete(route_t *r, const struct route_entry *entry)
{
struct rtentry rt;
struct addr dst;
memset(&rt, 0, sizeof(rt));
rt.rt_flags = RTF_UP;
if (ADDR_ISHOST(&entry->route_dst)) {
rt.rt_flags |= RTF_HOST;
memcpy(&dst, &entry->route_dst, sizeof(dst));
} else
addr_net(&entry->route_dst, &dst);
if (addr_ntos(&dst, &rt.rt_dst) < 0 ||
addr_btos(entry->route_dst.addr_bits, &rt.rt_genmask) < 0)
return (-1);
return (ioctl(r->fd, SIOCDELRT, &rt));
}
int
route_get(route_t *r, struct route_entry *entry)
{
static int seq;
struct nlmsghdr *nmsg;
struct rtmsg *rmsg;
struct rtattr *rta;
struct sockaddr_nl snl;
struct iovec iov;
struct msghdr msg;
u_char buf[512];
int i;
if (entry->route_dst.addr_type != ADDR_TYPE_IP) {
errno = EINVAL;
return (-1);
}
memset(buf, 0, sizeof(buf));
nmsg = (struct nlmsghdr *)buf;
nmsg->nlmsg_len = NLMSG_LENGTH(sizeof(*nmsg)) +
RTA_LENGTH(IP_ADDR_LEN);
nmsg->nlmsg_flags = NLM_F_REQUEST;
nmsg->nlmsg_type = RTM_GETROUTE;
nmsg->nlmsg_seq = ++seq;
rmsg = (struct rtmsg *)(nmsg + 1);
rmsg->rtm_family = AF_INET;
rmsg->rtm_dst_len = entry->route_dst.addr_bits;
rta = RTM_RTA(rmsg);
rta->rta_type = RTA_DST;
rta->rta_len = RTA_LENGTH(IP_ADDR_LEN);
/* XXX - gross hack for default route */
if (entry->route_dst.addr_ip == IP_ADDR_ANY) {
i = htonl(0x60060606);
memcpy(RTA_DATA(rta), &i, IP_ADDR_LEN);
} else
memcpy(RTA_DATA(rta), &entry->route_dst.addr_ip, IP_ADDR_LEN);
memset(&snl, 0, sizeof(snl));
snl.nl_family = AF_NETLINK;
iov.iov_base = nmsg;
iov.iov_len = nmsg->nlmsg_len;
memset(&msg, 0, sizeof(msg));
msg.msg_name = &snl;
msg.msg_namelen = sizeof(snl);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
if (sendmsg(r->nlfd, &msg, 0) < 0)
return (-1);
iov.iov_base = buf;
iov.iov_len = sizeof(buf);
if ((i = recvmsg(r->nlfd, &msg, 0)) <= 0)
return (-1);
if (nmsg->nlmsg_len < (int)sizeof(*nmsg) || nmsg->nlmsg_len > i ||
nmsg->nlmsg_seq != seq) {
errno = EINVAL;
return (-1);
}
if (nmsg->nlmsg_type == NLMSG_ERROR)
return (-1);
i -= NLMSG_LENGTH(sizeof(*nmsg));
while (RTA_OK(rta, i)) {
if (rta->rta_type == RTA_GATEWAY) {
entry->route_gw.addr_type = ADDR_TYPE_IP;
memcpy(&entry->route_gw.addr_ip,
RTA_DATA(rta), IP_ADDR_LEN);
entry->route_gw.addr_bits = IP_ADDR_BITS;
return (0);
}
rta = RTA_NEXT(rta, i);
}
errno = ESRCH;
return (-1);
}
int
route_loop(route_t *r, route_handler callback, void *arg)
{
FILE *fp;
char buf[BUFSIZ], ifbuf[16];
int i, iflags, refcnt, use, metric, mss, win, irtt, ret;
struct route_entry entry;
uint32_t mask;
entry.route_dst.addr_type = entry.route_gw.addr_type = ADDR_TYPE_IP;
entry.route_dst.addr_bits = entry.route_gw.addr_bits = IP_ADDR_BITS;
if ((fp = fopen(PROC_ROUTE_FILE, "r")) == NULL)
return (-1);
ret = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
i = sscanf(buf,
"%16s %X %X %X %d %d %d %X %d %d %d\n",
ifbuf, &entry.route_dst.addr_ip, &entry.route_gw.addr_ip,
&iflags, &refcnt, &use, &metric, &mask, &mss, &win, &irtt);
if (i < 10 || !(iflags & RTF_UP))
continue;
if (entry.route_gw.addr_ip == IP_ADDR_ANY)
continue;
entry.route_dst.addr_type = entry.route_gw.addr_type =
ADDR_TYPE_IP;
if (addr_mtob(&mask, IP_ADDR_LEN,
&entry.route_dst.addr_bits) < 0)
continue;
if ((ret = callback(&entry, arg)) != 0)
break;
}
if (ferror(fp)) {
fclose(fp);
return (-1);
}
fclose(fp);
return (ret);
}
route_t *
route_close(route_t *r)
{
if (r != NULL) {
if (r->fd >= 0)
close(r->fd);
if (r->nlfd >= 0)
close(r->nlfd);
free(r);
}
return (NULL);
}

View File

@@ -0,0 +1,58 @@
/*
* route-none.c
*
* Copyright (c) 2000 Dug Song <dugsong@monkey.org>
*
* $Id: route-none.c,v 1.5 2002/02/04 03:59:45 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "dnet.h"
route_t *
route_open(void)
{
errno = ENOSYS;
return (NULL);
}
int
route_add(route_t *r, const struct route_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
route_delete(route_t *r, const struct route_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
route_get(route_t *r, struct route_entry *entry)
{
errno = ENOSYS;
return (-1);
}
int
route_loop(route_t *r, route_handler callback, void *arg)
{
errno = ENOSYS;
return (-1);
}
route_t *
route_close(route_t *r)
{
return (NULL);
}

View File

@@ -0,0 +1,157 @@
/*
* route-win32.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id: route-win32.c,v 1.12 2005/02/15 07:11:32 dugsong Exp $
*/
#include "config.h"
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "dnet.h"
struct route_handle {
MIB_IPFORWARDTABLE *ipftable;
};
route_t *
route_open(void)
{
return (calloc(1, sizeof(route_t)));
}
int
route_add(route_t *route, const struct route_entry *entry)
{
MIB_IPFORWARDROW ipfrow;
struct addr net;
memset(&ipfrow, 0, sizeof(ipfrow));
if (GetBestInterface(entry->route_gw.addr_ip,
&ipfrow.dwForwardIfIndex) != NO_ERROR)
return (-1);
if (addr_net(&entry->route_dst, &net) < 0 ||
net.addr_type != ADDR_TYPE_IP)
return (-1);
ipfrow.dwForwardDest = net.addr_ip;
addr_btom(entry->route_dst.addr_bits,
&ipfrow.dwForwardMask, IP_ADDR_LEN);
ipfrow.dwForwardNextHop = entry->route_gw.addr_ip;
ipfrow.dwForwardType = 4; /* XXX - next hop != final dest */
ipfrow.dwForwardProto = 3; /* XXX - MIB_PROTO_NETMGMT */
if (CreateIpForwardEntry(&ipfrow) != NO_ERROR)
return (-1);
return (0);
}
int
route_delete(route_t *route, const struct route_entry *entry)
{
MIB_IPFORWARDROW ipfrow;
DWORD mask;
if (entry->route_dst.addr_type != ADDR_TYPE_IP ||
GetBestRoute(entry->route_dst.addr_ip,
IP_ADDR_ANY, &ipfrow) != NO_ERROR)
return (-1);
addr_btom(entry->route_dst.addr_bits, &mask, IP_ADDR_LEN);
if (ipfrow.dwForwardDest != entry->route_dst.addr_ip ||
ipfrow.dwForwardMask != mask) {
errno = ENXIO;
SetLastError(ERROR_NO_DATA);
return (-1);
}
if (DeleteIpForwardEntry(&ipfrow) != NO_ERROR)
return (-1);
return (0);
}
int
route_get(route_t *route, struct route_entry *entry)
{
MIB_IPFORWARDROW ipfrow;
DWORD mask;
if (entry->route_dst.addr_type != ADDR_TYPE_IP ||
GetBestRoute(entry->route_dst.addr_ip,
IP_ADDR_ANY, &ipfrow) != NO_ERROR)
return (-1);
if (ipfrow.dwForwardProto == 2 && /* XXX - MIB_IPPROTO_LOCAL */
(ipfrow.dwForwardNextHop|IP_CLASSA_NET) !=
(IP_ADDR_LOOPBACK|IP_CLASSA_NET) &&
!IP_LOCAL_GROUP(ipfrow.dwForwardNextHop)) {
errno = ENXIO;
SetLastError(ERROR_NO_DATA);
return (-1);
}
addr_btom(entry->route_dst.addr_bits, &mask, IP_ADDR_LEN);
entry->route_gw.addr_type = ADDR_TYPE_IP;
entry->route_gw.addr_bits = IP_ADDR_BITS;
entry->route_gw.addr_ip = ipfrow.dwForwardNextHop;
return (0);
}
int
route_loop(route_t *r, route_handler callback, void *arg)
{
struct route_entry entry;
ULONG len;
int i, ret;
for (len = sizeof(r->ipftable[0]); ; ) {
if (r->ipftable)
free(r->ipftable);
r->ipftable = malloc(len);
ret = GetIpForwardTable(r->ipftable, &len, FALSE);
if (ret == NO_ERROR)
break;
else if (ret != ERROR_INSUFFICIENT_BUFFER)
return (-1);
}
entry.route_dst.addr_type = ADDR_TYPE_IP;
entry.route_dst.addr_bits = IP_ADDR_BITS;
entry.route_gw.addr_type = ADDR_TYPE_IP;
entry.route_gw.addr_bits = IP_ADDR_BITS;
for (i = 0; i < (int)r->ipftable->dwNumEntries; i++) {
entry.route_dst.addr_ip = r->ipftable->table[i].dwForwardDest;
addr_mtob(&r->ipftable->table[i].dwForwardMask, IP_ADDR_LEN,
&entry.route_dst.addr_bits);
entry.route_gw.addr_ip =
r->ipftable->table[i].dwForwardNextHop;
if ((ret = (*callback)(&entry, arg)) != 0)
return (ret);
}
return (0);
}
route_t *
route_close(route_t *r)
{
if (r != NULL) {
if (r->ipftable != NULL)
free(r->ipftable);
free(r);
}
return (NULL);
}

View File

@@ -0,0 +1,73 @@
/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <string.h>
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
strlcat(dst, src, siz)
char *dst;
const char *src;
size_t siz;
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}

View File

@@ -0,0 +1,69 @@
/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <string.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(dst, src, siz)
char *dst;
const char *src;
size_t siz;
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View File

@@ -0,0 +1,85 @@
/* $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <string.h>
#include <stdio.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
#else
static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no more tokens).
*
* If *stringp is NULL, strsep returns NULL.
*/
char *
strsep(stringp, delim)
register char **stringp;
register const char *delim;
{
register char *s;
register const char *spanp;
register int c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}

View File

@@ -0,0 +1,146 @@
/*
* tun-bsd.c
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: tun-bsd.c,v 1.3 2005/02/10 23:50:04 dugsong Exp $
*/
#include "config.h"
#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct tun {
int fd;
intf_t *intf;
struct intf_entry save;
};
#define MAX_DEVS 16 /* XXX - max number of tunnel devices */
tun_t *
tun_open(struct addr *src, struct addr *dst, int mtu)
{
struct intf_entry ifent;
tun_t *tun;
char dev[128];
int i;
if (src->addr_type != ADDR_TYPE_IP || dst->addr_type != ADDR_TYPE_IP ||
src->addr_bits != IP_ADDR_BITS || dst->addr_bits != IP_ADDR_BITS) {
errno = EINVAL;
return (NULL);
}
if ((tun = calloc(1, sizeof(*tun))) == NULL)
return (NULL);
if ((tun->intf = intf_open()) == NULL)
return (tun_close(tun));
memset(&ifent, 0, sizeof(ifent));
ifent.intf_len = sizeof(ifent);
for (i = 0; i < MAX_DEVS; i++) {
snprintf(dev, sizeof(dev), "/dev/tun%d", i);
strlcpy(ifent.intf_name, dev + 5, sizeof(ifent.intf_name));
tun->save = ifent;
if ((tun->fd = open(dev, O_RDWR, 0)) != -1 &&
intf_get(tun->intf, &tun->save) == 0) {
route_t *r;
struct route_entry entry;
ifent.intf_flags = INTF_FLAG_UP|INTF_FLAG_POINTOPOINT;
ifent.intf_addr = *src;
ifent.intf_dst_addr = *dst;
ifent.intf_mtu = mtu;
if (intf_set(tun->intf, &ifent) < 0)
tun = tun_close(tun);
/* XXX - try to ensure our route got set */
if ((r = route_open()) != NULL) {
entry.route_dst = *dst;
entry.route_gw = *src;
route_add(r, &entry);
route_close(r);
}
break;
}
}
if (i == MAX_DEVS)
tun = tun_close(tun);
return (tun);
}
const char *
tun_name(tun_t *tun)
{
return (tun->save.intf_name);
}
int
tun_fileno(tun_t *tun)
{
return (tun->fd);
}
ssize_t
tun_send(tun_t *tun, const void *buf, size_t size)
{
#ifdef __OpenBSD__
struct iovec iov[2];
uint32_t af = htonl(AF_INET);
iov[0].iov_base = &af;
iov[0].iov_len = sizeof(af);
iov[1].iov_base = (void *)buf;
iov[1].iov_len = size;
return (writev(tun->fd, iov, 2));
#else
return (write(tun->fd, buf, size));
#endif
}
ssize_t
tun_recv(tun_t *tun, void *buf, size_t size)
{
#ifdef __OpenBSD__
struct iovec iov[2];
uint32_t af;
iov[0].iov_base = &af;
iov[0].iov_len = sizeof(af);
iov[1].iov_base = (void *)buf;
iov[1].iov_len = size;
return (readv(tun->fd, iov, 2) - sizeof(af));
#else
return (read(tun->fd, buf, size));
#endif
}
tun_t *
tun_close(tun_t *tun)
{
if (tun->fd > 0)
close(tun->fd);
if (tun->intf != NULL) {
/* Restore interface configuration on close. */
intf_set(tun->intf, &tun->save);
intf_close(tun->intf);
}
free(tun);
return (NULL);
}

View File

@@ -0,0 +1,114 @@
/*
* tun-linux.c
*
* Universal TUN/TAP driver, in Linux 2.4+
* /usr/src/linux/Documentation/networking/tuntap.txt
*
* Copyright (c) 2001 Dug Song <dugsong@monkey.org>
*
* $Id: tun-linux.c,v 1.3 2005/02/10 20:18:01 dugsong Exp $
*/
#include "config.h"
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dnet.h"
struct tun {
int fd;
intf_t *intf;
struct ifreq ifr;
};
tun_t *
tun_open(struct addr *src, struct addr *dst, int mtu)
{
tun_t *tun;
struct intf_entry ifent;
if ((tun = calloc(1, sizeof(*tun))) == NULL)
return (NULL);
if ((tun->fd = open("/dev/net/tun", O_RDWR, 0)) < 0 ||
(tun->intf = intf_open()) == NULL)
return (tun_close(tun));
tun->ifr.ifr_flags = IFF_TUN;
if (ioctl(tun->fd, TUNSETIFF, (void *) &tun->ifr) < 0)
return (tun_close(tun));
memset(&ifent, 0, sizeof(ifent));
strlcpy(ifent.intf_name, tun->ifr.ifr_name, sizeof(ifent.intf_name));
ifent.intf_flags = INTF_FLAG_UP|INTF_FLAG_POINTOPOINT;
ifent.intf_addr = *src;
ifent.intf_dst_addr = *dst;
ifent.intf_mtu = mtu;
if (intf_set(tun->intf, &ifent) < 0)
return (tun_close(tun));
return (tun);
}
const char *
tun_name(tun_t *tun)
{
return (tun->ifr.ifr_name);
}
int
tun_fileno(tun_t *tun)
{
return (tun->fd);
}
ssize_t
tun_send(tun_t *tun, const void *buf, size_t size)
{
struct iovec iov[2];
uint32_t type = ETH_TYPE_IP;
iov[0].iov_base = &type;
iov[0].iov_len = sizeof(type);
iov[1].iov_base = (void *)buf;
iov[1].iov_len = size;
return (writev(tun->fd, iov, 2));
}
ssize_t
tun_recv(tun_t *tun, void *buf, size_t size)
{
struct iovec iov[2];
uint32_t type;
iov[0].iov_base = &type;
iov[0].iov_len = sizeof(type);
iov[1].iov_base = (void *)buf;
iov[1].iov_len = size;
return (readv(tun->fd, iov, 2) - sizeof(type));
}
tun_t *
tun_close(tun_t *tun)
{
if (tun->fd > 0)
close(tun->fd);
if (tun->intf != NULL)
intf_close(tun->intf);
free(tun);
return (NULL);
}

Some files were not shown because too many files have changed in this diff Show More