diff options
Diffstat (limited to 'libnet/include')
30 files changed, 7830 insertions, 0 deletions
diff --git a/libnet/include/CVS/Entries b/libnet/include/CVS/Entries new file mode 100644 index 0000000..11472d5 --- /dev/null +++ b/libnet/include/CVS/Entries @@ -0,0 +1,10 @@ +/Makefile.am/1.1.1.1/Thu Jun 26 21:55:10 2003// +/bpf.h/1.1.1.1/Thu Jun 26 21:55:10 2003// +/gnuc.h/1.1.1.1/Thu Jun 26 21:55:10 2003// +/ifaddrlist.h/1.2/Tue Sep 23 22:36:54 2003// +/stamp-h.in/1.1.1.1/Thu Jun 26 21:55:10 2003// +D/libnet//// +D/win32//// +/config.h.in/1.11/Fri Jan 16 10:13:40 2004// +/libnet.h.in/1.5/Sat Jan 17 07:51:19 2004// +/Makefile.in/1.13/Thu Mar 11 18:50:20 2004// diff --git a/libnet/include/CVS/Repository b/libnet/include/CVS/Repository new file mode 100644 index 0000000..4ec92b7 --- /dev/null +++ b/libnet/include/CVS/Repository @@ -0,0 +1 @@ +/usr/local/CVS/libnet/include diff --git a/libnet/include/CVS/Root b/libnet/include/CVS/Root new file mode 100644 index 0000000..52fa133 --- /dev/null +++ b/libnet/include/CVS/Root @@ -0,0 +1 @@ +mike@66.234.207.232:/usr/local/CVS diff --git a/libnet/include/Makefile.am b/libnet/include/Makefile.am new file mode 100644 index 0000000..5cea26e --- /dev/null +++ b/libnet/include/Makefile.am @@ -0,0 +1,7 @@ +# $Id: Makefile.am,v 1.1.1.1 2003/06/26 21:55:10 route Exp $ + +include $(top_srcdir)/Makefile.am.common + +include_HEADERS = libnet.h + +SUBDIRS = libnet diff --git a/libnet/include/Makefile.in b/libnet/include/Makefile.in new file mode 100644 index 0000000..10565b8 --- /dev/null +++ b/libnet/include/Makefile.in @@ -0,0 +1,395 @@ +# Makefile.in generated by automake 1.6.3 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# 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@ + +# $Id: Makefile.in,v 1.13 2004/03/11 18:50:20 mike Exp $ + +# $Id: Makefile.in,v 1.13 2004/03/11 18:50:20 mike Exp $ +# +# Libnet automake information file +# Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> +# All rights reserved. +# +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_alias = @build_alias@ +build_triplet = @build@ +host_alias = @host_alias@ +host_triplet = @host@ +target_alias = @target_alias@ +target_triplet = @target@ + +EXEEXT = @EXEEXT@ +OBJEXT = @OBJEXT@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +ADDITIONAL_LIBS = @ADDITIONAL_LIBS@ +AMTAR = @AMTAR@ +AWK = @AWK@ +CC = @CC@ +DEPDIR = @DEPDIR@ +ENDIANESS = @ENDIANESS@ +HAVE_PACKET_SOCKET = @HAVE_PACKET_SOCKET@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBNET_CONFIG_CFLAGS = @LIBNET_CONFIG_CFLAGS@ +LIBNET_CONFIG_DEFINES = @LIBNET_CONFIG_DEFINES@ +LIBNET_CONFIG_LIBS = @LIBNET_CONFIG_LIBS@ +LIBNET_VERSION = @LIBNET_VERSION@ +MAINT = @MAINT@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +VERSION = @VERSION@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ + +AUTOMAKE_OPTIONS = foreign no-dependencies + +DISTCLEANFILES = *~ + +include_HEADERS = libnet.h + +SUBDIRS = libnet +subdir = include +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = libnet.h +depcomp = +am__depfiles_maybe = +DIST_SOURCES = +HEADERS = $(include_HEADERS) + + +RECURSIVE_TARGETS = info-recursive dvi-recursive install-info-recursive \ + uninstall-info-recursive all-recursive install-data-recursive \ + install-exec-recursive installdirs-recursive install-recursive \ + uninstall-recursive check-recursive installcheck-recursive +DIST_COMMON = $(include_HEADERS) Makefile.am Makefile.in config.h.in \ + libnet.h.in +DIST_SUBDIRS = $(SUBDIRS) +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/Makefile.am.common $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) + +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@ $(top_srcdir)/configure.in $(ACLOCAL_M4) $(top_srcdir)/acconfig.h + cd $(top_srcdir) && $(AUTOHEADER) + touch $(srcdir)/config.h.in + +distclean-hdr: + -rm -f config.h stamp-h1 +libnet.h: $(top_builddir)/config.status libnet.h.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +uninstall-info-am: +includeHEADERS_INSTALL = $(INSTALL_HEADER) +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(includedir) + @list='$(include_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + 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="`echo $$p | sed -e 's|^.*/||'`"; \ + 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 + +ETAGS = etags +ETAGSFLAGS = + +tags: TAGS + +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-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && tags="$$tags -i $$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; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_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 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @list='$(DISTFILES)'; for file in $$list; do \ + 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"; \ + $(mkinstalldirs) "$(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='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d $(distdir)/$$subdir \ + || mkdir $(distdir)/$$subdir \ + || exit 1; \ + (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: + $(mkinstalldirs) $(DESTDIR)$(includedir) + +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_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(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 mostlyclean-am + +distclean: distclean-recursive + +distclean-am: clean-am distclean-generic distclean-hdr distclean-tags + +dvi: dvi-recursive + +dvi-am: + +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 + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic + +uninstall-am: uninstall-includeHEADERS uninstall-info-am + +uninstall-info: uninstall-info-recursive + +.PHONY: $(RECURSIVE_TARGETS) GTAGS all all-am check check-am clean \ + clean-generic clean-recursive distclean distclean-generic \ + distclean-hdr distclean-recursive distclean-tags distdir dvi \ + dvi-am dvi-recursive info info-am info-recursive install \ + install-am install-data install-data-am install-data-recursive \ + install-exec install-exec-am install-exec-recursive \ + install-includeHEADERS install-info install-info-am \ + install-info-recursive install-man install-recursive \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am installdirs-recursive maintainer-clean \ + maintainer-clean-generic maintainer-clean-recursive mostlyclean \ + mostlyclean-generic mostlyclean-recursive tags tags-recursive \ + uninstall uninstall-am uninstall-includeHEADERS \ + uninstall-info-am uninstall-info-recursive uninstall-recursive + +# 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: diff --git a/libnet/include/bpf.h b/libnet/include/bpf.h new file mode 100644 index 0000000..8648a9a --- /dev/null +++ b/libnet/include/bpf.h @@ -0,0 +1,264 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)bpf.h 7.1 (Berkeley) 5/7/91 + * + * @(#) $Header: /usr/local/CVS/libnet/include/bpf.h,v 1.1.1.1 2003/06/26 21:55:10 route Exp $ (LBL) + */ + +#ifndef BPF_MAJOR_VERSION + +/* BSD style release date */ +#define BPF_RELEASE 199606 + +typedef int bpf_int32; +typedef u_int bpf_u_int32; + +/* + * Alignment macros. BPF_WORDALIGN rounds up to the next + * even multiple of BPF_ALIGNMENT. + */ +#define BPF_ALIGNMENT sizeof(bpf_int32) +#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) + +#define BPF_MAXINSNS 512 +#define BPF_MAXBUFSIZE 0x8000 +#define BPF_MINBUFSIZE 32 + +/* + * Structure for BIOCSETF. + */ +struct bpf_program { + u_int bf_len; + struct bpf_insn *bf_insns; +}; + +/* + * Struct returned by BIOCGSTATS. + */ +struct bpf_stat { + u_int bs_recv; /* number of packets received */ + u_int bs_drop; /* number of packets dropped */ +}; + +/* + * Struct return by BIOCVERSION. This represents the version number of + * the filter language described by the instruction encodings below. + * bpf understands a program iff kernel_major == filter_major && + * kernel_minor >= filter_minor, that is, if the value returned by the + * running kernel has the same major number and a minor number equal + * equal to or less than the filter being downloaded. Otherwise, the + * results are undefined, meaning an error may be returned or packets + * may be accepted haphazardly. + * It has nothing to do with the source code version. + */ +struct bpf_version { + u_short bv_major; + u_short bv_minor; +}; +/* Current version number of filter architecture. */ +#define BPF_MAJOR_VERSION 1 +#define BPF_MINOR_VERSION 1 + +/* + * BPF ioctls + * + * The first set is for compatibility with Sun's pcc style + * header files. If your using gcc, we assume that you + * have run fixincludes so the latter set should work. + */ +#if (defined(sun) || defined(ibm032)) && !defined(__GNUC__) +#define BIOCGBLEN _IOR(B,102, u_int) +#define BIOCSBLEN _IOWR(B,102, u_int) +#define BIOCSETF _IOW(B,103, struct bpf_program) +#define BIOCFLUSH _IO(B,104) +#define BIOCPROMISC _IO(B,105) +#define BIOCGDLT _IOR(B,106, u_int) +#define BIOCGETIF _IOR(B,107, struct ifreq) +#define BIOCSETIF _IOW(B,108, struct ifreq) +#define BIOCSRTIMEOUT _IOW(B,109, struct timeval) +#define BIOCGRTIMEOUT _IOR(B,110, struct timeval) +#define BIOCGSTATS _IOR(B,111, struct bpf_stat) +#define BIOCIMMEDIATE _IOW(B,112, u_int) +#define BIOCVERSION _IOR(B,113, struct bpf_version) +#define BIOCSTCPF _IOW(B,114, struct bpf_program) +#define BIOCSUDPF _IOW(B,115, struct bpf_program) +#else +#define BIOCGBLEN _IOR('B',102, u_int) +#define BIOCSBLEN _IOWR('B',102, u_int) +#define BIOCSETF _IOW('B',103, struct bpf_program) +#define BIOCFLUSH _IO('B',104) +#define BIOCPROMISC _IO('B',105) +#define BIOCGDLT _IOR('B',106, u_int) +#define BIOCGETIF _IOR('B',107, struct ifreq) +#define BIOCSETIF _IOW('B',108, struct ifreq) +#define BIOCSRTIMEOUT _IOW('B',109, struct timeval) +#define BIOCGRTIMEOUT _IOR('B',110, struct timeval) +#define BIOCGSTATS _IOR('B',111, struct bpf_stat) +#define BIOCIMMEDIATE _IOW('B',112, u_int) +#define BIOCVERSION _IOR('B',113, struct bpf_version) +#define BIOCSTCPF _IOW('B',114, struct bpf_program) +#define BIOCSUDPF _IOW('B',115, struct bpf_program) +#endif + +/* + * Structure prepended to each packet. + */ +struct bpf_hdr { + struct timeval bh_tstamp; /* time stamp */ + bpf_u_int32 bh_caplen; /* length of captured portion */ + bpf_u_int32 bh_datalen; /* original length of packet */ + u_short bh_hdrlen; /* length of bpf header (this struct + plus alignment padding) */ +}; +/* + * Because the structure above is not a multiple of 4 bytes, some compilers + * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work. + * Only the kernel needs to know about it; applications use bh_hdrlen. + */ +#ifdef KERNEL +#define SIZEOF_BPF_HDR 18 +#endif + +/* + * Data-link level type codes. + */ +#define DLT_NULL 0 /* no link-layer encapsulation */ +#define DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ +#define DLT_AX25 3 /* Amateur Radio AX.25 */ +#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ +#define DLT_CHAOS 5 /* Chaos */ +#define DLT_IEEE802 6 /* IEEE 802 Networks */ +#define DLT_ARCNET 7 /* ARCNET */ +#define DLT_SLIP 8 /* Serial Line IP */ +#define DLT_PPP 9 /* Point-to-point Protocol */ +#define DLT_FDDI 10 /* FDDI */ +#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */ +#define DLT_RAW 12 /* raw IP */ +#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */ + +/* + * The instruction encondings. + */ +/* instruction classes */ +#define BPF_CLASS(code) ((code) & 0x07) +#define BPF_LD 0x00 +#define BPF_LDX 0x01 +#define BPF_ST 0x02 +#define BPF_STX 0x03 +#define BPF_ALU 0x04 +#define BPF_JMP 0x05 +#define BPF_RET 0x06 +#define BPF_MISC 0x07 + +/* ld/ldx fields */ +#define BPF_SIZE(code) ((code) & 0x18) +#define BPF_W 0x00 +#define BPF_H 0x08 +#define BPF_B 0x10 +#define BPF_MODE(code) ((code) & 0xe0) +#define BPF_IMM 0x00 +#define BPF_ABS 0x20 +#define BPF_IND 0x40 +#define BPF_MEM 0x60 +#define BPF_LEN 0x80 +#define BPF_MSH 0xa0 + +/* alu/jmp fields */ +#define BPF_OP(code) ((code) & 0xf0) +#define BPF_ADD 0x00 +#define BPF_SUB 0x10 +#define BPF_MUL 0x20 +#define BPF_DIV 0x30 +#define BPF_OR 0x40 +#define BPF_AND 0x50 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70 +#define BPF_NEG 0x80 +#define BPF_JA 0x00 +#define BPF_JEQ 0x10 +#define BPF_JGT 0x20 +#define BPF_JGE 0x30 +#define BPF_JSET 0x40 +#define BPF_SRC(code) ((code) & 0x08) +#define BPF_K 0x00 +#define BPF_X 0x08 + +/* ret - BPF_K and BPF_X also apply */ +#define BPF_RVAL(code) ((code) & 0x18) +#define BPF_A 0x10 + +/* misc */ +#define BPF_MISCOP(code) ((code) & 0xf8) +#define BPF_TAX 0x00 +#define BPF_TXA 0x80 + +/* + * The instruction data structure. + */ +struct bpf_insn { + u_short code; + u_char jt; + u_char jf; + bpf_int32 k; +}; + +/* + * Macros for insn array initializers. + */ +#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } +#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } + +#ifdef KERNEL +extern u_int bpf_filter(); +extern void bpfattach(); +extern void bpf_tap(); +extern void bpf_mtap(); +#else +#if __STDC__ +extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); +#endif +#endif + +/* + * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). + */ +#define BPF_MEMWORDS 16 + +#endif diff --git a/libnet/include/config.h.in b/libnet/include/config.h.in new file mode 100644 index 0000000..1a085dd --- /dev/null +++ b/libnet/include/config.h.in @@ -0,0 +1,118 @@ +/* include/config.h.in. Generated from configure.in by autoheader. */ +/* +dnl $Id: config.h.in,v 1.11 2004/01/16 10:13:40 mike Exp $ +dnl +dnl Libnet autoconfiguration acconfig.h file +dnl Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> +dnl All rights reserved. +dnl +dnl Process this file with autoheader to produce a config.h file. +dnl +*/ + +#undef LIBNET_BSDISH_OS +#undef LIBNET_BSD_BYTE_SWAP +#undef DLPI_DEV_PREFIX +#undef HAVE_DEV_DLPI +#undef HAVE_SOLARIS +#undef HAVE_SOLARIS_IPV6 +#undef HAVE_HPUX11 +#undef HAVE_SOCKADDR_SA_LEN +#undef HAVE_DLPI +#undef HAVE_PACKET_SOCKET +#undef HAVE_STRUCT_IP_CSUM +#undef HAVE_LIB_PCAP +#undef LBL_ALIGN +#undef STUPID_SOLARIS_CHECKSUM_BUG +#undef _BSD_SOURCE +#undef __BSD_SOURCE +#undef __FAVOR_BSD +#undef LIBNET_BIG_ENDIAN +#undef LIBNET_LIL_ENDIAN +#undef NO_SNPRINTF + + +/* +dnl EOF +*/ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `nsl' library (-lnsl). */ +#undef HAVE_LIBNSL + +/* Define to 1 if you have the `packet' library (-lpacket). */ +#undef HAVE_LIBPACKET + +/* Define to 1 if you have the `socket' library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* Define to 1 if you have the `wpcap' library (-lwpcap). */ +#undef HAVE_LIBWPCAP + +/* Define if you have the Linux /proc filesystem. */ +#undef HAVE_LINUX_PROCFS + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <net/ethernet.h> header file. */ +#undef HAVE_NET_ETHERNET_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/bufmod.h> header file. */ +#undef HAVE_SYS_BUFMOD_H + +/* Define to 1 if you have the <sys/dlpi_ext.h> header file. */ +#undef HAVE_SYS_DLPI_EXT_H + +/* Define to 1 if you have the <sys/sockio.h> header file. */ +#undef HAVE_SYS_SOCKIO_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION diff --git a/libnet/include/gnuc.h b/libnet/include/gnuc.h new file mode 100644 index 0000000..c051c74 --- /dev/null +++ b/libnet/include/gnuc.h @@ -0,0 +1,43 @@ +/* @(#) $Header: /usr/local/CVS/libnet/include/gnuc.h,v 1.1.1.1 2003/06/26 21:55:10 route Exp $ (LBL) */ + +/* Define __P() macro, if necessary */ +#ifndef __P +#if __STDC__ +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +/* inline foo */ +#ifdef __GNUC__ +#define inline __inline +#else +#define inline +#endif + +/* + * Handle new and old "dead" routine prototypes + * + * For example: + * + * __dead void foo(void) __attribute__((volatile)); + * + */ +#ifdef __GNUC__ +#ifndef __dead +#define __dead volatile +#endif +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif +#else +#ifndef __dead +#define __dead +#endif +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif diff --git a/libnet/include/ifaddrlist.h b/libnet/include/ifaddrlist.h new file mode 100644 index 0000000..4c0dca6 --- /dev/null +++ b/libnet/include/ifaddrlist.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +struct ifaddrlist +{ +#if (HAVE_SOLARIS || HAVE_HPUX11) + u_int addr; +#else + u_int32_t addr; +#endif + int8_t *device; +}; + +struct libnet_ifaddr_list +{ + u_int32_t addr; + int8_t *device; +}; + +int +ifaddrlist( + struct ifaddrlist **, + int8_t * + ); + + +int +set_up_interface( + struct sockaddr_in **, + u_int8_t ** + ); + +/* EOF */ diff --git a/libnet/include/libnet.h.in b/libnet/include/libnet.h.in new file mode 100644 index 0000000..89fd64b --- /dev/null +++ b/libnet/include/libnet.h.in @@ -0,0 +1,132 @@ +/* + * $Id: libnet.h.in,v 1.5 2004/01/17 07:51:19 mike Exp $ + * + * libnet.h - Network routine library header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_H +#define __LIBNET_H +/** + * @file libnet.h + * @brief toplevel libnet header file + */ + +/** + * @mainpage Libnet Packet Assembly Library + * + * @section intro Overview + * + * Libnet is a high-level API (toolkit) allowing the application programmer to + * construct and inject network packets. It provides a portable and simplified + * interface for low-level network packet shaping, handling and injection. + * Libnet hides much of the tedium of packet creation from the application + * programmer such as multiplexing, buffer management, arcane packet header + * information, byte-ordering, OS-dependent issues, and much more. Libnet + * features portable packet creation interfaces at the IP layer and link layer, + * as well as a host of supplementary and complementary functionality. Using + * libnet, quick and simple packet assembly applications can be whipped up with + * little effort. With a bit more time, more complex programs can be written + * (Traceroute and ping were easily rewritten using libnet and + * <a href="www.tcpdump.org">libpcap</a>). + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define _GNU_SOURCE +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <signal.h> +#include <stdlib.h> +#if !defined(__WIN32__) +#include <sys/ioctl.h> +#endif /* __WIN32__ */ +#if defined(HAVE_SYS_SOCKIO_H) && !defined(SIOCGIFADDR) +#include <sys/sockio.h> +#endif +#include <sys/stat.h> +#include <sys/types.h> +#include <ctype.h> +#if !defined(__WIN32__) +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <net/if.h> +#else /* __WIN32__ */ +#if (__CYGWIN__) +#include <sys/socket.h> +#endif +#include <ws2tcpip.h> +#include <windows.h> +#include <winsock2.h> +#include <win32/in_systm.h> +#endif /* __WIN32__ */ +#if !(__linux__) && !(__WIN32__) && !(__APPLE__) && !(__CYGWIN__) +#include <netinet/ip_var.h> +#else /* __linux__ */ +#if (HAVE_NET_ETHERNET_H) +#include <net/ethernet.h> +#endif /* HAVE_NET_ETHERNET_H */ +#endif /* __linux__ */ +#if !defined(__WIN32__) +#include <netinet/tcp.h> +#include <netinet/udp.h> +#if (__linux__) && !(__GLIBC__) +/* we get multiple definitions of IGMP_AGE_THRESHOLD if we include netinet */ +#include <linux/igmp.h> +#else +#include <netinet/igmp.h> +#endif +#include <arpa/inet.h> +#include <sys/time.h> +#include <netdb.h> +#endif /* __WIN32__ */ +#include <errno.h> +#include <stdarg.h> + +#define LIBNET_VERSION "@LIBNET_VERSION@" +#define @ENDIANESS@ 1 + +#include "./libnet/libnet-types.h" +#include "./libnet/libnet-macros.h" +#include "./libnet/libnet-headers.h" +#include "./libnet/libnet-structures.h" +#include "./libnet/libnet-asn1.h" +#include "./libnet/libnet-functions.h" + +#ifdef __cplusplus +} +#endif + +#endif /* __LIBNET_H */ + +/* EOF */ diff --git a/libnet/include/libnet/.#libnet-functions.h.1.28 b/libnet/include/libnet/.#libnet-functions.h.1.28 new file mode 100644 index 0000000..303f591 --- /dev/null +++ b/libnet/include/libnet/.#libnet-functions.h.1.28 @@ -0,0 +1,1582 @@ +/* + * $Id: libnet-functions.h,v 1.28 2004/01/15 20:11:15 mike Exp $ + * + * libnet-functions.h - function prototypes + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_FUNCTIONS_H +#define __LIBNET_FUNCTIONS_H +/** + * @file libnet-functions.h + * @brief libnet exported function prototypes + */ + +/** + * Creates the libnet environment. It initializes the library and returns a + * libnet context. If the injection_type is LIBNET_LINK, the function + * initializes the injection primitives for the link-layer interface enabling + * the application programmer to build packets starting at the data-link layer + * (which also provides more granular control over the IP layer). If libnet + * uses the link-layer and the device argument is non-NULL, the function + * attempts to use the specified network device for packet injection. This + * is either a int16_t canonical string that references the device (such as + * "eth0" for a 100MB Ethernet card on Linux or "fxp0" for a 100MB Ethernet + * card on OpenBSD) or the dots and decimals representation of the device's + * IP address (192.168.0.1). If device is NULL, libnet attempts to find a + * suitable device to use. If the injection_type is LIBNET_RAW4, the function + * initializes the injection primitives for the IPv4 raw socket interface. The + * final argument, err_buf, should be a buffer of size LIBNET_ERRBUF_SIZE and + * holds an error message if the function fails. This function requires root + * privileges to execute successfully. Upon success, the function returns a + * valid libnet context for use in later function calls; upon failure, the + * function returns NULL. + * @param injection_type packet injection type (Add these later) + * @param device the interface to use (NULL and libnet will choose one) + * @param err_buf will contain an error message on failure + * @return libnet context ready for use or NULL on error. + */ +libnet_t * +libnet_init(int injection_type, char *device, char *err_buf); + +/** + * Shuts down the libnet session referenced by l. It closes the network + * interface and frees all internal memory structures associated with l. + * @param l pointer to a libnet context + */ +void +libnet_destroy(libnet_t *l); + +/** + * Clears the current packet referenced and frees all pblocks. Should be + * called when the programmer want to send a completely new packet of + * a different type using the same context. + * @param l pointer to a libnet context + */ +void +libnet_clear_packet(libnet_t *l); + +/** + * Fills in a libnet_stats structure with packet injection statistics + * (packets written, bytes written, packet sending errors). + * @param l pointer to a libnet context + * @param ls pointer to a libnet statistics structure + */ +void +libnet_stats(libnet_t *l, struct libnet_stats *ls); + +/** + * Returns the FILENO of the file descriptor used for packet injection. + * @param l pointer to a libnet context + * @return the file number of the file descriptor used for packet injection + */ +int +libnet_getfd(libnet_t *l); + +/** + * Returns the canonical name of the device used for packet injection. + * @param l pointer to a libnet context + * @return the canonical name of the device used for packet injection. Note + * it can be NULL without being an error. + */ +int8_t * +libnet_getdevice(libnet_t *l); + +/** + * Returns the pblock buffer contents for the specified ptag; a + * subsequent call to libnet_getpbuf_size() should be made to determine the + * size of the buffer. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @return a pointer to the pblock buffer or NULL on error + */ +u_int8_t * +libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag); + +/** + * Returns the pblock buffer size for the specified ptag; a + * previous call to libnet_getpbuf() should be made to pull the actual buffer + * contents. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @return the size of the pblock buffer + */ +u_int32_t +libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag); + +/** + * Returns the last error set inside of the referenced libnet context. This + * function should be called anytime a function fails or an error condition + * is detected inside of libnet. + * @param l pointer to a libnet context + * @return an error string or NULL if no error has occured + */ +char * +libnet_geterror(libnet_t *l); + +/** + * Seeds the psuedo-random number generator. + * @param l pointer to a libnet context + * @return 1 on success, -1 on failure + */ +int +libnet_seed_prand(libnet_t *l); + +/** + * Generates an unsigned psuedo-random value within the range specified by + * mod. + * LIBNET_PR2 0 - 1 + * LIBNET_PR8 0 - 255 + * LIBNET_PR16 0 - 32767 + * LIBNET_PRu16 0 - 65535 + * LIBNET_PR32 0 - 2147483647 + * LIBNET_PRu32 0 - 4294967295 + * + * @param mod one the of LIBNET_PR* constants + * @return 1 on success, -1 on failure + */ +u_int32_t +libnet_get_prand(int mod); + +/** + * If a given protocol header is built with the checksum field set to "0", by + * default libnet will calculate the header checksum prior to injection. If the + * header is set to any other value, by default libnet will not calculate the + * header checksum. To over-ride this behavior, use libnet_toggle_checksum(). + * Switches auto-checksumming on or off for the specified ptag. If mode is set + * to LIBNET_ON, libnet will mark the specificed ptag to calculate a checksum + * for the ptag prior to injection. This assumes that the ptag refers to a + * protocol that has a checksum field. If mode is set to LIBNET_OFF, libnet + * will clear the checksum flag and no checksum will be computed prior to + * injection. This assumes that the programmer will assign a value (zero or + * otherwise) to the checksum field. Often times this is useful if a + * precomputed checksum or some other predefined value is going to be used. + * Note that when libnet is initialized with LIBNET_RAW4, the IPv4 header + * checksum will always be computed by the kernel prior to injection, + * regardless of what the programmer sets. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @param mode LIBNET_ON or LIBNET_OFF + * @return 1 on success, -1 on failure + */ +int +libnet_toggle_checksum(libnet_t *l, libnet_ptag_t ptag, int mode); + +/** + * Takes a network byte ordered IPv4 address and returns a pointer to either a + * canonical DNS name (if it has one) or a string of dotted decimals. This may + * incur a DNS lookup if the hostname and mode is set to LIBNET_RESOLVE. If + * mode is set to LIBNET_DONT_RESOLVE, no DNS lookup will be performed and + * the function will return a pointer to a dotted decimal string. The function + * cannot fail -- if no canonical name exists, it will fall back on returning + * a dotted decimal string. This function is non-reentrant. + * @param in network byte ordered IPv4 address + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return a pointer to presentation format string + */ +char * +libnet_addr2name4(u_int32_t in, u_int8_t use_name); + +/** + * Takes a dotted decimal string or a canonical DNS name and returns a + * network byte ordered IPv4 address. This may incur a DNS lookup if mode is + * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode + * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can + * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and + * host_name refers to a canonical DNS name. + * @param l pointer to a libnet context + * @param host_name pointer to a string containing a presentation format host + * name + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return network byte ordered IPv4 address or -1 (2^32 - 1) on error + */ +u_int32_t +libnet_name2addr4(libnet_t *l, char *host_name, u_int8_t use_name); + +extern const struct libnet_in6_addr in6addr_error; + +/** + * Takes a dotted decimal string or a canonical DNS name and returns a + * network byte ordered IPv6 address. This may incur a DNS lookup if mode is + * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode + * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can + * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and + * host_name refers to a canonical DNS name. + * @param l pointer to a libnet context + * @param host_name pointer to a string containing a presentation format host + * name + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return network byte ordered IPv6 address structure + */ +struct libnet_in6_addr +libnet_name2addr6(libnet_t *l, char *host_name, u_int8_t use_name); + +/** + * Should document this baby right here. + */ +void +libnet_addr2name6_r(struct libnet_in6_addr addr, u_int8_t use_name, +char *host_name, int host_name_len); + +/** + * Creates a new port list. Port list chains are useful for TCP and UDP-based + * applications that need to send packets to a range of ports (contiguous or + * otherwise). The port list chain, which token_list points to, should contain + * a series of int8_tacters from the following list: "0123456789,-" of the + * general format "x - y, z", where "xyz" are port numbers between 0 and + * 65,535. plist points to the front of the port list chain list for use in + * further libnet_plist_chain() functions. Upon success, the function returns + * 1. Upon failure, the function returns -1 and libnet_geterror() can tell you + * why. + * @param l pointer to a libnet context + * @param plist if successful, will refer to the portlist, if not, NULL + * @param token_list string containing the port list primitive + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list); + +/** + * Returns the next port list chain pair from the port list chain plist. bport + * and eport contain the starting port number and ending port number, + * respectively. Upon success, the function returns 1 and fills in the port + * variables; however, if the list is empty, the function returns 0 and sets + * both port variables to 0. Upon failure, the function returns -1. + * @param plist previously created portlist + * @param bport will contain the beginning port number or 0 + * @param eport will contain the ending port number or 0 + * @return 1 on success, 0 if empty, -1 on failure + */ +int +libnet_plist_chain_next_pair(libnet_plist_t *plist, u_int16_t *bport, +u_int16_t *eport); + +/** + * Runs through the port list and prints the contents of the port list chain + * list to stdout. + * @param plist previously created portlist + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_dump(libnet_plist_t *plist); + +/** + * Runs through the port list and prints the contents of the port list chain + * list to string. This function uses strdup and is not re-entrant. It also + * has a memory leak and should not really be used. + * @param plist previously created portlist + * @return a printable string containing the port list contents on success + * NULL on error + */ +char * +libnet_plist_chain_dump_string(libnet_plist_t *plist); + +/** + * Frees all memory associated with port list chain. + * @param plist previously created portlist + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_free(libnet_plist_t *plist); + +/** + *\section PBF Packet Builder Functions + * + * The core of libnet is the platform-independent packet-building + * functionality. These functions enable an application programmer to build + * protocol headers (and data) in a simple and consistent manner without having + * to worry (too much) about low-level network odds and ends. Each + * libnet_build() function builds a piece of a packet (generally a protocol + * header). While it is perfectly possible to build an entire, + * ready-to-transmit packet with a single call to a libnet_build() function, + * generally more than one builder-class function call is required to construct + * a full packet. A complete wire-ready packet generally consists of more than + * one piece. + * Every function that builds a protocol header takes a series of arguments + * roughly corresponding to the header values as they appear on the wire. This + * process is intuitive but often makes for functions with huge prototypes and + * large stack frames. + * One important thing to note is that you must call these functions in order, + * corresponding to how they should appear on the wire (from the highest + * protocol layer on down). This building process is intuitive; it approximates + * what happens in an operating system kernel. In other words, to build a + * Network Time Protocol (NTP) packet by using the link-layer interface, the + * application programmer would call the libnet_build() functions in the + * following order: + * 1. libnet_build_ntp() + * 2. libnet_build_udp() + * 3. libnet_build_ipv4() + * 4. libnet_build_ethernet() + * This ordering is essential for libnet 1.1.x to properly link together the + * packet internally (previous libnet versions did not have the requirement). + * + *\subsection TPI The Payload Interface + * + * The payload interface specifies an optional way to include data directly + * after the protocol header in question. You can use this function for a + * variety of purposes, including the following: + * - Including additional or arbitrary protocol header information that is not + * available from a libnet interface + * - Including a packet payload (data segment) + * - Building another protocol header that is not available from a libnet + * interface + * To employ the interface, the application programmer should construct the i + * payload data and pass a u_int8_t * to this data and its size to the desired + * libnet_build() function. Libnet handles the rest. + * + *\subsection PT Protocol Tags and Packet Builder Return Values + * + * Libnet uses the protocol tag (ptag) to identify individual pieces of a + * packet after being created. A new ptag results every time a libnet_build() + * function with an empty (0) ptag argument completes successfully. This new + * ptag now refers to the packet piece just created. The application + * programmer's responsibility is to save this value if he or she plans to + * modify this particular portion later on in the program. If the application + * programmer needs to modify some portion of that particular packet piece + * again, he or she calls the same libnet_build() function specifying the + * saved ptag argument. Libnet then searches for that packet piece and modifies + * it rather than creating a new one. Upon failure for any reason, + * libnet_build() functions return -1; libnet_geterror()tells you why. + */ + +/** + * Builds an IEEE 802.1q VLAN tagging header. Depending on the value of + * len_proto, the function wraps the 802.1q header inside either an IEEE 802.3 + * header or an RFC 894 Ethernet II (DIX) header (both resulting in an 18-byte + * frame). If len is 1500 or less, most receiving protocol stacks parse the + * frame as an IEEE 802.3 encapsulated frame. If len is one of the Ethernet type + * values, most protocol stacks parse the frame as an RFC 894 Ethernet II + * encapsulated frame. Note the length value is calculated without the 802.1q + * header of 18 bytes. + * @param dst pointer to a six byte source ethernet address + * @param src pointer to a six byte destination ethernet address + * @param tpi tag protocol identifier + * @param priority priority + * @param cfi canonical format indicator + * @param vlan_id vlan identifier + * @param len_proto length (802.3) protocol (Ethernet II) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_1q(u_int8_t *dst, u_int8_t *src, u_int16_t tpi, +u_int8_t priority, u_int8_t cfi, u_int16_t vlan_id, u_int16_t len_proto, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.1x extended authentication protocol header. + * @param eap_ver the EAP version + * @param eap_type the EAP type + * @param length frame length + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_1x(u_int8_t eap_ver, u_int8_t eap_type, u_int16_t length, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.2 LLC header. + * @param dsap destination service access point + * @param ssap source service access point + * @param control control field + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_2(u_int8_t dsap, u_int8_t ssap, u_int8_t control, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.2 LLC SNAP header. + * @param dsap destination service access point + * @param ssap source service access point + * @param control control field + * @param oui Organizationally Unique Identifier + * @param type upper layer protocol + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_2snap(u_int8_t dsap, u_int8_t ssap, u_int8_t control, +u_int8_t *oui, u_int16_t type, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.3 header. The 802.3 header is almost identical to the + * RFC 894 Ethernet II header, the exception being that the field immediately + * following the source address holds the frame's length (as opposed to the + * layer 3 protocol). You should only use this function when libnet is + * initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param src source ethernet address + * @param len frame length sans header + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_3(u_int8_t *dst, u_int8_t *src, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an Ethernet header. The RFC 894 Ethernet II header is almost + * identical to the IEEE 802.3 header, with the exception that the field + * immediately following the source address holds the layer 3 protocol (as + * opposed to frame's length). You should only use this function when + * libnet is initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param src source ethernet address + * @param type upper layer protocol type + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Autobuilds an Ethernet header. The RFC 894 Ethernet II header is almost + * identical to the IEEE 802.3 header, with the exception that the field + * immediately following the source address holds the layer 3 protocol (as + * opposed to frame's length). You should only use this function when + * libnet is initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param type upper layer protocol type + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t type, libnet_t *l); + +/** + * @param fc class format and priority + * @oaram dst destination fddi address + * @oaram src source fddi address + * @param dsap destination service access point + * @param ssap source service access point + * @param cf cf + * @param org IEEE organizational code + * @param type upper layer protocol + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t *src, u_int8_t dsap, +u_int8_t ssap, u_int8_t cf, u_int8_t *org, u_int16_t type, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t dsap, u_int8_t ssap, +u_int8_t cf, u_int8_t *org, u_int16_t type, libnet_t *l); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_arp(u_int16_t hrd, u_int16_t pro, u_int8_t hln, u_int8_t pln, +u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, u_int8_t *tpa, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_arp(u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, +u_int8_t *tpa, libnet_t *l); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, +u_int8_t control, u_int16_t win, u_int16_t sum, u_int16_t urg, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_tcp_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_udp(u_int16_t sp, u_int16_t dp, u_int16_t len, u_int16_t sum, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_cdp(u_int8_t version, u_int8_t ttl, u_int16_t sum, u_int16_t type, +u_int16_t len, u_int8_t *value, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_mask(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, u_int32_t mask, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_unreach(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, u_int16_t orig_frag, +u_int8_t orig_ttl, u_int8_t orig_prot, u_int16_t orig_check, +u_int32_t orig_src, u_int32_t orig_dst, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_redirect(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int32_t gateway, u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, +u_int16_t orig_frag, u_int8_t orig_ttl, u_int8_t orig_prot, +u_int16_t orig_check, u_int32_t orig_src, u_int32_t orig_dst, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_timeexceed(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, u_int16_t orig_frag, +u_int8_t orig_ttl, u_int8_t orig_prot, u_int16_t orig_check, +u_int32_t orig_src, u_int32_t orig_dst, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_timestamp(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, n_time otime, n_time rtime, n_time ttime, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_igmp(u_int8_t type, u_int8_t code, u_int16_t sum, u_int32_t ip, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag, +u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, +libnet_t *l); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh, +u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag, +u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype, +u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst, +libnet_t *l); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_isl(u_int8_t *dhost, u_int8_t type, u_int8_t user, u_int8_t *shost, +u_int16_t len, u_int8_t *snap, u_int16_t vid, u_int16_t index, +u_int16_t reserved, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_esp_hdr(u_int32_t spi, u_int32_t seq, u_int32_t iv, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_esp_ftr(u_int8_t len, u_int8_t nxt_hdr, int8_t *auth, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_ah(u_int8_t nxt_hdr, u_int8_t len, u_int16_t res, +u_int32_t spi, u_int32_t seq, u_int32_t auth, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_dnsv4(u_int16_t h_len, u_int16_t id, u_int16_t flags, +u_int16_t num_q, u_int16_t num_anws_rr, u_int16_t num_auth_rr, +u_int16_t num_addi_rr, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_rip(u_int8_t cmd, u_int8_t version, u_int16_t rd, u_int16_t af, +u_int16_t rt, u_int32_t addr, u_int32_t mask, u_int32_t next_hop, +u_int32_t metric, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_rpc_call(u_int32_t rm, u_int32_t xid, u_int32_t prog_num, +u_int32_t prog_vers, u_int32_t procedure, u_int32_t cflavor, u_int32_t clength, +u_int8_t *cdata, u_int32_t vflavor, u_int32_t vlength, u_int8_t *vdata, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_stp_conf(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, +u_int8_t flags, u_int8_t *root_id, u_int32_t root_pc, u_int8_t *bridge_id, +u_int16_t port_id, u_int16_t message_age, u_int16_t max_age, +u_int16_t hello_time, u_int16_t f_delay, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_stp_tcn(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, u_int8_t *src, +u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *org, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, +u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *org, u_int16_t type, +libnet_t *l); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_vrrp(u_int8_t version, u_int8_t type, u_int8_t vrouter_id, +u_int8_t priority, u_int8_t ip_count, u_int8_t auth_type, u_int8_t advert_int, +u_int16_t sum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_mpls(u_int32_t label, u_int8_t experimental, u_int8_t bos, +u_int8_t ttl, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ntp(u_int8_t leap_indicator, u_int8_t version, u_int8_t mode, +u_int8_t stratum, u_int8_t poll, u_int8_t precision, u_int16_t delay_int, +u_int16_t delay_frac, u_int16_t dispersion_int, u_int16_t dispersion_frac, +u_int32_t reference_id, u_int32_t ref_ts_int, u_int32_t ref_ts_frac, +u_int32_t orig_ts_int, u_int32_t orig_ts_frac, u_int32_t rec_ts_int, +u_int32_t rec_ts_frac, u_int32_t xmt_ts_int, u_int32_t xmt_ts_frac, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2(u_int16_t len, u_int8_t type, u_int32_t rtr_id, +u_int32_t area_id, u_int16_t sum, u_int16_t autype, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_hello(u_int32_t netmask, u_int16_t interval, u_int8_t opts, +u_int8_t priority, u_int dead_int, u_int32_t des_rtr, u_int32_t bkup_rtr, +u_int32_t neighbor, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_dbd(u_int16_t dgram_len, u_int8_t opts, u_int8_t type, +u_int seqnum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsr(u_int type, u_int lsid, u_int32_t advrtr, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsu(u_int num, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa(u_int16_t age, u_int8_t opts, u_int8_t type, +u_int lsid, u_int32_t advrtr, u_int seqnum, u_int16_t sum, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_rtr(u_int16_t flags, u_int16_t num, u_int id, +u_int data, u_int8_t type, u_int8_t tos, u_int16_t metric, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_net(u_int32_t nmask, u_int rtrid, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_sum(u_int32_t nmask, u_int metric, u_int tos, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_as(u_int32_t nmask, u_int metric, u_int32_t fwdaddr, +u_int tag, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_data(u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_dhcpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, +u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, +u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, +u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bootpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, +u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, +u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, +u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +inline u_int32_t libnet_gre_length(u_int16_t fv); + +#define libnet_egre_length libnet_gre_length + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre(u_int16_t fv, u_int16_t type, u_int16_t checksum, +u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +#define libnet_build_egre libnet_build_gre + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre_sre(u_int16_t af, u_int8_t offset, u_int8_t length, +u_int8_t *routing, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_MARKER_SIZE], +u_int16_t len, u_int8_t type, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_open(u_int8_t version, u_int16_t src_as, u_int16_t hold_time, +u_int32_t bgp_id, u_int8_t opt_len, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, u_int8_t *withdrawn_rt, +u_int16_t total_path_attr_len, u_int8_t *path_attributes, u_int16_t info_len, +u_int8_t *reachability_info, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_notification(u_int8_t err_code, u_int8_t err_subcode, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_link(u_int8_t *dst, u_int8_t *src, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_link(u_int8_t *dst, u_int16_t type, libnet_t *l); + +int +libnet_write(libnet_t *l); + +int +libnet_write_raw_ipv4(libnet_t *l, u_int8_t *packet, u_int32_t size); + +int +libnet_write_raw_ipv6(libnet_t *l, u_int8_t *packet, u_int32_t size); + +int +libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size); + +#if ((__WIN32__) && !(__CYGWIN__)) +SOCKET +libnet_open_raw4(libnet_t *l); +#else +int +libnet_open_raw4(libnet_t *l); +#endif + +int +libnet_close_raw4(libnet_t *l); + +int +libnet_open_raw6(libnet_t *l); + +int +libnet_close_raw6(libnet_t *l); + +int +libnet_select_device(libnet_t *l); + +int +libnet_open_link(libnet_t *l); + +int +libnet_close_link(libnet_t *l); + +u_int32_t +libnet_get_ipaddr4(libnet_t *l); + +struct libnet_in6_addr +libnet_get_ipaddr6(libnet_t *l); + +struct libnet_ether_addr * +libnet_get_hwaddr(libnet_t *l); + +int +libnet_do_checksum(libnet_t *l, u_int8_t *packet, int protocol, int len); + +u_int32_t +libnet_compute_crc(u_int8_t *buf, u_int32_t len); + +u_int16_t +libnet_ip_check(u_int16_t *addr, int len); + +int +libnet_in_cksum(u_int16_t *addr, int len); + + +/* + * libnet_pblock_probe + * + * If ptag is 0, function will create a pblock for the protocol unit type, + * append it to the list and return a pointer to it. If ptag is not 0, + * function will search the pblock list for the specified protocol block + * and return a pointer to it. + */ +libnet_pblock_t * +libnet_pblock_probe(libnet_t *l, libnet_ptag_t ptag, u_int32_t n, +u_int8_t type); + +/* + * libnet_pblock_new + * + * Function creates the pblock list if l->protocol_blocks == NULL or appends + * an entry to the doubly linked list. + */ +libnet_pblock_t * +libnet_pblock_new(libnet_t *l, u_int32_t size); + + +/* + * libnet_pblock_swap + * + * Function swaps two pblocks in memory. + */ +int +libnet_pblock_swap(libnet_t *l, libnet_ptag_t ptag1, libnet_ptag_t ptag2); + + +/* + * libnet_pblock_insert_before + * + * Function inserts a pblock into the doubly linked list. + */ +int +libnet_pblock_insert_before(libnet_t *l, libnet_ptag_t ptag1, +libnet_ptag_t ptag2); + +/* + * libnet_pblock_delete + * + * Function removes a pblock from context + */ +void +libnet_pblock_delete(libnet_t *l, libnet_pblock_t *p); + +/* + * libnet_pblock_update + * + * Function updates the pblock meta-inforation. Internally it updates the + * ptag with a monotonically increasing variable kept in l. This way each + * pblock has a succesively increasing ptag identifier. + */ +libnet_ptag_t +libnet_pblock_update(libnet_t *l, libnet_pblock_t *p, u_int32_t h, +u_int8_t type); + + +/* + * libnet_pblock_find + * + * Function locates a given block by it's ptag. + */ +libnet_pblock_t * +libnet_pblock_find(libnet_t *l, libnet_ptag_t ptag); + + +/* + * libnet_pblock_append + * + * Function copies protocol block data over. + */ +int +libnet_pblock_append(libnet_t *l, libnet_pblock_t *p, u_int8_t *buf, +u_int32_t len); + + +/* + * libnet_pblock_setflags + * + * Function sets pblock flags. + */ +void +libnet_pblock_setflags(libnet_pblock_t *p, u_int8_t flags); + + +/* + * libnet_pblock_p2p + * + * Function returns the protocol number for the protocol block type. If + * the type is unknown, the function defaults to returning IPPROTO_IP. + */ +int +libnet_pblock_p2p(u_int8_t type); + + +/* + * libnet_pblock_coalesce + * + * Function assembles the packet for subsequent writing. Function makes two + * passes through the pblock list: + * 1st & 2nd) determine total size of the packet for contiguous malloc + * and copy over packet chunks + * 3rd run) run through the original list and see which protocol blocks had + * the checksum flag set (checksums usually need to be done over + * an assembled packet so it's easier to do it here) + */ +int +libnet_pblock_coalesce(libnet_t *l, u_int8_t **packet, u_int32_t *size); + + +/* + * __libnet_dump_context + * + * Function returns the contents of the libnet file context. Not meant for + * the applications programer. + */ +void +__libnet_dump_context(libnet_t *l); + +/* + * __libnet_dump_pblock + * + * Function returns the contents of each pblock in a given context. Not meant + * for the applications programer. + */ +void +__libnet_dump_pblock(libnet_t *l); + +/* + * __libnet_dump_pblock_type + * + * Function returns a canonical string referring to the pblock type. + */ +int8_t * +__libnet_dump_pblock_type(u_int8_t type); + +/* + * __libnet_hex_dump + * + * Function dumps the contents of the supplied buffer to the supplied + * stream pointer. Very useful for debugging. Will swap endianness based + * disposition of mode variable. Use requires unwrapping the libnet file + * context structure so it's hidden down here. If you find it, consider + * yourself a trepid adventurer. + */ +void +__libnet_dump_hex(u_int8_t *packet, u_int32_t len, int swap, FILE *stream); + + +/* + * libnet_hex_aton + * + * hexidecimal strings of the format "##:##:##:## ... :##:##" to a uint8_t. + * + */ +u_int8_t * +libnet_hex_aton(int8_t *s, int *len); + +/* + * libnet_adv_cull_packet + * + * advanced interface, culls the packet from inside libnet, wraps + * libnet_pblock_coalesce(). + * + */ +int +libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, u_int32_t *packet_s); + +/* + * libnet_adv_cull_header + * + * advanced interface, culls the header from referenced ptag from inside + * libnet. + * + */ +int +libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, u_int8_t **header, +u_int32_t *header_s); + +/* + * libnet_adv_write_link + * + * advanced interface, writes a prebuilt frame to the wire + * + */ +int +libnet_adv_write_link(libnet_t *l, u_int8_t *packet, u_int32_t packet_s); + +/* + * libnet_cq_add + * + * Function adds a context to the libnet context queue. + */ +int +libnet_cq_add(libnet_t *l, char *label); + +/* + * libnet_cq_remove + * + * Function removes a context from the libnet context queue. + * + */ +libnet_t * +libnet_cq_remove(libnet_t *l); + +/* + * libnet_cq_remove_by_label + * + * Function removes a libnet context from the queue, indexed by it's + * canonical label. + */ +libnet_t * +libnet_cq_remove_by_label(char *label); + +/* + * libnet_cq_getlabel + * + * Function returns the label (if any) associated with the context. + */ +int8_t * +libnet_cq_getlabel(libnet_t *l); + +/* + * libnet_cq_find_by_label + * + * Function locates a libnet context from the queue, indexed by it's + * canonical label. + * + */ +libnet_t * +libnet_cq_find_by_label(char *label); + +/* + * libnet_cq_destroy + * + * Function destroys the entire context queue, calling libnet_destory() on + * each member context. + */ +void libnet_cq_destroy(); + +/* + * libnet_cq_head + * + * Function intiailizes the interator interface and sets a write lock on + * the context queue. + */ +libnet_t * +libnet_cq_head(); + +/* + * libnet_cq_head + * + * Function returns 1 if at the end of the context queue, 0 otherwise. + */ +int +libnet_cq_last(); + +/* + * libnet_cq_head + * + * Function returns the next context from the context queue. + */ +libnet_t * +libnet_cq_next(); + +/* + * libnet_cq_size + * + * Function returns the number of entries in the context queue. + */ +u_int32_t +libnet_cq_size(); + +/* + * libnet_check_iface + * + * By testing if we can retrieve the FLAGS of an iface + * we can know if it exists or not and if it is up. + */ +int +libnet_check_iface(libnet_t *l); + + +#if defined(__WIN32__) +BYTE * +libnet_win32_get_remote_mac(libnet_t *l, DWORD IP); +int +libnet_close_link_interface(libnet_t *l); +BYTE * +libnet_win32_read_arp_table(DWORD IP); +#endif +#endif /* __LIBNET_FUNCTIONS_H */ + +/* EOF */ diff --git a/libnet/include/libnet/CVS/Entries b/libnet/include/libnet/CVS/Entries new file mode 100644 index 0000000..c7a7da3 --- /dev/null +++ b/libnet/include/libnet/CVS/Entries @@ -0,0 +1,9 @@ +/Makefile.am/1.2/Sat Oct 18 17:20:03 2003// +/libnet-types.h/1.3/Sat Jan 3 20:31:00 2004// +/libnet-asn1.h/1.3/Sat Jan 17 07:51:19 2004// +/libnet-macros.h/1.6/Mon Mar 1 20:26:12 2004// +/Makefile.in/1.14/Thu Mar 11 18:50:20 2004// +/libnet-headers.h/1.14/Thu Mar 11 18:50:20 2004// +/libnet-structures.h/1.18/Tue Mar 16 18:40:58 2004// +/libnet-functions.h/1.42/Thu Mar 25 18:50:48 2004// +D diff --git a/libnet/include/libnet/CVS/Repository b/libnet/include/libnet/CVS/Repository new file mode 100644 index 0000000..928f449 --- /dev/null +++ b/libnet/include/libnet/CVS/Repository @@ -0,0 +1 @@ +/usr/local/CVS/libnet/include/libnet diff --git a/libnet/include/libnet/CVS/Root b/libnet/include/libnet/CVS/Root new file mode 100644 index 0000000..52fa133 --- /dev/null +++ b/libnet/include/libnet/CVS/Root @@ -0,0 +1 @@ +mike@66.234.207.232:/usr/local/CVS diff --git a/libnet/include/libnet/Makefile.am b/libnet/include/libnet/Makefile.am new file mode 100644 index 0000000..ef43b53 --- /dev/null +++ b/libnet/include/libnet/Makefile.am @@ -0,0 +1,12 @@ +# $Id: Makefile.am,v 1.2 2003/10/18 17:20:03 mike Exp $ + +include $(top_srcdir)/Makefile.am.common + +libnetincludedir = $(includedir)/libnet + +libnetinclude_HEADERS = libnet-asn1.h \ + libnet-functions.h \ + libnet-headers.h \ + libnet-macros.h \ + libnet-structures.h \ + libnet-types.h diff --git a/libnet/include/libnet/Makefile.in b/libnet/include/libnet/Makefile.in new file mode 100644 index 0000000..7be8368 --- /dev/null +++ b/libnet/include/libnet/Makefile.in @@ -0,0 +1,294 @@ +# Makefile.in generated by automake 1.6.3 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# 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@ + +# $Id: Makefile.in,v 1.14 2004/03/11 18:50:20 mike Exp $ + +# $Id: Makefile.in,v 1.14 2004/03/11 18:50:20 mike Exp $ +# +# Libnet automake information file +# Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> +# All rights reserved. +# +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_alias = @build_alias@ +build_triplet = @build@ +host_alias = @host_alias@ +host_triplet = @host@ +target_alias = @target_alias@ +target_triplet = @target@ + +EXEEXT = @EXEEXT@ +OBJEXT = @OBJEXT@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +ADDITIONAL_LIBS = @ADDITIONAL_LIBS@ +AMTAR = @AMTAR@ +AWK = @AWK@ +CC = @CC@ +DEPDIR = @DEPDIR@ +ENDIANESS = @ENDIANESS@ +HAVE_PACKET_SOCKET = @HAVE_PACKET_SOCKET@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBNET_CONFIG_CFLAGS = @LIBNET_CONFIG_CFLAGS@ +LIBNET_CONFIG_DEFINES = @LIBNET_CONFIG_DEFINES@ +LIBNET_CONFIG_LIBS = @LIBNET_CONFIG_LIBS@ +LIBNET_VERSION = @LIBNET_VERSION@ +MAINT = @MAINT@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +VERSION = @VERSION@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ + +AUTOMAKE_OPTIONS = foreign no-dependencies + +DISTCLEANFILES = *~ + +libnetincludedir = $(includedir)/libnet + +libnetinclude_HEADERS = libnet-asn1.h \ + libnet-functions.h \ + libnet-headers.h \ + libnet-macros.h \ + libnet-structures.h \ + libnet-types.h + +subdir = include/libnet +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +depcomp = +am__depfiles_maybe = +DIST_SOURCES = +HEADERS = $(libnetinclude_HEADERS) + +DIST_COMMON = $(libnetinclude_HEADERS) Makefile.am Makefile.in +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/Makefile.am.common $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign include/libnet/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +uninstall-info-am: +libnetincludeHEADERS_INSTALL = $(INSTALL_HEADER) +install-libnetincludeHEADERS: $(libnetinclude_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libnetincludedir) + @list='$(libnetinclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(libnetincludeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(libnetincludedir)/$$f"; \ + $(libnetincludeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(libnetincludedir)/$$f; \ + done + +uninstall-libnetincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libnetinclude_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(libnetincludedir)/$$f"; \ + rm -f $(DESTDIR)$(libnetincludedir)/$$f; \ + done + +ETAGS = etags +ETAGSFLAGS = + +tags: TAGS + +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: $(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 "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_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 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = ../.. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @list='$(DISTFILES)'; for file in $$list; do \ + 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"; \ + $(mkinstalldirs) "$(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: + $(mkinstalldirs) $(DESTDIR)$(libnetincludedir) + +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_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(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 mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: install-libnetincludeHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +uninstall-am: uninstall-info-am uninstall-libnetincludeHEADERS + +.PHONY: GTAGS all all-am check check-am clean clean-generic distclean \ + distclean-generic distclean-tags distdir dvi dvi-am info \ + info-am install install-am install-data install-data-am \ + install-exec install-exec-am install-info install-info-am \ + install-libnetincludeHEADERS install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic tags \ + uninstall uninstall-am uninstall-info-am \ + uninstall-libnetincludeHEADERS + +# 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: diff --git a/libnet/include/libnet/libnet-asn1.h b/libnet/include/libnet/libnet-asn1.h new file mode 100644 index 0000000..ea27356 --- /dev/null +++ b/libnet/include/libnet/libnet-asn1.h @@ -0,0 +1,255 @@ +/* + * $Id: libnet-asn1.h,v 1.3 2004/01/17 07:51:19 mike Exp $ + * + * libnet-asn1.h - Network routine library ASN.1 header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> + * All rights reserved. + * + * Definitions for Abstract Syntax Notation One, ASN.1 + * As defined in ISO/IS 8824 and ISO/IS 8825 + * + * Copyright 1988, 1989 by Carnegie Mellon University + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of CMU not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + * + * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __LIBNET_ASN1_H +#define __LIBNET_ASN1_H + +#ifndef EIGHTBIT_SUBIDS +typedef u_int32_t oid; +#define MAX_SUBID 0xFFFFFFFF +#else +typedef u_int8_t oid; +#define MAX_SUBID 0xFF +#endif + +#define MAX_OID_LEN 64 /* max subid's in an oid */ + +#define ASN_BOOLEAN (0x01) +#define ASN_INTEGER (0x02) +#define ASN_BIT_STR (0x03) +#define ASN_OCTET_STR (0x04) +#define ASN_NULL (0x05) +#define ASN_OBJECT_ID (0x06) +#define ASN_SEQUENCE (0x10) +#define ASN_SET (0x11) + +#define ASN_UNIVERSAL (0x00) +#define ASN_APPLICATION (0x40) +#define ASN_CONTEXT (0x80) +#define ASN_PRIVATE (0xC0) + +#define ASN_PRIMITIVE (0x00) +#define ASN_CONSTRUCTOR (0x20) + +#define ASN_LONG_LEN (0x80) +#define ASN_EXTENSION_ID (0x1F) +#define ASN_BIT8 (0x80) + +#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR) +#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID) + +/* + * All of the build_asn1_* (build_asn1_length being an exception) functions + * take the same first 3 arguments: + * + * u_int8_t *data: This is a pointer to the start of the data object to be + * manipulated. + * int *datalen: This is a pointer to the number of valid bytes following + * "data". This should be not be exceeded in any function. + * Upon exiting a function, this value will reflect the + * changed "data" and then refer to the new number of valid + * bytes until the end of "data". + * u_int8_t type: The ASN.1 object type. + */ + + +/* + * Builds an ASN object containing an integer. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_int( + u_int8_t *, /* Pointer to the output buffer */ + int *, /* Number of valid bytes left in the buffer */ + u_int8_t, /* ASN object type */ + int32_t *, /* Pointer to a int32_t integer */ + int /* Size of a int32_t integer */ + ); + + +/* + * Builds an ASN object containing an unsigned integer. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_uint( + u_int8_t *, /* Pointer to the output buffer */ + int *, /* Number of valid bytes left in the buffer */ + u_int8_t, /* ASN object type */ + u_int32_t *, /* Pointer to an unsigned int32_t integer */ + int /* Size of a int32_t integer */ + ); + + +/* + * Builds an ASN object containing an octect string. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_string( + u_int8_t *, /* Pointer to the output buffer */ + int *, /* Number of valid bytes left in the buffer */ + u_int8_t, /* ASN object type */ + u_int8_t *, /* Pointer to a string to be built into an object */ + int /* Size of the string */ + ); + + +/* + * Builds an ASN header for an object with the ID and length specified. This + * only works on data types < 30, i.e. no extension octets. The maximum + * length is 0xFFFF; + * + * Returns a pointer to the first byte of the contents of this object or + * NULL upon error + */ + +u_int8_t * +libnet_build_asn1_header( + u_int8_t *, /* Pointer to the start of the object */ + int *, /* Number of valid bytes left in buffer */ + u_int8_t, /* ASN object type */ + int /* ASN object length */ + ); + + +u_int8_t * +libnet_build_asn1_length( + u_int8_t *, /* Pointer to start of object */ + int *, /* Number of valid bytes in buffer */ + int /* Length of object */ + ); + + +/* + * Builds an ASN header for a sequence with the ID and length specified. + * + * This only works on data types < 30, i.e. no extension octets. + * The maximum length is 0xFFFF; + * + * Returns a pointer to the first byte of the contents of this object. + * Returns NULL on any error. + */ + +u_int8_t * +libnet_build_asn1_sequence( + u_int8_t *, + int *, + u_int8_t, + int + ); + + +/* + * Builds an ASN object identifier object containing the input string. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_objid( + u_int8_t *, + int *, + u_int8_t, + oid *, + int + ); + + +/* + * Builds an ASN null object. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_null( + u_int8_t *, + int *, + u_int8_t + ); + + +/* + * Builds an ASN bitstring. + * + * Returns NULL upon error or a pointer to the first byte past the end of + * this object (the start of the next object). + */ + +u_int8_t * +libnet_build_asn1_bitstring( + u_int8_t *, + int *, + u_int8_t, + u_int8_t *, /* Pointer to the input buffer */ + int /* Length of the input buffer */ + ); + + +#endif /* __LIBNET_ASN1_H */ + +/* EOF */ diff --git a/libnet/include/libnet/libnet-functions.h b/libnet/include/libnet/libnet-functions.h new file mode 100644 index 0000000..3c5b18c --- /dev/null +++ b/libnet/include/libnet/libnet-functions.h @@ -0,0 +1,2151 @@ +/* + * $Id: libnet-functions.h,v 1.42 2004/03/25 18:50:48 mike Exp $ + * + * libnet-functions.h - function prototypes + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_FUNCTIONS_H +#define __LIBNET_FUNCTIONS_H +/** + * @file libnet-functions.h + * @brief libnet exported function prototypes + */ + +/** + * Creates the libnet environment. It initializes the library and returns a + * libnet context. If the injection_type is LIBNET_LINK or LIBNET_LINK_ADV, the + * function initializes the injection primitives for the link-layer interface + * enabling the application programmer to build packets starting at the + * data-link layer (which also provides more granular control over the IP + * layer). If libnet uses the link-layer and the device argument is non-NULL, + * the function attempts to use the specified network device for packet + * injection. This is either a canonical string that references the device + * (such as "eth0" for a 100MB Ethernet card on Linux or "fxp0" for a 100MB + * Ethernet card on OpenBSD) or the dots and decimals representation of the + * device's IP address (192.168.0.1). If device is NULL, libnet attempts to + * find a suitable device to use. If the injection_type is LIBNET_RAW4 or + * LIBNET_RAW4_ADV, the function initializes the injection primitives for the + * IPv4 raw socket interface. The final argument, err_buf, should be a buffer + * of size LIBNET_ERRBUF_SIZE and holds an error message if the function fails. + * This function requires root privileges to execute successfully. Upon + * success, the function returns a valid libnet context for use in later + * function calls; upon failure, the function returns NULL. + * @param injection_type packet injection type (LIBNET_LINK, LIBNET_LINK_ADV, LIBNET_RAW4, LIBNET_RAW4_ADV, LIBNET_RAW6, LIBNET_RAW6_ADV) + * @param device the interface to use (NULL and libnet will choose one) + * @param err_buf will contain an error message on failure + * @return libnet context ready for use or NULL on error. + */ +libnet_t * +libnet_init(int injection_type, char *device, char *err_buf); + +/** + * Shuts down the libnet session referenced by l. It closes the network + * interface and frees all internal memory structures associated with l. + * @param l pointer to a libnet context + */ +void +libnet_destroy(libnet_t *l); + +/** + * Clears the current packet referenced and frees all pblocks. Should be + * called when the programmer want to send a completely new packet of + * a different type using the same context. + * @param l pointer to a libnet context + */ +void +libnet_clear_packet(libnet_t *l); + +/** + * Fills in a libnet_stats structure with packet injection statistics + * (packets written, bytes written, packet sending errors). + * @param l pointer to a libnet context + * @param ls pointer to a libnet statistics structure + */ +void +libnet_stats(libnet_t *l, struct libnet_stats *ls); + +/** + * Returns the FILENO of the file descriptor used for packet injection. + * @param l pointer to a libnet context + * @return the file number of the file descriptor used for packet injection + */ +int +libnet_getfd(libnet_t *l); + +/** + * Returns the canonical name of the device used for packet injection. + * @param l pointer to a libnet context + * @return the canonical name of the device used for packet injection. Note + * it can be NULL without being an error. + */ +int8_t * +libnet_getdevice(libnet_t *l); + +/** + * Returns the pblock buffer contents for the specified ptag; a + * subsequent call to libnet_getpbuf_size() should be made to determine the + * size of the buffer. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @return a pointer to the pblock buffer or NULL on error + */ +u_int8_t * +libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag); + +/** + * Returns the pblock buffer size for the specified ptag; a + * previous call to libnet_getpbuf() should be made to pull the actual buffer + * contents. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @return the size of the pblock buffer + */ +u_int32_t +libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag); + +/** + * Returns the last error set inside of the referenced libnet context. This + * function should be called anytime a function fails or an error condition + * is detected inside of libnet. + * @param l pointer to a libnet context + * @return an error string or NULL if no error has occured + */ +char * +libnet_geterror(libnet_t *l); + +/** + * Returns the sum of the size of all of the pblocks inside of l (this should + * be the resuling packet size). + * @param l pointer to a libnet context + * @return the size of the packet in l + */ +u_int32_t +libnet_getpacket_size(libnet_t *l); + +/** + * Seeds the psuedo-random number generator. + * @param l pointer to a libnet context + * @return 1 on success, -1 on failure + */ +int +libnet_seed_prand(libnet_t *l); + +/** + * Generates an unsigned psuedo-random value within the range specified by + * mod. + * LIBNET_PR2 0 - 1 + * LIBNET_PR8 0 - 255 + * LIBNET_PR16 0 - 32767 + * LIBNET_PRu16 0 - 65535 + * LIBNET_PR32 0 - 2147483647 + * LIBNET_PRu32 0 - 4294967295 + * + * @param mod one the of LIBNET_PR* constants + * @return 1 on success, -1 on failure + */ +u_int32_t +libnet_get_prand(int mod); + +/** + * If a given protocol header is built with the checksum field set to "0", by + * default libnet will calculate the header checksum prior to injection. If the + * header is set to any other value, by default libnet will not calculate the + * header checksum. To over-ride this behavior, use libnet_toggle_checksum(). + * Switches auto-checksumming on or off for the specified ptag. If mode is set + * to LIBNET_ON, libnet will mark the specificed ptag to calculate a checksum + * for the ptag prior to injection. This assumes that the ptag refers to a + * protocol that has a checksum field. If mode is set to LIBNET_OFF, libnet + * will clear the checksum flag and no checksum will be computed prior to + * injection. This assumes that the programmer will assign a value (zero or + * otherwise) to the checksum field. Often times this is useful if a + * precomputed checksum or some other predefined value is going to be used. + * Note that when libnet is initialized with LIBNET_RAW4, the IPv4 header + * checksum will always be computed by the kernel prior to injection, + * regardless of what the programmer sets. + * @param l pointer to a libnet context + * @param ptag the ptag reference number + * @param mode LIBNET_ON or LIBNET_OFF + * @return 1 on success, -1 on failure + */ +int +libnet_toggle_checksum(libnet_t *l, libnet_ptag_t ptag, int mode); + +/** + * Takes a network byte ordered IPv4 address and returns a pointer to either a + * canonical DNS name (if it has one) or a string of dotted decimals. This may + * incur a DNS lookup if the hostname and mode is set to LIBNET_RESOLVE. If + * mode is set to LIBNET_DONT_RESOLVE, no DNS lookup will be performed and + * the function will return a pointer to a dotted decimal string. The function + * cannot fail -- if no canonical name exists, it will fall back on returning + * a dotted decimal string. This function is non-reentrant. + * @param in network byte ordered IPv4 address + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return a pointer to presentation format string + */ +char * +libnet_addr2name4(u_int32_t in, u_int8_t use_name); + +/** + * Takes a dotted decimal string or a canonical DNS name and returns a + * network byte ordered IPv4 address. This may incur a DNS lookup if mode is + * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode + * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can + * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and + * host_name refers to a canonical DNS name. + * @param l pointer to a libnet context + * @param host_name pointer to a string containing a presentation format host + * name + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return network byte ordered IPv4 address or -1 (2^32 - 1) on error + */ +u_int32_t +libnet_name2addr4(libnet_t *l, char *host_name, u_int8_t use_name); + +extern const struct libnet_in6_addr in6addr_error; + +/** + * Takes a dotted decimal string or a canonical DNS name and returns a + * network byte ordered IPv6 address. This may incur a DNS lookup if mode is + * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode + * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can + * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and + * host_name refers to a canonical DNS name. + * @param l pointer to a libnet context + * @param host_name pointer to a string containing a presentation format host + * name + * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE + * @return network byte ordered IPv6 address structure + */ +struct libnet_in6_addr +libnet_name2addr6(libnet_t *l, char *host_name, u_int8_t use_name); + +/** + * Should document this baby right here. + */ +void +libnet_addr2name6_r(struct libnet_in6_addr addr, u_int8_t use_name, +char *host_name, int host_name_len); + +/** + * Creates a new port list. Port list chains are useful for TCP and UDP-based + * applications that need to send packets to a range of ports (contiguous or + * otherwise). The port list chain, which token_list points to, should contain + * a series of int8_tacters from the following list: "0123456789,-" of the + * general format "x - y, z", where "xyz" are port numbers between 0 and + * 65,535. plist points to the front of the port list chain list for use in + * further libnet_plist_chain() functions. Upon success, the function returns + * 1. Upon failure, the function returns -1 and libnet_geterror() can tell you + * why. + * @param l pointer to a libnet context + * @param plist if successful, will refer to the portlist, if not, NULL + * @param token_list string containing the port list primitive + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list); + +/** + * Returns the next port list chain pair from the port list chain plist. bport + * and eport contain the starting port number and ending port number, + * respectively. Upon success, the function returns 1 and fills in the port + * variables; however, if the list is empty, the function returns 0 and sets + * both port variables to 0. Upon failure, the function returns -1. + * @param plist previously created portlist + * @param bport will contain the beginning port number or 0 + * @param eport will contain the ending port number or 0 + * @return 1 on success, 0 if empty, -1 on failure + */ +int +libnet_plist_chain_next_pair(libnet_plist_t *plist, u_int16_t *bport, +u_int16_t *eport); + +/** + * Runs through the port list and prints the contents of the port list chain + * list to stdout. + * @param plist previously created portlist + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_dump(libnet_plist_t *plist); + +/** + * Runs through the port list and prints the contents of the port list chain + * list to string. This function uses strdup and is not re-entrant. It also + * has a memory leak and should not really be used. + * @param plist previously created portlist + * @return a printable string containing the port list contents on success + * NULL on error + */ +char * +libnet_plist_chain_dump_string(libnet_plist_t *plist); + +/** + * Frees all memory associated with port list chain. + * @param plist previously created portlist + * @return 1 on success, -1 on failure + */ +int +libnet_plist_chain_free(libnet_plist_t *plist); + +/** + * @section PBF Packet Builder Functions + * + * The core of libnet is the platform-independent packet-building + * functionality. These functions enable an application programmer to build + * protocol headers (and data) in a simple and consistent manner without having + * to worry (too much) about low-level network odds and ends. Each + * libnet_build() function builds a piece of a packet (generally a protocol + * header). While it is perfectly possible to build an entire, + * ready-to-transmit packet with a single call to a libnet_build() function, + * generally more than one builder-class function call is required to construct + * a full packet. A complete wire-ready packet generally consists of more than + * one piece. + * Every function that builds a protocol header takes a series of arguments + * roughly corresponding to the header values as they appear on the wire. This + * process is intuitive but often makes for functions with huge prototypes and + * large stack frames. + * One important thing to note is that you must call these functions in order, + * corresponding to how they should appear on the wire (from the highest + * protocol layer on down). This building process is intuitive; it approximates + * what happens in an operating system kernel. In other words, to build a + * Network Time Protocol (NTP) packet by using the link-layer interface, the + * application programmer would call the libnet_build() functions in the + * following order: + * 1. libnet_build_ntp() + * 2. libnet_build_udp() + * 3. libnet_build_ipv4() + * 4. libnet_build_ethernet() + * This ordering is essential for libnet 1.1.x to properly link together the + * packet internally (previous libnet versions did not have the requirement). + * + * @subsection TPI The Payload Interface + * + * The payload interface specifies an optional way to include data directly + * after the protocol header in question. You can use this function for a + * variety of purposes, including the following: + * - Including additional or arbitrary protocol header information that is not + * available from a libnet interface + * - Including a packet payload (data segment) + * - Building another protocol header that is not available from a libnet + * interface + * To employ the interface, the application programmer should construct the i + * payload data and pass a u_int8_t * to this data and its size to the desired + * libnet_build() function. Libnet handles the rest. + * + * It is important to note that some functions (notably the IPv6 builders) do + * use the payload interface to specify variable length but ostensibly + * non-optional data. See the individual libnet_build_ipv6*() functions for + * more information. + * + * @subsection PT Protocol Tags and Packet Builder Return Values + * + * Libnet uses the protocol tag (ptag) to identify individual pieces of a + * packet after being created. A new ptag results every time a libnet_build() + * function with an empty (0) ptag argument completes successfully. This new + * ptag now refers to the packet piece just created. The application + * programmer's responsibility is to save this value if he or she plans to + * modify this particular portion later on in the program. If the application + * programmer needs to modify some portion of that particular packet piece + * again, he or she calls the same libnet_build() function specifying the + * saved ptag argument. Libnet then searches for that packet piece and modifies + * it rather than creating a new one. Upon failure for any reason, + * libnet_build() functions return -1; libnet_geterror() tells you why. + */ + +/** + * Builds an IEEE 802.1q VLAN tagging header. Depending on the value of + * len_proto, the function wraps the 802.1q header inside either an IEEE 802.3 + * header or an RFC 894 Ethernet II (DIX) header (both resulting in an 18-byte + * frame). If len is 1500 or less, most receiving protocol stacks parse the + * frame as an IEEE 802.3 encapsulated frame. If len is one of the Ethernet type + * values, most protocol stacks parse the frame as an RFC 894 Ethernet II + * encapsulated frame. Note the length value is calculated without the 802.1q + * header of 18 bytes. + * @param dst pointer to a six byte source ethernet address + * @param src pointer to a six byte destination ethernet address + * @param tpi tag protocol identifier + * @param priority priority + * @param cfi canonical format indicator + * @param vlan_id vlan identifier + * @param len_proto length (802.3) protocol (Ethernet II) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_1q(u_int8_t *dst, u_int8_t *src, u_int16_t tpi, +u_int8_t priority, u_int8_t cfi, u_int16_t vlan_id, u_int16_t len_proto, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.1x extended authentication protocol header. + * @param eap_ver the EAP version + * @param eap_type the EAP type + * @param length frame length + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_1x(u_int8_t eap_ver, u_int8_t eap_type, u_int16_t length, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.2 LLC header. + * @param dsap destination service access point + * @param ssap source service access point + * @param control control field + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_2(u_int8_t dsap, u_int8_t ssap, u_int8_t control, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.2 LLC SNAP header. + * @param dsap destination service access point + * @param ssap source service access point + * @param control control field + * @param oui Organizationally Unique Identifier + * @param type upper layer protocol + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_2snap(u_int8_t dsap, u_int8_t ssap, u_int8_t control, +u_int8_t *oui, u_int16_t type, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.3 header. The 802.3 header is almost identical to the + * RFC 894 Ethernet II header, the exception being that the field immediately + * following the source address holds the frame's length (as opposed to the + * layer 3 protocol). You should only use this function when libnet is + * initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param src source ethernet address + * @param len frame length sans header + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_802_3(u_int8_t *dst, u_int8_t *src, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an Ethernet header. The RFC 894 Ethernet II header is almost + * identical to the IEEE 802.3 header, with the exception that the field + * immediately following the source address holds the layer 3 protocol (as + * opposed to frame's length). You should only use this function when + * libnet is initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param src source ethernet address + * @param type upper layer protocol type + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Autobuilds an Ethernet header. The RFC 894 Ethernet II header is almost + * identical to the IEEE 802.3 header, with the exception that the field + * immediately following the source address holds the layer 3 protocol (as + * opposed to frame's length). You should only use this function when + * libnet is initialized with the LIBNET_LINK interface. + * @param dst destination ethernet address + * @param type upper layer protocol type + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t type, libnet_t *l); + +/** + * Builds a Fiber Distributed Data Interface (FDDI) header. + * @param fc class format and priority + * @oaram dst destination fddi address + * @oaram src source fddi address + * @param dsap destination service access point + * @param ssap source service access point + * @param cf cf + * @param oui 3 byte IEEE organizational code + * @param type upper layer protocol + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t *src, u_int8_t dsap, +u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Autobuilds a Fiber Distributed Data Interface (FDDI) header. + * @param fc class format and priority + * @oaram dst destination fddi address + * @param dsap destination service access point + * @param ssap source service access point + * @param cf cf + * @param oui IEEE organizational code + * @param type upper layer protocol + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t dsap, u_int8_t ssap, +u_int8_t cf, u_int8_t *oui, u_int16_t type, libnet_t *l); + +/** + * Builds an Address Resolution Protocol (ARP) header. Depending on the op + * value, the function builds one of several different types of RFC 826 or + * RFC 903 RARP packets. + * @param hrd hardware address format + * @param pro protocol address format + * @param hln hardware address length + * @param pln protocol address length + * @param op ARP operation type + * @param sha sender's hardware address + * @param spa sender's protocol address + * @param tha target hardware address + * @param tpa targer protocol address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_arp(u_int16_t hrd, u_int16_t pro, u_int8_t hln, u_int8_t pln, +u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, u_int8_t *tpa, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Autouilds an Address Resolution Protocol (ARP) header. Depending on the op + * value, the function builds one of several different types of RFC 826 or + * RFC 903 RARP packets. + * @param op ARP operation type + * @param sha sender's hardware address + * @param spa sender's protocol address + * @param tha target hardware address + * @param tpa targer protocol address + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_arp(u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, +u_int8_t *tpa, libnet_t *l); + +/** + * Builds an RFC 793 Transmission Control Protocol (TCP) header. + * @param sp source port + * @param dp destination port + * @param seq sequence number + * @param ack acknowledgement number + * @param control control flags + * @param win window size + * @param sum checksum (0 for libnet to autofill) + * @param urg urgent pointer + * @parama len total length of the TCP packet (for checksum calculation) + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, +u_int8_t control, u_int16_t win, u_int16_t sum, u_int16_t urg, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 793 Transmission Control Protocol (TCP) options header. + * The function expects options to be a valid TCP options string of size + * options_s, which is no larger than 40 bytes (the maximum size of an + * options string). The function checks to ensure that the packet consists of + * a TCP header preceded by an IPv4 header, and that the addition of the + * options string would not result in a packet larger than 65,535 bytes + * (IPMAXPACKET). The function counts up the number of 32-bit words in the + * options string and adjusts the TCP header length value as necessary. + * @param options byte string of TCP options + * @param options_s length of options string + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_tcp_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an RFC 768 User Datagram Protocol (UDP) header. + * @param sp source port + * @param dp destination port + * @param len total length of the UDP packet + * @param sum checksum (0 for libnet to autofill) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_udp(u_int16_t sp, u_int16_t dp, u_int16_t len, u_int16_t sum, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a Cisco Discovery Protocol (CDP) header. Cisco Systems designed CDP + * to aid in the network management of adjacent Cisco devices. The CDP protocol + * specifies data by using a type/length/value (TLV) setup. The first TLV can + * specified by using the functions type, length, and value arguments. To + * specify additional TLVs, the programmer could either use the payload + * interface or libnet_build_data() to construct them. + * @param version CDP version + * @param ttl time to live (time information should be cached by recipient) + * @param sum checksum (0 for libnet to autofill) + * @param type type of data contained in value + * @param len length of value arugment + * @param value the CDP information string + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_cdp(u_int8_t version, u_int8_t ttl, u_int16_t sum, u_int16_t type, +u_int16_t len, u_int8_t *value, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) + * echo request/reply header + * @param type type of ICMP packet (should be ICMP_ECHOREPLY or ICMP_ECHO) + * @param code code of ICMP packet (should be 0) + * @param sum checksum (0 for libnet to autofill) + * @param id identification number + * @param seq packet sequence number + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) + * IP netmask request/reply header. + * @param type type of ICMP packet (should be ICMP_MASKREQ or ICMP_MASKREPLY) + * @param code code of ICMP packet (should be 0) + * @param sum checksum (0 for libnet to autofill) + * @param id identification number + * @param seq packet sequence number + * @param mask subnet mask + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_mask(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, u_int32_t mask, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) + * unreachable header. The IP header that caused the error message should be + * built by a previous call to libnet_build_ipv4(). + * @param type type of ICMP packet (should be ICMP_UNREACH) + * @param code code of ICMP packet (should be one of the 16 unreachable codes) + * @param sum checksum (0 for libnet to autofill) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_unreach(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Message Control Protocol (ICMP) + * redirect header. The IP header that caused the error message should be + * built by a previous call to libnet_build_ipv4(). + * @param type type of ICMP packet (should be ICMP_REDIRECT) + * @param code code of ICMP packet (should be one of the four redirect codes) + * @param sum checksum (0 for libnet to autofill) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_redirect(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int32_t gateway, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) time + * exceeded header. The IP header that caused the error message should be + * built by a previous call to libnet_build_ipv4(). + * @param type type of ICMP packet (should be ICMP_TIMXCEED) + * @param code code of ICMP packet (ICMP_TIMXCEED_INTRANS / ICMP_TIMXCEED_REASS) + * @param sum checksum (0 for libnet to autofill) + * @param payload optional payload or NULL + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_timeexceed(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) + * timestamp request/reply header. + * @param type type of ICMP packet (should be ICMP_TSTAMP or ICMP_TSTAMPREPLY) + * @param code code of ICMP packet (should be 0) + * @param sum checksum (0 for libnet to autofill) + * @param id identification number + * @param seq sequence number + * @param otime originate timestamp + * @param rtime receive timestamp + * @param ttime transmit timestamp + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_icmpv4_timestamp(u_int8_t type, u_int8_t code, u_int16_t sum, +u_int16_t id, u_int16_t seq, n_time otime, n_time rtime, n_time ttime, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1112 Internet Group Memebership Protocol (IGMP) header. + * @param type packet type + * @param code packet code (should be 0) + * @param sum checksum (0 for libnet to autofill) + * @param ip IPv4 address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_igmp(u_int8_t type, u_int8_t code, u_int16_t sum, u_int32_t ip, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a version 4 RFC 791 Internet Protocol (IP) header. + * @param len total length of the IP packet including all subsequent data + * @param tos type of service bits + * @param id IP identification number + * @param frag fragmentation bits and offset + * @param ttl time to live in the network + * @param prot upper layer protocol + * @param sum checksum (0 for libnet to autofill) + * @param src source IPv4 address (little endian) + * @param dst destination IPv4 address (little endian) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag, +u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an version 4 Internet Protocol (IP) options header. The function + * expects options to be a valid IP options string of size options_s, no larger + * than 40 bytes (the maximum size of an options string). The function checks + * to make sure that the preceding header is an IPv4 header and that the + * options string would not result in a packet larger than 65,535 bytes + * (IPMAXPACKET). The function counts up the number of 32-bit words in the + * options string and adjusts the IP header length value as necessary. + * @param options byte string of IP options + * @param options_s length of options string + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Autobuilds a version 4 Internet Protocol (IP) header. The function is useful * to build an IP header quickly when you do not need a granular level of + * control. The function takes the same len, prot, and dst arguments as + * libnet_build_ipv4(). The function does not accept a ptag argument, but it + * does return a ptag. In other words, you can use it to build a new IP header + * but not to modify an existing one. + * @param len total length of the IP packet including all subsequent data + * @param prot upper layer protocol + * @param dst destination IPv4 address (little endian) + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, libnet_t *l); + +/** + * Builds a version 6 RFC 2460 Internet Protocol (IP) header. + * @param tc traffic class + * @param fl flow label + * @param len total length of the IP packet + * @param nh next header + * @param hl hop limit + * @param src source IPv6 address + * @param dst destination IPv6 address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh, +u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a version 6 RFC 2460 Internet Protocol (IP) fragmentation header. + * @param nh next header + * @param reserved unused value... OR IS IT! + * @param frag fragmentation bits (ala ipv4) + * @param id packet identification + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag, +u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds a version 6 RFC 2460 Internet Protocol (IP) routing header. This + * function is special in that it uses the payload interface to include the + * "type-specific data"; that is the routing information. Most often this will + * be a number of 128-bit IPv6 addresses. The application programmer will build + * a byte string of IPv6 address and pass them to the function using the + * payload interface. + * @param nh next header + * @param len length of the header in 8-byte octets not including the first 8 octets + * @rtype routing header type + * @param segments number of routing segments that follow + * @param payload optional payload of routing information + * @param payload_s payload length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype, +u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds a version 6 RFC 2460 Internet Protocol (IP) destination options + * header. This function is special in that it uses the payload interface to + * include the options data. The application programmer will build an IPv6 + * options byte string and pass it to the function using the payload interface. + * @param nh next header + * @param len length of the header in 8-byte octets not including the first 8 octets + * @param payload options payload + * @param payload_s payload length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a version 6 RFC 2460 Internet Protocol (IP) hop by hop options + * header. This function is special in that it uses the payload interface to + * include the options data. The application programmer will build an IPv6 + * hop by hop options byte string and pass it to the function using the payload + * interface. + * @param nh next header + * @param len length of the header in 8-byte octets not including the first 8 octets + * @param payload options payload + * @param payload_s payload length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * This function is not yet implement and is a NONOP. + * @param len length + * @param nh next header + * @param dst destination IPv6 address + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst, +libnet_t *l); + +/** + * Builds a Cisco Inter-Switch Link (ISL) header. + * @param dhost destination address (should be 01:00:0c:00:00) + * @param type type of frame + * @param user user defined data + * @param shost source mac address + * @param len total length of the encapuslated packet less 18 bytes + * @param snap SNAP information (0xaaaa03 + vendor code) + * @param vid 15 bit VLAN ID, 1 bit BPDU or CDP indicator + * @param index port index + * @param reserved used for FDDI and token ring + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_isl(u_int8_t *dhost, u_int8_t type, u_int8_t user, u_int8_t *shost, +u_int16_t len, u_int8_t *snap, u_int16_t vid, u_int16_t index, +u_int16_t reserved, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an Internet Protocol Security Encapsulating Security Payload header. + * @param spi security parameter index + * @param seq ESP sequence number + * @param iv initialization vector + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_esp_hdr(u_int32_t spi, u_int32_t seq, u_int32_t iv, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an Internet Protocol Security Encapsulating Security Payload footer. + * @param len padding length + * @param nh next header + * @param auth authentication data + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_esp_ftr(u_int8_t len, u_int8_t nh, int8_t *auth, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an Internet Protocol Security Authentication header. + * @param nh next header + * @param len payload length + * @param res reserved + * @param spi security parameter index + * @param seq sequence number + * @param auth authentication data + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ipsec_ah(u_int8_t nh, u_int8_t len, u_int16_t res, +u_int32_t spi, u_int32_t seq, u_int32_t auth, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1035 version 4 DNS header. Additional DNS payload information + * should be specified using the payload interface. + * @param id DNS packet id + * @param flags control flags + * @param num_q number of questions + * @param num_anws_rr number of answer resource records + * @param num_auth_rr number of authority resource records + * @param num_addi_rr number of additional resource records + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_dnsv4(u_int16_t h_len, u_int16_t id, u_int16_t flags, +u_int16_t num_q, u_int16_t num_anws_rr, u_int16_t num_auth_rr, +u_int16_t num_addi_rr, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds a Routing Information Protocol header (RFCs 1058 and 2453). + * @param cmd command + * @param version protocol version + * @param rd version one: 0, version two: routing domain + * @param af address family + * @param rt version one: 0, version two: route tag + * @param addr IPv4 address + * @param mask version one: 0, version two: subnet mask + * @param next_hop version one: 0, version two: next hop address + * @param metric routing metric + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_rip(u_int8_t cmd, u_int8_t version, u_int16_t rd, u_int16_t af, +u_int16_t rt, u_int32_t addr, u_int32_t mask, u_int32_t next_hop, +u_int32_t metric, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an Remote Procedure Call (Version 2) Call message header as + * specified in RFC 1831. This builder provides the option for + * specifying the record marking which is required when used with + * streaming protocols (TCP). + * @param rm record marking indicating the position in a stream, 0 otherwise + * @param xid transaction identifier used to link calls and replies + * @param prog_num remote program specification typically between 0 - 1fffffff + * @param prog_vers remote program version specification + * @param procedure procedure to be performed by remote program + * @param cflavor authentication credential type + * @param clength credential length (should be 0) + * @param cdata opaque credential data (currently unused) + * @param vflavor authentication verifier type + * @param vlength verifier length (should be 0) + * @param vdata opaque verifier data (currently unused) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_rpc_call(u_int32_t rm, u_int32_t xid, u_int32_t prog_num, +u_int32_t prog_vers, u_int32_t procedure, u_int32_t cflavor, u_int32_t clength, +u_int8_t *cdata, u_int32_t vflavor, u_int32_t vlength, u_int8_t *vdata, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.1d Spanning Tree Protocol (STP) configuration header. + * STP frames are usually encapsulated inside of an 802.2 + 802.3 frame + * combination. + * @param id protocol id + * @param version protocol version + * @param bpdu_type bridge protocol data unit type + * @param flags flags + * @param root_id root id + * @param root_pc root path cost + * @param bridge_id bridge id + * @param port_id port id + * @param message_age message age + * @param max_age max age + * @param hello_time hello time + * @param f_delay forward delay + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_stp_conf(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, +u_int8_t flags, u_int8_t *root_id, u_int32_t root_pc, u_int8_t *bridge_id, +u_int16_t port_id, u_int16_t message_age, u_int16_t max_age, +u_int16_t hello_time, u_int16_t f_delay, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an IEEE 802.1d Spanning Tree Protocol (STP) topology change + * notification header. STP frames are usually encapsulated inside of an + * 802.2 + 802.3 frame combination. + * @param id protocol id + * @param version protocol version + * @param bpdu_type bridge protocol data unit type + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_stp_tcn(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a token ring header. + * @param ac access control + * @param fc frame control + * @param dst destination address + * @param src source address + * @param dsap destination service access point + * @param ssap source service access point + * @param cf control field + * @param oui Organizationally Unique Identifier + * @param type upper layer protocol type + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, u_int8_t *src, +u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Auto-builds a token ring header. + * @param ac access control + * @param fc frame control + * @param dst destination address + * @param dsap destination service access point + * @param ssap source service access point + * @param cf control field + * @param oui Organizationally Unique Identifier + * @param type upper layer protocol type + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, +u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, +libnet_t *l); + +/** + * Builds an RFC 2338 Virtual Router Redundacy Protool (VRRP) header. Use the + * payload interface to specify address and autthentication information. To + * build a "legal" packet, the destination IPv4 address should be the multicast * address 224.0.0.18, the IP TTL should be set to 255, and the IP protocol + * should be set to 112. + * @param version VRRP version (should be 2) + * @param type VRRP packet type (should be 1 -- ADVERTISEMENT) + * @param vrouter_id virtual router identification + * @param priority priority (higher numbers indicate higher priority) + * @param ip_count number of IPv4 addresses contained in this advertisement + * @param auth_type type of authentication (0, 1, 2 -- see RFC) + * @param advert_int interval between advertisements + * @param sum checksum (0 for libnet to autofill) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_vrrp(u_int8_t version, u_int8_t type, u_int8_t vrouter_id, +u_int8_t priority, u_int8_t ip_count, u_int8_t auth_type, u_int8_t advert_int, +u_int16_t sum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an RFC 3032 Multi-Protocol Label Switching (MPLS) header. + * @param label 20-bit label value + * @param experimental 3-bit reserved field + * @param bos 1-bit bottom of stack identifier + * @param ttl time to live + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_mpls(u_int32_t label, u_int8_t experimental, u_int8_t bos, +u_int8_t ttl, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an RFC 958 Network Time Protocol (NTP) header. + * @param leap_indicator the leap indicator + * @param version NTP protocol version + * @param mode NTP mode + * @param stratum stratum + * @param poll polling interval + * @param precision precision + * @param delay_interval delay interval + * @param delay_frac delay fraction + * @param dispersion_int dispersion interval + * @param dispersion_frac dispersion fraction + * @param reference_id reference id + * @param ref_ts_int reference timestamp integer + * @param ref_ts_frac reference timestamp fraction + * @param orig_ts_int original timestamp integer + * @param orig_ts_frac original timestamp fraction + * @param rec_ts_int receiver timestamp integer + * @param rec_ts_frac reciever timestamp fraction + * @param xmt_ts_int transmit timestamp integer + * @param xmt_ts_frac transmit timestamp integer + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ntp(u_int8_t leap_indicator, u_int8_t version, u_int8_t mode, +u_int8_t stratum, u_int8_t poll, u_int8_t precision, u_int16_t delay_int, +u_int16_t delay_frac, u_int16_t dispersion_int, u_int16_t dispersion_frac, +u_int32_t reference_id, u_int32_t ref_ts_int, u_int32_t ref_ts_frac, +u_int32_t orig_ts_int, u_int32_t orig_ts_frac, u_int32_t rec_ts_int, +u_int32_t rec_ts_frac, u_int32_t xmt_ts_int, u_int32_t xmt_ts_frac, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2(u_int16_t len, u_int8_t type, u_int32_t rtr_id, +u_int32_t area_id, u_int16_t sum, u_int16_t autype, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_hello(u_int32_t netmask, u_int16_t interval, u_int8_t opts, +u_int8_t priority, u_int dead_int, u_int32_t des_rtr, u_int32_t bkup_rtr, +u_int32_t neighbor, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_dbd(u_int16_t dgram_len, u_int8_t opts, u_int8_t type, +u_int seqnum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsr(u_int type, u_int lsid, u_int32_t advrtr, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsu(u_int num, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa(u_int16_t age, u_int8_t opts, u_int8_t type, +u_int lsid, u_int32_t advrtr, u_int seqnum, u_int16_t sum, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_rtr(u_int16_t flags, u_int16_t num, u_int id, +u_int data, u_int8_t type, u_int8_t tos, u_int16_t metric, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_net(u_int32_t nmask, u_int rtrid, u_int8_t *payload, +u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_sum(u_int32_t nmask, u_int metric, u_int tos, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_ospfv2_lsa_as(u_int32_t nmask, u_int metric, u_int32_t fwdaddr, +u_int tag, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds a generic libnet protocol header. This is useful for including an + * optional payload to a packet that might need to change repeatedly inside + * of a loop. + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_data(u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_dhcpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, +u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, +u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, +u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bootpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, +u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, +u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, +u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +inline u_int32_t +libnet_getgre_length(u_int16_t fv); + +/** + * Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate any + * protocol. Hence, the IP part of the packet is usually referred as "delivery + * header". It is then followed by the GRE header and finally the encapsulated + * packet (IP or whatever). + * As GRE is very modular, the first GRE header describes the structure of the + * header, using bits and flag to specify which fields will be present in the + * header. + * @param fv the 16 0 to 7: which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to 15: version. + * @param payload optional payload or NULL + * @param type which protocol is encapsulated (PPP, IP, ...) + * @param sum checksum (0 for libnet to autofill). + * @param offset byte offset from the start of the routing field to the first byte of the SRE + * @param key inserted by the encapsulator to authenticate the source + * @param seq sequence number used by the receiver to sort the packets + * @param len size of the GRE packet + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre(u_int16_t fv, u_int16_t type, u_int16_t sum, +u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate any + * protocol. Hence, the IP part of the packet is usually referred as "delivery + * header". It is then followed by the GRE header and finally the encapsulated + * packet (IP or whatever). + * As GRE is very modular, the first GRE header describes the structure of the + * header, using bits and flag to specify which fields will be present in the + * header. + * @param fv the 16 0 to 7: which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to 15: version. + * @param payload optional payload or NULL + * @param type which protocol is encapsulated (PPP, IP, ...) + * @param sum checksum (0 for libnet to autofill). + * @param offset byte offset from the start of the routing field to the first byte of the SRE + * @param key inserted by the encapsulator to authenticate the source + * @param seq sequence number used by the receiver to sort the packets + * @param len size of the GRE packet + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_egre(u_int16_t fv, u_int16_t type, u_int16_t sum, +u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre_sre(u_int16_t af, u_int8_t offset, u_int8_t length, +u_int8_t *routing, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, +libnet_ptag_t ptag); + +/** + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) header. The primary + * function of a BGP speaking system is to exchange network reachability + * information with other BGP systems. This network reachability information + * includes information on the list of Autonomous Systems (ASs) that + * reachability information traverses. This information is sufficient to + * construct a graph of AS connectivity from which routing loops may be pruned + * and some policy decisions at the AS level may be enforced. + * This function builds the base BGP header which is used as a preamble before + * any other BGP header. For example, a BGP KEEPALIVE message may be built with + * only this function, while an error notification requires a subsequent call + * to libnet_build_bgp4_notification. + * @param marker a value the receiver can predict (if the message type is not BGP OPEN, or no authentication is used, these 16 bytes are normally set as all ones) + * @param len total length of the BGP message, including the header + * @param type type code of the message (OPEN, UPDATE, NOTIFICATION or KEEPALIVE) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_MARKER_SIZE], +u_int16_t len, u_int8_t type, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) OPEN header. This is + * the first message sent by each side of a BGP connection. The optional + * parameters options should be constructed using the payload interface (see + * RFC 1771 for the options structures). + * @param version protocol version (should be set to 4) + * @param src_as Autonomous System of the sender + * @param hold_time used to compute the maximum allowed time between the receipt of KEEPALIVE, and/or UPDATE messages by the sender + * @param bgp_id BGP identifier of the sender + * @param opt_len total length of the optional parameters field in bytes + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_open(u_int8_t version, u_int16_t src_as, u_int16_t hold_time, +u_int32_t bgp_id, u_int8_t opt_len, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) update header. Update + * messages are used to transfer routing information between BGP peers. + * @param unfeasible_rt_len indicates the length of the (next) "withdrawn routes" field in bytes + * @param withdrawn_rt list of IP addresses prefixes for the routes that are being withdrawn; each IP address prefix is built as a 2-tuple <length (1 byte), prefix (variable)> + * @param total_path_attr_len indicates the length of the (next) "path attributes" field in bytes + * @param path_attributes each attribute is a 3-tuple <type (2 bytes), length, value> + * @param info_len indicates the length of the (next) "network layer reachability information" field in bytes (needed for internal memory size calculation) + * @param reachability_info 2-tuples <length (1 byte), prefix (variable)>. + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, u_int8_t *withdrawn_rt, +u_int16_t total_path_attr_len, u_int8_t *path_attributes, u_int16_t info_len, +u_int8_t *reachability_info, u_int8_t *payload, u_int32_t payload_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) notification header. + * A NOTIFICATION message is sent when an error condition is detected. Specific + * error information may be passed through the payload interface. + * @param err_code type of notification + * @param err_subcode more specific information about the reported error. + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_bgp4_notification(u_int8_t err_code, u_int8_t err_subcode, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a Sebek header. The Sebek protocol was designed by the Honeynet + * Project as a transport mechanism for post-intrusion forensic data. More + * information may be found here: http://www.honeynet.org/papers/sebek.pdf. + * @param magic identify packets that should be hidden + * @param version protocol version, currently 1 + * @param type type of record (read data is type 0, write data is type 1) + * @param counter PDU counter used to identify when packet are lost + * @param time_sec seconds since EPOCH according to the honeypot + * @param time_usec residual microseconds + * @param pid PID + * @param uid UID + * @param fd FD + * @param cmd[SEBEK_CMD_LENGTH] 12 first characters of the command + * @param length length in bytes of the PDU's body + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_sebek(u_int32_t magic, u_int16_t version, u_int16_t type, +u_int32_t counter, u_int32_t time_sec, u_int32_t time_usec, u_int32_t pid, +u_int32_t uid, u_int32_t fd, u_int8_t cmd[SEBEK_CMD_LENGTH], u_int32_t length, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds a link layer header for an initialized l. The function + * determines the proper link layer header format from how l was initialized. + * The function current supports Ethernet and Token Ring link layers. + * @param dst the destination MAC address + * @param src the source MAC address + * @param oui Organizationally Unique Identifier (unused for Ethernet) + * @param type the upper layer protocol type + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_build_link(u_int8_t *dst, u_int8_t *src, u_int8_t *oui, u_int16_t type, +u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Automatically builds a link layer header for an initialized l. The function + * determines the proper link layer header format from how l was initialized. + * The function current supports Ethernet and Token Ring link layers. + * @param dst the destination MAC address + * @param oui Organizationally Unique Identifier (unused for Ethernet) + * @param type the upper layer protocol type + * @param l pointer to a libnet context + * @return protocol tag value on success, -1 on error + */ +libnet_ptag_t +libnet_autobuild_link(u_int8_t *dst, u_int8_t *oui, u_int16_t type, +libnet_t *l); + +/** + * Writes a prebuilt packet to the network. The function assumes that l was + * previously initialized (via a call to libnet_init()) and that a + * previously constructed packet has been built inside this context (via one or + * more calls to the libnet_build* family of functions) and is ready to go. + * Depending on how libnet was initialized, the function will write the packet + * to the wire either via the raw or link layer interface. The function will + * also bump up the internal libnet stat counters which are retrievable via + * libnet_stats(). + * @param l pointer to a libnet context + * @return the number of bytes written, -1 on error + */ +int +libnet_write(libnet_t *l); + +/** + * Returns the IP address for the device libnet was initialized with. If + * libnet was initialized without a device (in raw socket mode) the function + * will attempt to find one. If the function fails and returns -1 a call to + * libnet_geterrror() will tell you why. + * @param l pointer to a libnet context + * @return a big endian IP address suitable for use in a libnet_build function or -1 + */ + +u_int32_t +libnet_get_ipaddr4(libnet_t *l); + +/** + * This function is not yet implemented under IPv6. + * @param l pointer to a libnet context + * @return well, nothing yet + */ +struct libnet_in6_addr +libnet_get_ipaddr6(libnet_t *l); + +/** + * Returns the MAC address for the device libnet was initialized with. If + * libnet was initialized without a device the function will attempt to find + * one. If the function fails and returns NULL a call to libnet_geterror() will + * tell you why. + * @param l pointer to a libnet context + * @return a pointer to the MAC address or NULL + */ +struct libnet_ether_addr * +libnet_get_hwaddr(libnet_t *l); + +/** + * Takes a colon separated hexidecimal address (from the command line) and + * returns a bytestring suitable for use in a libnet_build function. Note this + * function performs an implicit malloc and the return value should be freed + * after its use. + * @param s the string to be parsed + * @param len the resulting size of the returned byte string + * @return a byte string or NULL on failure + */ +u_int8_t * +libnet_hex_aton(int8_t *s, int *len); + +/** + * [Advanced Interface] + * Yanks a prebuilt, wire-ready packet from the given libnet context. If + * libnet was configured to do so (which it is by default) the packet will have + * all checksums written in. This function is part of the advanced interface + * and is only available when libnet is initialized in advanced mode. It is + * important to note that the function performs an implicit malloc() and a + * corresponding call to libnet_adv_free_packet() should be made to free the + * memory packet occupies. If the function fails libnet_geterror() can tell you + * why. + * @param l pointer to a libnet context + * @param packet will contain the wire-ready packet + * @param packet_s will contain the packet size + * @return 1 on success, -1 on failure + */ +int +libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, u_int32_t *packet_s); + +/** + * [Advanced Interface] + * Pulls the header from the specified ptag from the given libnet context. This + * function is part of the advanced interface and is only available when libnet + * is initialized in advanced mode. If the function fails libnet_geterror() can + * tell you why. + * @param l pointer to a libnet context + * @param ptag the ptag referencing the header to pull + * @param header will contain the header + * @param header_s will contain the header size + * @return 1 on success, -1 on failure + */ +int +libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, u_int8_t **header, +u_int32_t *header_s); + +/** + * [Advanced Interface] + * Writes a packet the network at the link layer. This function is useful to + * write a packet that has been constructed by hand by the application + * programmer or, more commonly, to write a packet that has been returned by + * a call to libnet_adv_cull_packet(). This function is part of the advanced + * interface and is only available when libnet is initialized in advanced mode. + * If the function fails libnet_geterror() can tell you why. + * @param l pointer to a libnet context + * @param packet a pointer to the packet to inject + * @param packet_s the size of the packet + * @return the number of bytes written, or -1 on failure + */ +int +libnet_adv_write_link(libnet_t *l, u_int8_t *packet, u_int32_t packet_s); + +/** + * [Advanced Interface] + * Frees the memory allocated when libnet_adv_cull_packet() is called. + * @param l pointer to a libnet context + * @param packet a pointer to the packet to free + */ +void +libnet_adv_free_packet(libnet_t *l, u_int8_t *packet); + +/** + * [Context Queue] + * Adds a new context to the libnet context queue. If no queue exists, this + * function will create the queue and add the specified libnet context as the + * first entry on the list. The functions checks to ensure niether l nor label + * are NULL, and that label doesn't refer to an existing context already in the + * queue. Additionally, l should refer to a libnet context previously + * initialized with a call to libnet_init(). If the context queue in write + * locked, this function will fail. + * @param l pointer to a libnet context + * @param label a canonical name given to recognize the new context, no longer than LIBNET_LABEL_SIZE + * @return 1 on success, -1 on failure +*/ +int +libnet_cq_add(libnet_t *l, char *label); + +/** + * [Context Queue] + * Removes a specified context from the libnet context queue by specifying the + * libnet context pointer. Note the function will remove the specified context + * from the context queue and cleanup internal memory from the queue, it is up + * to the application programmer to free the returned libnet context with a + * call to libnet_destroy(). Also, as it is not necessary to keep the libnet + * context pointer when initially adding it to the context queue, most + * application programmers will prefer to refer to entries on the context + * queue by canonical name and would use libnet_cq_remove_by_label(). If the + * context queue is write locked, this function will fail. + * @param l pointer to a libnet context + * @return the pointer to the removed libnet context, NULL on failure + */ +libnet_t * +libnet_cq_remove(libnet_t *l); + +/** + * [Context Queue] + * Removes a specified context from the libnet context queue by specifying the + * canonical name. Note the function will remove the specified context from + * the context queue and cleanup internal memory from the queue, it is up to + * the application programmer to free the returned libnet context with a call + * to libnet_destroy(). If the context queue is write locked, this function + * will fail. + * @param label canonical name of the context to remove + * @return the pointer to the removed libnet context, NULL on failure + */ +libnet_t * +libnet_cq_remove_by_label(char *label); + +/** + * [Context Queue] + * Returns the canonical label associated with the context. + * @param l pointer to a libnet context + * @return pointer to the libnet context's label + */ +int8_t * +libnet_cq_getlabel(libnet_t *l); + +/** + * [Context Queue] + * Locates a libnet context from the queue, indexed by a canonical label. + * @param label canonical label of the libnet context to retrieve + * @return the expected libnet context, NULL on failure + */ +libnet_t * +libnet_cq_find_by_label(char *label); + +/** + * [Context Queue] + * Destroys the entire context queue, calling libnet_destroy() on each + * member context. + */ +void +libnet_cq_destroy(); + +/** + * [Context Queue] + * Intiailizes the interator interface and set a write lock on the entire + * queue. This function is intended to be called just prior to interating + * through the entire list of contexts (with the probable intent of inject a + * series of packets in rapid succession). This function is often used as + * per the following: + * + * for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) + * { + * ... + * } + * + * Much of the time, the application programmer will use the iterator as it is + * written above; as such, libnet provides a macro to do exactly that, + * for_each_context_in_cq(l). Warning: do not call the iterator more than once + * in a single loop. + * @return the head of the context queue + */ +libnet_t * +libnet_cq_head(); + +/** + * [Context Queue] + * Check whether the iterator is at the last context in the queue. + * @return 1 if at the end of the context queue, 0 otherwise + */ +int +libnet_cq_last(); + +/** + * [Context Queue] + * Get next context from the context queue. + * @reutrn the next context from the context queue + */ +libnet_t * +libnet_cq_next(); + +/** + * [Context Queue] + * Function returns the number of libnet contexts that are in the queue. + * @return the number of libnet contexts currently in the queue + */ +u_int32_t +libnet_cq_size(); + +/** + * [Diagnostic] + * Prints the contents of the given context. + * @param l pointer to a libnet context + */ +void +libnet_diag_dump_context(libnet_t *l); + +/** + * [Diagnostic] + * Prints the contents of every pblock. + * @param l pointer to a libnet context + */ +void +libnet_diag_dump_pblock(libnet_t *l); + +/** + * [Diagnostic] + * Returns the canonical name of the pblock type. + * @param type pblock type + * @return a string representing the pblock type type or "unknown" for an unknown value + */ +char * +libnet_diag_dump_pblock_type(u_int8_t type); + +/** + * [Diagnostic] + * Function prints the contents of the supplied buffer to the supplied + * stream pointer. Will swap endianness based disposition of mode variable. + * Useful to be used in conjunction with the advanced interface and a culled + * packet. + * @param packet the packet to print + * @param len length of the packet in bytes + * @param swap 1 to swap byte order, 0 to not + * @param stream a stream pointer to print to + */ +void +libnet_diag_dump_hex(u_int8_t *packet, u_int32_t len, int swap, FILE *stream); + +/* + * [Internal] + */ +int +libnet_write_raw_ipv4(libnet_t *l, u_int8_t *packet, u_int32_t size); + +/* + * [Internal] + */ +int +libnet_write_raw_ipv6(libnet_t *l, u_int8_t *packet, u_int32_t size); + +/* + * [Internal] + */ +int +libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size); + +#if ((__WIN32__) && !(__CYGWIN__)) +/* + * [Internal] + */ +SOCKET +libnet_open_raw4(libnet_t *l); +#else +/* + * [Internal] + */ +int +libnet_open_raw4(libnet_t *l); +#endif + +/* + * [Internal] + */ +int +libnet_close_raw4(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_open_raw6(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_close_raw6(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_select_device(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_open_link(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_close_link(libnet_t *l); + +/* + * [Internal] + */ +int +libnet_do_checksum(libnet_t *l, u_int8_t *packet, int protocol, int len); + +/* + * [Internal] + */ +u_int32_t +libnet_compute_crc(u_int8_t *buf, u_int32_t len); + +/* + * [Internal] + */ +u_int16_t +libnet_ip_check(u_int16_t *addr, int len); + +/* + * [Internal] + */ +int +libnet_in_cksum(u_int16_t *addr, int len); + +/* + * [Internal] + * If ptag is 0, function will create a pblock for the protocol unit type, + * append it to the list and return a pointer to it. If ptag is not 0, + * function will search the pblock list for the specified protocol block + * and return a pointer to it. + */ +libnet_pblock_t * +libnet_pblock_probe(libnet_t *l, libnet_ptag_t ptag, u_int32_t n, +u_int8_t type); + +/* + * [Internal] + * Function creates the pblock list if l->protocol_blocks == NULL or appends + * an entry to the doubly linked list. + */ +libnet_pblock_t * +libnet_pblock_new(libnet_t *l, u_int32_t size); + +/* + * [Internal] + * Function swaps two pblocks in memory. + */ +int +libnet_pblock_swap(libnet_t *l, libnet_ptag_t ptag1, libnet_ptag_t ptag2); + +/* + * [Internal] + * Function inserts a pblock into the doubly linked list. + */ +int +libnet_pblock_insert_before(libnet_t *l, libnet_ptag_t ptag1, +libnet_ptag_t ptag2); + +/* + * [Internal] + * Function removes a pblock from context + */ +void +libnet_pblock_delete(libnet_t *l, libnet_pblock_t *p); + +/* + * [Internal] + * Function updates the pblock meta-inforation. Internally it updates the + * ptag with a monotonically increasing variable kept in l. This way each + * pblock has a succesively increasing ptag identifier. + */ +libnet_ptag_t +libnet_pblock_update(libnet_t *l, libnet_pblock_t *p, u_int32_t h, +u_int8_t type); + + + /* + * [Internal] + * Checksums are a real pain in the <beep>!!! + * Function updates referer used to compute the checksum. All + * pblock need to know where is their referer (ie IP header). + * So, this function is called each time a new IP header is inserted. + * It updates the ip_pos field (referer) of each subsequent pblock. + */ +void +libnet_pblock_record_ip_offset(libnet_t *l, u_int32_t offset); + +/* + * [Internal] + * Function locates a given block by it's ptag. + */ +libnet_pblock_t * +libnet_pblock_find(libnet_t *l, libnet_ptag_t ptag); + +/* + * [Internal] + * Function copies protocol block data over. + */ +int +libnet_pblock_append(libnet_t *l, libnet_pblock_t *p, u_int8_t *buf, +u_int32_t len); + +/* + * [Internal] + * Function sets pblock flags. + */ +void +libnet_pblock_setflags(libnet_pblock_t *p, u_int8_t flags); + +/* + * [Internal] + * Function returns the protocol number for the protocol block type. If + * the type is unknown, the function defaults to returning IPPROTO_IP. + */ +int +libnet_pblock_p2p(u_int8_t type); + +/* + * [Internal] + * Function assembles the packet for subsequent writing. Function makes two + * passes through the pblock list: + */ +int +libnet_pblock_coalesce(libnet_t *l, u_int8_t **packet, u_int32_t *size); + +#if !(__WIN32__) +/* + * [Internal] + * By testing if we can retrieve the FLAGS of an iface + * we can know if it exists or not and if it is up. + */ +int +libnet_check_iface(libnet_t *l); +#endif + +#if defined(__WIN32__) +/* + * [Internal] + */ +BYTE * +libnet_win32_get_remote_mac(libnet_t *l, DWORD IP); + +/* + * [Internal] + */ +int +libnet_close_link_interface(libnet_t *l); + +/* + * [Internal] + */ +BYTE * +libnet_win32_read_arp_table(DWORD IP); +#endif +#endif /* __LIBNET_FUNCTIONS_H */ + +/* EOF */ diff --git a/libnet/include/libnet/libnet-headers.h b/libnet/include/libnet/libnet-headers.h new file mode 100644 index 0000000..2d44e08 --- /dev/null +++ b/libnet/include/libnet/libnet-headers.h @@ -0,0 +1,1662 @@ +/* + * $Id: libnet-headers.h,v 1.14 2004/03/11 18:50:20 mike Exp $ + * + * libnet-headers.h - Network routine library headers header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_HEADERS_H +#define __LIBNET_HEADERS_H +/** + * @file libnet-headers.h + * @brief libnet header information + */ + +/** + * Libnet defines header sizes for every builder function exported. + */ +#define LIBNET_802_1Q_H 0x12 /**< 802.1Q header: 18 bytes */ +#define LIBNET_802_1X_H 0x04 /**< 802.1X header: 4 bytes */ +#define LIBNET_802_2_H 0x03 /**< 802.2 LLC header: 3 bytes */ +#define LIBNET_802_2SNAP_H 0x08 /**< 802.2 LLC/SNAP header:8 bytes */ +#define LIBNET_802_3_H 0x0e /**< 802.3 header: 14 bytes */ +#define LIBNET_ARP_H 0x08 /**< ARP header w/o addrs: 8 bytes */ +#define LIBNET_ARP_ETH_IP_H 0x1c /**< ARP w/ ETH and IP: 28 bytes */ +#define LIBNET_BGP4_HEADER_H 0x13 /**< BGP header: 19 bytes */ +#define LIBNET_BGP4_OPEN_H 0x0a /**< BGP open header: 10 bytes */ +#define LIBNET_BGP4_UPDATE_H 0x04 /**< BGP open header: 4 bytes */ +#define LIBNET_BGP4_NOTIFICATION_H 0x02 /**< BGP notif. header: 2 bytes */ +#define LIBNET_CDP_H 0x08 /**< CDP header base: 8 bytes */ +#define LIBNET_DHCPV4_H 0xf0 /**< DHCP v4 header: 240 bytes */ +#define LIBNET_UDP_DNSV4_H 0x0c /**< UDP DNS v4 header: 12 bytes */ +#define LIBNET_TCP_DNSV4_H 0x0e /**< TCP DNS v4 header: 14 bytes */ +#define LIBNET_ETH_H 0x0e /**< Ethernet header: 14 bytes */ +#define LIBNET_FDDI_H 0x15 /**< FDDI header: 21 bytes */ +#define LIBNET_ICMPV4_H 0x04 /**< ICMP header base: 4 bytes */ +#define LIBNET_ICMPV4_ECHO_H 0x08 /**< ICMP_ECHO header: 8 bytes */ +#define LIBNET_ICMPV4_MASK_H 0x0c /**< ICMP_MASK header: 12 bytes */ +#define LIBNET_ICMPV4_UNREACH_H 0x08 /**< ICMP_UNREACH header: 8 bytes */ +#define LIBNET_ICMPV4_TIMXCEED_H 0x08 /**< ICMP_TIMXCEED header: 8 bytes */ +#define LIBNET_ICMPV4_REDIRECT_H 0x08 /**< ICMP_REDIRECT header: 8 bytes */ +#define LIBNET_ICMPV4_TS_H 0x14 /**< ICMP_TIMESTAMP headr:20 bytes */ +#define LIBNET_ICMPV6_H 0x08 /**< ICMP6 header base: 8 bytes */ +#define LIBNET_IGMP_H 0x08 /**< IGMP header: 8 bytes */ +#define LIBNET_IPV4_H 0x14 /**< IPv4 header: 20 bytes */ +#define LIBNET_IPV6_H 0x28 /**< IPv6 header: 40 bytes */ +#define LIBNET_IPV6_FRAG_H 0x08 /**< IPv6 frag header: 8 bytes */ +#define LIBNET_IPV6_ROUTING_H 0x04 /**< IPv6 frag header base:4 bytes */ +#define LIBNET_IPV6_DESTOPTS_H 0x02 /**< IPv6 dest opts base: 2 bytes */ +#define LIBNET_IPV6_HBHOPTS_H 0x02 /**< IPv6 hop/hop opt base:2 bytes */ +#define LIBNET_IPSEC_ESP_HDR_H 0x0c /**< IPSEC ESP header: 12 bytes */ +#define LIBNET_IPSEC_ESP_FTR_H 0x02 /**< IPSEC ESP footer: 2 bytes */ +#define LIBNET_IPSEC_AH_H 0x10 /**< IPSEC AH header: 16 bytes */ +#define LIBNET_ISL_H 0x1a /**< ISL header: 26 bytes */ +#define LIBNET_GRE_H 0x04 /**< GRE header: 4 bytes */ +#define LIBNET_GRE_SRE_H 0x04 /**< GRE SRE header: 4 bytes */ +#define LIBNET_MPLS_H 0x04 /**< MPLS header: 4 bytes */ +#define LIBNET_OSPF_H 0x10 /**< OSPF header: 16 bytes */ +#define LIBNET_OSPF_HELLO_H 0x18 /**< OSPF hello header: 24 bytes */ +#define LIBNET_OSPF_DBD_H 0x08 /**< OSPF DBD header: 8 bytes */ +#define LIBNET_OSPF_LSR_H 0x0c /**< OSPF LSR header: 12 bytes */ +#define LIBNET_OSPF_LSU_H 0x04 /**< OSPF LSU header: 4 bytes */ +#define LIBNET_OSPF_LSA_H 0x14 /**< OSPF LSA header: 20 bytes */ +#define LIBNET_OSPF_AUTH_H 0x08 /**< OSPF AUTH header: 8 bytes */ +#define LIBNET_OSPF_CKSUM 0x10 /**< OSPF CKSUM header: 16 bytes */ +#define LIBNET_OSPF_LS_RTR_H 0x10 /**< OSPF LS RTR header: 16 bytes */ +#define LIBNET_OSPF_LS_NET_H 0x08 /**< OSPF LS NET header: 8 bytes */ +#define LIBNET_OSPF_LS_SUM_H 0x0c /**< OSPF LS SUM header: 12 bytes */ +#define LIBNET_OSPF_LS_AS_EXT_H 0x10 /**< OSPF LS AS header: 16 bytes */ +#define LIBNET_NTP_H 0x30 /**< NTP header: 48 bytes */ +#define LIBNET_RIP_H 0x18 /**< RIP header base: 24 bytes */ +#define LIBNET_RPC_CALL_H 0x28 /**< RPC header: 40 bytes + * (assuming 8 byte auth header) + */ +#define LIBNET_RPC_CALL_TCP_H 0x2c /**< RPC header: 44 bytes + * (with record marking) + */ +#define LIBNET_SEBEK_H 0x30 /* sebek header: 48 bytes */ +#define LIBNET_STP_CONF_H 0x23 /**< STP conf header: 35 bytes */ +#define LIBNET_STP_TCN_H 0x04 /**< STP tcn header: 4 bytes */ +#define LIBNET_TOKEN_RING_H 0x16 /**< Token Ring header: 22 bytes */ +#define LIBNET_TCP_H 0x14 /**< TCP header: 20 bytes */ +#define LIBNET_UDP_H 0x08 /**< UDP header: 8 bytes */ +#define LIBNET_VRRP_H 0x08 /**< VRRP header: 8 bytes */ + +/** + * IEEE 802.1Q (Virtual Local Area Network) VLAN header, static header + * size: 18 bytes + */ +struct libnet_802_1q_hdr +{ + u_int8_t vlan_dhost[ETHER_ADDR_LEN]; /**< destination ethernet address */ + u_int8_t vlan_shost[ETHER_ADDR_LEN]; /**< source ethernet address */ + u_int16_t vlan_tpi; /**< tag protocol ID */ + u_int16_t vlan_priority_c_vid; /**< priority | VLAN ID */ +#define LIBNET_802_1Q_PRIMASK 0x0007 /**< priority mask */ +#define LIBNET_802_1Q_CFIMASK 0x0001 /**< CFI mask */ +#define LIBNET_802_1Q_VIDMASK 0x0fff /**< vid mask */ + u_int16_t vlan_len; /**< length or type (802.3 / Eth 2) */ +}; + +/** + * IEEE 802.1X EAP (Extensible Authentication Protocol) header, static header + * size: 4 bytes + */ +struct libnet_802_1x_hdr +{ + u_int8_t dot1x_version; /**< protocol version */ + u_int8_t dot1x_type; /**< frame type */ +#define LIBNET_802_1X_PACKET 0x00 /**< 802.1x packet */ +#define LIBNET_802_1X_START 0x01 /**< 802.1x start */ +#define LIBNET_802_1X_LOGOFF 0x02 /**< 802.1x logoff */ +#define LIBNET_802_1X_KEY 0x03 /**< 802.1x key */ +#define LIBNET_802_1X_ENCASFAL 0x04 /**< 802.1x encasfal */ + u_int16_t dot1x_length; /**< total frame length */ +}; + +/* + * IEEE 802.2 LLC header + * Link Layer Control + * static header size: 3 bytes + */ +struct libnet_802_2_hdr +{ + u_int8_t llc_dsap; /* destination service access point */ + u_int8_t llc_ssap; /* source service access point */ +#define LIBNET_SAP_STP 0x42 +#define LIBNET_SAP_SNAP 0xaa + u_int8_t llc_control; /* control field */ +}; + + +/* + * IEEE 802.2 LLC/SNAP header + * SubNetwork Attachment Point + * static header size: 8 bytes + */ +struct libnet_802_2snap_hdr +{ + u_int8_t snap_dsap; /* destination service access point */ + u_int8_t snap_ssap; /* destination service access point */ + u_int8_t snap_control; /* control field */ + u_int8_t snap_oui[3]; /* OUI */ + u_int16_t snap_type; /* type */ +}; + + +/* + * 802.3 header + * IEEE Ethernet + * Static header size: 14 bytes + */ +struct libnet_802_3_hdr +{ + u_int8_t _802_3_dhost[ETHER_ADDR_LEN];/* destination ethernet address */ + u_int8_t _802_3_shost[ETHER_ADDR_LEN];/* source ethernet address */ + u_int16_t _802_3_len; /* packet type ID */ +}; + + +/* + * ARP header + * Address Resolution Protocol + * Base header size: 8 bytes + */ +struct libnet_arp_hdr +{ + u_int16_t ar_hrd; /* format of hardware address */ +#define ARPHRD_NETROM 0 /* from KA9Q: NET/ROM pseudo */ +#define ARPHRD_ETHER 1 /* Ethernet 10Mbps */ +#define ARPHRD_EETHER 2 /* Experimental Ethernet */ +#define ARPHRD_AX25 3 /* AX.25 Level 2 */ +#define ARPHRD_PRONET 4 /* PROnet token ring */ +#define ARPHRD_CHAOS 5 /* Chaosnet */ +#define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB */ +#define ARPHRD_ARCNET 7 /* ARCnet */ +#define ARPHRD_APPLETLK 8 /* APPLEtalk */ +#define ARPHRD_LANSTAR 9 /* Lanstar */ +#define ARPHRD_DLCI 15 /* Frame Relay DLCI */ +#define ARPHRD_ATM 19 /* ATM */ +#define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id) */ +#define ARPHRD_IPSEC 31 /* IPsec tunnel */ + u_int16_t ar_pro; /* format of protocol address */ + u_int8_t ar_hln; /* length of hardware address */ + u_int8_t ar_pln; /* length of protocol addres */ + u_int16_t ar_op; /* operation type */ +#define ARPOP_REQUEST 1 /* req to resolve address */ +#define ARPOP_REPLY 2 /* resp to previous request */ +#define ARPOP_REVREQUEST 3 /* req protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* resp giving protocol address */ +#define ARPOP_INVREQUEST 8 /* req to identify peer */ +#define ARPOP_INVREPLY 9 /* resp identifying peer */ + /* address information allocated dynamically */ +}; + +/* + * BGP4 header + * Border Gateway Protocol 4 + * Base header size : 19 bytes + */ +struct libnet_bgp4_header_hdr +{ +#define LIBNET_BGP4_MARKER_SIZE 16 + u_int8_t marker[LIBNET_BGP4_MARKER_SIZE]; + u_int16_t len; + u_int8_t type; +#define LIBNET_BGP4_OPEN 1 +#define LIBNET_BGP4_UPDATE 2 +#define LIBNET_BGP4_NOTIFICATION 3 +#define LIBNET_BGP4_KEEPALIVE 4 +}; + +/* + * BGP4 open header + * Border Gateway Protocol 4 + * Base header size : 10 bytes + */ +struct libnet_bgp4_open_hdr +{ + u_int8_t version; + u_int16_t src_as; + u_int16_t hold_time; + u_int32_t bgp_id; + u_int8_t opt_len; +}; + +/* + * BGP4 notification message + * + * Border Gateway Protocol 4 + * Base header size : 2 bytes + * + * Use payload if you need data + */ +struct libnet_bgp4_notification_hdr +{ +#define LIBNET_BGP4_MESSAGE_HEADER_ERROR 1 +#define LIBNET_BGP4_OPEN_MESSAGE_ERROR 2 +#define LIBNET_BGP4_UPDATE_MESSAGE_ERROR 3 +#define LIBNET_BGP4_HOLD_TIMER_EXPIRED 4 +#define LIBNET_BGP4_FINITE_STATE__ERROR 5 +#define LIBNET_BGP4_CEASE 6 + u_int8_t err_code; + +/* Message Header Error subcodes */ +#define LIBNET_BGP4_CONNECTION_NOT_SYNCHRONIZED 1 +#define LIBNET_BGP4_BAD_MESSAGE_LENGTH 2 +#define LIBNET_BGP4_BAD_MESSAGE_TYPE 3 +/* OPEN Message Error subcodes */ +#define LIBNET_BGP4_UNSUPPORTED_VERSION_NUMBER 1 +#define LIBNET_BGP4_BAD_PEER_AS 2 +#define LIBNET_BGP4_BAD_BGP_IDENTIFIER 3 +#define LIBNET_BGP4_UNSUPPORTED_OPTIONAL_PARAMETER 4 +#define LIBNET_BGP4_AUTHENTICATION_FAILURE 5 +#define LIBNET_BGP4_UNACCEPTABLE_HOLD_TIME 6 +/* UPDATE Message Error subcodes */ +#define LIBNET_BGP4_MALFORMED_ATTRIBUTE_LIST +#define LIBNET_BGP4_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE +#define LIBNET_BGP4_MISSING_WELL_KNOWN_ATTRIBUTE +#define LIBNET_BGP4_ATTRIBUTE_FLAGS_ERROR +#define LIBNET_BGP4_ATTRIBUTE_LENGTH_ERROR +#define LIBNET_BGP4_INVALID_ORIGIN_ATTRIBUTE +#define LIBNET_BGP4_AS_ROUTING_LOOP +#define LIBNET_BGP4_INVALID_NEXT_HOP_ATTRIBUTE +#define LIBNET_BGP4_OPTIONAL_ATTRIBUTE_ERROR +#define LIBNET_BGP4_INVALID_NETWORK_FIELD +#define LIBNET_BGP4_MALFORMED_AS_PATH + u_int8_t err_subcode; +}; + + + +/* + * CDP header + * Cisco Discovery Protocol + * Base header size: 8 bytes + */ + +/* + * For checksum stuff -- IANA says 135-254 is "unassigned" as of 12.2001. + * Let's hope this one stays that way for a while! + */ +#define LIBNET_PROTO_CDP 200 +struct libnet_cdp_hdr +{ + u_int8_t cdp_version; /* version (should always be 0x01) */ + u_int8_t cdp_ttl; /* time reciever should hold info in this packet */ + u_int16_t cdp_sum; /* checksum */ + u_int16_t cdp_type; /* type */ +#define LIBNET_CDP_DEVID 0x1 /* device id */ +#define LIBNET_CDP_ADDRESS 0x2 /* address */ +#define LIBNET_CDP_PORTID 0x3 /* port id */ +#define LIBNET_CDP_CAPABIL 0x4 /* capabilities */ +#define LIBNET_CDP_VERSION 0x5 /* version */ +#define LIBNET_CDP_PLATFORM 0x6 /* platform */ +#define LIBNET_CDP_IPPREFIX 0x7 /* ip prefix */ + u_int16_t cdp_len; /* type + length + value */ + /* value information done dynamically */ + +/* CDP capabilities */ +#define LIBNET_CDP_CAP_L3R 0x01/* performs level 3 routing */ +#define LIBNET_CDP_CAP_L2B 0x02/* performs level 2 transparent bridging */ +#define LIBNET_CDP_CAP_L2SRB 0x04/* performs level 2 sourceroute bridging */ +#define LIBNET_CDP_CAP_L2S 0x08/* performs level 2 switching */ +#define LIBNET_CDP_CAP_SR 0x10/* sends and recieves packets on a network */ +#define LIBNET_CDP_CAP_NOI 0x20/* does not forward IGMP on non-router ports */ +#define LIBNET_CDP_CAP_L1F 0x40/* provides level 1 functionality */ +}; + + +/* + * Used as an overlay for type/len/values + */ +struct libnet_cdp_value_hdr +{ + u_int16_t cdp_type; + u_int16_t cdp_len; +}; + + +/* + * DHCP header + * Dynamic Host Configuration Protocol + * Static header size: f0 bytes + */ +struct libnet_dhcpv4_hdr +{ + u_int8_t dhcp_opcode; /* opcode */ +#define LIBNET_DHCP_REQUEST 0x1 +#define LIBNET_DHCP_REPLY 0x2 + u_int8_t dhcp_htype; /* hardware address type */ + u_int8_t dhcp_hlen; /* hardware address length */ + u_int8_t dhcp_hopcount; /* used by proxy servers */ + u_int32_t dhcp_xid; /* transaction ID */ + u_int16_t dhcp_secs; /* number of seconds since trying to bootstrap */ + u_int16_t dhcp_flags; /* flags for DHCP, unused for BOOTP */ + u_int32_t dhcp_cip; /* client's IP */ + u_int32_t dhcp_yip; /* your IP */ + u_int32_t dhcp_sip; /* server's IP */ + u_int32_t dhcp_gip; /* gateway IP */ + u_int8_t dhcp_chaddr[16]; /* client hardware address */ + u_int8_t dhcp_sname[64]; /* server host name */ + u_int8_t dhcp_file[128]; /* boot file name */ + u_int32_t dhcp_magic; /* BOOTP magic header */ +#define DHCP_MAGIC 0x63825363 +#define LIBNET_BOOTP_MIN_LEN 0x12c +#define LIBNET_DHCP_PAD 0x00 +#define LIBNET_DHCP_SUBNETMASK 0x01 +#define LIBNET_DHCP_TIMEOFFSET 0x02 +#define LIBNET_DHCP_ROUTER 0x03 +#define LIBNET_DHCP_TIMESERVER 0x04 +#define LIBNET_DHCP_NAMESERVER 0x05 +#define LIBNET_DHCP_DNS 0x06 +#define LIBNET_DHCP_LOGSERV 0x07 +#define LIBNET_DHCP_COOKIESERV 0x08 +#define LIBNET_DHCP_LPRSERV 0x09 +#define LIBNET_DHCP_IMPSERV 0x0a +#define LIBNET_DHCP_RESSERV 0x0b +#define LIBNET_DHCP_HOSTNAME 0x0c +#define LIBNET_DHCP_BOOTFILESIZE 0x0d +#define LIBNET_DHCP_DUMPFILE 0x0e +#define LIBNET_DHCP_DOMAINNAME 0x0f +#define LIBNET_DHCP_SWAPSERV 0x10 +#define LIBNET_DHCP_ROOTPATH 0x11 +#define LIBNET_DHCP_EXTENPATH 0x12 +#define LIBNET_DHCP_IPFORWARD 0x13 +#define LIBNET_DHCP_SRCROUTE 0x14 +#define LIBNET_DHCP_POLICYFILTER 0x15 +#define LIBNET_DHCP_MAXASMSIZE 0x16 +#define LIBNET_DHCP_IPTTL 0x17 +#define LIBNET_DHCP_MTUTIMEOUT 0x18 +#define LIBNET_DHCP_MTUTABLE 0x19 +#define LIBNET_DHCP_MTUSIZE 0x1a +#define LIBNET_DHCP_LOCALSUBNETS 0x1b +#define LIBNET_DHCP_BROADCASTADDR 0x1c +#define LIBNET_DHCP_DOMASKDISCOV 0x1d +#define LIBNET_DHCP_MASKSUPPLY 0x1e +#define LIBNET_DHCP_DOROUTEDISC 0x1f +#define LIBNET_DHCP_ROUTERSOLICIT 0x20 +#define LIBNET_DHCP_STATICROUTE 0x21 +#define LIBNET_DHCP_TRAILERENCAP 0x22 +#define LIBNET_DHCP_ARPTIMEOUT 0x23 +#define LIBNET_DHCP_ETHERENCAP 0x24 +#define LIBNET_DHCP_TCPTTL 0x25 +#define LIBNET_DHCP_TCPKEEPALIVE 0x26 +#define LIBNET_DHCP_TCPALIVEGARBAGE 0x27 +#define LIBNET_DHCP_NISDOMAIN 0x28 +#define LIBNET_DHCP_NISSERVERS 0x29 +#define LIBNET_DHCP_NISTIMESERV 0x2a +#define LIBNET_DHCP_VENDSPECIFIC 0x2b +#define LIBNET_DHCP_NBNS 0x2c +#define LIBNET_DHCP_NBDD 0x2d +#define LIBNET_DHCP_NBTCPIP 0x2e +#define LIBNET_DHCP_NBTCPSCOPE 0x2f +#define LIBNET_DHCP_XFONT 0x30 +#define LIBNET_DHCP_XDISPLAYMGR 0x31 +#define LIBNET_DHCP_DISCOVERADDR 0x32 +#define LIBNET_DHCP_LEASETIME 0x33 +#define LIBNET_DHCP_OPTIONOVERLOAD 0x34 +#define LIBNET_DHCP_MESSAGETYPE 0x35 +#define LIBNET_DHCP_SERVIDENT 0x36 +#define LIBNET_DHCP_PARAMREQUEST 0x37 +#define LIBNET_DHCP_MESSAGE 0x38 +#define LIBNET_DHCP_MAXMSGSIZE 0x39 +#define LIBNET_DHCP_RENEWTIME 0x3a +#define LIBNET_DHCP_REBINDTIME 0x3b +#define LIBNET_DHCP_CLASSSID 0x3c +#define LIBNET_DHCP_CLIENTID 0x3d +#define LIBNET_DHCP_NISPLUSDOMAIN 0x40 +#define LIBNET_DHCP_NISPLUSSERVERS 0x41 +#define LIBNET_DHCP_MOBILEIPAGENT 0x44 +#define LIBNET_DHCP_SMTPSERVER 0x45 +#define LIBNET_DHCP_POP3SERVER 0x46 +#define LIBNET_DHCP_NNTPSERVER 0x47 +#define LIBNET_DHCP_WWWSERVER 0x48 +#define LIBNET_DHCP_FINGERSERVER 0x49 +#define LIBNET_DHCP_IRCSERVER 0x4a +#define LIBNET_DHCP_STSERVER 0x4b +#define LIBNET_DHCP_STDASERVER 0x4c +#define LIBNET_DHCP_END 0xff + +#define LIBNET_DHCP_MSGDISCOVER 0x01 +#define LIBNET_DHCP_MSGOFFER 0x02 +#define LIBNET_DHCP_MSGREQUEST 0x03 +#define LIBNET_DHCP_MSGDECLINE 0x04 +#define LIBNET_DHCP_MSGACK 0x05 +#define LIBNET_DHCP_MSGNACK 0x06 +#define LIBNET_DHCP_MSGRELEASE 0x07 +#define LIBNET_DHCP_MSGINFORM 0x08 +}; + + +/* + * Base DNSv4 header + * Domain Name System + * Base header size: 12/14 bytes + */ +/* this little guy got left out in the cold */ +#define LIBNET_DNS_H LIBNET_UDP_DNSV4_H +struct libnet_dnsv4_hdr +{ + u_int16_t h_len; /* length of the packet - only used with TCP */ + u_int16_t id; /* DNS packet ID */ + u_int16_t flags; /* DNS flags */ + u_int16_t num_q; /* Number of questions */ + u_int16_t num_answ_rr; /* Number of answer resource records */ + u_int16_t num_auth_rr; /* Number of authority resource records */ + u_int16_t num_addi_rr; /* Number of additional resource records */ +}; + + +/* + * Ethernet II header + * Static header size: 14 bytes + */ +struct libnet_ethernet_hdr +{ + u_int8_t ether_dhost[ETHER_ADDR_LEN];/* destination ethernet address */ + u_int8_t ether_shost[ETHER_ADDR_LEN];/* source ethernet address */ + u_int16_t ether_type; /* protocol */ +}; + +#ifndef ETHERTYPE_PUP +#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ +#endif +#ifndef ETHERTYPE_IP +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#endif +#ifndef ETHERTYPE_ARP +#define ETHERTYPE_ARP 0x0806 /* addr. resolution protocol */ +#endif +#ifndef ETHERTYPE_REVARP +#define ETHERTYPE_REVARP 0x8035 /* reverse addr. resolution protocol */ +#endif +#ifndef ETHERTYPE_VLAN +#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */ +#endif +#ifndef ETHERTYPE_EAP +#define ETHERTYPE_EAP 0x888e /* IEEE 802.1X EAP authentication */ +#endif +#ifndef ETHERTYPE_MPLS +#define ETHERTYPE_MPLS 0x8847 /* MPLS */ +#endif +#ifndef ETHERTYPE_LOOPBACK +#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */ +#endif + +struct libnet_ether_addr +{ + u_int8_t ether_addr_octet[6]; /* Ethernet address */ +}; + +/* + * Fiber Distributed Data Interface header + * + * Static header size: 21 bytes (LLC and 48-bit address addr only) + * + * Note: Organization field is 3 bytes which throws off the + * alignment of type. Therefore fddi_type (19 bytes in) + * is specified as two u_int8_ts. + */ +struct libnet_fddi_hdr +{ + u_int8_t fddi_frame_control; /* Class/Format/Priority */ +#define LIBNET_FDDI_LLC_FRAME 0x10 +#define LIBNET_FDDI_48BIT_ADDR 0x40 +#define LIBNET_FDDI_FC_REQD LIBNET_FDDI_LLC_FRAME | LIBNET_FDDI_48BIT_ADDR + u_int8_t fddi_dhost[FDDI_ADDR_LEN]; /* destination fddi address */ + u_int8_t fddi_shost[FDDI_ADDR_LEN]; /* source fddi address */ + u_int8_t fddi_llc_dsap; /* DSAP */ + u_int8_t fddi_llc_ssap; /* SSAP */ + u_int8_t fddi_llc_control_field; /* Class/Format/Priority */ + u_int8_t fddi_llc_org_code[LIBNET_ORG_CODE_SIZE]; /* Organization Code 3-bytes */ + u_int8_t fddi_type; /* Protocol Type */ + u_int8_t fddi_type1; /* see note above. */ +#define FDDI_TYPE_IP 0x0800 /* IP protocol */ +#define FDDI_TYPE_ARP 0x0806 /* addr. resolution protocol */ +#define FDDI_TYPE_REVARP 0x8035 /* reverse addr. resolution protocol */ +}; + + +struct libnet_fddi_addr +{ + u_int8_t fddi_addr_octet[6]; /* FDDI address */ +}; + + +/* + * GRE header - RFC 1701 & 2637 + * Generic Routing Encapsulation (GRE) + * Base header size: 4 bytes + */ +struct libnet_gre_hdr +{ + u_int16_t flags_ver; +#define GRE_CSUM 0x8000 +#define GRE_ROUTING 0x4000 +#define GRE_KEY 0x2000 +#define GRE_SEQ 0x1000 +#define GRE_STRICT 0x0800 +#define GRE_REC 0x0700 +#define GRE_ACK 0x0080 + +#define GRE_FLAGS_MASK 0x00F8 +#define GRE_VERSION_MASK 0x0007 + +#define GRE_VERSION_0 0x0000 +#define GRE_VERSION_1 0x0001 + + u_int16_t type; +#define GRE_SNA 0x0004 +#define GRE_OSI_NETWORK_LAYER 0x00FE +#define GRE_PUP 0x0200 +#define GRE_XNS 0x0600 +#define GRE_IP 0x0800 +#define GRE_CHAOS 0x0804 +#define GRE_RFC_826_ARP 0x0806 +#define GRE_FRAME_RELAY_ARP 0x0808 +#define GRE_VINES 0x0BAD +#define GRE_VINES_ECHO 0x0BAE +#define GRE_VINES_LOOPBACK 0x0BAF +#define GRE_DECNET 0x6003 +#define GRE_TRANSPARENT_ETHERNET_BRIDGING 0x6558 +#define GRE_RAW_FRAME_RELAY 0x6559 +#define GRE_APOLLO_DOMAIN 0x8019 +#define GRE_ETHERTALK 0x809B +#define GRE_NOVELL_IPX 0x8137 +#define GRE_RFC_1144_TCP_IP_COMPRESSION 0x876B +#define GRE_IP_AUTONOMOUS_SYSTEMS 0x876C +#define GRE_SECURE_DATA 0x876D +#define GRE_PPP 0x880b /* taken from RFC 2637 */ + + union { + struct { + u_int16_t sum; /* optional */ + u_int16_t offset; /* optional */ + u_int32_t key; /* optional */ + u_int32_t seq; /* optional */ + } _gre; + + struct { + u_int16_t payload_s; /* optional */ + u_int16_t callID; /* optional */ + u_int32_t seq; /* optional */ + u_int32_t ack; /* optional */ + } _egre; + }_data; + +#define gre_sum _data._gre.sum +#define gre_offset _data._gre.offset +#define gre_key _data._gre.key +#define gre_seq _data._gre.seq + +#define egre_payload_s _data._egre.payload_s +#define egre_callID _data._egre.callID +#define egre_seq _data._egre.seq +#define egre_ack _data._egre.ack +}; + + +#ifndef IPPROTO_GRE +#define IPPROTO_GRE 47 +#endif + +/* + * Source Route Entries (SRE) + * This is used for GRE as the Routing field is a list of SREs - RFC 1701 + * Base header size: 4 bytes + */ +struct libnet_gre_sre_hdr +{ + u_int16_t af; /* address familly */ + u_int8_t sre_offset; + u_int8_t sre_length; + u_int8_t *routing; +}; + + +/* + * IPv4 header + * Internet Protocol, version 4 + * Static header size: 20 bytes + */ +struct libnet_ipv4_hdr +{ +#if (LIBNET_LIL_ENDIAN) + u_int8_t ip_hl:4, /* header length */ + ip_v:4; /* version */ +#endif +#if (LIBNET_BIG_ENDIAN) + u_int8_t ip_v:4, /* version */ + ip_hl:4; /* header length */ +#endif + u_int8_t ip_tos; /* type of service */ +#ifndef IPTOS_LOWDELAY +#define IPTOS_LOWDELAY 0x10 +#endif +#ifndef IPTOS_THROUGHPUT +#define IPTOS_THROUGHPUT 0x08 +#endif +#ifndef IPTOS_RELIABILITY +#define IPTOS_RELIABILITY 0x04 +#endif +#ifndef IPTOS_LOWCOST +#define IPTOS_LOWCOST 0x02 +#endif + u_int16_t ip_len; /* total length */ + u_int16_t ip_id; /* identification */ + u_int16_t ip_off; +#ifndef IP_RF +#define IP_RF 0x8000 /* reserved fragment flag */ +#endif +#ifndef IP_DF +#define IP_DF 0x4000 /* dont fragment flag */ +#endif +#ifndef IP_MF +#define IP_MF 0x2000 /* more fragments flag */ +#endif +#ifndef IP_OFFMASK +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ +#endif + u_int8_t ip_ttl; /* time to live */ + u_int8_t ip_p; /* protocol */ + u_int16_t ip_sum; /* checksum */ + struct in_addr ip_src, ip_dst; /* source and dest address */ +}; + +/* + * IP options + */ +#ifndef IPOPT_EOL +#define IPOPT_EOL 0 /* end of option list */ +#endif +#ifndef IPOPT_NOP +#define IPOPT_NOP 1 /* no operation */ +#endif +#ifndef IPOPT_RR +#define IPOPT_RR 7 /* record packet route */ +#endif +#ifndef IPOPT_TS +#define IPOPT_TS 68 /* timestamp */ +#endif +#ifndef IPOPT_SECURITY +#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ +#endif +#ifndef IPOPT_LSRR +#define IPOPT_LSRR 131 /* loose source route */ +#endif +#ifndef IPOPT_SATID +#define IPOPT_SATID 136 /* satnet id */ +#endif +#ifndef IPOPT_SSRR +#define IPOPT_SSRR 137 /* strict source route */ +#endif + +struct libnet_in6_addr +{ + union + { + u_int8_t __u6_addr8[16]; + u_int16_t __u6_addr16[8]; + u_int32_t __u6_addr32[4]; + } __u6_addr; /* 128-bit IP6 address */ +}; +#define libnet_s6_addr __u6_addr.__u6_addr8 + +/* + * IPv6 header + * Internet Protocol, version 6 + * Static header size: 40 bytes + */ +struct libnet_ipv6_hdr +{ + u_int8_t ip_flags[4]; /* version, traffic class, flow label */ + u_int16_t ip_len; /* total length */ + u_int8_t ip_nh; /* next header */ + u_int8_t ip_hl; /* hop limit */ + struct libnet_in6_addr ip_src, ip_dst; /* source and dest address */ + +}; + +/* + * IPv6 frag header + * Internet Protocol, version 6 + * Static header size: 8 bytes + */ +#define LIBNET_IPV6_NH_FRAGMENT 44 +struct libnet_ipv6_frag_hdr +{ + u_int8_t ip_nh; /* next header */ + u_int8_t ip_reserved; /* reserved */ + u_int16_t ip_frag; /* fragmentation stuff */ + u_int32_t ip_id; /* id */ +}; + +/* + * IPv6 routing header + * Internet Protocol, version 6 + * Base header size: 4 bytes + */ +#define LIBNET_IPV6_NH_ROUTING 43 +struct libnet_ipv6_routing_hdr +{ + u_int8_t ip_nh; /* next header */ + u_int8_t ip_len; /* length of header in 8 octet units (sans 1st) */ + u_int8_t ip_rtype; /* routing type */ + u_int8_t ip_segments; /* segments left */ + /* routing information allocated dynamically */ +}; + +/* + * IPv6 destination options header + * Internet Protocol, version 6 + * Base header size: 2 bytes + */ +#define LIBNET_IPV6_NH_DESTOPTS 60 +struct libnet_ipv6_destopts_hdr +{ + u_int8_t ip_nh; /* next header */ + u_int8_t ip_len; /* length of header in 8 octet units (sans 1st) */ + /* destination options information allocated dynamically */ +}; + +/* + * IPv6 hop by hop options header + * Internet Protocol, version 6 + * Base header size: 2 bytes + */ +#define LIBNET_IPV6_NH_HBH 0 +struct libnet_ipv6_hbhopts_hdr +{ + u_int8_t ip_nh; /* next header */ + u_int8_t ip_len; /* length of header in 8 octet units (sans 1st) */ + /* destination options information allocated dynamically */ +}; + +/* + * ICMP6 header + * Internet Control Message Protocol v6 + * Base header size: 8 bytes + */ +#ifndef IPPROTO_ICMP6 +#define IPPROTO_ICMP6 0x3a +#endif +struct libnet_icmpv6_hdr +{ + u_int8_t icmp_type; /* ICMP type */ +#ifndef ICMP6_ECHO +#define ICMP6_ECHO 128 +#endif +#ifndef ICMP6_ECHOREPLY +#define ICMP6_ECHOREPLY 129 +#endif +#ifndef ICMP6_UNREACH +#define ICMP6_UNREACH 1 +#endif +#ifndef ICMP6_PKTTOOBIG +#define ICMP6_PKTTOOBIG 2 +#endif +#ifndef ICMP6_TIMXCEED +#define ICMP6_TIMXCEED 3 +#endif +#ifndef ICMP6_PARAMPROB +#define ICMP6_PARAMPROB 4 +#endif + u_int8_t icmp_code; /* ICMP code */ + u_int16_t icmp_sum; /* ICMP Checksum */ + u_int16_t id; /* ICMP id */ + u_int16_t seq; /* ICMP sequence number */ +}; + + + +/* + * ICMP header + * Internet Control Message Protocol + * Base header size: 4 bytes + */ +struct libnet_icmpv4_hdr +{ + u_int8_t icmp_type; /* ICMP type */ +#ifndef ICMP_ECHOREPLY +#define ICMP_ECHOREPLY 0 +#endif +#ifndef ICMP_UNREACH +#define ICMP_UNREACH 3 +#endif +#ifndef ICMP_SOURCEQUENCH +#define ICMP_SOURCEQUENCH 4 +#endif +#ifndef ICMP_REDIRECT +#define ICMP_REDIRECT 5 +#endif +#ifndef ICMP_ECHO +#define ICMP_ECHO 8 +#endif +#ifndef ICMP_ROUTERADVERT +#define ICMP_ROUTERADVERT 9 +#endif +#ifndef ICMP_ROUTERSOLICIT +#define ICMP_ROUTERSOLICIT 10 +#endif +#ifndef ICMP_TIMXCEED +#define ICMP_TIMXCEED 11 +#endif +#ifndef ICMP_PARAMPROB +#define ICMP_PARAMPROB 12 +#endif +#ifndef ICMP_TSTAMP +#define ICMP_TSTAMP 13 +#endif +#ifndef ICMP_TSTAMPREPLY +#define ICMP_TSTAMPREPLY 14 +#endif +#ifndef ICMP_IREQ +#define ICMP_IREQ 15 +#endif +#ifndef ICMP_IREQREPLY +#define ICMP_IREQREPLY 16 +#endif +#ifndef ICMP_MASKREQ +#define ICMP_MASKREQ 17 +#endif +#ifndef ICMP_MASKREPLY +#define ICMP_MASKREPLY 18 +#endif + u_int8_t icmp_code; /* ICMP code */ +#ifndef ICMP_UNREACH_NET +#define ICMP_UNREACH_NET 0 +#endif +#ifndef ICMP_UNREACH_HOST +#define ICMP_UNREACH_HOST 1 +#endif +#ifndef ICMP_UNREACH_PROTOCOL +#define ICMP_UNREACH_PROTOCOL 2 +#endif +#ifndef ICMP_UNREACH_PORT +#define ICMP_UNREACH_PORT 3 +#endif +#ifndef ICMP_UNREACH_NEEDFRAG +#define ICMP_UNREACH_NEEDFRAG 4 +#endif +#ifndef ICMP_UNREACH_SRCFAIL +#define ICMP_UNREACH_SRCFAIL 5 +#endif +#ifndef ICMP_UNREACH_NET_UNKNOWN +#define ICMP_UNREACH_NET_UNKNOWN 6 +#endif +#ifndef ICMP_UNREACH_HOST_UNKNOWN +#define ICMP_UNREACH_HOST_UNKNOWN 7 +#endif +#ifndef ICMP_UNREACH_ISOLATED +#define ICMP_UNREACH_ISOLATED 8 +#endif +#ifndef ICMP_UNREACH_NET_PROHIB +#define ICMP_UNREACH_NET_PROHIB 9 +#endif +#ifndef ICMP_UNREACH_HOST_PROHIB +#define ICMP_UNREACH_HOST_PROHIB 10 +#endif +#ifndef ICMP_UNREACH_TOSNET +#define ICMP_UNREACH_TOSNET 11 +#endif +#ifndef ICMP_UNREACH_TOSHOST +#define ICMP_UNREACH_TOSHOST 12 +#endif +#ifndef ICMP_UNREACH_FILTER_PROHIB +#define ICMP_UNREACH_FILTER_PROHIB 13 +#endif +#ifndef ICMP_UNREACH_HOST_PRECEDENCE +#define ICMP_UNREACH_HOST_PRECEDENCE 14 +#endif +#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF +#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 +#endif +#ifndef ICMP_REDIRECT_NET +#define ICMP_REDIRECT_NET 0 +#endif +#ifndef ICMP_REDIRECT_HOST +#define ICMP_REDIRECT_HOST 1 +#endif +#ifndef ICMP_REDIRECT_TOSNET +#define ICMP_REDIRECT_TOSNET 2 +#endif +#ifndef ICMP_REDIRECT_TOSHOST +#define ICMP_REDIRECT_TOSHOST 3 +#endif +#ifndef ICMP_TIMXCEED_INTRANS +#define ICMP_TIMXCEED_INTRANS 0 +#endif +#ifndef ICMP_TIMXCEED_REASS +#define ICMP_TIMXCEED_REASS 1 +#endif +#ifndef ICMP_PARAMPROB_OPTABSENT +#define ICMP_PARAMPROB_OPTABSENT 1 +#endif + + u_int16_t icmp_sum; /* ICMP Checksum */ + + union + { + struct + { + u_int16_t id; /* ICMP id */ + u_int16_t seq;/* ICMP sequence number */ + } echo; + +#undef icmp_id +#undef icmp_seq +#define icmp_id hun.echo.id +#define icmp_seq hun.echo.seq + + u_int32_t gateway; /* gateway host */ + struct + { + u_int16_t pad;/* padding */ + u_int16_t mtu;/* MTU size */ + } frag; + } hun; + union + { + struct + { + n_time its_otime; + n_time its_rtime; + n_time its_ttime; + } ts; + struct + { + struct libnet_ipv4_hdr idi_ip; + /* options and then 64 bits of data */ + } ip; + u_int32_t mask; + int8_t data[1]; + +#undef icmp_mask +#define icmp_mask dun.mask +#undef icmp_data +#define icmp_data dun.data + +#undef icmp_otime +#define icmp_otime dun.ts.its_otime +#undef icmp_rtime +#define icmp_rtime dun.ts.its_rtime +#undef icmp_ttime +#define icmp_ttime dun.ts.its_ttime + }dun; +}; + + +/* + * IGMP header + * Internet Group Message Protocol + * Static header size: 8 bytes + */ +struct libnet_igmp_hdr +{ + u_int8_t igmp_type; /* IGMP type */ +#ifndef IGMP_MEMBERSHIP_QUERY +#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */ +#endif +#ifndef IGMP_V1_MEMBERSHIP_REPORT +#define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */ +#endif +#ifndef IGMP_V2_MEMBERSHIP_REPORT +#define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */ +#endif +#ifndef IGMP_LEAVE_GROUP +#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */ +#endif + u_int8_t igmp_code; /* IGMP code */ + u_int16_t igmp_sum; /* IGMP checksum */ + struct in_addr igmp_group;/* IGMP host IP */ +}; + + +/* + * IPSEC header + * Internet Protocol Security Protocol + * Encapsulating Security Payload Header Static header size: 12 bytes + * Encapsulating Security Payload Footer Base header size: 2 bytes + * Authentication Header Static Size: 16 bytes + */ +#ifndef IPPROTO_ESP +#define IPPROTO_ESP 50 /* not everyone's got this */ +#endif +struct libnet_esp_hdr +{ + u_int32_t esp_spi; /* security parameter index */ + u_int32_t esp_seq; /* ESP sequence number */ + u_int32_t esp_iv; /* initialization vector */ +}; + +struct libnet_esp_ftr +{ + u_int8_t esp_pad_len; /* padding length */ + u_int8_t esp_nh; /* next header pointer */ + int8_t *esp_auth; /* authentication data */ +}; + +#ifndef IPPROTO_AH +#define IPPROTO_AH 51 /* not everyone's got this */ +#endif +struct libnet_ah_hdr +{ + u_int8_t ah_nh; /* next header */ + u_int8_t ah_len; /* payload length */ + u_int16_t ah_res; /* reserved */ + u_int32_t ah_spi; /* security parameter index */ + u_int32_t ah_seq; /* AH sequence number */ + u_int32_t ah_auth; /* authentication data */ +}; + + +/* + * ISL header + * Cisco Inter-Switch Link + * Static header size: 26 bytes + */ +/* + * For checksum stuff -- IANA says 135-254 is "unassigned" as of 12.2001. + * Let's hope this one stays that way for a while! + */ +#define LIBNET_PROTO_ISL 201 +struct libnet_isl_hdr +{ + u_int8_t isl_dhost[5]; /* destination address "01:00:0c:00:00" */ +#if (LIBNET_LIL_ENDIAN) + u_int8_t isl_type:4, /* type of frame */ + isl_user:4; /* user defined bits */ +#endif +#if (LIBNET_BIG_ENDIAN) + u_int8_t isl_user:4, /* user defined bits */ + isl_type:4; /* type of frame */ +#endif + u_int8_t isl_shost[6]; /* source address */ + u_int16_t isl_len; /* total length of packet - 18 bytes */ + u_int8_t isl_snap[6]; /* 0xaaaa03 + vendor code */ + u_int16_t isl_vid; /* 15 bit VLAN ID, 1 bit BPDU / CDP indicator */ + u_int16_t isl_index; /* port index */ + u_int16_t isl_reserved; /* used for FDDI and token ring */ + /* ethernet frame and 4 byte isl crc */ +}; + +#ifndef IPPROTO_OSPF +#define IPPROTO_OSPF 89 /* not everyone's got this */ +#endif +#define IPPROTO_OSPF_LSA 890 /* made this up. Hope it's unused */ +#define LIBNET_MODX 4102 /* used in LSA checksum */ + +/* + * Options used in multiple OSPF packets + * More info can be found in section A.2 of RFC 2328. + */ +#define LIBNET_OPT_EBIT 0x02 /* describes the way AS-external-LSAs are flooded */ +#define LIBNET_OPT_MCBIT 0x04 /* whether or not IP multicast dgrams are fwdd */ +#define LIBNET_OPT_NPBIT 0x08 /* describes handling of type-7 LSAs */ +#define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */ +#define LIBNET_OPT_DCBIT 0x20 /* describes handling of demand circuits */ + + +/* + * MPLS header + * Multi-Protocol Label Switching + * Static header size: 4 bytes + */ +struct libnet_mpls_hdr +{ + u_int32_t mpls_les; /* 20 bits label, 3 bits exp, 1 bit bos, ttl */ +#define LIBNET_MPLS_BOS_ON 1 +#define LIBNET_MPLS_BOS_OFF 0 +}; + +/* + * NTP header + * Network Time Protocol + * Static header size: 48 bytes + */ +struct libnet_ntp_hdr_l_fp /* int32_t floating point (64-bit) */ +{ + u_int32_t integer; /* integer */ + u_int32_t fraction; /* fraction */ +}; + +struct libnet_ntp_hdr_s_fp /* int16_t floating point (32-bit) */ +{ + u_int16_t integer; /* integer */ + u_int16_t fraction; /* fraction */ +}; + + +struct libnet_ntp_hdr +{ + u_int8_t ntp_li_vn_mode; /* leap indicator, version, mode */ +#define LIBNET_NTP_LI_NW 0x0 /* no warning */ +#define LIBNET_NTP_LI_AS 0x1 /* last minute has 61 seconds */ +#define LIBNET_NTP_LI_DS 0x2 /* last minute has 59 seconds */ +#define LIBNET_NTP_LI_AC 0x3 /* alarm condition */ + +#define LIBNET_NTP_VN_2 0x2 /* version 2 */ +#define LIBNET_NTP_VN_3 0x3 /* version 3 */ +#define LIBNET_NTP_VN_4 0x4 /* version 4 */ + +#define LIBNET_NTP_MODE_R 0x0 /* reserved */ +#define LIBNET_NTP_MODE_A 0x1 /* symmetric active */ +#define LIBNET_NTP_MODE_P 0x2 /* symmetric passive */ +#define LIBNET_NTP_MODE_C 0x3 /* client */ +#define LIBNET_NTP_MODE_S 0x4 /* server */ +#define LIBNET_NTP_MODE_B 0x5 /* broadcast */ +#define LIBNET_NTP_MODE_RC 0x6 /* reserved for NTP control message */ +#define LIBNET_NTP_MODE_RP 0x7 /* reserved for private use */ + u_int8_t ntp_stratum; /* stratum */ +#define LIBNET_NTP_STRATUM_UNAVAIL 0x0 /* unspecified or unavailable */ +#define LIBNET_NTP_STRATUM_PRIMARY 0x1 /* primary reference (radio clock) */ + /* 2 - 15 is secondary */ + /* 16 - 255 is reserved */ + u_int8_t ntp_poll; /* poll interval (should be 4 - 12) */ + u_int8_t ntp_precision; /* local clock precision */ + struct libnet_ntp_hdr_s_fp ntp_delay; /* roundtrip delay */ + struct libnet_ntp_hdr_s_fp ntp_dispersion; /* nominal error */ + u_int32_t ntp_reference_id; /* reference source id */ +#define LIBNET_NTP_REF_LOCAL 0x4c4f434c /* uncalibrated local clock */ +#define LIBNET_NTP_REF_PPS 0x50505300 /* atomic / pulse-per-second clock */ +#define LIBNET_NTP_REF_ACTS 0x41435453 /* NIST dialup modem */ +#define LIBNET_NTP_REF_USNO 0x55534e4f /* USNO modem service */ +#define LIBNET_NTP_REF_PTB 0x50544200 /* PTB (German) modem service */ +#define LIBNET_NTP_REF_TDF 0x54444600 /* Allouis (French) radio */ +#define LIBNET_NTP_REF_DCF 0x44434600 /* Mainflingen (German) radio */ +#define LIBNET_NTP_REF_MSF 0x4d534600 /* Rugby (UK) radio */ +#define LIBNET_NTP_REF_WWV 0x57575600 /* Ft Collins (US) radio */ +#define LIBNET_NTP_REF_WWVB 0x57575642 /* Boulder (US) radio */ +#define LIBNET_NTP_REF_WWVH 0x57575648 /* Kaui Hawaii (US) radio */ +#define LIBNET_NTP_REF_CHU 0x43485500 /* Ottaha (Canada) radio */ +#define LIBNET_NTP_REF_LORC 0x4c4f5243 /* LORAN-C radionavigation */ +#define LIBNET_NTP_REF_OMEG 0x4f4d4547 /* OMEGA radionavigation */ +#define LIBNET_NTP_REF_GPS 0x47505300 /* global positioning system */ +#define LIBNET_NTP_REF_GOES 0x474f4553 /* geostationary orbit env satellite */ + struct libnet_ntp_hdr_l_fp ntp_ref_ts; /* reference timestamp */ + struct libnet_ntp_hdr_l_fp ntp_orig_ts; /* originate timestamp */ + struct libnet_ntp_hdr_l_fp ntp_rec_ts; /* receive timestamp */ + struct libnet_ntp_hdr_l_fp ntp_xmt_ts; /* transmit timestamp */ +}; + + +/* + * OSPFv2 header + * Open Shortest Path First + * Static header size: 16 bytes + */ +struct libnet_ospf_hdr +{ + u_int8_t ospf_v; /* version */ +#define OSPFVERSION 2 + u_int8_t ospf_type; /* type */ +#define LIBNET_OSPF_UMD 0 /* UMd monitoring packet */ +#define LIBNET_OSPF_HELLO 1 /* HELLO packet */ +#define LIBNET_OSPF_DBD 2 /* dataBase description packet */ +#define LIBNET_OSPF_LSR 3 /* link state request packet */ +#define LIBNET_OSPF_LSU 4 /* link state Update Packet */ +#define LIBNET_OSPF_LSA 5 /* link state acknowledgement packet */ + u_int16_t ospf_len; /* length */ + struct in_addr ospf_rtr_id; /* source router ID */ + struct in_addr ospf_area_id;/* roam ID */ + u_int16_t ospf_sum; /* checksum */ + u_int16_t ospf_auth_type; /* authentication type */ +#define LIBNET_OSPF_AUTH_NULL 0 /* null password */ +#define LIBNET_OSPF_AUTH_SIMPLE 1 /* simple, plaintext, 8 int8_t password */ +#define LIBNET_OSPF_AUTH_MD5 2 /* MD5 */ +}; + + +/* + * OSPF authentication header + * Open Shortest Path First + * Static header size: 8 bytes + */ +struct libnet_auth_hdr +{ + u_int16_t ospf_auth_null; /* NULL */ + u_int8_t ospf_auth_keyid; /* authentication key ID */ + u_int8_t ospf_auth_len; /* auth data length */ + u_int ospf_auth_seq; /* cryptographic sequence number */ +}; + + +/* + * OSPF hello header + * Open Shortest Path First + * Static header size: 28 bytes + */ +struct libnet_ospf_hello_hdr +{ + struct in_addr hello_nmask; /* netmask associated with the interface */ + u_int16_t hello_intrvl; /* num of seconds between routers last packet */ + u_int8_t hello_opts; /* Options for HELLO packets (look above) */ + u_int8_t hello_rtr_pri; /* router's priority (if 0, can't be backup) */ + u_int hello_dead_intvl; /* # of secs a router is silent till deemed down */ + struct in_addr hello_des_rtr; /* Designated router on the network */ + struct in_addr hello_bkup_rtr; /* Backup router */ + struct in_addr hello_nbr; /* neighbor router, memcpy more as needed */ +}; + + +/* + * Database Description header. + */ +struct libnet_dbd_hdr +{ + u_int16_t dbd_mtu_len; /* max length of IP dgram that this 'if' can use */ + u_int8_t dbd_opts; /* DBD packet options (from above) */ + u_int8_t dbd_type; /* type of exchange occurring */ +#define LIBNET_DBD_IBI 0x01 /* init */ +#define LIBNET_DBD_MBIT 0x02 /* more DBD packets are to come */ +#define LIBNET_DBD_MSBIT 0x04 /* If 1, sender is the master in the exchange */ + u_int dbd_seq; /* DBD sequence number */ +}; + + +/* + * used for the LS type field in all LS* headers + */ +#define LIBNET_LS_TYPE_RTR 1 /* router-LSA */ +#define LIBNET_LS_TYPE_NET 2 /* network-LSA */ +#define LIBNET_LS_TYPE_IP 3 /* summary-LSA (IP Network) */ +#define LIBNET_LS_TYPE_ASBR 4 /* summary-LSA (ASBR) */ +#define LIBNET_LS_TYPE_ASEXT 5 /* AS-external-LSA */ + + +/* + * Link State Request header + */ +struct libnet_lsr_hdr +{ + u_int lsr_type; /* type of LS being requested */ + u_int lsr_lsid; /* link state ID */ + struct in_addr lsr_adrtr; /* advertising router (memcpy more as needed) */ +}; + + +/* + * Link State Update header + */ +struct libnet_lsu_hdr +{ + u_int lsu_num; /* number of LSAs that will be broadcasted */ +}; + + +/* + * Link State Acknowledgement header. + */ +struct libnet_lsa_hdr +{ + u_int16_t lsa_age; /* time in seconds since the LSA was originated */ + u_int8_t lsa_opts; /* look above for OPTS_* */ + u_int8_t lsa_type; /* look below for LS_TYPE_* */ + u_int lsa_id; /* link State ID */ + struct in_addr lsa_adv; /* router ID of Advertising router */ + u_int lsa_seq; /* LSA sequence number to detect old/bad ones */ + u_int16_t lsa_sum; /* "Fletcher Checksum" of all fields minus age */ + u_int16_t lsa_len; /* length in bytes including the 20 byte header */ +}; + + +/* + * Router LSA data format + * + * Other stuff for TOS can be added for backward compatability, for this + * version, only OSPFv2 is being FULLY supported. + */ +struct libnet_rtr_lsa_hdr +{ + u_int16_t rtr_flags; /* set to help describe packet */ +#define LIBNET_RTR_FLAGS_W 0x0100 /* W bit */ +#define LIBNET_RTR_FLAGS_E 0x0200 /* E bit */ +#define LIBNET_RTR_FLAGS_B 0x0400 /* B bit */ + u_int16_t rtr_num; /* number of links within that packet */ + u_int rtr_link_id; /* describes link_data (look below) */ +#define LIBNET_LINK_ID_NBR_ID 1 /* Neighbors router ID, also can be 4 */ +#define LIBNET_LINK_ID_IP_DES 2 /* IP address of designated router */ +#define LIBNET_LINK_ID_SUB 3 /* IP subnet number */ + u_int rtr_link_data; /* Depending on link_id, info is here */ + u_int8_t rtr_type; /* Description of router link */ +#define LIBNET_RTR_TYPE_PTP 1 /* Point-To-Point */ +#define LIBNET_RTR_TYPE_TRANS 2 /* Connection to a "transit network" */ +#define LIBNET_RTR_TYPE_STUB 3 /* Connectin to a "stub network" */ +#define RTR_TYPE_VRTL 4 /* connects to a "virtual link" */ + u_int8_t rtr_tos_num; /* number of different TOS metrics for this link */ + u_int16_t rtr_metric; /* the "cost" of using this link */ +}; + + +/* + * Network LSA data format. + */ +struct libnet_net_lsa_hdr +{ + struct in_addr net_nmask; /* Netmask for that network */ + u_int net_rtr_id; /* ID of router attached to that network */ +}; + + +/* + * Summary LSA data format. + */ +struct libnet_sum_lsa_hdr +{ + struct in_addr sum_nmask; /* Netmask of destination IP address */ + u_int sum_metric; /* Same as in rtr_lsa (&0xfff to use last 24bit */ + u_int sum_tos_metric; /* first 8bits are TOS, 24bits are TOS Metric */ +}; + + +/* + * AS External LSA data format. + * & 0xfff logic operator for as_metric to get last 24bits. + */ +struct libnet_as_lsa_hdr +{ + struct in_addr as_nmask; /* Netmask for advertised destination */ + u_int as_metric; /* May have to set E bit in first 8bits */ +#define LIBNET_AS_E_BIT_ON 0x80000000 /* as_metric */ + struct in_addr as_fwd_addr; /* Forwarding address */ + u_int as_rte_tag; /* External route tag */ +}; + + +/* + * Base RIP header + * Routing Information Protocol + * Base header size: 24 bytes + */ +struct libnet_rip_hdr +{ + u_int8_t rip_cmd; /* RIP command */ +#define RIPCMD_REQUEST 1 /* want info */ +#define RIPCMD_RESPONSE 2 /* responding to request */ +#define RIPCMD_TRACEON 3 /* turn tracing on */ +#define RIPCMD_TRACEOFF 4 /* turn it off */ +#define RIPCMD_POLL 5 /* like request, but anyone answers */ +#define RIPCMD_POLLENTRY 6 /* like poll, but for entire entry */ +#define RIPCMD_MAX 7 /* ? command */ + u_int8_t rip_ver; /* RIP version */ +#define RIPVER_0 0 +#define RIPVER_1 1 +#define RIPVER_2 2 + u_int16_t rip_rd; /* Zero (v1) or Routing Domain (v2) */ + u_int16_t rip_af; /* Address family */ + u_int16_t rip_rt; /* Zero (v1) or Route Tag (v2) */ + u_int32_t rip_addr; /* IP address */ + u_int32_t rip_mask; /* Zero (v1) or Subnet Mask (v2) */ + u_int32_t rip_next_hop; /* Zero (v1) or Next hop IP address (v2) */ + u_int32_t rip_metric; /* Metric */ +}; + +/* + * RPC headers + * Remote Procedure Call + */ +#define LIBNET_RPC_CALL 0 +#define LIBNET_RPC_REPLY 1 +#define LIBNET_RPC_VERS 2 +#define LIBNET_RPC_LAST_FRAG 0x80000000 + +/* + * Portmap defines + */ +#define LIBNET_PMAP_PROGRAM 100000 +#define LIBNET_PMAP_PROC_NULL 0 +#define LIBNET_PMAP_PROC_SET 1 +#define LIBNET_PMAP_PROC_UNSET 2 +#define LIBNET_PMAP_PROC_GETADDR 3 +#define LIBNET_PMAP_PROC_DUMP 4 +#define LIBNET_PMAP_PROC_CALLIT 5 +#define LIBNET_PMAP_PROC_BCAST 5 /* Not a typo */ +#define LIBNET_PMAP_PROC_GETTIME 6 +#define LIBNET_PMAP_PROC_UADDR2TADDR 7 +#define LIBNET_PMAP_PROC_TADDR2UADDR 8 +#define LIBNET_PMAP_PROC_GETVERSADDR 9 +#define LIBNET_PMAP_PROC_INDIRECT 10 +#define LIBNET_PMAP_PROC_GETADDRLIST 11 +#define LIBNET_PMAP_PROC_GETSTAT 12 + +/* There will be more to add... */ + +struct libnet_rpc_opaque_auth +{ + u_int32_t rpc_auth_flavor; + u_int32_t rpc_auth_length; +// u_int8_t *rpc_auth_data; +}; + +struct libnet_rpc_call +{ + u_int32_t rpc_rpcvers; /* RPC version - must be 2 */ + u_int32_t rpc_prognum; /* Program Number */ + u_int32_t rpc_vers; /* Program Version */ + u_int32_t rpc_procedure; /* RPC procedure */ + struct libnet_rpc_opaque_auth rpc_credentials; + struct libnet_rpc_opaque_auth rpc_verifier; +}; + +struct libnet_rpc_call_hdr +{ + u_int32_t rpc_xid; /* xid (transaction identifier) */ + u_int32_t rpc_type; + struct libnet_rpc_call rpc_call; +}; + +struct libnet_rpc_call_tcp_hdr +{ + u_int32_t rpc_record_marking; /* used with byte stream protocols */ + struct libnet_rpc_call_hdr rpc_common; +}; + +/* + * STP configuration header + * Spanning Tree Protocol + * Static header size: 35 bytes + */ +struct libnet_stp_conf_hdr +{ + u_int16_t stp_id; /* protocol id */ + u_int8_t stp_version; /* protocol version */ + u_int8_t stp_bpdu_type; /* bridge protocol data unit type */ + u_int8_t stp_flags; /* control flags */ + u_int8_t stp_rootid[8]; /* root id */ + u_int32_t stp_rootpc; /* root path cost */ + u_int8_t stp_bridgeid[8]; /* bridge id */ + u_int16_t stp_portid; /* port id */ + u_int16_t stp_mage; /* message age */ + u_int16_t stp_maxage; /* max age */ + u_int16_t stp_hellot; /* hello time */ + u_int16_t stp_fdelay; /* forward delay */ +}; + + +/* + * STP topology change notification header + * Spanning Tree Protocol + * Static header size: 4 bytes + */ +struct libnet_stp_tcn_hdr +{ + u_int16_t stp_id; /* protocol id */ + u_int8_t stp_version; /* protocol version */ + u_int8_t stp_bpdu_type; /* bridge protocol data unit type */ +}; + + +/* + * TCP header + * Transmission Control Protocol + * Static header size: 20 bytes + */ +struct libnet_tcp_hdr +{ + u_int16_t th_sport; /* source port */ + u_int16_t th_dport; /* destination port */ + u_int32_t th_seq; /* sequence number */ + u_int32_t th_ack; /* acknowledgement number */ +#if (LIBNET_LIL_ENDIAN) + u_int8_t th_x2:4, /* (unused) */ + th_off:4; /* data offset */ +#endif +#if (LIBNET_BIG_ENDIAN) + u_int8_t th_off:4, /* data offset */ + th_x2:4; /* (unused) */ +#endif + u_int8_t th_flags; /* control flags */ +#ifndef TH_FIN +#define TH_FIN 0x01 /* finished send data */ +#endif +#ifndef TH_SYN +#define TH_SYN 0x02 /* synchronize sequence numbers */ +#endif +#ifndef TH_RST +#define TH_RST 0x04 /* reset the connection */ +#endif +#ifndef TH_PUSH +#define TH_PUSH 0x08 /* push data to the app layer */ +#endif +#ifndef TH_ACK +#define TH_ACK 0x10 /* acknowledge */ +#endif +#ifndef TH_URG +#define TH_URG 0x20 /* urgent! */ +#endif +#ifndef TH_ECE +#define TH_ECE 0x40 +#endif +#ifndef TH_CWR +#define TH_CWR 0x80 +#endif + u_int16_t th_win; /* window */ + u_int16_t th_sum; /* checksum */ + u_int16_t th_urp; /* urgent pointer */ +}; + +/* + * Token Ring Header + */ +struct libnet_token_ring_hdr +{ + u_int8_t token_ring_access_control; +#define LIBNET_TOKEN_RING_FRAME 0x10 + u_int8_t token_ring_frame_control; +#define LIBNET_TOKEN_RING_LLC_FRAME 0x40 + u_int8_t token_ring_dhost[TOKEN_RING_ADDR_LEN]; + u_int8_t token_ring_shost[TOKEN_RING_ADDR_LEN]; + u_int8_t token_ring_llc_dsap; + u_int8_t token_ring_llc_ssap; + u_int8_t token_ring_llc_control_field; + u_int8_t token_ring_llc_org_code[LIBNET_ORG_CODE_SIZE]; + u_int16_t token_ring_type; +#define TOKEN_RING_TYPE_IP 0x0800 /* IP protocol */ +#define TOKEN_RING_TYPE_ARP 0x0806 /* addr. resolution protocol */ +#define TOKEN_RING_TYPE_REVARP 0x8035 /* reverse addr. resolution protocol */ +}; + +struct libnet_token_ring_addr +{ + u_int8_t token_ring_addr_octet[6]; /* Token Ring address */ +}; + +/* + * UDP header + * User Data Protocol + * Static header size: 8 bytes + */ +struct libnet_udp_hdr +{ + u_int16_t uh_sport; /* soure port */ + u_int16_t uh_dport; /* destination port */ + u_int16_t uh_ulen; /* length */ + u_int16_t uh_sum; /* checksum */ +}; + +/* + * Sebek header + * Static header size: 48 bytes + */ +struct libnet_sebek_hdr +{ + u_int32_t magic; /* identify packets that should be hidden */ + u_int16_t version; /* protocol version, currently 1 */ +#define SEBEK_PROTO_VERSION 1 + u_int16_t type; /* type of record (read data is type 0, write data is type 1) */ +#define SEBEK_TYPE_READ 0 /* Currently, only read is supported */ +#define SEBEK_TYPE_WRITE 1 + u_int32_t counter; /* PDU counter used to identify when packet are lost */ + u_int32_t time_sec; /* seconds since EPOCH according to the honeypot */ + u_int32_t time_usec; /* residual microseconds */ + u_int32_t pid; /* PID */ + u_int32_t uid; /* UID */ + u_int32_t fd; /* FD */ +#define SEBEK_CMD_LENGTH 12 + u_int8_t cmd[SEBEK_CMD_LENGTH]; /* 12 first characters of the command */ + u_int32_t length; /* length in bytes of the PDU's body */ +}; + + +/* + * VRRP header + * Virtual Router Redundancy Protocol + * Static header size: 8 bytes + */ +#ifndef IPPROTO_VRRP +#define IPPROTO_VRRP 112 /* not everyone's got this */ +#endif +struct libnet_vrrp_hdr +{ +#if (LIBNET_LIL_ENDIAN) + u_int8_t vrrp_v:4, /* protocol version */ + vrrp_t:4; /* packet type */ +#endif +#if (LIBNET_BIG_ENDIAN) + u_int8_t vrrp_t:4, /* packet type */ + vrrp_v:4; /* protocol version */ +#endif +#define LIBNET_VRRP_VERSION_01 0x1 +#define LIBNET_VRRP_VERSION_02 0x2 +#define LIBNET_VRRP_TYPE_ADVERT 0x1 + u_int8_t vrrp_vrouter_id; /* virtual router id */ + u_int8_t vrrp_priority; /* priority */ + u_int8_t vrrp_ip_count; /* number of IP addresses */ + u_int8_t vrrp_auth_type; /* authorization type */ +#define LIBNET_VRRP_AUTH_NONE 0x1 +#define LIBNET_VRRP_AUTH_PASSWD 0x2 +#define LIBNET_VRRP_AUTH_IPAH 0x3 + u_int8_t vrrp_advert_int; /* advertisement interval */ + u_int16_t vrrp_sum; /* checksum */ + /* additional addresses */ + /* authentication info */ +}; + +#endif /* __LIBNET_HEADERS_H */ + +/* EOF */ diff --git a/libnet/include/libnet/libnet-macros.h b/libnet/include/libnet/libnet-macros.h new file mode 100644 index 0000000..bae6b87 --- /dev/null +++ b/libnet/include/libnet/libnet-macros.h @@ -0,0 +1,186 @@ +/* + * $Id: libnet-macros.h,v 1.6 2004/03/01 20:26:12 mike Exp $ + * + * libnet-macros.h - Network routine library macro header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_MACROS_H +#define __LIBNET_MACROS_H +/** + * @file libnet-macros.h + * @brief libnet macros and symbloc constants + */ + +/* for systems without snprintf */ +#if defined(NO_SNPRINTF) +#define snprintf(buf, len, args...) sprintf(buf, ##args) +#endif + + +/** + * Used for libnet's name resolution functions, specifies that no DNS lookups + * should be performed and the IP address should be kept in numeric form. + */ +#define LIBNET_DONT_RESOLVE 0 + +/** + * Used for libnet's name resolution functions, specifies that a DNS lookup + * can be performed if needed to resolve the IP address to a canonical form. + */ +#define LIBNET_RESOLVE 1 + +/** + * Used several places, to specify "on" or "one" + */ +#define LIBNET_ON 0 + +/** + * Used several places, to specify "on" or "one" + */ +#define LIBNET_OFF 1 + +/** + * IPv6 error code + */ +#ifndef IN6ADDR_ERROR_INIT +#define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff } } } +#endif + +/** + * Used for libnet_get_prand() to specify function disposition + */ +#define LIBNET_PR2 0 +#define LIBNET_PR8 1 +#define LIBNET_PR16 2 +#define LIBNET_PRu16 3 +#define LIBNET_PR32 4 +#define LIBNET_PRu32 5 +#define LIBNET_PRAND_MAX 0xffffffff + +/** + * The biggest an IP packet can be -- 65,535 bytes. + */ +#define LIBNET_MAX_PACKET 0xffff +#ifndef IP_MAXPACKET +#define IP_MAXPACKET 0xffff +#endif + + +/* ethernet addresses are 6 octets long */ +#ifndef ETHER_ADDR_LEN +#define ETHER_ADDR_LEN 0x6 +#endif + +/* FDDI addresses are 6 octets long */ +#ifndef FDDI_ADDR_LEN +#define FDDI_ADDR_LEN 0x6 +#endif + +/* token ring addresses are 6 octets long */ +#ifndef TOKEN_RING_ADDR_LEN +#define TOKEN_RING_ADDR_LEN 0x6 +#endif + +/* LLC Organization Code is 3 bytes long */ +#define LIBNET_ORG_CODE_SIZE 0x3 + +/** + * The libnet error buffer is 256 bytes long. + */ +#define LIBNET_ERRBUF_SIZE 0x100 + +/** + * IP and TCP options can be up to 40 bytes long. + */ +#define LIBNET_MAXOPTION_SIZE 0x28 + +/* some BSD variants have this endianess problem */ +#if (LIBNET_BSD_BYTE_SWAP) +#define FIX(n) ntohs(n) +#define UNFIX(n) htons(n) +#else +#define FIX(n) (n) +#define UNFIX(n) (n) +#endif + +/* used internally for checksum stuff */ +#define LIBNET_CKSUM_CARRY(x) \ + (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff)) + +/* used interally for OSPF stuff */ +#define LIBNET_OSPF_AUTHCPY(x, y) \ + memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y)) +#define LIBNET_OSPF_CKSUMBUF(x, y) \ + memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y)) + +/* used internally for NTP leap indicator, version, and mode */ +#define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \ + ((u_int8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7))) + +/* Not all systems have IFF_LOOPBACK */ +#ifdef IFF_LOOPBACK +#define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK) +#else +#define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0) +#endif + +/* advanced mode check */ +#define LIBNET_ISADVMODE(x) (x & 0x08) + +/* context queue macros and constants */ +#define LIBNET_LABEL_SIZE 64 +#define LIBNET_LABEL_DEFAULT "cardshark" +#define CQ_LOCK_UNLOCKED (u_int)0x00000000 +#define CQ_LOCK_READ (u_int)0x00000001 +#define CQ_LOCK_WRITE (u_int)0x00000002 + +/** + * Provides an interface to iterate through the context queue of libnet + * contexts. Before calling this macro, be sure to set the queue using + * libnet_cq_head(). + */ +#define for_each_context_in_cq(l) \ + for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) + +/* return 1 if write lock is set on cq */ +#define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE) + +/* return 1 if read lock is set on cq */ +#define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ) + +/* return 1 if any lock is set on cq */ +#define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE)) + +/* check if a context queue is locked */ +#define check_cq_lock(x) (l_cqd.cq_lock & x) + +#endif /* __LIBNET_MACROS_H */ + +/* EOF */ diff --git a/libnet/include/libnet/libnet-structures.h b/libnet/include/libnet/libnet-structures.h new file mode 100644 index 0000000..38aff5d --- /dev/null +++ b/libnet/include/libnet/libnet-structures.h @@ -0,0 +1,222 @@ +/* + * $Id: libnet-structures.h,v 1.18 2004/03/16 18:40:58 mike Exp $ + * + * libnet-structures.h - Network routine library structures header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_STRUCTURES_H +#define __LIBNET_STRUCTURES_H + +#if ((__WIN32__) && !(__CYGWIN__)) +#include "Packet32.h" +#endif + +/* port list chain structure */ +typedef struct libnet_port_list_chain libnet_plist_t; +struct libnet_port_list_chain +{ + u_int16_t node; /* node number */ + u_int16_t bport; /* beggining port */ + u_int16_t eport; /* terminating port */ + u_int8_t id; /* global array offset */ + libnet_plist_t *next; /* next node in the list */ +}; + + +/* libnet statistics structure */ +struct libnet_stats +{ +#if (!defined(__WIN32__) || (__CYGWIN__)) + u_int64_t packets_sent; /* packets sent */ + u_int64_t packet_errors; /* packets errors */ + u_int64_t bytes_written; /* bytes written */ +#else + __int64 packets_sent; /* packets sent */ + __int64 packet_errors; /* packets errors */ + __int64 bytes_written; /* bytes written */ +#endif +}; + + +/* + * Libnet ptags are how we identify specific protocol blocks inside the + * list. + */ +typedef int32_t libnet_ptag_t; +#define LIBNET_PTAG_INITIALIZER 0 + + +/* + * Libnet generic protocol block memory object. Sort of a poor man's mbuf. + */ +struct libnet_protocol_block +{ + u_int8_t *buf; /* protocol buffer */ + u_int32_t b_len; /* length of buf */ + u_int16_t h_len; /* header length (for checksumming) */ + u_int32_t ip_offset; /* offset to IP header for csums */ + u_int32_t copied; /* bytes copied */ + u_int8_t type; /* type of pblock */ +/* this needs to be updated every time a new packet builder is added */ +#define LIBNET_PBLOCK_ARP_H 0x01 /* ARP header */ +#define LIBNET_PBLOCK_DHCPV4_H 0x02 /* DHCP v4 header */ +#define LIBNET_PBLOCK_DNSV4_H 0x03 /* DNS v4 header */ +#define LIBNET_PBLOCK_ETH_H 0x04 /* Ethernet header */ +#define LIBNET_PBLOCK_ICMPV4_H 0x05 /* ICMP v4 base header */ +#define LIBNET_PBLOCK_ICMPV4_ECHO_H 0x06 /* ICMP v4 echo header */ +#define LIBNET_PBLOCK_ICMPV4_MASK_H 0x07 /* ICMP v4 mask header */ +#define LIBNET_PBLOCK_ICMPV4_UNREACH_H 0x08 /* ICMP v4 unreach header */ +#define LIBNET_PBLOCK_ICMPV4_TIMXCEED_H 0x09 /* ICMP v4 exceed header */ +#define LIBNET_PBLOCK_ICMPV4_REDIRECT_H 0x0a /* ICMP v4 redirect header */ +#define LIBNET_PBLOCK_ICMPV4_TS_H 0x0b /* ICMP v4 timestamp header */ +#define LIBNET_PBLOCK_IGMP_H 0x0c /* IGMP header */ +#define LIBNET_PBLOCK_IPV4_H 0x0d /* IP v4 header */ +#define LIBNET_PBLOCK_IPO_H 0x0e /* IP v4 options */ +#define LIBNET_PBLOCK_IPDATA 0x0f /* IP data */ +#define LIBNET_PBLOCK_OSPF_H 0x10 /* OSPF base header */ +#define LIBNET_PBLOCK_OSPF_HELLO_H 0x11 /* OSPF hello header */ +#define LIBNET_PBLOCK_OSPF_DBD_H 0x12 /* OSPF dbd header */ +#define LIBNET_PBLOCK_OSPF_LSR_H 0x13 /* OSPF lsr header */ +#define LIBNET_PBLOCK_OSPF_LSU_H 0x14 /* OSPF lsu header */ +#define LIBNET_PBLOCK_OSPF_LSA_H 0x15 /* OSPF lsa header */ +#define LIBNET_PBLOCK_OSPF_AUTH_H 0x16 /* OSPF auth header */ +#define LIBNET_PBLOCK_OSPF_CKSUM 0x17 /* OSPF checksum header */ +#define LIBNET_PBLOCK_LS_RTR_H 0x18 /* linkstate rtr header */ +#define LIBNET_PBLOCK_LS_NET_H 0x19 /* linkstate net header */ +#define LIBNET_PBLOCK_LS_SUM_H 0x1a /* linkstate as sum header */ +#define LIBNET_PBLOCK_LS_AS_EXT_H 0x1b /* linkstate as ext header */ +#define LIBNET_PBLOCK_NTP_H 0x1c /* NTP header */ +#define LIBNET_PBLOCK_RIP_H 0x1d /* RIP header */ +#define LIBNET_PBLOCK_TCP_H 0x1e /* TCP header */ +#define LIBNET_PBLOCK_TCPO_H 0x1f /* TCP options */ +#define LIBNET_PBLOCK_TCPDATA 0x20 /* TCP data */ +#define LIBNET_PBLOCK_UDP_H 0x21 /* UDP header */ +#define LIBNET_PBLOCK_VRRP_H 0x22 /* VRRP header */ +#define LIBNET_PBLOCK_DATA_H 0x23 /* generic data */ +#define LIBNET_PBLOCK_CDP_H 0x24 /* CDP header */ +#define LIBNET_PBLOCK_IPSEC_ESP_HDR_H 0x25 /* IPSEC ESP header */ +#define LIBNET_PBLOCK_IPSEC_ESP_FTR_H 0x26 /* IPSEC ESP footer */ +#define LIBNET_PBLOCK_IPSEC_AH_H 0x27 /* IPSEC AH header */ +#define LIBNET_PBLOCK_802_1Q_H 0x28 /* 802.1q header */ +#define LIBNET_PBLOCK_802_2_H 0x29 /* 802.2 header */ +#define LIBNET_PBLOCK_802_2SNAP_H 0x2a /* 802.2 SNAP header */ +#define LIBNET_PBLOCK_802_3_H 0x2b /* 802.3 header */ +#define LIBNET_PBLOCK_STP_CONF_H 0x2c /* STP configuration header */ +#define LIBNET_PBLOCK_STP_TCN_H 0x2d /* STP TCN header */ +#define LIBNET_PBLOCK_ISL_H 0x2e /* ISL header */ +#define LIBNET_PBLOCK_IPV6_H 0x2f /* IP v6 header */ +#define LIBNET_PBLOCK_802_1X_H 0x30 /* 802.1x header */ +#define LIBNET_PBLOCK_RPC_CALL_H 0x31 /* RPC Call header */ +#define LIBNET_PBLOCK_MPLS_H 0x32 /* MPLS header */ +#define LIBNET_PBLOCK_FDDI_H 0x33 /* FDDI header */ +#define LIBNET_PBLOCK_TOKEN_RING_H 0x34 /* TOKEN RING header */ +#define LIBNET_PBLOCK_BGP4_HEADER_H 0x35 /* BGP4 header */ +#define LIBNET_PBLOCK_BGP4_OPEN_H 0x36 /* BGP4 open header */ +#define LIBNET_PBLOCK_BGP4_UPDATE_H 0x37 /* BGP4 update header */ +#define LIBNET_PBLOCK_BGP4_NOTIFICATION_H 0x38 /* BGP4 notification header */ +#define LIBNET_PBLOCK_GRE_H 0x39 /* GRE header */ +#define LIBNET_PBLOCK_GRE_SRE_H 0x3a /* GRE SRE header */ +#define LIBNET_PBLOCK_IPV6_FRAG_H 0x3b /* IPv6 frag header */ +#define LIBNET_PBLOCK_IPV6_ROUTING_H 0x3c /* IPv6 routing header */ +#define LIBNET_PBLOCK_IPV6_DESTOPTS_H 0x3d /* IPv6 dest opts header */ +#define LIBNET_PBLOCK_IPV6_HBHOPTS_H 0x3e /* IPv6 hop/hop opts header */ +#define LIBNET_PBLOCK_SEBEK_H 0x3f /* Sebek header */ + u_int8_t flags; /* control flags */ +#define LIBNET_PBLOCK_DO_CHECKSUM 0x01 /* needs a checksum */ + libnet_ptag_t ptag; /* protocol block tag */ + struct libnet_protocol_block *next; /* next pblock */ + struct libnet_protocol_block *prev; /* prev pblock */ +}; +typedef struct libnet_protocol_block libnet_pblock_t; + + +/* + * Libnet context + * Opaque structure. Nothing in here should ever been touched first hand by + * the applications programmer. + */ +struct libnet_context +{ +#if ((__WIN32__) && !(__CYGWIN__)) + SOCKET fd; + LPADAPTER lpAdapter; +#else + int fd; /* file descriptor of packet device */ +#endif + int injection_type; /* raw (ipv4 or ipv6) or link */ +#define LIBNET_LINK 0x00 /* link-layer interface */ +#define LIBNET_RAW4 0x01 /* raw socket interface (ipv4) */ +#define LIBNET_RAW6 0x02 /* raw socket interface (ipv6) */ +/* the following should actually set a flag in the flags variable above */ +#define LIBNET_LINK_ADV 0x08 /* advanced mode link-layer */ +#define LIBNET_RAW4_ADV 0x09 /* advanced mode raw socket (ipv4) */ +#define LIBNET_RAW6_ADV 0x0a /* advanced mode raw socket (ipv6) */ +#define LIBNET_ADV_MASK 0x08 /* mask to determine adv mode */ + + libnet_pblock_t *protocol_blocks; /* protocol headers / data */ + libnet_pblock_t *pblock_end; /* last node in list */ + u_int32_t n_pblocks; /* number of pblocks */ + + int link_type; /* link-layer type */ + int link_offset; /* link-layer header size */ + int aligner; /* used to align packets */ + char *device; /* device name */ + + struct libnet_stats stats; /* statistics */ + libnet_ptag_t ptag_state; /* state holder for pblock tag */ + char label[LIBNET_LABEL_SIZE]; /* textual label for cq interface */ + + char err_buf[LIBNET_ERRBUF_SIZE]; /* error buffer */ + u_int32_t total_size; /* total size */ +}; +typedef struct libnet_context libnet_t; + +/* + * Libnet context queue structure + * Opaque structure. Nothing in here should ever been touched first hand by + * the applications programmer. + */ +typedef struct _libnet_context_queue libnet_cq_t; +struct _libnet_context_queue +{ + libnet_t *context; /* pointer to libnet context */ + libnet_cq_t *next; /* next node in the list */ + libnet_cq_t *prev; /* previous node in the list */ +}; + +struct _libnet_context_queue_descriptor +{ + u_int32_t node; /* number of nodes in the list */ + u_int32_t cq_lock; /* lock status */ + libnet_cq_t *current; /* current context */ +}; +typedef struct _libnet_context_queue_descriptor libnet_cqd_t; + +#endif /* __LIBNET_STRUCTURES_H */ + +/* EOF */ diff --git a/libnet/include/libnet/libnet-types.h b/libnet/include/libnet/libnet-types.h new file mode 100644 index 0000000..dcb0524 --- /dev/null +++ b/libnet/include/libnet/libnet-types.h @@ -0,0 +1,45 @@ +/* + * $Id: libnet-types.h,v 1.3 2004/01/03 20:31:00 mike Exp $ + * + * libnet-types.h - Network routine library macro header file + * + * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef __LIBNET_TYPES_H +#define __LIBNET_TYPES_H + +/* Solaris has messed up POSIX nomenclature for these */ +#if (__sun__ && __svr4__) +typedef uint8_t u_int8_t; +typedef uint16_t u_int16_t; +typedef uint32_t u_int32_t; +typedef uint64_t u_int64_t; +#endif + +#endif /* __LIBNET_TYPES_H */ + +/* EOF */ diff --git a/libnet/include/stamp-h.in b/libnet/include/stamp-h.in new file mode 100644 index 0000000..9788f70 --- /dev/null +++ b/libnet/include/stamp-h.in @@ -0,0 +1 @@ +timestamp diff --git a/libnet/include/win32/CVS/Entries b/libnet/include/win32/CVS/Entries new file mode 100644 index 0000000..4407902 --- /dev/null +++ b/libnet/include/win32/CVS/Entries @@ -0,0 +1,5 @@ +/config.h/1.4/Sat Jan 3 20:31:00 2004// +/getopt.h/1.1.1.1/Thu Jun 26 21:55:10 2003// +/in_systm.h/1.2/Sat Jun 28 18:03:57 2003// +/libnet.h/1.7/Sat Jan 3 20:31:00 2004// +D diff --git a/libnet/include/win32/CVS/Repository b/libnet/include/win32/CVS/Repository new file mode 100644 index 0000000..33fb6d6 --- /dev/null +++ b/libnet/include/win32/CVS/Repository @@ -0,0 +1 @@ +/usr/local/CVS/libnet/include/win32 diff --git a/libnet/include/win32/CVS/Root b/libnet/include/win32/CVS/Root new file mode 100644 index 0000000..52fa133 --- /dev/null +++ b/libnet/include/win32/CVS/Root @@ -0,0 +1 @@ +mike@66.234.207.232:/usr/local/CVS diff --git a/libnet/include/win32/config.h b/libnet/include/win32/config.h new file mode 100644 index 0000000..97033a9 --- /dev/null +++ b/libnet/include/win32/config.h @@ -0,0 +1,112 @@ +/* include/config.h.in. Generated from configure.in by autoheader. */ +/* +dnl $Id: config.h,v 1.4 2004/01/03 20:31:00 mike Exp $ +dnl +dnl Libnet autoconfiguration acconfig.h file +dnl Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> +dnl All rights reserved. +dnl +dnl Process this file with autoheader to produce a config.h file. +dnl +*/ + +#undef LIBNET_BSDISH_OS +#undef LIBNET_BSD_BYTE_SWAP +#undef DLPI_DEV_PREFIX +#undef HAVE_DEV_DLPI +#undef HAVE_SOLARIS +#undef HAVE_SOLARIS_IPV6 +#undef HAVE_HPUX11 +#undef HAVE_SOCKADDR_SA_LEN +#undef HAVE_DLPI +#undef HAVE_PACKET_SOCKET +#undef HAVE_STRUCT_IP_CSUM +#undef HAVE_LIB_PCAP +#undef LBL_ALIGN +#undef STUPID_SOLARIS_CHECKSUM_BUG +#undef _BSD_SOURCE +#undef __BSD_SOURCE +#undef __FAVOR_BSD +#undef LIBNET_BIG_ENDIAN +#define LIBNET_LIL_ENDIAN 1 +#undef NO_SNPRINTF + + +/* +dnl EOF +*/ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `nsl' library (-lnsl). */ +#undef HAVE_LIBNSL + +/* Define to 1 if you have the `packet' library (-lpacket). */ +#undef HAVE_LIBPACKET + +/* Define to 1 if you have the `socket' library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* Define to 1 if you have the `wpcap' library (-lwpcap). */ +#undef HAVE_LIBWPCAP + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the <net/ethernet.h> header file. */ +#define HAVE_NET_ETHERNET_H 1 + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/bufmod.h> header file. */ +#undef HAVE_SYS_BUFMOD_H + +/* Define to 1 if you have the <sys/dlpi_ext.h> header file. */ +#undef HAVE_SYS_DLPI_EXT_H + +/* Define to 1 if you have the <sys/sockio.h> header file. */ +#undef HAVE_SYS_SOCKIO_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS diff --git a/libnet/include/win32/getopt.h b/libnet/include/win32/getopt.h new file mode 100644 index 0000000..6b6f643 --- /dev/null +++ b/libnet/include/win32/getopt.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1987, 1993, 1994, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that 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. + */ + +#ifndef __GETOPT_H__ +#define __GETOPT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +extern int opterr; /* if error message should be printed */ +extern int optind; /* index into parent argv vector */ +extern int optopt; /* character checked for validity */ +extern int optreset; /* reset getopt */ +extern char *optarg; /* argument associated with option */ + +int getopt (int, char * const *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* __GETOPT_H__ */ + +#ifndef __UNISTD_GETOPT__ +#ifndef __GETOPT_LONG_H__ +#define __GETOPT_LONG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +struct option { + const char *name; + int has_arg; + int *flag; + int val; +}; + +int getopt_long (int, char *const *, const char *, const struct option *, int *); +#ifndef HAVE_DECL_GETOPT +#define HAVE_DECL_GETOPT 1 +#endif + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +#ifdef __cplusplus +} +#endif + +#endif /* __GETOPT_LONG_H__ */ +#endif /* __UNISTD_GETOPT__ */ diff --git a/libnet/include/win32/in_systm.h b/libnet/include/win32/in_systm.h new file mode 100644 index 0000000..b0ee1a2 --- /dev/null +++ b/libnet/include/win32/in_systm.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)in_systm.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/netinet/in_systm.h,v 1.9 1999/12/29 04:41:00 peter Exp $ + */ + +#ifdef _WIN32 +#ifndef _NETINET_IN_SYSTM_H_ +#define _NETINET_IN_SYSTM_H_ + +typedef unsigned char u_int8_t; +typedef unsigned short u_int16_t; +typedef unsigned int u_int32_t; +typedef unsigned __int64 u_int64_t; + +typedef __int64 int64_t; +typedef int64_t rlim_t; + + +typedef u_int32_t in_addr_t; +typedef u_int32_t in_port_t; + +/* + * Miscellaneous internetwork + * definitions for kernel. + */ + +/* + * Network types. + * + * Internally the system keeps counters in the headers with the bytes + * swapped so that VAX instructions will work on them. It reverses + * the bytes before transmission at each protocol level. The n_ types + * represent the types with the bytes in ``high-ender'' order. + */ +typedef u_int16_t n_short; /* short as received from the net */ +typedef u_int32_t n_long; /* long as received from the net */ + +typedef u_int32_t n_time; /* ms since 00:00 GMT, byte rev */ + +#ifdef _KERNEL +n_time iptime __P((void)); +#endif + +#endif + +#endif diff --git a/libnet/include/win32/libnet.h b/libnet/include/win32/libnet.h new file mode 100644 index 0000000..4f0c10a --- /dev/null +++ b/libnet/include/win32/libnet.h @@ -0,0 +1,106 @@ +/*
+ * $Id: libnet.h,v 1.7 2004/01/03 20:31:00 mike Exp $
+ *
+ * libnet.h - Network routine library header file for Win32 VC++
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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
+
+#ifndef __LIBNET_H
+#define __LIBNET_H
+
+#include <winsock2.h>
+#include <windows.h>
+#include <time.h>
+#include "in_systm.h"
+#include "pcap.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* __WIN32__ is NOT a predefined MACRO, use _WIN32
+ * __CYGWIN__ is defined within the cygwin environment.
+ */
+#ifndef __WIN32__
+#define __WIN32__ _WIN32
+#endif
+
+#define LIBNET_LIL_ENDIAN 1
+#define HAVE_CONFIG_H 1
+
+/* Some UNIX to Win32 conversions */
+#define STDOUT_FILENO stdout
+#define snprintf _snprintf
+#define write _write
+#define open _open
+#define random rand
+#define close closesocket
+#define __func__ __FUNCTION__
+
+/* __FUNCTION__ available in VC ++ 7.0 (.NET) and greater */
+#if _MSC_VER < 1300
+#define __FUNCTION__ __FILE__
+#endif
+
+#pragma comment (lib,"ws2_32") /* Winsock 2 */
+#pragma comment (lib,"iphlpapi") /* IP Helper */
+#pragma comment (lib,"wpcap") /* Winpcap */
+#pragma comment (lib,"packet")
+
+/* "@LIBNET_VERSION@" will not work in VC++, so version.h doesn't get populated */
+#define VERSION "1.1.1"
+
+/* To use Win32 native versions */
+#define WPCAP 1
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdarg.h>
+#include "../libnet/libnet-macros.h"
+#include "../libnet/libnet-headers.h"
+#include "../libnet/libnet-structures.h"
+#include "../libnet/libnet-asn1.h"
+#include "../libnet/libnet-functions.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIBNET_H */
+
+#endif
+/* EOF */
|