[-]
[+]
|
Changed |
ntopng.changes
|
|
[-]
[+]
|
Changed |
ntopng.spec
^
|
|
[-]
[+]
|
Added |
ntopng-1.0.2_json-c_Werror.patch
^
|
@@ -0,0 +1,6 @@
+--- third-party/json-c/Makefile.am.inc.orig 2013-10-18 20:00:27.307055968 +0200
++++ third-party/json-c/Makefile.am.inc 2013-10-18 20:00:37.335056366 +0200
+@@ -1,2 +1,2 @@
+-AM_CFLAGS = -Wall -Werror -Wextra -Wwrite-strings -Wno-unused-parameter -std=gnu99 -D_GNU_SOURCE -D_REENTRANT
++AM_CFLAGS = -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -std=gnu99 -D_GNU_SOURCE -D_REENTRANT
+
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/INSTALL
^
|
@@ -1,7 +1,7 @@
Installation Instructions
*************************
-Copyright (C) 1994-1996, 1999-2002, 2004-2012 Free Software Foundation,
+Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation,
Inc.
Copying and distribution of this file, with or without modification,
@@ -309,10 +309,9 @@
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
-an Autoconf limitation. Until the limitation is lifted, you can use
-this workaround:
+an Autoconf bug. Until the bug is fixed you can use this workaround:
- CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
+ CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
@@ -368,3 +367,4 @@
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
+
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/Makefile.in
^
|
@@ -1,8 +1,9 @@
-# Makefile.in generated by automake 1.12.2 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2012 Free Software Foundation, Inc.
-
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
@@ -52,9 +53,10 @@
host_triplet = @host@
subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in $(srcdir)/libndpi.pc.in \
- $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
- config.guess config.sub depcomp install-sh ltmain.sh missing
+ $(srcdir)/Makefile.in $(srcdir)/config.h.in \
+ $(srcdir)/libndpi.pc.in $(top_srcdir)/configure AUTHORS \
+ COPYING ChangeLog INSTALL NEWS config.guess config.sub depcomp \
+ install-sh ltmain.sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -65,6 +67,7 @@
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno config.status.lineno
mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = config.h
CONFIG_CLEAN_FILES = libndpi.pc
CONFIG_CLEAN_VPATH_FILES =
SOURCES =
@@ -114,10 +117,9 @@
distclean-recursive maintainer-clean-recursive
AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
- cscope distdir dist dist-all distcheck
+ distdir dist dist-all distcheck
ETAGS = etags
CTAGS = ctags
-CSCOPE = cscope
DIST_SUBDIRS = $(SUBDIRS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
@@ -128,7 +130,6 @@
&& rm -rf "$(distdir)" \
|| { sleep 5 && rm -rf "$(distdir)"; }; \
else :; fi
-am__post_remove_distdir = $(am__remove_distdir)
am__relativize = \
dir0=`pwd`; \
sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -156,7 +157,6 @@
reldir="$$dir2"
DIST_ARCHIVES = $(distdir).tar.gz
GZIP_ENV = --best
-DIST_TARGETS = dist-gzip
distuninstallcheck_listfiles = find . -type f -print
am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
| sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
@@ -216,6 +216,7 @@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PLATFORM_DEPENDENT = @PLATFORM_DEPENDENT@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -278,7 +279,8 @@
ACLOCAL_AMFLAGS = -I m4
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libndpi.pc
-all: all-recursive
+all: config.h
+ $(MAKE) $(AM_MAKEFLAGS) all-recursive
.SUFFIXES:
am--refresh: Makefile
@@ -315,6 +317,21 @@
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+ @if test ! -f $@; then rm -f stamp-h1; else :; fi
+ @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+ @rm -f stamp-h1
+ cd $(top_builddir) && $(SHELL) ./config.status config.h
+$(srcdir)/config.h.in: $(am__configure_deps)
+ ($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+ rm -f stamp-h1
+ touch $@
+
+distclean-hdr:
+ -rm -f config.h stamp-h1
libndpi.pc: $(top_builddir)/config.status $(srcdir)/libndpi.pc.in
cd $(top_builddir) && $(SHELL) ./config.status $@
@@ -349,12 +366,12 @@
dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir)
# 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) $(RECURSIVE_CLEAN_TARGETS):
+# 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):
@fail= failcom='exit 1'; \
for f in x $$MAKEFLAGS; do \
case $$f in \
@@ -364,11 +381,7 @@
done; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
- case "$@" in \
- distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
- *) list='$(SUBDIRS)' ;; \
- esac; \
- for subdir in $$list; do \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
@@ -382,6 +395,37 @@
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+ @fail= failcom='exit 1'; \
+ for f in x $$MAKEFLAGS; do \
+ case $$f in \
+ *=* | --[!k]*);; \
+ *k*) failcom='fail=yes';; \
+ esac; \
+ done; \
+ 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; \
+ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
@@ -390,10 +434,6 @@
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
-cscopelist-recursive:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \
- done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -405,7 +445,7 @@
mkid -fID $$unique
tags: TAGS
-TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
@@ -422,7 +462,7 @@
set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ 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 | \
@@ -440,9 +480,9 @@
fi; \
fi
ctags: CTAGS
-CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ 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 | \
@@ -457,32 +497,8 @@
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
-cscope: cscope.files
- test ! -s cscope.files \
- || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS)
-
-clean-cscope:
- -rm -f cscope.files
-
-cscope.files: clean-cscope cscopelist-recursive cscopelist
-
-cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP)'; \
- case "$(srcdir)" in \
- [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
- *) sdir=$(subdir)/$(srcdir) ;; \
- esac; \
- for i in $$list; do \
- if test -f "$$i"; then \
- echo "$(subdir)/$$i"; \
- else \
- echo "$$sdir/$$i"; \
- fi; \
- done >> $(top_builddir)/cscope.files
-
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
- -rm -f cscope.out cscope.in.out cscope.po.out cscope.files
distdir: $(DISTFILES)
$(am__remove_distdir)
@@ -550,36 +566,40 @@
|| chmod -R a+r "$(distdir)"
dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
dist-bzip2: distdir
tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
dist-lzip: distdir
tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
+
+dist-lzma: distdir
+ tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
+ $(am__remove_distdir)
dist-xz: distdir
tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
dist-tarZ: distdir
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
dist-shar: distdir
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
dist-zip: distdir
-rm -f $(distdir).zip
zip -rq $(distdir).zip $(distdir)
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
-dist dist-all:
- $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:'
- $(am__post_remove_distdir)
+dist dist-all: distdir
+ tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+ $(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
# it guarantees that the distribution is self-contained by making another
@@ -590,6 +610,8 @@
GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \
bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
+ *.tar.lzma*) \
+ lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
*.tar.lz*) \
lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
*.tar.xz*) \
@@ -635,7 +657,7 @@
&& $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
&& cd "$$am__cwd" \
|| exit 1
- $(am__post_remove_distdir)
+ $(am__remove_distdir)
@(echo "$(distdir) archives ready for distribution: "; \
list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
@@ -667,7 +689,7 @@
exit 1; } >&2
check-am: all-am
check: check-recursive
-all-am: Makefile $(DATA)
+all-am: Makefile $(DATA) config.h
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(pkgconfigdir)"; do \
@@ -710,8 +732,8 @@
distclean: distclean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -f Makefile
-distclean-am: clean-am distclean-generic distclean-libtool \
- distclean-tags
+distclean-am: clean-am distclean-generic distclean-hdr \
+ distclean-libtool distclean-tags
dvi: dvi-recursive
@@ -773,16 +795,14 @@
uninstall-am: uninstall-pkgconfigDATA
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \
- cscopelist-recursive ctags-recursive install-am install-strip \
- tags-recursive
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \
+ ctags-recursive install-am install-strip tags-recursive
.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
- all all-am am--refresh check check-am clean clean-cscope \
- clean-generic clean-libtool cscope cscopelist \
- cscopelist-recursive ctags ctags-recursive dist dist-all \
- dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ dist-xz \
- dist-zip distcheck distclean distclean-generic \
+ all all-am am--refresh check check-am clean clean-generic \
+ clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
+ dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ dist-xz \
+ dist-zip distcheck distclean distclean-generic distclean-hdr \
distclean-libtool distclean-tags distcleancheck distdir \
distuninstallcheck dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/aclocal.m4
^
|
@@ -1,7 +1,8 @@
-# generated automatically by aclocal 1.12.2 -*- Autoconf -*-
-
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# generated automatically by aclocal 1.11.6 -*- Autoconf -*-
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
+# Inc.
# This file 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.
@@ -17,15 +18,16 @@
[m4_warning([this file was generated for autoconf 2.69.
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
-To do so, use the procedure documented by the package, typically 'autoreconf'.])])
+To do so, use the procedure documented by the package, typically `autoreconf'.])])
-# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software
+# Foundation, Inc.
#
# This file 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.
-# serial 8
+# serial 1
# AM_AUTOMAKE_VERSION(VERSION)
# ----------------------------
@@ -33,10 +35,10 @@
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.12'
+[am__api_version='1.11'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.12.2], [],
+m4_if([$1], [1.11.6], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -52,24 +54,24 @@
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.12.2])dnl
+[AM_AUTOMAKE_VERSION([1.11.6])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
#
# This file 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.
-# serial 2
+# serial 1
# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
-# $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to
-# '$srcdir', '$srcdir/..', or '$srcdir/../..'.
+# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
#
# Of course, Automake must honor this variable whenever it calls a
# tool from the auxiliary directory. The problem is that $srcdir (and
@@ -88,7 +90,7 @@
#
# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
# are both prefixed by $srcdir. In an in-source build this is usually
-# harmless because $srcdir is '.', but things will broke when you
+# harmless because $srcdir is `.', but things will broke when you
# start a VPATH build or use an absolute $srcdir.
#
# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
@@ -114,21 +116,22 @@
# AM_CONDITIONAL -*- Autoconf -*-
-# Copyright (C) 1997-2012 Free Software Foundation, Inc.
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
+# Free Software Foundation, Inc.
#
# This file 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.
-# serial 10
+# serial 9
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
# Define a conditional.
AC_DEFUN([AM_CONDITIONAL],
-[AC_PREREQ([2.52])dnl
- m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
- [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
+ [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
AC_SUBST([$1_TRUE])dnl
AC_SUBST([$1_FALSE])dnl
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
@@ -147,15 +150,16 @@
Usually this means the macro was only invoked conditionally.]])
fi])])
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009,
+# 2010, 2011 Free Software Foundation, Inc.
#
# This file 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.
-# serial 17
+# serial 12
-# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
# written in clear, in which case automake, when reading aclocal.m4,
# will think it sees a *use*, and therefore will trigger all it's
# C support machinery. Also note that it means that autoscan, seeing
@@ -165,7 +169,7 @@
# _AM_DEPENDENCIES(NAME)
# ----------------------
# See how the compiler implements dependency checking.
-# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC".
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
# We try a few techniques and use that to set a single cache variable.
#
# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
@@ -178,13 +182,12 @@
AC_REQUIRE([AM_MAKE_INCLUDE])dnl
AC_REQUIRE([AM_DEP_TRACK])dnl
-m4_if([$1], [CC], [depcc="$CC" am_compiler_list=],
- [$1], [CXX], [depcc="$CXX" am_compiler_list=],
- [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
- [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'],
- [$1], [UPC], [depcc="$UPC" am_compiler_list=],
- [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
- [depcc="$$1" am_compiler_list=])
+ifelse([$1], CC, [depcc="$CC" am_compiler_list=],
+ [$1], CXX, [depcc="$CXX" am_compiler_list=],
+ [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+ [$1], UPC, [depcc="$UPC" am_compiler_list=],
+ [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
+ [depcc="$$1" am_compiler_list=])
AC_CACHE_CHECK([dependency style of $depcc],
[am_cv_$1_dependencies_compiler_type],
@@ -192,8 +195,8 @@
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
- # making a dummy file named 'D' -- because '-MD' means "put the output
- # in D".
+ # making a dummy file named `D' -- because `-MD' means `put the output
+ # in D'.
rm -rf conftest.dir
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
@@ -233,16 +236,16 @@
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
- # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
- # Solaris 10 /bin/sh.
- echo '/* dummy */' > sub/conftst$i.h
+ # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+ # Solaris 8's {/usr,}/bin/sh.
+ touch sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
- # We check with '-c' and '-o' for the sake of the "dashmstdout"
+ # We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
- # handle '-M -o', and we need to detect this. Also, some Intel
- # versions had trouble with output in subdirs.
+ # handle `-M -o', and we need to detect this. Also, some Intel
+ # versions had trouble with output in subdirs
am__obj=sub/conftest.${OBJEXT-o}
am__minus_obj="-o $am__obj"
case $depmode in
@@ -251,8 +254,8 @@
test "$am__universal" = false || continue
;;
nosideeffect)
- # After this tag, mechanisms are not by side-effect, so they'll
- # only be used when explicitly requested.
+ # after this tag, mechanisms are not by side-effect, so they'll
+ # only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
@@ -260,7 +263,7 @@
fi
;;
msvc7 | msvc7msys | msvisualcpp | msvcmsys)
- # This compiler won't grok '-c -o', but also, the minuso test has
+ # This compiler won't grok `-c -o', but also, the minuso test has
# not run yet. These depmodes are late enough in the game, and
# so weak that their functioning should not be impacted.
am__obj=conftest.${OBJEXT-o}
@@ -308,7 +311,7 @@
# AM_SET_DEPDIR
# -------------
# Choose a directory name for dependency files.
-# This macro is AC_REQUIREd in _AM_DEPENDENCIES.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
AC_DEFUN([AM_SET_DEPDIR],
[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
@@ -318,13 +321,9 @@
# AM_DEP_TRACK
# ------------
AC_DEFUN([AM_DEP_TRACK],
-[AC_ARG_ENABLE([dependency-tracking], [dnl
-AS_HELP_STRING(
- [--enable-dependency-tracking],
- [do not reject slow dependency extractors])
-AS_HELP_STRING(
- [--disable-dependency-tracking],
- [speeds up one-time build])])
+[AC_ARG_ENABLE(dependency-tracking,
+[ --disable-dependency-tracking speeds up one-time build
+ --enable-dependency-tracking do not reject slow dependency extractors])
if test "x$enable_dependency_tracking" != xno; then
am_depcomp="$ac_aux_dir/depcomp"
AMDEPBACKSLASH='\'
@@ -339,13 +338,14 @@
# Generate code to set up dependency tracking. -*- Autoconf -*-
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
#
# This file 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.
-# serial 6
+#serial 5
# _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------
@@ -364,7 +364,7 @@
# Strip MF so we end up with the name of the file.
mf=`echo "$mf" | sed -e 's/:.*$//'`
# Check whether this is an Automake generated Makefile or not.
- # We used to match only the files named 'Makefile.in', but
+ # We used to match only the files named `Makefile.in', but
# some people rename them; so instead we look at the file content.
# Grep'ing the first line is not enough: some people post-process
# each Makefile.in and add a new line on top of each file to say so.
@@ -376,19 +376,21 @@
continue
fi
# Extract the definition of DEPDIR, am__include, and am__quote
- # from the Makefile without running 'make'.
+ # from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
am__include=`sed -n 's/^am__include = //p' < "$mf"`
test -z "am__include" && continue
am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+ # When using ansi2knr, U may be empty or an underscore; expand it
+ U=`sed -n 's/^U = //p' < "$mf"`
# Find all dependency output files, they are included files with
# $(DEPDIR) in their names. We invoke sed twice because it is the
# simplest approach to changing $(DEPDIR) to its actual value in the
# expansion.
for file in `sed -n "
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
- sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do
+ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`AS_DIRNAME(["$file"])`
@@ -406,7 +408,7 @@
# This macro should only be invoked once -- use via AC_REQUIRE.
#
# This code is only required when automatic dependency tracking
-# is enabled. FIXME. This creates each '.P' file that we will
+# is enabled. FIXME. This creates each `.P' file that we will
# need in order to bootstrap the dependency handling code.
AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
[AC_CONFIG_COMMANDS([depfiles],
@@ -416,13 +418,14 @@
# Do all the work for Automake. -*- Autoconf -*-
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
#
# This file 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.
-# serial 19
+# serial 16
# This macro actually does too much. Some checks are only needed if
# your package does certain things. But this isn't really a big deal.
@@ -468,41 +471,31 @@
# Define the identity of the package.
dnl Distinguish between old-style and new-style calls.
m4_ifval([$2],
-[AC_DIAGNOSE([obsolete],
-[$0: two- and three-arguments forms are deprecated. For more info, see:
-http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_INIT_AUTOMAKE-invocation])
-m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
AC_SUBST([PACKAGE], [$1])dnl
AC_SUBST([VERSION], [$2])],
[_AM_SET_OPTIONS([$1])dnl
dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
-m4_if(
- m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]),
- [ok:ok],,
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
[m4_fatal([AC_INIT should be called with package and version arguments])])dnl
AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
_AM_IF_OPTION([no-define],,
-[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package])
- AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
# Some tools Automake needs.
AC_REQUIRE([AM_SANITY_CHECK])dnl
AC_REQUIRE([AC_ARG_PROGRAM])dnl
-AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}])
-AM_MISSING_PROG([AUTOCONF], [autoconf])
-AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}])
-AM_MISSING_PROG([AUTOHEADER], [autoheader])
-AM_MISSING_PROG([MAKEINFO], [makeinfo])
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
-AC_REQUIRE([AC_PROG_MKDIR_P])dnl
-# For better backward compatibility. To be removed once Automake 1.9.x
-# dies out for good. For more background, see:
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
-AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
# We need awk for the "check" target. The system "awk" is bad on
# some platforms.
AC_REQUIRE([AC_PROG_AWK])dnl
@@ -513,35 +506,28 @@
[_AM_PROG_TAR([v7])])])
_AM_IF_OPTION([no-dependencies],,
[AC_PROVIDE_IFELSE([AC_PROG_CC],
- [_AM_DEPENDENCIES([CC])],
- [m4_define([AC_PROG_CC],
- m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl
+ [_AM_DEPENDENCIES(CC)],
+ [define([AC_PROG_CC],
+ defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_CXX],
- [_AM_DEPENDENCIES([CXX])],
- [m4_define([AC_PROG_CXX],
- m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl
+ [_AM_DEPENDENCIES(CXX)],
+ [define([AC_PROG_CXX],
+ defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_OBJC],
- [_AM_DEPENDENCIES([OBJC])],
- [m4_define([AC_PROG_OBJC],
- m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl
-dnl Support for Objective C++ was only introduced in Autoconf 2.65,
-dnl but we still cater to Autoconf 2.62.
-m4_ifdef([AC_PROG_OBJCXX],
-[AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
- [_AM_DEPENDENCIES([OBJCXX])],
- [m4_define([AC_PROG_OBJCXX],
- m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])])dnl
+ [_AM_DEPENDENCIES(OBJC)],
+ [define([AC_PROG_OBJC],
+ defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
])
_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
-dnl The 'parallel-tests' driver may need to know about EXEEXT, so add the
-dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro
+dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
+dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro
dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
AC_CONFIG_COMMANDS_PRE(dnl
[m4_provide_if([_AM_COMPILER_EXEEXT],
[AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
])
-dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
+dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
@@ -569,13 +555,14 @@
done
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation,
+# Inc.
#
# This file 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.
-# serial 8
+# serial 1
# AM_PROG_INSTALL_SH
# ------------------
@@ -590,9 +577,9 @@
install_sh="\${SHELL} $am_aux_dir/install-sh"
esac
fi
-AC_SUBST([install_sh])])
+AC_SUBST(install_sh)])
-# Copyright (C) 2003-2012 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -615,13 +602,13 @@
# Check to see how 'make' treats includes. -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc.
#
# This file 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.
-# serial 5
+# serial 4
# AM_MAKE_INCLUDE()
# -----------------
@@ -640,7 +627,7 @@
_am_result=none
# First try GNU make style include.
echo "include confinc" > confmf
-# Ignore all kinds of additional output from 'make'.
+# Ignore all kinds of additional output from `make'.
case `$am_make -s -f confmf 2> /dev/null` in #(
*the\ am__doit\ target*)
am__include=include
@@ -667,13 +654,14 @@
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
-# Copyright (C) 1997-2012 Free Software Foundation, Inc.
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
#
# This file 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.
-# serial 7
+# serial 6
# AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------
@@ -703,19 +691,49 @@
am_missing_run="$MISSING --run "
else
am_missing_run=
- AC_MSG_WARN(['missing' script is too old or missing])
+ AC_MSG_WARN([`missing' script is too old or missing])
fi
])
+# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation,
+# Inc.
+#
+# This file 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.
+
+# serial 1
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+ [[\\/$]]* | ?:[[\\/]]*) ;;
+ */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
# Helper functions for option handling. -*- Autoconf -*-
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software
+# Foundation, Inc.
#
# This file 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.
-# serial 6
+# serial 5
# _AM_MANGLE_OPTION(NAME)
# -----------------------
@@ -726,7 +744,7 @@
# --------------------
# Set option NAME. Presently that only means defining a flag for this option.
AC_DEFUN([_AM_SET_OPTION],
-[m4_define(_AM_MANGLE_OPTION([$1]), [1])])
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
# _AM_SET_OPTIONS(OPTIONS)
# ------------------------
@@ -742,18 +760,22 @@
# Check to make sure that the build environment is sane. -*- Autoconf -*-
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Free Software Foundation, Inc.
#
# This file 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.
-# serial 9
+# serial 5
# AM_SANITY_CHECK
# ---------------
AC_DEFUN([AM_SANITY_CHECK],
[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
# Reject unsafe characters in $srcdir or the absolute working directory
# name. Accept space and tab only in the latter.
am_lf='
@@ -764,40 +786,32 @@
esac
case $srcdir in
*[[\\\"\#\$\&\'\`$am_lf\ \ ]]*)
- AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);;
+ AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
esac
-# Do 'set' in a subshell so we don't clobber the current shell's
+# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
- am_has_slept=no
- for am_try in 1 2; do
- echo "timestamp, slept: $am_has_slept" > conftest.file
- set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
- if test "$[*]" = "X"; then
- # -L didn't work.
- set X `ls -t "$srcdir/configure" conftest.file`
- fi
- if test "$[*]" != "X $srcdir/configure conftest.file" \
- && test "$[*]" != "X conftest.file $srcdir/configure"; then
-
- # If neither matched, then we have a broken ls. This can happen
- # if, for instance, CONFIG_SHELL is bash and it inherits a
- # broken ls alias from the environment. This has actually
- # happened. Such a system could not be considered "sane".
- AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
- alias in your environment])
- fi
- if test "$[2]" = conftest.file || test $am_try -eq 2; then
- break
- fi
- # Just in case.
- sleep 1
- am_has_slept=yes
- done
+ set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+ if test "$[*]" = "X"; then
+ # -L didn't work.
+ set X `ls -t "$srcdir/configure" conftest.file`
+ fi
+ rm -f conftest.file
+ if test "$[*]" != "X $srcdir/configure conftest.file" \
+ && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+ # If neither matched, then we have a broken ls. This can happen
+ # if, for instance, CONFIG_SHELL is bash and it inherits a
+ # broken ls alias from the environment. This has actually
+ # happened. Such a system could not be considered "sane".
+ AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
+alias in your environment])
+ fi
+
test "$[2]" = conftest.file
)
then
@@ -807,55 +821,39 @@
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
-AC_MSG_RESULT([yes])
-# If we didn't sleep, we still need to ensure time stamps of config.status and
-# generated files are strictly newer.
-am_sleep_pid=
-if grep 'slept: no' conftest.file >/dev/null 2>&1; then
- ( sleep 1 ) &
- am_sleep_pid=$!
-fi
-AC_CONFIG_COMMANDS_PRE(
- [AC_MSG_CHECKING([that generated files are newer than configure])
- if test -n "$am_sleep_pid"; then
- # Hide warnings about reused PIDs.
- wait $am_sleep_pid 2>/dev/null
- fi
- AC_MSG_RESULT([done])])
-rm -f conftest.file
-])
+AC_MSG_RESULT(yes)])
-# Copyright (C) 2001-2012 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
#
# This file 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.
-# serial 2
+# serial 1
# AM_PROG_INSTALL_STRIP
# ---------------------
-# One issue with vendor 'install' (even GNU) is that you can't
+# One issue with vendor `install' (even GNU) is that you can't
# specify the program used to strip binaries. This is especially
# annoying in cross-compiling environments, where the build's strip
# is unlikely to handle the host's binaries.
# Fortunately install-sh will honor a STRIPPROG variable, so we
-# always use install-sh in "make install-strip", and initialize
+# always use install-sh in `make install-strip', and initialize
# STRIPPROG with the value of the STRIP variable (set by the user).
AC_DEFUN([AM_PROG_INSTALL_STRIP],
[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
-# Installed binaries are usually stripped using 'strip' when the user
-# run "make install-strip". However 'strip' might not be the right
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'. However `strip' might not be the right
# tool to use in cross-compilation environments, therefore Automake
-# will honor the 'STRIP' environment variable to overrule this program.
-dnl Don't test for $cross_compiling = yes, because it might be 'maybe'.
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
if test "$cross_compiling" != no; then
AC_CHECK_TOOL([STRIP], [strip], :)
fi
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
-# Copyright (C) 2006-2012 Free Software Foundation, Inc.
+# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -876,18 +874,18 @@
# Check how to create a tarball. -*- Autoconf -*-
-# Copyright (C) 2004-2012 Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc.
#
# This file 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.
-# serial 3
+# serial 2
# _AM_PROG_TAR(FORMAT)
# --------------------
# Check how to create a tarball in format FORMAT.
-# FORMAT should be one of 'v7', 'ustar', or 'pax'.
+# FORMAT should be one of `v7', `ustar', or `pax'.
#
# Substitute a variable $(am__tar) that is a command
# writing to stdout a FORMAT-tarball containing the directory
@@ -910,7 +908,7 @@
_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
_am_tools=${am_cv_prog_tar_$1-$_am_tools}
# Do not fold the above two line into one, because Tru64 sh and
-# Solaris sh will not grok spaces in the rhs of '-'.
+# Solaris sh will not grok spaces in the rhs of `-'.
for _am_tool in $_am_tools
do
case $_am_tool in
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/config.guess
^
|
@@ -4,7 +4,7 @@
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
-timestamp='2012-06-10'
+timestamp='2012-02-10'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@@ -1256,7 +1256,7 @@
NEO-?:NONSTOP_KERNEL:*:*)
echo neo-tandem-nsk${UNAME_RELEASE}
exit ;;
- NSE-*:NONSTOP_KERNEL:*:*)
+ NSE-?:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
NSR-?:NONSTOP_KERNEL:*:*)
|
[-]
[+]
|
Added |
nDPI.tar.bz2/config.h.in
^
|
@@ -0,0 +1,65 @@
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#undef HAVE_NETINET_IN_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 <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/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
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+ */
+#undef LT_OBJDIR
+
+/* 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 home page for this package. */
+#undef PACKAGE_URL
+
+/* 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
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/configure
^
|
@@ -633,6 +633,7 @@
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
+PLATFORM_DEPENDENT
CPP
OTOOL64
OTOOL
@@ -1384,10 +1385,8 @@
--enable-static[=PKGS] build static libraries [default=yes]
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
- --enable-dependency-tracking
- do not reject slow dependency extractors
- --disable-dependency-tracking
- speeds up one-time build
+ --disable-dependency-tracking speeds up one-time build
+ --enable-dependency-tracking do not reject slow dependency extractors
--disable-libtool-lock avoid locking (might break parallel builds)
Optional Packages:
@@ -2190,7 +2189,7 @@
-am__api_version='1.12'
+am__api_version='1.11'
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
@@ -2316,6 +2315,9 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5
$as_echo_n "checking whether build environment is sane... " >&6; }
+# Just in case
+sleep 1
+echo timestamp > conftest.file
# Reject unsafe characters in $srcdir or the absolute working directory
# name. Accept space and tab only in the latter.
am_lf='
@@ -2326,40 +2328,32 @@
esac
case $srcdir in
*[\\\"\#\$\&\'\`$am_lf\ \ ]*)
- as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;;
+ as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;;
esac
-# Do 'set' in a subshell so we don't clobber the current shell's
+# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
- am_has_slept=no
- for am_try in 1 2; do
- echo "timestamp, slept: $am_has_slept" > conftest.file
- set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
- if test "$*" = "X"; then
- # -L didn't work.
- set X `ls -t "$srcdir/configure" conftest.file`
- fi
- if test "$*" != "X $srcdir/configure conftest.file" \
- && test "$*" != "X conftest.file $srcdir/configure"; then
+ set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+ if test "$*" = "X"; then
+ # -L didn't work.
+ set X `ls -t "$srcdir/configure" conftest.file`
+ fi
+ rm -f conftest.file
+ if test "$*" != "X $srcdir/configure conftest.file" \
+ && test "$*" != "X conftest.file $srcdir/configure"; then
+
+ # If neither matched, then we have a broken ls. This can happen
+ # if, for instance, CONFIG_SHELL is bash and it inherits a
+ # broken ls alias from the environment. This has actually
+ # happened. Such a system could not be considered "sane".
+ as_fn_error $? "ls -t appears to fail. Make sure there is not a broken
+alias in your environment" "$LINENO" 5
+ fi
- # If neither matched, then we have a broken ls. This can happen
- # if, for instance, CONFIG_SHELL is bash and it inherits a
- # broken ls alias from the environment. This has actually
- # happened. Such a system could not be considered "sane".
- as_fn_error $? "ls -t appears to fail. Make sure there is not a broken
- alias in your environment" "$LINENO" 5
- fi
- if test "$2" = conftest.file || test $am_try -eq 2; then
- break
- fi
- # Just in case.
- sleep 1
- am_has_slept=yes
- done
test "$2" = conftest.file
)
then
@@ -2371,16 +2365,6 @@
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
-# If we didn't sleep, we still need to ensure time stamps of config.status and
-# generated files are strictly newer.
-am_sleep_pid=
-if grep 'slept: no' conftest.file >/dev/null 2>&1; then
- ( sleep 1 ) &
- am_sleep_pid=$!
-fi
-
-rm -f conftest.file
-
test "$program_prefix" != NONE &&
program_transform_name="s&^&$program_prefix&;$program_transform_name"
# Use a double $ so make ignores it.
@@ -2407,8 +2391,8 @@
am_missing_run="$MISSING --run "
else
am_missing_run=
- { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5
-$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;}
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5
+$as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;}
fi
if test x"${install_sh}" != xset; then
@@ -2420,10 +2404,10 @@
esac
fi
-# Installed binaries are usually stripped using 'strip' when the user
-# run "make install-strip". However 'strip' might not be the right
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'. However `strip' might not be the right
# tool to use in cross-compilation environments, therefore Automake
-# will honor the 'STRIP' environment variable to overrule this program.
+# will honor the `STRIP' environment variable to overrule this program.
if test "$cross_compiling" != no; then
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
@@ -2562,6 +2546,12 @@
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
$as_echo "$MKDIR_P" >&6; }
+mkdir_p="$MKDIR_P"
+case $mkdir_p in
+ [\\/$]* | ?:[\\/]*) ;;
+ */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+
for ac_prog in gawk mawk nawk awk
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
@@ -2694,12 +2684,6 @@
MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
-# For better backward compatibility. To be removed once Automake 1.9.x
-# dies out for good. For more background, see:
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
-# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
-mkdir_p='$(MKDIR_P)'
-
# We need awk for the "check" target. The system "awk" is bad on
# some platforms.
# Always define AMTAR for backward compatibility. Yes, it's still used
@@ -2897,7 +2881,7 @@
_am_result=none
# First try GNU make style include.
echo "include confinc" > confmf
-# Ignore all kinds of additional output from 'make'.
+# Ignore all kinds of additional output from `make'.
case `$am_make -s -f confmf 2> /dev/null` in #(
*the\ am__doit\ target*)
am__include=include
@@ -3741,8 +3725,8 @@
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
- # making a dummy file named 'D' -- because '-MD' means "put the output
- # in D".
+ # making a dummy file named `D' -- because `-MD' means `put the output
+ # in D'.
rm -rf conftest.dir
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
@@ -3777,16 +3761,16 @@
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
- # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
- # Solaris 10 /bin/sh.
- echo '/* dummy */' > sub/conftst$i.h
+ # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+ # Solaris 8's {/usr,}/bin/sh.
+ touch sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
- # We check with '-c' and '-o' for the sake of the "dashmstdout"
+ # We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
- # handle '-M -o', and we need to detect this. Also, some Intel
- # versions had trouble with output in subdirs.
+ # handle `-M -o', and we need to detect this. Also, some Intel
+ # versions had trouble with output in subdirs
am__obj=sub/conftest.${OBJEXT-o}
am__minus_obj="-o $am__obj"
case $depmode in
@@ -3795,8 +3779,8 @@
test "$am__universal" = false || continue
;;
nosideeffect)
- # After this tag, mechanisms are not by side-effect, so they'll
- # only be used when explicitly requested.
+ # after this tag, mechanisms are not by side-effect, so they'll
+ # only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
@@ -3804,7 +3788,7 @@
fi
;;
msvc7 | msvc7msys | msvisualcpp | msvcmsys)
- # This compiler won't grok '-c -o', but also, the minuso test has
+ # This compiler won't grok `-c -o', but also, the minuso test has
# not run yet. These depmodes are late enough in the game, and
# so weak that their functioning should not be impacted.
am__obj=conftest.${OBJEXT-o}
@@ -4578,7 +4562,8 @@
;;
*)
lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
- if test -n "$lt_cv_sys_max_cmd_len"; then
+ if test -n "$lt_cv_sys_max_cmd_len" && \
+ test undefined != "$lt_cv_sys_max_cmd_len"; then
lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
else
@@ -4979,10 +4964,6 @@
fi
;;
-gnu*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
haiku*)
lt_cv_deplibs_check_method=pass_all
;;
@@ -5021,11 +5002,11 @@
;;
# This must be glibc/ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
lt_cv_deplibs_check_method=pass_all
;;
-netbsd*)
+netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
else
@@ -6119,7 +6100,14 @@
LD="${LD-ld} -m elf_i386_fbsd"
;;
x86_64-*linux*)
- LD="${LD-ld} -m elf_i386"
+ case `/usr/bin/file conftest.o` in
+ *x86-64*)
+ LD="${LD-ld} -m elf32_x86_64"
+ ;;
+ *)
+ LD="${LD-ld} -m elf_i386"
+ ;;
+ esac
;;
ppc64-*linux*|powerpc64-*linux*)
LD="${LD-ld} -m elf32ppclinux"
@@ -7948,7 +7936,7 @@
lt_prog_compiler_static='-non_shared'
;;
- linux* | k*bsd*-gnu | kopensolaris*-gnu)
+ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
case $cc_basename in
# old Intel for x86_64 which still supported -KPIC.
ecc*)
@@ -8426,6 +8414,9 @@
openbsd*)
with_gnu_ld=no
;;
+ linux* | k*bsd*-gnu | gnu*)
+ link_all_deplibs=no
+ ;;
esac
ld_shlibs=yes
@@ -8647,7 +8638,7 @@
fi
;;
- netbsd*)
+ netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
wlarc=
@@ -8824,6 +8815,7 @@
if test "$aix_use_runtimelinking" = yes; then
shared_flag="$shared_flag "'${wl}-G'
fi
+ link_all_deplibs=no
else
# not using gcc
if test "$host_cpu" = ia64; then
@@ -9277,7 +9269,7 @@
link_all_deplibs=yes
;;
- netbsd*)
+ netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out
else
@@ -10114,17 +10106,6 @@
esac
;;
-gnu*)
- version_type=linux # correct to gnu/linux during the next big refactor
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=no
- hardcode_into_libs=yes
- ;;
-
haiku*)
version_type=linux # correct to gnu/linux during the next big refactor
need_lib_prefix=no
@@ -10241,7 +10222,7 @@
;;
# This must be glibc/ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
version_type=linux # correct to gnu/linux during the next big refactor
need_lib_prefix=no
need_version=no
@@ -10305,6 +10286,18 @@
dynamic_linker='GNU/Linux ld.so'
;;
+netbsdelf*-gnu)
+ version_type=linux
+ need_lib_prefix=no
+ need_version=no
+ library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+ soname_spec='${libname}${release}${shared_ext}$major'
+ shlibpath_var=LD_LIBRARY_PATH
+ shlibpath_overrides_runpath=no
+ hardcode_into_libs=yes
+ dynamic_linker='NetBSD ld.elf_so'
+ ;;
+
netbsd*)
version_type=sunos
need_lib_prefix=no
@@ -11826,8 +11819,8 @@
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
- # making a dummy file named 'D' -- because '-MD' means "put the output
- # in D".
+ # making a dummy file named `D' -- because `-MD' means `put the output
+ # in D'.
rm -rf conftest.dir
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
@@ -11862,16 +11855,16 @@
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
- # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
- # Solaris 10 /bin/sh.
- echo '/* dummy */' > sub/conftst$i.h
+ # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+ # Solaris 8's {/usr,}/bin/sh.
+ touch sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
- # We check with '-c' and '-o' for the sake of the "dashmstdout"
+ # We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
- # handle '-M -o', and we need to detect this. Also, some Intel
- # versions had trouble with output in subdirs.
+ # handle `-M -o', and we need to detect this. Also, some Intel
+ # versions had trouble with output in subdirs
am__obj=sub/conftest.${OBJEXT-o}
am__minus_obj="-o $am__obj"
case $depmode in
@@ -11880,8 +11873,8 @@
test "$am__universal" = false || continue
;;
nosideeffect)
- # After this tag, mechanisms are not by side-effect, so they'll
- # only be used when explicitly requested.
+ # after this tag, mechanisms are not by side-effect, so they'll
+ # only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
@@ -11889,7 +11882,7 @@
fi
;;
msvc7 | msvc7msys | msvisualcpp | msvcmsys)
- # This compiler won't grok '-c -o', but also, the minuso test has
+ # This compiler won't grok `-c -o', but also, the minuso test has
# not run yet. These depmodes are late enough in the game, and
# so weak that their functioning should not be impacted.
am__obj=conftest.${OBJEXT-o}
@@ -11947,6 +11940,15 @@
+case "$host:$CC" in
+ *darwin* )
+ RES=`gcc -Wall -fno-color-diagnostics src/lib/ndpi_main.c 2>&1 | grep "unrecognized command line option "|wc -l`
+ if test $RES -eq 0; then
+ PLATFORM_DEPENDENT="-fno-color-diagnostics"
+ fi
+ ;;
+esac
+
for ac_header in netinet/in.h stdint.h stdlib.h string.h unistd.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -11963,6 +11965,11 @@
ac_config_files="$ac_config_files Makefile src/lib/Makefile src/include/Makefile libndpi.pc"
+
+ac_config_headers="$ac_config_headers config.h"
+
+
+
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
@@ -12053,43 +12060,7 @@
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-# Transform confdefs.h into DEFS.
-# Protect against shell expansion while executing Makefile rules.
-# Protect against Makefile macro expansion.
-#
-# If the first sed substitution is executed (which looks for macros that
-# take arguments), then branch to the quote section. Otherwise,
-# look for a macro that doesn't take arguments.
-ac_script='
-:mline
-/\\$/{
- N
- s,\\\n,,
- b mline
-}
-t clear
-:clear
-s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g
-t quote
-s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g
-t quote
-b any
-:quote
-s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g
-s/\[/\\&/g
-s/\]/\\&/g
-s/\$/$$/g
-H
-:any
-${
- g
- s/^\n//
- s/\n/ /g
- p
-}
-'
-DEFS=`sed -n "$ac_script" confdefs.h`
-
+DEFS=-DHAVE_CONFIG_H
ac_libobjs=
ac_ltlibobjs=
@@ -12108,14 +12079,6 @@
LTLIBOBJS=$ac_ltlibobjs
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5
-$as_echo_n "checking that generated files are newer than configure... " >&6; }
- if test -n "$am_sleep_pid"; then
- # Hide warnings about reused PIDs.
- wait $am_sleep_pid 2>/dev/null
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5
-$as_echo "done" >&6; }
if test -n "$EXEEXT"; then
am__EXEEXT_TRUE=
am__EXEEXT_FALSE='#'
@@ -12551,11 +12514,15 @@
"*) set x $ac_config_files; shift; ac_config_files=$*;;
esac
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
# Files that config.status was made for.
config_files="$ac_config_files"
+config_headers="$ac_config_headers"
config_commands="$ac_config_commands"
_ACEOF
@@ -12577,10 +12544,15 @@
--recheck update $as_me by reconfiguring in the same conditions
--file=FILE[:TEMPLATE]
instantiate the configuration file FILE
+ --header=FILE[:TEMPLATE]
+ instantiate the configuration header FILE
Configuration files:
$config_files
+Configuration headers:
+$config_headers
+
Configuration commands:
$config_commands
@@ -12647,7 +12619,18 @@
esac
as_fn_append CONFIG_FILES " '$ac_optarg'"
ac_need_defaults=false;;
- --he | --h | --help | --hel | -h )
+ --header | --heade | --head | --hea )
+ $ac_shift
+ case $ac_optarg in
+ *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ esac
+ as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+ ac_need_defaults=false;;
+ --he | --h)
+ # Conflict between --help and --header
+ as_fn_error $? "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+ --help | --hel | -h )
$as_echo "$ac_cs_usage"; exit ;;
-q | -quiet | --quiet | --quie | --qui | --qu | --q \
| -silent | --silent | --silen | --sile | --sil | --si | --s)
@@ -12991,6 +12974,7 @@
"src/lib/Makefile") CONFIG_FILES="$CONFIG_FILES src/lib/Makefile" ;;
"src/include/Makefile") CONFIG_FILES="$CONFIG_FILES src/include/Makefile" ;;
"libndpi.pc") CONFIG_FILES="$CONFIG_FILES libndpi.pc" ;;
+ "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac
@@ -13003,6 +12987,7 @@
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+ test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
fi
@@ -13191,8 +13176,116 @@
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
fi # test -n "$CONFIG_FILES"
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+ ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
+ if test -z "$ac_tt"; then
+ break
+ elif $ac_last_try; then
+ as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+ else
+ ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+ fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any. Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[ ]*#[ ]*define[ ][ ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ for (key in D) D_is_set[key] = 1
+ FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+ line = \$ 0
+ split(line, arg, " ")
+ if (arg[1] == "#") {
+ defundef = arg[2]
+ mac1 = arg[3]
+ } else {
+ defundef = substr(arg[1], 2)
+ mac1 = arg[2]
+ }
+ split(mac1, mac2, "(") #)
+ macro = mac2[1]
+ prefix = substr(line, 1, index(line, defundef) - 1)
+ if (D_is_set[macro]) {
+ # Preserve the white space surrounding the "#".
+ print prefix "define", macro P[macro] D[macro]
+ next
+ } else {
+ # Replace #undef with comments. This is necessary, for example,
+ # in the case of _POSIX_SOURCE, which is predefined and required
+ # on some systems where configure will not decide to define it.
+ if (defundef == "undef") {
+ print "/*", prefix defundef, macro, "*/"
+ next
+ }
+ }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
-eval set X " :F $CONFIG_FILES :C $CONFIG_COMMANDS"
+
+eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS"
shift
for ac_tag
do
@@ -13411,7 +13504,64 @@
esac \
|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
;;
-
+ :H)
+ #
+ # CONFIG_HEADER
+ #
+ if test x"$ac_file" != x-; then
+ {
+ $as_echo "/* $configure_input */" \
+ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
+ } >"$ac_tmp/config.h" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
+ else
+ rm -f "$ac_file"
+ mv "$ac_tmp/config.h" "$ac_file" \
+ || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ fi
+ else
+ $as_echo "/* $configure_input */" \
+ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
+ || as_fn_error $? "could not create -" "$LINENO" 5
+ fi
+# Compute "$ac_file"'s index in $config_headers.
+_am_arg="$ac_file"
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+ case $_am_header in
+ $_am_arg | $_am_arg:* )
+ break ;;
+ * )
+ _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+ esac
+done
+echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
+$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$_am_arg" : 'X\(//\)[^/]' \| \
+ X"$_am_arg" : 'X\(//\)$' \| \
+ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$_am_arg" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)[^/].*/{
+ s//\1/
+ q
+ }
+ /^X\(\/\/\)$/{
+ s//\1/
+ q
+ }
+ /^X\(\/\).*/{
+ s//\1/
+ q
+ }
+ s/.*/./; q'`/stamp-h$_am_stamp_count
+ ;;
:C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
$as_echo "$as_me: executing $ac_file commands" >&6;}
@@ -13434,7 +13584,7 @@
# Strip MF so we end up with the name of the file.
mf=`echo "$mf" | sed -e 's/:.*$//'`
# Check whether this is an Automake generated Makefile or not.
- # We used to match only the files named 'Makefile.in', but
+ # We used to match only the files named `Makefile.in', but
# some people rename them; so instead we look at the file content.
# Grep'ing the first line is not enough: some people post-process
# each Makefile.in and add a new line on top of each file to say so.
@@ -13468,19 +13618,21 @@
continue
fi
# Extract the definition of DEPDIR, am__include, and am__quote
- # from the Makefile without running 'make'.
+ # from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
am__include=`sed -n 's/^am__include = //p' < "$mf"`
test -z "am__include" && continue
am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+ # When using ansi2knr, U may be empty or an underscore; expand it
+ U=`sed -n 's/^U = //p' < "$mf"`
# Find all dependency output files, they are included files with
# $(DEPDIR) in their names. We invoke sed twice because it is the
# simplest approach to changing $(DEPDIR) to its actual value in the
# expansion.
for file in `sed -n "
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
- sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do
+ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`$as_dirname -- "$file" ||
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/configure.ac
^
|
@@ -10,6 +10,15 @@
LT_INIT
+case "$host:$CC" in
+ *darwin* )
+ RES=`gcc -Wall -fno-color-diagnostics src/lib/ndpi_main.c 2>&1 | grep "unrecognized command line option "|wc -l`
+ if test $RES -eq 0; then
+ PLATFORM_DEPENDENT="-fno-color-diagnostics"
+ fi
+ ;;
+esac
+
AC_CHECK_HEADERS([netinet/in.h stdint.h stdlib.h string.h unistd.h])
AC_CONFIG_FILES([Makefile
@@ -17,4 +26,8 @@
src/include/Makefile
libndpi.pc
])
+
+AC_CONFIG_HEADERS(config.h)
+AC_SUBST(PLATFORM_DEPENDENT)
+
AC_OUTPUT
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/depcomp
^
|
@@ -3,7 +3,8 @@
scriptversion=2012-03-27.16; # UTC
-# Copyright (C) 1999-2012 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
+# 2011, 2012 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/example/Makefile
^
|
@@ -1,8 +1,8 @@
INC=-I../src/include/
LIB=../src/lib/.libs/libndpi.a -lpcap
-FLAGS=-g
+FLAGS=-g #-fno-color-diagnostics
pcapReader: pcapReader.c Makefile ../src/lib/.libs/libndpi.a
- gcc $(FLAGS) $(INC) pcapReader.c -o pcapReader $(LIB)
+ gcc $(FLAGS) $(INC) pcapReader.c -o pcapReader $(LIB) -lpthread
clean:
\/bin/rm -f pcapReader
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/example/pcapReader.c
^
|
@@ -1,895 +1,952 @@
-/*
- * pcapReader.c
- *
- * Copyright (C) 2011-13 - ntop.org
- * Copyright (C) 2009-2011 by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#ifdef WIN32
-#include <winsock2.h> /* winsock.h is included automatically */
-#include <process.h>
-#include <io.h>
-#include <getopt.h>
-#define getopt getopt____
-#else
-#include <unistd.h>
-#include <netinet/in.h>
-#endif
-#include <string.h>
-#include <stdarg.h>
-#include <search.h>
-#include <pcap.h>
-#include <signal.h>
-
-#include "linux_compat.h"
-#include "ndpi_main.h"
-
-static void setupDetection(void);
-
-// cli options
-static char *_pcap_file = NULL;
-static char *_bpf_filter = NULL;
-static char *_protoFilePath = NULL;
-
-// pcap
-static char _pcap_error_buffer[PCAP_ERRBUF_SIZE];
-static pcap_t *_pcap_handle = NULL;
-static int _pcap_datalink_type = 0;
-static u_int8_t enable_protocol_guess = 1, verbose = 0;
-static u_int32_t guessed_flow_protocols = 0;
-static u_int16_t decode_tunnels = 0;
-static u_int16_t num_loops = 1;
-static u_int8_t shutdown_app = 0;
-
-// detection
-static struct ndpi_detection_module_struct *ndpi_struct = NULL;
-static u_int32_t detection_tick_resolution = 1000;
-static time_t capture_until = 0;
-
-// results
-static u_int64_t raw_packet_count = 0;
-static u_int64_t ip_packet_count = 0;
-static u_int64_t total_bytes = 0;
-static u_int64_t protocol_counter[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
-static u_int64_t protocol_counter_bytes[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
-static u_int32_t protocol_flows[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1] = { 0 };
-
-
-#define GTP_U_V1_PORT 2152
-#define MAX_NDPI_FLOWS 2000000
-// id tracking
-typedef struct ndpi_id {
- u_int8_t ip[4];
- struct ndpi_id_struct *ndpi_id;
-} ndpi_id_t;
-
-static u_int32_t size_id_struct = 0;
-
-#ifndef ETH_P_IP
-#define ETH_P_IP 0x0800
-#endif
-
-// flow tracking
-typedef struct ndpi_flow {
- u_int32_t lower_ip;
- u_int32_t upper_ip;
- u_int16_t lower_port;
- u_int16_t upper_port;
- u_int8_t detection_completed, protocol;
- struct ndpi_flow_struct *ndpi_flow;
-
- u_int16_t packets, bytes;
- // result only, not used for flow identification
- u_int32_t detected_protocol;
-
- void *src_id, *dst_id;
-} ndpi_flow_t;
-
-#define NUM_ROOTS 512
-
-static u_int32_t size_flow_struct = 0;
-static struct ndpi_flow *ndpi_flows_root[NUM_ROOTS] = { NULL };
-static u_int32_t ndpi_flow_count = 0;
-
-
-static void help(u_int long_help) {
- printf("pcapReader -i <file|device> [-f <filter>][-s <duration>]\n"
- " [-p <protos>][-l <loops>[-d][-h][-t][-v]\n\n"
- "Usage:\n"
- " -i <file.pcap|device> | Specify a pcap file to read packets from or a device for live capture\n"
- " -f <BPF filter> | Specify a BPF filter for filtering selected traffic\n"
- " -s <duration> | Maximum capture duration in seconds (live traffic capture only)\n"
- " -p <file>.protos | Specify a protocol file (eg. protos.txt)\n"
- " -l <num loops> | Number of detection loops (test only)\n"
- " -d | Disable protocol guess and use only DPI\n"
- " -t | Dissect GTP tunnels\n"
- " -h | This help\n"
- " -v | Verbose 'unknown protocol' packet print\n");
-
- if(long_help) {
- printf("\n\nSupported protocols:\n");
- setupDetection();
- ndpi_dump_protocols(ndpi_struct);
- }
-
- exit(-1);
-}
-
-static void parseOptions(int argc, char **argv)
-{
- int opt;
-
- while ((opt = getopt(argc, argv, "df:i:hp:l:s:tv")) != EOF) {
- switch (opt) {
- case 'd':
- enable_protocol_guess = 0;
- break;
-
- case 'i':
- _pcap_file = optarg;
- break;
-
- case 'f':
- _bpf_filter = optarg;
- break;
-
- case 'l':
- num_loops = atoi(optarg);
- break;
-
- case 'p':
- _protoFilePath = optarg;
- break;
-
- case 's':
- capture_until = atoi(optarg);
- break;
-
- case 't':
- decode_tunnels = 1;
- break;
-
- case 'v':
- verbose = 1;
- break;
-
- case 'h':
- help(1);
- break;
-
- default:
- help(0);
- break;
- }
- }
-
- // check parameters
- if (_pcap_file == NULL || strcmp(_pcap_file, "") == 0) {
- help(0);
- }
-}
-
-static void debug_printf(u_int32_t protocol, void *id_struct,
- ndpi_log_level_t log_level,
- const char *format, ...) {
-}
-
-static void *malloc_wrapper(unsigned long size)
-{
- return malloc(size);
-}
-
-static void free_wrapper(void *freeable)
-{
- free(freeable);
-}
-
-
-static char* ipProto2Name(u_short proto_id) {
- static char proto[8];
-
- switch(proto_id) {
- case IPPROTO_TCP:
- return("TCP");
- break;
- case IPPROTO_UDP:
- return("UDP");
- break;
- case IPPROTO_ICMP:
- return("ICMP");
- break;
- case 112:
- return("VRRP");
- break;
- }
-
- snprintf(proto, sizeof(proto), "%u", proto_id);
- return(proto);
-}
-
-/*
- * A faster replacement for inet_ntoa().
- */
-char* intoaV4(unsigned int addr, char* buf, u_short bufLen) {
- char *cp, *retStr;
- uint byte;
- int n;
-
- cp = &buf[bufLen];
- *--cp = '\0';
-
- n = 4;
- do {
- byte = addr & 0xff;
- *--cp = byte % 10 + '0';
- byte /= 10;
- if (byte > 0) {
- *--cp = byte % 10 + '0';
- byte /= 10;
- if (byte > 0)
- *--cp = byte + '0';
- }
- *--cp = '.';
- addr >>= 8;
- } while (--n > 0);
-
- /* Convert the string to lowercase */
- retStr = (char*)(cp+1);
-
- return(retStr);
-}
-
-static void printFlow(struct ndpi_flow *flow) {
- char buf1[32], buf2[32];
-
- printf("\t%s %s:%u > %s:%u [proto: %u/%s][%u pkts/%u bytes]\n",
- ipProto2Name(flow->protocol),
- intoaV4(ntohl(flow->lower_ip), buf1, sizeof(buf1)),
- ntohs(flow->lower_port),
- intoaV4(ntohl(flow->upper_ip), buf2, sizeof(buf2)),
- ntohs(flow->upper_port),
- flow->detected_protocol,
- ndpi_get_proto_name(ndpi_struct, flow->detected_protocol),
- flow->packets, flow->bytes);
-}
-
-static void node_print_unknown_proto_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
- struct ndpi_flow *flow = *(struct ndpi_flow**)node;
-
- if (flow->detected_protocol != 0 /* UNKNOWN */) return;
-
- if((which == ndpi_preorder) || (which == ndpi_leaf)) /* Avoid walking the same node multiple times */
- printFlow(flow);
-}
-
-static void node_print_known_proto_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
- struct ndpi_flow *flow = *(struct ndpi_flow**)node;
-
- if (flow->detected_protocol == 0 /* UNKNOWN */) return;
-
- if((which == ndpi_preorder) || (which == ndpi_leaf)) /* Avoid walking the same node multiple times */
- printFlow(flow);
-}
-
-static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
- struct ndpi_flow *flow = *(struct ndpi_flow**)node;
-
-#if 0
- printf("<%d>Walk on node %s (%p)\n",
- depth,
- which == preorder?"preorder":
- which == postorder?"postorder":
- which == endorder?"endorder":
- which == leaf?"leaf": "unknown",
- flow);
-#endif
-
- if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
- if(enable_protocol_guess) {
- if (flow->detected_protocol == 0 /* UNKNOWN */) {
- flow->detected_protocol = ndpi_guess_undetected_protocol(ndpi_struct,
- flow->protocol,
- ntohl(flow->lower_ip),
- ntohs(flow->lower_port),
- ntohl(flow->upper_ip),
- ntohs(flow->upper_port));
-
- if (flow->detected_protocol != 0)
- guessed_flow_protocols++;
-
- // printFlow(flow);
- }
- }
-
- protocol_counter[flow->detected_protocol] += flow->packets;
- protocol_counter_bytes[flow->detected_protocol] += flow->bytes;
- protocol_flows[flow->detected_protocol]++;
- }
-}
-
-static int node_cmp(const void *a, const void *b) {
- struct ndpi_flow *fa = (struct ndpi_flow*)a;
- struct ndpi_flow *fb = (struct ndpi_flow*)b;
-
- if(fa->lower_ip < fb->lower_ip) return(-1); else { if(fa->lower_ip > fb->lower_ip) return(1); }
- if(fa->lower_port < fb->lower_port) return(-1); else { if(fa->lower_port > fb->lower_port) return(1); }
- if(fa->upper_ip < fb->upper_ip) return(-1); else { if(fa->upper_ip > fb->upper_ip) return(1); }
- if(fa->upper_port < fb->upper_port) return(-1); else { if(fa->upper_port > fb->upper_port) return(1); }
- if(fa->protocol < fb->protocol) return(-1); else { if(fa->protocol > fb->protocol) return(1); }
-
- return(0);
-}
-
-
-static struct ndpi_flow *get_ndpi_flow(const struct ndpi_iphdr *iph, u_int16_t ipsize,
- struct ndpi_id_struct **src,
- struct ndpi_id_struct **dst)
-{
- u_int32_t idx;
- u_int16_t l4_packet_len;
- struct ndpi_tcphdr *tcph = NULL;
- struct ndpi_udphdr *udph = NULL;
- u_int32_t lower_ip;
- u_int32_t upper_ip;
- u_int16_t lower_port;
- u_int16_t upper_port;
- struct ndpi_flow flow;
- void *ret;
-
- if (ipsize < 20)
- return NULL;
-
- if ((iph->ihl * 4) > ipsize || ipsize < ntohs(iph->tot_len)
- || (iph->frag_off & htons(0x1FFF)) != 0)
- return NULL;
-
- l4_packet_len = ntohs(iph->tot_len) - (iph->ihl * 4);
-
- if (iph->saddr < iph->daddr) {
- lower_ip = iph->saddr;
- upper_ip = iph->daddr;
- } else {
- lower_ip = iph->daddr;
- upper_ip = iph->saddr;
- }
-
- if (iph->protocol == 6 && l4_packet_len >= 20) {
- // tcp
- tcph = (struct ndpi_tcphdr *) ((u_int8_t *) iph + iph->ihl * 4);
- if (iph->saddr < iph->daddr) {
- lower_port = tcph->source;
- upper_port = tcph->dest;
- } else {
- lower_port = tcph->dest;
- upper_port = tcph->source;
- }
- } else if (iph->protocol == 17 && l4_packet_len >= 8) {
- // udp
- udph = (struct ndpi_udphdr *) ((u_int8_t *) iph + iph->ihl * 4);
- if(iph->saddr < iph->daddr) {
- lower_port = udph->source;
- upper_port = udph->dest;
- } else {
- lower_port = udph->dest;
- upper_port = udph->source;
- }
- } else {
- // non tcp/udp protocols
- lower_port = 0;
- upper_port = 0;
- }
-
- flow.protocol = iph->protocol;
- flow.lower_ip = lower_ip;
- flow.upper_ip = upper_ip;
- flow.lower_port = lower_port;
- flow.upper_port = upper_port;
-
- idx = (lower_ip + upper_ip + iph->protocol + lower_port + upper_port) % NUM_ROOTS;
- ret = ndpi_tfind(&flow, (void*)&ndpi_flows_root[idx], node_cmp);
-
- if(ret == NULL) {
- if (ndpi_flow_count == MAX_NDPI_FLOWS) {
- printf("ERROR: maximum flow count (%u) has been exceeded\n", MAX_NDPI_FLOWS);
- exit(-1);
- } else {
- struct ndpi_flow *newflow = (struct ndpi_flow*)malloc(sizeof(struct ndpi_flow));
-
- if(newflow == NULL) {
- printf("[NDPI] %s(1): not enough memory\n", __FUNCTION__);
- return(NULL);
- }
-
- memset(newflow, 0, sizeof(struct ndpi_flow));
- newflow->protocol = iph->protocol;
- newflow->lower_ip = lower_ip, newflow->upper_ip = upper_ip;
- newflow->lower_port = lower_port, newflow->upper_port = upper_port;
-
- if((newflow->ndpi_flow = calloc(1, size_flow_struct)) == NULL) {
- printf("[NDPI] %s(2): not enough memory\n", __FUNCTION__);
- return(NULL);
- }
-
- if((newflow->src_id = calloc(1, size_id_struct)) == NULL) {
- printf("[NDPI] %s(3): not enough memory\n", __FUNCTION__);
- return(NULL);
- }
-
- if((newflow->dst_id = calloc(1, size_id_struct)) == NULL) {
- printf("[NDPI] %s(4): not enough memory\n", __FUNCTION__);
- return(NULL);
- }
-
- ndpi_tsearch(newflow, (void*)&ndpi_flows_root[idx], node_cmp); /* Add */
-
- ndpi_flow_count += 1;
-
- //printFlow(newflow);
-
- *src = newflow->src_id, *dst = newflow->dst_id;
- return(newflow);
- }
- } else {
- struct ndpi_flow *flow = *(struct ndpi_flow**)ret;
-
- if(flow->lower_ip == lower_ip && flow->upper_ip == upper_ip
- && flow->lower_port == lower_port && flow->upper_port == upper_port)
- *src = flow->src_id, *dst = flow->dst_id;
- else
- *src = flow->dst_id, *dst = flow->src_id;
-
- return flow;
- }
-}
-
-static void setupDetection(void)
-{
- NDPI_PROTOCOL_BITMASK all;
-
- // init global detection structure
- ndpi_struct = ndpi_init_detection_module(detection_tick_resolution, malloc_wrapper, free_wrapper, debug_printf);
- if (ndpi_struct == NULL) {
- printf("ERROR: global structure initialization failed\n");
- exit(-1);
- }
- // enable all protocols
- NDPI_BITMASK_SET_ALL(all);
- ndpi_set_protocol_detection_bitmask2(ndpi_struct, &all);
-
- // allocate memory for id and flow tracking
- size_id_struct = ndpi_detection_get_sizeof_ndpi_id_struct();
- size_flow_struct = ndpi_detection_get_sizeof_ndpi_flow_struct();
-
- // clear memory for results
- memset(protocol_counter, 0, sizeof(protocol_counter));
- memset(protocol_counter_bytes, 0, sizeof(protocol_counter_bytes));
- memset(protocol_flows, 0, sizeof(protocol_flows));
-
- if(_protoFilePath != NULL)
- ndpi_load_protocols_file(ndpi_struct, _protoFilePath);
-
- raw_packet_count = ip_packet_count = total_bytes = 0;
- ndpi_flow_count = 0;
-}
-
-static void free_ndpi_flow(struct ndpi_flow *flow) {
- if(flow->ndpi_flow) { ndpi_free(flow->ndpi_flow); flow->ndpi_flow = NULL; }
- if(flow->src_id) { ndpi_free(flow->src_id); flow->src_id = NULL; }
- if(flow->dst_id) { ndpi_free(flow->dst_id); flow->dst_id = NULL; }
-}
-
-static void ndpi_flow_freer(void *node) {
- struct ndpi_flow *flow = (struct ndpi_flow*)node;
- free_ndpi_flow(flow);
- ndpi_free(flow);
-}
-
-
-static void terminateDetection(void)
-{
- int i;
-
- for(i=0; i<NUM_ROOTS; i++) {
- ndpi_tdestroy(ndpi_flows_root[i], ndpi_flow_freer);
- ndpi_flows_root[i] = NULL;
- }
-
- ndpi_exit_detection_module(ndpi_struct, free_wrapper);
-}
-
-static unsigned int packet_processing(const u_int64_t time, const struct ndpi_iphdr *iph,
- u_int16_t ipsize, u_int16_t rawsize)
-{
- struct ndpi_id_struct *src, *dst;
- struct ndpi_flow *flow;
- struct ndpi_flow_struct *ndpi_flow = NULL;
- u_int32_t protocol = 0;
- u_int16_t frag_off = ntohs(iph->frag_off);
-
- flow = get_ndpi_flow(iph, ipsize, &src, &dst);
- if (flow != NULL) {
- ndpi_flow = flow->ndpi_flow;
- flow->packets++, flow->bytes += rawsize;
- } else
- return(0);
-
- ip_packet_count++;
- total_bytes += rawsize + 24 /* CRC etc */;
-
- if(flow->detection_completed) return;
-
- // only handle unfragmented packets
- if ((frag_off & 0x3FFF) == 0) {
- // here the actual detection is performed
- protocol = (const u_int32_t)ndpi_detection_process_packet(ndpi_struct, ndpi_flow, (uint8_t *) iph, ipsize, time, src, dst);
- } else {
- static u_int8_t frag_warning_used = 0;
-
- if (frag_warning_used == 0) {
- printf("\n\nWARNING: fragmented ip packets are not supported and will be skipped \n\n");
- frag_warning_used = 1;
- }
-
- return 0;
- }
-
-#if 0
- if(verbose && (protocol == 0)) {
- char buf1[32], buf2[32];
-
- printf("%s %s:%u > %s:%u [proto: %u/%s]\n",
- ipProto2Name(flow->protocol),
- intoaV4(ntohl(flow->lower_ip), buf1, sizeof(buf1)), ntohs(flow->lower_port),
- intoaV4(ntohl(flow->upper_ip), buf2, sizeof(buf2)), ntohs(flow->upper_port),
- protocol, ndpi_get_proto_name(ndpi_struct, protocol));
- }
-#endif
-
- flow->detected_protocol = protocol;
-
- if((flow->detected_protocol != NDPI_PROTOCOL_UNKNOWN)
- || (iph->protocol == IPPROTO_UDP)
- || ((iph->protocol == IPPROTO_TCP) && (flow->packets > 10))) {
- flow->detection_completed = 1;
-
-#if 0
- if(flow->ndpi_flow->l4.tcp.host_server_name[0] != '\0')
- printf("%s\n", flow->ndpi_flow->l4.tcp.host_server_name);
-#endif
-
- free_ndpi_flow(flow);
- }
-
-#if 0
- if(ndpi_flow->l4.tcp.host_server_name[0] != '\0')
- printf("%s\n", ndpi_flow->l4.tcp.host_server_name);
-#endif
-
- return 0;
-}
-
-/* ****************************************************** */
-
-
-char* formatTraffic(float numBits, int bits, char *buf) {
- char unit;
-
- if(bits)
- unit = 'b';
- else
- unit = 'B';
-
- if(numBits < 1024) {
- snprintf(buf, 32, "%lu %c", (unsigned long)numBits, unit);
- } else if (numBits < 1048576) {
- snprintf(buf, 32, "%.2f K%c", (float)(numBits)/1024, unit);
- } else {
- float tmpMBits = ((float)numBits)/1048576;
-
- if(tmpMBits < 1024) {
- snprintf(buf, 32, "%.2f M%c", tmpMBits, unit);
- } else {
- tmpMBits /= 1024;
-
- if(tmpMBits < 1024) {
- snprintf(buf, 32, "%.2f G%c", tmpMBits, unit);
- } else {
- snprintf(buf, 32, "%.2f T%c", (float)(tmpMBits)/1024, unit);
- }
- }
- }
-
- return(buf);
-}
-
-char* formatPackets(float numPkts, char *buf) {
- if(numPkts < 1000) {
- snprintf(buf, 32, "%.2f", numPkts);
- } else if(numPkts < 1000000) {
- snprintf(buf, 32, "%.2f K", numPkts/1000);
- } else {
- numPkts /= 1000000;
- snprintf(buf, 32, "%.2f M", numPkts);
- }
-
- return(buf);
-}
-
-static void printResults(u_int64_t tot_usec)
-{
- u_int32_t i;
-
- printf("\x1b[2K\n");
- printf("pcap file contains\n");
- printf("\tIP packets: \x1b[33m%-13llu\x1b[0m of %llu packets total\n",
- (long long unsigned int)ip_packet_count,
- (long long unsigned int)raw_packet_count);
- printf("\tIP bytes: \x1b[34m%-13llu\x1b[0m\n",
- (long long unsigned int)total_bytes);
- printf("\tUnique flows: \x1b[36m%-13u\x1b[0m\n", ndpi_flow_count);
-
- if(tot_usec > 0) {
- char buf[32], buf1[32];
- float t = (float)(ip_packet_count*1000000)/(float)tot_usec;
- float b = (float)(total_bytes * 8 *1000000)/(float)tot_usec;
-
- printf("\tnDPI throughout: \x1b[36m%s pps / %s/sec\x1b[0m\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
- }
-
- for(i=0; i<NUM_ROOTS; i++)
- ndpi_twalk(ndpi_flows_root[i], node_proto_guess_walker, NULL);
-
- if(enable_protocol_guess)
- printf("\tGuessed flow protocols: \x1b[35m%-13u\x1b[0m\n", guessed_flow_protocols);
-
- printf("\n\nDetected protocols:\n");
- for (i = 0; i <= ndpi_get_num_supported_protocols(ndpi_struct); i++) {
- if (protocol_counter[i] > 0) {
- printf("\t\x1b[31m%-20s\x1b[0m packets: \x1b[33m%-13llu\x1b[0m bytes: \x1b[34m%-13llu\x1b[0m "
- "flows: \x1b[36m%-13u\x1b[0m\n",
- ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i],
- (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]);
- }
- }
-
- if(verbose && (protocol_counter[0] > 0)) {
- printf("\n");
-
- for(i=0; i<NUM_ROOTS; i++)
- ndpi_twalk(ndpi_flows_root[i], node_print_known_proto_walker, NULL);
-
- printf("\n\nUndetected flows:\n");
- for(i=0; i<NUM_ROOTS; i++)
- ndpi_twalk(ndpi_flows_root[i], node_print_unknown_proto_walker, NULL);
- }
-
- printf("\n\n");
-}
-
-static void closePcapFile(void)
-{
- if (_pcap_handle != NULL) {
- pcap_close(_pcap_handle);
- }
-}
-
-// executed for each packet in the pcap file
-void sigproc(int sig) {
- static int called = 0;
-
- if(called) return; else called = 1;
- shutdown_app = 1;
-
- closePcapFile();
- printResults(0);
- terminateDetection();
- exit(0);
-}
-
-static void openPcapFileOrDevice(void)
-{
- u_int snaplen = 1514;
- int promisc = 1;
- char errbuf[PCAP_ERRBUF_SIZE];
-
- if((_pcap_handle = pcap_open_live(_pcap_file, snaplen, promisc, 500, errbuf)) == NULL) {
- _pcap_handle = pcap_open_offline(_pcap_file, _pcap_error_buffer);
- capture_until = 0;
-
- if (_pcap_handle == NULL) {
- printf("ERROR: could not open pcap file: %s\n", _pcap_error_buffer);
- exit(-1);
- } else
- printf("Reading packets from pcap file %s...\n", _pcap_file);
- } else
- printf("Capturing live traffic from device %s...\n", _pcap_file);
-
- _pcap_datalink_type = pcap_datalink(_pcap_handle);
-
- if(_bpf_filter != NULL) {
- struct bpf_program fcode;
-
- if(pcap_compile(_pcap_handle, &fcode, _bpf_filter, 1, 0xFFFFFF00) < 0) {
- printf("pcap_compile error: '%s'\n", pcap_geterr(_pcap_handle));
- } else {
- if(pcap_setfilter(_pcap_handle, &fcode) < 0) {
- printf("pcap_setfilter error: '%s'\n", pcap_geterr(_pcap_handle));
- } else
- printf("Succesfully set BPF filter to '%s'\n", _bpf_filter);
- }
- }
-
- if(capture_until > 0) {
- printf("Capturing traffic up to %u seconds\n", (unsigned int)capture_until);
-
-#ifndef WIN32
- alarm(capture_until);
- signal(SIGALRM, sigproc);
-#endif
- capture_until += time(NULL);
- }
-}
-
-static void pcap_packet_callback(u_char * args, const struct pcap_pkthdr *header, const u_char * packet)
-{
- const struct ndpi_ethhdr *ethernet;
- struct ndpi_iphdr *iph;
- u_int64_t time;
- static u_int64_t lasttime = 0;
- u_int16_t type, ip_offset;
-
- raw_packet_count++;
-
- if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) {
- if(_pcap_handle != NULL)
- pcap_breakloop(_pcap_handle);
-
- return;
- }
-
- time = ((uint64_t) header->ts.tv_sec) * detection_tick_resolution +
- header->ts.tv_usec / (1000000 / detection_tick_resolution);
- if (lasttime > time) {
- // printf("\nWARNING: timestamp bug in the pcap file (ts delta: %llu, repairing)\n", lasttime - time);
- time = lasttime;
- }
- lasttime = time;
-
- if(_pcap_datalink_type == DLT_EN10MB) {
- ethernet = (struct ndpi_ethhdr *) packet;
- ip_offset = sizeof(struct ndpi_ethhdr);
- type = ntohs(ethernet->h_proto);
- } else if(_pcap_datalink_type == 113 /* Linux Cooked Capture */) {
- type = packet[14] << 8 + packet[15];
- ip_offset = 16;
- } else
- return;
-
- if(type == 0x8100 /* VLAN */) {
- type = packet[ip_offset+2] << 8 + packet[ip_offset+3];
- ip_offset += 4;
- }
-
- iph = (struct ndpi_iphdr *) &packet[ip_offset];
-
- // just work on Ethernet packets that contain IP
- if (type == ETH_P_IP && header->caplen >= ip_offset) {
- u_int16_t frag_off = ntohs(iph->frag_off);
-
- if(header->caplen < header->len) {
- static u_int8_t cap_warning_used = 0;
- if (cap_warning_used == 0) {
- printf("\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
- cap_warning_used = 1;
- }
- }
-
- if (iph->version != 4) {
- static u_int8_t ipv4_warning_used = 0;
-
- v4_warning:
- if (ipv4_warning_used == 0) {
- printf("\n\nWARNING: only IPv4 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
- ipv4_warning_used = 1;
- }
- return;
- }
-
- if(decode_tunnels && (iph->protocol == IPPROTO_UDP) && ((frag_off & 0x3FFF) == 0)) {
- u_short ip_len = ((u_short)iph->ihl * 4);
- struct ndpi_udphdr *udp = (struct ndpi_udphdr *)&packet[ip_offset+ip_len];
- u_int16_t sport = ntohs(udp->source), dport = ntohs(udp->dest);
-
- if((sport == GTP_U_V1_PORT) || (dport == GTP_U_V1_PORT)) {
- /* Check if it's GTPv1 */
- u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
- u_int8_t flags = packet[offset];
- u_int8_t message_type = packet[offset+1];
-
- if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) && (message_type == 0xFF /* T-PDU */)) {
- ip_offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr)+8 /* GTPv1 header len */;
-
- if(flags & 0x04) ip_offset += 1; /* next_ext_header is present */
- if(flags & 0x02) ip_offset += 4; /* sequence_number is present (it also includes next_ext_header and pdu_number) */
- if(flags & 0x01) ip_offset += 1; /* pdu_number is present */
-
- iph = (struct ndpi_iphdr *) &packet[ip_offset];
-
- if (iph->version != 4) {
- // printf("WARNING: not good (packet_id=%u)!\n", (unsigned int)raw_packet_count);
- goto v4_warning;
- }
- }
- }
-
- }
-
- // process the packet
- packet_processing(time, iph, header->len - ip_offset, header->len);
- }
-}
-
-static void runPcapLoop(void)
-{
-
-
- if((!shutdown_app) && (_pcap_handle != NULL))
- pcap_loop(_pcap_handle, -1, &pcap_packet_callback, NULL);
-}
-
-void test_lib() {
- struct timeval begin, end;
- u_int64_t tot_usec;
-
- setupDetection();
- openPcapFileOrDevice();
- signal(SIGINT, sigproc);
-
- gettimeofday(&begin, NULL);
- runPcapLoop();
- gettimeofday(&end, NULL);
-
- tot_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec);
- closePcapFile();
- printResults(tot_usec);
- terminateDetection();
-}
-
-int main(int argc, char **argv)
-{
- int i;
-
- parseOptions(argc, argv);
-
- printf("\n-----------------------------------------------------------\n"
- "* NOTE: This is demo app to show *some* nDPI features.\n"
- "* In this demo we have implemented only some basic features\n"
- "* just to show you what you can do with the library. Feel \n"
- "* free to extend it and send us the patches for inclusion\n"
- "------------------------------------------------------------\n\n");
-
- for(i=0; i<num_loops; i++)
- test_lib();
-
- return 0;
-}
-
+/*
+ * pcapReader.c
+ *
+ * Copyright (C) 2011-13 - ntop.org
+ * Copyright (C) 2009-2011 by ipoque GmbH
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef WIN32
+#include <winsock2.h> /* winsock.h is included automatically */
+#include <process.h>
+#include <io.h>
+#include <getopt.h>
+#define getopt getopt____
+#else
+#include <unistd.h>
+#include <netinet/in.h>
+#endif
+#include <string.h>
+#include <stdarg.h>
+#include <search.h>
+#include <pcap.h>
+#include <signal.h>
+
+#include "../config.h"
+#include "linux_compat.h"
+#include "ndpi_main.h"
+
+static void setupDetection(void);
+
+// cli options
+static char *_pcap_file = NULL;
+static char *_bpf_filter = NULL;
+static char *_protoFilePath = NULL;
+
+// pcap
+static char _pcap_error_buffer[PCAP_ERRBUF_SIZE];
+static pcap_t *_pcap_handle = NULL;
+static int _pcap_datalink_type = 0;
+static u_int8_t enable_protocol_guess = 1, verbose = 0;
+static u_int32_t guessed_flow_protocols = 0;
+static u_int16_t decode_tunnels = 0;
+static u_int16_t num_loops = 1;
+static u_int8_t shutdown_app = 0;
+
+// detection
+static struct ndpi_detection_module_struct *ndpi_struct = NULL;
+static u_int32_t detection_tick_resolution = 1000;
+static time_t capture_until = 0;
+
+// results
+static u_int64_t raw_packet_count = 0;
+static u_int64_t ip_packet_count = 0;
+static u_int64_t total_bytes = 0;
+static u_int64_t protocol_counter[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
+static u_int64_t protocol_counter_bytes[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
+static u_int32_t protocol_flows[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1] = { 0 };
+
+
+#define GTP_U_V1_PORT 2152
+#define MAX_NDPI_FLOWS 2000000
+// id tracking
+typedef struct ndpi_id {
+ u_int8_t ip[4];
+ struct ndpi_id_struct *ndpi_id;
+} ndpi_id_t;
+
+static u_int32_t size_id_struct = 0;
+
+#ifndef ETH_P_IP
+#define ETH_P_IP 0x0800
+#endif
+
+// flow tracking
+typedef struct ndpi_flow {
+ u_int32_t lower_ip;
+ u_int32_t upper_ip;
+ u_int16_t lower_port;
+ u_int16_t upper_port;
+ u_int8_t detection_completed, protocol;
+ struct ndpi_flow_struct *ndpi_flow;
+
+ u_int16_t packets, bytes;
+ // result only, not used for flow identification
+ u_int32_t detected_protocol;
+ char host_server_name[48];
+
+ void *src_id, *dst_id;
+} ndpi_flow_t;
+
+#define NUM_ROOTS 512
+
+static u_int32_t size_flow_struct = 0;
+static struct ndpi_flow *ndpi_flows_root[NUM_ROOTS] = { NULL };
+static u_int32_t ndpi_flow_count = 0;
+
+
+static void help(u_int long_help) {
+ printf("pcapReader -i <file|device> [-f <filter>][-s <duration>]\n"
+ " [-p <protos>][-l <loops>[-d][-h][-t][-v <level>]\n\n"
+ "Usage:\n"
+ " -i <file.pcap|device> | Specify a pcap file to read packets from or a device for live capture\n"
+ " -f <BPF filter> | Specify a BPF filter for filtering selected traffic\n"
+ " -s <duration> | Maximum capture duration in seconds (live traffic capture only)\n"
+ " -p <file>.protos | Specify a protocol file (eg. protos.txt)\n"
+ " -l <num loops> | Number of detection loops (test only)\n"
+ " -d | Disable protocol guess and use only DPI\n"
+ " -t | Dissect GTP tunnels\n"
+ " -h | This help\n"
+ " -v <1|2> | Verbose 'unknown protocol' packet print. 1=verbose, 2=very verbose\n");
+
+ if(long_help) {
+ printf("\n\nSupported protocols:\n");
+ setupDetection();
+ ndpi_dump_protocols(ndpi_struct);
+ }
+
+ exit(-1);
+}
+
+static void parseOptions(int argc, char **argv)
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "df:i:hp:l:s:tv:")) != EOF) {
+ switch (opt) {
+ case 'd':
+ enable_protocol_guess = 0;
+ break;
+
+ case 'i':
+ _pcap_file = optarg;
+ break;
+
+ case 'f':
+ _bpf_filter = optarg;
+ break;
+
+ case 'l':
+ num_loops = atoi(optarg);
+ break;
+
+ case 'p':
+ _protoFilePath = optarg;
+ break;
+
+ case 's':
+ capture_until = atoi(optarg);
+ break;
+
+ case 't':
+ decode_tunnels = 1;
+ break;
+
+ case 'v':
+ verbose = atoi(optarg);
+ break;
+
+ case 'h':
+ help(1);
+ break;
+
+ default:
+ help(0);
+ break;
+ }
+ }
+
+ // check parameters
+ if(_pcap_file == NULL || strcmp(_pcap_file, "") == 0) {
+ help(0);
+ }
+}
+
+static void debug_printf(u_int32_t protocol, void *id_struct,
+ ndpi_log_level_t log_level,
+ const char *format, ...) {
+}
+
+static void *malloc_wrapper(unsigned long size)
+{
+ return malloc(size);
+}
+
+static void free_wrapper(void *freeable)
+{
+ free(freeable);
+}
+
+
+static char* ipProto2Name(u_short proto_id) {
+ static char proto[8];
+
+ switch(proto_id) {
+ case IPPROTO_TCP:
+ return("TCP");
+ break;
+ case IPPROTO_UDP:
+ return("UDP");
+ break;
+ case IPPROTO_ICMP:
+ return("ICMP");
+ break;
+ case 112:
+ return("VRRP");
+ break;
+ }
+
+ snprintf(proto, sizeof(proto), "%u", proto_id);
+ return(proto);
+}
+
+/*
+ * A faster replacement for inet_ntoa().
+ */
+char* intoaV4(unsigned int addr, char* buf, u_short bufLen) {
+ char *cp, *retStr;
+ uint byte;
+ int n;
+
+ cp = &buf[bufLen];
+ *--cp = '\0';
+
+ n = 4;
+ do {
+ byte = addr & 0xff;
+ *--cp = byte % 10 + '0';
+ byte /= 10;
+ if(byte > 0) {
+ *--cp = byte % 10 + '0';
+ byte /= 10;
+ if(byte > 0)
+ *--cp = byte + '0';
+ }
+ *--cp = '.';
+ addr >>= 8;
+ } while (--n > 0);
+
+ /* Convert the string to lowercase */
+ retStr = (char*)(cp+1);
+
+ return(retStr);
+}
+
+static void printFlow(struct ndpi_flow *flow) {
+ char buf1[32], buf2[32];
+
+ printf("\t%s %s:%u > %s:%u [proto: %u/%s][%u pkts/%u bytes][%s]\n",
+ ipProto2Name(flow->protocol),
+ intoaV4(ntohl(flow->lower_ip), buf1, sizeof(buf1)),
+ ntohs(flow->lower_port),
+ intoaV4(ntohl(flow->upper_ip), buf2, sizeof(buf2)),
+ ntohs(flow->upper_port),
+ flow->detected_protocol,
+ ndpi_get_proto_name(ndpi_struct, flow->detected_protocol),
+ flow->packets, flow->bytes,
+ flow->host_server_name);
+}
+
+static void node_print_unknown_proto_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
+ struct ndpi_flow *flow = *(struct ndpi_flow**)node;
+
+ if(flow->detected_protocol != 0 /* UNKNOWN */) return;
+
+ if((which == ndpi_preorder) || (which == ndpi_leaf)) /* Avoid walking the same node multiple times */
+ printFlow(flow);
+}
+
+static void node_print_known_proto_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
+ struct ndpi_flow *flow = *(struct ndpi_flow**)node;
+
+ if(flow->detected_protocol == 0 /* UNKNOWN */) return;
+
+ if((which == ndpi_preorder) || (which == ndpi_leaf)) /* Avoid walking the same node multiple times */
+ printFlow(flow);
+}
+
+static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
+ struct ndpi_flow *flow = *(struct ndpi_flow**)node;
+
+#if 0
+ printf("<%d>Walk on node %s (%p)\n",
+ depth,
+ which == preorder?"preorder":
+ which == postorder?"postorder":
+ which == endorder?"endorder":
+ which == leaf?"leaf": "unknown",
+ flow);
+#endif
+
+ if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
+ if(enable_protocol_guess) {
+ if(flow->detected_protocol == 0 /* UNKNOWN */) {
+ flow->detected_protocol = ndpi_guess_undetected_protocol(ndpi_struct,
+ flow->protocol,
+ ntohl(flow->lower_ip),
+ ntohs(flow->lower_port),
+ ntohl(flow->upper_ip),
+ ntohs(flow->upper_port));
+
+ if(flow->detected_protocol != 0)
+ guessed_flow_protocols++;
+
+ // printFlow(flow);
+ }
+ }
+
+ protocol_counter[flow->detected_protocol] += flow->packets;
+ protocol_counter_bytes[flow->detected_protocol] += flow->bytes;
+ protocol_flows[flow->detected_protocol]++;
+ }
+}
+
+static int node_cmp(const void *a, const void *b) {
+ struct ndpi_flow *fa = (struct ndpi_flow*)a;
+ struct ndpi_flow *fb = (struct ndpi_flow*)b;
+
+ if(fa->lower_ip < fb->lower_ip) return(-1); else { if(fa->lower_ip > fb->lower_ip) return(1); }
+ if(fa->lower_port < fb->lower_port) return(-1); else { if(fa->lower_port > fb->lower_port) return(1); }
+ if(fa->upper_ip < fb->upper_ip) return(-1); else { if(fa->upper_ip > fb->upper_ip) return(1); }
+ if(fa->upper_port < fb->upper_port) return(-1); else { if(fa->upper_port > fb->upper_port) return(1); }
+ if(fa->protocol < fb->protocol) return(-1); else { if(fa->protocol > fb->protocol) return(1); }
+
+ return(0);
+}
+
+
+static struct ndpi_flow *get_ndpi_flow(const u_int8_t version,
+ const struct ndpi_iphdr *iph,
+ u_int16_t ip_offset,
+ u_int16_t ipsize,
+ u_int16_t l4_packet_len,
+ struct ndpi_id_struct **src,
+ struct ndpi_id_struct **dst,
+ u_int8_t *proto)
+{
+ u_int32_t idx, l4_offset;
+ struct ndpi_tcphdr *tcph = NULL;
+ struct ndpi_udphdr *udph = NULL;
+ u_int32_t lower_ip;
+ u_int32_t upper_ip;
+ u_int16_t lower_port;
+ u_int16_t upper_port;
+ struct ndpi_flow flow;
+ void *ret;
+
+ if(version == 4) {
+ if(ipsize < 20)
+ return NULL;
+
+ if((iph->ihl * 4) > ipsize || ipsize < ntohs(iph->tot_len)
+ || (iph->frag_off & htons(0x1FFF)) != 0)
+ return NULL;
+ }
+
+ if(iph->saddr < iph->daddr) {
+ lower_ip = iph->saddr;
+ upper_ip = iph->daddr;
+ } else {
+ lower_ip = iph->daddr;
+ upper_ip = iph->saddr;
+ }
+
+ *proto = iph->protocol;
+ l4_offset = iph->ihl * 4;
+ if(iph->protocol == 6 && l4_packet_len >= 20) {
+ // tcp
+ tcph = (struct ndpi_tcphdr *) ((u_int8_t *) iph + l4_offset);
+ if(iph->saddr < iph->daddr) {
+ lower_port = tcph->source;
+ upper_port = tcph->dest;
+ } else {
+ lower_port = tcph->dest;
+ upper_port = tcph->source;
+ }
+ } else if(iph->protocol == 17 && l4_packet_len >= 8) {
+ // udp
+ udph = (struct ndpi_udphdr *) ((u_int8_t *) iph + l4_offset);
+ if(iph->saddr < iph->daddr) {
+ lower_port = udph->source;
+ upper_port = udph->dest;
+ } else {
+ lower_port = udph->dest;
+ upper_port = udph->source;
+ }
+ } else {
+ // non tcp/udp protocols
+ lower_port = 0;
+ upper_port = 0;
+ }
+
+ flow.protocol = iph->protocol;
+ flow.lower_ip = lower_ip;
+ flow.upper_ip = upper_ip;
+ flow.lower_port = lower_port;
+ flow.upper_port = upper_port;
+
+ /*
+ printf("[NDPI] [%u][%u:%u <-> %u:%u]\n",
+ iph->protocol, lower_ip, lower_port, upper_ip, upper_port);
+ */
+
+ idx = (lower_ip + upper_ip + iph->protocol + lower_port + upper_port) % NUM_ROOTS;
+ ret = ndpi_tfind(&flow, (void*)&ndpi_flows_root[idx], node_cmp);
+
+ if(ret == NULL) {
+ if(ndpi_flow_count == MAX_NDPI_FLOWS) {
+ printf("ERROR: maximum flow count (%u) has been exceeded\n", MAX_NDPI_FLOWS);
+ exit(-1);
+ } else {
+ struct ndpi_flow *newflow = (struct ndpi_flow*)malloc(sizeof(struct ndpi_flow));
+
+ if(newflow == NULL) {
+ printf("[NDPI] %s(1): not enough memory\n", __FUNCTION__);
+ return(NULL);
+ }
+
+ memset(newflow, 0, sizeof(struct ndpi_flow));
+ newflow->protocol = iph->protocol;
+ newflow->lower_ip = lower_ip, newflow->upper_ip = upper_ip;
+ newflow->lower_port = lower_port, newflow->upper_port = upper_port;
+
+ if((newflow->ndpi_flow = calloc(1, size_flow_struct)) == NULL) {
+ printf("[NDPI] %s(2): not enough memory\n", __FUNCTION__);
+ return(NULL);
+ }
+
+ if((newflow->src_id = calloc(1, size_id_struct)) == NULL) {
+ printf("[NDPI] %s(3): not enough memory\n", __FUNCTION__);
+ return(NULL);
+ }
+
+ if((newflow->dst_id = calloc(1, size_id_struct)) == NULL) {
+ printf("[NDPI] %s(4): not enough memory\n", __FUNCTION__);
+ return(NULL);
+ }
+
+ ndpi_tsearch(newflow, (void*)&ndpi_flows_root[idx], node_cmp); /* Add */
+
+ ndpi_flow_count += 1;
+
+ //printFlow(newflow);
+
+ *src = newflow->src_id, *dst = newflow->dst_id;
+ return(newflow);
+ }
+ } else {
+ struct ndpi_flow *flow = *(struct ndpi_flow**)ret;
+
+ if(flow->lower_ip == lower_ip && flow->upper_ip == upper_ip
+ && flow->lower_port == lower_port && flow->upper_port == upper_port)
+ *src = flow->src_id, *dst = flow->dst_id;
+ else
+ *src = flow->dst_id, *dst = flow->src_id;
+
+ return flow;
+ }
+}
+
+static struct ndpi_flow *get_ndpi_flow6(const struct ndpi_ip6_hdr *iph6,
+ u_int16_t ip_offset,
+ struct ndpi_id_struct **src,
+ struct ndpi_id_struct **dst,
+ u_int8_t *proto)
+{
+ struct ndpi_iphdr iph;
+
+ memset(&iph, 0, sizeof(iph));
+ iph.version = 4;
+ iph.saddr = iph6->ip6_src.__u6_addr.__u6_addr32[2] + iph6->ip6_src.__u6_addr.__u6_addr32[3];
+ iph.daddr = iph6->ip6_dst.__u6_addr.__u6_addr32[2] + iph6->ip6_dst.__u6_addr.__u6_addr32[3];
+ iph.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
+ return(get_ndpi_flow(6, &iph, ip_offset,
+ sizeof(struct ndpi_ip6_hdr),
+ ntohs(iph6->ip6_ctlun.ip6_un1.ip6_un1_plen),
+ src, dst, proto));
+}
+
+static void setupDetection(void)
+{
+ NDPI_PROTOCOL_BITMASK all;
+
+ // init global detection structure
+ ndpi_struct = ndpi_init_detection_module(detection_tick_resolution, malloc_wrapper, free_wrapper, debug_printf);
+ if(ndpi_struct == NULL) {
+ printf("ERROR: global structure initialization failed\n");
+ exit(-1);
+ }
+ // enable all protocols
+ NDPI_BITMASK_SET_ALL(all);
+ ndpi_set_protocol_detection_bitmask2(ndpi_struct, &all);
+
+ // allocate memory for id and flow tracking
+ size_id_struct = ndpi_detection_get_sizeof_ndpi_id_struct();
+ size_flow_struct = ndpi_detection_get_sizeof_ndpi_flow_struct();
+
+ // clear memory for results
+ memset(protocol_counter, 0, sizeof(protocol_counter));
+ memset(protocol_counter_bytes, 0, sizeof(protocol_counter_bytes));
+ memset(protocol_flows, 0, sizeof(protocol_flows));
+
+ if(_protoFilePath != NULL)
+ ndpi_load_protocols_file(ndpi_struct, _protoFilePath);
+
+ raw_packet_count = ip_packet_count = total_bytes = 0;
+ ndpi_flow_count = 0;
+}
+
+static void free_ndpi_flow(struct ndpi_flow *flow) {
+ if(flow->ndpi_flow) { ndpi_free(flow->ndpi_flow); flow->ndpi_flow = NULL; }
+ if(flow->src_id) { ndpi_free(flow->src_id); flow->src_id = NULL; }
+ if(flow->dst_id) { ndpi_free(flow->dst_id); flow->dst_id = NULL; }
+}
+
+static void ndpi_flow_freer(void *node) {
+ struct ndpi_flow *flow = (struct ndpi_flow*)node;
+ free_ndpi_flow(flow);
+ ndpi_free(flow);
+}
+
+
+static void terminateDetection(void)
+{
+ int i;
+
+ for(i=0; i<NUM_ROOTS; i++) {
+ ndpi_tdestroy(ndpi_flows_root[i], ndpi_flow_freer);
+ ndpi_flows_root[i] = NULL;
+ }
+
+ ndpi_exit_detection_module(ndpi_struct, free_wrapper);
+}
+
+static unsigned int packet_processing(const u_int64_t time,
+ const struct ndpi_iphdr *iph,
+ struct ndpi_ip6_hdr *iph6,
+ u_int16_t ip_offset,
+ u_int16_t ipsize, u_int16_t rawsize)
+{
+ struct ndpi_id_struct *src, *dst;
+ struct ndpi_flow *flow;
+ struct ndpi_flow_struct *ndpi_flow = NULL;
+ u_int32_t protocol = 0;
+ u_int8_t proto;
+
+ if(iph)
+ flow = get_ndpi_flow(4, iph, ip_offset, ipsize,
+ ntohs(iph->tot_len) - (iph->ihl * 4),
+ &src, &dst, &proto);
+ else
+ flow = get_ndpi_flow6(iph6, ip_offset, &src, &dst, &proto);
+
+ if(flow != NULL) {
+ ndpi_flow = flow->ndpi_flow;
+ flow->packets++, flow->bytes += rawsize;
+ } else
+ return(0);
+
+ ip_packet_count++;
+ total_bytes += rawsize + 24 /* CRC etc */;
+
+ if(flow->detection_completed) return(0);
+
+ protocol = (const u_int32_t)ndpi_detection_process_packet(ndpi_struct, ndpi_flow,
+ iph ? (uint8_t *)iph : (uint8_t *)iph6,
+ ipsize, time, src, dst);
+
+ flow->detected_protocol = protocol;
+
+ if((flow->detected_protocol != NDPI_PROTOCOL_UNKNOWN)
+ || (proto == IPPROTO_UDP)
+ || ((proto == IPPROTO_TCP) && (flow->packets > 10))) {
+ flow->detection_completed = 1;
+
+#if 0
+ if(flow->ndpi_flow->l4.tcp.host_server_name[0] != '\0')
+ printf("%s\n", flow->ndpi_flow->l4.tcp.host_server_name);
+#endif
+
+ if(verbose > 1) {
+ char buf1[32], buf2[32];
+
+ printf("%s %s:%u > %s:%u [proto: %u/%s][%s]\n",
+ ipProto2Name(flow->protocol),
+ intoaV4(ntohl(flow->lower_ip), buf1, sizeof(buf1)), ntohs(flow->lower_port),
+ intoaV4(ntohl(flow->upper_ip), buf2, sizeof(buf2)), ntohs(flow->upper_port),
+ protocol, ndpi_get_proto_name(ndpi_struct, protocol),
+ flow->ndpi_flow->host_server_name);
+ }
+
+ snprintf(flow->host_server_name, sizeof(flow->host_server_name), "%s", flow->ndpi_flow->host_server_name);
+ free_ndpi_flow(flow);
+ }
+
+#if 0
+ if(ndpi_flow->l4.tcp.host_server_name[0] != '\0')
+ printf("%s\n", ndpi_flow->l4.tcp.host_server_name);
+#endif
+
+ return 0;
+}
+
+/* ****************************************************** */
+
+
+char* formatTraffic(float numBits, int bits, char *buf) {
+ char unit;
+
+ if(bits)
+ unit = 'b';
+ else
+ unit = 'B';
+
+ if(numBits < 1024) {
+ snprintf(buf, 32, "%lu %c", (unsigned long)numBits, unit);
+ } else if(numBits < 1048576) {
+ snprintf(buf, 32, "%.2f K%c", (float)(numBits)/1024, unit);
+ } else {
+ float tmpMBits = ((float)numBits)/1048576;
+
+ if(tmpMBits < 1024) {
+ snprintf(buf, 32, "%.2f M%c", tmpMBits, unit);
+ } else {
+ tmpMBits /= 1024;
+
+ if(tmpMBits < 1024) {
+ snprintf(buf, 32, "%.2f G%c", tmpMBits, unit);
+ } else {
+ snprintf(buf, 32, "%.2f T%c", (float)(tmpMBits)/1024, unit);
+ }
+ }
+ }
+
+ return(buf);
+}
+
+char* formatPackets(float numPkts, char *buf) {
+ if(numPkts < 1000) {
+ snprintf(buf, 32, "%.2f", numPkts);
+ } else if(numPkts < 1000000) {
+ snprintf(buf, 32, "%.2f K", numPkts/1000);
+ } else {
+ numPkts /= 1000000;
+ snprintf(buf, 32, "%.2f M", numPkts);
+ }
+
+ return(buf);
+}
+
+static void printResults(u_int64_t tot_usec)
+{
+ u_int32_t i;
+
+ printf("\x1b[2K\n");
+ printf("pcap file contains\n");
+ printf("\tIP packets: \x1b[33m%-13llu\x1b[0m of %llu packets total\n",
+ (long long unsigned int)ip_packet_count,
+ (long long unsigned int)raw_packet_count);
+ printf("\tIP bytes: \x1b[34m%-13llu\x1b[0m\n",
+ (long long unsigned int)total_bytes);
+ printf("\tUnique flows: \x1b[36m%-13u\x1b[0m\n", ndpi_flow_count);
+
+ if(tot_usec > 0) {
+ char buf[32], buf1[32];
+ float t = (float)(ip_packet_count*1000000)/(float)tot_usec;
+ float b = (float)(total_bytes * 8 *1000000)/(float)tot_usec;
+
+ printf("\tnDPI throughout: \x1b[36m%s pps / %s/sec\x1b[0m\n", formatPackets(t, buf), formatTraffic(b, 1, buf1));
+ }
+
+ for(i=0; i<NUM_ROOTS; i++)
+ ndpi_twalk(ndpi_flows_root[i], node_proto_guess_walker, NULL);
+
+ if(enable_protocol_guess)
+ printf("\tGuessed flow protocols: \x1b[35m%-13u\x1b[0m\n", guessed_flow_protocols);
+
+ printf("\n\nDetected protocols:\n");
+ for (i = 0; i <= ndpi_get_num_supported_protocols(ndpi_struct); i++) {
+ if(protocol_counter[i] > 0) {
+ printf("\t\x1b[31m%-20s\x1b[0m packets: \x1b[33m%-13llu\x1b[0m bytes: \x1b[34m%-13llu\x1b[0m "
+ "flows: \x1b[36m%-13u\x1b[0m\n",
+ ndpi_get_proto_name(ndpi_struct, i), (long long unsigned int)protocol_counter[i],
+ (long long unsigned int)protocol_counter_bytes[i], protocol_flows[i]);
+ }
+ }
+
+ if(verbose && (protocol_counter[0] > 0)) {
+ printf("\n");
+
+ for(i=0; i<NUM_ROOTS; i++)
+ ndpi_twalk(ndpi_flows_root[i], node_print_known_proto_walker, NULL);
+
+ printf("\n\nUndetected flows:\n");
+ for(i=0; i<NUM_ROOTS; i++)
+ ndpi_twalk(ndpi_flows_root[i], node_print_unknown_proto_walker, NULL);
+ }
+
+ printf("\n\n");
+}
+
+static void closePcapFile(void)
+{
+ if(_pcap_handle != NULL) {
+ pcap_close(_pcap_handle);
+ }
+}
+
+// executed for each packet in the pcap file
+void sigproc(int sig) {
+ static int called = 0;
+
+ if(called) return; else called = 1;
+ shutdown_app = 1;
+
+ closePcapFile();
+ printResults(0);
+ terminateDetection();
+ exit(0);
+}
+
+static void openPcapFileOrDevice(void)
+{
+ u_int snaplen = 1514;
+ int promisc = 1;
+ char errbuf[PCAP_ERRBUF_SIZE];
+
+ if((_pcap_handle = pcap_open_live(_pcap_file, snaplen, promisc, 500, errbuf)) == NULL) {
+ _pcap_handle = pcap_open_offline(_pcap_file, _pcap_error_buffer);
+ capture_until = 0;
+
+ if(_pcap_handle == NULL) {
+ printf("ERROR: could not open pcap file: %s\n", _pcap_error_buffer);
+ exit(-1);
+ } else
+ printf("Reading packets from pcap file %s...\n", _pcap_file);
+ } else
+ printf("Capturing live traffic from device %s...\n", _pcap_file);
+
+ _pcap_datalink_type = pcap_datalink(_pcap_handle);
+
+ if(_bpf_filter != NULL) {
+ struct bpf_program fcode;
+
+ if(pcap_compile(_pcap_handle, &fcode, _bpf_filter, 1, 0xFFFFFF00) < 0) {
+ printf("pcap_compile error: '%s'\n", pcap_geterr(_pcap_handle));
+ } else {
+ if(pcap_setfilter(_pcap_handle, &fcode) < 0) {
+ printf("pcap_setfilter error: '%s'\n", pcap_geterr(_pcap_handle));
+ } else
+ printf("Succesfully set BPF filter to '%s'\n", _bpf_filter);
+ }
+ }
+
+ if(capture_until > 0) {
+ printf("Capturing traffic up to %u seconds\n", (unsigned int)capture_until);
+
+#ifndef WIN32
+ alarm(capture_until);
+ signal(SIGALRM, sigproc);
+#endif
+ capture_until += time(NULL);
+ }
+}
+
+static void pcap_packet_callback(u_char * args, const struct pcap_pkthdr *header, const u_char * packet)
+{
+ const struct ndpi_ethhdr *ethernet;
+ struct ndpi_iphdr *iph;
+ struct ndpi_ip6_hdr *iph6;
+ u_int64_t time;
+ static u_int64_t lasttime = 0;
+ u_int16_t type, ip_offset, ip_len;
+ u_int16_t frag_off = 0;
+ u_int8_t proto = 0;
+
+ raw_packet_count++;
+
+ if((capture_until != 0) && (header->ts.tv_sec >= capture_until)) {
+ if(_pcap_handle != NULL)
+ pcap_breakloop(_pcap_handle);
+
+ return;
+ }
+
+ time = ((uint64_t) header->ts.tv_sec) * detection_tick_resolution +
+ header->ts.tv_usec / (1000000 / detection_tick_resolution);
+ if(lasttime > time) {
+ // printf("\nWARNING: timestamp bug in the pcap file (ts delta: %llu, repairing)\n", lasttime - time);
+ time = lasttime;
+ }
+ lasttime = time;
+
+ if(_pcap_datalink_type == DLT_EN10MB) {
+ ethernet = (struct ndpi_ethhdr *) packet;
+ ip_offset = sizeof(struct ndpi_ethhdr);
+ type = ntohs(ethernet->h_proto);
+ } else if(_pcap_datalink_type == 113 /* Linux Cooked Capture */) {
+ type = (packet[14] << 8) + packet[15];
+ ip_offset = 16;
+ } else
+ return;
+
+ if(type == 0x8100 /* VLAN */) {
+ type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
+ ip_offset += 4;
+ }
+
+ iph = (struct ndpi_iphdr *) &packet[ip_offset];
+
+ // just work on Ethernet packets that contain IP
+ if(type == ETH_P_IP && header->caplen >= ip_offset) {
+ frag_off = ntohs(iph->frag_off);
+
+ proto = iph->protocol;
+ if(header->caplen < header->len) {
+ static u_int8_t cap_warning_used = 0;
+ if(cap_warning_used == 0) {
+ printf("\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
+ cap_warning_used = 1;
+ }
+ }
+ }
+
+ if(iph->version == 4) {
+ ip_len = ((u_short)iph->ihl * 4);
+ iph6 = NULL;
+
+ if((frag_off & 0x3FFF) != 0) {
+ static u_int8_t ipv4_frags_warning_used = 0;
+
+ v4_frags_warning:
+ if(ipv4_frags_warning_used == 0) {
+ printf("\n\nWARNING: IPv4 fragments are not handled by this demo (nDPI supports them)\n");
+ ipv4_frags_warning_used = 1;
+ }
+
+ return;
+ }
+
+ } else if(iph->version == 6) {
+ iph6 = (struct ndpi_ip6_hdr *)&packet[ip_offset];
+ proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
+ ip_len = sizeof(struct ndpi_ip6_hdr);
+ iph = NULL;
+ } else {
+ static u_int8_t ipv4_warning_used = 0;
+
+ v4_warning:
+ if(ipv4_warning_used == 0) {
+ printf("\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
+ ipv4_warning_used = 1;
+ }
+
+ return;
+ }
+
+ if(decode_tunnels && (proto == IPPROTO_UDP)) {
+ struct ndpi_udphdr *udp = (struct ndpi_udphdr *)&packet[ip_offset+ip_len];
+ u_int16_t sport = ntohs(udp->source), dport = ntohs(udp->dest);
+
+ if((sport == GTP_U_V1_PORT) || (dport == GTP_U_V1_PORT)) {
+ /* Check if it's GTPv1 */
+ u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
+ u_int8_t flags = packet[offset];
+ u_int8_t message_type = packet[offset+1];
+
+ if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) && (message_type == 0xFF /* T-PDU */)) {
+ ip_offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr)+8 /* GTPv1 header len */;
+
+ if(flags & 0x04) ip_offset += 1; /* next_ext_header is present */
+ if(flags & 0x02) ip_offset += 4; /* sequence_number is present (it also includes next_ext_header and pdu_number) */
+ if(flags & 0x01) ip_offset += 1; /* pdu_number is present */
+
+ iph = (struct ndpi_iphdr *) &packet[ip_offset];
+
+ if(iph->version != 4) {
+ // printf("WARNING: not good (packet_id=%u)!\n", (unsigned int)raw_packet_count);
+ goto v4_warning;
+ }
+ }
+ }
+ }
+
+ // process the packet
+ packet_processing(time, iph, iph6, ip_offset, header->len - ip_offset, header->len);
+}
+
+static void runPcapLoop(void)
+{
+
+
+ if((!shutdown_app) && (_pcap_handle != NULL))
+ pcap_loop(_pcap_handle, -1, &pcap_packet_callback, NULL);
+}
+
+void test_lib() {
+ struct timeval begin, end;
+ u_int64_t tot_usec;
+
+ setupDetection();
+ openPcapFileOrDevice();
+ signal(SIGINT, sigproc);
+
+ gettimeofday(&begin, NULL);
+ runPcapLoop();
+ gettimeofday(&end, NULL);
+
+ tot_usec = end.tv_sec*1000000 + end.tv_usec - (begin.tv_sec*1000000 + begin.tv_usec);
+ closePcapFile();
+ printResults(tot_usec);
+ terminateDetection();
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ parseOptions(argc, argv);
+
+ printf("\n-----------------------------------------------------------\n"
+ "* NOTE: This is demo app to show *some* nDPI features.\n"
+ "* In this demo we have implemented only some basic features\n"
+ "* just to show you what you can do with the library. Feel \n"
+ "* free to extend it and send us the patches for inclusion\n"
+ "------------------------------------------------------------\n\n");
+
+ printf("Using nDPI %s (%s)\n", PACKAGE_VERSION, ndpi_revision());
+
+ for(i=0; i<num_loops; i++)
+ test_lib();
+
+ return 0;
+}
+
/* ****************************************************** */
@@ -920,7 +977,7 @@
__int64 t;
static int tzflag;
- if (tv)
+ if(tv)
{
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
@@ -932,17 +989,16 @@
tv->tv_usec = (long)(t % 1000000);
}
- if (tz)
- {
- if (!tzflag)
- {
- _tzset();
- tzflag++;
- }
- tz->tz_minuteswest = _timezone / 60;
- tz->tz_dsttime = _daylight;
+ if(tz) {
+ if(!tzflag) {
+ _tzset();
+ tzflag++;
}
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
return 0;
}
#endif /* WIN32 */
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/install-sh
^
|
@@ -1,7 +1,7 @@
#!/bin/sh
# install - install a program, script, or datafile
-scriptversion=2011-11-20.07; # UTC
+scriptversion=2011-01-19.21; # UTC
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
@@ -35,7 +35,7 @@
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
-# 'make' implicit rules from creating a file called install from it
+# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
@@ -156,7 +156,7 @@
-s) stripcmd=$stripprog;;
-t) dst_arg=$2
- # Protect names problematic for 'test' and other utilities.
+ # Protect names problematic for `test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
@@ -190,7 +190,7 @@
fi
shift # arg
dst_arg=$arg
- # Protect names problematic for 'test' and other utilities.
+ # Protect names problematic for `test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
@@ -202,7 +202,7 @@
echo "$0: no input file specified." >&2
exit 1
fi
- # It's OK to call 'install-sh -d' without argument.
+ # It's OK to call `install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
@@ -240,7 +240,7 @@
for src
do
- # Protect names problematic for 'test' and other utilities.
+ # Protect names problematic for `test' and other utilities.
case $src in
-* | [=\(\)!]) src=./$src;;
esac
@@ -354,7 +354,7 @@
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
- # other-writable bit of parent directory when it shouldn't.
+ # other-writeable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
ls_ld_tmpdir=`ls -ld "$tmpdir"`
case $ls_ld_tmpdir in
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/ltmain.sh
^
|
@@ -70,7 +70,7 @@
# compiler: $LTCC
# compiler flags: $LTCFLAGS
# linker: $LD (gnu? $with_gnu_ld)
-# $progname: (GNU libtool) 2.4.2
+# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1.2ubuntu1
# automake: $automake_version
# autoconf: $autoconf_version
#
@@ -80,7 +80,7 @@
PROGRAM=libtool
PACKAGE=libtool
-VERSION=2.4.2
+VERSION="2.4.2 Debian-2.4.2-1.2ubuntu1"
TIMESTAMP=""
package_revision=1.3337
@@ -5851,10 +5851,9 @@
# -tp=* Portland pgcc target processor selection
# --sysroot=* for sysroot support
# -O*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
- # -stdlib=* select c++ std lib with clang
-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
- -O*|-flto*|-fwhopr*|-fuse-linker-plugin|-stdlib=*)
+ -O*|-flto*|-fwhopr*|-fuse-linker-plugin)
func_quote_for_eval "$arg"
arg="$func_quote_for_eval_result"
func_append compile_command " $arg"
@@ -6125,7 +6124,10 @@
case $pass in
dlopen) libs="$dlfiles" ;;
dlpreopen) libs="$dlprefiles" ;;
- link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
+ link)
+ libs="$deplibs %DEPLIBS%"
+ test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
+ ;;
esac
fi
if test "$linkmode,$pass" = "lib,dlpreopen"; then
@@ -6445,19 +6447,19 @@
# It is a libtool convenience library, so add in its objects.
func_append convenience " $ladir/$objdir/$old_library"
func_append old_convenience " $ladir/$objdir/$old_library"
+ tmp_libs=
+ for deplib in $dependency_libs; do
+ deplibs="$deplib $deplibs"
+ if $opt_preserve_dup_deps ; then
+ case "$tmp_libs " in
+ *" $deplib "*) func_append specialdeplibs " $deplib" ;;
+ esac
+ fi
+ func_append tmp_libs " $deplib"
+ done
elif test "$linkmode" != prog && test "$linkmode" != lib; then
func_fatal_error "\`$lib' is not a convenience library"
fi
- tmp_libs=
- for deplib in $dependency_libs; do
- deplibs="$deplib $deplibs"
- if $opt_preserve_dup_deps ; then
- case "$tmp_libs " in
- *" $deplib "*) func_append specialdeplibs " $deplib" ;;
- esac
- fi
- func_append tmp_libs " $deplib"
- done
continue
fi # $pass = conv
@@ -7350,6 +7352,9 @@
revision="$number_minor"
lt_irix_increment=no
;;
+ *)
+ func_fatal_configuration "$modename: unknown library version type \`$version_type'"
+ ;;
esac
;;
no)
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/m4/libtool.m4
^
|
@@ -1324,7 +1324,14 @@
LD="${LD-ld} -m elf_i386_fbsd"
;;
x86_64-*linux*)
- LD="${LD-ld} -m elf_i386"
+ case `/usr/bin/file conftest.o` in
+ *x86-64*)
+ LD="${LD-ld} -m elf32_x86_64"
+ ;;
+ *)
+ LD="${LD-ld} -m elf_i386"
+ ;;
+ esac
;;
ppc64-*linux*|powerpc64-*linux*)
LD="${LD-ld} -m elf32ppclinux"
@@ -1688,7 +1695,8 @@
;;
*)
lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
- if test -n "$lt_cv_sys_max_cmd_len"; then
+ if test -n "$lt_cv_sys_max_cmd_len" && \
+ test undefined != "$lt_cv_sys_max_cmd_len"; then
lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
else
@@ -2512,17 +2520,6 @@
esac
;;
-gnu*)
- version_type=linux # correct to gnu/linux during the next big refactor
- need_lib_prefix=no
- need_version=no
- library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
- soname_spec='${libname}${release}${shared_ext}$major'
- shlibpath_var=LD_LIBRARY_PATH
- shlibpath_overrides_runpath=no
- hardcode_into_libs=yes
- ;;
-
haiku*)
version_type=linux # correct to gnu/linux during the next big refactor
need_lib_prefix=no
@@ -2639,7 +2636,7 @@
;;
# This must be glibc/ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
version_type=linux # correct to gnu/linux during the next big refactor
need_lib_prefix=no
need_version=no
@@ -2684,6 +2681,18 @@
dynamic_linker='GNU/Linux ld.so'
;;
+netbsdelf*-gnu)
+ version_type=linux
+ need_lib_prefix=no
+ need_version=no
+ library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+ soname_spec='${libname}${release}${shared_ext}$major'
+ shlibpath_var=LD_LIBRARY_PATH
+ shlibpath_overrides_runpath=no
+ hardcode_into_libs=yes
+ dynamic_linker='NetBSD ld.elf_so'
+ ;;
+
netbsd*)
version_type=sunos
need_lib_prefix=no
@@ -3243,10 +3252,6 @@
fi
;;
-gnu*)
- lt_cv_deplibs_check_method=pass_all
- ;;
-
haiku*)
lt_cv_deplibs_check_method=pass_all
;;
@@ -3285,11 +3290,11 @@
;;
# This must be glibc/ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
lt_cv_deplibs_check_method=pass_all
;;
-netbsd*)
+netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
else
@@ -4037,7 +4042,7 @@
;;
esac
;;
- linux* | k*bsd*-gnu | kopensolaris*-gnu)
+ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
case $cc_basename in
KCC*)
# KAI C++ Compiler
@@ -4101,7 +4106,7 @@
;;
esac
;;
- netbsd*)
+ netbsd* | netbsdelf*-gnu)
;;
*qnx* | *nto*)
# QNX uses GNU C++, but need to define -shared option too, otherwise
@@ -4336,7 +4341,7 @@
_LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
;;
- linux* | k*bsd*-gnu | kopensolaris*-gnu)
+ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
case $cc_basename in
# old Intel for x86_64 which still supported -KPIC.
ecc*)
@@ -4578,6 +4583,9 @@
;;
esac
;;
+ linux* | k*bsd*-gnu | gnu*)
+ _LT_TAGVAR(link_all_deplibs, $1)=no
+ ;;
*)
_LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
;;
@@ -4640,6 +4648,9 @@
openbsd*)
with_gnu_ld=no
;;
+ linux* | k*bsd*-gnu | gnu*)
+ _LT_TAGVAR(link_all_deplibs, $1)=no
+ ;;
esac
_LT_TAGVAR(ld_shlibs, $1)=yes
@@ -4861,7 +4872,7 @@
fi
;;
- netbsd*)
+ netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
wlarc=
@@ -5038,6 +5049,7 @@
if test "$aix_use_runtimelinking" = yes; then
shared_flag="$shared_flag "'${wl}-G'
fi
+ _LT_TAGVAR(link_all_deplibs, $1)=no
else
# not using gcc
if test "$host_cpu" = ia64; then
@@ -5342,7 +5354,7 @@
_LT_TAGVAR(link_all_deplibs, $1)=yes
;;
- netbsd*)
+ netbsd* | netbsdelf*-gnu)
if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out
else
@@ -6222,9 +6234,6 @@
_LT_TAGVAR(ld_shlibs, $1)=yes
;;
- gnu*)
- ;;
-
haiku*)
_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
_LT_TAGVAR(link_all_deplibs, $1)=yes
@@ -6386,7 +6395,7 @@
_LT_TAGVAR(inherit_rpath, $1)=yes
;;
- linux* | k*bsd*-gnu | kopensolaris*-gnu)
+ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
case $cc_basename in
KCC*)
# Kuck and Associates, Inc. (KAI) C++ Compiler
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/missing
^
|
@@ -1,9 +1,10 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
-scriptversion=2012-01-06.18; # UTC
+scriptversion=2012-01-06.13; # UTC
-# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# This program is free software; you can redistribute it and/or modify
@@ -25,7 +26,7 @@
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
- echo 1>&2 "Try '$0 --help' for more information"
+ echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
@@ -33,7 +34,7 @@
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
-# In the cases where this matters, 'missing' is being run in the
+# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
@@ -64,7 +65,7 @@
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
-Handle 'PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
@@ -73,20 +74,20 @@
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
- aclocal touch file 'aclocal.m4'
- autoconf touch file 'configure'
- autoheader touch file 'config.h.in'
+ aclocal touch file \`aclocal.m4'
+ autoconf touch file \`configure'
+ autoheader touch file \`config.h.in'
autom4te touch the output file, or create a stub one
- automake touch all 'Makefile.in' files
- bison create 'y.tab.[ch]', if possible, from existing .[ch]
- flex create 'lex.yy.c', if possible, from existing .c
+ automake touch all \`Makefile.in' files
+ bison create \`y.tab.[ch]', if possible, from existing .[ch]
+ flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
- lex create 'lex.yy.c', if possible, from existing .c
+ lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
- yacc create 'y.tab.[ch]', if possible, from existing .[ch]
+ yacc create \`y.tab.[ch]', if possible, from existing .[ch]
-Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
-'g' are ignored when checking the name.
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
Send bug reports to <bug-automake@gnu.org>."
exit $?
@@ -98,8 +99,8 @@
;;
-*)
- echo 1>&2 "$0: Unknown '$1' option"
- echo 1>&2 "Try '$0 --help' for more information"
+ echo 1>&2 "$0: Unknown \`$1' option"
+ echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
@@ -126,7 +127,7 @@
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
# Could not run --version or --help. This is probably someone
- # running '$TOOL --version' or '$TOOL --help' to check whether
+ # running `$TOOL --version' or `$TOOL --help' to check whether
# $TOOL exists and not knowing $TOOL uses missing.
exit 1
fi
@@ -138,27 +139,27 @@
case $program in
aclocal*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'acinclude.m4' or '${configure_ac}'. You might want
- to install the Automake and Perl packages. Grab them from
+WARNING: \`$1' is $msg. You should only need it if
+ you modified \`acinclude.m4' or \`${configure_ac}'. You might want
+ to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified '${configure_ac}'. You might want to install the
- Autoconf and GNU m4 packages. Grab them from any GNU
+WARNING: \`$1' is $msg. You should only need it if
+ you modified \`${configure_ac}'. You might want to install the
+ \`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'acconfig.h' or '${configure_ac}'. You might want
- to install the Autoconf and GNU m4 packages. Grab them
+WARNING: \`$1' is $msg. You should only need it if
+ you modified \`acconfig.h' or \`${configure_ac}'. You might want
+ to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
@@ -175,9 +176,9 @@
automake*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified 'Makefile.am', 'acinclude.m4' or '${configure_ac}'.
- You might want to install the Automake and Perl packages.
+WARNING: \`$1' is $msg. You should only need it if
+ you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+ You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
@@ -186,10 +187,10 @@
autom4te*)
echo 1>&2 "\
-WARNING: '$1' is needed, but is $msg.
+WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
- You can get '$1' as part of Autoconf from any GNU
+ You can get \`$1' as part of \`Autoconf' from any GNU
archive site."
file=`echo "$*" | sed -n "$sed_output"`
@@ -209,10 +210,10 @@
bison*|yacc*)
echo 1>&2 "\
-WARNING: '$1' $msg. You should only need it if
- you modified a '.y' file. You may need the Bison package
+WARNING: \`$1' $msg. You should only need it if
+ you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
- Bison from any GNU archive site."
+ \`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if test $# -ne 1; then
eval LASTARG=\${$#}
@@ -239,10 +240,10 @@
lex*|flex*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified a '.l' file. You may need the Flex package
+WARNING: \`$1' is $msg. You should only need it if
+ you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
- Flex from any GNU archive site."
+ \`Flex' from any GNU archive site."
rm -f lex.yy.c
if test $# -ne 1; then
eval LASTARG=\${$#}
@@ -262,10 +263,10 @@
help2man*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
+WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
- Help2man package in order for those modifications to take
- effect. You can get Help2man from any GNU archive site."
+ \`Help2man' package in order for those modifications to take
+ effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
@@ -280,12 +281,12 @@
makeinfo*)
echo 1>&2 "\
-WARNING: '$1' is $msg. You should only need it if
- you modified a '.texi' or '.texinfo' file, or any other file
+WARNING: \`$1' is $msg. You should only need it if
+ you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
- call might also be the consequence of using a buggy 'make' (AIX,
- DU, IRIX). You might want to install the Texinfo package or
- the GNU make package. Grab either from any GNU archive site."
+ call might also be the consequence of using a buggy \`make' (AIX,
+ DU, IRIX). You might want to install the \`Texinfo' package or
+ the \`GNU make' package. Grab either from any GNU archive site."
# The file to touch is that specified with -o ...
file=`echo "$*" | sed -n "$sed_output"`
test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
@@ -309,12 +310,12 @@
*)
echo 1>&2 "\
-WARNING: '$1' is needed, and is $msg.
+WARNING: \`$1' is needed, and is $msg.
You might have modified some files without having the
- proper tools for further handling them. Check the 'README' file,
+ proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
- some other package would contain this missing '$1' program."
+ some other package would contain this missing \`$1' program."
exit 1
;;
esac
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/Makefile.in
^
|
@@ -1,8 +1,9 @@
-# Makefile.in generated by automake 1.12.2 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2012 Free Software Foundation, Inc.
-
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
@@ -61,6 +62,7 @@
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
SOURCES =
@@ -157,6 +159,7 @@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PLATFORM_DEPENDENT = @PLATFORM_DEPENDENT@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -333,20 +336,6 @@
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
-cscopelist: $(HEADERS) $(SOURCES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP)'; \
- case "$(srcdir)" in \
- [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
- *) sdir=$(subdir)/$(srcdir) ;; \
- esac; \
- for i in $$list; do \
- if test -f "$$i"; then \
- echo "$(subdir)/$$i"; \
- else \
- echo "$$sdir/$$i"; \
- fi; \
- done >> $(top_builddir)/cscope.files
-
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -486,7 +475,7 @@
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
- clean-libtool cscopelist ctags distclean distclean-generic \
+ clean-libtool ctags distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/linux_compat.h
^
|
@@ -38,8 +38,10 @@
#endif
#endif
-#pragma pack(push) /* push current alignment to stack */
-#pragma pack(1) /* set alignment to 1 byte boundary */
+#pragma pack(push, 1) /* push current alignment to stack */
+#pragma pack(1) /* set alignment to 1 byte boundary */
+
+#pragma pack(pop) /* restore original alignment from stack */
struct ndpi_ethhdr {
u_char h_dest[6]; /* destination eth addr */
@@ -47,7 +49,10 @@
u_int16_t h_proto; /* packet type ID field */
};
-#pragma pack(pop) /* restore original alignment from stack */
+struct ndpi_80211q {
+ u_int16_t vlanId;
+ u_int16_t protoType;
+};
struct ndpi_iphdr {
#if defined(__LITTLE_ENDIAN__)
|
[-]
[+]
|
Added |
nDPI.tar.bz2/src/include/ndpi_credis.h
^
|
@@ -0,0 +1,485 @@
+/* ndpi_credis.h -- a C client library for Redis, public API.
+ *
+ * Copyright (c) 2009-2010, Jonas Romfelt <jonas at romfelt dot se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Ndpi_Credis 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 __NDPI_NDPI_CREDIS_H
+#define __NDPI_NDPI_CREDIS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * Functions list below is modelled after the Redis Command Reference (except
+ * for the ndpi_credis_connect() and ndpi_credis_close() functions), use this reference
+ * for further descriptions of each command:
+ *
+ * http://code.google.com/p/redis/wiki/CommandReference
+ *
+ * Comments are only available when it is not obvious how Ndpi_Credis implements
+ * the Redis command. In general, functions return 0 on success or a negative
+ * value on error. Refer to NDPI_NDPI_CREDIS_ERR_* codes. The return code -1 is
+ * typically used when for instance a key is not found.
+ *
+ * IMPORTANT! Memory buffers are allocated, used and managed by ndpi_credis
+ * internally. Subsequent calls to ndpi_credis functions _will_ destroy the data
+ * to which returned values reference to. If for instance the returned value
+ * by a call to ndpi_credis_get() is to be used later in the program, a strdup()
+ * is highly recommended. However, each `REDIS' handle has its own state and
+ * manages its own memory buffers independently. That means that one of two
+ * handles can be destroyed while the other keeps its connection and data.
+ *
+ * EXAMPLE
+ *
+ * Connect to a Redis server and set value of key `fruit' to `banana':
+ *
+ * NDPI_REDIS rh = ndpi_credis_connect("localhost", 6789, 2000);
+ * ndpi_credis_set(rh, "fruit", "banana");
+ * ndpi_credis_close(rh);
+ *
+ * TODO
+ *
+ * - Add support for missing Redis commands marked as TODO below
+ * - Currently only support for zero-terminated strings, not for storing
+ * abritary binary data as bulk data. Basically an API issue since it is
+ * partially supported internally.
+ * - Test
+ */
+
+/* handle to a Redis server connection */
+typedef struct _cr_redis* NDPI_REDIS;
+
+#define NDPI_CREDIS_OK 0
+#define NDPI_CREDIS_ERR -90
+#define NDPI_CREDIS_ERR_NOMEM -91
+#define NDPI_CREDIS_ERR_RESOLVE -92
+#define NDPI_CREDIS_ERR_CONNECT -93
+#define NDPI_CREDIS_ERR_SEND -94
+#define NDPI_CREDIS_ERR_RECV -95
+#define NDPI_CREDIS_ERR_TIMEOUT -96
+#define NDPI_CREDIS_ERR_PROTOCOL -97
+
+#define NDPI_CREDIS_TYPE_NONE 1
+#define NDPI_CREDIS_TYPE_STRING 2
+#define NDPI_CREDIS_TYPE_LIST 3
+#define NDPI_CREDIS_TYPE_SET 4
+
+#define NDPI_CREDIS_SERVER_MASTER 1
+#define NDPI_CREDIS_SERVER_SLAVE 2
+
+typedef enum _ndpi_cr_aggregate {
+ NDPI_NONE,
+ NDPI_SUM,
+ NDPI_MIN,
+ NDPI_MAX
+} NDPI_REDIS_AGGREGATE;
+
+#define NDPI_CREDIS_VERSION_STRING_SIZE 32
+#define NDPI_CREDIS_MULTIPLEXING_API_SIZE 16
+#define NDPI_CREDIS_USED_MEMORY_HUMAN_SIZE 32
+
+typedef struct _ndpi_cr_info {
+ char redis_version[NDPI_CREDIS_VERSION_STRING_SIZE];
+ int arch_bits;
+ char multiplexing_api[NDPI_CREDIS_MULTIPLEXING_API_SIZE];
+ long process_id;
+ long uptime_in_seconds;
+ long uptime_in_days;
+ int connected_clients;
+ int connected_slaves;
+ int blocked_clients;
+ unsigned long used_memory;
+ char used_memory_human[NDPI_CREDIS_USED_MEMORY_HUMAN_SIZE];
+ long long changes_since_last_save;
+ int bgsave_in_progress;
+ long last_save_time;
+ int bgrewriteaof_in_progress;
+ long long total_connections_received;
+ long long total_commands_processed;
+ long long expired_keys;
+ unsigned long hash_max_zipmap_entries;
+ unsigned long hash_max_zipmap_value;
+ long pubsub_channels;
+ unsigned int pubsub_patterns;
+ int vm_enabled;
+ int role;
+} NDPI_REDIS_INFO;
+
+
+/*
+ * Connection handling
+ */
+
+/* `host' is the host to connect to, either as an host name or a IP address,
+ * if set to NULL connection is made to "localhost". `port' is the TCP port
+ * that Redis is listening to, set to 0 will use default port (6379).
+ * `timeout' is the time in milliseconds to use as timeout, when connecting
+ * to a Redis server and waiting for reply, it can be changed after a
+ * connection has been made using ndpi_credis_settimeout() */
+NDPI_REDIS ndpi_credis_connect(const char *host, int port, int timeout);
+
+/* set Redis server reply `timeout' in millisecs */
+void ndpi_credis_settimeout(NDPI_REDIS rhnd, int timeout);
+
+void ndpi_credis_close(NDPI_REDIS rhnd);
+
+void ndpi_credis_quit(NDPI_REDIS rhnd);
+
+int ndpi_credis_auth(NDPI_REDIS rhnd, const char *password);
+
+int ndpi_credis_ping(NDPI_REDIS rhnd);
+
+/* if a function call returns error it is _possible_ that the Redis server
+ * replied with an error message. It is returned by this function. */
+char* ndpi_credis_errorreply(NDPI_REDIS rhnd);
+
+/*
+ * Commands operating on all the kind of values
+ */
+
+/* returns -1 if the key doesn't exists and 0 if it does */
+int ndpi_credis_exists(NDPI_REDIS rhnd, const char *key);
+
+/* returns -1 if the key doesn't exists and 0 if it was removed
+ * TODO add support to (Redis >= 1.1) remove multiple keys
+ */
+int ndpi_credis_del(NDPI_REDIS rhnd, const char *key);
+
+/* returns type, refer to NDPI_CREDIS_TYPE_* defines */
+int ndpi_credis_type(NDPI_REDIS rhnd, const char *key);
+
+/* returns number of keys returned in vector `keyv' */
+int ndpi_credis_keys(NDPI_REDIS rhnd, const char *pattern, char ***keyv);
+
+int ndpi_credis_randomkey(NDPI_REDIS rhnd, char **key);
+
+int ndpi_credis_rename(NDPI_REDIS rhnd, const char *key, const char *new_key_name);
+
+/* returns -1 if the key already exists */
+int ndpi_credis_renamenx(NDPI_REDIS rhnd, const char *key, const char *new_key_name);
+
+/* returns size of db */
+int ndpi_credis_dbsize(NDPI_REDIS rhnd);
+
+/* returns -1 if the timeout was not set; either due to key already has
+ an associated timeout or key does not exist */
+int ndpi_credis_expire(NDPI_REDIS rhnd, const char *key, int secs);
+
+/* returns time to live seconds or -1 if key does not exists or does not
+ * have expire set */
+int ndpi_credis_ttl(NDPI_REDIS rhnd, const char *key);
+
+int ndpi_credis_select(NDPI_REDIS rhnd, int index);
+
+/* returns -1 if the key was not moved; already present at target
+ * or not found on current db */
+int ndpi_credis_move(NDPI_REDIS rhnd, const char *key, int index);
+
+int ndpi_credis_flushdb(NDPI_REDIS rhnd);
+
+int ndpi_credis_flushall(NDPI_REDIS rhnd);
+
+
+/*
+ * Commands operating on string values
+ */
+
+int ndpi_credis_set(NDPI_REDIS rhnd, const char *key, const char *val);
+
+/* returns -1 if the key doesn't exists */
+int ndpi_credis_get(NDPI_REDIS rhnd, const char *key, char **val);
+
+/* returns -1 if the key doesn't exists */
+int ndpi_credis_getset(NDPI_REDIS rhnd, const char *key, const char *set_val, char **get_val);
+
+/* returns number of values returned in vector `valv'. `keyc' is the number of
+ * keys stored in `keyv'. */
+int ndpi_credis_mget(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***valv);
+
+/* returns -1 if the key already exists and hence not set */
+int ndpi_credis_setnx(NDPI_REDIS rhnd, const char *key, const char *val);
+
+/* TODO
+ * SETEX key time value Set+Expire combo command
+ * MSET key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation
+ * MSETNX key1 value1 key2 value2 ... keyN valueN set a multiple keys to multiple values in a single atomic operation if none of
+ */
+
+/* if `new_val' is not NULL it will return the value after the increment was performed */
+int ndpi_credis_incr(NDPI_REDIS rhnd, const char *key, int *new_val);
+
+/* if `new_val' is not NULL it will return the value after the increment was performed */
+int ndpi_credis_incrby(NDPI_REDIS rhnd, const char *key, int incr_val, int *new_val);
+
+/* if `new_val' is not NULL it will return the value after the decrement was performed */
+int ndpi_credis_decr(NDPI_REDIS rhnd, const char *key, int *new_val);
+
+/* if `new_val' is not NULL it will return the value after the decrement was performed */
+int ndpi_credis_decrby(NDPI_REDIS rhnd, const char *key, int decr_val, int *new_val);
+
+/* returns new length of string after `val' has been appended */
+int ndpi_credis_append(NDPI_REDIS rhnd, const char *key, const char *val);
+
+int ndpi_credis_substr(NDPI_REDIS rhnd, const char *key, int start, int end, char **substr);
+
+
+/*
+ * Commands operating on lists
+ */
+
+int ndpi_credis_rpush(NDPI_REDIS rhnd, const char *key, const char *element);
+int ndpi_credis_rpushx(NDPI_REDIS rhnd, const char *key, const char *element); /* ntop */
+
+int ndpi_credis_lpush(NDPI_REDIS rhnd, const char *key, const char *element);
+
+/* returns length of list */
+int ndpi_credis_llen(NDPI_REDIS rhnd, const char *key);
+
+/* returns number of elements returned in vector `elementv' */
+int ndpi_credis_lrange(NDPI_REDIS rhnd, const char *key, int start, int range, char ***elementv);
+
+int ndpi_credis_ltrim(NDPI_REDIS rhnd, const char *key, int start, int end);
+
+/* returns -1 if the key doesn't exists */
+int ndpi_credis_lindex(NDPI_REDIS rhnd, const char *key, int index, char **element);
+
+int ndpi_credis_lset(NDPI_REDIS rhnd, const char *key, int index, const char *element);
+
+/* returns number of elements removed */
+int ndpi_credis_lrem(NDPI_REDIS rhnd, const char *key, int count, const char *element);
+
+/* returns -1 if the key doesn't exists */
+int ndpi_credis_lpop(NDPI_REDIS rhnd, const char *key, char **val);
+
+/* returns -1 if the key doesn't exists */
+int ndpi_credis_rpop(NDPI_REDIS rhnd, const char *key, char **val);
+
+/* TODO
+ * BLPOP key1 key2 ... keyN timeout Blocking LPOP
+ * BRPOP key1 key2 ... keyN timeout Blocking RPOP
+ * RPOPLPUSH srckey dstkey Return and remove (atomically) the last element of the source List stored at _srckey_ and push the same element to the destination List stored at _dstkey_
+ */
+
+
+/*
+ * Commands operating on sets
+ */
+
+/* returns -1 if the given member was already a member of the set */
+int ndpi_credis_sadd(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns -1 if the given member is not a member of the set */
+int ndpi_credis_srem(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns -1 if the given key doesn't exists else value is returned in `member' */
+int ndpi_credis_spop(NDPI_REDIS rhnd, const char *key, char **member);
+
+/* returns -1 if the member doesn't exists in the source set */
+int ndpi_credis_smove(NDPI_REDIS rhnd, const char *sourcekey, const char *destkey,
+ const char *member);
+
+/* returns cardinality (number of members) or 0 if the given key doesn't exists */
+int ndpi_credis_scard(NDPI_REDIS rhnd, const char *key);
+
+/* returns -1 if the key doesn't exists and 0 if it does */
+int ndpi_credis_sismember(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns number of members returned in vector `members'. `keyc' is the number of
+ * keys stored in `keyv'. */
+int ndpi_credis_sinter(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members);
+
+/* `keyc' is the number of keys stored in `keyv' */
+int ndpi_credis_sinterstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv);
+
+/* returns number of members returned in vector `members'. `keyc' is the number of
+ * keys stored in `keyv'. */
+int ndpi_credis_sunion(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members);
+
+/* `keyc' is the number of keys stored in `keyv' */
+int ndpi_credis_sunionstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv);
+
+/* returns number of members returned in vector `members'. `keyc' is the number of
+ * keys stored in `keyv'. */
+int ndpi_credis_sdiff(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members);
+
+/* `keyc' is the number of keys stored in `keyv' */
+int ndpi_credis_sdiffstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv);
+
+/* returns number of members returned in vector `members' */
+int ndpi_credis_smembers(NDPI_REDIS rhnd, const char *key, char ***members);
+
+/* TODO Redis >= 1.1
+ * SRANDMEMBER key Return a random member of the Set value at key
+ */
+
+
+/*
+ * Commands operating on sorted sets
+ */
+
+/* returns -1 if member was already a member of the sorted set and only score was updated,
+ * 0 is returned if the new element was added */
+int ndpi_credis_zadd(NDPI_REDIS rhnd, const char *key, double score, const char *member);
+
+/* returns -1 if the member was not a member of the sorted set */
+int ndpi_credis_zrem(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns -1 if the member was not a member of the sorted set, the score of the member after
+ * the increment by `incr_score' is returned by `new_score' */
+int ndpi_credis_zincrby(NDPI_REDIS rhnd, const char *key, double incr_score, const char *member, double *new_score);
+
+/* returns the rank of the given member or -1 if the member was not a member of the sorted set */
+int ndpi_credis_zrank(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns the reverse rank of the given member or -1 if the member was not a member of the sorted set */
+int ndpi_credis_zrevrank(NDPI_REDIS rhnd, const char *key, const char *member);
+
+/* returns number of elements returned in vector `elementv'
+ * TODO add support for WITHSCORES */
+int ndpi_credis_zrange(NDPI_REDIS rhnd, const char *key, int start, int end, char ***elementv);
+
+/* returns number of elements returned in vector `elementv'
+ * TODO add support for WITHSCORES */
+int ndpi_credis_zrevrange(NDPI_REDIS rhnd, const char *key, int start, int end, char ***elementv);
+
+/* returns cardinality or -1 if `key' does not exist */
+int ndpi_credis_zcard(NDPI_REDIS rhnd, const char *key);
+
+/* returns -1 if the `key' does not exist or the `member' is not in the sorted set,
+ * score is returned in `score' */
+int ndpi_credis_zscore(NDPI_REDIS rhnd, const char *key, const char *member, double *score);
+
+/* returns number of elements removed or -1 if key does not exist */
+int ndpi_credis_zremrangebyscore(NDPI_REDIS rhnd, const char *key, double min, double max);
+
+/* returns number of elements removed or -1 if key does not exist */
+int ndpi_credis_zremrangebyrank(NDPI_REDIS rhnd, const char *key, int start, int end);
+
+/* TODO
+ * ZRANGEBYSCORE key min max Return all the elements with score >= min and score <= max (a range query) from the sorted set
+ */
+
+/* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not
+ * NULL, `keyc' is also the number of weights stored in `weightv'. */
+int ndpi_credis_zinterstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv,
+ const int *weightv, NDPI_REDIS_AGGREGATE aggregate);
+
+/* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not
+ * NULL, `keyc' is also the number of weights stored in `weightv'. */
+int ndpi_credis_zunionstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv,
+ const int *weightv, NDPI_REDIS_AGGREGATE aggregate);
+
+/*
+ * Commands operating on hashes
+ */
+
+/* TODO
+ * HSET key field value Set the hash field to the specified value. Creates the hash if needed.
+ * HGET key field Retrieve the value of the specified hash field.
+ * HMSET key field1 value1 ... fieldN valueN Set the hash fields to their respective values.
+ * HINCRBY key field integer Increment the integer value of the hash at _key_ on _field_ with _integer_.
+ * HEXISTS key field Test for existence of a specified field in a hash
+ * HDEL key field Remove the specified field from a hash
+ * HLEN key Return the number of items in a hash.
+ * HKEYS key Return all the fields in a hash.
+ * HVALS key Return all the values in a hash.
+ * HGETALL key Return all the fields and associated values in a hash.
+ */
+
+
+/*
+ * Sorting
+ */
+
+/* returns number of elements returned in vector `elementv' */
+int ndpi_credis_sort(NDPI_REDIS rhnd, const char *query, char ***elementv);
+
+
+/*
+ * Transactions
+ */
+
+/* TODO
+ * MULTI/EXEC/DISCARD Redis atomic transactions
+ */
+
+
+/*
+ * Publish/Subscribe
+ */
+
+/* TODO
+ * SUBSCRIBE/UNSUBSCRIBE/PUBLISH Redis Public/Subscribe messaging paradigm implementation
+ */
+
+
+/*
+ * Persistence control commands
+ */
+
+int ndpi_credis_save(NDPI_REDIS rhnd);
+
+int ndpi_credis_bgsave(NDPI_REDIS rhnd);
+
+/* returns UNIX time stamp of last successfull save to disk */
+int ndpi_credis_lastsave(NDPI_REDIS rhnd);
+
+int ndpi_credis_shutdown(NDPI_REDIS rhnd);
+
+int ndpi_credis_bgrewriteaof(NDPI_REDIS rhnd);
+
+
+/*
+ * Remote server control commands
+ */
+
+/* Because the information returned by the Redis changes with virtually every
+ * major release, ndpi_credis tries to parse for as many fields as it is aware of,
+ * staying backwards (and forwards) compatible with older (and newer) versions
+ * of Redis.
+ * Information fields not supported by the Redis server connected to, are set
+ * to zero. */
+int ndpi_credis_info(NDPI_REDIS rhnd, NDPI_REDIS_INFO *info);
+
+int ndpi_credis_monitor(NDPI_REDIS rhnd);
+
+/* setting host to NULL and/or port to 0 will turn off replication */
+int ndpi_credis_slaveof(NDPI_REDIS rhnd, const char *host, int port);
+
+/* TODO
+ * CONFIG Configure a Redis server at runtime
+ */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NDPI_CREDIS_H */
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_macros.h
^
|
@@ -26,53 +26,49 @@
#ifndef __NDPI_MACROS_H__
#define __NDPI_MACROS_H__
+#define NDPI_NUM_BITS 256
+
+typedef u_int32_t ndpi_ndpi_mask;
+#define NDPI_BITS /* 32 */ (sizeof(ndpi_ndpi_mask) * 8 /* number of bits in a byte */) /* bits per mask */
+#define howmanybits(x, y) (((x)+((y)-1))/(y))
+
+
+#define NDPI_SET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] |= (1 << (((u_int32_t)n) % NDPI_BITS)))
+#define NDPI_CLR(p, n) ((p)->fds_bits[(n)/NDPI_BITS] &= ~(1 << (((u_int32_t)n) % NDPI_BITS)))
+#define NDPI_ISSET(p, n) ((p)->fds_bits[(n)/NDPI_BITS] & (1 << (((u_int32_t)n) % NDPI_BITS)))
+#define NDPI_ZERO(p) memset((char *)(p), 0, sizeof(*(p)))
+#define NDPI_ONE(p) memset((char *)(p), 0xFF, sizeof(*(p)))
+
+#define NDPI_NUM_FDS_BITS howmanybits(NDPI_NUM_BITS, NDPI_BITS)
+
#ifdef __cplusplus
extern "C" {
#endif
- typedef struct ndpi_protocol_bitmask_struct {
- u_int64_t bitmask[3];
- } ndpi_protocol_bitmask_struct_t;
-#define NDPI_PROTOCOL_BITMASK struct ndpi_protocol_bitmask_struct
+typedef struct ndpi_protocol_bitmask_struct {
+ ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
+} ndpi_protocol_bitmask_struct_t;
+
+#define NDPI_PROTOCOL_BITMASK ndpi_protocol_bitmask_struct_t
-#define NDPI_SAVE_AS_BITMASK(bmask,value) \
- { \
- (bmask).bitmask[0] = 0; \
- (bmask).bitmask[1] = 0; \
- (bmask).bitmask[2] = 0; \
- (bmask).bitmask[(value) >> 6] = (((u_int64_t)1)<<((value) & 0x3F)); \
-}
-
-#define NDPI_BITMASK_COMPARE(a,b) (((a).bitmask[0]) & ((b).bitmask[0]) || ((a).bitmask[1]) & ((b).bitmask[1]) || ((a).bitmask[2]) & ((b).bitmask[2]))
-
-#define NDPI_BITMASK_MATCH(a,b) (((a).bitmask[0]) == ((b).bitmask[0]) && ((a).bitmask[1]) == ((b).bitmask[1]) && ((a).bitmask[2]) == ((b).bitmask[2]))
-
-// all protocols in b are also in a
-#define NDPI_BITMASK_CONTAINS_BITMASK(a,b) ((((a).bitmask[0] & (b).bitmask[0]) == (b).bitmask[0]) && (((a).bitmask[1] & (b).bitmask[1]) == (b).bitmask[1]) && (((a).bitmask[2] & (b).bitmask[2]) == (b).bitmask[2]))
-
-#define NDPI_BITMASK_ADD(a,b) {(a).bitmask[0] |= (b).bitmask[0]; (a).bitmask[1] |= (b).bitmask[1]; (a).bitmask[2] |= (b).bitmask[2];}
-#define NDPI_BITMASK_AND(a,b) {(a).bitmask[0] &= (b).bitmask[0]; (a).bitmask[1] &= (b).bitmask[1]; (a).bitmask[2] &= (b).bitmask[2];}
-#define NDPI_BITMASK_DEL(a,b) {(a).bitmask[0] = (a).bitmask[0] & (~((b).bitmask[0])); (a).bitmask[1] = (a).bitmask[1] & ( ~((b).bitmask[1])); (a).bitmask[0] = (a).bitmask[0] & (~((b).bitmask[0]));}
-#define NDPI_BITMASK_SET(a,b) {(a).bitmask[0] = ((b).bitmask[0]); (a).bitmask[1] = (b).bitmask[1]; (a).bitmask[2] = (b).bitmask[2];}
-#define NDPI_BITMASK_RESET(a) {((a).bitmask[0]) = 0; ((a).bitmask[1]) = 0; ((a).bitmask[2]) = 0;}
-#define NDPI_BITMASK_SET_ALL(a) {((a).bitmask[0]) = 0xFFFFFFFFFFFFFFFFULL; ((a).bitmask[1]) = 0xFFFFFFFFFFFFFFFFULL; ((a).bitmask[2]) = 0xFFFFFFFFFFFFFFFFULL;}
+int NDPI_BITMASK_COMPARE(NDPI_PROTOCOL_BITMASK a, NDPI_PROTOCOL_BITMASK b);
+int NDPI_BITMASK_IS_EMPTY(NDPI_PROTOCOL_BITMASK a);
+void NDPI_DUMP_BITMASK(NDPI_PROTOCOL_BITMASK a);
+
+#define NDPI_BITMASK_ADD(a,b) NDPI_SET(&a,b)
+#define NDPI_BITMASK_DEL(a,b) NDPI_CLR(&a,b)
+#define NDPI_BITMASK_RESET(a) NDPI_ZERO(&a)
+#define NDPI_BITMASK_SET_ALL(a) NDPI_ONE(&a)
+#define NDPI_BITMASK_SET(a, b) { memcpy(&a, &b, sizeof(NDPI_PROTOCOL_BITMASK)); }
/* this is a very very tricky macro *g*,
* the compiler will remove all shifts here if the protocol is static...
*/
-#define NDPI_ADD_PROTOCOL_TO_BITMASK(bmask,value) \
- {(bmask).bitmask[(value) >> 6] |= (((u_int64_t)1)<<((value) & 0x3F));} \
-
-#define NDPI_DEL_PROTOCOL_FROM_BITMASK(bmask,value) \
- {(bmask).bitmask[(value) >> 6] = (bmask).bitmask[(value) >> 6] & (~(((u_int64_t)1)<<((value) & 0x3F)));} \
-
-#define NDPI_COMPARE_PROTOCOL_TO_BITMASK(bmask,value) \
- ((bmask).bitmask[(value) >> 6] & (((u_int64_t)1)<<((value) & 0x3F))) \
+#define NDPI_ADD_PROTOCOL_TO_BITMASK(bmask,value) NDPI_SET(&bmask,value)
+#define NDPI_DEL_PROTOCOL_FROM_BITMASK(bmask,value) NDPI_CLR(&bmask,value)
+#define NDPI_COMPARE_PROTOCOL_TO_BITMASK(bmask,value) NDPI_ISSET(&bmask,value)
+#define NDPI_SAVE_AS_BITMASK(bmask,value) { NDPI_ZERO(&bmask) ; NDPI_ADD_PROTOCOL_TO_BITMASK(bmask, value); }
-#define NDPI_BITMASK_DEBUG_OUTPUT_BITMASK_STRING "%llu , %llu , %llu"
-#define NDPI_BITMASK_DEBUG_OUTPUT_BITMASK_VALUE(bm) (bm).bitmask[0] , (bm).bitmask[1] , (bm).bitmask[2]
-#define NDPI_BITMASK_IS_ZERO(a) ( (a).bitmask[0] == 0 && (a).bitmask[1] == 0 && (a).bitmask[2] == 0)
-#define NDPI_BITMASK_CONTAINS_NEGATED_BITMASK(a,b) ((((a).bitmask[0] & ~(b).bitmask[0]) == ~(b).bitmask[0]) && (((a).bitmask[1] & ~(b).bitmask[1]) == ~(b).bitmask[1]) && (((a).bitmask[2] & ~(b).bitmask[2]) == ~(b).bitmask[2]))
#define ndpi_min(a,b) ((a < b) ? a : b)
#define ndpi_max(a,b) ((a > b) ? a : b)
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_main.h
^
|
@@ -1,170 +1,213 @@
-/*
- * ndpi_main.h
- *
- * Copyright (C) 2009-2011 by ipoque GmbH
- * Copyright (C) 2011-13 - ntop.org
- *
- * This file is part of nDPI, an open source deep packet inspection
- * library based on the OpenDPI and PACE technology by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#ifndef __NDPI_MAIN_INCLUDE_FILE__
-#define __NDPI_MAIN_INCLUDE_FILE__
-
-#ifndef __KERNEL__
-#include <stdint.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#endif
-
-#ifndef WIN32
-#ifndef __KERNEL__
-#include <sys/time.h>
-#endif
-
-#if 1 && !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__
-
-#ifndef __KERNEL__
-#include <endian.h>
-#include <byteswap.h>
-#else
-#include <asm/byteorder.h>
-#include <linux/ctype.h>
-#endif
-
-#endif
-
-/* default includes */
-
-#ifndef __KERNEL__
-#include <sys/param.h>
-#include <limits.h>
-#endif
-
-#endif
-
-#ifdef WIN32
-#include <Winsock2.h> /* winsock.h is included automatically */
-#include <process.h>
-#include <io.h>
-#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
-#include <process.h> /* for getpid() and the exec..() family */
-
-
-#define snprintf _snprintf
-
-#define __attribute__(x)
-typedef char int8_t;
-typedef unsigned char u_int8_t;
-typedef unsigned char u_char;
-typedef __int16 int16_t;
-typedef unsigned __int16 u_int16_t;
-typedef __int32 int32_t;
-typedef unsigned __int32 u_int32_t;
-typedef unsigned __int64 u_int64_t;
-#endif
-
-#include "linux_compat.h"
-
-#if defined(__FreeBSD__) || defined(__NetBSD__)
-#include <netinet/in.h>
-#if defined(__NetBSD__)
-#include <netinet/in_systm.h>
-#endif
-#endif
-
-#ifndef WIN32
-#ifndef __KERNEL__
-
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
-#else
-#include <linux/ip.h>
-#include <linux/tcp.h>
-#include <linux/udp.h>
-#endif
-#endif
-
-#include "ndpi_define.h"
-#include "ndpi_macros.h"
-#include "ndpi_protocols_osdpi.h"
-
-typedef enum {
- ndpi_preorder,
- ndpi_postorder,
- ndpi_endorder,
- ndpi_leaf
-} ndpi_VISIT;
-
-void *ndpi_tdelete(const void * __restrict, void ** __restrict,
- int (*)(const void *, const void *));
-void *ndpi_tfind(const void *, void *, int (*)(const void *, const void *));
-void *ndpi_tsearch(const void *, void**, int (*)(const void *, const void *));
-void ndpi_twalk(const void *, void (*)(const void *, ndpi_VISIT, int, void*), void *user_data);
-void ndpi_tdestroy(void *vrootp, void (*freefct)(void *));
-
-
-typedef struct node_t {
- char *key;
- struct node_t *left, *right;
-} ndpi_node;
-
-
-u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-
-u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-
-#include "ndpi_api.h"
-#include "ndpi_protocol_history.h"
-#include "ndpi_structs.h"
-
-
-/* function to parse a packet which has line based information into a line based structure
- * this function will also set some well known line pointers like:
- * - host, user agent, empty line,....
- */
-extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
-extern void ndpi_parse_packet_line_info_unix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
-extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int16_t counter);
-extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
- struct ndpi_flow_struct *flow,
- u_int16_t detected_protocol, ndpi_protocol_type_t protocol_type);
-extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
- struct ndpi_flow_struct *flow,
- u_int16_t detected_protocol,
- ndpi_protocol_type_t protocol_type);
-extern void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet);
-extern void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow);
-extern void ndpi_ip_clear(ndpi_ip_addr_t * ip);
-extern int ndpi_ip_is_set(const ndpi_ip_addr_t * ip);
-extern int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
-extern int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
-extern void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
-extern void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
-extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const ndpi_ip_addr_t * ip);
-extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
- const struct ndpi_packet_struct *packet);
-extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
-
-#endif /* __NDPI_MAIN_INCLUDE_FILE__ */
+/*
+ * ndpi_main.h
+ *
+ * Copyright (C) 2009-2011 by ipoque GmbH
+ * Copyright (C) 2011-13 - ntop.org
+ *
+ * This file is part of nDPI, an open source deep packet inspection
+ * library based on the OpenDPI and PACE technology by ipoque GmbH
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef __NDPI_MAIN_INCLUDE_FILE__
+#define __NDPI_MAIN_INCLUDE_FILE__
+
+#ifndef __KERNEL__
+#include <stdint.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <pthread.h>
+#include <ctype.h>
+#endif
+
+#ifndef WIN32
+#ifndef __KERNEL__
+#include <sys/time.h>
+#endif
+
+#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__
+
+#ifndef __KERNEL__
+#include <endian.h>
+#include <byteswap.h>
+#else
+#include <asm/byteorder.h>
+#include <linux/ctype.h>
+#endif
+
+#endif
+
+/* default includes */
+
+#ifndef __KERNEL__
+#include <sys/param.h>
+#include <limits.h>
+#endif
+
+#endif
+
+#ifdef WIN32
+#include <Winsock2.h> /* winsock.h is included automatically */
+#include <process.h>
+#include <io.h>
+#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
+#include <process.h> /* for getpid() and the exec..() family */
+
+
+#define snprintf _snprintf
+
+#define __attribute__(x)
+#include <stdint.h>
+#ifndef __GNUC__
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int uint;
+typedef unsigned long u_long;
+#endif
+typedef u_char u_int8_t;
+typedef u_short u_int16_t;
+typedef uint u_int32_t;
+typedef unsigned __int64 u_int64_t;
+#endif /* Win32 */
+
+
+#include "linux_compat.h"
+
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+#include <netinet/in.h>
+#if defined(__NetBSD__)
+#include <netinet/in_systm.h>
+#endif
+#endif
+
+#ifndef WIN32
+#ifndef __KERNEL__
+
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#else
+#include <linux/ip.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
+#endif
+#endif
+
+#include "ndpi_define.h"
+#include "ndpi_macros.h"
+#include "ndpi_protocols_osdpi.h"
+
+typedef enum {
+ ndpi_preorder,
+ ndpi_postorder,
+ ndpi_endorder,
+ ndpi_leaf
+} ndpi_VISIT;
+
+void *ndpi_tdelete(const void * __restrict, void ** __restrict,
+ int (*)(const void *, const void *));
+void *ndpi_tfind(const void *, void *, int (*)(const void *, const void *));
+void *ndpi_tsearch(const void *, void**, int (*)(const void *, const void *));
+void ndpi_twalk(const void *, void (*)(const void *, ndpi_VISIT, int, void*), void *user_data);
+void ndpi_tdestroy(void *vrootp, void (*freefct)(void *));
+
+
+typedef struct node_t {
+ char *key;
+ struct node_t *left, *right;
+} ndpi_node;
+
+/* Least recently used cache */
+
+struct ndpi_LruCacheNumEntry {
+ u_int32_t key;
+ u_int32_t value;
+};
+
+struct ndpi_LruCacheStrEntry {
+ char *key, *value;
+ time_t expire_time;
+};
+
+struct ndpi_LruCacheEntry {
+ u_int8_t numeric_node;
+
+ union {
+ struct ndpi_LruCacheNumEntry num; /* numeric_node == 1 */
+ struct ndpi_LruCacheStrEntry str; /* numeric_node == 0 */
+ } u;
+
+ struct ndpi_LruCacheEntry *next; /* Hash collision list */
+};
+
+struct ndpi_LruCache {
+ u_int32_t max_cache_node_len, hash_size, mem_size;
+ u_int32_t num_cache_add, num_cache_find, num_cache_misses;
+ u_int32_t last_num_cache_add, last_num_cache_find, last_num_cache_misses;
+ u_int32_t *current_hash_size; /* Allocated dynamically */
+ struct ndpi_LruCacheEntry **hash; /* Allocated dynamically */
+};
+
+
+u_int32_t ndpi_find_lru_cache_num(struct ndpi_LruCache *cache, u_int32_t key);
+int ndpi_add_to_lru_cache_num(struct ndpi_LruCache *cache, u_int32_t key, u_int32_t value);
+
+u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+
+u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
+
+#include "ndpi_api.h"
+#include "ndpi_protocol_history.h"
+#include "ndpi_structs.h"
+
+
+/* function to parse a packet which has line based information into a line based structure
+ * this function will also set some well known line pointers like:
+ * - host, user agent, empty line,....
+ */
+extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
+extern void ndpi_parse_packet_line_info_unix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
+extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int16_t counter);
+extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
+ struct ndpi_flow_struct *flow,
+ u_int16_t detected_protocol, ndpi_protocol_type_t protocol_type);
+extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
+ struct ndpi_flow_struct *flow,
+ u_int16_t detected_protocol,
+ ndpi_protocol_type_t protocol_type);
+extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
+ u_int16_t protoId, char *protoName,
+ ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts);
+extern void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet);
+extern void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow);
+extern void ndpi_ip_clear(ndpi_ip_addr_t * ip);
+extern int ndpi_ip_is_set(const ndpi_ip_addr_t * ip);
+extern int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
+extern int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
+extern void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
+extern void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
+extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const ndpi_ip_addr_t * ip);
+extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
+ const struct ndpi_packet_struct *packet);
+extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
+
+#endif /* __NDPI_MAIN_INCLUDE_FILE__ */
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_protocols.h
^
|
@@ -221,9 +221,6 @@
void ndpi_search_mgcp(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow);
-void ndpi_search_gadugadu(struct ndpi_detection_module_struct
- *ndpi_struct, struct ndpi_flow_struct *flow);
-
void ndpi_search_zattoo(struct ndpi_detection_module_struct*ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_qq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_feidian(struct ndpi_detection_module_struct
@@ -352,5 +349,11 @@
void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_skinny(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_tor(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
+void ndpi_search_whois_das(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
+u_int8_t is_skype_connection(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t src_host, u_int32_t dst_host);
+void add_skype_connection(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t src_host, u_int32_t dst_host);
+
-#endif /* __NDPI_PROTOCOLS_INCLUDE_FILE__ */
+#endif /* __NDPI_PROTOCOLS_INCLUDE_FILE__ */
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_protocols_osdpi.h
^
|
@@ -62,13 +62,18 @@
#define NDPI_PROTOCOL_MYSQL 20
#define NDPI_PROTOCOL_TDS 21
#define NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK 22
-#define NDPI_PROTOCOL_I23V5 23
+
+
+#define NDPI_PROTOCOL_MAIL_POPS 23
+ //#define NDPI_PROTOCOL_I23V5 23
+
#define NDPI_PROTOCOL_APPLEJUICE 24
#define NDPI_PROTOCOL_DIRECTCONNECT 25
#define NDPI_PROTOCOL_SOCRATES 26
#define NDPI_PROTOCOL_WINMX 27
#define NDPI_PROTOCOL_VMWARE 28
-#define NDPI_PROTOCOL_PANDO 29
+ //#define NDPI_PROTOCOL_PANDO 29
+#define NDPI_PROTOCOL_MAIL_SMTPS 29
#define NDPI_PROTOCOL_FILETOPIA 30
#define NDPI_PROTOCOL_IMESH 31
#define NDPI_PROTOCOL_KONTIKI 32
@@ -90,7 +95,8 @@
#define NDPI_PROTOCOL_QQ 48
#define NDPI_PROTOCOL_MOVE 49
#define NDPI_PROTOCOL_RTSP 50
-#define NDPI_PROTOCOL_FEIDIAN 51
+//#define NDPI_PROTOCOL_FEIDIAN 51
+#define NDPI_PROTOCOL_MAIL_IMAPS 51
#define NDPI_PROTOCOL_ICECAST 52
#define NDPI_PROTOCOL_PPLIVE 53
#define NDPI_PROTOCOL_PPSTREAM 54
@@ -103,7 +109,7 @@
#define NDPI_PROTOCOL_QQLIVE 61
#define NDPI_PROTOCOL_THUNDER 62
#define NDPI_PROTOCOL_SOULSEEK 63
-#define NDPI_PROTOCOL_GADUGADU 64
+#define NDPI_PROTOCOL_SSL_NO_CERT 64 /* SSL without certificate (Skype, Ultrasurf?) - ntop.org */
#define NDPI_PROTOCOL_IRC 65
#define NDPI_PROTOCOL_POPO 66
#define NDPI_PROTOCOL_UNENCRYPED_JABBER 67
@@ -209,13 +215,14 @@
#define NDPI_PROTOCOL_ORACLE 167 /* Remy Mudingay <mudingay@ill.fr> */
#define NDPI_PROTOCOL_CORBA 168 /* Remy Mudingay <mudingay@ill.fr> */
#define NDPI_PROTOCOL_UBUNTUONE 169 /* Remy Mudingay <mudingay@ill.fr> */
+#define NDPI_PROTOCOL_WHOIS_DAS 170
/* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */
-#define NDPI_LAST_IMPLEMENTED_PROTOCOL 169
+#define NDPI_LAST_IMPLEMENTED_PROTOCOL 170
#define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1)
-#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS 128
+#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
#ifdef __cplusplus
}
#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_public_functions.h
^
|
@@ -130,6 +130,7 @@
/* Public malloc/free */
void* ndpi_malloc(unsigned long size);
+ void* ndpi_calloc(unsigned long count, unsigned long size);
void ndpi_free(void *ptr);
void *ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
char *ndpi_strdup(const char *s);
@@ -146,6 +147,14 @@
void* (*__ndpi_malloc)(unsigned long size),
void (*__ndpi_free)(void *ptr),
ndpi_debug_function_ptr ndpi_debug_printf);
+
+ /**
+ * This function enables cache support in nDPI used for some protocol such as Skype
+ * @param cache host name
+ * @param cache port
+ */
+ void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* host, u_int port);
+
/**
* This function destroys the detection module
* @param ndpi_struct the to clearing detection module
@@ -243,13 +252,19 @@
struct ndpi_flow_struct *flow, char *string_to_match, u_int string_to_match_len);
char* ndpi_get_proto_name(struct ndpi_detection_module_struct *mod, u_int16_t proto_id);
+ int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto);
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod);
int matchStringProtocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
char *string_to_match, u_int string_to_match_len);
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path);
-
u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
+ char* ndpi_revision(void);
+
+ void* ndpi_create_empty_automa(struct ndpi_detection_module_struct *ndpi_struct);
+ int ndpi_add_host_url_subprotocol_to_automa(struct ndpi_detection_module_struct *ndpi_struct, char *value, int protocol_id, void* automa);
+ void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct, void* automa);
+
#ifdef __cplusplus
}
#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/include/ndpi_structs.h
^
|
@@ -26,6 +26,7 @@
#ifndef __NDPI_STRUCTS_INCLUDE_FILE__
#define __NDPI_STRUCTS_INCLUDE_FILE__
+#include "ndpi_credis.h"
#include "linux_compat.h"
#include "ndpi_define.h"
@@ -197,11 +198,6 @@
#ifdef NDPI_PROTOCOL_FTP
u_int32_t ftp_timer_set:1;
#endif
-#ifdef NDPI_PROTOCOL_GADUGADU
- u_int32_t gadu_gadu_ft_direction:1;
- u_int32_t gadu_gadu_voice:1;
- u_int32_t gg_next_id:1;
-#endif
#ifdef NDPI_PROTOCOL_RTSP
u_int32_t rtsp_ts_set:1;
#endif
@@ -259,9 +255,6 @@
#ifdef NDPI_PROTOCOL_TDS
u_int32_t tds_stage:3;
#endif
-#ifdef NDPI_PROTOCOL_GADUGADU
- u_int32_t gadugadu_stage:2;
-#endif
#ifdef NDPI_PROTOCOL_USENET
u_int32_t usenet_stage:2;
#endif
@@ -308,7 +301,7 @@
u_int32_t telnet_stage:2; // 0 - 2
#endif
#ifdef NDPI_PROTOCOL_SSL
- u_int32_t ssl_stage:2; // 0 - 3
+ u_int8_t ssl_stage:2, ssl_seen_client_cert:1, ssl_seen_server_cert:1; // 0 - 5
#endif
#ifdef NDPI_PROTOCOL_POSTGRES
u_int32_t postgres_stage:3;
@@ -371,6 +364,12 @@
#endif
;
+#if defined(WIN32)
+#define pthread_t HANDLE
+#define pthread_mutex_t HANDLE
+#define pthread_rwlock_t pthread_mutex_t
+#endif
+
struct ndpi_flow_udp_struct {
#ifdef NDPI_PROTOCOL_BATTLEFIELD
u_int32_t battlefield_msg_id;
@@ -387,9 +386,6 @@
#ifdef NDPI_PROTOCOL_PPSTREAM
u_int32_t ppstream_stage:3; // 0-7
#endif
-#ifdef NDPI_PROTOCOL_FEIDIAN
- u_int32_t feidian_stage:1; // 0-7
-#endif
#ifdef NDPI_PROTOCOL_HALFLIFE2
u_int32_t halflife2_stage:2; // 0 - 2
#endif
@@ -420,6 +416,20 @@
#endif
;
+#if defined(WIN32)
+#define pthread_t HANDLE
+#define pthread_mutex_t HANDLE
+#define pthread_rwlock_t pthread_mutex_t
+
+#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
+
+#define pthread_rwlock_init pthread_mutex_init
+#define pthread_rwlock_wrlock pthread_mutex_lock
+#define pthread_rwlock_rdlock pthread_mutex_lock
+#define pthread_rwlock_unlock pthread_mutex_unlock
+#define pthread_rwlock_destroy pthread_mutex_destroy
+#endif
+
typedef struct ndpi_int_one_line_struct {
const u_int8_t *ptr;
u_int16_t len;
@@ -492,6 +502,7 @@
u_int8_t packet_unix_lines_parsed_complete;
u_int8_t empty_line_position_set;
u_int8_t packet_direction:1;
+ u_int8_t ssl_certificate_detected:4, ssl_certificate_num_checks:4;
} ndpi_packet_struct_t;
struct ndpi_detection_module_struct;
@@ -578,8 +589,6 @@
void *ac_automa; /* Real type is AC_AUTOMATA_t */
u_int8_t ac_automa_finalized;
- /*gadu gadu*/
- u_int32_t gadugadu_peer_connection_timeout;
/* pplive params */
u_int32_t pplive_connection_timeout;
/* ftp parameters */
@@ -612,8 +621,21 @@
#endif
u_int8_t ip_version_limit;
+ /* Cache */
+ NDPI_REDIS redis;
+
+ /* Skype (we need a lock as this cache can be accessed concurrently) */
+ struct ndpi_LruCache skypeCache;
+#ifndef __KERNEL__
+ pthread_mutex_t skypeCacheLock;
+#else
+ spinlock_t skypeCacheLock;
+#endif
+
/* ********************* */
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
+
+ u_int8_t match_dns_host_names:1;
} ndpi_detection_module_struct_t;
typedef struct ndpi_flow_struct {
@@ -632,8 +654,7 @@
__attribute__ ((__packed__))
#endif
protocol_stack_info;
-#endif
-
+#endif
/* init parameter, internal used to set up timestamp,... */
u_int8_t init_finished:1;
@@ -649,8 +670,15 @@
struct ndpi_flow_udp_struct udp;
} l4;
- u_char host_server_name[64]; /* HTTP host or DNS query */
+ u_char host_server_name[256]; /* HTTP host or DNS query */
+ u_char detected_os[32]; /* Via HTTP User-Agent */
+ union {
+ struct {
+ u_int8_t num_queries, num_answer_rrs;
+ u_int16_t query_type, query_class;
+ } dns;
+ } protos;
/* ALL protocol specific 64 bit variables here */
/* protocols which have marked a connection as this connection cannot be protocol XXX, multiple u_int64_t */
@@ -667,11 +695,6 @@
#endif
#endif
-#ifdef NDPI_PROTOCOL_I23V5
- u_int32_t i23v5_len1;
- u_int32_t i23v5_len2;
- u_int32_t i23v5_len3;
-#endif
u_int16_t packet_counter; // can be 0-65000
u_int16_t packet_direction_counter[2];
u_int16_t byte_counter[2];
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/Makefile.am
^
|
@@ -1,11 +1,11 @@
lib_LTLIBRARIES = libndpi.la
noinst_HEADERS = ../include/ndpi_main.h \
- ../include/ndpi_protocol_history.h \
- ../include/ndpi_protocols.h \
- ../include/ndpi_structs.h \
- ../include/ndpi_utils.h \
- ../include/linux_compat.h
+ ../include/ndpi_protocol_history.h \
+ ../include/ndpi_protocols.h \
+ ../include/ndpi_structs.h \
+ ../include/ndpi_utils.h \
+ ../include/linux_compat.h
# this will create a library 1.4.0
@@ -14,7 +14,7 @@
LIB_ANC=0
# ntop
-AM_CFLAGS=-fPIC
+AM_CFLAGS=-fPIC @PLATFORM_DEPENDENT@
libndpi_la_CPPFLAGS = -I$(top_srcdir)/src/include/ -I$(top_srcdir)/src/lib/third_party/include/
libndpi_la_LDFLAGS=-version-info ${LIB_AC}:${LIB_REV}:${LIB_ANC}
@@ -40,19 +40,16 @@
protocols/dofus.c \
protocols/edonkey.c \
protocols/fasttrack.c \
- protocols/feidian.c \
protocols/fiesta.c \
protocols/filetopia.c \
protocols/flash.c \
protocols/florensia.c \
protocols/ftp.c \
- protocols/gadu_gadu.c \
protocols/gnutella.c \
protocols/guildwars.c \
protocols/halflife2_and_mods.c \
protocols/http_activesync.c \
protocols/http.c \
- protocols/i23v5.c \
protocols/iax.c \
protocols/icecast.c \
protocols/imesh.c \
@@ -81,7 +78,6 @@
protocols/ntp.c \
protocols/openft.c \
protocols/oscar.c \
- protocols/pando.c \
protocols/pcanywhere.c \
protocols/popo.c \
protocols/postgres.c \
@@ -146,6 +142,7 @@
protocols/rsync.c \
protocols/rtcp.c \
protocols/skinny.c \
- protocols/tor.c
+ protocols/tor.c \
+ protocols/whoisdas.c
# NTOP protocols are at the end
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/Makefile.in
^
|
@@ -1,8 +1,9 @@
-# Makefile.in generated by automake 1.12.2 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
-# Copyright (C) 1994-2012 Free Software Foundation, Inc.
-
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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.
@@ -53,7 +54,7 @@
host_triplet = @host@
subdir = src/lib
DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+ $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -62,6 +63,7 @@
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
@@ -103,13 +105,12 @@
libndpi_la-dhcpv6.lo libndpi_la-directconnect.lo \
libndpi_la-directdownloadlink.lo libndpi_la-dns.lo \
libndpi_la-dofus.lo libndpi_la-edonkey.lo \
- libndpi_la-fasttrack.lo libndpi_la-feidian.lo \
- libndpi_la-fiesta.lo libndpi_la-filetopia.lo \
- libndpi_la-flash.lo libndpi_la-florensia.lo libndpi_la-ftp.lo \
- libndpi_la-gadu_gadu.lo libndpi_la-gnutella.lo \
- libndpi_la-guildwars.lo libndpi_la-halflife2_and_mods.lo \
- libndpi_la-http_activesync.lo libndpi_la-http.lo \
- libndpi_la-i23v5.lo libndpi_la-iax.lo libndpi_la-icecast.lo \
+ libndpi_la-fasttrack.lo libndpi_la-fiesta.lo \
+ libndpi_la-filetopia.lo libndpi_la-flash.lo \
+ libndpi_la-florensia.lo libndpi_la-ftp.lo \
+ libndpi_la-gnutella.lo libndpi_la-guildwars.lo \
+ libndpi_la-halflife2_and_mods.lo libndpi_la-http_activesync.lo \
+ libndpi_la-http.lo libndpi_la-iax.lo libndpi_la-icecast.lo \
libndpi_la-imesh.lo libndpi_la-ipp.lo libndpi_la-irc.lo \
libndpi_la-jabber.lo libndpi_la-kerberos.lo \
libndpi_la-kontiki.lo libndpi_la-ldap.lo \
@@ -121,8 +122,8 @@
libndpi_la-netbios.lo libndpi_la-nfs.lo \
libndpi_la-non_tcp_udp.lo libndpi_la-tcp_udp.lo \
libndpi_la-ntp.lo libndpi_la-openft.lo libndpi_la-oscar.lo \
- libndpi_la-pando.lo libndpi_la-pcanywhere.lo \
- libndpi_la-popo.lo libndpi_la-postgres.lo libndpi_la-pplive.lo \
+ libndpi_la-pcanywhere.lo libndpi_la-popo.lo \
+ libndpi_la-postgres.lo libndpi_la-pplive.lo \
libndpi_la-ppstream.lo libndpi_la-pptp.lo libndpi_la-qq.lo \
libndpi_la-quake.lo libndpi_la-rdp.lo libndpi_la-rtp.lo \
libndpi_la-rtsp.lo libndpi_la-shoutcast.lo libndpi_la-sip.lo \
@@ -145,12 +146,12 @@
libndpi_la-ciscovpn.lo libndpi_la-teamspeak.lo \
libndpi_la-viber.lo libndpi_la-openvpn.lo libndpi_la-corba.lo \
libndpi_la-oracle.lo libndpi_la-rsync.lo libndpi_la-rtcp.lo \
- libndpi_la-skinny.lo libndpi_la-tor.lo
+ libndpi_la-skinny.lo libndpi_la-tor.lo libndpi_la-whoisdas.lo
libndpi_la_OBJECTS = $(am_libndpi_la_OBJECTS)
libndpi_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libndpi_la_LDFLAGS) $(LDFLAGS) -o $@
-DEFAULT_INCLUDES = -I.@am__isrc@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
@@ -229,6 +230,7 @@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PLATFORM_DEPENDENT = @PLATFORM_DEPENDENT@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -289,11 +291,11 @@
top_srcdir = @top_srcdir@
lib_LTLIBRARIES = libndpi.la
noinst_HEADERS = ../include/ndpi_main.h \
- ../include/ndpi_protocol_history.h \
- ../include/ndpi_protocols.h \
- ../include/ndpi_structs.h \
- ../include/ndpi_utils.h \
- ../include/linux_compat.h
+ ../include/ndpi_protocol_history.h \
+ ../include/ndpi_protocols.h \
+ ../include/ndpi_structs.h \
+ ../include/ndpi_utils.h \
+ ../include/linux_compat.h
# this will create a library 1.4.0
@@ -302,7 +304,7 @@
LIB_ANC = 0
# ntop
-AM_CFLAGS = -fPIC
+AM_CFLAGS = -fPIC @PLATFORM_DEPENDENT@
libndpi_la_CPPFLAGS = -I$(top_srcdir)/src/include/ -I$(top_srcdir)/src/lib/third_party/include/
libndpi_la_LDFLAGS = -version-info ${LIB_AC}:${LIB_REV}:${LIB_ANC}
libndpi_la_SOURCES = \
@@ -326,19 +328,16 @@
protocols/dofus.c \
protocols/edonkey.c \
protocols/fasttrack.c \
- protocols/feidian.c \
protocols/fiesta.c \
protocols/filetopia.c \
protocols/flash.c \
protocols/florensia.c \
protocols/ftp.c \
- protocols/gadu_gadu.c \
protocols/gnutella.c \
protocols/guildwars.c \
protocols/halflife2_and_mods.c \
protocols/http_activesync.c \
protocols/http.c \
- protocols/i23v5.c \
protocols/iax.c \
protocols/icecast.c \
protocols/imesh.c \
@@ -367,7 +366,6 @@
protocols/ntp.c \
protocols/openft.c \
protocols/oscar.c \
- protocols/pando.c \
protocols/pcanywhere.c \
protocols/popo.c \
protocols/postgres.c \
@@ -432,7 +430,8 @@
protocols/rsync.c \
protocols/rtcp.c \
protocols/skinny.c \
- protocols/tor.c
+ protocols/tor.c \
+ protocols/whoisdas.c
all: all-am
@@ -494,14 +493,12 @@
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
- @list='$(lib_LTLIBRARIES)'; \
- locs=`for p in $$list; do echo $$p; done | \
- sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
- sort -u`; \
- test -z "$$locs" || { \
- echo rm -f $${locs}; \
- rm -f $${locs}; \
- }
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
libndpi.la: $(libndpi_la_OBJECTS) $(libndpi_la_DEPENDENCIES) $(EXTRA_libndpi_la_DEPENDENCIES)
$(libndpi_la_LINK) -rpath $(libdir) $(libndpi_la_OBJECTS) $(libndpi_la_LIBADD) $(LIBS)
@@ -533,13 +530,11 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-dropbox.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-edonkey.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-fasttrack.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-feidian.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-fiesta.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-filetopia.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-flash.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-florensia.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-ftp.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-gadu_gadu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-gnutella.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-gtp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-guildwars.Plo@am__quote@
@@ -547,7 +542,6 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-halflife2_and_mods.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-http.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-http_activesync.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-i23v5.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-iax.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-icecast.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-imesh.Plo@am__quote@
@@ -581,7 +575,6 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-openvpn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-oracle.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-oscar.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-pando.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-pcanywhere.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-popo.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-postgres.Plo@am__quote@
@@ -631,6 +624,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-vmware.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-vnc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-warcraft3.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-whoisdas.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-winmx.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-world_of_kung_fu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libndpi_la-world_of_warcraft.Plo@am__quote@
@@ -800,13 +794,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-fasttrack.lo `test -f 'protocols/fasttrack.c' || echo '$(srcdir)/'`protocols/fasttrack.c
-libndpi_la-feidian.lo: protocols/feidian.c
-@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-feidian.lo -MD -MP -MF $(DEPDIR)/libndpi_la-feidian.Tpo -c -o libndpi_la-feidian.lo `test -f 'protocols/feidian.c' || echo '$(srcdir)/'`protocols/feidian.c
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-feidian.Tpo $(DEPDIR)/libndpi_la-feidian.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='protocols/feidian.c' object='libndpi_la-feidian.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-feidian.lo `test -f 'protocols/feidian.c' || echo '$(srcdir)/'`protocols/feidian.c
-
libndpi_la-fiesta.lo: protocols/fiesta.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-fiesta.lo -MD -MP -MF $(DEPDIR)/libndpi_la-fiesta.Tpo -c -o libndpi_la-fiesta.lo `test -f 'protocols/fiesta.c' || echo '$(srcdir)/'`protocols/fiesta.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-fiesta.Tpo $(DEPDIR)/libndpi_la-fiesta.Plo
@@ -842,13 +829,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-ftp.lo `test -f 'protocols/ftp.c' || echo '$(srcdir)/'`protocols/ftp.c
-libndpi_la-gadu_gadu.lo: protocols/gadu_gadu.c
-@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-gadu_gadu.lo -MD -MP -MF $(DEPDIR)/libndpi_la-gadu_gadu.Tpo -c -o libndpi_la-gadu_gadu.lo `test -f 'protocols/gadu_gadu.c' || echo '$(srcdir)/'`protocols/gadu_gadu.c
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-gadu_gadu.Tpo $(DEPDIR)/libndpi_la-gadu_gadu.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='protocols/gadu_gadu.c' object='libndpi_la-gadu_gadu.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-gadu_gadu.lo `test -f 'protocols/gadu_gadu.c' || echo '$(srcdir)/'`protocols/gadu_gadu.c
-
libndpi_la-gnutella.lo: protocols/gnutella.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-gnutella.lo -MD -MP -MF $(DEPDIR)/libndpi_la-gnutella.Tpo -c -o libndpi_la-gnutella.lo `test -f 'protocols/gnutella.c' || echo '$(srcdir)/'`protocols/gnutella.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-gnutella.Tpo $(DEPDIR)/libndpi_la-gnutella.Plo
@@ -884,13 +864,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-http.lo `test -f 'protocols/http.c' || echo '$(srcdir)/'`protocols/http.c
-libndpi_la-i23v5.lo: protocols/i23v5.c
-@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-i23v5.lo -MD -MP -MF $(DEPDIR)/libndpi_la-i23v5.Tpo -c -o libndpi_la-i23v5.lo `test -f 'protocols/i23v5.c' || echo '$(srcdir)/'`protocols/i23v5.c
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-i23v5.Tpo $(DEPDIR)/libndpi_la-i23v5.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='protocols/i23v5.c' object='libndpi_la-i23v5.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-i23v5.lo `test -f 'protocols/i23v5.c' || echo '$(srcdir)/'`protocols/i23v5.c
-
libndpi_la-iax.lo: protocols/iax.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-iax.lo -MD -MP -MF $(DEPDIR)/libndpi_la-iax.Tpo -c -o libndpi_la-iax.lo `test -f 'protocols/iax.c' || echo '$(srcdir)/'`protocols/iax.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-iax.Tpo $(DEPDIR)/libndpi_la-iax.Plo
@@ -1087,13 +1060,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-oscar.lo `test -f 'protocols/oscar.c' || echo '$(srcdir)/'`protocols/oscar.c
-libndpi_la-pando.lo: protocols/pando.c
-@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-pando.lo -MD -MP -MF $(DEPDIR)/libndpi_la-pando.Tpo -c -o libndpi_la-pando.lo `test -f 'protocols/pando.c' || echo '$(srcdir)/'`protocols/pando.c
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-pando.Tpo $(DEPDIR)/libndpi_la-pando.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='protocols/pando.c' object='libndpi_la-pando.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-pando.lo `test -f 'protocols/pando.c' || echo '$(srcdir)/'`protocols/pando.c
-
libndpi_la-pcanywhere.lo: protocols/pcanywhere.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-pcanywhere.lo -MD -MP -MF $(DEPDIR)/libndpi_la-pcanywhere.Tpo -c -o libndpi_la-pcanywhere.lo `test -f 'protocols/pcanywhere.c' || echo '$(srcdir)/'`protocols/pcanywhere.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-pcanywhere.Tpo $(DEPDIR)/libndpi_la-pcanywhere.Plo
@@ -1549,6 +1515,13 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-tor.lo `test -f 'protocols/tor.c' || echo '$(srcdir)/'`protocols/tor.c
+libndpi_la-whoisdas.lo: protocols/whoisdas.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libndpi_la-whoisdas.lo -MD -MP -MF $(DEPDIR)/libndpi_la-whoisdas.Tpo -c -o libndpi_la-whoisdas.lo `test -f 'protocols/whoisdas.c' || echo '$(srcdir)/'`protocols/whoisdas.c
+@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libndpi_la-whoisdas.Tpo $(DEPDIR)/libndpi_la-whoisdas.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='protocols/whoisdas.c' object='libndpi_la-whoisdas.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libndpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libndpi_la-whoisdas.lo `test -f 'protocols/whoisdas.c' || echo '$(srcdir)/'`protocols/whoisdas.c
+
mostlyclean-libtool:
-rm -f *.lo
@@ -1604,20 +1577,6 @@
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
-cscopelist: $(HEADERS) $(SOURCES) $(LISP)
- list='$(SOURCES) $(HEADERS) $(LISP)'; \
- case "$(srcdir)" in \
- [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
- *) sdir=$(subdir)/$(srcdir) ;; \
- esac; \
- for i in $$list; do \
- if test -f "$$i"; then \
- echo "$(subdir)/$$i"; \
- else \
- echo "$$sdir/$$i"; \
- fi; \
- done >> $(top_builddir)/cscope.files
-
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -1762,7 +1721,7 @@
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
- clean-libLTLIBRARIES clean-libtool cscopelist ctags distclean \
+ clean-libLTLIBRARIES clean-libtool ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
|
[-]
[+]
|
Added |
nDPI.tar.bz2/src/lib/ndpi_cache.c
^
|
@@ -0,0 +1,549 @@
+/*
+ * ndpi_cache.c
+ *
+ * Copyright (C) 2013 - ntop.org
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+static u_int8_t traceLRU = 0;
+
+#ifndef __KERNEL__
+#ifdef __GNUC__
+#define likely(x) __builtin_expect((x),1)
+#define unlikely(x) __builtin_expect((x),0)
+#else
+#define likely(x) (x)
+#define unlikely(x) (x)
+#endif
+#endif
+
+/* ************************************************************************ */
+
+static u_int32_t get_now(void) {
+#ifndef __KERNEL__
+ return(time(NULL));
+#else
+ return(jiffies);
+#endif
+}
+
+/* ************************************************************************ */
+
+static u_int32_t compute_timeout(u_int32_t t) {
+#ifndef __KERNEL__
+ return(t);
+#else
+ return(t*HZ);
+#endif
+}
+
+/* ************************************************************************ */
+
+int ndpi_init_lru_cache(struct ndpi_LruCache *cache, u_int32_t max_size) {
+ if(unlikely(traceLRU))
+ printf("%s(max_size=%u)", __FUNCTION__, max_size);
+
+ cache->max_cache_node_len = 4;
+ cache->hash_size = max_size/cache->max_cache_node_len;
+
+#ifdef FULL_STATS
+ cache->mem_size += cache->hash_size*sizeof(struct ndpi_LruCacheEntry*);
+#endif
+ if((cache->hash = (struct ndpi_LruCacheEntry**)ndpi_calloc(cache->hash_size, sizeof(struct ndpi_LruCacheEntry*))) == NULL) {
+ printf("ERROR: Not enough memory?");
+ return(-1);
+ }
+
+#ifdef FULL_STATS
+ cache->mem_size += cache->hash_size*sizeof(u_int32_t);
+#endif
+ if((cache->current_hash_size = (u_int32_t*)ndpi_calloc(cache->hash_size, sizeof(u_int32_t))) == NULL) {
+ printf("ERROR: Not enough memory?");
+ return(-1);
+ }
+
+ return(0);
+}
+
+/* ************************************ */
+
+static void free_lru_cache_entry(struct ndpi_LruCache *cache, struct ndpi_LruCacheEntry *entry) {
+ if(entry->numeric_node) {
+ ; /* Nothing to do */
+ } else {
+#ifdef FULL_STATS
+ cache->mem_size -= strlen(entry->u.str.key);
+ cache->mem_size -= strlen(entry->u.str.value);
+#endif
+ ndpi_free(entry->u.str.key);
+ ndpi_free(entry->u.str.value);
+ }
+}
+
+/* ************************************ */
+
+void ndpi_free_lru_cache(struct ndpi_LruCache *cache) {
+ int i;
+
+ if(unlikely(traceLRU)) printf("%s()", __FUNCTION__);
+
+ for(i=0; i<(int)cache->hash_size; i++) {
+ struct ndpi_LruCacheEntry *head = cache->hash[i];
+
+ while(head != NULL) {
+ struct ndpi_LruCacheEntry *next = head->next;
+
+ free_lru_cache_entry(cache, head);
+ ndpi_free(head);
+#ifdef FULL_STATS
+ cache->mem_size -= sizeof(struct ndpi_LruCacheEntry);
+#endif
+ head = next;
+ }
+ }
+
+ ndpi_free(cache->hash);
+#ifdef FULL_STATS
+ cache->mem_size -= cache->hash_size*sizeof(struct ndpi_LruCacheEntry*);
+#endif
+ ndpi_free(cache->current_hash_size);
+#ifdef FULL_STATS
+ cache->mem_size -= cache->hash_size*sizeof(u_int32_t);
+#endif
+}
+
+/* ************************************ */
+
+static u_int32_t lru_hash_string(char *a) {
+ u_int32_t h = 0, i;
+
+ for(i=0; a[i] != 0; i++) h += ((u_int32_t)a[i])*(i+1);
+ return(h);
+}
+
+/* ************************************ */
+
+#ifdef _NOT_USED_
+static u_int32_t lru_node_key_hash(struct ndpi_LruCacheEntry *a) {
+ if(a->numeric_node)
+ return((u_int32_t)a->u.num.key);
+ else
+ return(lru_hash_string(a->u.str.key));
+}
+#endif
+
+/* ************************************ */
+
+#ifdef _NOT_USED_
+/*
+ Return codes
+ 0 Items are the same
+ -1 a < b
+ 1 a > b
+*/
+static int lru_node_key_entry_compare(struct ndpi_LruCacheEntry *a,
+ struct ndpi_LruCacheEntry *b) {
+ if(a->numeric_node) {
+ if(a->u.num.key == b->u.num.key)
+ return(0);
+ else if(a->u.num.key < b->u.num.key)
+ return(-1);
+ else
+ return(1);
+ } else
+ return(strcmp(a->u.str.key, b->u.str.key));
+}
+#endif
+
+/* ********************************************* */
+
+struct ndpi_LruCacheEntry* lru_allocCacheNumericNode(struct ndpi_LruCache *cache, u_int32_t key, u_int32_t value) {
+ struct ndpi_LruCacheEntry *node = (struct ndpi_LruCacheEntry*)ndpi_calloc(1, sizeof(struct ndpi_LruCacheEntry));
+
+ if(unlikely(traceLRU))
+ printf("%s(key=%lu, value=%u)", __FUNCTION__,
+ (long unsigned int)key, (unsigned int)value);
+
+ if(node == NULL)
+ printf("ERROR: Not enough memory?");
+ else {
+ node->numeric_node = 1;
+ node->u.num.key = key, node->u.num.value = value;
+ }
+
+#ifdef FULL_STATS
+ cache->mem_size += sizeof(struct ndpi_LruCacheEntry);
+ //printf("%s(key=%lu, value=%u) [memory: %u]", __FUNCTION__, key, value, cache->mem_size);
+#endif
+
+ return(node);
+}
+
+/* ************************************ */
+
+struct ndpi_LruCacheEntry* lru_allocCacheStringNode(struct ndpi_LruCache *cache, char *key, char *value, u_int32_t timeout) {
+ struct ndpi_LruCacheEntry *node = (struct ndpi_LruCacheEntry*)ndpi_calloc(1, sizeof(struct ndpi_LruCacheEntry));
+
+ if(unlikely(traceLRU))
+ printf("%s(key=%s, value=%s)", __FUNCTION__, key, value);
+
+ if(node == NULL)
+ printf("ERROR: Not enough memory?");
+ else {
+ node->numeric_node = 0;
+ node->u.str.key = ndpi_strdup(key), node->u.str.value = ndpi_strdup(value);
+ node->u.str.expire_time = (timeout == 0) ? 0 : (compute_timeout(timeout) + get_now());
+
+#ifdef FULL_STATS
+ cache->mem_size += sizeof(struct ndpi_LruCacheEntry) + strlen(key) + strlen(value);
+ //printf("%s(key=%s, value=%s) [memory: %u]", __FUNCTION__, key, value, cache->mem_size);
+#endif
+ }
+
+ return(node);
+}
+
+/* ************************************ */
+
+static void trim_subhash(struct ndpi_LruCache *cache, u_int32_t hash_id) {
+ if(unlikely(traceLRU))
+ printf("%s()", __FUNCTION__);
+
+ if(cache->current_hash_size[hash_id] >= cache->max_cache_node_len) {
+ struct ndpi_LruCacheEntry *head = cache->hash[hash_id], *prev = NULL;
+
+ /* Find the last entry and remove it */
+ while(head->next != NULL) {
+ prev = head;
+ head = head->next;
+ }
+
+ if(prev) {
+ prev->next = head->next;
+ free_lru_cache_entry(cache, head);
+ ndpi_free(head);
+#ifdef FULL_STATS
+ cache->mem_size -= sizeof(struct ndpi_LruCacheEntry);
+#endif
+ cache->current_hash_size[hash_id]--;
+ } else
+ printf("ERROR: Internal error in %s()", __FUNCTION__);
+ }
+}
+
+/* ************************************ */
+
+#ifdef _NOT_USED_
+static void validate_unit_len(struct ndpi_LruCache *cache, u_int32_t hash_id) {
+ struct ndpi_LruCacheEntry *head = cache->hash[hash_id];
+ u_int num = 0;
+
+ while(head != NULL) {
+ head = head->next, num++;
+ }
+
+ if(num != cache->current_hash_size[hash_id])
+ printf("ERROR: Invalid length [expected: %u][read: %u][hash_id: %u]",
+ cache->current_hash_size[hash_id], num, hash_id);
+}
+#endif
+
+/* ************************************ */
+
+int ndpi_add_to_lru_cache_num(struct ndpi_LruCache *cache,
+ u_int32_t key, u_int32_t value) {
+ if(cache->hash_size == 0)
+ return(0);
+ else {
+ u_int32_t hash_id = key % cache->hash_size;
+ struct ndpi_LruCacheEntry *node;
+ u_int8_t node_already_existing = 0;
+ int rc = 0;
+
+ if(unlikely(traceLRU))
+ printf("%s(key=%lu, value=%u)", __FUNCTION__, (long unsigned int)key, (unsigned int)value);
+
+ // validate_unit_len(cache, hash_id);
+ cache->num_cache_add++;
+
+ /* [1] Add to hash */
+ if(cache->hash[hash_id] == NULL) {
+ if((node = lru_allocCacheNumericNode(cache, key, value)) == NULL) {
+ rc = -1;
+ goto ret_add_to_lru_cache;
+ }
+
+ cache->hash[hash_id] = node;
+ cache->current_hash_size[hash_id]++;
+ } else {
+ /* Check if the element exists */
+ struct ndpi_LruCacheEntry *head = cache->hash[hash_id];
+
+ while(head != NULL) {
+ if(head->u.num.key == key) {
+ /* Duplicated key found */
+ node = head;
+ node->u.num.value = value; /* Overwrite old value */
+ node_already_existing = 1;
+ break;
+ } else
+ head = head->next;
+ }
+
+ if(!node_already_existing) {
+ if((node = lru_allocCacheNumericNode(cache, key, value)) == NULL) {
+ rc = -2;
+ goto ret_add_to_lru_cache;
+ }
+
+ node->next = cache->hash[hash_id];
+ cache->hash[hash_id] = node;
+ cache->current_hash_size[hash_id]++;
+ }
+ }
+
+ trim_subhash(cache, hash_id);
+
+ // validate_unit_len(cache, hash_id);
+
+ ret_add_to_lru_cache:
+ return(rc);
+ }
+}
+
+/* ************************************ */
+
+int ndpi_add_to_lru_cache_str_timeout(struct ndpi_LruCache *cache,
+ char *key, char *value,
+ u_int32_t timeout) {
+ if(cache->hash_size == 0)
+ return(0);
+ else {
+ u_int32_t hash_val = lru_hash_string(key);
+ u_int32_t hash_id = hash_val % cache->hash_size;
+ struct ndpi_LruCacheEntry *node;
+ u_int8_t node_already_existing = 0;
+ int rc = 0;
+
+ if(unlikely(traceLRU))
+ printf("%s(key=%s, value=%s)", __FUNCTION__, key, value);
+
+ // validate_unit_len(cache, hash_id);
+ cache->num_cache_add++;
+
+ /* [1] Add to hash */
+ if(cache->hash[hash_id] == NULL) {
+ if((node = lru_allocCacheStringNode(cache, key, value, timeout)) == NULL) {
+ rc = -1;
+ goto ret_add_to_lru_cache;
+ }
+
+ cache->hash[hash_id] = node;
+ cache->current_hash_size[hash_id]++;
+ } else {
+ /* Check if the element exists */
+ struct ndpi_LruCacheEntry *head = cache->hash[hash_id];
+
+ while(head != NULL) {
+ if(strcmp(head->u.str.key, key) == 0) {
+ /* Duplicated key found */
+ node = head;
+ if(node->u.str.value) {
+#ifdef FULL_STATS
+ cache->mem_size -= strlen(node->u.str.value);
+#endif
+ ndpi_free(node->u.str.value);
+ }
+
+ node->u.str.value = ndpi_strdup(value); /* Overwrite old value */
+#ifdef FULL_STATS
+ cache->mem_size += strlen(value);
+#endif
+
+ node->u.str.expire_time = (timeout == 0) ? 0 : (compute_timeout(timeout) + get_now());
+ node_already_existing = 1;
+ break;
+ } else
+ head = head->next;
+ }
+
+ if(!node_already_existing) {
+ if((node = lru_allocCacheStringNode(cache, key, value, timeout)) == NULL) {
+ rc = -2;
+ goto ret_add_to_lru_cache;
+ }
+
+ node->next = cache->hash[hash_id];
+ cache->hash[hash_id] = node;
+ cache->current_hash_size[hash_id]++;
+ }
+ }
+
+ trim_subhash(cache, hash_id);
+
+ // validate_unit_len(cache, hash_id);
+
+ ret_add_to_lru_cache:
+ return(rc);
+ }
+}
+
+/* ************************************ */
+
+int ndpi_add_to_lru_cache_str(struct ndpi_LruCache *cache, char *key, char *value) {
+ ndpi_add_to_lru_cache_str_timeout(cache, key, value, 0);
+ return(0);
+}
+
+/* ************************************ */
+
+u_int32_t ndpi_find_lru_cache_num(struct ndpi_LruCache *cache, u_int32_t key) {
+ if(cache->hash_size == 0)
+ return(0);
+ else {
+ u_int32_t hash_id = key % cache->hash_size;
+ struct ndpi_LruCacheEntry *head, *prev = NULL;
+ u_int32_t ret_val = NDPI_PROTOCOL_UNKNOWN;
+
+ if(unlikely(traceLRU))
+ printf("%s(%lu)", __FUNCTION__, (long unsigned int)key);
+
+ head = cache->hash[hash_id];
+ // validate_unit_len(cache, hash_id);
+ cache->num_cache_find++;
+
+ while(head != NULL) {
+ if(head->u.num.key == key) {
+ ret_val = head->u.num.value;
+
+ /* We now need to move it in front */
+ if(prev != NULL) {
+ /* We're not the first element yet */
+ prev->next = head->next;
+ head->next = cache->hash[hash_id];
+ cache->hash[hash_id] = head;
+ }
+ break;
+ } else {
+ prev = head;
+ head = head->next;
+ }
+ }
+
+ if(ret_val == NDPI_PROTOCOL_UNKNOWN) cache->num_cache_misses++;
+
+ return(ret_val);
+ }
+}
+
+/* ************************************ */
+
+char*ndpi_find_lru_cache_str(struct ndpi_LruCache *cache, char *key) {
+ if(cache->hash_size == 0)
+ return(0);
+ else {
+ u_int32_t hash_val = lru_hash_string(key);
+ u_int32_t hash_id = hash_val % cache->hash_size;
+ struct ndpi_LruCacheEntry *head, *prev = NULL;
+ char *ret_val = NULL;
+ time_t now = get_now();
+
+ if(unlikely(traceLRU))
+ printf("%s(%s)", __FUNCTION__, key);
+
+ // validate_unit_len(cache, hash_id);
+ cache->num_cache_find++;
+ head = cache->hash[hash_id];
+
+ while(head != NULL) {
+ if(strcmp(head->u.str.key, key) == 0) {
+ if(head->u.str.expire_time < now) {
+ /* The node has expired */
+ if(prev == NULL)
+ cache->hash[hash_id] = head->next;
+ else
+ prev->next = head->next;
+
+ free_lru_cache_entry(cache, head);
+ ndpi_free(head);
+#ifdef FULL_STATS
+ cache->mem_size -= sizeof(struct ndpi_LruCacheEntry);
+#endif
+ ret_val = NULL;
+ cache->current_hash_size[hash_id]--;
+ } else
+ ret_val = head->u.str.value;
+ break;
+ } else {
+ prev = head;
+ head = head->next;
+ }
+ }
+
+ if(ret_val == NULL) cache->num_cache_misses++;
+ // validate_unit_len(cache, hash_id);
+
+ return(ret_val);
+ }
+}
+
+/* ************************************ */
+
+#ifdef _NOT_USED_
+static void dumpndpi_LruCacheStat(struct ndpi_LruCache *cache,
+ char* cacheName, u_int timeDifference) {
+ u_int32_t tot_cache_add = 0, tot_cache_find = 0;
+ u_int32_t tot_mem = 0, grand_total_mem = 0;
+ u_int32_t num_cache_add = 0, num_cache_find = 0;
+ u_int32_t num_cache_misses = 0, grand_total = 0;
+ float a, f, m;
+ int j, tot;
+
+ tot_cache_add += cache->num_cache_add;
+ num_cache_add += cache->num_cache_add - cache->last_num_cache_add;
+ cache->last_num_cache_add = cache->num_cache_add;
+
+ tot_cache_find += cache->num_cache_find;
+ num_cache_find += cache->num_cache_find - cache->last_num_cache_find;
+ cache->last_num_cache_find = cache->num_cache_find;
+
+ num_cache_misses += cache->num_cache_misses - cache->last_num_cache_misses;
+ cache->last_num_cache_misses = cache->num_cache_misses;
+
+ for(tot=0, tot_mem=0, j=0; j<(int)cache->hash_size; j++)
+ tot += cache->current_hash_size[j], tot_mem += (cache->mem_size+sizeof(struct ndpi_LruCache));
+
+ grand_total += tot;
+ grand_total_mem += tot_mem;
+
+#ifdef FULL_STATS
+ if(tot > 0)
+ printf("LRUCacheUnit %s [current_hash_size: %u][max_cache_node_len: %u][mem_size: %.1f MB/%.1f MB]",
+ cacheName, tot, cache->max_cache_node_len, (float)tot_mem/(float)(1024*1024), (float)grand_total_mem/(float)(1024*1024));
+#endif
+
+ a = (timeDifference > 0) ? ((float)num_cache_add)/(float)timeDifference : 0;
+ f = (timeDifference > 0) ? ((float)num_cache_find)/(float)timeDifference : 0;
+ m = (num_cache_add > 0) ? ((float)(num_cache_misses*100))/((float)num_cache_find) : 0;
+
+ if(tot_cache_find || tot_cache_add)
+ printf("LRUCache %s [find: %u operations/%.1f find/sec]"
+ "[cache miss %u/%.1f %%][add: %u operations/%.1f add/sec][tot: %u][mem_size: %.1f MB]",
+ cacheName, tot_cache_find, f, num_cache_misses, m, tot_cache_add, a, grand_total,
+ (float)grand_total_mem/(float)(1024*1024));
+}
+#endif
+
|
[-]
[+]
|
Added |
nDPI.tar.bz2/src/lib/ndpi_credis.c
^
|
@@ -0,0 +1,1576 @@
+/* ndpi_credis.c -- a C client library for Redis
+ *
+ * Copyright (c) 2009-2010, Jonas Romfelt <jonas at romfelt dot se>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Ndpi_Credis 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#define _CRT_SECURE_NO_DEPRECATE
+#define WIN32_LEAN_AND_MEAN
+#include <winsock2.h>
+#else
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ndpi_credis.h"
+
+#ifdef WIN32
+void close(int fd) {
+ closesocket(fd);
+}
+#endif
+
+#define CR_ERROR '-'
+#define CR_INLINE '+'
+#define CR_BULK '$'
+#define CR_MULTIBULK '*'
+#define CR_INT ':'
+
+#define CR_BUFFER_SIZE 4096
+#define CR_BUFFER_WATERMARK ((CR_BUFFER_SIZE)/10+1)
+#define CR_MULTIBULK_SIZE 256
+
+#define _STRINGIF(arg) #arg
+#define STRINGIFY(arg) _STRINGIF(arg)
+
+#define CR_VERSION_STRING_SIZE_STR STRINGIFY(NDPI_CNDPI_REDIS_VERSION_STRING_SIZE)
+#define CR_MULTIPLEXING_API_SIZE_STR STRINGIFY(NDPI_CNDPI_REDIS_MULTIPLEXING_API_SIZE)
+#define CR_USED_MEMORY_HUMAN_SIZE_STR STRINGIFY(NDPI_CNDPI_REDIS_USED_MEMORY_HUMAN_SIZE)
+
+#undef CREDIS_DEBUG
+
+#ifdef CREDIS_DEBUG
+/* add -DCREDIS_DEBUG to CPPFLAGS in Makefile for debug outputs */
+#define DEBUG_PRINT(...) \
+ do { \
+ printf("%s() @ %d: ", __FUNCTION__, __LINE__); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ } while (0)
+#else
+#define DEBUG_PRINT(...)
+#endif
+
+
+/* format warnings are GNU C specific */
+#if !__GNUC__
+#define __attribute__(x)
+#endif
+
+typedef struct _cr_buffer {
+ char *data;
+ int idx;
+ int len;
+ int size;
+} cr_buffer;
+
+typedef struct _cr_multibulk {
+ char **bulks;
+ int *idxs;
+ int size;
+ int len;
+} cr_multibulk;
+
+typedef struct _cr_reply {
+ int integer;
+ char *line;
+ char *bulk;
+ cr_multibulk multibulk;
+} cr_reply;
+
+typedef struct _cr_redis {
+ struct {
+ int major;
+ int minor;
+ int patch;
+ } version;
+ int fd;
+ char *ip;
+ int port;
+ int timeout;
+ cr_buffer buf;
+ cr_reply reply;
+ int error;
+} cr_redis;
+
+
+/* Returns pointer to the '\r' of the first occurence of "\r\n", or NULL
+ * if not found */
+static char * cr_findnl(char *buf, int len) {
+ while (--len >= 0) {
+ if (*(buf++) == '\r')
+ if (*buf == '\n')
+ return --buf;
+ }
+ return NULL;
+}
+
+/* Allocate at least `size' bytes more buffer memory, keeping content of
+ * previously allocated memory untouched.
+ * Returns:
+ * 0 on success
+ * -1 on error, i.e. more memory not available */
+static int cr_moremem(cr_buffer *buf, int size)
+{
+ char *ptr;
+ int total, n;
+
+ n = size / CR_BUFFER_SIZE + 1;
+ total = buf->size + n * CR_BUFFER_SIZE;
+
+ DEBUG_PRINT("allocate %d x CR_BUFFER_SIZE, total %d bytes", n, total);
+
+ ptr = (char*)realloc(buf->data, total);
+ if (ptr == NULL)
+ return -1;
+
+ buf->data = ptr;
+ buf->size = total;
+ return 0;
+}
+
+/* Allocate at least `size' more multibulk storage, keeping content of
+ * previously allocated memory untouched.
+ * Returns:
+ * 0 on success
+ * -1 on error, i.e. more memory not available */
+static int cr_morebulk(cr_multibulk *mb, int size)
+{
+ char **cptr;
+ int *iptr;
+ int total, n;
+
+ n = (size / CR_MULTIBULK_SIZE + 1) * CR_MULTIBULK_SIZE;
+ total = mb->size + n;
+
+ DEBUG_PRINT("allocate %d x CR_MULTIBULK_SIZE, total %d (%lu bytes)",
+ n, total, total * ((sizeof(char *)+sizeof(int))));
+ cptr = (char**)realloc(mb->bulks, total * sizeof(char *));
+ iptr = (int*)realloc(mb->idxs, total * sizeof(int));
+
+ if (cptr == NULL || iptr == NULL)
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ mb->bulks = cptr;
+ mb->idxs = iptr;
+ mb->size = total;
+ return 0;
+}
+
+/* Splits string `str' on character `token' builds a multi-bulk array from
+ * the items. This function will modify the contents of what `str' points
+ * to.
+ * Returns:
+ * 0 on success
+ * <0 on error, i.e. more memory not available */
+static int cr_splitstrtromultibulk(NDPI_REDIS rhnd, char *str, const char token)
+{
+ int i = 0;
+
+ if (str != NULL) {
+ rhnd->reply.multibulk.bulks[i++] = str;
+ while ((str = strchr(str, token))) {
+ *str++ = '\0';
+ if (i >= rhnd->reply.multibulk.size)
+ if (cr_morebulk(&(rhnd->reply.multibulk), 1))
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ rhnd->reply.multibulk.bulks[i++] = str;
+ }
+ }
+ rhnd->reply.multibulk.len = i;
+ return 0;
+}
+
+/* Appends a printf style formatted to the end of buffer `buf'. If available
+ * memory in buffer is not enough to hold `str' more memory is allocated to
+ * the buffer.
+ * Returns:
+ * 0 on success
+ * <0 on error, i.e. more memory not available */
+static int cr_appendstrf(cr_buffer *buf, const char *format, ...)
+{
+ int rc, avail;
+ va_list ap;
+
+ avail = buf->size - buf->len;
+
+ va_start(ap, format);
+ rc = vsnprintf(buf->data + buf->len, avail, format, ap);
+ va_end(ap);
+
+ if (rc < 0)
+ return -1;
+
+ if (rc >= avail) {
+ if (cr_moremem(buf, rc - avail + 1))
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ va_start(ap, format);
+ rc = vsnprintf(buf->data + buf->len, buf->size - buf->len, format, ap);
+ va_end(ap);
+ }
+ buf->len += rc;
+
+ return 0;
+}
+
+/* Appends a zero-terminated string `str' to the end of buffer `buf'. If
+ * available memory in buffer is not enough to hold `str' more memory is
+ * allocated to the buffer. If `space' is not 0 `str' is padded with a space.
+ * Returns:
+ * 0 on success
+ * <0 on error, i.e. more memory not available */
+static int cr_appendstr(cr_buffer *buf, const char *str, int space)
+{
+ int avail, len, reqd;
+
+ len = strlen(str);
+ avail = buf->size - buf->len;
+
+ /* required memory: len, terminating zero and possibly a space */
+ reqd = len + 1;
+ if (space)
+ reqd++;
+
+ if (reqd > avail)
+ if (cr_moremem(buf, reqd - avail + 1))
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ if (space)
+ buf->data[buf->len++] = ' ';
+
+ memcpy(buf->data + buf->len, str, len);
+ buf->len += len;
+
+ buf->data[buf->len] = '\0';
+
+ return 0;
+}
+
+/* Appends an array of strings `strv' to the end of buffer `buf', each
+ * separated with a space. If `newline' is not 0 "\r\n" is added last
+ * to buffer.
+ * Returns:
+ * 0 on success
+ * <0 on error, i.e. more memory not available */
+static int cr_appendstrarray(cr_buffer *buf, int strc, const char **strv, int newline)
+{
+ int rc, i;
+
+ for (i = 0; i < strc; i++) {
+ if ((rc = cr_appendstr(buf, strv[i], 1)) != 0)
+ return rc;
+ }
+
+ if (newline) {
+ if ((rc = cr_appendstr(buf, "\r\n", 0)) != 0)
+ return rc;
+ }
+
+ return 0;
+}
+
+/* Helper function for select that waits for `timeout' milliseconds
+ * for `fd' to become readable (`readable' == 1) or writable.
+ * Returns:
+ * >0 `fd' became readable or writable
+ * 0 timeout
+ * -1 on error */
+int cr_select(int fd, int timeout, int readable)
+{
+ struct timeval tv;
+ fd_set fds;
+
+ tv.tv_sec = timeout/1000;
+ tv.tv_usec = (timeout%1000)*1000;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ if (readable == 1)
+ return select(fd+1, &fds, NULL, NULL, &tv);
+
+ return select(fd+1, NULL, &fds, NULL, &tv);
+}
+#define cr_selectreadable(fd, timeout) cr_select(fd, timeout, 1)
+#define cr_selectwritable(fd, timeout) cr_select(fd, timeout, 0)
+
+/* Receives at most `size' bytes from socket `fd' to `buf'. Times out after
+ * `msecs' milliseconds if no data has yet arrived.
+ * Returns:
+ * >0 number of read bytes on success
+ * 0 server closed connection
+ * -1 on error
+ * -2 on timeout */
+static int cr_receivedata(int fd, unsigned int msecs, char *buf, int size)
+{
+ int rc = cr_selectreadable(fd, msecs);
+
+ if (rc > 0)
+ return recv(fd, buf, size, 0);
+ else if (rc == 0)
+ return -2;
+ else
+ return -1;
+}
+
+/* Sends `size' bytes from `buf' to socket `fd' and times out after `msecs'
+ * milliseconds if not all data has been sent.
+ * Returns:
+ * >0 number of bytes sent; if less than `size' it means that timeout occurred
+ * -1 on error */
+static int cr_senddata(int fd, unsigned int msecs, char *buf, int size)
+{
+ fd_set fds;
+ struct timeval tv;
+ int rc, sent=0;
+
+ /* NOTE: On Linux, select() modifies timeout to reflect the amount
+ * of time not slept, on other systems it is likely not the same */
+ tv.tv_sec = msecs/1000;
+ tv.tv_usec = (msecs%1000)*1000;
+
+ while (sent < size) {
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ rc = select(fd+1, NULL, &fds, NULL, &tv);
+
+ if (rc > 0) {
+ rc = send(fd, buf+sent, size-sent, 0);
+ if (rc < 0)
+ return -1;
+ sent += rc;
+ }
+ else if (rc == 0) /* timeout */
+ break;
+ else
+ return -1;
+ }
+
+ return sent;
+}
+
+/* Buffered read line, returns pointer to zero-terminated string
+ * and length of that string. `start' specifies from which byte
+ * to start looking for "\r\n".
+ * Returns:
+ * >0 length of string to which pointer `line' refers. `idx' is
+ * an optional pointer for returning start index of line with
+ * respect to buffer.
+ * 0 connection to Redis server was closed
+ * -1 on error, i.e. a string is not available */
+static int cr_readln(NDPI_REDIS rhnd, int start, char **line, int *idx)
+{
+ cr_buffer *buf = &(rhnd->buf);
+ char *nl;
+ int rc, len, avail, more;
+
+ /* do we need more data before we expect to find "\r\n"? */
+ if ((more = buf->idx + start + 2 - buf->len) < 0)
+ more = 0;
+
+ while (more > 0 ||
+ (nl = cr_findnl(buf->data + buf->idx + start, buf->len - (buf->idx + start))) == NULL) {
+ avail = buf->size - buf->len;
+ if (avail < CR_BUFFER_WATERMARK || avail < more) {
+ DEBUG_PRINT("available buffer memory is low, get more memory");
+ if (cr_moremem(buf, more>0?more:1))
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ avail = buf->size - buf->len;
+ }
+
+ rc = cr_receivedata(rhnd->fd, rhnd->timeout, buf->data + buf->len, avail);
+ if (rc > 0) {
+ DEBUG_PRINT("received %d bytes: %s", rc, buf->data + buf->len);
+ buf->len += rc;
+ }
+ else if (rc == 0)
+ return 0; /* EOF reached, connection terminated */
+ else
+ return -1; /* error */
+
+ /* do we need more data before we expect to find "\r\n"? */
+ if ((more = buf->idx + start + 2 - buf->len) < 0)
+ more = 0;
+ }
+
+ *nl = '\0'; /* zero terminate */
+
+ *line = buf->data + buf->idx;
+ if (idx)
+ *idx = buf->idx;
+ len = nl - *line;
+ buf->idx = (nl - buf->data) + 2; /* skip "\r\n" */
+
+ DEBUG_PRINT("size=%d, len=%d, idx=%d, start=%d, line=%s",
+ buf->size, buf->len, buf->idx, start, *line);
+
+ return len;
+}
+
+static int cr_receivemultibulk(NDPI_REDIS rhnd, char *line)
+{
+ int bnum, blen, i, rc=0, idx;
+
+ bnum = atoi(line);
+
+ if (bnum == -1) {
+ rhnd->reply.multibulk.len = 0; /* no data or key didn't exist */
+ return 0;
+ }
+ else if (bnum > rhnd->reply.multibulk.size) {
+ DEBUG_PRINT("available multibulk storage is low, get more memory");
+ if (cr_morebulk(&(rhnd->reply.multibulk), bnum - rhnd->reply.multibulk.size))
+ return NDPI_CREDIS_ERR_NOMEM;
+ }
+
+ for (i = 0; bnum > 0 && (rc = cr_readln(rhnd, 0, &line, NULL)) > 0; i++, bnum--) {
+ if (*(line++) != CR_BULK)
+ return NDPI_CREDIS_ERR_PROTOCOL;
+
+ blen = atoi(line);
+ if (blen == -1)
+ rhnd->reply.multibulk.idxs[i] = -1;
+ else {
+ if ((rc = cr_readln(rhnd, blen, &line, &idx)) != blen)
+ return NDPI_CREDIS_ERR_PROTOCOL;
+
+ rhnd->reply.multibulk.idxs[i] = idx;
+ }
+ }
+
+ if (bnum != 0) {
+ DEBUG_PRINT("bnum != 0, bnum=%d, rc=%d", bnum, rc);
+ return NDPI_CREDIS_ERR_PROTOCOL;
+ }
+
+ rhnd->reply.multibulk.len = i;
+ for (i = 0; i < rhnd->reply.multibulk.len; i++) {
+ if (rhnd->reply.multibulk.idxs[i] > 0)
+ rhnd->reply.multibulk.bulks[i] = rhnd->buf.data + rhnd->reply.multibulk.idxs[i];
+ else
+ rhnd->reply.multibulk.bulks[i] = NULL;
+ }
+
+ return 0;
+}
+
+static int cr_receivebulk(NDPI_REDIS rhnd, char *line)
+{
+ int blen;
+
+ blen = atoi(line);
+ if (blen == -1) {
+ rhnd->reply.bulk = NULL; /* key didn't exist */
+ return 0;
+ }
+ if (cr_readln(rhnd, blen, &line, NULL) >= 0) {
+ rhnd->reply.bulk = line;
+ return 0;
+ }
+
+ return NDPI_CREDIS_ERR_PROTOCOL;
+}
+
+static int cr_receiveinline(NDPI_REDIS rhnd, char *line)
+{
+ rhnd->reply.line = line;
+ return 0;
+}
+
+static int cr_receiveint(NDPI_REDIS rhnd, char *line)
+{
+ rhnd->reply.integer = atoi(line);
+ return 0;
+}
+
+static int cr_receiveerror(NDPI_REDIS rhnd, char *line)
+{
+ rhnd->reply.line = line;
+ return NDPI_CREDIS_ERR_PROTOCOL;
+}
+
+static int cr_receivereply(NDPI_REDIS rhnd, char recvtype)
+{
+ char *line, prefix=0;
+
+ /* reset common send/receive buffer */
+ rhnd->buf.len = 0;
+ rhnd->buf.idx = 0;
+
+ if (cr_readln(rhnd, 0, &line, NULL) > 0) {
+ prefix = *(line++);
+
+ if (prefix != recvtype && prefix != CR_ERROR)
+ return NDPI_CREDIS_ERR_PROTOCOL;
+
+ switch(prefix) {
+ case CR_ERROR:
+ return cr_receiveerror(rhnd, line);
+ case CR_INLINE:
+ return cr_receiveinline(rhnd, line);
+ case CR_INT:
+ return cr_receiveint(rhnd, line);
+ case CR_BULK:
+ return cr_receivebulk(rhnd, line);
+ case CR_MULTIBULK:
+ return cr_receivemultibulk(rhnd, line);
+ }
+ }
+
+ return NDPI_CREDIS_ERR_RECV;
+}
+
+static void cr_delete(NDPI_REDIS rhnd)
+{
+ if (rhnd->reply.multibulk.bulks != NULL)
+ free(rhnd->reply.multibulk.bulks);
+ if (rhnd->reply.multibulk.idxs != NULL)
+ free(rhnd->reply.multibulk.idxs);
+ if (rhnd->buf.data != NULL)
+ free(rhnd->buf.data);
+ if (rhnd->ip != NULL)
+ free(rhnd->ip);
+ if (rhnd != NULL)
+ free(rhnd);
+}
+
+NDPI_REDIS cr_new(void)
+{
+ NDPI_REDIS rhnd;
+
+ if ((rhnd = (cr_redis*)calloc(sizeof(cr_redis), 1)) == NULL ||
+ (rhnd->ip = (char*)malloc(32)) == NULL ||
+ (rhnd->buf.data = (char*)malloc(CR_BUFFER_SIZE)) == NULL ||
+ (rhnd->reply.multibulk.bulks = (char**)malloc(sizeof(char *)*CR_MULTIBULK_SIZE)) == NULL ||
+ (rhnd->reply.multibulk.idxs = (int*)malloc(sizeof(int)*CR_MULTIBULK_SIZE)) == NULL) {
+ cr_delete(rhnd);
+ return NULL;
+ }
+
+ rhnd->buf.size = CR_BUFFER_SIZE;
+ rhnd->reply.multibulk.size = CR_MULTIBULK_SIZE;
+
+ return rhnd;
+}
+
+/* Send message that has been prepared in message buffer prior to the call
+ * to this function. Wait and receive reply. */
+static int cr_sendandreceive(NDPI_REDIS rhnd, char recvtype)
+{
+ int rc;
+
+ DEBUG_PRINT("Sending message: len=%d, data=%s", rhnd->buf.len, rhnd->buf.data);
+
+ rc = cr_senddata(rhnd->fd, rhnd->timeout, rhnd->buf.data, rhnd->buf.len);
+
+ if (rc != rhnd->buf.len) {
+ if (rc < 0)
+ return NDPI_CREDIS_ERR_SEND;
+ return NDPI_CREDIS_ERR_TIMEOUT;
+ }
+
+ return cr_receivereply(rhnd, recvtype);
+}
+
+/* Prepare message buffer for sending using a printf()-style formatting. */
+__attribute__ ((format(printf,3,4)))
+static int cr_sendfandreceive(NDPI_REDIS rhnd, char recvtype, const char *format, ...)
+{
+ int rc;
+ va_list ap;
+ cr_buffer *buf = &(rhnd->buf);
+
+ va_start(ap, format);
+ rc = vsnprintf(buf->data, buf->size, format, ap);
+ va_end(ap);
+
+ if (rc < 0)
+ return -1;
+
+ if (rc >= buf->size) {
+ DEBUG_PRINT("truncated, get more memory and try again");
+ if (cr_moremem(buf, rc - buf->size + 1))
+ return NDPI_CREDIS_ERR_NOMEM;
+
+ va_start(ap, format);
+ rc = vsnprintf(buf->data, buf->size, format, ap);
+ va_end(ap);
+ }
+
+ buf->len = rc;
+
+ return cr_sendandreceive(rhnd, recvtype);
+}
+
+char * ndpi_credis_errorreply(NDPI_REDIS rhnd)
+{
+ return rhnd->reply.line;
+}
+
+void ndpi_credis_close(NDPI_REDIS rhnd)
+{
+ if (rhnd) {
+ if (rhnd->fd > 0)
+ close(rhnd->fd);
+#ifdef WIN32
+ WSACleanup();
+#endif
+ cr_delete(rhnd);
+ }
+}
+
+NDPI_REDIS ndpi_credis_connect(const char *host, int port, int timeout)
+{
+ int fd, rc, flags, yes = 1, use_he = 0;
+ struct sockaddr_in sa;
+ struct hostent *he;
+ NDPI_REDIS rhnd;
+
+#ifdef WIN32
+ unsigned long addr;
+ WSADATA data;
+
+ if (WSAStartup(MAKEWORD(2,2), &data) != 0) {
+ DEBUG_PRINT("Failed to init Windows Sockets DLL\n");
+ return NULL;
+ }
+#endif
+
+ if ((rhnd = cr_new()) == NULL)
+ return NULL;
+
+ if (host == NULL)
+ host = "127.0.0.1";
+ if (port == 0)
+ port = 6379;
+
+#ifdef WIN32
+ if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ||
+ setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char *)&yes, sizeof(yes)) == -1 ||
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&yes, sizeof(yes)) == -1)
+ goto error;
+#else
+ if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ||
+ setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&yes, sizeof(yes)) == -1 ||
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *)&yes, sizeof(yes)) == -1)
+ goto error;
+#endif
+
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(port);
+
+#ifdef WIN32
+ /* TODO use getaddrinfo() instead! */
+ addr = inet_addr(host);
+ if (addr == INADDR_NONE) {
+ he = gethostbyname(host);
+ use_he = 1;
+ }
+ else {
+ he = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
+ use_he = 1;
+ }
+#else
+ if (inet_aton(host, &sa.sin_addr) == 0) {
+ he = gethostbyname(host);
+ use_he = 1;
+ }
+#endif
+
+ if (use_he) {
+ if (he == NULL)
+ goto error;
+ memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr));
+ }
+
+ /* connect with user specified timeout */
+
+ flags = fcntl(fd, F_GETFL);
+ if ((rc = fcntl(fd, F_SETFL, flags | O_NONBLOCK)) < 0) {
+ DEBUG_PRINT("Setting socket non-blocking failed with: %d\n", rc);
+ }
+
+ if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != 0) {
+ if (errno != EINPROGRESS)
+ goto error;
+
+ if (cr_selectwritable(fd, timeout) > 0) {
+ int err;
+ unsigned int len = sizeof(err);
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) == -1 || err)
+ goto error;
+ }
+ else /* timeout or select error */
+ goto error;
+ }
+ /* else connect completed immediately */
+
+ strcpy(rhnd->ip, inet_ntoa(sa.sin_addr));
+ rhnd->port = port;
+ rhnd->fd = fd;
+ rhnd->timeout = timeout;
+
+ /* We can receive 2 version formats: x.yz and x.y.z, where x.yz was only used prior
+ * first 1.1.0 release(?), e.g. stable releases 1.02 and 1.2.6 */
+ if (cr_sendfandreceive(rhnd, CR_BULK, "INFO\r\n") == 0) {
+ int items = sscanf(rhnd->reply.bulk,
+ "redis_version:%d.%d.%d\r\n",
+ &(rhnd->version.major),
+ &(rhnd->version.minor),
+ &(rhnd->version.patch));
+
+ if(items == 0)
+ items = sscanf(rhnd->reply.bulk,
+ "# Server\r\nredis_version:%d.%d.%d\r\n",
+ &(rhnd->version.major),
+ &(rhnd->version.minor),
+ &(rhnd->version.patch));
+
+ if (items < 2)
+ goto error;
+ if (items == 2) {
+ rhnd->version.patch = rhnd->version.minor;
+ rhnd->version.minor = 0;
+ }
+ DEBUG_PRINT("Connected to Redis version: %d.%d.%d\n",
+ rhnd->version.major, rhnd->version.minor, rhnd->version.patch);
+ }
+
+ return rhnd;
+
+error:
+ if (fd > 0)
+ close(fd);
+ cr_delete(rhnd);
+
+ return NULL;
+}
+
+void ndpi_credis_settimeout(NDPI_REDIS rhnd, int timeout)
+{
+ rhnd->timeout = timeout;
+}
+
+int ndpi_credis_set(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+#ifdef ORIGINAL
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SET %s %zu\r\n%zs\r\n",
+ key, strlen(val), val);
+#else
+ /* L.Deri */
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SET %s %s\r\n%zu\r\n",
+ key, val, strlen(val));
+#endif
+}
+
+int ndpi_credis_get(NDPI_REDIS rhnd, const char *key, char **val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "GET %s\r\n", key);
+
+ if (rc == 0 && (*val = rhnd->reply.bulk) == NULL)
+ return -1;
+
+ return rc;
+}
+
+int ndpi_credis_getset(NDPI_REDIS rhnd, const char *key, const char *set_val, char **get_val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "GETSET %s %zu\r\n%s\r\n",
+ key, strlen(set_val), set_val);
+
+ if (rc == 0 && (*get_val = rhnd->reply.bulk) == NULL)
+ return -1;
+
+ return rc;
+}
+
+int ndpi_credis_ping(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "PING\r\n");
+}
+
+int ndpi_credis_auth(NDPI_REDIS rhnd, const char *password)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "AUTH %s\r\n", password);
+}
+
+static int cr_multikeybulkcommand(NDPI_REDIS rhnd, const char *cmd, int keyc,
+ const char **keyv, char ***valv)
+{
+ cr_buffer *buf = &(rhnd->buf);
+ int rc;
+
+ buf->len = 0;
+ if ((rc = cr_appendstr(buf, cmd, 0)) != 0)
+ return rc;
+ if ((rc = cr_appendstrarray(buf, keyc, keyv, 1)) != 0)
+ return rc;
+ if ((rc = cr_sendandreceive(rhnd, CR_MULTIBULK)) == 0) {
+ *valv = rhnd->reply.multibulk.bulks;
+ rc = rhnd->reply.multibulk.len;
+ }
+
+ return rc;
+}
+
+static int cr_multikeystorecommand(NDPI_REDIS rhnd, const char *cmd, const char *destkey,
+ int keyc, const char **keyv)
+{
+ cr_buffer *buf = &(rhnd->buf);
+ int rc;
+
+ buf->len = 0;
+ if ((rc = cr_appendstr(buf, cmd, 0)) != 0)
+ return rc;
+ if ((rc = cr_appendstr(buf, destkey, 1)) != 0)
+ return rc;
+ if ((rc = cr_appendstrarray(buf, keyc, keyv, 1)) != 0)
+ return rc;
+
+ return cr_sendandreceive(rhnd, CR_INLINE);
+}
+
+int ndpi_credis_mget(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***valv)
+{
+ return cr_multikeybulkcommand(rhnd, "MGET", keyc, keyv, valv);
+}
+
+int ndpi_credis_setnx(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "SETNX %s %zu\r\n%s\r\n",
+ key, strlen(val), val);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+static int cr_incr(NDPI_REDIS rhnd, int incr, int decr, const char *key, int *new_val)
+{
+ int rc = 0;
+
+ if (incr == 1 || decr == 1)
+ rc = cr_sendfandreceive(rhnd, CR_INT, "%s %s\r\n",
+ incr>0?"INCR":"DECR", key);
+ else if (incr > 1 || decr > 1)
+ rc = cr_sendfandreceive(rhnd, CR_INT, "%s %s %d\r\n",
+ incr>0?"INCRBY":"DECRBY", key, incr>0?incr:decr);
+
+ if (rc == 0 && new_val != NULL)
+ *new_val = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_incr(NDPI_REDIS rhnd, const char *key, int *new_val)
+{
+ return cr_incr(rhnd, 1, 0, key, new_val);
+}
+
+int ndpi_credis_decr(NDPI_REDIS rhnd, const char *key, int *new_val)
+{
+ return cr_incr(rhnd, 0, 1, key, new_val);
+}
+
+int ndpi_credis_incrby(NDPI_REDIS rhnd, const char *key, int incr_val, int *new_val)
+{
+ return cr_incr(rhnd, incr_val, 0, key, new_val);
+}
+
+int ndpi_credis_decrby(NDPI_REDIS rhnd, const char *key, int decr_val, int *new_val)
+{
+ return cr_incr(rhnd, 0, decr_val, key, new_val);
+}
+
+int ndpi_credis_append(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "APPEND %s %zu\r\n%s\r\n",
+ key, strlen(val), val);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_substr(NDPI_REDIS rhnd, const char *key, int start, int end, char **substr)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "SUBSTR %s %d %d\r\n",
+ key, start, end);
+
+ if (rc == 0 && substr)
+ *substr = rhnd->reply.bulk;
+
+ return rc;
+}
+
+int ndpi_credis_exists(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "EXISTS %s\r\n", key);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_del(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "DEL %s\r\n", key);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_type(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INLINE, "TYPE %s\r\n", key);
+
+ if (rc == 0) {
+ char *t = rhnd->reply.line;
+ if (!strcmp("string", t))
+ rc = NDPI_CREDIS_TYPE_STRING;
+ else if (!strcmp("list", t))
+ rc = NDPI_CREDIS_TYPE_LIST;
+ else if (!strcmp("set", t))
+ rc = NDPI_CREDIS_TYPE_SET;
+ else
+ rc = NDPI_CREDIS_TYPE_NONE;
+ }
+
+ return rc;
+}
+
+int ndpi_credis_keys(NDPI_REDIS rhnd, const char *pattern, char ***keyv)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "KEYS %s\r\n", pattern);
+
+ if (rc == 0) {
+ /* server returns keys as space-separated strings, use multi-bulk
+ * storage to store keys */
+ if ((rc = cr_splitstrtromultibulk(rhnd, rhnd->reply.bulk, ' ')) == 0) {
+ *keyv = rhnd->reply.multibulk.bulks;
+ rc = rhnd->reply.multibulk.len;
+ }
+ }
+
+ return rc;
+}
+
+int ndpi_credis_randomkey(NDPI_REDIS rhnd, char **key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INLINE, "RANDOMKEY\r\n");
+
+ if (rc == 0 && key)
+ *key = rhnd->reply.line;
+
+ return rc;
+}
+
+int ndpi_credis_rename(NDPI_REDIS rhnd, const char *key, const char *new_key_name)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "RENAME %s %s\r\n",
+ key, new_key_name);
+}
+
+int ndpi_credis_renamenx(NDPI_REDIS rhnd, const char *key, const char *new_key_name)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "RENAMENX %s %s\r\n",
+ key, new_key_name);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_dbsize(NDPI_REDIS rhnd)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "DBSIZE\r\n");
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_expire(NDPI_REDIS rhnd, const char *key, int secs)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "EXPIRE %s %d\r\n", key, secs);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_ttl(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "TTL %s\r\n", key);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+static int cr_push(NDPI_REDIS rhnd, int left, const char *key, const char *val)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "%s %s %s\r\n%zu\r\n",
+ left==1?"LPUSH":"RPUSH", key, val, strlen(val));
+}
+
+static int cr_rpushx(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "%s %s %s\r\n%zu\r\n",
+ "RPUSHX", key, val, strlen(val));
+}
+
+int ndpi_credis_rpush(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ return cr_push(rhnd, 0, key, val);
+}
+
+/* ntop */
+int ndpi_credis_rpushx(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ return cr_rpushx(rhnd, key, val);
+}
+
+int ndpi_credis_lpush(NDPI_REDIS rhnd, const char *key, const char *val)
+{
+ return cr_push(rhnd, 1, key, val);
+}
+
+int ndpi_credis_llen(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "LLEN %s\r\n", key);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_lrange(NDPI_REDIS rhnd, const char *key, int start, int end, char ***valv)
+{
+ int rc;
+
+ if ((rc = cr_sendfandreceive(rhnd, CR_MULTIBULK, "LRANGE %s %d %d\r\n",
+ key, start, end)) == 0) {
+ *valv = rhnd->reply.multibulk.bulks;
+ rc = rhnd->reply.multibulk.len;
+ }
+
+ return rc;
+}
+
+int ndpi_credis_ltrim(NDPI_REDIS rhnd, const char *key, int start, int end)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "LTRIM %s %d %d\r\n",
+ key, start, end);
+}
+
+int ndpi_credis_lindex(NDPI_REDIS rhnd, const char *key, int index, char **val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "LINDEX %s %d\r\n", key, index);
+
+ if (rc == 0 && (*val = rhnd->reply.bulk) == NULL)
+ return -1;
+
+ return rc;
+}
+
+int ndpi_credis_lset(NDPI_REDIS rhnd, const char *key, int index, const char *val)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "LSET %s %d %zu\r\n%s\r\n",
+ key, index, strlen(val), val);
+}
+
+int ndpi_credis_lrem(NDPI_REDIS rhnd, const char *key, int count, const char *val)
+{
+ return cr_sendfandreceive(rhnd, CR_INT, "LREM %s %d %zu\r\n%s\r\n",
+ key, count, strlen(val), val);
+}
+
+static int cr_pop(NDPI_REDIS rhnd, int left, const char *key, char **val)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "%s %s\r\n",
+ left==1?"LPOP":"RPOP", key);
+
+ if (rc == 0 && (*val = rhnd->reply.bulk) == NULL)
+ return -1;
+
+ return rc;
+}
+
+int ndpi_credis_lpop(NDPI_REDIS rhnd, const char *key, char **val)
+{
+ return cr_pop(rhnd, 1, key, val);
+}
+
+int ndpi_credis_rpop(NDPI_REDIS rhnd, const char *key, char **val)
+{
+ return cr_pop(rhnd, 0, key, val);
+}
+
+int ndpi_credis_select(NDPI_REDIS rhnd, int index)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SELECT %d\r\n", index);
+}
+
+int ndpi_credis_move(NDPI_REDIS rhnd, const char *key, int index)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "MOVE %s %d\r\n", key, index);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_flushdb(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "FLUSHDB\r\n");
+}
+
+int ndpi_credis_flushall(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "FLUSHALL\r\n");
+}
+
+int ndpi_credis_sort(NDPI_REDIS rhnd, const char *query, char ***elementv)
+{
+ int rc;
+
+ if ((rc = cr_sendfandreceive(rhnd, CR_MULTIBULK, "SORT %s\r\n", query)) == 0) {
+ *elementv = rhnd->reply.multibulk.bulks;
+ rc = rhnd->reply.multibulk.len;
+ }
+
+ return rc;
+}
+
+int ndpi_credis_save(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SAVE\r\n");
+}
+
+int ndpi_credis_bgsave(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "BGSAVE\r\n");
+}
+
+int ndpi_credis_lastsave(NDPI_REDIS rhnd)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "LASTSAVE\r\n");
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_shutdown(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SHUTDOWN\r\n");
+}
+
+int ndpi_credis_bgrewriteaof(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "BGREWRITEAOF\r\n");
+}
+
+/* Parse Redis `info' string for a particular `fld', storing its value to
+ * `storage' according to `format'.
+ */
+void cr_parseinfo(const char *info, const char *fld, const char *format, void *storage)
+{
+ if(info) {
+ char *str = (char*)strstr(info, (char*)fld);
+ if (str) {
+ str += strlen(fld) + 1; /* also skip the ':' */
+ sscanf(str, format, storage);
+ }
+ }
+}
+
+int ndpi_credis_info(NDPI_REDIS rhnd, NDPI_REDIS_INFO *info)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "INFO\r\n");
+
+ if (rc == 0) {
+ char role;
+ memset(info, 0, sizeof(NDPI_REDIS_INFO));
+ cr_parseinfo(rhnd->reply.bulk, "redis_version", "%"CR_VERSION_STRING_SIZE_STR"s\r\n", &(info->redis_version));
+ cr_parseinfo(rhnd->reply.bulk, "arch_bits", "%d", &(info->arch_bits));
+ cr_parseinfo(rhnd->reply.bulk, "multiplexing_api", "%"CR_MULTIPLEXING_API_SIZE_STR"s\r\n", &(info->multiplexing_api));
+ cr_parseinfo(rhnd->reply.bulk, "process_id", "%ld", &(info->process_id));
+ cr_parseinfo(rhnd->reply.bulk, "uptime_in_seconds", "%ld", &(info->uptime_in_seconds));
+ cr_parseinfo(rhnd->reply.bulk, "uptime_in_days", "%ld", &(info->uptime_in_days));
+ cr_parseinfo(rhnd->reply.bulk, "connected_clients", "%d", &(info->connected_clients));
+ cr_parseinfo(rhnd->reply.bulk, "connected_slaves", "%d", &(info->connected_slaves));
+ cr_parseinfo(rhnd->reply.bulk, "blocked_clients", "%d", &(info->blocked_clients));
+ cr_parseinfo(rhnd->reply.bulk, "used_memory", "%zu", &(info->used_memory));
+ cr_parseinfo(rhnd->reply.bulk, "used_memory_human", "%"CR_USED_MEMORY_HUMAN_SIZE_STR"s", &(info->used_memory_human));
+ cr_parseinfo(rhnd->reply.bulk, "changes_since_last_save", "%lld", &(info->changes_since_last_save));
+ cr_parseinfo(rhnd->reply.bulk, "bgsave_in_progress", "%d", &(info->bgsave_in_progress));
+ cr_parseinfo(rhnd->reply.bulk, "last_save_time", "%ld", &(info->last_save_time));
+ cr_parseinfo(rhnd->reply.bulk, "bgrewriteaof_in_progress", "%d", &(info->bgrewriteaof_in_progress));
+ cr_parseinfo(rhnd->reply.bulk, "total_connections_received", "%lld", &(info->total_connections_received));
+ cr_parseinfo(rhnd->reply.bulk, "total_commands_processed", "%lld", &(info->total_commands_processed));
+ cr_parseinfo(rhnd->reply.bulk, "expired_keys", "%lld", &(info->expired_keys));
+ cr_parseinfo(rhnd->reply.bulk, "hash_max_zipmap_entries", "%zu", &(info->hash_max_zipmap_entries));
+ cr_parseinfo(rhnd->reply.bulk, "hash_max_zipmap_value", "%zu", &(info->hash_max_zipmap_value));
+ cr_parseinfo(rhnd->reply.bulk, "pubsub_channels", "%ld", &(info->pubsub_channels));
+ cr_parseinfo(rhnd->reply.bulk, "pubsub_patterns", "%u", &(info->pubsub_patterns));
+ cr_parseinfo(rhnd->reply.bulk, "vm_enabled", "%d", &(info->vm_enabled));
+ cr_parseinfo(rhnd->reply.bulk, "role", "%c", &role);
+
+ info->role = ((role=='m')?NDPI_CREDIS_SERVER_MASTER:NDPI_CREDIS_SERVER_SLAVE);
+ }
+
+ return rc;
+}
+
+int ndpi_credis_monitor(NDPI_REDIS rhnd)
+{
+ return cr_sendfandreceive(rhnd, CR_INLINE, "MONITOR\r\n");
+}
+
+int ndpi_credis_slaveof(NDPI_REDIS rhnd, const char *host, int port)
+{
+ if (host == NULL || port == 0)
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SLAVEOF no one\r\n");
+ else
+ return cr_sendfandreceive(rhnd, CR_INLINE, "SLAVEOF %s %d\r\n", host, port);
+}
+
+static int cr_setaddrem(NDPI_REDIS rhnd, const char *cmd, const char *key, const char *member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "%s %s %zu\r\n%s\r\n",
+ cmd, key, strlen(member), member);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_sadd(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ return cr_setaddrem(rhnd, "SADD", key, member);
+}
+
+int ndpi_credis_srem(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ return cr_setaddrem(rhnd, "SREM", key, member);
+}
+
+int ndpi_credis_spop(NDPI_REDIS rhnd, const char *key, char **member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "SPOP %s\r\n", key);
+
+ if (rc == 0 && (*member = rhnd->reply.bulk) == NULL)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_smove(NDPI_REDIS rhnd, const char *sourcekey, const char *destkey,
+ const char *member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "SMOVE %s %s %s\r\n",
+ sourcekey, destkey, member);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_scard(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "SCARD %s\r\n", key);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_sinter(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members)
+{
+ return cr_multikeybulkcommand(rhnd, "SINTER", keyc, keyv, members);
+}
+
+int ndpi_credis_sunion(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members)
+{
+ return cr_multikeybulkcommand(rhnd, "SUNION", keyc, keyv, members);
+}
+
+int ndpi_credis_sdiff(NDPI_REDIS rhnd, int keyc, const char **keyv, char ***members)
+{
+ return cr_multikeybulkcommand(rhnd, "SDIFF", keyc, keyv, members);
+}
+
+int ndpi_credis_sinterstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv)
+{
+ return cr_multikeystorecommand(rhnd, "SINTERSTORE", destkey, keyc, keyv);
+}
+
+int ndpi_credis_sunionstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv)
+{
+ return cr_multikeystorecommand(rhnd, "SUNIONSTORE", destkey, keyc, keyv);
+}
+
+int ndpi_credis_sdiffstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv)
+{
+ return cr_multikeystorecommand(rhnd, "SDIFFSTORE", destkey, keyc, keyv);
+}
+
+int ndpi_credis_sismember(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ return cr_setaddrem(rhnd, "SISMEMBER", key, member);
+}
+
+int ndpi_credis_smembers(NDPI_REDIS rhnd, const char *key, char ***members)
+{
+ return cr_multikeybulkcommand(rhnd, "SMEMBERS", 1, &key, members);
+}
+
+int ndpi_credis_zadd(NDPI_REDIS rhnd, const char *key, double score, const char *member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "ZADD %s %f %zu\r\n%s\r\n",
+ key, score, strlen(member), member);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+int ndpi_credis_zrem(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "ZREM %s %zu\r\n%s\r\n",
+ key, strlen(member), member);
+
+ if (rc == 0 && rhnd->reply.integer == 0)
+ rc = -1;
+
+ return rc;
+}
+
+/* TODO what does Redis return if member is not member of set? */
+int ndpi_credis_zincrby(NDPI_REDIS rhnd, const char *key, double incr_score, const char *member, double *new_score)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "ZINCRBY %s %f %zu\r\n%s\r\n",
+ key, incr_score, strlen(member), member);
+
+ if (rc == 0 && new_score)
+ *new_score = strtod(rhnd->reply.bulk, NULL);
+
+ return rc;
+}
+
+/* TODO what does Redis return if member is not member of set? */
+static int cr_zrank(NDPI_REDIS rhnd, int reverse, const char *key, const char *member)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "%s %s %zu\r\n%s\r\n",
+ reverse==1?"ZREVRANK":"ZRANK", key, strlen(member), member);
+
+ if (rc == 0)
+ rc = atoi(rhnd->reply.bulk);
+
+ return rc;
+}
+
+int ndpi_credis_zrank(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ return cr_zrank(rhnd, 0, key, member);
+}
+
+int ndpi_credis_zrevrank(NDPI_REDIS rhnd, const char *key, const char *member)
+{
+ return cr_zrank(rhnd, 1, key, member);
+}
+
+int cr_zrange(NDPI_REDIS rhnd, int reverse, const char *key, int start, int end, char ***elementv)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_MULTIBULK, "%s %s %d %d\r\n",
+ reverse==1?"ZREVRANGE":"ZRANGE", key, start, end);
+
+ if (rc == 0) {
+ *elementv = rhnd->reply.multibulk.bulks;
+ rc = rhnd->reply.multibulk.len;
+ }
+
+ return rc;
+}
+
+int ndpi_credis_zrange(NDPI_REDIS rhnd, const char *key, int start, int end, char ***elementv)
+{
+ return cr_zrange(rhnd, 0, key, start, end, elementv);
+}
+
+int ndpi_credis_zrevrange(NDPI_REDIS rhnd, const char *key, int start, int end, char ***elementv)
+{
+ return cr_zrange(rhnd, 1, key, start, end, elementv);
+}
+
+int ndpi_credis_zcard(NDPI_REDIS rhnd, const char *key)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "ZCARD %s\r\n", key);
+
+ if (rc == 0) {
+ if (rhnd->reply.integer == 0)
+ rc = -1;
+ else
+ rc = rhnd->reply.integer;
+ }
+
+ return rc;
+}
+
+int ndpi_credis_zscore(NDPI_REDIS rhnd, const char *key, const char *member, double *score)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_BULK, "ZSCORE %s %zu\r\n%s\r\n",
+ key, strlen(member), member);
+
+ if (rc == 0) {
+ if (!rhnd->reply.bulk)
+ rc = -1;
+ else if (score)
+ *score = strtod(rhnd->reply.bulk, NULL);
+ }
+
+ return rc;
+}
+
+int ndpi_credis_zremrangebyscore(NDPI_REDIS rhnd, const char *key, double min, double max)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "ZREMRANGEBYSCORE %s %f %f\r\n",
+ key, min, max);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_zremrangebyrank(NDPI_REDIS rhnd, const char *key, int start, int end)
+{
+ int rc = cr_sendfandreceive(rhnd, CR_INT, "ZREMRANGEBYRANK %s %d %d\r\n",
+ key, start, end);
+
+ if (rc == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+/* TODO add writev() support instead and push strings to send onto a vector of
+ * strings to send instead... */
+static int cr_zstore(NDPI_REDIS rhnd, int inter, const char *destkey, int keyc, const char **keyv,
+ const int *weightv, NDPI_REDIS_AGGREGATE aggregate)
+{
+ cr_buffer *buf = &(rhnd->buf);
+ int rc, i;
+
+ buf->len = 0;
+
+ if ((rc = cr_appendstrf(buf, "%s %s %d ", inter?"ZINTERSTORE":"ZUNIONSTORE", destkey, keyc)) != 0)
+ return rc;
+ if ((rc = cr_appendstrarray(buf, keyc, keyv, 0)) != 0)
+ return rc;
+ if (weightv != NULL)
+ for (i = 0; i < keyc; i++)
+ if ((rc = cr_appendstrf(buf, " %d", weightv[i])) != 0)
+ return rc;
+
+ switch (aggregate) {
+ case NDPI_SUM:
+ rc = cr_appendstr(buf, "AGGREGATE SUM", 0);
+ break;
+ case NDPI_MIN:
+ rc = cr_appendstr(buf, "AGGREGATE MIN", 0);
+ break;
+ case NDPI_MAX:
+ rc = cr_appendstr(buf, "AGGREGATE MAX", 0);
+ break;
+ case NDPI_NONE:
+ ; /* avoiding compiler warning */
+ }
+ if (rc != 0)
+ return rc;
+
+ if ((rc = cr_appendstr(buf, "\r\n", 0)) != 0)
+ return rc;
+
+ if ((rc = cr_sendandreceive(rhnd, CR_INT)) == 0)
+ rc = rhnd->reply.integer;
+
+ return rc;
+}
+
+int ndpi_credis_zinterstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv,
+ const int *weightv, NDPI_REDIS_AGGREGATE aggregate)
+{
+ return cr_zstore(rhnd, 1, destkey, keyc, keyv, weightv, aggregate);
+}
+
+int ndpi_credis_zunionstore(NDPI_REDIS rhnd, const char *destkey, int keyc, const char **keyv,
+ const int *weightv, NDPI_REDIS_AGGREGATE aggregate)
+{
+ return cr_zstore(rhnd, 0, destkey, keyc, keyv, weightv, aggregate);
+}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/ndpi_main.c
^
|
@@ -34,11 +34,20 @@
#include "ahocorasick.h"
-#include <time.h>
+#undef DEBUG
#ifdef __KERNEL__
+#include <linux/version.h>
#define printf printk
+#else
+#include <time.h>
+#ifndef WIN32
+#include <unistd.h>
#endif
+#endif
+
+// #include "ndpi_credis.c"
+#include "ndpi_cache.c"
typedef struct {
char *string_to_match, *proto_name;
@@ -50,8 +59,116 @@
#define strtok_r(a,b,c) strtok(a,b)
#endif
-/* ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/src/lib/libc/stdlib/tsearch.c */
+#ifdef __KERNEL__
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
+static inline char _tolower(const char c)
+{
+ return c | 0x20;
+}
+
+static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+ unsigned long long acc;
+ int ok;
+
+ if (base == 0) {
+ if (s[0] == '0') {
+ if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
+ base = 16;
+ else
+ base = 8;
+ } else
+ base = 10;
+ }
+ if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
+ s += 2;
+
+ acc = 0;
+ ok = 0;
+ while (*s) {
+ unsigned int val;
+
+ if ('0' <= *s && *s <= '9')
+ val = *s - '0';
+ else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
+ val = _tolower(*s) - 'a' + 10;
+ else if (*s == '\n') {
+ if (*(s + 1) == '\0')
+ break;
+ else
+ return -EINVAL;
+ } else
+ return -EINVAL;
+
+ if (val >= base)
+ return -EINVAL;
+ if (acc > div_u64(ULLONG_MAX - val, base))
+ return -ERANGE;
+ acc = acc * base + val;
+ ok = 1;
+
+ s++;
+ }
+ if (!ok)
+ return -EINVAL;
+ *res = acc;
+ return 0;
+}
+int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
+{
+ if (s[0] == '+')
+ s++;
+ return _kstrtoull(s, base, res);
+}
+int kstrtoll(const char *s, unsigned int base, long long *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ if (s[0] == '-') {
+ rv = _kstrtoull(s + 1, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if ((long long)(-tmp) >= 0)
+ return -ERANGE;
+ *res = -tmp;
+ } else {
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if ((long long)tmp < 0)
+ return -ERANGE;
+ *res = tmp;
+ }
+ return 0;
+}
+int kstrtoint(const char *s, unsigned int base, int *res)
+{
+ long long tmp;
+ int rv;
+
+ rv = kstrtoll(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (long long)(int)tmp)
+ return -ERANGE;
+ *res = tmp;
+ return 0;
+}
+#endif
+
+int atoi(const char *str) {
+ int rc;
+
+ if(kstrtoint(str, 0, &rc) == 0 /* Success */)
+ return(rc);
+ else
+ return(0);
+}
+#endif
+
+/* ftp://ftp.cc.uoc.gr/mirrors/OpenBSD/src/lib/libc/stdlib/tsearch.c */
/* find or insert datum into search tree */
void *
ndpi_tsearch(const void *vkey, void **vrootp,
@@ -198,6 +315,14 @@
/* ****************************************** */
+
+
+
+
+
+
+/* ****************************************** */
+
#ifdef WIN32
/* http://opensource.apple.com/source/Libc/Libc-186/string.subproj/strcasecmp.c */
@@ -282,6 +407,8 @@
/* Forward */
static void addDefaultPort(ndpi_port_range *range,
ndpi_proto_defaults_t *def, ndpi_default_ports_tree_node_t **root);
+static int removeDefaultPort(ndpi_port_range *range,
+ ndpi_proto_defaults_t *def, ndpi_default_ports_tree_node_t **root);
/* ****************************************** */
@@ -289,6 +416,18 @@
/* ****************************************** */
+void* ndpi_calloc(unsigned long count, unsigned long size) {
+ unsigned long len = count*size;
+ void *p = ndpi_malloc(len);
+
+ if(p)
+ memset(p, 0, len);
+
+ return(p);
+}
+
+/* ****************************************** */
+
void ndpi_free(void *ptr) { _ndpi_free(ptr); }
/* ****************************************** */
@@ -340,6 +479,18 @@
/* ******************************************************************** */
+void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* redis_host, u_int redis_port) {
+#if 0
+ if(((ndpi_mod->redis = ndpi_credis_connect(redis_host, redis_port, 10000)) == NULL)
+ || (ndpi_credis_ping(ndpi_mod->redis) != 0)) {
+ printf("Redis Connection error: %s:%d", redis_host, redis_port);
+ ndpi_mod->redis = NULL;
+ }
+#endif
+}
+
+/* ******************************************************************** */
+
ndpi_port_range* ndpi_build_default_ports_range(ndpi_port_range *ports,
u_int16_t portA_low, u_int16_t portA_high,
u_int16_t portB_low, u_int16_t portB_high,
@@ -378,9 +529,9 @@
/* ******************************************************************** */
-static void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
- u_int16_t protoId, char *protoName,
- ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts) {
+void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
+ u_int16_t protoId, char *protoName,
+ ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts) {
char *name = ndpi_strdup(protoName);
int j;
@@ -462,6 +613,35 @@
/* ****************************************************** */
+/*
+ NOTE
+
+ This function must be called with a semaphore set, this in order to avoid
+ changing the datastrutures while using them
+*/
+static int removeDefaultPort(ndpi_port_range *range,
+ ndpi_proto_defaults_t *def,
+ ndpi_default_ports_tree_node_t **root) {
+ ndpi_default_ports_tree_node_t node;
+ ndpi_default_ports_tree_node_t *ret;
+ u_int16_t port;
+
+ for(port=range->port_low; port<=range->port_high; port++) {
+ node.proto = def, node.default_port = port;
+ ret = *(ndpi_default_ports_tree_node_t**)ndpi_tdelete(&node, (void*)root,
+ ndpi_default_ports_tree_node_t_cmp); /* Add it to the tree */
+
+ if(ret != NULL) {
+ ndpi_free((ndpi_default_ports_tree_node_t*)ret);
+ return(0);
+ }
+ }
+
+ return(-1);
+}
+
+/* ****************************************************** */
+
static int ndpi_add_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
char *attr, char *value, int protocol_id) {
AC_PATTERN_t ac_pattern;
@@ -499,32 +679,52 @@
return(0);
}
+/* ****************************************************** */
+
+/*
+ NOTE
+
+ This function must be called with a semaphore set, this in order to avoid
+ changing the datastrutures while using them
+*/
+static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
+ char *attr, char *value, int protocol_id) {
+
+ printf("[NDPI] Missing implementation of %s()\n", __FUNCTION__);
+ return(-1);
+}
+
/* ******************************************************************** */
+ndpi_protocol_match host_match[] = {
+ { ".twitter.com", "Twitter", NDPI_PROTOCOL_TWITTER },
+ { ".twttr.com", "Twitter", NDPI_PROTOCOL_TWITTER },
+ { ".netflix.com", "NetFlix", NDPI_PROTOCOL_NETFLIX },
+ { ".facebook.com", "FaceBook", NDPI_PROTOCOL_FACEBOOK },
+ { ".fbcdn.net", "FaceBook", NDPI_PROTOCOL_FACEBOOK },
+ { "fbcdn-", "FaceBook", NDPI_PROTOCOL_FACEBOOK }, /* fbcdn-video-a-akamaihd.net */
+ { ".dropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX },
+ { ".gmail.", "GoogleGmail", NDPI_PROTOCOL_GMAIL },
+ { "maps.google.com", "GoogleMaps", NDPI_PROTOCOL_GOOGLE_MAPS },
+ { "maps.gstatic.com", "GoogleMaps", NDPI_PROTOCOL_GOOGLE_MAPS },
+ { ".gstatic.com", "Google", NDPI_PROTOCOL_GOOGLE },
+ { ".google.com", "Google", NDPI_PROTOCOL_GOOGLE },
+ { ".youtube.", "YouTube", NDPI_PROTOCOL_YOUTUBE },
+ { "itunes.apple.com", "AppleiTunes", NDPI_PROTOCOL_APPLE_ITUNES },
+ { ".apple.com", "Apple", NDPI_PROTOCOL_APPLE },
+ { ".mzstatic.com", "Apple", NDPI_PROTOCOL_APPLE },
+ { ".icloud.com", "AppleiCloud", NDPI_PROTOCOL_APPLE_ICLOUD },
+ { ".viber.com", "Viber", NDPI_PROTOCOL_VIBER },
+ { ".last.fm", "LastFM", NDPI_PROTOCOL_LASTFM },
+ { ".grooveshark.com", "GrooveShark", NDPI_PROTOCOL_GROOVESHARK },
+ { ".tuenti.com", "Tuenti", NDPI_PROTOCOL_TUENTI },
+ { ".skype.com", "Skype", NDPI_PROTOCOL_SKYPE },
+ { ".skypeassets.com", "Skype", NDPI_PROTOCOL_SKYPE },
+ { ".yahoo.", "Yahoo", NDPI_PROTOCOL_YAHOO },
+ { NULL, 0 }
+};
+
static void init_string_based_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
- ndpi_protocol_match host_match[] = {
- { ".twitter.com", "Twitter", NDPI_PROTOCOL_TWITTER },
- { ".twttr.com", "Twitter", NDPI_PROTOCOL_TWITTER },
- { ".netflix.com", "NetFlix", NDPI_PROTOCOL_NETFLIX },
- { ".facebook.com", "FaceBook", NDPI_PROTOCOL_FACEBOOK },
- { ".fbcdn.net", "FaceBook", NDPI_PROTOCOL_FACEBOOK },
- { ".dropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX },
- { ".gmail.", "GoogleGmail", NDPI_PROTOCOL_GMAIL },
- { "maps.google.com", "GoogleMaps", NDPI_PROTOCOL_GOOGLE_MAPS },
- { "maps.gstatic.com", "GoogleMaps", NDPI_PROTOCOL_GOOGLE_MAPS },
- { ".gstatic.com", "Google", NDPI_PROTOCOL_GOOGLE },
- { ".google.com", "Google", NDPI_PROTOCOL_GOOGLE },
- { ".youtube.", "YouTube", NDPI_PROTOCOL_YOUTUBE },
- { "itunes.apple.com", "AppleiTunes", NDPI_PROTOCOL_APPLE_ITUNES },
- { ".apple.com", "Apple", NDPI_PROTOCOL_APPLE },
- { ".mzstatic.com", "Apple", NDPI_PROTOCOL_APPLE },
- { ".icloud.com", "AppleiCloud", NDPI_PROTOCOL_APPLE_ICLOUD },
- { ".viber.com", "Viber", NDPI_PROTOCOL_VIBER },
- { ".last.fm", "LastFM", NDPI_PROTOCOL_LASTFM },
- { ".grooveshark.com", "GrooveShark", NDPI_PROTOCOL_GROOVESHARK },
- { ".tuenti.com", "Tuenti", NDPI_PROTOCOL_TUENTI },
- { NULL, 0 }
- };
int i;
for(i=0; host_match[i].string_to_match != NULL; i++) {
@@ -555,14 +755,23 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FTP, "FTP",
ndpi_build_default_ports(ports_a, 20, 21, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_POP, "Mail_POP",
- ndpi_build_default_ports(ports_a, 110, 995, 0, 0, 0) /* TCP */,
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_POP, "POP",
+ ndpi_build_default_ports(ports_a, 110, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_POPS, "POPS",
+ ndpi_build_default_ports(ports_a, 995, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_SMTP, "SMTP",
+ ndpi_build_default_ports(ports_a, 25, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_SMTP, "Mail_SMTP",
- ndpi_build_default_ports(ports_a, 25, 465, 0, 0, 0) /* TCP */,
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_SMTPS, "SMTPS",
+ ndpi_build_default_ports(ports_a, 465, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_IMAP, "Mail_IMAP",
- ndpi_build_default_ports(ports_a, 143, 993, 0, 0, 0) /* TCP */,
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_IMAP, "IMAP",
+ ndpi_build_default_ports(ports_a, 143, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_MAIL_IMAPS, "IMAPS",
+ ndpi_build_default_ports(ports_a, 993, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_DNS, "DNS",
ndpi_build_default_ports(ports_a, 53, 0, 0, 0, 0) /* TCP */,
@@ -618,9 +827,6 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, "Direct_Download_Link",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_I23V5, "I23V5",
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
- ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_APPLEJUICE, "AppleJuice",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
@@ -636,9 +842,6 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_VMWARE, "VMware",
ndpi_build_default_ports(ports_a, 903, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 902, 903, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_PANDO, "Pando",
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
- ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FILETOPIA, "Filetopia",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
@@ -702,9 +905,6 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_RTSP, "RTSP",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 554, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FEIDIAN, "Feidian",
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
- ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ICECAST, "IceCast",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
@@ -741,7 +941,7 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_SOULSEEK, "Soulseek",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_GADUGADU, "Gadugadu",
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_SSL_NO_CERT, "SSL_No_Cert",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_IRC, "IRC",
@@ -788,7 +988,7 @@
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_IPSEC, "IPsec",
ndpi_build_default_ports(ports_a, 500, 0, 0, 0, 0) /* TCP */,
- ndpi_build_default_ports(ports_b, 500, 0, 0, 0, 0) /* UDP */);
+ ndpi_build_default_ports(ports_b, 500, 4500, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_GRE, "GRE",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
@@ -817,7 +1017,7 @@
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_VNC, "VNC",
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_a, 5900, 5901, 5800, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_PCANYWHERE, "PcAnywhere",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
@@ -1028,10 +1228,13 @@
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_UBUNTUONE, "UbuntuONE",
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
+ ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_WHOIS_DAS, "Whois-DAS",
+ ndpi_build_default_ports(ports_a, 43, 4343, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
init_string_based_protocols(ndpi_mod);
- for(i=0; i<ndpi_mod->ndpi_num_supported_protocols; i++) {
+ for(i=0; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++) {
if(ndpi_mod->proto_defaults[i].protoName == NULL) {
printf("[NDPI] %s(missing protoId=%d) INTERNAL ERROR: not all protocols have been initialized\n", __FUNCTION__, i);
}
@@ -1070,6 +1273,9 @@
}
memset(ndpi_str, 0, sizeof(struct ndpi_detection_module_struct));
+#ifdef HAVE_REDIS
+ ndpi_str->redis = NULL;
+#endif
NDPI_BITMASK_RESET(ndpi_str->detection_bitmask);
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
@@ -1082,7 +1288,6 @@
ndpi_str->directconnect_connection_ip_tick_timeout =
NDPI_DIRECTCONNECT_CONNECTION_IP_TICK_TIMEOUT * ticks_per_second;
- ndpi_str->gadugadu_peer_connection_timeout = NDPI_GADGADU_PEER_CONNECTION_TIMEOUT * ticks_per_second;
ndpi_str->edonkey_upper_ports_only = NDPI_EDONKEY_UPPER_PORTS_ONLY;
ndpi_str->ftp_connection_timeout = NDPI_FTP_CONNECTION_TIMEOUT * ticks_per_second;
@@ -1108,6 +1313,15 @@
ndpi_str->ndpi_num_custom_protocols = 0;
ndpi_str->ac_automa = ac_automata_init(ac_match_handler);
+
+ ndpi_init_lru_cache(&ndpi_str->skypeCache, 4096);
+
+#ifndef __KERNEL__
+ pthread_mutex_init(&ndpi_str->skypeCacheLock, NULL);
+#else
+ spin_lock_init(&ndpi_str->skypeCacheLock);
+#endif
+
ndpi_init_protocol_defaults(ndpi_str);
return ndpi_str;
}
@@ -1118,7 +1332,7 @@
if(ndpi_struct != NULL) {
int i;
- for(i=0; i<ndpi_struct->ndpi_num_supported_protocols; i++) {
+ for(i=0; i<(int)ndpi_struct->ndpi_num_supported_protocols; i++) {
if(ndpi_struct->proto_defaults[i].protoName)
ndpi_free(ndpi_struct->proto_defaults[i].protoName);
}
@@ -1129,6 +1343,10 @@
if(ndpi_struct->ac_automa != NULL)
ac_automata_release((AC_AUTOMATA_t*)ndpi_struct->ac_automa);
+ ndpi_free_lru_cache(&ndpi_struct->skypeCache);
+#ifndef __KERNEL__
+ pthread_mutex_destroy(&ndpi_struct->skypeCacheLock);
+#endif
ndpi_free(ndpi_struct);
}
}
@@ -1187,6 +1405,85 @@
/* ******************************************************************** */
+int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule, u_int8_t do_add) {
+ char *at, *proto, *elem;
+ ndpi_proto_defaults_t *def;
+ int subprotocol_id, i;
+
+ at = strrchr(rule, '@');
+ if(at == NULL) {
+ printf("Invalid rule '%s'\n", rule);
+ return(-1);
+ } else
+ at[0] = 0, proto = &at[1];
+
+ for(i=0, def = NULL; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++) {
+ if(strcasecmp(ndpi_mod->proto_defaults[i].protoName, proto) == 0) {
+ def = &ndpi_mod->proto_defaults[i];
+ subprotocol_id = i;
+ break;
+ }
+ }
+
+ if(def == NULL) {
+ if(!do_add) {
+ /* We need to remove a rule */
+ printf("Unable to find protocol '%s': skipping rule '%s'\n", proto, rule);
+ return(-3);
+ } else {
+ ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
+
+ if(ndpi_mod->ndpi_num_custom_protocols >= (NDPI_MAX_NUM_CUSTOM_PROTOCOLS-1)) {
+ printf("Too many protocols defined (%u): skipping protocol %s\n",
+ ndpi_mod->ndpi_num_custom_protocols, proto);
+ return(-2);
+ }
+
+ ndpi_set_proto_defaults(ndpi_mod, ndpi_mod->ndpi_num_supported_protocols, ndpi_strdup(proto),
+ ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
+ def = &ndpi_mod->proto_defaults[ndpi_mod->ndpi_num_supported_protocols];
+ subprotocol_id = ndpi_mod->ndpi_num_supported_protocols;
+ ndpi_mod->ndpi_num_supported_protocols++, ndpi_mod->ndpi_num_custom_protocols++;
+ }
+ }
+
+ while((elem = strsep(&rule, ",")) != NULL) {
+ char *attr = elem, *value = NULL;
+ ndpi_port_range range;
+ int is_tcp = 0, is_udp = 0;
+
+ if (strncmp(attr, "tcp:", 4) == 0)
+ is_tcp = 1, value = &attr[4];
+ else if (strncmp(attr, "udp:", 4) == 0)
+ is_udp = 1, value = &attr[4];
+ else if (strncmp(attr, "host:", 5) == 0) {
+ /* host:"<value>",host:"<value>",.....@<subproto> */
+ value = &attr[5];
+ if (value[0] == '"') value++; /* remove leading " */
+ if (value[strlen(value)-1] == '"') value[strlen(value)-1] = '\0'; /* remove trailing " */
+ }
+
+ if (is_tcp || is_udp) {
+ if(sscanf(value, "%u-%u", (unsigned int *)&range.port_low, (unsigned int *)&range.port_high) != 2)
+ range.port_low = range.port_high = atoi(&elem[4]);
+ if(do_add)
+ addDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
+ else
+ removeDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
+ } else {
+ if(do_add)
+ ndpi_add_host_url_subprotocol(ndpi_mod, "host", value, subprotocol_id);
+ else
+ ndpi_remove_host_url_subprotocol(ndpi_mod, "host", value, subprotocol_id);
+ }
+ }
+
+ return(0);
+}
+
+/* ******************************************************************** */
+
/*
Format:
<tcp|udp>:<port>,<tcp|udp>:<port>,.....@<proto>
@@ -1209,9 +1506,7 @@
}
while(fd) {
- char buffer[512], *line, *at, *proto, *elem, *holder;
- ndpi_proto_defaults_t *def;
- int subprotocol_id;
+ char buffer[512], *line;
if(!(line = fgets(buffer, sizeof(buffer), fd)))
break;
@@ -1221,65 +1516,7 @@
else
line[i-1] = '\0';
- at = strrchr(line, '@');
- if(at == NULL) {
- printf("Invalid line '%s'\n", line);
- continue;
- } else
- at[0] = 0, proto = &at[1];
-
- for(i=0, def = NULL; i<ndpi_mod->ndpi_num_supported_protocols; i++) {
- if(strcasecmp(ndpi_mod->proto_defaults[i].protoName, proto) == 0) {
- def = &ndpi_mod->proto_defaults[i];
- subprotocol_id = i;
- break;
- }
- }
-
- if(def == NULL) {
- ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
-
- if(ndpi_mod->ndpi_num_custom_protocols >= (NDPI_MAX_NUM_CUSTOM_PROTOCOLS-1)) {
- printf("Too many protocols defined (%u): skipping protocol %s\n",
- ndpi_mod->ndpi_num_custom_protocols, proto);
- continue;
- }
-
- ndpi_set_proto_defaults(ndpi_mod, ndpi_mod->ndpi_num_supported_protocols, ndpi_strdup(proto),
- ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
- ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
- def = &ndpi_mod->proto_defaults[ndpi_mod->ndpi_num_supported_protocols];
- subprotocol_id = ndpi_mod->ndpi_num_supported_protocols;
- ndpi_mod->ndpi_num_supported_protocols++, ndpi_mod->ndpi_num_custom_protocols++;
- }
-
- elem = strtok_r(line, ",", &holder);
- while(elem != NULL) {
- char *attr = elem, *value;
- ndpi_port_range range;
- int is_tcp = 0, is_udp = 0;
-
- if (strncmp(attr, "tcp:", 4) == 0)
- is_tcp = 1, value = &attr[4];
- else if (strncmp(attr, "udp:", 4) == 0)
- is_udp = 1, value = &attr[4];
- else if (strncmp(attr, "host:", 5) == 0) {
- /* host:"<value>",host:"<value>",.....@<subproto> */
- value = &attr[5];
- if (value[0] == '"') value++; /* remove leading " */
- if (value[strlen(value)-1] == '"') value[strlen(value)-1] = '\0'; /* remove trailing " */
- }
-
- if (is_tcp || is_udp) {
- if(sscanf(value, "%u-%u", (unsigned int *)&range.port_low, (unsigned int *)&range.port_high) != 2)
- range.port_low = range.port_high = atoi(&elem[4]);
- addDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
- } else {
- ndpi_add_host_url_subprotocol(ndpi_mod, "host", value, subprotocol_id);
- }
-
- elem = strtok_r(NULL, ",", &holder);
- }
+ ndpi_handle_rule(ndpi_mod, line, 1);
}
fclose(fd);
@@ -1882,19 +2119,6 @@
a++;
}
#endif
-#ifdef NDPI_PROTOCOL_PANDO
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_PANDO) != 0) {
- ndpi_struct->callback_buffer[a].func = ndpi_search_pando_tcp_udp;
- ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
- NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION;
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].excluded_protocol_bitmask, NDPI_PROTOCOL_PANDO);
-
- a++;
- }
-#endif
#if defined(NDPI_PROTOCOL_IPSEC) || defined(NDPI_PROTOCOL_GRE) || defined(NDPI_PROTOCOL_ICMP) || defined(NDPI_PROTOCOL_IGMP) || defined(NDPI_PROTOCOL_EGP) || defined(NDPI_PROTOCOL_SCTP) || defined(NDPI_PROTOCOL_OSPF) || defined(NDPI_PROTOCOL_IP_IN_IP) || defined(NDPI_PROTOCOL_ICMPV6)
/* always add non tcp/udp if one protocol is compiled in */
if (1) {
@@ -2051,23 +2275,6 @@
a++;
}
#endif
-#ifdef NDPI_PROTOCOL_GADUGADU
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_GADUGADU) != 0) {
- ndpi_struct->callback_buffer[a].func = ndpi_search_gadugadu;
- ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
- NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITH_PAYLOAD;
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
-#ifdef NDPI_PROTOCOL_HTTP
- NDPI_ADD_PROTOCOL_TO_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_HTTP);
-#endif
- NDPI_ADD_PROTOCOL_TO_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_GADUGADU);
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].excluded_protocol_bitmask, NDPI_PROTOCOL_GADUGADU);
-
- a++;
- }
-#endif
#ifdef NDPI_PROTOCOL_ZATTOO
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_ZATTOO) != 0) {
ndpi_struct->callback_buffer[a].func = ndpi_search_zattoo;
@@ -2105,19 +2312,6 @@
a++;
}
#endif
-#ifdef NDPI_PROTOCOL_FEIDIAN
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_FEIDIAN) != 0) {
- ndpi_struct->callback_buffer[a].func = ndpi_search_feidian;
- ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
- NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION;
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].excluded_protocol_bitmask, NDPI_PROTOCOL_FEIDIAN);
-
- a++;
- }
-#endif
#ifdef NDPI_PROTOCOL_SSH
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_SSH) != 0) {
ndpi_struct->callback_buffer[a].func = ndpi_search_ssh_tcp;
@@ -2192,18 +2386,6 @@
a++;
}
#endif
-#ifdef NDPI_PROTOCOL_I23V5
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_I23V5) != 0) {
- ndpi_struct->callback_buffer[a].func = ndpi_search_i23v5;
- ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
- NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION;
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
-
- NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].excluded_protocol_bitmask, NDPI_PROTOCOL_I23V5);
- a++;
- }
-#endif
#ifdef NDPI_PROTOCOL_SOCRATES
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_SOCRATES) != 0) {
ndpi_struct->callback_buffer[a].func = ndpi_search_socrates;
@@ -2970,7 +3152,7 @@
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_GTP) != 0) {
ndpi_struct->callback_buffer[a].func = ndpi_search_gtp;
ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
- NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD;
+ NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD;
NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
NDPI_ADD_PROTOCOL_TO_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_GTP);
@@ -3158,6 +3340,20 @@
}
#endif
+#ifdef NDPI_PROTOCOL_WHOIS_DAS
+ if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_WHOIS_DAS) != 0) {
+ ndpi_struct->callback_buffer[a].func = ndpi_search_whois_das;
+ ndpi_struct->callback_buffer[a].ndpi_selection_bitmask =
+ NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION;
+
+ NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_UNKNOWN);
+ NDPI_ADD_PROTOCOL_TO_BITMASK(ndpi_struct->callback_buffer[a].detection_bitmask, NDPI_PROTOCOL_WHOIS_DAS);
+
+ NDPI_SAVE_AS_BITMASK(ndpi_struct->callback_buffer[a].excluded_protocol_bitmask, NDPI_PROTOCOL_WHOIS_DAS);
+ a++;
+ }
+#endif
+
#ifdef NDPI_PROTOCOL_ORACLE
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, NDPI_PROTOCOL_ORACLE) != 0) {
ndpi_struct->callback_buffer[a].func = ndpi_search_oracle;
@@ -3314,14 +3510,16 @@
return 0;
}
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */
+
+
static u_int8_t ndpi_iph_is_valid_and_not_fragmented(const struct ndpi_iphdr *iph, const u_int16_t ipsize)
{
-#ifdef REQUIRE_FULL_PACKETS
+ //#ifdef REQUIRE_FULL_PACKETS
if (ipsize < iph->ihl * 4 ||
ipsize < ntohs(iph->tot_len) || ntohs(iph->tot_len) < iph->ihl * 4 || (iph->frag_off & htons(0x1FFF)) != 0) {
return 0;
}
-#endif
+ //#endif
return 1;
}
@@ -3755,8 +3953,7 @@
if ((ndpi_struct->callback_buffer_tcp_payload[a].ndpi_selection_bitmask & ndpi_selection_packet) ==
ndpi_struct->callback_buffer_tcp_payload[a].ndpi_selection_bitmask
&& NDPI_BITMASK_COMPARE(flow->excluded_protocol_bitmask,
- ndpi_struct->
- callback_buffer_tcp_payload[a].excluded_protocol_bitmask) == 0
+ ndpi_struct->callback_buffer_tcp_payload[a].excluded_protocol_bitmask) == 0
&& NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer_tcp_payload[a].detection_bitmask,
detection_bitmask) != 0) {
ndpi_struct->callback_buffer_tcp_payload[a].func(ndpi_struct, flow);
@@ -4120,15 +4317,14 @@
packet->http_response.ptr = NULL;
packet->http_response.len = 0;
- if (packet->payload_packet_len == 0)
+ if((packet->payload_packet_len == 0)
+ || (packet->payload == NULL))
return;
packet->line[packet->parsed_lines].ptr = packet->payload;
packet->line[packet->parsed_lines].len = 0;
-
-
- for (a = 0; a < end; a++) {
+ for (a = 0; (a+1) < end; a++) {
if (get_u_int16_t(packet->payload, a) == ntohs(0x0d0a)) {
packet->line[packet->parsed_lines].len = (u_int16_t)(((unsigned long) &packet->payload[a]) - ((unsigned long) packet->line[packet->parsed_lines].ptr));
@@ -4963,6 +5159,9 @@
const void *ret;
ndpi_default_ports_tree_node_t node;
+ if(shost && dhost && is_skype_connection(ndpi_struct, shost, dhost))
+ return(NDPI_PROTOCOL_SKYPE);
+
node.default_port = sport;
ret = ndpi_tfind(&node, (proto == IPPROTO_TCP) ? (void*)&ndpi_struct->tcpRoot : (void*)&ndpi_struct->udpRoot, ndpi_default_ports_tree_node_t_cmp);
@@ -4982,16 +5181,32 @@
/* ****************************************************** */
char* ndpi_get_proto_name(struct ndpi_detection_module_struct *ndpi_mod, u_int16_t proto_id) {
- if(proto_id > ndpi_mod->ndpi_num_supported_protocols) proto_id = NDPI_PROTOCOL_UNKNOWN;
+ if((proto_id >= ndpi_mod->ndpi_num_supported_protocols)
+ && ((proto_id < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS)
+ && (ndpi_mod->proto_defaults[proto_id].protoName == NULL)))
+ proto_id = NDPI_PROTOCOL_UNKNOWN;
+
return(ndpi_mod->proto_defaults[proto_id].protoName);
}
/* ****************************************************** */
+int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto) {
+ int i;
+
+ for(i=0; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++)
+ if(strcasecmp(proto, ndpi_mod->proto_defaults[i].protoName) == 0)
+ return(i);
+
+ return(-1);
+}
+
+/* ****************************************************** */
+
void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
int i;
- for(i=0; i<ndpi_mod->ndpi_num_supported_protocols; i++)
+ for(i=0; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++)
printf("[%3d] %s\n", i, ndpi_mod->proto_defaults[i].protoName);
}
@@ -5029,7 +5244,7 @@
struct ndpi_packet_struct *packet = &flow->packet;
AC_TEXT_t ac_input_text;
- if(ndpi_struct->ac_automa == NULL) return(NDPI_PROTOCOL_UNKNOWN);
+ if((ndpi_struct->ac_automa == NULL) || (string_to_match_len== 0)) return(NDPI_PROTOCOL_UNKNOWN);
if(!ndpi_struct->ac_automa_finalized) {
ac_automata_finalize((AC_AUTOMATA_t*)ndpi_struct->ac_automa);
@@ -5068,5 +5283,147 @@
return(NDPI_PROTOCOL_UNKNOWN);
}
+/* ****************************************************** */
+
+void* ndpi_create_empty_automa(struct ndpi_detection_module_struct *ndpi_struct) {
+ int i;
+ void *automa = ac_automata_init(ac_match_handler);
+
+ for(i=0; host_match[i].string_to_match != NULL; i++)
+ ndpi_add_host_url_subprotocol_to_automa(ndpi_struct,
+ host_match[i].string_to_match,
+ host_match[i].protocol_id, automa);
+
+ return(automa);
+}
+
+/* ****************************************************** */
+
+int ndpi_add_host_url_subprotocol_to_automa(struct ndpi_detection_module_struct *ndpi_struct, char *value, int protocol_id, void* automa) {
+ AC_PATTERN_t ac_pattern;
+
+ /* e.g attr = "host" value = ".facebook.com" protocol_id = NDPI_PROTOCOL_FACEBOOK */
+
+#ifdef DEBUG
+ printf("[NDPI] ndpi_add_host_url_subprotocol(%s, %s, %d)\n", attr, value, protocol_id);
+#endif
+
+ if(protocol_id >= NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS) {
+ printf("[NDPI] %s(protoId=%d): INTERNAL ERROR\n", __FUNCTION__, protocol_id);
+ return(-1);
+ }
+
+ if(automa == NULL) return(-2);
+
+ ac_pattern.astring = value;
+ ac_pattern.rep.number = protocol_id;
+ ac_pattern.length = strlen(ac_pattern.astring);
+ ac_automata_add(((AC_AUTOMATA_t*)automa), &ac_pattern);
+
+#ifdef DEBUG
+ printf("[NTOP] new subprotocol: %s = %s -> %d\n", attr, value, protocol_id);
+#endif
+
+ return(0);
+}
+
+/* ****************************************************** */
+
+void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct, void* automa) {
+ void *old_automa;
+
+ ac_automata_finalize((AC_AUTOMATA_t*)automa);
+ ndpi_struct->ac_automa_finalized = 1;
+
+ old_automa = ndpi_struct->ac_automa;
+
+ ndpi_struct->ac_automa = automa;
+
+ if(old_automa != NULL) {
+#ifndef __KERNEL__
+ sleep(1); /* Make sure nobody is using it */
+#endif
+ ac_automata_release((AC_AUTOMATA_t*)old_automa);
+ }
+}
+
-
\ No newline at end of file
+/* ****************************************************** */
+
+char* ndpi_revision() {
+ return("$Revision: 6880 $");
+}
+
+/* ****************************************************** */
+
+#ifdef WIN32
+
+/*
+int pthread_mutex_init(pthread_mutex_t *mutex, void *unused) {
+ unused = NULL;
+ *mutex = CreateMutex(NULL, FALSE, NULL);
+ return *mutex == NULL ? -1 : 0;
+}
+
+int pthread_mutex_destroy(pthread_mutex_t *mutex) {
+ return CloseHandle(*mutex) == 0 ? -1 : 0;
+}
+
+int pthread_mutex_lock(pthread_mutex_t *mutex) {
+ return WaitForSingleObject(*mutex, INFINITE) == WAIT_OBJECT_0 ? 0 : -1;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex) {
+ return ReleaseMutex(*mutex) == 0 ? -1 : 0;
+}
+*/
+/* http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/port/gettimeofday.c;h=75a91993b74414c0a1c13a2a09ce739cb8aa8a08;hb=HEAD */
+int gettimeofday(struct timeval * tp, struct timezone * tzp) {
+ /* FILETIME of Jan 1 1970 00:00:00. */
+ const unsigned __int64 epoch = (__int64)(116444736000000000);
+
+ FILETIME file_time;
+ SYSTEMTIME system_time;
+ ULARGE_INTEGER ularge;
+
+ GetSystemTime(&system_time);
+ SystemTimeToFileTime(&system_time, &file_time);
+ ularge.LowPart = file_time.dwLowDateTime;
+ ularge.HighPart = file_time.dwHighDateTime;
+
+ tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L);
+ tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
+
+ return 0;
+ }
+#endif
+
+int NDPI_BITMASK_COMPARE(NDPI_PROTOCOL_BITMASK a, NDPI_PROTOCOL_BITMASK b) {
+ int i;
+
+ for(i=0; i<NDPI_NUM_FDS_BITS; i++) {
+ if(a.fds_bits[i] & b.fds_bits[i])
+ return(1);
+ }
+
+ return(0);
+}
+
+int NDPI_BITMASK_IS_EMPTY(NDPI_PROTOCOL_BITMASK a) {
+ int i;
+
+ for(i=0; i<NDPI_NUM_FDS_BITS; i++)
+ if(a.fds_bits[i] != 0)
+ return(0);
+
+ return(1);
+}
+
+void NDPI_DUMP_BITMASK(NDPI_PROTOCOL_BITMASK a) {
+ int i;
+
+ for(i=0; i<NDPI_NUM_FDS_BITS; i++)
+ printf("[%d=%u]", i, a.fds_bits[i]);
+
+ printf("\n");
+}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/bittorrent.c
^
|
@@ -370,6 +370,12 @@
void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
+
+ /* This is broadcast */
+ if(packet->iph
+ && ((packet->iph->saddr == 0xFFFFFFFF) || (packet->iph->daddr == 0xFFFFFFFF)))
+ return;
+
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */
@@ -378,6 +384,10 @@
ndpi_int_search_bittorrent_tcp(ndpi_struct, flow);
}
else if(packet->udp != NULL) {
+ if((ntohs(packet->udp->source) < 1024)
+ || (ntohs(packet->udp->dest) < 1024)) /* High ports only */
+ return;
+
/*
Check for uTP http://www.bittorrent.org/beps/bep_0029.html
@@ -390,15 +400,33 @@
u_int8_t v0_flags = packet->payload[18];
/* Check if this is protocol v1 */
- u_int8_t v1_version = packet->payload[0];
- u_int8_t v1_extension = packet->payload[1];
-
- if((((v1_version & 0x0f) == 1)
- && ((v1_version >> 4) < 6 /* ST_NUM_STATES */)
- && (v1_extension < 3 /* EXT_NUM_EXT */))
- || ((v0_flags < 6 /* ST_NUM_STATES */)
- || (v0_extension < 3 /* EXT_NUM_EXT */))) {
+ u_int8_t v1_version = packet->payload[0];
+ u_int8_t v1_extension = packet->payload[1];
+ u_int32_t v1_window_size = *((u_int32_t*)&packet->payload[12]);
+
+ if(((v1_version & 0x0f) == 1)
+ && ((v1_version >> 4) < 5 /* ST_NUM_STATES */)
+ && (v1_extension < 3 /* EXT_NUM_EXT */)
+ && (v1_window_size < 32768 /* 32k */)
+ ) {
goto bittorrent_found;
+ } else if((v0_flags < 6 /* ST_NUM_STATES */)
+ && (v0_extension < 3 /* EXT_NUM_EXT */)) {
+ u_int32_t ts = ntohl(*((u_int32_t*)&(packet->payload[4])));
+ u_int32_t now;
+
+#ifndef __KERNEL__
+ now = (u_int32_t)time(NULL);
+#else
+ struct timespec t;
+
+ getnstimeofday(&t);
+ now = t.tv_sec;
+#endif
+
+ if((ts < (now+86400)) && (ts > (now-86400))) {
+ goto bittorrent_found;
+ }
}
}
@@ -408,9 +436,9 @@
if(packet->payload_packet_len > 19 /* min size */) {
char *begin;
- if(ndpi_strnstr(packet->payload, ":target20:", packet->payload_packet_len)
- || ndpi_strnstr(packet->payload, ":find_node1:", packet->payload_packet_len)
- || ndpi_strnstr(packet->payload, "d1:ad2:id20:", packet->payload_packet_len)) {
+ if(ndpi_strnstr((const char *)packet->payload, ":target20:", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, ":find_node1:", packet->payload_packet_len)
+ || ndpi_strnstr((const char *)packet->payload, "d1:ad2:id20:", packet->payload_packet_len)) {
bittorrent_found:
NDPI_LOG_BITTORRENT(NDPI_PROTOCOL_BITTORRENT,
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/citrix.c
^
|
@@ -62,7 +62,7 @@
char citrix_header[] = { 0x1a, 0x43, 0x47, 0x50, 0x2f, 0x30, 0x31 };
if((memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0)
- || (ndpi_strnstr(packet->payload, "Citrix.TcpProxyService", payload_len) != NULL)) {
+ || (ndpi_strnstr((const char *)packet->payload, "Citrix.TcpProxyService", payload_len) != NULL)) {
NDPI_LOG(NDPI_PROTOCOL_CITRIX, ndpi_struct, NDPI_LOG_DEBUG, "Found citrix.\n");
ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_REAL_PROTOCOL);
}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/dns.c
^
|
@@ -111,7 +111,7 @@
int i = packet->tcp ? 2 : 0;
struct dns_packet_header header, *dns = (struct dns_packet_header*)&packet->payload[i];
u_int8_t is_query, ret_code, is_dns = 0;
- u_int32_t a_record = 0, query_offset;
+ u_int32_t a_record[NDPI_MAX_DNS_REQUESTS] = { 0 }, query_offset, num_a_records = 0;
header.flags = ntohs(dns->flags);
header.transaction_id = ntohs(dns->transaction_id);
@@ -127,8 +127,8 @@
if(is_query) {
/* DNS Request */
if((header.num_queries > 0) && (header.num_queries <= NDPI_MAX_DNS_REQUESTS)
- && (header.answer_rrs == 0)
- && (header.authority_rrs == 0)) {
+ && (((header.flags & 0x2800) == 0x2800 /* Dynamic DNS Update */)
+ || ((header.answer_rrs == 0) && (header.authority_rrs == 0)))) {
/* This is a good query */
is_dns = 1;
}
@@ -183,8 +183,12 @@
if(rsp_type == 1 /* A */) {
if(data_len == 4) {
- a_record = ntohl(*((u_int32_t*)&packet->payload[i]));
- break; /* One record is enough */
+ u_int32_t v = ntohl(*((u_int32_t*)&packet->payload[i]));
+
+ if(num_a_records < (NDPI_MAX_DNS_REQUESTS-1))
+ a_record[num_a_records++] = v;
+ else
+ break; /* One record is enough */
}
}
@@ -205,14 +209,12 @@
) {
/* This is a good reply */
is_dns = 1;
+ flow->protos.dns.num_queries = header.num_queries, flow->protos.dns.num_answer_rrs = header.answer_rrs;
}
}
if(is_dns) {
int j = 0;
-#ifdef DEBUG
- u_int16_t query_type, query_class;
-#endif
i = query_offset+1;
@@ -227,23 +229,42 @@
if(a_record != 0) {
char a_buf[32];
-
- j += snprintf(&flow->host_server_name[j], sizeof(flow->host_server_name)-1-j, "@%s",
- ndpi_intoa_v4(a_record, a_buf, sizeof(a_buf)));
+ int i;
+
+ for(i=0; i<num_a_records; i++) {
+ j += snprintf((char*)&flow->host_server_name[j], sizeof(flow->host_server_name)-1-j, "%s%s",
+ (i == 0) ? "@" : ";",
+ ndpi_intoa_v4(a_record[i], a_buf, sizeof(a_buf)));
+ }
}
flow->host_server_name[j] = '\0';
+ if(j > 0) {
#ifdef DEBUG
+ printf("==> %s\n", flow->host_server_name);
+#endif
+
+ if(ndpi_struct->match_dns_host_names)
+ ndpi_match_string_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name, strlen((const char*)flow->host_server_name));
+ }
+
i++;
- memcpy(&query_type, &packet->payload[i], 2); query_type = ntohs(query_type), i += 2;
- memcpy(&query_class, &packet->payload[i], 2); query_class = ntohs(query_class), i += 2;
+ memcpy(&flow->protos.dns.query_type, &packet->payload[i], 2); flow->protos.dns.query_type = ntohs(flow->protos.dns.query_type), i += 2;
+ memcpy(&flow->protos.dns.query_class, &packet->payload[i], 2); flow->protos.dns.query_class = ntohs(flow->protos.dns.query_class), i += 2;
- printf("%s [type=%04X][class=%04X]\n", flow->host_server_name, query_type, query_class);
+#ifdef DEBUG
+ printf("%s [type=%04X][class=%04X]\n", flow->host_server_name, flow->protos.dns.query_type, flow->protos.dns.query_class);
#endif
- NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "found DNS.\n");
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_DNS, NDPI_REAL_PROTOCOL);
+ if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
+ /*
+ Do not set the protocol with DNS if ndpi_match_string_subprotocol() has
+ matched a subprotocol
+ */
+ NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "found DNS.\n");
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_DNS, NDPI_REAL_PROTOCOL);
+ }
} else {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/dropbox.c
^
|
@@ -47,7 +47,7 @@
if((packet->udp->source == dropbox_port)
&& (packet->udp->dest == dropbox_port)) {
if(payload_len > 2) {
- if(strncmp(packet->payload, "{\"", 2) == 0) {
+ if(strncmp((const char *)packet->payload, "{\"", 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "Found dropbox.\n");
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0);
return;
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/edonkey.c
^
|
@@ -111,7 +111,6 @@
/* check for client hello */
if (packet->payload_packet_len >= 32 && get_l32(packet->payload, 1) <= (packet->payload_packet_len - 5)
&& (packet->payload[0] == 0xe3 || packet->payload[0] == 0xc5)) {
-
if (packet->payload[5] == 0x01 && ((packet->payload[6] == 0x10 && get_l32(packet->payload, 29) < 0x0F)
|| (get_l32(packet->payload, 28) > 0x00
&& get_l32(packet->payload, 28) < 0x0F))) {
|
[-]
[+]
|
Deleted |
nDPI.tar.bz2/src/lib/protocols/feidian.c
^
|
@@ -1,87 +0,0 @@
-/*
- * feidian.c
- *
- * Copyright (C) 2009-2011 by ipoque GmbH
- * Copyright (C) 2011-13 - ntop.org
- *
- * This file is part of nDPI, an open source deep packet inspection
- * library based on the OpenDPI and PACE technology by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "ndpi_protocols.h"
-
-#ifdef NDPI_PROTOCOL_FEIDIAN
-
-static void ndpi_int_feidian_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
- struct ndpi_flow_struct *flow, ndpi_protocol_type_t protocol_type)
-{
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_FEIDIAN, protocol_type);
-}
-
-
-void ndpi_search_feidian(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
-
-
- // struct ndpi_id_struct *src=ndpi_struct->src;
- // struct ndpi_id_struct *dst=ndpi_struct->dst;
-
-
- if (packet->tcp != NULL) {
- if (packet->tcp->dest == htons(8080) && packet->payload_packet_len == 4
- && packet->payload[0] == 0x29 && packet->payload[1] == 0x1c
- && packet->payload[2] == 0x32 && packet->payload[3] == 0x01) {
- NDPI_LOG(NDPI_PROTOCOL_FEIDIAN, ndpi_struct, NDPI_LOG_DEBUG,
- "Feidian: found the flow (TCP): packet_size: %u; Flowstage: %u\n",
- packet->payload_packet_len, flow->l4.udp.feidian_stage);
- ndpi_int_feidian_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- } else if (packet->payload_packet_len > 50 && memcmp(packet->payload, "GET /", 5) == 0) {
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->host_line.ptr != NULL && packet->host_line.len == 18
- && memcmp(packet->host_line.ptr, "config.feidian.com", 18) == 0) {
- ndpi_int_feidian_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
- return;
- }
- }
- NDPI_LOG(NDPI_PROTOCOL_FEIDIAN, ndpi_struct, NDPI_LOG_DEBUG,
- "Feidian: discarted the flow (TCP): packet_size: %u; Flowstage: %u\n",
- packet->payload_packet_len, flow->l4.udp.feidian_stage);
- } else if (packet->udp != NULL) {
- if (ntohs(packet->udp->source) == 53124 || ntohs(packet->udp->dest) == 53124) {
- if (flow->l4.udp.feidian_stage == 0 && (packet->payload_packet_len == 112)
- && packet->payload[0] == 0x1c && packet->payload[1] == 0x1c
- && packet->payload[2] == 0x32 && packet->payload[3] == 0x01) {
- flow->l4.udp.feidian_stage = 1;
- return;
- } else if (flow->l4.udp.feidian_stage == 1
- && (packet->payload_packet_len == 116 || packet->payload_packet_len == 112)
- && packet->payload[0] == 0x1c
- && packet->payload[1] == 0x1c && packet->payload[2] == 0x32 && packet->payload[3] == 0x01) {
- ndpi_int_feidian_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- }
- NDPI_LOG(NDPI_PROTOCOL_FEIDIAN, ndpi_struct, NDPI_LOG_DEBUG,
- "Feidian: discarted the flow (UDP): packet_size: %u; Flowstage: %u\n",
- packet->payload_packet_len, flow->l4.udp.feidian_stage);
- }
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FEIDIAN);
-}
-#endif
|
[-]
[+]
|
Deleted |
nDPI.tar.bz2/src/lib/protocols/gadu_gadu.c
^
|
@@ -1,471 +0,0 @@
-/*
- * gadu_gadu.c
- *
- * Copyright (C) 2009-2011 by ipoque GmbH
- * Copyright (C) 2011-13 - ntop.org
- *
- * This file is part of nDPI, an open source deep packet inspection
- * library based on the OpenDPI and PACE technology by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "ndpi_protocols.h"
-#include "ndpi_utils.h"
-
-#ifdef NDPI_PROTOCOL_GADUGADU
-
-static void ndpi_int_gadugadu_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
- struct ndpi_flow_struct *flow, ndpi_protocol_type_t protocol_type)
-{
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_GADUGADU, protocol_type);
-}
-
-static void parse_gg_foneno(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
- struct ndpi_id_struct *src = flow->src;
- u_int16_t pos = 18;
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: parse_gg_foneno.\n");
-
- if (packet->payload_packet_len < 19) {
- return;
- }
-
- while (packet->payload[pos] != '?') {
- pos++;
- if ((pos + 18) > packet->payload_packet_len)
- return;
- }
- pos++;
- if (pos + 16 < packet->payload_packet_len) {
- char fmnumber[8];
- int i = 0;
- if (memcmp(&packet->payload[pos], "fmnumber=", 9) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: fmnumber found .\n");
- } else
- return;
-
- pos += 9;
- while (packet->payload[pos] != '&') {
- fmnumber[i] = packet->payload[pos];
- i++;
- pos++;
- if (pos > packet->payload_packet_len || i > 7)
- break;
- }
- if (i < 8) {
- fmnumber[i] = '\0';
- if (src != NULL) {
- memcpy(src->gg_fmnumber, fmnumber, i);
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: fmnumber %s\n", src->gg_fmnumber);
- }
- }
- }
-
-}
-
-static u_int8_t check_for_gadugadu_payload_pattern(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
-
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: check for 0xbebadec0 pattern in payload.\n");
-
- if (packet->payload_packet_len == 12) {
- if ((flow->packet_counter == 1) && (ntohl(get_u_int32_t(packet->payload, 0)) == 0xbebadec0)) {
- flow->l4.tcp.gadugadu_stage++;
- return 1;
- }
- if ((flow->l4.tcp.gadugadu_stage == 1) && (flow->packet_counter == 2)
- && (ntohl(get_u_int32_t(packet->payload, 0)) == 0xbebadec0)) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: gadugadu pattern bebadec0 FOUND \n");
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return 1;
- }
- }
- return 0;
-}
-
-static u_int8_t check_for_http(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: check for http.\n");
-
- if (packet->payload_packet_len < 50) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: Packet too small.\n");
- return 0;
- } else if (memcmp(packet->payload, "GET /appsvc/appmsg", 18) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: GET FOUND\n");
- parse_gg_foneno(ndpi_struct, flow);
- // parse packet
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->parsed_lines <= 1) {
- return 0;
- }
- if (packet->host_line.ptr == NULL) {
- return 0;
- }
- if (!(packet->host_line.len >= 19 && memcmp(packet->host_line.ptr, "appmsg.gadu-gadu.pl", 19) == 0)) {
- return 0;
- }
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: Is gadugadu host FOUND %s\n", packet->host_line.ptr);
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
-
- } else if (memcmp(packet->payload, "POST /send/message/", 15) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: GET FOUND\n");
-
- // parse packet
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->parsed_lines <= 1) {
- return 0;
- }
- if (packet->host_line.ptr == NULL) {
- return 0;
- }
- if (!(packet->host_line.len >= 17 && memcmp(packet->host_line.ptr, "life.gadu-gadu.pl", 17) == 0)) {
- return 0;
- }
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: Is gadugadu post FOUND %s\n", packet->host_line.ptr);
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
-
- } else if (memcmp(packet->payload, "GET /rotate_token", 17) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: GET FOUND\n");
-
- // parse packet
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->parsed_lines <= 1) {
- return 0;
- }
- if (packet->host_line.ptr == NULL) {
- return 0;
- }
- if (!(packet->host_line.len >= 13 && memcmp(packet->host_line.ptr, "sms.orange.pl", 13) == 0)) {
- return 0;
- }
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: gadugadu sms FOUND %s\n", packet->host_line.ptr);
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
-
- } else if ((memcmp(packet->payload, "GET /nowosci.xml", NDPI_STATICSTRING_LEN("GET /nowosci.xml")) == 0) ||
- (memcmp(packet->payload, "GET /gadu-gadu.xml", NDPI_STATICSTRING_LEN("GET /gadu-gadu.xml")) == 0) ||
- (memcmp(packet->payload, "POST /access_token", NDPI_STATICSTRING_LEN("POST /access_token")) == 0)) {
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->user_agent_line.ptr == NULL) {
- return 0;
- }
- if (!(packet->user_agent_line.len >= NDPI_STATICSTRING_LEN("Gadu-Gadu Client") &&
- memcmp(packet->user_agent_line.ptr, "Gadu-Gadu Client", NDPI_STATICSTRING_LEN("Gadu-Gadu Client")) == 0)) {
- return 0;
- }
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: gadugadu FOUND %s\n", packet->user_agent_line.ptr);
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
-
- }
-
- return 1;
-
-}
-
-static void ndpi_search_gadugadu_tcp(struct ndpi_detection_module_struct *ndpi_struct,
- struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
-
- struct ndpi_id_struct *src = flow->src;
- struct ndpi_id_struct *dst = flow->dst;
-
- if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_GADUGADU) {
- if (src != NULL)
- src->gg_timeout = packet->tick_timestamp;
- if (dst != NULL)
- dst->gg_timeout = packet->tick_timestamp;
-
- if (packet->payload_packet_len == 311) {
- if (packet->payload[28] != 0) {
- if (src != NULL) {
- src->gg_timeout = packet->tick_timestamp;
- if (ntohs(packet->tcp->dest) == 8074 || ntohs(packet->tcp->dest) == 443)
- src->gadu_gadu_ft_direction = 0;
- else
- src->gadu_gadu_ft_direction = 1;
- src->gadu_gadu_voice = 0;
-
-
- }
- if (dst != NULL) {
- dst->gg_timeout = packet->tick_timestamp;
- if (ntohs(packet->tcp->dest) == 8074 || ntohs(packet->tcp->dest) == 443)
- dst->gadu_gadu_ft_direction = 0;
- else
- dst->gadu_gadu_ft_direction = 1;
- dst->gadu_gadu_voice = 0;
-
-
- }
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "gg filetransfer setup detected\n");
-
- } else {
- if (src != NULL) {
- src->gadu_gadu_voice = 1;
- src->gg_timeout = packet->tick_timestamp;
- }
- if (dst != NULL) {
- dst->gadu_gadu_voice = 1;
- dst->gg_timeout = packet->tick_timestamp;
- }
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "gg voice setup detected \n");
- }
- }
- return;
- }
-#ifdef NDPI_PROTOCOL_HTTP
- if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP) {
-#endif
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: HTTP CHECK FOUND\n");
- if (packet->tcp != NULL && ntohs(packet->tcp->dest) == 80)
- if (check_for_http(ndpi_struct, flow))
- return;
-#ifdef NDPI_PROTOCOL_HTTP
- }
-#endif
-
-
- /* the following code is implemented asymmetrically. */
- if (packet->tcp != NULL &&
- (ntohs(packet->tcp->dest) == 443 || ntohs(packet->tcp->dest) == 8074
- || ntohs(packet->tcp->source) == 443 || ntohs(packet->tcp->source) == 8074)) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: found port 8074 or 443.\n");
- if (flow->packet_counter <= 6) {
-
-
- if ((packet->payload_packet_len == 9
- || packet->payload_packet_len == 12
- || packet->payload_packet_len == 100
- || (packet->payload_packet_len > 190 && packet->payload_packet_len < 210)
- )
- && get_l32(packet->payload, 4) == packet->payload_packet_len - 8
- && (ntohl(get_u_int32_t(packet->payload, 0)) == 0x01000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x02000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x03000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x12000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x19000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x31000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x35000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x10000000
- || ntohl(get_u_int32_t(packet->payload, 0)) == 0x15000000)) {
- flow->l4.tcp.gadugadu_stage++;
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG,
- "Gadu-Gadu: len=9,12,100,190-210, stage++.\n");
- }
-
-
-
- /*detection of mirinda client .this has a different way of communicating ports */
- if (packet->payload_packet_len == 114
- && ntohl(get_u_int32_t(packet->payload, 0)) == 0x19000000
- && get_l32(packet->payload, 4) == packet->payload_packet_len - 8) {
- flow->l4.tcp.gadugadu_stage++;
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: len=114, stage++.\n");
- /* here the asymmetric implementation ends */
-
-
- if (flow->l4.tcp.gadugadu_stage == 2) {
- if (src != NULL) {
-
- memcpy(src->gg_call_id[src->gg_next_id], &packet->payload[8], 4);
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "call id parsed %d\n", packet->payload[8]);
-
- src->gg_ft_ip_address = get_u_int32_t(packet->payload, 86);
- src->gg_ft_port = htons(get_u_int16_t(packet->payload, 90));
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU,
- ndpi_struct, NDPI_LOG_DEBUG,
- "mirinda file transfer port %d \n", ntohs(src->gg_ft_port));
- }
- if (dst != NULL) {
-
- memcpy(dst->gg_call_id[dst->gg_next_id], &packet->payload[8], 4);
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "call id parsed %d\n", packet->payload[8]);
-
- dst->gg_ft_ip_address = get_u_int32_t(packet->payload, 86);
- dst->gg_ft_port = htons(get_u_int16_t(packet->payload, 90));
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU,
- ndpi_struct, NDPI_LOG_DEBUG,
- "mirinda file transfer port %d \n", ntohs(dst->gg_ft_port));
- }
- }
- }
-
- if (flow->l4.tcp.gadugadu_stage == 2) {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "Gadu-Gadu: add connection.\n");
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- }
- return;
- }
-
- }
- /*mirinda file detection */
- if (packet->tcp != NULL && src != NULL) {
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (src->detected_protocol_bitmask, NDPI_PROTOCOL_GADUGADU) != 0
- && ((src->gg_ft_ip_address == packet->iph->saddr && src->gg_ft_port == packet->tcp->source)
- || (src->gg_ft_ip_address == packet->iph->daddr && src->gg_ft_port == packet->tcp->dest))) {
- if ((packet->tick_timestamp - src->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "file transfer detected %d\n", ntohs(packet->tcp->dest));
- return;
- } else {
- src->gg_ft_ip_address = 0;
- src->gg_ft_port = 0;
- }
- } else if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (src->detected_protocol_bitmask, NDPI_PROTOCOL_GADUGADU) != 0 && (packet->tcp->dest == htons(80)
- || packet->tcp->source ==
- htons(80))
- && packet->payload_packet_len == 12 && (memcmp(src->gg_call_id[0], &packet->payload[5], 4) == 0
- || (src->gg_call_id[1][0]
- && (memcmp(src->gg_call_id[1], &packet->payload[5], 4)
- == 0)))) {
- if ((packet->tick_timestamp - src->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "http file transfer detetced \n");
- return;
- } else {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "http file transfer timeout \n");
-
-
- }
-
- } else if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (src->detected_protocol_bitmask,
- NDPI_PROTOCOL_GADUGADU) != 0
- && packet->payload_packet_len == 8 &&
- (memcmp(src->gg_call_id[0], &packet->payload[0], 4) == 0 || (src->gg_call_id[1][0]
- &&
- (memcmp
- (src->gg_call_id[1],
- &packet->payload[0], 4)
- == 0)))) {
- if ((packet->tick_timestamp - src->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "file transfer detetced %d\n", htons(packet->tcp->dest));
- return;
- } else {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, " file transfer timeout \n");
- }
- }
- }
-
- if (packet->tcp != NULL && dst != NULL) {
- if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (dst->detected_protocol_bitmask, NDPI_PROTOCOL_GADUGADU) != 0
- && ((dst->gg_ft_ip_address == packet->iph->saddr && dst->gg_ft_port == packet->tcp->source)
- || (dst->gg_ft_ip_address == packet->iph->daddr && dst->gg_ft_port == packet->tcp->dest))) {
- if ((packet->tick_timestamp - dst->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "file transfer detected %d\n", ntohs(packet->tcp->dest));
- return;
- } else {
- dst->gg_ft_ip_address = 0;
- dst->gg_ft_port = 0;
- }
- } else if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (dst->detected_protocol_bitmask, NDPI_PROTOCOL_GADUGADU) != 0 && (packet->tcp->dest == htons(80)
- || packet->tcp->source ==
- htons(80))
- && packet->payload_packet_len == 12 && (memcmp(dst->gg_call_id[0], &packet->payload[0], 4) == 0
- || (dst->gg_call_id[1][0]
- && (memcmp(dst->gg_call_id[1], &packet->payload[0], 4)
- == 0)))) {
- if ((packet->tick_timestamp - dst->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "http file transfer detetced \n");
- return;
- } else {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, "http file transfer timeout \n");
-
-
- }
-
- } else if (NDPI_COMPARE_PROTOCOL_TO_BITMASK
- (dst->detected_protocol_bitmask,
- NDPI_PROTOCOL_GADUGADU) != 0
- && packet->payload_packet_len == 8 &&
- (memcmp(dst->gg_call_id[0], &packet->payload[0], 4) == 0 || (dst->gg_call_id[1][0]
- &&
- (memcmp
- (dst->gg_call_id[1],
- &packet->payload[0], 4)
- == 0)))) {
- if ((packet->tick_timestamp - dst->gg_timeout) < ndpi_struct->gadugadu_peer_connection_timeout) {
-
- ndpi_int_gadugadu_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
-
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct,
- NDPI_LOG_DEBUG, "file transfer detected %d\n", ntohs(packet->tcp->dest));
- return;
- } else {
- NDPI_LOG(NDPI_PROTOCOL_GADUGADU, ndpi_struct, NDPI_LOG_DEBUG, " file transfer timeout \n");
- }
- }
- }
- /** newly added start **/
- if (packet->tcp != NULL && ((ntohs(packet->tcp->dest) == 80) || (ntohs(packet->tcp->source) == 80))) {
- if (check_for_gadugadu_payload_pattern(ndpi_struct, flow)) {
- return;
- }
- }
-
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GADUGADU);
-
-}
-
-void ndpi_search_gadugadu(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- ndpi_search_gadugadu_tcp(ndpi_struct, flow);
-}
-#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/http.c
^
|
@@ -480,6 +480,20 @@
}
#endif
+static void setHttpUserAgent(struct ndpi_flow_struct *flow, char *ua) {
+ if(!strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000";
+ else if(!strcmp(ua, "Windows NT 5.1")) ua = "Windows XP";
+ else if(!strcmp(ua, "Windows NT 5.2")) ua = "Windows Server 2003";
+ else if(!strcmp(ua, "Windows NT 6.0")) ua = "Windows Vista";
+ else if(!strcmp(ua, "Windows NT 7.0")) ua = "Windows 7";
+ else if(!strcmp(ua, "Windows NT 6.1")) ua = "Windows 7";
+ else if(!strcmp(ua, "Windows NT 6.2")) ua = "Windows 8";
+ else if(!strcmp(ua, "Windows NT 6.3")) ua = "Windows 8.1";
+
+ //printf("==> %s\n", ua);
+ snprintf((char*)flow->detected_os, sizeof(flow->detected_os), "%s", ua);
+}
+
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
// int i = 0;
struct ndpi_packet_struct *packet = &flow->packet;
@@ -509,10 +523,17 @@
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP) {
/* Try matching subprotocols */
- ndpi_match_string_subprotocol(ndpi_struct, flow, (char*)packet->host_line.ptr, packet->host_line.len);
+ // ndpi_match_string_subprotocol(ndpi_struct, flow, (char*)packet->host_line.ptr, packet->host_line.len);
+ ndpi_match_string_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name, strlen((const char *)flow->host_server_name));
}
}
+/*
+ NOTE
+
+ ndpi_parse_packet_line_info @ ndpi_main.c
+ is the code that parses the packet
+ */
static void check_content_type_and_change_protocol(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
@@ -572,6 +593,64 @@
}
/* check user agent here too */
if (packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {
+ /* Format:
+ Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ....
+ */
+ if(packet->user_agent_line.len > 7) {
+ char ua[256];
+ u_int mlen = ndpi_min(packet->user_agent_line.len, sizeof(ua)-1);
+
+ strncpy(ua, (const char *)packet->user_agent_line.ptr, mlen);
+ ua[mlen] = '\0';
+
+ if(strncmp(ua, "Mozilla", 7) == 0) {
+ char *parent = strchr(ua, '(');
+
+ if(parent) {
+ char *token, *end;
+
+ parent++;
+ end = strchr(parent, ')');
+ if(end) end[0] = '\0';
+
+ token = strsep(&parent, ";");
+ if(token) {
+ if((strcmp(token, "X11") == 0)
+ || (strcmp(token, "compatible") == 0)
+ || (strcmp(token, "Linux") == 0)
+ || (strcmp(token, "Macintosh") == 0)
+ ) {
+ token = strsep(&parent, ";");
+ if(token && (token[0] == ' ')) token++; /* Skip space */
+
+ if(token
+ && ((strcmp(token, "U") == 0)
+ || (strncmp(token, "MSIE", 4) == 0))) {
+ token = strsep(&parent, ";");
+ if(token && (token[0] == ' ')) token++; /* Skip space */
+
+ if(token && (strncmp(token, "Update", 6) == 0)) {
+ token = strsep(&parent, ";");
+
+ if(token && (token[0] == ' ')) token++; /* Skip space */
+
+ if(token && (strncmp(token, "AOL", 3) == 0)) {
+ token = strsep(&parent, ";");
+
+ if(token && (token[0] == ' ')) token++; /* Skip space */
+ }
+ }
+ }
+ }
+
+ if(token) {
+ setHttpUserAgent(flow, token);
+ }
+ }
+ }
+ }
+ }
+
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "User Agent Type Line found %.*s\n",
packet->user_agent_line.len, packet->user_agent_line.ptr);
#ifdef NDPI_PROTOCOL_XBOX
@@ -602,7 +681,7 @@
/* Copy result for nDPI apps */
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
- strncpy((const char*)flow->host_server_name, (const char*)packet->host_line.ptr, len);
+ strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
flow->host_server_name[len] = '\0';
parseHttpSubprotocol(ndpi_struct, flow);
|
[-]
[+]
|
Deleted |
nDPI.tar.bz2/src/lib/protocols/i23v5.c
^
|
@@ -1,94 +0,0 @@
-/*
- * i23v5.c
- *
- * Copyright (C) 2009-2011 by ipoque GmbH
- * Copyright (C) 2011-13 - ntop.org
- *
- * This file is part of nDPI, an open source deep packet inspection
- * library based on the OpenDPI and PACE technology by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "ndpi_protocols.h"
-#ifdef NDPI_PROTOCOL_I23V5
-
-
-static void ndpi_i23v5_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
-
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_I23V5, NDPI_REAL_PROTOCOL);
-}
-
-void ndpi_search_i23v5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
-
-// struct ndpi_id_struct *src=ndpi_struct->src;
-// struct ndpi_id_struct *dst=ndpi_struct->dst;
-
- u_int32_t i;
- u_int32_t sum;
-
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "search i23v5.\n");
-
- /*
- * encryption of i23v5 is tricky: the 7th bit of the first byte and the sescond bit of the second byte must be set.
- * Three lengths are written in three packets after 0x0d58, 0x0e58 and 0x0f58 but without a certain order.
- * The sum of the three packets is in another packet at any place.
- */
-
- if (packet->payload_packet_len > 7 && ((packet->payload[0] & 0x04) == 0x04 && (packet->payload[2] & 0x80) == 0x80)) {
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "found i23v5 handshake bits.\n");
-
- for (i = 3; i < packet->payload_packet_len - 5; i++) {
- if (packet->payload[i] == 0x0d && packet->payload[i + 1] == 0x58) {
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "found first i23v5 key len.\n");
- flow->i23v5_len1 = get_u_int32_t(packet->payload, i + 2);
- return;
- }
- }
- for (i = 3; i < packet->payload_packet_len - 5; i++) {
- if (packet->payload[i] == 0x0e && packet->payload[i + 1] == 0x58) {
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "found second i23v5 key len.\n");
- flow->i23v5_len2 = get_u_int32_t(packet->payload, i + 2);
- return;
- }
- }
- for (i = 3; i < packet->payload_packet_len - 5; i++) {
- if (packet->payload[i] == 0x0f && packet->payload[i + 1] == 0x58) {
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "found third i23v5 key len.\n");
- flow->i23v5_len3 = get_u_int32_t(packet->payload, i + 2);
- return;
- }
- }
- if (flow->i23v5_len1 != 0 && flow->i23v5_len2 != 0 && flow->i23v5_len3 != 0) {
- for (i = 3; i < packet->payload_packet_len - 5; i++) {
- sum = flow->i23v5_len1 + flow->i23v5_len2 + flow->i23v5_len3;
- if (get_u_int32_t(packet->payload, i) == sum) {
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "key sum matches.\n");
- ndpi_i23v5_add_connection(ndpi_struct, flow);
- }
-
- }
- }
- }
-
- NDPI_LOG(NDPI_PROTOCOL_I23V5, ndpi_struct, NDPI_LOG_DEBUG, "exclude i23v5.\n");
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_I23V5);
-}
-
-#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/imesh.c
^
|
@@ -37,253 +37,254 @@
void ndpi_search_imesh_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
- struct ndpi_packet_struct *packet = &flow->packet;
+ struct ndpi_packet_struct *packet = &flow->packet;
- if (packet->udp != NULL) {
+ if (packet->udp != NULL) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "UDP FOUND\n");
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "UDP FOUND\n");
- // this is the login packet
- if (packet->payload_packet_len == 28 && (get_u_int32_t(packet->payload, 0)) == htonl(0x02000000) &&
- get_u_int32_t(packet->payload, 24) == 0 &&
- (packet->udp->dest == htons(1864) || packet->udp->source == htons(1864))) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh Login detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (packet->payload_packet_len == 36) {
- if (get_u_int32_t(packet->payload, 0) == htonl(0x02000000) && packet->payload[4] != 0 &&
- packet->payload[5] == 0 && get_u_int16_t(packet->payload, 6) == htons(0x0083) &&
- get_u_int32_t(packet->payload, 24) == htonl(0x40000000) &&
- (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
- packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5]
- || packet->payload[packet->payload_packet_len - 1] ==
- packet->payload[packet->payload_packet_len - 5] - 1)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (get_u_int16_t(packet->payload, 0) == htons(0x0200) && get_u_int16_t(packet->payload, 2) != 0 &&
- get_u_int32_t(packet->payload, 4) == htonl(0x02000083) && get_u_int32_t(packet->payload, 24) == htonl(0x40000000) &&
- (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
- packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5]
- || packet->payload[packet->payload_packet_len - 1] ==
- packet->payload[packet->payload_packet_len - 5] - 1)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- }
- if (packet->payload_packet_len == 24 && get_u_int16_t(packet->payload, 0) == htons(0x0200)
- && get_u_int16_t(packet->payload, 2) != 0 && get_u_int32_t(packet->payload, 4) == htonl(0x03000084) &&
- (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
- packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5] ||
- packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] - 1)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (packet->payload_packet_len == 32 && get_u_int32_t(packet->payload, 0) == htonl(0x02000000) &&
- get_u_int16_t(packet->payload, 21) == 0 && get_u_int16_t(packet->payload, 26) == htons(0x0100)) {
- if (get_u_int32_t(packet->payload, 4) == htonl(0x00000081) && packet->payload[11] == packet->payload[15] &&
- get_l16(packet->payload, 24) == htons(packet->udp->source)) {
- /* packet->payload[28] = source address */
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (get_u_int32_t(packet->payload, 4) == htonl(0x01000082)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- }
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh UDP packetlen: %d\n",
- packet->payload_packet_len);
-
- }
-
- if (packet->tcp != NULL) {
-
- if (packet->payload_packet_len == 64 && get_u_int32_t(packet->payload, 0) == htonl(0x40000000) &&
- get_u_int32_t(packet->payload, 4) == 0 && get_u_int32_t(packet->payload, 8) == htonl(0x0000fcff) &&
- get_u_int32_t(packet->payload, 12) == htonl(0x04800100) && get_u_int32_t(packet->payload, 45) == htonl(0xff020000) &&
- get_u_int16_t(packet->payload, 49) == htons(0x001a)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (packet->payload_packet_len == 95 && get_u_int32_t(packet->payload, 0) == htonl(0x5f000000) &&
- get_u_int16_t(packet->payload, 4) == 0 && get_u_int16_t(packet->payload, 7) == htons(0x0004) &&
- get_u_int32_t(packet->payload, 20) == 0 && get_u_int32_t(packet->payload, 28) == htonl(0xc8000400) &&
- packet->payload[9] == 0x80 && get_u_int32_t(packet->payload, 10) == get_u_int32_t(packet->payload, 24)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- if (packet->payload_packet_len == 28 && get_u_int32_t(packet->payload, 0) == htonl(0x1c000000) &&
- get_u_int16_t(packet->payload, 10) == htons(0xfcff) && get_u_int32_t(packet->payload, 12) == htonl(0x07801800) &&
- (get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == htons(0x1900) ||
- get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == htons(0x1a00))) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
-
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "TCP FOUND :: Payload %u\n",
- packet->payload_packet_len);
-
- if (packet->actual_payload_len == 0) {
- return;
- }
- if ((packet->actual_payload_len == 8 || packet->payload_packet_len == 10) /* PATTERN:: 04 00 00 00 00 00 00 00 [00 00] */
- &&get_u_int32_t(packet->payload, 0) == htonl(0x04000000)
- && get_u_int32_t(packet->payload, 4) == 0) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 10 /* PATTERN:: ?? ?? 04|00 00 64|00 00 */
- && (packet->payload[2] == 0x04 || packet->payload[2] == 0x00)
- && packet->payload[3] == 0x00 && (packet->payload[4] == 0x00 || packet->payload[4] == 0x64)
- && packet->payload[5] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 2 && packet->payload[0] == 0x06 && packet->payload[1] == 0x00) {
- flow->l4.tcp.imesh_stage++;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 04|00 00 01|00 00 01|00 00 ?? 00 */
- && packet->payload[0] == 0x06
- && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x00)
- && packet->payload[3] == 0x00 && (packet->payload[4] == 0x00 || packet->payload[4] == 0x01)
- && packet->payload[5] == 0x00 && (packet->payload[6] == 0x01 || packet->payload[6] == 0x00)
- && packet->payload[7] == 0x00 && packet->payload[9] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 24 && packet->payload[0] == 0x06 // PATTERN :: 06 00 12 00 00 00 34 00 00
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x12
- && packet->payload[3] == 0x00
- && packet->payload[4] == 0x00
- && packet->payload[5] == 0x00
- && packet->payload[6] == 0x34 && packet->payload[7] == 0x00 && packet->payload[8] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 8 /* PATTERN:: 06|00 00 02 00 00 00 33 00 */
- && (packet->payload[0] == 0x06 || packet->payload[0] == 0x00)
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x02
- && packet->payload[3] == 0x00
- && packet->payload[4] == 0x00
- && packet->payload[5] == 0x00 && packet->payload[6] == 0x33 && packet->payload[7] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->payload_packet_len == 6 /* PATTERN:: 02 00 00 00 33 00 */
- && packet->payload[0] == 0x02
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x00
- && packet->payload[3] == 0x00 && packet->payload[4] == 0x33 && packet->payload[5] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 12 && packet->payload[0] == 0x06 // PATTERN : 06 00 06 00 00 00 64 00
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x06
- && packet->payload[3] == 0x00
- && packet->payload[4] == 0x00
- && packet->payload[5] == 0x00 && packet->payload[6] == 0x64 && packet->payload[7] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 04|01 00 00 00 01|00 00 ?? 00 */
- && packet->payload[0] == 0x06
- && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x01)
- && packet->payload[3] == 0x00
- && packet->payload[4] == 0x00
- && packet->payload[5] == 0x00 && (packet->payload[6] == 0x01 || packet->payload[6] == 0x00)
- && packet->payload[7] == 0x00
- /* && packet->payload[8]==0x00 */
- && packet->payload[9] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if ((packet->actual_payload_len == 64 || packet->actual_payload_len == 52 /* PATTERN:: [len] 00 00 00 00 */
- || packet->actual_payload_len == 95)
- && get_u_int16_t(packet->payload, 0) == (packet->actual_payload_len)
- && packet->payload[1] == 0x00 && packet->payload[2] == 0x00
- && packet->payload[3] == 0x00 && packet->payload[4] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 6 && packet->payload[0] == 0x06 // PATTERN : 06 00 04|6c 00|01 00 00
- && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x6c)
- && (packet->payload[3] == 0x00 || packet->payload[3] == 0x01)
- && packet->payload[4] == 0x00 && packet->payload[5] == 0x00) {
-
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 6 /* PATTERN:: [len] ?? ee 00 00 00 */
- && get_u_int16_t(packet->payload, 0) == (packet->actual_payload_len)
- && packet->payload[2] == 0xee
- && packet->payload[3] == 0x00 && packet->payload[4] == 0x00 && packet->payload[5] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 00 00 00 00 00 00 */
- && packet->payload[0] == 0x06
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x00
- && packet->payload[3] == 0x00
- && packet->payload[4] == 0x00
- && packet->payload[5] == 0x00 && packet->payload[6] == 0x00 && packet->payload[7] == 0x00) {
- flow->l4.tcp.imesh_stage += 2;
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
- "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
- }
-
-
- /* http login */
- if (packet->payload_packet_len > NDPI_STATICSTRING_LEN("POST /registration") &&
- memcmp(packet->payload, "POST /registration", NDPI_STATICSTRING_LEN("POST /registration")) == 0) {
- ndpi_parse_packet_line_info(ndpi_struct, flow);
- if (packet->parsed_lines > 6 &&
- packet->host_line.ptr != NULL &&
- packet->host_line.len == NDPI_STATICSTRING_LEN("login.bearshare.com") &&
- packet->line[1].ptr != NULL &&
- packet->line[1].len == NDPI_STATICSTRING_LEN("Authorization: Basic Og==") &&
- packet->line[4].ptr != NULL &&
- packet->line[4].len == NDPI_STATICSTRING_LEN("Accept-Encoding: identity") &&
- memcmp(packet->line[1].ptr, "Authorization: Basic Og==",
- NDPI_STATICSTRING_LEN("Authorization: Basic Og==")) == 0 &&
- memcmp(packet->host_line.ptr, "login.bearshare.com",
- NDPI_STATICSTRING_LEN("login.bearshare.com")) == 0 &&
- memcmp(packet->line[4].ptr, "Accept-Encoding: identity",
- NDPI_STATICSTRING_LEN("Accept-Encoding: identity") == 0)) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh Login detected\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
- return;
- }
- }
- /*give one packet tolerance for detection */
- if (flow->l4.tcp.imesh_stage >= 4) {
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
- ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
- return;
- }
- }
-
- if ((flow->packet_counter < 5) || packet->actual_payload_len == 0) {
- return;
- }
- //imesh_not_found_end:
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IMESH);
- NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh excluded at stage %d\n",
- packet->tcp != NULL ? flow->l4.tcp.imesh_stage : 0);
+ // this is the login packet
+ if (packet->payload_packet_len == 28 && (get_u_int32_t(packet->payload, 0)) == htonl(0x02000000) &&
+ get_u_int32_t(packet->payload, 24) == 0 &&
+ (packet->udp->dest == htons(1864) || packet->udp->source == htons(1864))) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh Login detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (packet->payload_packet_len == 36) {
+ if (get_u_int32_t(packet->payload, 0) == htonl(0x02000000) && packet->payload[4] != 0 &&
+ packet->payload[5] == 0 && get_u_int16_t(packet->payload, 6) == htons(0x0083) &&
+ get_u_int32_t(packet->payload, 24) == htonl(0x40000000) &&
+ (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
+ packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5]
+ || packet->payload[packet->payload_packet_len - 1] ==
+ packet->payload[packet->payload_packet_len - 5] - 1)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (get_u_int16_t(packet->payload, 0) == htons(0x0200) && get_u_int16_t(packet->payload, 2) != 0 &&
+ get_u_int32_t(packet->payload, 4) == htonl(0x02000083) && get_u_int32_t(packet->payload, 24) == htonl(0x40000000) &&
+ (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
+ packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5]
+ || packet->payload[packet->payload_packet_len - 1] ==
+ packet->payload[packet->payload_packet_len - 5] - 1)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ }
+ if (packet->payload_packet_len == 24 && get_u_int16_t(packet->payload, 0) == htons(0x0200)
+ && get_u_int16_t(packet->payload, 2) != 0 && get_u_int32_t(packet->payload, 4) == htonl(0x03000084) &&
+ (packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] ||
+ packet->payload[packet->payload_packet_len - 1] - 1 == packet->payload[packet->payload_packet_len - 5] ||
+ packet->payload[packet->payload_packet_len - 1] == packet->payload[packet->payload_packet_len - 5] - 1)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (packet->payload_packet_len == 32 && get_u_int32_t(packet->payload, 0) == htonl(0x02000000) &&
+ get_u_int16_t(packet->payload, 21) == 0 && get_u_int16_t(packet->payload, 26) == htons(0x0100)) {
+ if (get_u_int32_t(packet->payload, 4) == htonl(0x00000081) && packet->payload[11] == packet->payload[15] &&
+ get_l16(packet->payload, 24) == htons(packet->udp->source)) {
+ /* packet->payload[28] = source address */
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (get_u_int32_t(packet->payload, 4) == htonl(0x01000082)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ }
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh UDP packetlen: %d\n",
+ packet->payload_packet_len);
+
+ }
+
+ if (packet->tcp != NULL) {
+ if (packet->payload_packet_len == 64 && get_u_int32_t(packet->payload, 0) == htonl(0x40000000) &&
+ get_u_int32_t(packet->payload, 4) == 0 && get_u_int32_t(packet->payload, 8) == htonl(0x0000fcff) &&
+ get_u_int32_t(packet->payload, 12) == htonl(0x04800100) && get_u_int32_t(packet->payload, 45) == htonl(0xff020000) &&
+ get_u_int16_t(packet->payload, 49) == htons(0x001a)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (packet->payload_packet_len == 95 && get_u_int32_t(packet->payload, 0) == htonl(0x5f000000) &&
+ get_u_int16_t(packet->payload, 4) == 0 && get_u_int16_t(packet->payload, 7) == htons(0x0004) &&
+ get_u_int32_t(packet->payload, 20) == 0 && get_u_int32_t(packet->payload, 28) == htonl(0xc8000400) &&
+ packet->payload[9] == 0x80 && get_u_int32_t(packet->payload, 10) == get_u_int32_t(packet->payload, 24)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ if (packet->payload_packet_len == 28 && get_u_int32_t(packet->payload, 0) == htonl(0x1c000000) &&
+ get_u_int16_t(packet->payload, 10) == htons(0xfcff) && get_u_int32_t(packet->payload, 12) == htonl(0x07801800) &&
+ (get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == htons(0x1900) ||
+ get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == htons(0x1a00))) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "TCP FOUND :: Payload %u\n",
+ packet->payload_packet_len);
+
+ if (packet->actual_payload_len == 0) {
+ return;
+ }
+ if ((packet->actual_payload_len == 8 || packet->payload_packet_len == 10) /* PATTERN:: 04 00 00 00 00 00 00 00 [00 00] */
+ &&get_u_int32_t(packet->payload, 0) == htonl(0x04000000)
+ && get_u_int32_t(packet->payload, 4) == 0) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 10 /* PATTERN:: ?? ?? 04|00 00 64|00 00 */
+ && (packet->payload[2] == 0x04 || packet->payload[2] == 0x00)
+ && packet->payload[3] == 0x00 && (packet->payload[4] == 0x00 || packet->payload[4] == 0x64)
+ && packet->payload[5] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 2 && packet->payload[0] == 0x06 && packet->payload[1] == 0x00) {
+ flow->l4.tcp.imesh_stage++;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 04|00 00 01|00 00 01|00 00 ?? 00 */
+ && packet->payload[0] == 0x06
+ && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x00)
+ && packet->payload[3] == 0x00 && (packet->payload[4] == 0x00 || packet->payload[4] == 0x01)
+ && packet->payload[5] == 0x00 && (packet->payload[6] == 0x01 || packet->payload[6] == 0x00)
+ && packet->payload[7] == 0x00 && packet->payload[9] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 24 && packet->payload[0] == 0x06 // PATTERN :: 06 00 12 00 00 00 34 00 00
+ && packet->payload[1] == 0x00
+ && packet->payload[2] == 0x12
+ && packet->payload[3] == 0x00
+ && packet->payload[4] == 0x00
+ && packet->payload[5] == 0x00
+ && packet->payload[6] == 0x34 && packet->payload[7] == 0x00 && packet->payload[8] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 8 /* PATTERN:: 06|00 00 02 00 00 00 33 00 */
+ && (packet->payload[0] == 0x06 || packet->payload[0] == 0x00)
+ && packet->payload[1] == 0x00
+ && packet->payload[2] == 0x02
+ && packet->payload[3] == 0x00
+ && packet->payload[4] == 0x00
+ && packet->payload[5] == 0x00 && packet->payload[6] == 0x33 && packet->payload[7] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->payload_packet_len == 6 /* PATTERN:: 02 00 00 00 33 00 */
+ && packet->payload[0] == 0x02
+ && packet->payload[1] == 0x00
+ && packet->payload[2] == 0x00
+ && packet->payload[3] == 0x00 && packet->payload[4] == 0x33 && packet->payload[5] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 12 && packet->payload[0] == 0x06 // PATTERN : 06 00 06 00 00 00 64 00
+ && packet->payload[1] == 0x00
+ && packet->payload[2] == 0x06
+ && packet->payload[3] == 0x00
+ && packet->payload[4] == 0x00
+ && packet->payload[5] == 0x00 && packet->payload[6] == 0x64 && packet->payload[7] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 04|01 00 00 00 01|00 00 ?? 00 */
+ && packet->payload[0] == 0x06
+ && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x01)
+ && packet->payload[3] == 0x00
+ && packet->payload[4] == 0x00
+ && packet->payload[5] == 0x00 && (packet->payload[6] == 0x01 || packet->payload[6] == 0x00)
+ && packet->payload[7] == 0x00
+ /* && packet->payload[8]==0x00 */
+ && packet->payload[9] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if ((packet->actual_payload_len == 64 || packet->actual_payload_len == 52 /* PATTERN:: [len] 00 00 00 00 */
+ || packet->actual_payload_len == 95)
+ && get_u_int16_t(packet->payload, 0) == (packet->actual_payload_len)
+ && packet->payload[1] == 0x00 && packet->payload[2] == 0x00
+ && packet->payload[3] == 0x00 && packet->payload[4] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 6 && packet->payload[0] == 0x06 // PATTERN : 06 00 04|6c 00|01 00 00
+ && packet->payload[1] == 0x00 && (packet->payload[2] == 0x04 || packet->payload[2] == 0x6c)
+ && (packet->payload[3] == 0x00 || packet->payload[3] == 0x01)
+ && packet->payload[4] == 0x00 && packet->payload[5] == 0x00) {
+
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 6 /* PATTERN:: [len] ?? ee 00 00 00 */
+ && get_u_int16_t(packet->payload, 0) == (packet->actual_payload_len)
+ && packet->payload[2] == 0xee
+ && packet->payload[3] == 0x00 && packet->payload[4] == 0x00 && packet->payload[5] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ } else if (packet->actual_payload_len == 10 /* PATTERN:: 06 00 00 00 00 00 00 00 */
+ && packet->payload[0] == 0x06
+ && packet->payload[1] == 0x00
+ && packet->payload[2] == 0x00
+ && packet->payload[3] == 0x00
+ && packet->payload[4] == 0x00
+ && packet->payload[5] == 0x00 && packet->payload[6] == 0x00 && packet->payload[7] == 0x00) {
+ flow->l4.tcp.imesh_stage += 2;
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG,
+ "IMESH FOUND :: Payload %u\n", packet->actual_payload_len);
+ }
+
+
+ /* http login */
+ if (packet->payload_packet_len > NDPI_STATICSTRING_LEN("POST /registration") &&
+ memcmp(packet->payload, "POST /registration", NDPI_STATICSTRING_LEN("POST /registration")) == 0) {
+ ndpi_parse_packet_line_info(ndpi_struct, flow);
+ if (packet->parsed_lines > 6 &&
+ packet->host_line.ptr != NULL &&
+ packet->host_line.len == NDPI_STATICSTRING_LEN("login.bearshare.com") &&
+ packet->line[1].ptr != NULL &&
+ packet->line[1].len == NDPI_STATICSTRING_LEN("Authorization: Basic Og==") &&
+ packet->line[4].ptr != NULL &&
+ packet->line[4].len == NDPI_STATICSTRING_LEN("Accept-Encoding: identity") &&
+ memcmp(packet->line[1].ptr, "Authorization: Basic Og==",
+ NDPI_STATICSTRING_LEN("Authorization: Basic Og==")) == 0 &&
+ memcmp(packet->host_line.ptr, "login.bearshare.com",
+ NDPI_STATICSTRING_LEN("login.bearshare.com")) == 0 &&
+ memcmp(packet->line[4].ptr, "Accept-Encoding: identity",
+ NDPI_STATICSTRING_LEN("Accept-Encoding: identity") == 0)) {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh Login detected\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_CORRELATED_PROTOCOL);
+ return;
+ }
+ }
+ /*give one packet tolerance for detection */
+ if((flow->l4.tcp.imesh_stage >= 4)
+ && (flow->l4.tcp.seen_syn && flow->l4.tcp.seen_syn_ack && flow->l4.tcp.seen_ack) /* We have seen the 3-way handshake */)
+ {
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "found imesh.\n");
+ ndpi_int_imesh_add_connection(ndpi_struct, flow, NDPI_REAL_PROTOCOL);
+ return;
+ }
+ }
+
+ if ((flow->packet_counter < 5) || packet->actual_payload_len == 0) {
+ return;
+ }
+ //imesh_not_found_end:
+ NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IMESH);
+ NDPI_LOG(NDPI_PROTOCOL_IMESH, ndpi_struct, NDPI_LOG_DEBUG, "iMesh excluded at stage %d\n",
+ packet->tcp != NULL ? flow->l4.tcp.imesh_stage : 0);
}
#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/netflow.c
^
|
@@ -24,6 +24,9 @@
#ifdef NDPI_PROTOCOL_NETFLOW
#ifndef __KERNEL__
+#ifdef WIN32
+extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
+#endif
#define do_gettimeofday(a) gettimeofday(a, NULL)
#endif
|
[-]
[+]
|
Deleted |
nDPI.tar.bz2/src/lib/protocols/pando.c
^
|
@@ -1,102 +0,0 @@
-/*
- * pando.c
- *
- * Copyright (C) 2009-2011 by ipoque GmbH
- * Copyright (C) 2011-13 - ntop.org
- *
- * This file is part of nDPI, an open source deep packet inspection
- * library based on the OpenDPI and PACE technology by ipoque GmbH
- *
- * nDPI is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * nDPI is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#include "ndpi_protocols.h"
-
-#ifdef NDPI_PROTOCOL_PANDO
-
-static void ndpi_int_pando_add_connection(struct ndpi_detection_module_struct
- *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_PANDO, NDPI_REAL_PROTOCOL);
-}
-
-
-#if !defined(WIN32)
-static inline
-#else
-__forceinline static
-#endif
-u_int8_t search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- struct ndpi_packet_struct *packet = &flow->packet;
- // struct ndpi_flow_struct *flow=ndpi_struct->flow;
- // struct ndpi_id_struct *src=ndpi_struct->src;
- // struct ndpi_id_struct *dst=ndpi_struct->dst;
-
- if (packet->tcp != NULL) {
-
- if (packet->payload_packet_len == 63 && memcmp(&packet->payload[1], "Pando protocol", 14) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Pando download detected\n");
- goto end_pando_found;
- }
-
- } else if (packet->udp != NULL) {
- if (packet->payload_packet_len > 20
- && packet->payload_packet_len < 100
- && packet->payload[0] == 0x00
- && packet->payload[1] == 0x00
- && packet->payload[2] == 0x00
- && packet->payload[3] == 0x09 && packet->payload[4] == 0x00 && packet->payload[5] == 0x00) {
- // bypass the detection because one packet has at a specific place the word Pando in it
- if (packet->payload_packet_len == 87 && memcmp(&packet->payload[25], "Pando protocol", 14) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG,
- "Pando UDP packet detected --> Pando in payload\n");
- goto end_pando_found;
- } else if (packet->payload_packet_len == 92 && memcmp(&packet->payload[72], "Pando", 5) == 0) {
- NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG,
- "Pando UDP packet detected --> Pando in payload\n");
- goto end_pando_found;
- }
- goto end_pando_maybe_found;
- }
- }
-
- goto end_pando_nothing_found;
-
- end_pando_found:
- ndpi_int_pando_add_connection(ndpi_struct, flow);
- return 1;
-
- end_pando_maybe_found:
- return 2;
-
- end_pando_nothing_found:
- return 0;
-}
-
-void ndpi_search_pando_tcp_udp(struct ndpi_detection_module_struct
- *ndpi_struct, struct ndpi_flow_struct *flow)
-{
- // struct ndpi_packet_struct *packet=&flow->packet;
- // struct ndpi_id_struct *src=ndpi_struct->src;
- // struct ndpi_id_struct *dst=ndpi_struct->dst;
-
- if (search_pando(ndpi_struct, flow) != 0)
- return;
-
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_PANDO);
-}
-#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/rtcp.c
^
|
@@ -38,10 +38,10 @@
} else if(packet->udp != NULL) {
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "calculating dport over udp.\n");
- if((packet->payload_packet_len >= 28 || packet->payload_packet_len <= 1200) &&
- ((packet->payload[0] == 0x80) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9)) && (packet->payload[2] == 0x00))
- || ((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
- && (packet->payload[2] == 0x00))) {
+ if(((packet->payload_packet_len >= 28 || packet->payload_packet_len <= 1200) &&
+ ((packet->payload[0] == 0x80) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9)) && (packet->payload[2] == 0x00)))
+ || (((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
+ && (packet->payload[2] == 0x00)))) {
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "found rtcp.\n");
ndpi_int_rtcp_add_connection(ndpi_struct, flow);
}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/rtp.c
^
|
@@ -31,13 +31,16 @@
struct ndpi_flow_struct *flow,
const u_int8_t * payload, const u_int16_t payload_len)
{
- struct ndpi_packet_struct *packet = &flow->packet;
+ //struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t payload_type = payload[1] & 0x7F;
-
+ u_int32_t *ssid = (u_int32_t*)&payload[8];
+
/* Check whether this is an RTP flow */
if((payload_len >= 12)
&& ((payload[0] & 0xFF) == 0x80) /* RTP magic byte[1] */
- && ((payload_type <= 34 /* PT_H263 */))) {
+ && ((payload_type < 128 /* http://anonsvn.wireshark.org/wireshark/trunk/epan/dissectors/packet-rtp.c */))
+ && (*ssid != 0)
+ ) {
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "Found rtp.\n");
ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_RTP, NDPI_REAL_PROTOCOL);
} else {
@@ -50,7 +53,10 @@
{
struct ndpi_packet_struct *packet = &flow->packet;
- ndpi_rtp_search(ndpi_struct, flow, packet->payload, packet->payload_packet_len);
+ if((packet->udp != NULL)
+ && (ntohs(packet->udp->source) > 1023)
+ && (ntohs(packet->udp->dest) > 1023))
+ ndpi_rtp_search(ndpi_struct, flow, packet->payload, packet->payload_packet_len);
}
#if 0
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/skinny.c
^
|
@@ -43,16 +43,15 @@
if(packet->tcp != NULL) {
sport = ntohs(packet->tcp->source), dport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_SKINNY, ndpi_struct, NDPI_LOG_DEBUG, "calculating SKINNY over tcp.\n");
- if (dport == 2000 && (packet->payload_packet_len == 24 &&
- memcmp(&packet->payload[0], keypadmsg_8_bytes, 8) == 0) ||
- (packet->payload_packet_len == 64 &&
- memcmp(&packet->payload[0], pattern_8_bytes, 8) == 0)) {
+ if (dport == 2000 && ((packet->payload_packet_len == 24 &&
+ memcmp(&packet->payload[0], keypadmsg_8_bytes, 8) == 0)
+ || ((packet->payload_packet_len == 64) && memcmp(&packet->payload[0], pattern_8_bytes, 8) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_SKINNY, ndpi_struct, NDPI_LOG_DEBUG, "found skinny.\n");
ndpi_int_skinny_add_connection(ndpi_struct, flow);
- } else if (sport == 2000 && (packet->payload_packet_len == 28 &&
+ } else if (sport == 2000 && ((packet->payload_packet_len == 28 &&
memcmp(&packet->payload[0], selectmsg_8_bytes, 8) == 0 ) ||
(packet->payload_packet_len == 44 &&
- memcmp(&packet->payload[0], pattern_9_bytes, 9) == 0 )) {
+ memcmp(&packet->payload[0], pattern_9_bytes, 9) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_SKINNY, ndpi_struct, NDPI_LOG_DEBUG, "found skinny.\n");
ndpi_int_skinny_add_connection(ndpi_struct, flow);
}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/skype.c
^
|
@@ -23,7 +23,6 @@
#ifdef NDPI_PROTOCOL_SKYPE
-#if 0
static u_int is_private_addr(u_int32_t addr) {
addr = ntohl(addr);
@@ -36,11 +35,68 @@
else
return(0);
}
+
+static u_int64_t get_skype_key(u_int32_t src_host, u_int32_t dst_host) {
+ u_int64_t key;
+
+ if(src_host < dst_host) {
+ key = src_host;
+ key = (key << 32)+dst_host;
+ } else {
+ key = dst_host;
+ key = (key << 32)+src_host;
+ }
+
+ return(key);
+}
+
+u_int8_t is_skype_connection(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t src_host, u_int32_t dst_host) {
+ u_int64_t key = get_skype_key(src_host, dst_host);
+ int rc;
+
+#ifndef __KERNEL__
+ pthread_mutex_lock(&ndpi_struct->skypeCacheLock);
+#else
+ spin_lock_bh(&ndpi_struct->skypeCacheLock);
+#endif
+ rc = (u_int8_t)ndpi_find_lru_cache_num(&ndpi_struct->skypeCache, key);
+#ifndef __KERNEL__
+ pthread_mutex_unlock(&ndpi_struct->skypeCacheLock);
+#else
+ spin_unlock_bh(&ndpi_struct->skypeCacheLock);
+#endif
+
+ return(rc == 1 ? 1 : 0);
+}
+
+void add_skype_connection(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t src_host, u_int32_t dst_host) {
+ u_int64_t key;
+
+ if(is_private_addr(ntohl(src_host)) && is_private_addr(ntohl(dst_host)))
+ return;
+
+ key = get_skype_key(src_host, dst_host);
+
+#ifndef __KERNEL__
+ pthread_mutex_lock(&ndpi_struct->skypeCacheLock);
+#else
+ spin_lock_bh(&ndpi_struct->skypeCacheLock);
+#endif
+
+ ndpi_add_to_lru_cache_num(&ndpi_struct->skypeCache, key, 1);
+
+#ifndef __KERNEL__
+ pthread_mutex_unlock(&ndpi_struct->skypeCacheLock);
+#else
+ spin_unlock_bh(&ndpi_struct->skypeCacheLock);
#endif
+}
static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
- struct ndpi_packet_struct *packet = &flow->packet;
+ struct ndpi_packet_struct *packet = &flow->packet;
// const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len;
@@ -52,19 +108,31 @@
packet->payload[3] & 0xFF);
#endif
+ /*
+ Skype AS8220
+ 212.161.8.0/24
+ */
+ if(((ntohl(packet->iph->saddr) & 0xFFFFFF00 /* 255.255.255.0 */) == 0xD4A10800 /* 212.161.8.0 */)
+ || ((ntohl(packet->iph->daddr) & 0xFFFFFF00 /* 255.255.255.0 */) == 0xD4A10800 /* 212.161.8.0 */)
+ || is_skype_connection(ndpi_struct, packet->iph->saddr, packet->iph->daddr)) {
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_REAL_PROTOCOL);
+ return;
+ }
+
if(packet->udp != NULL) {
flow->l4.udp.skype_packet_id++;
if(flow->l4.udp.skype_packet_id < 5) {
/* skype-to-skype */
if(((payload_len == 3) && ((packet->payload[2] & 0x0F)== 0x0d))
- || ((payload_len >= 16)
+ || ((payload_len >= 16)
&& (packet->payload[0] != 0x30) /* Avoid invalid SNMP detection */
&& (packet->payload[2] == 0x02))) {
NDPI_LOG(NDPI_PROTOCOL_SKYPE, ndpi_struct, NDPI_LOG_DEBUG, "Found skype.\n");
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_REAL_PROTOCOL);
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_REAL_PROTOCOL);
+ add_skype_connection(ndpi_struct, packet->iph->saddr, packet->iph->daddr);
}
-
+
return;
}
@@ -83,6 +151,7 @@
if((payload_len == 8) || (payload_len == 3)) {
NDPI_LOG(NDPI_PROTOCOL_SKYPE, ndpi_struct, NDPI_LOG_DEBUG, "Found skype.\n");
ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_REAL_PROTOCOL);
+ add_skype_connection(ndpi_struct, packet->iph->saddr, packet->iph->daddr);
}
/* printf("[SKYPE] [id: %u][len: %d]\n", flow->l4.tcp.skype_packet_id, payload_len); */
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/ssl.c
^
|
@@ -35,6 +35,28 @@
if (protocol != NDPI_PROTOCOL_SSL) {
ndpi_int_add_connection(ndpi_struct, flow, protocol, NDPI_CORRELATED_PROTOCOL);
} else {
+ struct ndpi_packet_struct *packet = &flow->packet;
+
+ if(packet->tcp != NULL) {
+ switch(protocol) {
+ case NDPI_PROTOCOL_SSL:
+ case NDPI_PROTOCOL_SSL_NO_CERT:
+ {
+ /*
+ In case of SSL there are probably sub-protocols
+ such as IMAPS that can be otherwise detected
+ */
+ u_int16_t sport = ntohs(packet->tcp->source);
+ u_int16_t dport = ntohs(packet->tcp->dest);
+
+ if((sport == 465) || (dport == 465)) protocol = NDPI_PROTOCOL_MAIL_SMTPS;
+ else if((sport == 993) || (dport == 993)) protocol = NDPI_PROTOCOL_MAIL_IMAPS;
+ else if((sport == 995) || (dport == 995)) protocol = NDPI_PROTOCOL_MAIL_POPS;
+ }
+ break;
+ }
+ }
+
ndpi_int_add_connection(ndpi_struct, flow, protocol, NDPI_REAL_PROTOCOL);
}
}
@@ -48,7 +70,7 @@
#define ndpi_ispunct(ch) (((ch) >= '!' && (ch) <= '/') || \
((ch) >= ':' && (ch) <= '@') || \
((ch) >= '[' && (ch) <= '`') || \
- ((ch) >= '{' && (ch) <= '~'))
+ ((ch) >= '{' && (ch) <= '~'))
static void stripCertificateTrailer(char *buffer, int buffer_len) {
int i;
@@ -80,6 +102,7 @@
int i;
if(handshake_protocol == 0x02 /* Server Hello */) {
+ flow->l4.tcp.ssl_seen_server_cert = 1;
for(i=total_len; i < packet->payload_packet_len-3; i++) {
if((packet->payload[i] == 0x04)
@@ -128,7 +151,9 @@
if((session_id_len+base_offset+2) <= total_len) {
u_int16_t cypher_len = packet->payload[session_id_len+base_offset+2] + (packet->payload[session_id_len+base_offset+1] << 8);
offset = base_offset + session_id_len + cypher_len + 2;
-
+
+ flow->l4.tcp.ssl_seen_client_cert = 1;
+
if(offset < total_len) {
u_int16_t compression_len;
u_int16_t extensions_len;
@@ -166,7 +191,7 @@
break;
}
- len = ndpi_min(extension_len-begin, buffer_len-1);
+ len = (u_int)ndpi_min(extension_len-begin, buffer_len-1);
strncpy(buffer, &server_name[begin], len);
buffer[len] = '\0';
stripCertificateTrailer(buffer, buffer_len);
@@ -197,12 +222,20 @@
|| (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL)) {
char certificate[64];
int rc = getSSLcertificate(ndpi_struct, flow, certificate, sizeof(certificate));
-
+
+ packet->ssl_certificate_num_checks++;
+
if(rc > 0) {
- /* printf("***** [SSL] %s\n", certificate); */
+ packet->ssl_certificate_detected = 1;
+ // printf("***** [SSL] %s\n", certificate);
if(ndpi_match_string_subprotocol(ndpi_struct, flow, certificate, strlen(certificate)) != NDPI_PROTOCOL_UNKNOWN)
return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
- }
+ }
+
+ if((packet->ssl_certificate_num_checks >= 2)
+ && (certificate[0] != '\0')
+ && flow->l4.tcp.seen_syn && flow->l4.tcp.seen_syn_ack && flow->l4.tcp.seen_ack) /* We have seen the 3-way handshake */
+ ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL_NO_CERT);
}
return(0);
@@ -216,7 +249,7 @@
struct ndpi_packet_struct *packet = &flow->packet;
#ifdef NDPI_PROTOCOL_ISKOOT
-
+
#endif
// struct ndpi_id_struct *src=flow->src;
// struct ndpi_id_struct *dst=flow->dst;
@@ -288,16 +321,26 @@
}
}
#endif
-
-
-
}
+
no_check_for_ssl_payload:
#endif
- NDPI_LOG(NDPI_PROTOCOL_SSL, ndpi_struct, NDPI_LOG_DEBUG, "found ssl connection.\n");
- sslDetectProtocolFromCertificate(ndpi_struct, flow);
-
- ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
+ if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
+ NDPI_LOG(NDPI_PROTOCOL_SSL, ndpi_struct, NDPI_LOG_DEBUG, "found ssl connection.\n");
+ sslDetectProtocolFromCertificate(ndpi_struct, flow);
+
+ if(!packet->ssl_certificate_detected
+ && (!(flow->l4.tcp.ssl_seen_client_cert && flow->l4.tcp.ssl_seen_server_cert))) {
+ /* SSL without certificate (Skype, Ultrasurf?) */
+ ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL_NO_CERT);
+#ifdef NDPI_PROTOCOL_SKYPE
+ //printf("[SSL] %08X -> %08X\n", packet->iph->saddr, packet->iph->daddr);
+ if(packet->iph)
+ add_skype_connection(ndpi_struct, packet->iph->saddr, packet->iph->daddr);
+#endif
+ } else
+ ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
+ }
}
@@ -305,7 +348,7 @@
{
struct ndpi_packet_struct *packet = &flow->packet;
- //
+ //
// struct ndpi_id_struct *src=flow->src;
// struct ndpi_id_struct *dst=flow->dst;
@@ -413,7 +456,7 @@
void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
-
+
// struct ndpi_id_struct *src=flow->src;
// struct ndpi_id_struct *dst=flow->dst;
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/tcp_udp.c
^
|
@@ -66,21 +66,33 @@
ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_APPLE, NDPI_REAL_PROTOCOL);
return;
}
+
+ /*
+ Skype
+ 157.56.0.0/14, 157.60.0.0/16, 157.54.0.0/15
+ */
+ if(
+ (((ntohl(packet->iph->saddr) & 0xFF3F0000 /* 255.63.0.0 */) == 0x9D380000 /* 157.56.0.0/ */) || ((ntohl(packet->iph->daddr) & 0xFF3F0000 /* 255.63.0.0 */) == 0x9D380000))
+ || (((ntohl(packet->iph->saddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x9D3C0000 /* 157.60.0.0/ */) || ((ntohl(packet->iph->daddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x9D3D0000))
+ || (((ntohl(packet->iph->saddr) & 0xFF7F0000 /* 255.255.0.0 */) == 0x9D360000 /* 157.54.0.0/ */) || ((ntohl(packet->iph->daddr) & 0xFF7F0000 /* 255.127.0.0 */) == 0x9D360000))
+ ) {
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_REAL_PROTOCOL);
+ return;
+ }
/*
Google
173.194.0.0/16
*/
- if(((ntohl(packet->iph->saddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0xADC20000 /* 66.114.160.0 */)
- || ((ntohl(packet->iph->daddr) & 0xFFFF0000 /* 255.255.0.0 */) ==0xDC20000 /* 66.114.160.0 */)) {
+ if(((ntohl(packet->iph->saddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0xADC20000 /* 173.194.0.0 */)
+ || ((ntohl(packet->iph->daddr) & 0xFFFF0000 /* 255.255.0.0 */) ==0xDC20000 /* 173.194.0.0 */)) {
ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_GOOGLE, NDPI_REAL_PROTOCOL);
return;
}
/*
- * Ubunut One
- * 91.189.89.0/21
- * 255.255.248.0
+ Ubuntu One
+ 91.189.89.0/21 (255.255.248.0)
*/
if(((ntohl(packet->iph->saddr) & 0xFFFFF800 /* 255.255.248.0 */) == 0x5BBD5900 /* 91.189.89.0*/)
|| ((ntohl(packet->iph->daddr) & 0xFFFFF800 /* 255.255.248.0 */) == 0x5BBD5900 /* 91.189.89.0 */)) {
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/tor.c
^
|
@@ -27,10 +27,11 @@
sport = ntohs(packet->tcp->source), dport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_TOR, ndpi_struct, NDPI_LOG_DEBUG, "calculating TOR over tcp.\n");
- if (((dport == 9001) || (sport == 9001)) || ((dport == 9030) || (sport == 9030)) &&
- ((packet->payload[0] == 0x17) || (packet->payload[0] == 0x16)) &&
- (packet->payload[1] == 0x03) && (packet->payload[2] == 0x01) &&
- (packet->payload[3] == 0x00)) {
+ if ((((dport == 9001) || (sport == 9001)) || ((dport == 9030) || (sport == 9030)))
+ && ((packet->payload[0] == 0x17) || (packet->payload[0] == 0x16))
+ && (packet->payload[1] == 0x03)
+ && (packet->payload[2] == 0x01)
+ && (packet->payload[3] == 0x00)) {
NDPI_LOG(NDPI_PROTOCOL_TOR, ndpi_struct, NDPI_LOG_DEBUG, "found tor.\n");
ndpi_int_tor_add_connection(ndpi_struct, flow);
}
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/protocols/warcraft3.c
^
|
@@ -30,71 +30,71 @@
#ifdef NDPI_PROTOCOL_WARCRAFT3
static void ndpi_int_warcraft3_add_connection(struct ndpi_detection_module_struct
- *ndpi_struct, struct ndpi_flow_struct *flow)
+ *ndpi_struct, struct ndpi_flow_struct *flow)
{
- ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_WARCRAFT3, NDPI_REAL_PROTOCOL);
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_WARCRAFT3, NDPI_REAL_PROTOCOL);
}
void ndpi_search_warcraft3(struct ndpi_detection_module_struct
- *ndpi_struct, struct ndpi_flow_struct *flow)
+ *ndpi_struct, struct ndpi_flow_struct *flow)
{
- struct ndpi_packet_struct *packet = &flow->packet;
+ struct ndpi_packet_struct *packet = &flow->packet;
-// struct ndpi_id_struct *src=ndpi_struct->src;
-// struct ndpi_id_struct *dst=ndpi_struct->dst;
+ // struct ndpi_id_struct *src=ndpi_struct->src;
+ // struct ndpi_id_struct *dst=ndpi_struct->dst;
- u_int16_t l;
+ u_int32_t l; /*
+ Leave it as u_int32_t because otherwise 'u_int16_t temp'
+ might overflood it and thus generate an infinite loop
+ */
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "search WARCRAFT3\n");
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "search WARCRAFT3\n");
- if (flow->packet_counter == 1 && packet->payload_packet_len == 1 && packet->payload[0] == 0x01) {
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "maybe warcraft3: packet_len == 1\n");
- return;
- } else if (packet->payload_packet_len >= 4 && (packet->payload[0] == 0xf7 || packet->payload[0] == 0xff)) {
-
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "packet_payload begins with 0xf7 or 0xff\n");
-
- l = packet->payload[2] + (packet->payload[3] << 8); // similar to ntohs
-
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "l = %u \n", l);
-
- while (l <= (packet->payload_packet_len - 4)) {
- if (packet->payload[l] == 0xf7) {
- u_int16_t temp = (packet->payload[l + 2 + 1] << 8) + packet->payload[l + 2];
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "another f7 visited.\n");
- if (temp <= 2) {
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "break\n");
- break;
- } else {
- l += temp;
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "l = %u \n", l);
- }
- } else {
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "break\n");
- break;
- }
- }
-
-
- if (l == packet->payload_packet_len) {
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "maybe WARCRAFT3\n");
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "flow->packet_counter = %u \n",
- flow->packet_counter);
- if (flow->packet_counter > 2) {
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "detected WARCRAFT3\n");
- ndpi_int_warcraft3_add_connection(ndpi_struct, flow);
- return;
- }
- return;
- }
+ if (flow->packet_counter == 1 && packet->payload_packet_len == 1 && packet->payload[0] == 0x01) {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "maybe warcraft3: packet_len == 1\n");
+ return;
+ } else if (packet->payload_packet_len >= 4 && (packet->payload[0] == 0xf7 || packet->payload[0] == 0xff)) {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "packet_payload begins with 0xf7 or 0xff\n");
- }
+ l = packet->payload[2] + (packet->payload[3] << 8); // similar to ntohs
+
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "l = %u \n", l);
+ while (l <= (packet->payload_packet_len - 4)) {
+ if (packet->payload[l] == 0xf7) {
+ u_int16_t temp = (packet->payload[l + 2 + 1] << 8) + packet->payload[l + 2];
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "another f7 visited.\n");
+
+ if((temp <= 2) || (temp > 1500)) {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "break\n");
+ break;
+ } else {
+ l += temp;
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "l = %u \n", l);
+ }
+ } else {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "break\n");
+ break;
+ }
+ }
+
+ if (l == packet->payload_packet_len) {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "maybe WARCRAFT3\n");
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "flow->packet_counter = %u \n",
+ flow->packet_counter);
+ if (flow->packet_counter > 2) {
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "detected WARCRAFT3\n");
+ ndpi_int_warcraft3_add_connection(ndpi_struct, flow);
+ return;
+ }
+ return;
+ }
+ }
- NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "no warcraft3 detected.\n");
- NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_WARCRAFT3);
+ NDPI_LOG(NDPI_PROTOCOL_WARCRAFT3, ndpi_struct, NDPI_LOG_DEBUG, "no warcraft3 detected.\n");
+ NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_WARCRAFT3);
}
#endif
|
[-]
[+]
|
Added |
nDPI.tar.bz2/src/lib/protocols/whoisdas.c
^
|
@@ -0,0 +1,58 @@
+/*
+ * ssh.c
+ *
+ * Copyright (C) 2013 - ntop.org
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include "ndpi_protocols.h"
+#ifdef NDPI_PROTOCOL_WHOIS_DAS
+
+void ndpi_search_whois_das(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
+{
+ struct ndpi_packet_struct *packet = &flow->packet;
+
+ if ((packet->tcp != NULL)
+ && (
+ ((ntohs(packet->tcp->source) == 43) || (ntohs(packet->tcp->dest) == 43))
+ ||
+ ((ntohs(packet->tcp->source) == 4343) || (ntohs(packet->tcp->dest) == 4343))
+ )
+ ) {
+ if(packet->payload_packet_len > 0) {
+ u_int max_len = sizeof(flow->host_server_name)-1;
+ u_int i, j;
+
+ for(i=strlen((const char *)flow->host_server_name), j=0; (i<max_len) && (j<packet->payload_packet_len); i++, j++) {
+ if((packet->payload[j] == '\n') || (packet->payload[j] == '\r')) break;
+
+ flow->host_server_name[i] = packet->payload[j];
+ }
+
+ flow->host_server_name[i] = '\0';
+
+ NDPI_LOG(NDPI_PROTOCOL_WHOIS_DAS, ndpi_struct, NDPI_LOG_DEBUG, "{WHOIS/DAS] %s\n", flow->host_server_name);
+ }
+
+ ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_WHOIS_DAS, NDPI_REAL_PROTOCOL);
+ } else {
+ NDPI_LOG(NDPI_PROTOCOL_WHOIS_DAS, ndpi_struct, NDPI_LOG_DEBUG, "excluding whois_das at stage %d\n", flow->l4.tcp.whois_das_stage);
+ NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_WHOIS_DAS);
+ }
+}
+
+#endif
|
[-]
[+]
|
Changed |
nDPI.tar.bz2/src/lib/third_party/src/node.c
^
|
@@ -148,7 +148,7 @@
if (str->length != newstr->length)
continue;
- for (j=0; j<str->length; j++)
+ for (j=0; j<(int)str->length; j++)
if(str->astring[j] != newstr->astring[j])
continue;
|
|
Added |
ntopng-1.0.2.tar.bz2
^
|
[-]
[+]
|
Changed |
ntopng.init
^
|
@@ -110,6 +110,17 @@
## Start daemon with startproc(8). If this fails
## the return value is set appropriately by startproc.
for IFACE in ${NTOPNG_IFACE} ; do
+ IFACEN=${IFACE}
+ if [ -n "`echo ${IFACE} | grep -i ^tcp`" ] ; then
+ idx=0
+ PORT=`echo ${IFACE} | awk -F: '{print $NF}'`
+ if [ -n "${PORT}" ] ; then
+ IFACE="zmq_${PORT}"
+ else
+ IFACE="zmq_${idx}"
+ idx=`expr ${idx} + 1`
+ fi
+ fi
echo -n "instance on interface ${IFACE} "
/sbin/startproc -p /var/run/ntopng/ntopng-${IFACE}.pid $NTOPNG_BIN -i ${IFACE} ${NTOPNG_OPTS}
rc_status -v
@@ -165,6 +176,17 @@
# NOTE: checkproc returns LSB compliant status values.
for IFACE in ${NTOPNG_IFACE} ; do
+ IFACEN=${IFACE}
+ if [ -n "`echo ${IFACE} | grep -i ^tcp`" ] ; then
+ idx=0
+ PORT=`echo ${IFACE} | awk -F: '{print $NF}'`
+ if [ -n "${PORT}" ] ; then
+ IFACE="zmq_${PORT}"
+ else
+ IFACE="zmq_${idx}"
+ idx=`expr ${idx} + 1`
+ fi
+ fi
echo -n "instance on interface ${IFACE} "
/sbin/checkproc -p /var/run/ntopng/ntopng-${IFACE}.pid $NTOPNG_BIN
rc_status -v
@@ -175,6 +197,17 @@
## argument to this init script which is required for a reload.
## Note: probe is not (yet) part of LSB (as of 1.9)
for IFACE in ${NTOPNG_IFACE} ; do
+ IFACEN=${IFACE}
+ if [ -n "`echo ${IFACE} | grep -i ^tcp`" ] ; then
+ idx=0
+ PORT=`echo ${IFACE} | awk -F: '{print $NF}'`
+ if [ -n "${PORT}" ] ; then
+ IFACE="zmq_${PORT}"
+ else
+ IFACE="zmq_${idx}"
+ idx=`expr ${idx} + 1`
+ fi
+ fi
test /etc/sysconfig/ntopng -nt /var/run/ntopng/ntopng-${IFACE}.pid && echo reload
done
;;
|