├── .gitignore ├── .travis.yml ├── COPYING ├── Makefile.am ├── Makefile.in ├── README.md ├── build.sh ├── config.guess ├── config.h ├── config.h.in ├── config.sub ├── configure ├── configure.ac ├── doc └── REGEX.txt ├── install-sh ├── m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 └── lt~obsolete.m4 ├── pkg └── deb │ └── debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── rules │ ├── source │ └── format │ └── watch ├── sipgrep.8 └── src ├── Makefile.am ├── Makefile.in ├── config.h.in ├── include ├── core_hep.h ├── ipreasm.h ├── log.h ├── sipgrep.h ├── sipparse.h ├── tcpreasm.h ├── transport_hep.h ├── user_interface.h └── uthash.h ├── ipreasm.c ├── log.c ├── sipgrep.c ├── sipparse.c ├── tcpreasm.c ├── transport_hep.c └── user_interface.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | arch: 3 | - amd64 4 | - ppc64le 5 | compiler: 6 | - gcc 7 | 8 | install: 9 | - sudo apt-get update || true 10 | - sudo apt-get install build-essential 11 | - sudo apt-get install libpcap-dev libpcre2-dev autoconf automake autogen 12 | 13 | script: 14 | - ./build.sh 15 | - ./configure 16 | - make 17 | - ./src/sipgrep -h 18 | 19 | notifications: 20 | slack: qxip:WuEGMSIAa8KEX6iL2zN2bZbv 21 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | src 3 | 4 | EXTRA_DIST = \ 5 | @PACKAGE_NAME@.spec 6 | 7 | ACLOCAL_AMFLAGS = -I m4 8 | 9 | distclean-local: 10 | rm -rf autom4te.cache 11 | 12 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.11.6 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software 6 | # Foundation, Inc. 7 | # This Makefile.in is free software; the Free Software Foundation 8 | # gives unlimited permission to copy and/or distribute it, 9 | # with or without modifications, as long as this notice is preserved. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 13 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. 15 | 16 | @SET_MAKE@ 17 | VPATH = @srcdir@ 18 | am__make_dryrun = \ 19 | { \ 20 | am__dry=no; \ 21 | case $$MAKEFLAGS in \ 22 | *\\[\ \ ]*) \ 23 | echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ 24 | | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ 25 | *) \ 26 | for am__flg in $$MAKEFLAGS; do \ 27 | case $$am__flg in \ 28 | *=*|--*) ;; \ 29 | *n*) am__dry=yes; break;; \ 30 | esac; \ 31 | done;; \ 32 | esac; \ 33 | test $$am__dry = yes; \ 34 | } 35 | pkgdatadir = $(datadir)/@PACKAGE@ 36 | pkgincludedir = $(includedir)/@PACKAGE@ 37 | pkglibdir = $(libdir)/@PACKAGE@ 38 | pkglibexecdir = $(libexecdir)/@PACKAGE@ 39 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 40 | install_sh_DATA = $(install_sh) -c -m 644 41 | install_sh_PROGRAM = $(install_sh) -c 42 | install_sh_SCRIPT = $(install_sh) -c 43 | INSTALL_HEADER = $(INSTALL_DATA) 44 | transform = $(program_transform_name) 45 | NORMAL_INSTALL = : 46 | PRE_INSTALL = : 47 | POST_INSTALL = : 48 | NORMAL_UNINSTALL = : 49 | PRE_UNINSTALL = : 50 | POST_UNINSTALL = : 51 | build_triplet = @build@ 52 | host_triplet = @host@ 53 | subdir = . 54 | DIST_COMMON = $(am__configure_deps) $(srcdir)/Makefile.am \ 55 | $(srcdir)/Makefile.in $(top_srcdir)/configure COPYING \ 56 | config.guess config.sub depcomp install-sh ltmain.sh missing 57 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 58 | am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ 59 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ 60 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ 61 | $(top_srcdir)/configure.ac 62 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 63 | $(ACLOCAL_M4) 64 | am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ 65 | configure.lineno config.status.lineno 66 | mkinstalldirs = $(install_sh) -d 67 | CONFIG_HEADER = $(top_builddir)/src/config.h 68 | CONFIG_CLEAN_FILES = 69 | CONFIG_CLEAN_VPATH_FILES = 70 | SOURCES = 71 | DIST_SOURCES = 72 | RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ 73 | html-recursive info-recursive install-data-recursive \ 74 | install-dvi-recursive install-exec-recursive \ 75 | install-html-recursive install-info-recursive \ 76 | install-pdf-recursive install-ps-recursive install-recursive \ 77 | installcheck-recursive installdirs-recursive pdf-recursive \ 78 | ps-recursive uninstall-recursive 79 | am__can_run_installinfo = \ 80 | case $$AM_UPDATE_INFO_DIR in \ 81 | n|no|NO) false;; \ 82 | *) (install-info --version) >/dev/null 2>&1;; \ 83 | esac 84 | RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ 85 | distclean-recursive maintainer-clean-recursive 86 | AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ 87 | $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ 88 | distdir dist dist-all distcheck 89 | ETAGS = etags 90 | CTAGS = ctags 91 | DIST_SUBDIRS = $(SUBDIRS) 92 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 93 | distdir = $(PACKAGE)-$(VERSION) 94 | top_distdir = $(distdir) 95 | am__remove_distdir = \ 96 | if test -d "$(distdir)"; then \ 97 | find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ 98 | && rm -rf "$(distdir)" \ 99 | || { sleep 5 && rm -rf "$(distdir)"; }; \ 100 | else :; fi 101 | am__relativize = \ 102 | dir0=`pwd`; \ 103 | sed_first='s,^\([^/]*\)/.*$$,\1,'; \ 104 | sed_rest='s,^[^/]*/*,,'; \ 105 | sed_last='s,^.*/\([^/]*\)$$,\1,'; \ 106 | sed_butlast='s,/*[^/]*$$,,'; \ 107 | while test -n "$$dir1"; do \ 108 | first=`echo "$$dir1" | sed -e "$$sed_first"`; \ 109 | if test "$$first" != "."; then \ 110 | if test "$$first" = ".."; then \ 111 | dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ 112 | dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ 113 | else \ 114 | first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ 115 | if test "$$first2" = "$$first"; then \ 116 | dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ 117 | else \ 118 | dir2="../$$dir2"; \ 119 | fi; \ 120 | dir0="$$dir0"/"$$first"; \ 121 | fi; \ 122 | fi; \ 123 | dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ 124 | done; \ 125 | reldir="$$dir2" 126 | DIST_ARCHIVES = $(distdir).tar.gz 127 | GZIP_ENV = --best 128 | distuninstallcheck_listfiles = find . -type f -print 129 | am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ 130 | | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' 131 | distcleancheck_listfiles = find . -type f -print 132 | ACLOCAL = @ACLOCAL@ 133 | AMTAR = @AMTAR@ 134 | AR = @AR@ 135 | AUTOCONF = @AUTOCONF@ 136 | AUTOHEADER = @AUTOHEADER@ 137 | AUTOMAKE = @AUTOMAKE@ 138 | AWK = @AWK@ 139 | CC = @CC@ 140 | CCDEPMODE = @CCDEPMODE@ 141 | CFLAGS = @CFLAGS@ 142 | CPP = @CPP@ 143 | CPPFLAGS = @CPPFLAGS@ 144 | CYGPATH_W = @CYGPATH_W@ 145 | DEFS = @DEFS@ 146 | DEPDIR = @DEPDIR@ 147 | DLLTOOL = @DLLTOOL@ 148 | DL_LIBS = @DL_LIBS@ 149 | DSYMUTIL = @DSYMUTIL@ 150 | DUMPBIN = @DUMPBIN@ 151 | ECHO_C = @ECHO_C@ 152 | ECHO_N = @ECHO_N@ 153 | ECHO_T = @ECHO_T@ 154 | EGREP = @EGREP@ 155 | EXEEXT = @EXEEXT@ 156 | FGREP = @FGREP@ 157 | GREP = @GREP@ 158 | HAVE_HEP = @HAVE_HEP@ 159 | HIREDIS_LIBS = @HIREDIS_LIBS@ 160 | INSTALL = @INSTALL@ 161 | INSTALL_DATA = @INSTALL_DATA@ 162 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 163 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 164 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 165 | LD = @LD@ 166 | LDFLAGS = @LDFLAGS@ 167 | LIBOBJS = @LIBOBJS@ 168 | LIBS = @LIBS@ 169 | LIBTOOL = @LIBTOOL@ 170 | LIPO = @LIPO@ 171 | LN_S = @LN_S@ 172 | LTLIBOBJS = @LTLIBOBJS@ 173 | MAKEINFO = @MAKEINFO@ 174 | MANIFEST_TOOL = @MANIFEST_TOOL@ 175 | MKDIR_P = @MKDIR_P@ 176 | NCURSES = @NCURSES@ 177 | NCURSES_LIBS = @NCURSES_LIBS@ 178 | NM = @NM@ 179 | NMEDIT = @NMEDIT@ 180 | OBJDUMP = @OBJDUMP@ 181 | OBJEXT = @OBJEXT@ 182 | OS_DARWIN = @OS_DARWIN@ 183 | OS_FREEBSD = @OS_FREEBSD@ 184 | OS_LINUX = @OS_LINUX@ 185 | OS_NETBSD = @OS_NETBSD@ 186 | OS_SOLARIS = @OS_SOLARIS@ 187 | OTOOL = @OTOOL@ 188 | OTOOL64 = @OTOOL64@ 189 | OUR_MODS = @OUR_MODS@ 190 | PACKAGE = @PACKAGE@ 191 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 192 | PACKAGE_NAME = @PACKAGE_NAME@ 193 | PACKAGE_STRING = @PACKAGE_STRING@ 194 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 195 | PACKAGE_URL = @PACKAGE_URL@ 196 | PACKAGE_VERSION = @PACKAGE_VERSION@ 197 | PATH_SEPARATOR = @PATH_SEPARATOR@ 198 | PCAP_LIBS = @PCAP_LIBS@ 199 | PCRE = @PCRE@ 200 | PCRE_LIBS = @PCRE_LIBS@ 201 | PTHREAD_LIBS = @PTHREAD_LIBS@ 202 | RANLIB = @RANLIB@ 203 | REDIS = @REDIS@ 204 | SED = @SED@ 205 | SET_MAKE = @SET_MAKE@ 206 | SHELL = @SHELL@ 207 | SSL = @SSL@ 208 | STRIP = @STRIP@ 209 | USE_NCURSES = @USE_NCURSES@ 210 | VERSION = @VERSION@ 211 | ZLIB = @ZLIB@ 212 | abs_builddir = @abs_builddir@ 213 | abs_srcdir = @abs_srcdir@ 214 | abs_top_builddir = @abs_top_builddir@ 215 | abs_top_srcdir = @abs_top_srcdir@ 216 | ac_ct_AR = @ac_ct_AR@ 217 | ac_ct_CC = @ac_ct_CC@ 218 | ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ 219 | am__include = @am__include@ 220 | am__leading_dot = @am__leading_dot@ 221 | am__quote = @am__quote@ 222 | am__tar = @am__tar@ 223 | am__untar = @am__untar@ 224 | bindir = @bindir@ 225 | build = @build@ 226 | build_alias = @build_alias@ 227 | build_cpu = @build_cpu@ 228 | build_os = @build_os@ 229 | build_vendor = @build_vendor@ 230 | builddir = @builddir@ 231 | datadir = @datadir@ 232 | datarootdir = @datarootdir@ 233 | docdir = @docdir@ 234 | dvidir = @dvidir@ 235 | exec_prefix = @exec_prefix@ 236 | host = @host@ 237 | host_alias = @host_alias@ 238 | host_cpu = @host_cpu@ 239 | host_os = @host_os@ 240 | host_vendor = @host_vendor@ 241 | htmldir = @htmldir@ 242 | includedir = @includedir@ 243 | infodir = @infodir@ 244 | install_sh = @install_sh@ 245 | libdir = @libdir@ 246 | libexecdir = @libexecdir@ 247 | localedir = @localedir@ 248 | localstatedir = @localstatedir@ 249 | mandir = @mandir@ 250 | mkdir_p = @mkdir_p@ 251 | oldincludedir = @oldincludedir@ 252 | pdfdir = @pdfdir@ 253 | prefix = @prefix@ 254 | program_transform_name = @program_transform_name@ 255 | psdir = @psdir@ 256 | sbindir = @sbindir@ 257 | sharedstatedir = @sharedstatedir@ 258 | srcdir = @srcdir@ 259 | sysconfdir = @sysconfdir@ 260 | target_alias = @target_alias@ 261 | top_build_prefix = @top_build_prefix@ 262 | top_builddir = @top_builddir@ 263 | top_srcdir = @top_srcdir@ 264 | SUBDIRS = \ 265 | src 266 | 267 | EXTRA_DIST = \ 268 | @PACKAGE_NAME@.spec 269 | 270 | ACLOCAL_AMFLAGS = -I m4 271 | all: all-recursive 272 | 273 | .SUFFIXES: 274 | am--refresh: Makefile 275 | @: 276 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 277 | @for dep in $?; do \ 278 | case '$(am__configure_deps)' in \ 279 | *$$dep*) \ 280 | echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ 281 | $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ 282 | && exit 0; \ 283 | exit 1;; \ 284 | esac; \ 285 | done; \ 286 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ 287 | $(am__cd) $(top_srcdir) && \ 288 | $(AUTOMAKE) --foreign Makefile 289 | .PRECIOUS: Makefile 290 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 291 | @case '$?' in \ 292 | *config.status*) \ 293 | echo ' $(SHELL) ./config.status'; \ 294 | $(SHELL) ./config.status;; \ 295 | *) \ 296 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ 297 | cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ 298 | esac; 299 | 300 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 301 | $(SHELL) ./config.status --recheck 302 | 303 | $(top_srcdir)/configure: $(am__configure_deps) 304 | $(am__cd) $(srcdir) && $(AUTOCONF) 305 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 306 | $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) 307 | $(am__aclocal_m4_deps): 308 | 309 | mostlyclean-libtool: 310 | -rm -f *.lo 311 | 312 | clean-libtool: 313 | -rm -rf .libs _libs 314 | 315 | distclean-libtool: 316 | -rm -f libtool config.lt 317 | 318 | # This directory's subdirectories are mostly independent; you can cd 319 | # into them and run `make' without going through this Makefile. 320 | # To change the values of `make' variables: instead of editing Makefiles, 321 | # (1) if the variable is set in `config.status', edit `config.status' 322 | # (which will cause the Makefiles to be regenerated when you run `make'); 323 | # (2) otherwise, pass the desired values on the `make' command line. 324 | $(RECURSIVE_TARGETS): 325 | @fail= failcom='exit 1'; \ 326 | for f in x $$MAKEFLAGS; do \ 327 | case $$f in \ 328 | *=* | --[!k]*);; \ 329 | *k*) failcom='fail=yes';; \ 330 | esac; \ 331 | done; \ 332 | dot_seen=no; \ 333 | target=`echo $@ | sed s/-recursive//`; \ 334 | list='$(SUBDIRS)'; for subdir in $$list; do \ 335 | echo "Making $$target in $$subdir"; \ 336 | if test "$$subdir" = "."; then \ 337 | dot_seen=yes; \ 338 | local_target="$$target-am"; \ 339 | else \ 340 | local_target="$$target"; \ 341 | fi; \ 342 | ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ 343 | || eval $$failcom; \ 344 | done; \ 345 | if test "$$dot_seen" = "no"; then \ 346 | $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ 347 | fi; test -z "$$fail" 348 | 349 | $(RECURSIVE_CLEAN_TARGETS): 350 | @fail= failcom='exit 1'; \ 351 | for f in x $$MAKEFLAGS; do \ 352 | case $$f in \ 353 | *=* | --[!k]*);; \ 354 | *k*) failcom='fail=yes';; \ 355 | esac; \ 356 | done; \ 357 | dot_seen=no; \ 358 | case "$@" in \ 359 | distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ 360 | *) list='$(SUBDIRS)' ;; \ 361 | esac; \ 362 | rev=''; for subdir in $$list; do \ 363 | if test "$$subdir" = "."; then :; else \ 364 | rev="$$subdir $$rev"; \ 365 | fi; \ 366 | done; \ 367 | rev="$$rev ."; \ 368 | target=`echo $@ | sed s/-recursive//`; \ 369 | for subdir in $$rev; do \ 370 | echo "Making $$target in $$subdir"; \ 371 | if test "$$subdir" = "."; then \ 372 | local_target="$$target-am"; \ 373 | else \ 374 | local_target="$$target"; \ 375 | fi; \ 376 | ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ 377 | || eval $$failcom; \ 378 | done && test -z "$$fail" 379 | tags-recursive: 380 | list='$(SUBDIRS)'; for subdir in $$list; do \ 381 | test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ 382 | done 383 | ctags-recursive: 384 | list='$(SUBDIRS)'; for subdir in $$list; do \ 385 | test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ 386 | done 387 | 388 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 389 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 390 | unique=`for i in $$list; do \ 391 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 392 | done | \ 393 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 394 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 395 | mkid -fID $$unique 396 | tags: TAGS 397 | 398 | TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 399 | $(TAGS_FILES) $(LISP) 400 | set x; \ 401 | here=`pwd`; \ 402 | if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ 403 | include_option=--etags-include; \ 404 | empty_fix=.; \ 405 | else \ 406 | include_option=--include; \ 407 | empty_fix=; \ 408 | fi; \ 409 | list='$(SUBDIRS)'; for subdir in $$list; do \ 410 | if test "$$subdir" = .; then :; else \ 411 | test ! -f $$subdir/TAGS || \ 412 | set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ 413 | fi; \ 414 | done; \ 415 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 416 | unique=`for i in $$list; do \ 417 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 418 | done | \ 419 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 420 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 421 | shift; \ 422 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ 423 | test -n "$$unique" || unique=$$empty_fix; \ 424 | if test $$# -gt 0; then \ 425 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 426 | "$$@" $$unique; \ 427 | else \ 428 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 429 | $$unique; \ 430 | fi; \ 431 | fi 432 | ctags: CTAGS 433 | CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ 434 | $(TAGS_FILES) $(LISP) 435 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 436 | unique=`for i in $$list; do \ 437 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 438 | done | \ 439 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 440 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 441 | test -z "$(CTAGS_ARGS)$$unique" \ 442 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 443 | $$unique 444 | 445 | GTAGS: 446 | here=`$(am__cd) $(top_builddir) && pwd` \ 447 | && $(am__cd) $(top_srcdir) \ 448 | && gtags -i $(GTAGS_ARGS) "$$here" 449 | 450 | distclean-tags: 451 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 452 | 453 | distdir: $(DISTFILES) 454 | $(am__remove_distdir) 455 | test -d "$(distdir)" || mkdir "$(distdir)" 456 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 457 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 458 | list='$(DISTFILES)'; \ 459 | dist_files=`for file in $$list; do echo $$file; done | \ 460 | sed -e "s|^$$srcdirstrip/||;t" \ 461 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 462 | case $$dist_files in \ 463 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 464 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 465 | sort -u` ;; \ 466 | esac; \ 467 | for file in $$dist_files; do \ 468 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 469 | if test -d $$d/$$file; then \ 470 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 471 | if test -d "$(distdir)/$$file"; then \ 472 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 473 | fi; \ 474 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 475 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ 476 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 477 | fi; \ 478 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ 479 | else \ 480 | test -f "$(distdir)/$$file" \ 481 | || cp -p $$d/$$file "$(distdir)/$$file" \ 482 | || exit 1; \ 483 | fi; \ 484 | done 485 | @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ 486 | if test "$$subdir" = .; then :; else \ 487 | $(am__make_dryrun) \ 488 | || test -d "$(distdir)/$$subdir" \ 489 | || $(MKDIR_P) "$(distdir)/$$subdir" \ 490 | || exit 1; \ 491 | dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ 492 | $(am__relativize); \ 493 | new_distdir=$$reldir; \ 494 | dir1=$$subdir; dir2="$(top_distdir)"; \ 495 | $(am__relativize); \ 496 | new_top_distdir=$$reldir; \ 497 | echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ 498 | echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ 499 | ($(am__cd) $$subdir && \ 500 | $(MAKE) $(AM_MAKEFLAGS) \ 501 | top_distdir="$$new_top_distdir" \ 502 | distdir="$$new_distdir" \ 503 | am__remove_distdir=: \ 504 | am__skip_length_check=: \ 505 | am__skip_mode_fix=: \ 506 | distdir) \ 507 | || exit 1; \ 508 | fi; \ 509 | done 510 | -test -n "$(am__skip_mode_fix)" \ 511 | || find "$(distdir)" -type d ! -perm -755 \ 512 | -exec chmod u+rwx,go+rx {} \; -o \ 513 | ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ 514 | ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ 515 | ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ 516 | || chmod -R a+r "$(distdir)" 517 | dist-gzip: distdir 518 | tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz 519 | $(am__remove_distdir) 520 | 521 | dist-bzip2: distdir 522 | tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 523 | $(am__remove_distdir) 524 | 525 | dist-lzip: distdir 526 | tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz 527 | $(am__remove_distdir) 528 | 529 | dist-lzma: distdir 530 | tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma 531 | $(am__remove_distdir) 532 | 533 | dist-xz: distdir 534 | tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz 535 | $(am__remove_distdir) 536 | 537 | dist-tarZ: distdir 538 | tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z 539 | $(am__remove_distdir) 540 | 541 | dist-shar: distdir 542 | shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz 543 | $(am__remove_distdir) 544 | 545 | dist-zip: distdir 546 | -rm -f $(distdir).zip 547 | zip -rq $(distdir).zip $(distdir) 548 | $(am__remove_distdir) 549 | 550 | dist dist-all: distdir 551 | tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz 552 | $(am__remove_distdir) 553 | 554 | # This target untars the dist file and tries a VPATH configuration. Then 555 | # it guarantees that the distribution is self-contained by making another 556 | # tarfile. 557 | distcheck: dist 558 | case '$(DIST_ARCHIVES)' in \ 559 | *.tar.gz*) \ 560 | GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ 561 | *.tar.bz2*) \ 562 | bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ 563 | *.tar.lzma*) \ 564 | lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ 565 | *.tar.lz*) \ 566 | lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ 567 | *.tar.xz*) \ 568 | xz -dc $(distdir).tar.xz | $(am__untar) ;;\ 569 | *.tar.Z*) \ 570 | uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ 571 | *.shar.gz*) \ 572 | GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ 573 | *.zip*) \ 574 | unzip $(distdir).zip ;;\ 575 | esac 576 | chmod -R a-w $(distdir); chmod u+w $(distdir) 577 | mkdir $(distdir)/_build 578 | mkdir $(distdir)/_inst 579 | chmod a-w $(distdir) 580 | test -d $(distdir)/_build || exit 0; \ 581 | dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ 582 | && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ 583 | && am__cwd=`pwd` \ 584 | && $(am__cd) $(distdir)/_build \ 585 | && ../configure --srcdir=.. --prefix="$$dc_install_base" \ 586 | $(AM_DISTCHECK_CONFIGURE_FLAGS) \ 587 | $(DISTCHECK_CONFIGURE_FLAGS) \ 588 | && $(MAKE) $(AM_MAKEFLAGS) \ 589 | && $(MAKE) $(AM_MAKEFLAGS) dvi \ 590 | && $(MAKE) $(AM_MAKEFLAGS) check \ 591 | && $(MAKE) $(AM_MAKEFLAGS) install \ 592 | && $(MAKE) $(AM_MAKEFLAGS) installcheck \ 593 | && $(MAKE) $(AM_MAKEFLAGS) uninstall \ 594 | && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ 595 | distuninstallcheck \ 596 | && chmod -R a-w "$$dc_install_base" \ 597 | && ({ \ 598 | (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ 599 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ 600 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ 601 | && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ 602 | distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ 603 | } || { rm -rf "$$dc_destdir"; exit 1; }) \ 604 | && rm -rf "$$dc_destdir" \ 605 | && $(MAKE) $(AM_MAKEFLAGS) dist \ 606 | && rm -rf $(DIST_ARCHIVES) \ 607 | && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ 608 | && cd "$$am__cwd" \ 609 | || exit 1 610 | $(am__remove_distdir) 611 | @(echo "$(distdir) archives ready for distribution: "; \ 612 | list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ 613 | sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' 614 | distuninstallcheck: 615 | @test -n '$(distuninstallcheck_dir)' || { \ 616 | echo 'ERROR: trying to run $@ with an empty' \ 617 | '$$(distuninstallcheck_dir)' >&2; \ 618 | exit 1; \ 619 | }; \ 620 | $(am__cd) '$(distuninstallcheck_dir)' || { \ 621 | echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ 622 | exit 1; \ 623 | }; \ 624 | test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ 625 | || { echo "ERROR: files left after uninstall:" ; \ 626 | if test -n "$(DESTDIR)"; then \ 627 | echo " (check DESTDIR support)"; \ 628 | fi ; \ 629 | $(distuninstallcheck_listfiles) ; \ 630 | exit 1; } >&2 631 | distcleancheck: distclean 632 | @if test '$(srcdir)' = . ; then \ 633 | echo "ERROR: distcleancheck can only run from a VPATH build" ; \ 634 | exit 1 ; \ 635 | fi 636 | @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ 637 | || { echo "ERROR: files left in build directory after distclean:" ; \ 638 | $(distcleancheck_listfiles) ; \ 639 | exit 1; } >&2 640 | check-am: all-am 641 | check: check-recursive 642 | all-am: Makefile 643 | installdirs: installdirs-recursive 644 | installdirs-am: 645 | install: install-recursive 646 | install-exec: install-exec-recursive 647 | install-data: install-data-recursive 648 | uninstall: uninstall-recursive 649 | 650 | install-am: all-am 651 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 652 | 653 | installcheck: installcheck-recursive 654 | install-strip: 655 | if test -z '$(STRIP)'; then \ 656 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 657 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 658 | install; \ 659 | else \ 660 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 661 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 662 | "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ 663 | fi 664 | mostlyclean-generic: 665 | 666 | clean-generic: 667 | 668 | distclean-generic: 669 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 670 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 671 | 672 | maintainer-clean-generic: 673 | @echo "This command is intended for maintainers to use" 674 | @echo "it deletes files that may require special tools to rebuild." 675 | clean: clean-recursive 676 | 677 | clean-am: clean-generic clean-libtool mostlyclean-am 678 | 679 | distclean: distclean-recursive 680 | -rm -f $(am__CONFIG_DISTCLEAN_FILES) 681 | -rm -f Makefile 682 | distclean-am: clean-am distclean-generic distclean-libtool \ 683 | distclean-local distclean-tags 684 | 685 | dvi: dvi-recursive 686 | 687 | dvi-am: 688 | 689 | html: html-recursive 690 | 691 | html-am: 692 | 693 | info: info-recursive 694 | 695 | info-am: 696 | 697 | install-data-am: 698 | 699 | install-dvi: install-dvi-recursive 700 | 701 | install-dvi-am: 702 | 703 | install-exec-am: 704 | 705 | install-html: install-html-recursive 706 | 707 | install-html-am: 708 | 709 | install-info: install-info-recursive 710 | 711 | install-info-am: 712 | 713 | install-man: 714 | 715 | install-pdf: install-pdf-recursive 716 | 717 | install-pdf-am: 718 | 719 | install-ps: install-ps-recursive 720 | 721 | install-ps-am: 722 | 723 | installcheck-am: 724 | 725 | maintainer-clean: maintainer-clean-recursive 726 | -rm -f $(am__CONFIG_DISTCLEAN_FILES) 727 | -rm -rf $(top_srcdir)/autom4te.cache 728 | -rm -f Makefile 729 | maintainer-clean-am: distclean-am maintainer-clean-generic 730 | 731 | mostlyclean: mostlyclean-recursive 732 | 733 | mostlyclean-am: mostlyclean-generic mostlyclean-libtool 734 | 735 | pdf: pdf-recursive 736 | 737 | pdf-am: 738 | 739 | ps: ps-recursive 740 | 741 | ps-am: 742 | 743 | uninstall-am: 744 | 745 | .MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ 746 | install-am install-strip tags-recursive 747 | 748 | .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ 749 | all all-am am--refresh check check-am clean clean-generic \ 750 | clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \ 751 | dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ dist-xz \ 752 | dist-zip distcheck distclean distclean-generic \ 753 | distclean-libtool distclean-local distclean-tags \ 754 | distcleancheck distdir distuninstallcheck dvi dvi-am html \ 755 | html-am info info-am install install-am install-data \ 756 | install-data-am install-dvi install-dvi-am install-exec \ 757 | install-exec-am install-html install-html-am install-info \ 758 | install-info-am install-man install-pdf install-pdf-am \ 759 | install-ps install-ps-am install-strip installcheck \ 760 | installcheck-am installdirs installdirs-am maintainer-clean \ 761 | maintainer-clean-generic mostlyclean mostlyclean-generic \ 762 | mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ 763 | uninstall uninstall-am 764 | 765 | 766 | distclean-local: 767 | rm -rf autom4te.cache 768 | 769 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 770 | # Otherwise a system limit (for SysV at least) may be exceeded. 771 | .NOEXPORT: 772 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/sipcapture/sipgrep.svg?branch=master)](https://travis-ci.org/sipcapture/sipgrep) 2 | 3 | SipGrep 2 4 | ======= 5 | 6 | Sipgrep is a powerful pcap-aware tool command line tool to sniff, capture, display and troubleshoot SIP signaling over IP networks, allowing the user to specify extended regular expressions matching against SIP headers. 7 | 8 | The first version of this program (dated 2005) was a small wrapper for ngrep. Version 2.x provides a full standalone application with numerous additional features geared towards SIP, building upon the excellent ngrep code baseline. 9 | 10 | 11 | ## Requirements: 12 | 13 | * libpcap 14 | * libpcre 15 | 16 | On Debian/Ubuntu: `sudo apt-get install libpcap-dev libpcre2-dev` 17 | 18 | On CentOS/RHEL: `yum install libpcap-devel pcre-devel` 19 | 20 | 21 | 22 | ## Installation 23 | 24 | ### Debian 25 | Sipgrep is available as [Debian package](https://packages.debian.org/sid/net/sipgrep) (Thanks @linuxmaniac) 26 | 27 | ### Clone from GIT: 28 | 29 | ``` 30 | cd /usr/src 31 | git clone https://github.com/sipcapture/sipgrep.git 32 | ``` 33 | 34 | ### Build and Install: 35 | 36 | ``` 37 | cd sipgrep 38 | ./build.sh (optional) 39 | ./configure 40 | make && make install 41 | ``` 42 | 43 | 44 | 45 | ## Usage: 46 | 47 | ``` 48 | ./sipgrep -V 49 | 50 | sipgrep: V2.01b 51 | 52 | ./sipgrep -h 53 | 54 | usage: sipgrep <-ahNViwgGJpevxlDTRMmqCJjxK> <-IO pcap_dump> <-n num> <-d dev> <-A num> 55 | <-s snaplen> <-S limitlen> <-c contact user> <-j user agent> 56 | <-f from user> <-t to user> <-H capture url> <-q autostop cond.> 57 | <-Q split cond.> <-P portrange> <-F file> <-z duration> 58 | 59 | -h is help/usage 60 | -V is version information 61 | -e is show empty packets 62 | -i is ignore case 63 | -x is disable bad parsing notification 64 | -v is invert match 65 | -R is don't do privilege revocation logic 66 | -w is word-regex (expression must match as a word) 67 | -p is don't go into promiscuous mode 68 | -l is make stdout line buffered 69 | -D is replay pcap_dumps with their recorded time intervals 70 | -T is print delta timestamp every time a packet is matched 71 | -m is don't do dialog match 72 | -M is don't do multi-line match (do single-line match instead) 73 | -I is read packet stream from pcap format file pcap_dump 74 | -O is dump matched packets in pcap format to pcap_dump 75 | -n is look at only num packets 76 | -A is dump num packets after a match 77 | -s is set the bpf caplen 78 | -S is set the limitlen on matched packets 79 | -C is no colors in stdout 80 | -c is search user in Contact: header 81 | -f is search user in From: header 82 | -t is search user in To: header 83 | -F is read the bpf filter from the specified file 84 | -H is homer sipcapture URL (i.e. udp:10.0.0.1:9061) 85 | -N is show sub protocol number 86 | -g is disabled clean up dialogs during trace 87 | -G is print dialog report during clean up 88 | -J is kill friendly scanner automatically 89 | -j is kill friendly scanner automatically matching user agent string 90 | -K is kill friendly scanner providing IP and port/portrange i.e.: 10.0.0.1:5060-5090 91 | -q is auto stop condition: 92 | duration:NUM - stop after NUM seconds 93 | filesize:NUM - stop this file after NUM KB 94 | -Q is pcap_dump split condition: 95 | duration:NUM - switch to next file after NUM secs 96 | filesize:NUM - switch to next file after NUM KB 97 | -a is disable packet re-assemblation 98 | -P is use specified portrange instead of default 5060-5061 99 | -d is use specified device instead of the pcap default 100 | -z is make statistics count maximum seconds 101 | 102 | ``` 103 | 104 | ### Examples: 105 | 106 | ``` 107 | #Find a dialog there From user contains '2323232' 108 | sipgrep -f 2323232 109 | 110 | #Find a dialog there To user contains '1111' and print dialog report 111 | sipgrep -f 1111 -G 112 | 113 | #Display only 603 replies without dialog match 114 | sipgrep '^SIP/2.0 603' -m 115 | 116 | #Display only OPTIONS and NOTIFY requests 117 | sipgrep '^(OPTIONS|NOTIFY)' 118 | 119 | #Display only SUBSCRIBE dialog 120 | sipgrep 'CSeq:\s?\d* (SUBSCRIBE|PUBLISH|NOTIFY)' -M 121 | 122 | #Kill friendly-scanner 123 | sipgrep -J 124 | 125 | #Kill friendly-scanner with custom UAC 126 | sipgrep -j sipvicious 127 | 128 | #Display dialogs and duplicate all traffic to HOMER sipcapture in HEPv3 129 | sipgrep -f 23333 -H udp:10.0.0.1:9061 130 | 131 | #collect all Calls/Regisrations untill pcap_dump smaller than 20 KB. 132 | sipgrep -q 'filesize:20' -O sipgrep.pcap 133 | 134 | #collect all Calls/Regisrations dialogs during 120 seconds, print reports and exit. 135 | sipgrep -g -G -q 'duration:120' 136 | 137 | #split pcap_dump to 20 KB files in sipgrep_INDEX_YYYYMMDDHHMM.pcap 138 | sipgrep -Q 'filesize:20' -O sipgrep.pcap 139 | 140 | #split pcap_dump in sipgrep_INDEX_YYYYMMDDHHMM.pcap each 120 seconds 141 | sipgrep -Q 'duration:120' -O sipgrep.pcap 142 | 143 | 144 | 145 | 146 | ``` 147 | 148 | 149 | 150 | ### Reports 151 | 152 | ``` 153 | ----------------------------------------------- 154 | Dialog finished: [53342c3b200e-hgf9cyc7r0i2] 155 | Type: Call 156 | From: "From Work with Love" ;tag=fucueumi19 157 | To: 158 | UAC: snom360/8.7.3.25 159 | CDR init ts: 1395928127 160 | CDR ringing ts: 1395928128 161 | SRD(PDD): 1 sec 162 | CDR answer ts: 1395928136 163 | WTA: 9 sec 164 | CDT (duration): 70 sec 165 | CDR termination ts: 1395928206 166 | Was connected: YES 167 | REASON: BYE 168 | ----------------------------------------------- 169 | 170 | ----------------------------------------------- 171 | Dialog finished: [552E1549D6A9E0F3@192.168.178.1] 172 | Type: Registration 173 | From: ;tag=3598882807 174 | To: 175 | UAC: AVM FRITZ!Box Fon WLAN 7170 Annex A 58.04.67 (Dec 18 2008) 176 | CDR init ts: 1395928251 177 | CDR termination ts: 1395928251 178 | SDT: 0 sec 179 | Was registered: YES 180 | REASON: 200 181 | ----------------------------------------------- 182 | 183 | ----------------------------------------------- 184 | Dialog finished: [2d714880c68a824dae62049eecc91599] 185 | Type: Call 186 | From: 7001;tag=1244ddd6 187 | To: 448455915802 188 | UAC: sipcli/v1.8 189 | CDR init ts: 1395928246 190 | SDT: 8 sec 191 | CDR termination ts: 1395928254 192 | Was connected: NO 193 | REASON: 407 194 | ----------------------------------------------- 195 | 196 | ``` 197 | 198 | ### Colorful SIP Output: 199 | 200 | ![Screenshot](https://cloud.githubusercontent.com/assets/4513061/2536095/2ca6e1f8-b599-11e3-9451-708b7c614f5f.png) 201 | 202 | 203 | ## License 204 | 205 | Copyright (c) 2014-2016 Alexandr Dubovikov 206 | 207 | sipgrep is released under GNU GPL v3. See [COPYING](COPYING) for details. 208 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "You need to have m4, automake, autoconf, libtool..."; 4 | #aclocal 5 | autoreconf --force --install 6 | #automake --add-missing 7 | autoconf 8 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the `fork' function. */ 8 | #define HAVE_FORK 1 9 | 10 | /* Define to 1 if you have the `gettimeofday' function. */ 11 | #define HAVE_GETTIMEOFDAY 1 12 | 13 | /* no HEP support */ 14 | #define HAVE_HEP 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 if you have the `dl' library (-ldl). */ 20 | #define HAVE_LIBDL 1 21 | 22 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 23 | /* #undef HAVE_LIBNSL */ 24 | 25 | /* Define to 1 if you have the `pcap' library (-lpcap). */ 26 | #define HAVE_LIBPCAP 1 27 | 28 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 29 | #define HAVE_LIBPTHREAD 1 30 | 31 | /* Define to 1 if you have the `socket' library (-lsocket). */ 32 | /* #undef HAVE_LIBSOCKET */ 33 | 34 | /* Define to 1 if you have the `wpcap' library (-lwpcap). */ 35 | /* #undef HAVE_LIBWPCAP */ 36 | 37 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 38 | to 0 otherwise. */ 39 | #define HAVE_MALLOC 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | #define HAVE_MEMORY_H 1 43 | 44 | /* Define to 1 if you have the `memset' function. */ 45 | #define HAVE_MEMSET 1 46 | 47 | /* Define to 1 if you have the `select' function. */ 48 | #define HAVE_SELECT 1 49 | 50 | /* Define to 1 if you have the `socket' function. */ 51 | #define HAVE_SOCKET 1 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #define HAVE_STDINT_H 1 55 | 56 | /* Define to 1 if you have the header file. */ 57 | #define HAVE_STDLIB_H 1 58 | 59 | /* Define to 1 if you have the `strdup' function. */ 60 | #define HAVE_STRDUP 1 61 | 62 | /* Define to 1 if you have the `strerror' function. */ 63 | #define HAVE_STRERROR 1 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #define HAVE_STRINGS_H 1 67 | 68 | /* Define to 1 if you have the header file. */ 69 | #define HAVE_STRING_H 1 70 | 71 | /* Define to 1 if you have the `strndup' function. */ 72 | #define HAVE_STRNDUP 1 73 | 74 | /* Define to 1 if you have the header file. */ 75 | #define HAVE_SYS_STAT_H 1 76 | 77 | /* Define to 1 if you have the header file. */ 78 | #define HAVE_SYS_TYPES_H 1 79 | 80 | /* Define to 1 if you have the header file. */ 81 | #define HAVE_UNISTD_H 1 82 | 83 | /* Define to 1 if you have the `vfork' function. */ 84 | #define HAVE_VFORK 1 85 | 86 | /* Define to 1 if you have the header file. */ 87 | /* #undef HAVE_VFORK_H */ 88 | 89 | /* Define to 1 if `fork' works. */ 90 | #define HAVE_WORKING_FORK 1 91 | 92 | /* Define to 1 if `vfork' works. */ 93 | #define HAVE_WORKING_VFORK 1 94 | 95 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 96 | */ 97 | #define LT_OBJDIR ".libs/" 98 | 99 | /* Define to 1 if Operating System is Darwin */ 100 | /* #undef OS_DARWIN */ 101 | 102 | /* Define to 1 if Operating System is FreeBSD */ 103 | /* #undef OS_FREEBSD */ 104 | 105 | /* Define to 1 if Operating System is Linux */ 106 | #define OS_LINUX 1 107 | 108 | /* Define to 1 if Operating System is NETBSD */ 109 | /* #undef OS_NETBSD */ 110 | 111 | /* Define to 1 if Operating System is SOLARIS */ 112 | /* #undef OS_SOLARIS */ 113 | 114 | /* Name of package */ 115 | #define PACKAGE "sipgrep" 116 | 117 | /* Define to the address where bug reports for this package should be sent. */ 118 | #define PACKAGE_BUGREPORT "support@sipcapture.org" 119 | 120 | /* Define to the full name of this package. */ 121 | #define PACKAGE_NAME "sipgrep" 122 | 123 | /* Define to the full name and version of this package. */ 124 | #define PACKAGE_STRING "sipgrep 2.2.0" 125 | 126 | /* Define to the one symbol short name of this package. */ 127 | #define PACKAGE_TARNAME "sipgrep" 128 | 129 | /* Define to the home page for this package. */ 130 | #define PACKAGE_URL "http://www.sipcapture.org" 131 | 132 | /* Define to the version of this package. */ 133 | #define PACKAGE_VERSION "2.2.0" 134 | 135 | /* Define to 1 if you have the ANSI C header files. */ 136 | #define STDC_HEADERS 1 137 | 138 | /* Use NCURSES library */ 139 | /* #undef USE_NCURSES */ 140 | 141 | /* Use PCRE library */ 142 | /* #undef USE_PCRE */ 143 | 144 | /* Use REDIS library */ 145 | /* #undef USE_REDIS */ 146 | 147 | /* Use OpenSSL SSL library */ 148 | /* #undef USE_SSL */ 149 | 150 | /* Use ZIP library */ 151 | /* #undef USE_ZLIB */ 152 | 153 | /* Version number of package */ 154 | #define VERSION "2.2.0" 155 | 156 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 157 | , or is not used. If the typedef were allowed, the 158 | #define below would cause a syntax error. */ 159 | /* #undef _UINT32_T */ 160 | 161 | /* Define for Solaris 2.5.1 so the uint8_t typedef from , 162 | , or is not used. If the typedef were allowed, the 163 | #define below would cause a syntax error. */ 164 | /* #undef _UINT8_T */ 165 | 166 | /* Define to the type of a signed integer type of width exactly 32 bits if 167 | such a type exists and the standard includes do not define it. */ 168 | /* #undef int32_t */ 169 | 170 | /* Define to the type of a signed integer type of width exactly 8 bits if such 171 | a type exists and the standard includes do not define it. */ 172 | /* #undef int8_t */ 173 | 174 | /* Define to rpl_malloc if the replacement function should be used. */ 175 | /* #undef malloc */ 176 | 177 | /* Define to `int' if does not define. */ 178 | /* #undef pid_t */ 179 | 180 | /* Define to the type of an unsigned integer type of width exactly 16 bits if 181 | such a type exists and the standard includes do not define it. */ 182 | /* #undef uint16_t */ 183 | 184 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 185 | such a type exists and the standard includes do not define it. */ 186 | /* #undef uint32_t */ 187 | 188 | /* Define to the type of an unsigned integer type of width exactly 8 bits if 189 | such a type exists and the standard includes do not define it. */ 190 | /* #undef uint8_t */ 191 | 192 | /* Define as `fork' if `vfork' does not work. */ 193 | /* #undef vfork */ 194 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_DLFCN_H 5 | 6 | /* Define to 1 if you have the `fork' function. */ 7 | #undef HAVE_FORK 8 | 9 | /* Define to 1 if you have the `gettimeofday' function. */ 10 | #undef HAVE_GETTIMEOFDAY 11 | 12 | /* no HEP support */ 13 | #undef HAVE_HEP 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the `dl' library (-ldl). */ 19 | #undef HAVE_LIBDL 20 | 21 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 22 | #undef HAVE_LIBNSL 23 | 24 | /* Define to 1 if you have the `pcap' library (-lpcap). */ 25 | #undef HAVE_LIBPCAP 26 | 27 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 28 | #undef HAVE_LIBPTHREAD 29 | 30 | /* Define to 1 if you have the `socket' library (-lsocket). */ 31 | #undef HAVE_LIBSOCKET 32 | 33 | /* Define to 1 if you have the `wpcap' library (-lwpcap). */ 34 | #undef HAVE_LIBWPCAP 35 | 36 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 37 | to 0 otherwise. */ 38 | #undef HAVE_MALLOC 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #undef HAVE_MEMORY_H 42 | 43 | /* Define to 1 if you have the `memset' function. */ 44 | #undef HAVE_MEMSET 45 | 46 | /* Define to 1 if you have the `select' function. */ 47 | #undef HAVE_SELECT 48 | 49 | /* Define to 1 if you have the `socket' function. */ 50 | #undef HAVE_SOCKET 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #undef HAVE_STDINT_H 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_STDLIB_H 57 | 58 | /* Define to 1 if you have the `strdup' function. */ 59 | #undef HAVE_STRDUP 60 | 61 | /* Define to 1 if you have the `strerror' function. */ 62 | #undef HAVE_STRERROR 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #undef HAVE_STRINGS_H 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #undef HAVE_STRING_H 69 | 70 | /* Define to 1 if you have the `strndup' function. */ 71 | #undef HAVE_STRNDUP 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #undef HAVE_SYS_STAT_H 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #undef HAVE_SYS_TYPES_H 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #undef HAVE_UNISTD_H 81 | 82 | /* Define to 1 if you have the `vfork' function. */ 83 | #undef HAVE_VFORK 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #undef HAVE_VFORK_H 87 | 88 | /* Define to 1 if `fork' works. */ 89 | #undef HAVE_WORKING_FORK 90 | 91 | /* Define to 1 if `vfork' works. */ 92 | #undef HAVE_WORKING_VFORK 93 | 94 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 95 | */ 96 | #undef LT_OBJDIR 97 | 98 | /* Define to 1 if Operating System is Darwin */ 99 | #undef OS_DARWIN 100 | 101 | /* Define to 1 if Operating System is FreeBSD */ 102 | #undef OS_FREEBSD 103 | 104 | /* Define to 1 if Operating System is Linux */ 105 | #undef OS_LINUX 106 | 107 | /* Define to 1 if Operating System is NETBSD */ 108 | #undef OS_NETBSD 109 | 110 | /* Define to 1 if Operating System is SOLARIS */ 111 | #undef OS_SOLARIS 112 | 113 | /* Name of package */ 114 | #undef PACKAGE 115 | 116 | /* Define to the address where bug reports for this package should be sent. */ 117 | #undef PACKAGE_BUGREPORT 118 | 119 | /* Define to the full name of this package. */ 120 | #undef PACKAGE_NAME 121 | 122 | /* Define to the full name and version of this package. */ 123 | #undef PACKAGE_STRING 124 | 125 | /* Define to the one symbol short name of this package. */ 126 | #undef PACKAGE_TARNAME 127 | 128 | /* Define to the home page for this package. */ 129 | #undef PACKAGE_URL 130 | 131 | /* Define to the version of this package. */ 132 | #undef PACKAGE_VERSION 133 | 134 | /* Define to 1 if you have the ANSI C header files. */ 135 | #undef STDC_HEADERS 136 | 137 | /* Use NCURSES library */ 138 | #undef USE_NCURSES 139 | 140 | /* Use PCRE library */ 141 | #undef USE_PCRE 142 | 143 | /* Use REDIS library */ 144 | #undef USE_REDIS 145 | 146 | /* Use OpenSSL SSL library */ 147 | #undef USE_SSL 148 | 149 | /* Use ZIP library */ 150 | #undef USE_ZLIB 151 | 152 | /* Version number of package */ 153 | #undef VERSION 154 | 155 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 156 | , or is not used. If the typedef were allowed, the 157 | #define below would cause a syntax error. */ 158 | #undef _UINT32_T 159 | 160 | /* Define for Solaris 2.5.1 so the uint8_t typedef from , 161 | , or is not used. If the typedef were allowed, the 162 | #define below would cause a syntax error. */ 163 | #undef _UINT8_T 164 | 165 | /* Define to the type of a signed integer type of width exactly 32 bits if 166 | such a type exists and the standard includes do not define it. */ 167 | #undef int32_t 168 | 169 | /* Define to the type of a signed integer type of width exactly 8 bits if such 170 | a type exists and the standard includes do not define it. */ 171 | #undef int8_t 172 | 173 | /* Define to rpl_malloc if the replacement function should be used. */ 174 | #undef malloc 175 | 176 | /* Define to `int' if does not define. */ 177 | #undef pid_t 178 | 179 | /* Define to the type of an unsigned integer type of width exactly 16 bits if 180 | such a type exists and the standard includes do not define it. */ 181 | #undef uint16_t 182 | 183 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 184 | such a type exists and the standard includes do not define it. */ 185 | #undef uint32_t 186 | 187 | /* Define to the type of an unsigned integer type of width exactly 8 bits if 188 | such a type exists and the standard includes do not define it. */ 189 | #undef uint8_t 190 | 191 | /* Define as `fork' if `vfork' does not work. */ 192 | #undef vfork 193 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.61) 2 | AC_INIT(sipgrep,2.2.1,support@sipcapture.org,,[http://www.sipcapture.org]) 3 | AC_COPYRIGHT("SIP Capture Solution") 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | AM_INIT_AUTOMAKE(foreign tar-ustar) 6 | AC_CONFIG_HEADERS([src/config.h]) 7 | AC_MSG_CHECKING([whether to use compression]) 8 | enableCompression=no 9 | AC_ARG_ENABLE(compression, 10 | [ --enable-compression Enable compression support)], 11 | [ZLIB="$enableval"] 12 | enableCompression=yes, 13 | [ZLIB="no"] 14 | ) 15 | AC_MSG_RESULT([$ZLIB]) 16 | AC_SUBST([ZLIB]) 17 | 18 | AC_MSG_CHECKING([whether to use ssl]) 19 | enableSSL=no 20 | AC_ARG_ENABLE(ssl, 21 | [ --enable-ssl Enable SSL support)], 22 | [SSL="$enableval"] 23 | enableSSL=yes, 24 | [SSL="no"] 25 | ) 26 | AC_MSG_RESULT([$SSL]) 27 | AC_SUBST([SSL]) 28 | 29 | usePCRE2=yes 30 | AC_SUBST([PCRE2]) 31 | 32 | useNCURSES=no 33 | AC_MSG_CHECKING([whether to use ncurses]) 34 | AC_ARG_ENABLE(ncurses, 35 | [ --enable-ncurses Enable ncurses support)], 36 | [NCURSES="$enableval"] 37 | useNCURSES=yes, 38 | [NCURSES="no"] 39 | ) 40 | AC_MSG_RESULT([$NCURSES]) 41 | AC_SUBST([NCURSES]) 42 | 43 | 44 | useRedis=no 45 | AC_MSG_CHECKING([whether to use redis]) 46 | AC_ARG_ENABLE(redis, 47 | [ --enable-redis Enable redis support)], 48 | [REDIS="$enableval"] 49 | useRedis=yes, 50 | [REDIS="no"] 51 | ) 52 | AC_MSG_RESULT([$REDIS]) 53 | AC_SUBST([REDIS]) 54 | 55 | dnl 56 | dnl IPv6 (and ICMPv6) support 57 | dnl 58 | 59 | AC_ARG_ENABLE(ipv6, 60 | [ --enable-ipv6 enable IPv6 (and ICMPv6) support], 61 | [ 62 | use_ipv6="$enableval" 63 | ], 64 | [ 65 | use_ipv6="no" 66 | ]) 67 | 68 | if test $use_ipv6 = yes; then 69 | AC_DEFINE(USE_IPv6, [1], [IPv6 (and ICMPv6) support]) 70 | AC_SUBST(USE_IPv6, yes) 71 | fi 72 | 73 | 74 | enableHEP=yes 75 | dnl 76 | dnl HEP/EEP support 77 | dnl 78 | 79 | AC_ARG_ENABLE(hep, 80 | [ --disable-hep disable HEP/EEP support], 81 | [ 82 | use_hep="no" 83 | ], 84 | [ 85 | use_hep="yes" 86 | ]) 87 | 88 | if test $use_hep = yes; then 89 | AC_DEFINE(HAVE_HEP, 1, [HEP support]) 90 | AC_SUBST(HAVE_HEP, yes) 91 | else 92 | AC_DEFINE(HAVE_HEP, 0, [no HEP support]) 93 | AC_SUBST(HAVE_HEP, no) 94 | enableHEP=no 95 | fi 96 | 97 | 98 | CONFIG_CFLAGS="${CFLAGS}" 99 | CONFIG_LDFLAGS="${LDFLAGS}" 100 | 101 | MODULES='$$(grep -v "\#" $(sipgrep_builddir)/modules.list | sed -e "s|^.*/||" | sort | uniq )' 102 | AM_MAKEFLAGS='"OUR_MODULES=$(MODULESS)" `test -n "$(VERBOSE)" || echo -s`' 103 | AC_SUBST(OUR_MODS) 104 | 105 | #AC_ENABLE_SHARED(yes) 106 | #AC_ENABLE_STATIC(no) 107 | 108 | #AC_CANONICAL_SYSTEM 109 | #AM_INIT_AUTOMAKE() 110 | 111 | LT_INIT 112 | 113 | AC_CANONICAL_HOST 114 | case "${host}" in 115 | *-*-darwin*) 116 | AC_DEFINE([OS_DARWIN], [1], [Define to 1 if Operating System is Darwin]) 117 | AC_SUBST(OS_DARWIN, 1) 118 | ;; 119 | *-*-freebsd*) 120 | AC_DEFINE([OS_FREEBSD], [1], [Define to 1 if Operating System is FreeBSD]) 121 | AC_SUBST(OS_FREEBSD, 1) 122 | ;; 123 | *-*-linux*) 124 | AC_DEFINE([OS_LINUX], [1], [Define to 1 if Operating System is Linux]) 125 | AC_SUBST(OS_LINUX, 1) 126 | ;; 127 | *-*-netbsd*) 128 | AC_DEFINE([OS_NETBSD], [1], [Define to 1 if Operating System is NETBSD]) 129 | AC_SUBST(OS_NETBSD, 1) 130 | ;; 131 | *-*-solaris*) 132 | AC_DEFINE([OS_SOLARIS], [1], [Define to 1 if Operating System is SOLARIS]) 133 | AC_SUBST(OS_SOLARIS, 1) 134 | AC_CHECK_LIB(socket, socket,, 135 | echo no socket in -lsocket\?; exit) 136 | AC_CHECK_LIB(nsl, gethostbyname,, 137 | echo no gethostbyname in -lnsl\?; exit) 138 | 139 | EXTRA_LIBS="$EXTRA_LIBS -lnsl -lsocket" 140 | ;; 141 | *) 142 | AC_MSG_RESULT([Unsupported operating system: ${host}]) 143 | ;; 144 | esac 145 | 146 | # Checks for programs 147 | AC_PROG_CC 148 | # AC_PROG_CC([gcc cc]) 149 | 150 | AC_PROG_INSTALL 151 | AC_PROG_LN_S 152 | AC_PROG_MAKE_SET 153 | AC_LIBTOOL_DLOPEN 154 | AC_PROG_LIBTOOL 155 | 156 | EXTRA_DEFINES="$EXTRA_DEFINES -D_BSD_SOURCE=1 -D__FAVOR_BSD=1" 157 | 158 | # Checks for libraries. 159 | AC_CHECK_LIB(pthread, pthread_create, , [AC_MSG_ERROR([sipgrep requires but cannot find pthread])]) 160 | if test "$OS_LINUX" = 1 ; then 161 | AC_CHECK_LIB(dl, dlopen, , [AC_MSG_ERROR([sipgrep requires but cannot find libdl])]) 162 | fi 163 | 164 | AC_CHECK_LIB(pcap, pcap_open_live, ,[AC_CHECK_LIB(wpcap, pcap_open_live, ,[AC_MSG_ERROR([sipgrep requires but cannot find libpcap])])]) 165 | 166 | AC_SUBST(PTHREAD_LIBS) 167 | AC_SUBST(DL_LIBS) 168 | AC_SUBST(PCAP_LIBS) 169 | 170 | 171 | dnl 172 | dnl check for pcre2 library 173 | dnl 174 | 175 | # Checks for libpcre2 176 | AC_CHECKING([for pcre2 Library and Header files]) 177 | AC_CHECK_HEADER([pcre2.h], ,AC_MSG_ERROR([Could not find pcre2 headers !]), [#define PCRE2_CODE_UNIT_WIDTH 8]) 178 | AC_CHECK_LIB([pcre2-8], [pcre2_compile_8], ,[AC_MSG_ERROR([libpcre2 required])]) 179 | AC_DEFINE(USE_PCRE2, 1, [Use PCRE2 library]) 180 | AC_SUBST(PCRE2_LIBS) 181 | 182 | 183 | dnl 184 | dnl check for ncurses library 185 | dnl 186 | 187 | # Checks for ncurses 188 | if test "$NCURSES" = "yes"; then 189 | AC_CHECKING([for ncurses Library and Header files]) 190 | AC_CHECK_HEADER([ncurses.h], ,AC_MSG_ERROR([Could not find ncurses headers !])) 191 | AC_CHECK_LIB([ncurses], [initscr],, [AC_MSG_ERROR([libncurses required])]) 192 | AC_DEFINE(USE_NCURSES, 1, [Use NCURSES library]) 193 | AC_SUBST(NCURSES_LIBS) 194 | AC_SUBST(USE_NCURSES, yes) 195 | fi 196 | 197 | 198 | dnl 199 | dnl check for compression library 200 | dnl 201 | 202 | if test "$ZLIB" = "yes"; then 203 | AC_CHECKING([for zip Library and Header files]) 204 | AC_CHECK_HEADER(zlib.h,,[AC_MSG_ERROR([zlib.h headers not found.])]) 205 | AC_CHECK_LIB(z, inflate, , [AC_MSG_ERROR([sipgrep requires but cannot find lz])]) 206 | AC_DEFINE(USE_ZLIB, 1, [Use ZIP library]) 207 | fi 208 | 209 | dnl 210 | dnl check for redis library 211 | dnl 212 | 213 | if test "$REDIS" = "yes"; then 214 | AC_CHECKING([for redis Library and Header files]) 215 | AC_CHECK_HEADER(hiredis/hiredis.h,,[AC_MSG_ERROR([hiredis/hiredis.h headers not found.])]) 216 | AC_CHECK_LIB(hiredis, redisCommand, , [AC_MSG_ERROR([sipgrep requires but cannot find lhiredis])]) 217 | AC_DEFINE(USE_REDIS, 1, [Use REDIS library]) 218 | AC_SUBST(HIREDIS_LIBS) 219 | fi 220 | 221 | 222 | dnl 223 | dnl check for OpenSSL-SSL library 224 | dnl 225 | 226 | if test "$SSL" = "yes"; then 227 | AC_CHECKING([for OpenSSL SSL Library and Header files]) 228 | AC_CHECK_HEADER(openssl/ssl.h,, [AC_MSG_ERROR([OpenSSL SSL headers not found.])]) 229 | AC_CHECK_LIB(ssl, SSL_accept, , [AC_MSG_ERROR([sipgrep requires but cannot find ssl])]) 230 | AC_DEFINE(USE_SSL, 1, [Use OpenSSL SSL library]) 231 | fi 232 | 233 | # Checks for header files. 234 | AC_CHECK_HEADER(pcap.h,,[AC_MSG_ERROR([sipgrep cannot find pcap.h])]) 235 | 236 | # conditional checks 237 | AM_CONDITIONAL([HAVE_HEP],[test "x$HAVE_HEP" == "xyes"]) 238 | AM_CONDITIONAL([USE_NCURSES],[test "x$USE_NCURSES" == "xyes"]) 239 | 240 | # Checks for typedefs, structures, and compiler characteristics. 241 | AC_TYPE_INT32_T 242 | AC_TYPE_INT8_T 243 | AC_TYPE_PID_T 244 | AC_TYPE_UINT16_T 245 | AC_TYPE_UINT32_T 246 | AC_TYPE_UINT8_T 247 | 248 | # Checks for library functions. 249 | AC_FUNC_FORK 250 | AC_FUNC_MALLOC 251 | AC_CHECK_FUNCS([gettimeofday memset select socket strdup strerror strndup]) 252 | 253 | AC_CONFIG_FILES([ 254 | Makefile 255 | src/Makefile 256 | ]) 257 | 258 | AC_OUTPUT 259 | 260 | 261 | echo 262 | echo $PACKAGE $VERSION 263 | echo 264 | echo Build directory............. : $sipgrep_builddir 265 | echo Installation prefix......... : $prefix 266 | echo IPv6 support.................: $use_ipv6 267 | echo HEP support................. : $enableHEP 268 | echo HEP Compression............. : $enableCompression 269 | echo SSL/TLS..................... : $enableSSL 270 | echo Ncurses support............. : $useNCURSES 271 | 272 | echo 273 | echo Build with REDIS............ : $useRedis 274 | echo Build with PCRE............. : $usePCRE2 275 | echo 276 | 277 | -------------------------------------------------------------------------------- /doc/REGEX.txt: -------------------------------------------------------------------------------- 1 | $Id: REGEX.txt,v 1.3 2005/02/22 06:28:14 jpr5 Exp $ 2 | 3 | Date: 2/21/05 4 | 5 | A note about PCRE vs. GNU regex: 6 | 7 | I ran several tests comparing GNU regex 0.12 to the PCRE 5.0 8 | library using 100 million loop iterations: optimized 9 | vs. non-optimized, match vs. non-match. The obvious conclusion 10 | is that GNU regex is the reigning king of speed, and that with 11 | regular expression engines optimization matters significantly. 12 | 13 | (Please note that I tried other third-party regex libraries like 14 | RxSpencer's and libhackerlab's, and none came close to 15 | comparing.) 16 | 17 | The test subject was "how now brown cow", and the pattern we 18 | were searching for in the match case was "now brown", and in the 19 | non-match case "not brown". Obviously, the speed of matches is 20 | directly related to the actual regex itself, and a 21 | well-formulated regex certainly performs more efficiently than a 22 | simple substring match. However, this test is reasonably 23 | indicative of how most people use ngrep, so the test results are 24 | still useful. 25 | 26 | Granted, on the single-match level the time difference is 27 | absolutely unnoticeable (it took 100 million loop iterations to 28 | compute something worthwhile), so this may not mean anything to 29 | you. Likewise, the stripped binary sizes are also within 10k of 30 | each other on the test compile box. 31 | 32 | If licensing terms are more sensitive for you than speed then 33 | compile against PCRE, which is available under the Artistic 34 | License (Free as in Beer). Otherwise, in all other cases the 35 | GNU regex library is the best candidate, and the speed can 36 | really help when piping those 500MB pcap dump files through 37 | ngrep over and over for analysis. 38 | 39 | 40 | Test results: 41 | 42 | CPU: Intel Pentium-M 2GHz 43 | L1 I cache: 32K, L1 D cache: 32K 44 | L2 cache: 2048K 45 | 46 | Iterations: 100M 47 | 48 | match nomatch 49 | 50 | [-O0] 51 | GNU regex-0.12 17.369s/17.385s 32.656s/32.069s 52 | PCRE-5.0 35.840s/35.795s 25.340s/25.344s 53 | 54 | [-O2] 55 | GNU regex-0.12 12.240s/12.280s 19.512s/19.489s 56 | PCRE-5.0 24.580s/24.578s 17.235s/17.238s 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # install - install a program, script, or datafile 3 | 4 | scriptversion=2011-01-19.21; # UTC 5 | 6 | # This originates from X11R5 (mit/util/scripts/install.sh), which was 7 | # later released in X11R6 (xc/config/util/install.sh) with the 8 | # following copyright and license. 9 | # 10 | # Copyright (C) 1994 X Consortium 11 | # 12 | # Permission is hereby granted, free of charge, to any person obtaining a copy 13 | # of this software and associated documentation files (the "Software"), to 14 | # deal in the Software without restriction, including without limitation the 15 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | # sell copies of the Software, and to permit persons to whom the Software is 17 | # furnished to do so, subject to the following conditions: 18 | # 19 | # The above copyright notice and this permission notice shall be included in 20 | # all copies or substantial portions of the Software. 21 | # 22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27 | # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | # 29 | # Except as contained in this notice, the name of the X Consortium shall not 30 | # be used in advertising or otherwise to promote the sale, use or other deal- 31 | # ings in this Software without prior written authorization from the X Consor- 32 | # tium. 33 | # 34 | # 35 | # FSF changes to this file are in the public domain. 36 | # 37 | # Calling this script install-sh is preferred over install.sh, to prevent 38 | # `make' implicit rules from creating a file called install from it 39 | # when there is no Makefile. 40 | # 41 | # This script is compatible with the BSD install script, but was written 42 | # from scratch. 43 | 44 | nl=' 45 | ' 46 | IFS=" "" $nl" 47 | 48 | # set DOITPROG to echo to test this script 49 | 50 | # Don't use :- since 4.3BSD and earlier shells don't like it. 51 | doit=${DOITPROG-} 52 | if test -z "$doit"; then 53 | doit_exec=exec 54 | else 55 | doit_exec=$doit 56 | fi 57 | 58 | # Put in absolute file names if you don't have them in your path; 59 | # or use environment vars. 60 | 61 | chgrpprog=${CHGRPPROG-chgrp} 62 | chmodprog=${CHMODPROG-chmod} 63 | chownprog=${CHOWNPROG-chown} 64 | cmpprog=${CMPPROG-cmp} 65 | cpprog=${CPPROG-cp} 66 | mkdirprog=${MKDIRPROG-mkdir} 67 | mvprog=${MVPROG-mv} 68 | rmprog=${RMPROG-rm} 69 | stripprog=${STRIPPROG-strip} 70 | 71 | posix_glob='?' 72 | initialize_posix_glob=' 73 | test "$posix_glob" != "?" || { 74 | if (set -f) 2>/dev/null; then 75 | posix_glob= 76 | else 77 | posix_glob=: 78 | fi 79 | } 80 | ' 81 | 82 | posix_mkdir= 83 | 84 | # Desired mode of installed file. 85 | mode=0755 86 | 87 | chgrpcmd= 88 | chmodcmd=$chmodprog 89 | chowncmd= 90 | mvcmd=$mvprog 91 | rmcmd="$rmprog -f" 92 | stripcmd= 93 | 94 | src= 95 | dst= 96 | dir_arg= 97 | dst_arg= 98 | 99 | copy_on_change=false 100 | no_target_directory= 101 | 102 | usage="\ 103 | Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104 | or: $0 [OPTION]... SRCFILES... DIRECTORY 105 | or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106 | or: $0 [OPTION]... -d DIRECTORIES... 107 | 108 | In the 1st form, copy SRCFILE to DSTFILE. 109 | In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110 | In the 4th, create DIRECTORIES. 111 | 112 | Options: 113 | --help display this help and exit. 114 | --version display version info and exit. 115 | 116 | -c (ignored) 117 | -C install only if different (preserve the last data modification time) 118 | -d create directories instead of installing files. 119 | -g GROUP $chgrpprog installed files to GROUP. 120 | -m MODE $chmodprog installed files to MODE. 121 | -o USER $chownprog installed files to USER. 122 | -s $stripprog installed files. 123 | -t DIRECTORY install into DIRECTORY. 124 | -T report an error if DSTFILE is a directory. 125 | 126 | Environment variables override the default commands: 127 | CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128 | RMPROG STRIPPROG 129 | " 130 | 131 | while test $# -ne 0; do 132 | case $1 in 133 | -c) ;; 134 | 135 | -C) copy_on_change=true;; 136 | 137 | -d) dir_arg=true;; 138 | 139 | -g) chgrpcmd="$chgrpprog $2" 140 | shift;; 141 | 142 | --help) echo "$usage"; exit $?;; 143 | 144 | -m) mode=$2 145 | case $mode in 146 | *' '* | *' '* | *' 147 | '* | *'*'* | *'?'* | *'['*) 148 | echo "$0: invalid mode: $mode" >&2 149 | exit 1;; 150 | esac 151 | shift;; 152 | 153 | -o) chowncmd="$chownprog $2" 154 | shift;; 155 | 156 | -s) stripcmd=$stripprog;; 157 | 158 | -t) dst_arg=$2 159 | # Protect names problematic for `test' and other utilities. 160 | case $dst_arg in 161 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 162 | esac 163 | shift;; 164 | 165 | -T) no_target_directory=true;; 166 | 167 | --version) echo "$0 $scriptversion"; exit $?;; 168 | 169 | --) shift 170 | break;; 171 | 172 | -*) echo "$0: invalid option: $1" >&2 173 | exit 1;; 174 | 175 | *) break;; 176 | esac 177 | shift 178 | done 179 | 180 | if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181 | # When -d is used, all remaining arguments are directories to create. 182 | # When -t is used, the destination is already specified. 183 | # Otherwise, the last argument is the destination. Remove it from $@. 184 | for arg 185 | do 186 | if test -n "$dst_arg"; then 187 | # $@ is not empty: it contains at least $arg. 188 | set fnord "$@" "$dst_arg" 189 | shift # fnord 190 | fi 191 | shift # arg 192 | dst_arg=$arg 193 | # Protect names problematic for `test' and other utilities. 194 | case $dst_arg in 195 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 196 | esac 197 | done 198 | fi 199 | 200 | if test $# -eq 0; then 201 | if test -z "$dir_arg"; then 202 | echo "$0: no input file specified." >&2 203 | exit 1 204 | fi 205 | # It's OK to call `install-sh -d' without argument. 206 | # This can happen when creating conditional directories. 207 | exit 0 208 | fi 209 | 210 | if test -z "$dir_arg"; then 211 | do_exit='(exit $ret); exit $ret' 212 | trap "ret=129; $do_exit" 1 213 | trap "ret=130; $do_exit" 2 214 | trap "ret=141; $do_exit" 13 215 | trap "ret=143; $do_exit" 15 216 | 217 | # Set umask so as not to create temps with too-generous modes. 218 | # However, 'strip' requires both read and write access to temps. 219 | case $mode in 220 | # Optimize common cases. 221 | *644) cp_umask=133;; 222 | *755) cp_umask=22;; 223 | 224 | *[0-7]) 225 | if test -z "$stripcmd"; then 226 | u_plus_rw= 227 | else 228 | u_plus_rw='% 200' 229 | fi 230 | cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231 | *) 232 | if test -z "$stripcmd"; then 233 | u_plus_rw= 234 | else 235 | u_plus_rw=,u+rw 236 | fi 237 | cp_umask=$mode$u_plus_rw;; 238 | esac 239 | fi 240 | 241 | for src 242 | do 243 | # Protect names problematic for `test' and other utilities. 244 | case $src in 245 | -* | [=\(\)!]) src=./$src;; 246 | esac 247 | 248 | if test -n "$dir_arg"; then 249 | dst=$src 250 | dstdir=$dst 251 | test -d "$dstdir" 252 | dstdir_status=$? 253 | else 254 | 255 | # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256 | # might cause directories to be created, which would be especially bad 257 | # if $src (and thus $dsttmp) contains '*'. 258 | if test ! -f "$src" && test ! -d "$src"; then 259 | echo "$0: $src does not exist." >&2 260 | exit 1 261 | fi 262 | 263 | if test -z "$dst_arg"; then 264 | echo "$0: no destination specified." >&2 265 | exit 1 266 | fi 267 | dst=$dst_arg 268 | 269 | # If destination is a directory, append the input filename; won't work 270 | # if double slashes aren't ignored. 271 | if test -d "$dst"; then 272 | if test -n "$no_target_directory"; then 273 | echo "$0: $dst_arg: Is a directory" >&2 274 | exit 1 275 | fi 276 | dstdir=$dst 277 | dst=$dstdir/`basename "$src"` 278 | dstdir_status=0 279 | else 280 | # Prefer dirname, but fall back on a substitute if dirname fails. 281 | dstdir=` 282 | (dirname "$dst") 2>/dev/null || 283 | expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284 | X"$dst" : 'X\(//\)[^/]' \| \ 285 | X"$dst" : 'X\(//\)$' \| \ 286 | X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287 | echo X"$dst" | 288 | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289 | s//\1/ 290 | q 291 | } 292 | /^X\(\/\/\)[^/].*/{ 293 | s//\1/ 294 | q 295 | } 296 | /^X\(\/\/\)$/{ 297 | s//\1/ 298 | q 299 | } 300 | /^X\(\/\).*/{ 301 | s//\1/ 302 | q 303 | } 304 | s/.*/./; q' 305 | ` 306 | 307 | test -d "$dstdir" 308 | dstdir_status=$? 309 | fi 310 | fi 311 | 312 | obsolete_mkdir_used=false 313 | 314 | if test $dstdir_status != 0; then 315 | case $posix_mkdir in 316 | '') 317 | # Create intermediate dirs using mode 755 as modified by the umask. 318 | # This is like FreeBSD 'install' as of 1997-10-28. 319 | umask=`umask` 320 | case $stripcmd.$umask in 321 | # Optimize common cases. 322 | *[2367][2367]) mkdir_umask=$umask;; 323 | .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324 | 325 | *[0-7]) 326 | mkdir_umask=`expr $umask + 22 \ 327 | - $umask % 100 % 40 + $umask % 20 \ 328 | - $umask % 10 % 4 + $umask % 2 329 | `;; 330 | *) mkdir_umask=$umask,go-w;; 331 | esac 332 | 333 | # With -d, create the new directory with the user-specified mode. 334 | # Otherwise, rely on $mkdir_umask. 335 | if test -n "$dir_arg"; then 336 | mkdir_mode=-m$mode 337 | else 338 | mkdir_mode= 339 | fi 340 | 341 | posix_mkdir=false 342 | case $umask in 343 | *[123567][0-7][0-7]) 344 | # POSIX mkdir -p sets u+wx bits regardless of umask, which 345 | # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346 | ;; 347 | *) 348 | tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349 | trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350 | 351 | if (umask $mkdir_umask && 352 | exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353 | then 354 | if test -z "$dir_arg" || { 355 | # Check for POSIX incompatibilities with -m. 356 | # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357 | # other-writeable bit of parent directory when it shouldn't. 358 | # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359 | ls_ld_tmpdir=`ls -ld "$tmpdir"` 360 | case $ls_ld_tmpdir in 361 | d????-?r-*) different_mode=700;; 362 | d????-?--*) different_mode=755;; 363 | *) false;; 364 | esac && 365 | $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366 | ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367 | test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368 | } 369 | } 370 | then posix_mkdir=: 371 | fi 372 | rmdir "$tmpdir/d" "$tmpdir" 373 | else 374 | # Remove any dirs left behind by ancient mkdir implementations. 375 | rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376 | fi 377 | trap '' 0;; 378 | esac;; 379 | esac 380 | 381 | if 382 | $posix_mkdir && ( 383 | umask $mkdir_umask && 384 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385 | ) 386 | then : 387 | else 388 | 389 | # The umask is ridiculous, or mkdir does not conform to POSIX, 390 | # or it failed possibly due to a race condition. Create the 391 | # directory the slow way, step by step, checking for races as we go. 392 | 393 | case $dstdir in 394 | /*) prefix='/';; 395 | [-=\(\)!]*) prefix='./';; 396 | *) prefix='';; 397 | esac 398 | 399 | eval "$initialize_posix_glob" 400 | 401 | oIFS=$IFS 402 | IFS=/ 403 | $posix_glob set -f 404 | set fnord $dstdir 405 | shift 406 | $posix_glob set +f 407 | IFS=$oIFS 408 | 409 | prefixes= 410 | 411 | for d 412 | do 413 | test X"$d" = X && continue 414 | 415 | prefix=$prefix$d 416 | if test -d "$prefix"; then 417 | prefixes= 418 | else 419 | if $posix_mkdir; then 420 | (umask=$mkdir_umask && 421 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422 | # Don't fail if two instances are running concurrently. 423 | test -d "$prefix" || exit 1 424 | else 425 | case $prefix in 426 | *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427 | *) qprefix=$prefix;; 428 | esac 429 | prefixes="$prefixes '$qprefix'" 430 | fi 431 | fi 432 | prefix=$prefix/ 433 | done 434 | 435 | if test -n "$prefixes"; then 436 | # Don't fail if two instances are running concurrently. 437 | (umask $mkdir_umask && 438 | eval "\$doit_exec \$mkdirprog $prefixes") || 439 | test -d "$dstdir" || exit 1 440 | obsolete_mkdir_used=true 441 | fi 442 | fi 443 | fi 444 | 445 | if test -n "$dir_arg"; then 446 | { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448 | { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449 | test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450 | else 451 | 452 | # Make a couple of temp file names in the proper directory. 453 | dsttmp=$dstdir/_inst.$$_ 454 | rmtmp=$dstdir/_rm.$$_ 455 | 456 | # Trap to clean up those temp files at exit. 457 | trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458 | 459 | # Copy the file name to the temp name. 460 | (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461 | 462 | # and set any options; do chmod last to preserve setuid bits. 463 | # 464 | # If any of these fail, we abort the whole thing. If we want to 465 | # ignore errors from any of these, just make sure not to ignore 466 | # errors from the above "$doit $cpprog $src $dsttmp" command. 467 | # 468 | { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470 | { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471 | { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472 | 473 | # If -C, don't bother to copy if it wouldn't change the file. 474 | if $copy_on_change && 475 | old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476 | new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477 | 478 | eval "$initialize_posix_glob" && 479 | $posix_glob set -f && 480 | set X $old && old=:$2:$4:$5:$6 && 481 | set X $new && new=:$2:$4:$5:$6 && 482 | $posix_glob set +f && 483 | 484 | test "$old" = "$new" && 485 | $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486 | then 487 | rm -f "$dsttmp" 488 | else 489 | # Rename the file to the real destination. 490 | $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491 | 492 | # The rename failed, perhaps because mv can't rename something else 493 | # to itself, or perhaps because mv is so ancient that it does not 494 | # support -f. 495 | { 496 | # Now remove or move aside any old file at destination location. 497 | # We try this two ways since rm can't unlink itself on some 498 | # systems and the destination file might be busy for other 499 | # reasons. In this case, the final cleanup might fail but the new 500 | # file should still install successfully. 501 | { 502 | test ! -f "$dst" || 503 | $doit $rmcmd -f "$dst" 2>/dev/null || 504 | { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505 | { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506 | } || 507 | { echo "$0: cannot unlink or rename $dst" >&2 508 | (exit 1); exit 1 509 | } 510 | } && 511 | 512 | # Now rename the file to the real destination. 513 | $doit $mvcmd "$dsttmp" "$dst" 514 | } 515 | fi || exit 1 516 | 517 | trap '' 0 518 | fi 519 | done 520 | 521 | # Local variables: 522 | # eval: (add-hook 'write-file-hooks 'time-stamp) 523 | # time-stamp-start: "scriptversion=" 524 | # time-stamp-format: "%:y-%02m-%02d.%02H" 525 | # time-stamp-time-zone: "UTC" 526 | # time-stamp-end: "; # UTC" 527 | # End: 528 | -------------------------------------------------------------------------------- /m4/ltoptions.m4: -------------------------------------------------------------------------------- 1 | # Helper functions for option handling. -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, 4 | # Inc. 5 | # Written by Gary V. Vaughan, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # serial 7 ltoptions.m4 12 | 13 | # This is to help aclocal find these macros, as it can't see m4_define. 14 | AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) 15 | 16 | 17 | # _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) 18 | # ------------------------------------------ 19 | m4_define([_LT_MANGLE_OPTION], 20 | [[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) 21 | 22 | 23 | # _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) 24 | # --------------------------------------- 25 | # Set option OPTION-NAME for macro MACRO-NAME, and if there is a 26 | # matching handler defined, dispatch to it. Other OPTION-NAMEs are 27 | # saved as a flag. 28 | m4_define([_LT_SET_OPTION], 29 | [m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl 30 | m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), 31 | _LT_MANGLE_DEFUN([$1], [$2]), 32 | [m4_warning([Unknown $1 option `$2'])])[]dnl 33 | ]) 34 | 35 | 36 | # _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) 37 | # ------------------------------------------------------------ 38 | # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. 39 | m4_define([_LT_IF_OPTION], 40 | [m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) 41 | 42 | 43 | # _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) 44 | # ------------------------------------------------------- 45 | # Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME 46 | # are set. 47 | m4_define([_LT_UNLESS_OPTIONS], 48 | [m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), 49 | [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), 50 | [m4_define([$0_found])])])[]dnl 51 | m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 52 | ])[]dnl 53 | ]) 54 | 55 | 56 | # _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) 57 | # ---------------------------------------- 58 | # OPTION-LIST is a space-separated list of Libtool options associated 59 | # with MACRO-NAME. If any OPTION has a matching handler declared with 60 | # LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about 61 | # the unknown option and exit. 62 | m4_defun([_LT_SET_OPTIONS], 63 | [# Set options 64 | m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), 65 | [_LT_SET_OPTION([$1], _LT_Option)]) 66 | 67 | m4_if([$1],[LT_INIT],[ 68 | dnl 69 | dnl Simply set some default values (i.e off) if boolean options were not 70 | dnl specified: 71 | _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no 72 | ]) 73 | _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no 74 | ]) 75 | dnl 76 | dnl If no reference was made to various pairs of opposing options, then 77 | dnl we run the default mode handler for the pair. For example, if neither 78 | dnl `shared' nor `disable-shared' was passed, we enable building of shared 79 | dnl archives by default: 80 | _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) 81 | _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) 82 | _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) 83 | _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], 84 | [_LT_ENABLE_FAST_INSTALL]) 85 | ]) 86 | ])# _LT_SET_OPTIONS 87 | 88 | 89 | ## --------------------------------- ## 90 | ## Macros to handle LT_INIT options. ## 91 | ## --------------------------------- ## 92 | 93 | # _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) 94 | # ----------------------------------------- 95 | m4_define([_LT_MANGLE_DEFUN], 96 | [[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) 97 | 98 | 99 | # LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) 100 | # ----------------------------------------------- 101 | m4_define([LT_OPTION_DEFINE], 102 | [m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl 103 | ])# LT_OPTION_DEFINE 104 | 105 | 106 | # dlopen 107 | # ------ 108 | LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes 109 | ]) 110 | 111 | AU_DEFUN([AC_LIBTOOL_DLOPEN], 112 | [_LT_SET_OPTION([LT_INIT], [dlopen]) 113 | AC_DIAGNOSE([obsolete], 114 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 115 | put the `dlopen' option into LT_INIT's first parameter.]) 116 | ]) 117 | 118 | dnl aclocal-1.4 backwards compatibility: 119 | dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) 120 | 121 | 122 | # win32-dll 123 | # --------- 124 | # Declare package support for building win32 dll's. 125 | LT_OPTION_DEFINE([LT_INIT], [win32-dll], 126 | [enable_win32_dll=yes 127 | 128 | case $host in 129 | *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) 130 | AC_CHECK_TOOL(AS, as, false) 131 | AC_CHECK_TOOL(DLLTOOL, dlltool, false) 132 | AC_CHECK_TOOL(OBJDUMP, objdump, false) 133 | ;; 134 | esac 135 | 136 | test -z "$AS" && AS=as 137 | _LT_DECL([], [AS], [1], [Assembler program])dnl 138 | 139 | test -z "$DLLTOOL" && DLLTOOL=dlltool 140 | _LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl 141 | 142 | test -z "$OBJDUMP" && OBJDUMP=objdump 143 | _LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl 144 | ])# win32-dll 145 | 146 | AU_DEFUN([AC_LIBTOOL_WIN32_DLL], 147 | [AC_REQUIRE([AC_CANONICAL_HOST])dnl 148 | _LT_SET_OPTION([LT_INIT], [win32-dll]) 149 | AC_DIAGNOSE([obsolete], 150 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 151 | put the `win32-dll' option into LT_INIT's first parameter.]) 152 | ]) 153 | 154 | dnl aclocal-1.4 backwards compatibility: 155 | dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) 156 | 157 | 158 | # _LT_ENABLE_SHARED([DEFAULT]) 159 | # ---------------------------- 160 | # implement the --enable-shared flag, and supports the `shared' and 161 | # `disable-shared' LT_INIT options. 162 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 163 | m4_define([_LT_ENABLE_SHARED], 164 | [m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl 165 | AC_ARG_ENABLE([shared], 166 | [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], 167 | [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], 168 | [p=${PACKAGE-default} 169 | case $enableval in 170 | yes) enable_shared=yes ;; 171 | no) enable_shared=no ;; 172 | *) 173 | enable_shared=no 174 | # Look at the argument we got. We use all the common list separators. 175 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 176 | for pkg in $enableval; do 177 | IFS="$lt_save_ifs" 178 | if test "X$pkg" = "X$p"; then 179 | enable_shared=yes 180 | fi 181 | done 182 | IFS="$lt_save_ifs" 183 | ;; 184 | esac], 185 | [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) 186 | 187 | _LT_DECL([build_libtool_libs], [enable_shared], [0], 188 | [Whether or not to build shared libraries]) 189 | ])# _LT_ENABLE_SHARED 190 | 191 | LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) 192 | LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) 193 | 194 | # Old names: 195 | AC_DEFUN([AC_ENABLE_SHARED], 196 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) 197 | ]) 198 | 199 | AC_DEFUN([AC_DISABLE_SHARED], 200 | [_LT_SET_OPTION([LT_INIT], [disable-shared]) 201 | ]) 202 | 203 | AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) 204 | AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) 205 | 206 | dnl aclocal-1.4 backwards compatibility: 207 | dnl AC_DEFUN([AM_ENABLE_SHARED], []) 208 | dnl AC_DEFUN([AM_DISABLE_SHARED], []) 209 | 210 | 211 | 212 | # _LT_ENABLE_STATIC([DEFAULT]) 213 | # ---------------------------- 214 | # implement the --enable-static flag, and support the `static' and 215 | # `disable-static' LT_INIT options. 216 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 217 | m4_define([_LT_ENABLE_STATIC], 218 | [m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl 219 | AC_ARG_ENABLE([static], 220 | [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], 221 | [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], 222 | [p=${PACKAGE-default} 223 | case $enableval in 224 | yes) enable_static=yes ;; 225 | no) enable_static=no ;; 226 | *) 227 | enable_static=no 228 | # Look at the argument we got. We use all the common list separators. 229 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 230 | for pkg in $enableval; do 231 | IFS="$lt_save_ifs" 232 | if test "X$pkg" = "X$p"; then 233 | enable_static=yes 234 | fi 235 | done 236 | IFS="$lt_save_ifs" 237 | ;; 238 | esac], 239 | [enable_static=]_LT_ENABLE_STATIC_DEFAULT) 240 | 241 | _LT_DECL([build_old_libs], [enable_static], [0], 242 | [Whether or not to build static libraries]) 243 | ])# _LT_ENABLE_STATIC 244 | 245 | LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) 246 | LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) 247 | 248 | # Old names: 249 | AC_DEFUN([AC_ENABLE_STATIC], 250 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) 251 | ]) 252 | 253 | AC_DEFUN([AC_DISABLE_STATIC], 254 | [_LT_SET_OPTION([LT_INIT], [disable-static]) 255 | ]) 256 | 257 | AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) 258 | AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) 259 | 260 | dnl aclocal-1.4 backwards compatibility: 261 | dnl AC_DEFUN([AM_ENABLE_STATIC], []) 262 | dnl AC_DEFUN([AM_DISABLE_STATIC], []) 263 | 264 | 265 | 266 | # _LT_ENABLE_FAST_INSTALL([DEFAULT]) 267 | # ---------------------------------- 268 | # implement the --enable-fast-install flag, and support the `fast-install' 269 | # and `disable-fast-install' LT_INIT options. 270 | # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. 271 | m4_define([_LT_ENABLE_FAST_INSTALL], 272 | [m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl 273 | AC_ARG_ENABLE([fast-install], 274 | [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], 275 | [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], 276 | [p=${PACKAGE-default} 277 | case $enableval in 278 | yes) enable_fast_install=yes ;; 279 | no) enable_fast_install=no ;; 280 | *) 281 | enable_fast_install=no 282 | # Look at the argument we got. We use all the common list separators. 283 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 284 | for pkg in $enableval; do 285 | IFS="$lt_save_ifs" 286 | if test "X$pkg" = "X$p"; then 287 | enable_fast_install=yes 288 | fi 289 | done 290 | IFS="$lt_save_ifs" 291 | ;; 292 | esac], 293 | [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) 294 | 295 | _LT_DECL([fast_install], [enable_fast_install], [0], 296 | [Whether or not to optimize for fast installation])dnl 297 | ])# _LT_ENABLE_FAST_INSTALL 298 | 299 | LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) 300 | LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) 301 | 302 | # Old names: 303 | AU_DEFUN([AC_ENABLE_FAST_INSTALL], 304 | [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) 305 | AC_DIAGNOSE([obsolete], 306 | [$0: Remove this warning and the call to _LT_SET_OPTION when you put 307 | the `fast-install' option into LT_INIT's first parameter.]) 308 | ]) 309 | 310 | AU_DEFUN([AC_DISABLE_FAST_INSTALL], 311 | [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) 312 | AC_DIAGNOSE([obsolete], 313 | [$0: Remove this warning and the call to _LT_SET_OPTION when you put 314 | the `disable-fast-install' option into LT_INIT's first parameter.]) 315 | ]) 316 | 317 | dnl aclocal-1.4 backwards compatibility: 318 | dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) 319 | dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) 320 | 321 | 322 | # _LT_WITH_PIC([MODE]) 323 | # -------------------- 324 | # implement the --with-pic flag, and support the `pic-only' and `no-pic' 325 | # LT_INIT options. 326 | # MODE is either `yes' or `no'. If omitted, it defaults to `both'. 327 | m4_define([_LT_WITH_PIC], 328 | [AC_ARG_WITH([pic], 329 | [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], 330 | [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], 331 | [lt_p=${PACKAGE-default} 332 | case $withval in 333 | yes|no) pic_mode=$withval ;; 334 | *) 335 | pic_mode=default 336 | # Look at the argument we got. We use all the common list separators. 337 | lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," 338 | for lt_pkg in $withval; do 339 | IFS="$lt_save_ifs" 340 | if test "X$lt_pkg" = "X$lt_p"; then 341 | pic_mode=yes 342 | fi 343 | done 344 | IFS="$lt_save_ifs" 345 | ;; 346 | esac], 347 | [pic_mode=default]) 348 | 349 | test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) 350 | 351 | _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl 352 | ])# _LT_WITH_PIC 353 | 354 | LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) 355 | LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) 356 | 357 | # Old name: 358 | AU_DEFUN([AC_LIBTOOL_PICMODE], 359 | [_LT_SET_OPTION([LT_INIT], [pic-only]) 360 | AC_DIAGNOSE([obsolete], 361 | [$0: Remove this warning and the call to _LT_SET_OPTION when you 362 | put the `pic-only' option into LT_INIT's first parameter.]) 363 | ]) 364 | 365 | dnl aclocal-1.4 backwards compatibility: 366 | dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) 367 | 368 | ## ----------------- ## 369 | ## LTDL_INIT Options ## 370 | ## ----------------- ## 371 | 372 | m4_define([_LTDL_MODE], []) 373 | LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], 374 | [m4_define([_LTDL_MODE], [nonrecursive])]) 375 | LT_OPTION_DEFINE([LTDL_INIT], [recursive], 376 | [m4_define([_LTDL_MODE], [recursive])]) 377 | LT_OPTION_DEFINE([LTDL_INIT], [subproject], 378 | [m4_define([_LTDL_MODE], [subproject])]) 379 | 380 | m4_define([_LTDL_TYPE], []) 381 | LT_OPTION_DEFINE([LTDL_INIT], [installable], 382 | [m4_define([_LTDL_TYPE], [installable])]) 383 | LT_OPTION_DEFINE([LTDL_INIT], [convenience], 384 | [m4_define([_LTDL_TYPE], [convenience])]) 385 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /pkg/deb/debian/changelog: -------------------------------------------------------------------------------- 1 | sipgrep (2.2.0~dev) UNRELEASED; urgency=medium 2 | 3 | * Devel version 4 | 5 | -- Victor Seva Fri, 18 Sep 2015 10:17:49 +0200 6 | 7 | sipgrep (2.1.0) unstable; urgency=medium 8 | 9 | * New release 10 | 11 | -- Victor Seva Fri, 18 Sep 2015 10:17:33 +0200 12 | 13 | sipgrep (2.0.0) unstable; urgency=low 14 | 15 | * Initial version 16 | 17 | -- Victor Seva Mon, 31 Mar 2014 08:34:33 +0200 18 | -------------------------------------------------------------------------------- /pkg/deb/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /pkg/deb/debian/control: -------------------------------------------------------------------------------- 1 | Source: sipgrep 2 | Section: net 3 | Priority: optional 4 | Maintainer: Debian VoIP Team 5 | Uploaders: Victor Seva 6 | Build-Depends: autotools-dev, 7 | debhelper (>= 9), 8 | dpkg-dev (>= 1.16.1~), 9 | libpcap-dev, 10 | libpcre2-dev, 11 | Standards-Version: 3.9.6 12 | Homepage: https://github.com/sipcapture/sipgrep 13 | Vcs-git: git://anonscm.debian.org/pkg-voip/sipgrep.git 14 | Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-voip/sipgrep.git 15 | 16 | Package: sipgrep 17 | Architecture: linux-any 18 | Multi-Arch: foreign 19 | Pre-Depends: ${misc:Pre-Depends} 20 | Depends: ${misc:Depends}, ${shlibs:Depends} 21 | Description: command line tool to sniff, capture, display SIP messages 22 | Powerful pcap-aware tool command line tool to sniff, capture, display 23 | and troubleshoot SIP signaling over IP networks, allowing the user to 24 | specify extended regular expressions matching against SIP headers. 25 | -------------------------------------------------------------------------------- /pkg/deb/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: sipgrep 3 | Upstream-Contact: Alexandr Dubovikov 4 | Source: https://github.com/sipcapture/sipgrep 5 | 6 | Files: * 7 | Copyright: 8 | Copyright (c) 2006 Jordan Ritter 9 | Copyright (c) 2007 Jan Andres 10 | Copyright (c) 2003-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ 11 | Copyright (c) 2014, 2015 Alexandr Dubovikov 12 | Copyright (c) 2014, 2015 Lorenzo Mangani 13 | License: GPL-3.0+ 14 | On Debian systems, the full text of the GNU General Public 15 | License version 3 can be found in the file `/usr/share/common-licenses/GPL-3'. 16 | 17 | Files: debian/* 18 | Copyright: 2014, 2015 Victor Seva 19 | License: GPL-3+ 20 | On Debian systems, the full text of the GNU General Public 21 | License version 3 can be found in the file `/usr/share/common-licenses/GPL-3'. 22 | -------------------------------------------------------------------------------- /pkg/deb/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | 4 | # Uncomment this to turn on verbose mode. 5 | #export DH_VERBOSE=1 6 | 7 | %: 8 | dh $@ --with autotools-dev 9 | 10 | override_dh_auto_configure: 11 | dh_auto_configure -- --enable-ipv6 12 | 13 | override_dh_auto_install: 14 | dh_auto_install --destdir=debian/sipgrep 15 | -------------------------------------------------------------------------------- /pkg/deb/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /pkg/deb/debian/watch: -------------------------------------------------------------------------------- 1 | version=3 2 | opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/sipgrep_$1\.tar\.gz/" \ 3 | https://github.com/sipcapture/sipgrep/tags .*/v?(\d\S*)\.tar\.gz 4 | -------------------------------------------------------------------------------- /sipgrep.8: -------------------------------------------------------------------------------- 1 | .\" $Id: sipgrep.8,v 2.00 2014/03/28 12:18:35 jpr5 Exp $ 2 | .\" 3 | .\" All content, except portions of the bpf filter explanation, are: 4 | .\" 5 | .\" Copyright (c) 2014 Alexandr Dubovikov 6 | .\" Copyright (c) 2014 Sipcapture.org 7 | .\" 8 | .\" Please refer to the COPYING file for more information. 9 | 10 | .TH SIPGREP 8 "March 2014" *nux "User Manuals" 11 | 12 | .SH NAME 13 | 14 | sipgrep \- sip packet grep 15 | 16 | .SH SYNOPSIS 17 | 18 | .B sipgrep <-ahNViwgGJpevxlDTRMmqCJj> <-IO 19 | .I pcap_dump 20 | .B > < -n 21 | .I num 22 | .B > < -d 23 | .I dev 24 | .B > < -A 25 | .I num 26 | .B > < -s 27 | .I snaplen 28 | .B > < -S 29 | .I limitlen 30 | .B > < -c 31 | .I contact user 32 | .B > < -j 33 | .I user agent 34 | .B > < -f 35 | .I from user 36 | .B > < -t 37 | .I to user 38 | .B > < -H 39 | .I capture URL 40 | .B > < -q 41 | .I seconds 42 | .B > < -P 43 | .I portrange 44 | .B > < -F 45 | .I file 46 | .B > < 47 | .I match expression 48 | .B > < 49 | .I bpf filter 50 | .B > 51 | 52 | .SH DESCRIPTION 53 | 54 | sipgrep strives to provide most of GNU grep's common features, applying 55 | them to the SIP signaling protocol. sipgrep is a pcap-aware tool that 56 | will allow you to specify extended regular expressions to match against data 57 | payloads of SIP packets with application specific filtering options. 58 | The tool understands filter logic common to other packet sniffing tools, 59 | such as 60 | .BR tcpdump (8) 61 | and 62 | .BR sipgrep (1). 63 | 64 | 65 | .SH OPTIONS 66 | .IP -h 67 | Display help/usage information. 68 | 69 | .IP -V 70 | Display version information. 71 | 72 | .IP -e 73 | Display empty packets. 74 | 75 | .IP -i 76 | Ignore case. 77 | 78 | .IP -v 79 | Invert match. 80 | 81 | .IP -R 82 | Do not try to drop privileges to the DROPPRIVS_USER. 83 | 84 | sipgrep makes no effort to validate input from live or offline sources 85 | as it is focused more on performance and handling large amounts of 86 | data than protocol correctness, which is most often a fair assumption 87 | to make. However, sometimes it matters and thus as a rule sipgrep will 88 | try to be defensive and drop any root privileges it might have. 89 | 90 | There exist scenarios where this behaviour can become an obstacle, so 91 | this option is provided to end-users who want to disable this feature, 92 | but must do so with an understanding of the risks. Packets can be 93 | randomly malformed or even specifically designed to overflow sniffers 94 | and take control of them, and revoking root privileges is currently 95 | the only risk mitigation sipgrep employs against such an attack. Use 96 | this option and turn it off at your own risk. 97 | 98 | .IP -w 99 | Match the regex expression as a word. 100 | 101 | .IP -p 102 | Don't put the interface into promiscuous mode. 103 | 104 | .IP -l 105 | Make stdout line buffered. 106 | 107 | .IP -D 108 | When reading pcap_dump files, replay them at their recorded time 109 | intervals (mimic realtime). 110 | 111 | .IP -T 112 | Print a timestamp in the form of +S.UUUUUU, indicating the delta 113 | between packet matches. 114 | 115 | .IP -m 116 | Disable SIP Dialog matching. 117 | 118 | .IP -M 119 | Disable multi-line match (prefers single-line match instead). 120 | 121 | .IP "-I pcap_dump" 122 | Input file pcap_dump into sipgrep. Works with any pcap-compatible dump 123 | file format. This option is useful for searching for a wide range of 124 | different patterns over the same packet stream. 125 | 126 | .IP "-O pcap_dump" 127 | Output matched packets to a pcap-compatible dump file. This feature 128 | does not interfere with normal output to stdout. 129 | 130 | .IP "-n num" 131 | Match only 132 | .I \fInum\fP 133 | packets total, then exit. 134 | 135 | .IP "-A num" 136 | Dump \fInum\fP packets of trailing context after matching a packet. 137 | 138 | .IP "-s snaplen" 139 | Set the bpf caplen to snaplen (default 65536). 140 | 141 | .IP "-S limitlen" 142 | Set the upper limit on the size of packets that sipgrep will look at. 143 | Useful for looking at only the first N bytes of packets without 144 | changing the BPF snaplen. 145 | 146 | .IP "-C" 147 | Do not use colors in stdout. 148 | 149 | .IP "-c" 150 | Match user in Contact: SIP header. 151 | 152 | .IP "-f" 153 | Match user in From: SIP header. 154 | 155 | .IP "-t" 156 | Match user in To: SIP header. 157 | 158 | .IP "-F file" 159 | Read in the bpf filter from the specified filename. This is a 160 | compatibility option for users familiar with tcpdump. Please note 161 | that specifying ``-F'' will override any bpf filter specified on the 162 | command-line. 163 | 164 | .IP "-H ip:port" 165 | Duplicate matching traffic to HEP Capture Server / HOMER. 166 | 167 | .IP -N 168 | Show sub-protocol number along with single-character identifier 169 | (useful when observing raw or unknown protocols). 170 | 171 | .IP -g 172 | Disable clean-up of Dialogs during trace. 173 | 174 | .IP -G 175 | Print Dialogs report during trace. 176 | 177 | .IP -J 178 | Automatically send SIP packet-of-death to SipVicious scanners (kill). 179 | 180 | .IP -j 181 | For matching user-agent strings send SIP packet-of-death to 182 | SipVicious scanners (kill). 183 | 184 | .IP -q 185 | Terminate sipgrep after a specified number of seconds. 186 | 187 | .IP -a 188 | Enable packet re-assemblation. 189 | 190 | .IP -P 191 | Specify SIP port range (default 5060-5061). 192 | 193 | .IP "-d dev" 194 | By default sipgrep will select a default interface to listen on. Use 195 | this option to force sipgrep to listen on interface \fIdev\fP. 196 | 197 | .SH DIAGNOSTICS 198 | 199 | Errors from 200 | .B sipgrep, libpcap, 201 | and the 202 | .B GNU regex library 203 | are all output to stderr. 204 | 205 | .SH AUTHOR 206 | 207 | Written by Alexandr Dubovikov . 208 | 209 | .SH REPORTING BUGS 210 | 211 | Please report bugs to the sipgrep Bug Tracker, located at 212 | 213 | https://github.com/sipcapture/sipgrep/issues 214 | 215 | Non-bug, non-feature-request general feedback should be sent to the 216 | author directly by email. 217 | 218 | .SH NOTES 219 | 220 | ALL YOUR BASE ARE BELONG TO HOMER. 221 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = sipgrep 2 | #AM_CFLAGS = -g -fPIC -rdynamic -I$(top_srcdir)/src/include ${EXTRA_DEFINES} 3 | #AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -I$(top_srcdir)/src/include 4 | #sipgrep_LDADD = $(LIBOBJS) 5 | sipgrep_SOURCES = sipgrep.c log.c ipreasm.c tcpreasm.c sipparse.c 6 | 7 | if HAVE_HEP 8 | sipgrep_SOURCES+=transport_hep.c 9 | endif 10 | 11 | if USE_NCURSES 12 | sipgrep_SOURCES+=user_interface.c 13 | endif 14 | 15 | -------------------------------------------------------------------------------- /src/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.11.6 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 5 | # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software 6 | # Foundation, Inc. 7 | # This Makefile.in is free software; the Free Software Foundation 8 | # gives unlimited permission to copy and/or distribute it, 9 | # with or without modifications, as long as this notice is preserved. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 13 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. 15 | 16 | @SET_MAKE@ 17 | 18 | VPATH = @srcdir@ 19 | am__make_dryrun = \ 20 | { \ 21 | am__dry=no; \ 22 | case $$MAKEFLAGS in \ 23 | *\\[\ \ ]*) \ 24 | echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ 25 | | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ 26 | *) \ 27 | for am__flg in $$MAKEFLAGS; do \ 28 | case $$am__flg in \ 29 | *=*|--*) ;; \ 30 | *n*) am__dry=yes; break;; \ 31 | esac; \ 32 | done;; \ 33 | esac; \ 34 | test $$am__dry = yes; \ 35 | } 36 | pkgdatadir = $(datadir)/@PACKAGE@ 37 | pkgincludedir = $(includedir)/@PACKAGE@ 38 | pkglibdir = $(libdir)/@PACKAGE@ 39 | pkglibexecdir = $(libexecdir)/@PACKAGE@ 40 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 41 | install_sh_DATA = $(install_sh) -c -m 644 42 | install_sh_PROGRAM = $(install_sh) -c 43 | install_sh_SCRIPT = $(install_sh) -c 44 | INSTALL_HEADER = $(INSTALL_DATA) 45 | transform = $(program_transform_name) 46 | NORMAL_INSTALL = : 47 | PRE_INSTALL = : 48 | POST_INSTALL = : 49 | NORMAL_UNINSTALL = : 50 | PRE_UNINSTALL = : 51 | POST_UNINSTALL = : 52 | build_triplet = @build@ 53 | host_triplet = @host@ 54 | bin_PROGRAMS = sipgrep$(EXEEXT) 55 | @HAVE_HEP_TRUE@am__append_1 = transport_hep.c 56 | @USE_NCURSES_TRUE@am__append_2 = user_interface.c 57 | subdir = src 58 | DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ 59 | $(srcdir)/config.h.in 60 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 61 | am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ 62 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ 63 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ 64 | $(top_srcdir)/configure.ac 65 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 66 | $(ACLOCAL_M4) 67 | mkinstalldirs = $(install_sh) -d 68 | CONFIG_HEADER = config.h 69 | CONFIG_CLEAN_FILES = 70 | CONFIG_CLEAN_VPATH_FILES = 71 | am__installdirs = "$(DESTDIR)$(bindir)" 72 | PROGRAMS = $(bin_PROGRAMS) 73 | am__sipgrep_SOURCES_DIST = sipgrep.c log.c ipreasm.c tcpreasm.c \ 74 | sipparse.c transport_hep.c user_interface.c 75 | @HAVE_HEP_TRUE@am__objects_1 = transport_hep.$(OBJEXT) 76 | @USE_NCURSES_TRUE@am__objects_2 = user_interface.$(OBJEXT) 77 | am_sipgrep_OBJECTS = sipgrep.$(OBJEXT) log.$(OBJEXT) ipreasm.$(OBJEXT) \ 78 | tcpreasm.$(OBJEXT) sipparse.$(OBJEXT) $(am__objects_1) \ 79 | $(am__objects_2) 80 | sipgrep_OBJECTS = $(am_sipgrep_OBJECTS) 81 | sipgrep_LDADD = $(LDADD) 82 | DEFAULT_INCLUDES = -I.@am__isrc@ 83 | depcomp = $(SHELL) $(top_srcdir)/depcomp 84 | am__depfiles_maybe = depfiles 85 | am__mv = mv -f 86 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ 87 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) 88 | LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ 89 | --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 90 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) 91 | CCLD = $(CC) 92 | LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ 93 | --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ 94 | $(LDFLAGS) -o $@ 95 | SOURCES = $(sipgrep_SOURCES) 96 | DIST_SOURCES = $(am__sipgrep_SOURCES_DIST) 97 | am__can_run_installinfo = \ 98 | case $$AM_UPDATE_INFO_DIR in \ 99 | n|no|NO) false;; \ 100 | *) (install-info --version) >/dev/null 2>&1;; \ 101 | esac 102 | ETAGS = etags 103 | CTAGS = ctags 104 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 105 | ACLOCAL = @ACLOCAL@ 106 | AMTAR = @AMTAR@ 107 | AR = @AR@ 108 | AUTOCONF = @AUTOCONF@ 109 | AUTOHEADER = @AUTOHEADER@ 110 | AUTOMAKE = @AUTOMAKE@ 111 | AWK = @AWK@ 112 | CC = @CC@ 113 | CCDEPMODE = @CCDEPMODE@ 114 | CFLAGS = @CFLAGS@ 115 | CPP = @CPP@ 116 | CPPFLAGS = @CPPFLAGS@ 117 | CYGPATH_W = @CYGPATH_W@ 118 | DEFS = @DEFS@ 119 | DEPDIR = @DEPDIR@ 120 | DLLTOOL = @DLLTOOL@ 121 | DL_LIBS = @DL_LIBS@ 122 | DSYMUTIL = @DSYMUTIL@ 123 | DUMPBIN = @DUMPBIN@ 124 | ECHO_C = @ECHO_C@ 125 | ECHO_N = @ECHO_N@ 126 | ECHO_T = @ECHO_T@ 127 | EGREP = @EGREP@ 128 | EXEEXT = @EXEEXT@ 129 | FGREP = @FGREP@ 130 | GREP = @GREP@ 131 | HAVE_HEP = @HAVE_HEP@ 132 | HIREDIS_LIBS = @HIREDIS_LIBS@ 133 | INSTALL = @INSTALL@ 134 | INSTALL_DATA = @INSTALL_DATA@ 135 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 136 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 137 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 138 | LD = @LD@ 139 | LDFLAGS = @LDFLAGS@ 140 | LIBOBJS = @LIBOBJS@ 141 | LIBS = @LIBS@ 142 | LIBTOOL = @LIBTOOL@ 143 | LIPO = @LIPO@ 144 | LN_S = @LN_S@ 145 | LTLIBOBJS = @LTLIBOBJS@ 146 | MAKEINFO = @MAKEINFO@ 147 | MANIFEST_TOOL = @MANIFEST_TOOL@ 148 | MKDIR_P = @MKDIR_P@ 149 | NCURSES = @NCURSES@ 150 | NCURSES_LIBS = @NCURSES_LIBS@ 151 | NM = @NM@ 152 | NMEDIT = @NMEDIT@ 153 | OBJDUMP = @OBJDUMP@ 154 | OBJEXT = @OBJEXT@ 155 | OS_DARWIN = @OS_DARWIN@ 156 | OS_FREEBSD = @OS_FREEBSD@ 157 | OS_LINUX = @OS_LINUX@ 158 | OS_NETBSD = @OS_NETBSD@ 159 | OS_SOLARIS = @OS_SOLARIS@ 160 | OTOOL = @OTOOL@ 161 | OTOOL64 = @OTOOL64@ 162 | OUR_MODS = @OUR_MODS@ 163 | PACKAGE = @PACKAGE@ 164 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 165 | PACKAGE_NAME = @PACKAGE_NAME@ 166 | PACKAGE_STRING = @PACKAGE_STRING@ 167 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 168 | PACKAGE_URL = @PACKAGE_URL@ 169 | PACKAGE_VERSION = @PACKAGE_VERSION@ 170 | PATH_SEPARATOR = @PATH_SEPARATOR@ 171 | PCAP_LIBS = @PCAP_LIBS@ 172 | PCRE = @PCRE@ 173 | PCRE_LIBS = @PCRE_LIBS@ 174 | PTHREAD_LIBS = @PTHREAD_LIBS@ 175 | RANLIB = @RANLIB@ 176 | REDIS = @REDIS@ 177 | SED = @SED@ 178 | SET_MAKE = @SET_MAKE@ 179 | SHELL = @SHELL@ 180 | SSL = @SSL@ 181 | STRIP = @STRIP@ 182 | USE_NCURSES = @USE_NCURSES@ 183 | VERSION = @VERSION@ 184 | ZLIB = @ZLIB@ 185 | abs_builddir = @abs_builddir@ 186 | abs_srcdir = @abs_srcdir@ 187 | abs_top_builddir = @abs_top_builddir@ 188 | abs_top_srcdir = @abs_top_srcdir@ 189 | ac_ct_AR = @ac_ct_AR@ 190 | ac_ct_CC = @ac_ct_CC@ 191 | ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ 192 | am__include = @am__include@ 193 | am__leading_dot = @am__leading_dot@ 194 | am__quote = @am__quote@ 195 | am__tar = @am__tar@ 196 | am__untar = @am__untar@ 197 | bindir = @bindir@ 198 | build = @build@ 199 | build_alias = @build_alias@ 200 | build_cpu = @build_cpu@ 201 | build_os = @build_os@ 202 | build_vendor = @build_vendor@ 203 | builddir = @builddir@ 204 | datadir = @datadir@ 205 | datarootdir = @datarootdir@ 206 | docdir = @docdir@ 207 | dvidir = @dvidir@ 208 | exec_prefix = @exec_prefix@ 209 | host = @host@ 210 | host_alias = @host_alias@ 211 | host_cpu = @host_cpu@ 212 | host_os = @host_os@ 213 | host_vendor = @host_vendor@ 214 | htmldir = @htmldir@ 215 | includedir = @includedir@ 216 | infodir = @infodir@ 217 | install_sh = @install_sh@ 218 | libdir = @libdir@ 219 | libexecdir = @libexecdir@ 220 | localedir = @localedir@ 221 | localstatedir = @localstatedir@ 222 | mandir = @mandir@ 223 | mkdir_p = @mkdir_p@ 224 | oldincludedir = @oldincludedir@ 225 | pdfdir = @pdfdir@ 226 | prefix = @prefix@ 227 | program_transform_name = @program_transform_name@ 228 | psdir = @psdir@ 229 | sbindir = @sbindir@ 230 | sharedstatedir = @sharedstatedir@ 231 | srcdir = @srcdir@ 232 | sysconfdir = @sysconfdir@ 233 | target_alias = @target_alias@ 234 | top_build_prefix = @top_build_prefix@ 235 | top_builddir = @top_builddir@ 236 | top_srcdir = @top_srcdir@ 237 | #AM_CFLAGS = -g -fPIC -rdynamic -I$(top_srcdir)/src/include ${EXTRA_DEFINES} 238 | #AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -I$(top_srcdir)/src/include 239 | #sipgrep_LDADD = $(LIBOBJS) 240 | sipgrep_SOURCES = sipgrep.c log.c ipreasm.c tcpreasm.c sipparse.c \ 241 | $(am__append_1) $(am__append_2) 242 | all: config.h 243 | $(MAKE) $(AM_MAKEFLAGS) all-am 244 | 245 | .SUFFIXES: 246 | .SUFFIXES: .c .lo .o .obj 247 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 248 | @for dep in $?; do \ 249 | case '$(am__configure_deps)' in \ 250 | *$$dep*) \ 251 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ 252 | && { if test -f $@; then exit 0; else break; fi; }; \ 253 | exit 1;; \ 254 | esac; \ 255 | done; \ 256 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \ 257 | $(am__cd) $(top_srcdir) && \ 258 | $(AUTOMAKE) --foreign src/Makefile 259 | .PRECIOUS: Makefile 260 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 261 | @case '$?' in \ 262 | *config.status*) \ 263 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ 264 | *) \ 265 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ 266 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 267 | esac; 268 | 269 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 270 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 271 | 272 | $(top_srcdir)/configure: $(am__configure_deps) 273 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 274 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 275 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 276 | $(am__aclocal_m4_deps): 277 | 278 | config.h: stamp-h1 279 | @if test ! -f $@; then rm -f stamp-h1; else :; fi 280 | @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi 281 | 282 | stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status 283 | @rm -f stamp-h1 284 | cd $(top_builddir) && $(SHELL) ./config.status src/config.h 285 | $(srcdir)/config.h.in: $(am__configure_deps) 286 | ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) 287 | rm -f stamp-h1 288 | touch $@ 289 | 290 | distclean-hdr: 291 | -rm -f config.h stamp-h1 292 | install-binPROGRAMS: $(bin_PROGRAMS) 293 | @$(NORMAL_INSTALL) 294 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ 295 | if test -n "$$list"; then \ 296 | echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ 297 | $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ 298 | fi; \ 299 | for p in $$list; do echo "$$p $$p"; done | \ 300 | sed 's/$(EXEEXT)$$//' | \ 301 | while read p p1; do if test -f $$p || test -f $$p1; \ 302 | then echo "$$p"; echo "$$p"; else :; fi; \ 303 | done | \ 304 | sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ 305 | -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ 306 | sed 'N;N;N;s,\n, ,g' | \ 307 | $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ 308 | { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ 309 | if ($$2 == $$4) files[d] = files[d] " " $$1; \ 310 | else { print "f", $$3 "/" $$4, $$1; } } \ 311 | END { for (d in files) print "f", d, files[d] }' | \ 312 | while read type dir files; do \ 313 | if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ 314 | test -z "$$files" || { \ 315 | echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ 316 | $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ 317 | } \ 318 | ; done 319 | 320 | uninstall-binPROGRAMS: 321 | @$(NORMAL_UNINSTALL) 322 | @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ 323 | files=`for p in $$list; do echo "$$p"; done | \ 324 | sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ 325 | -e 's/$$/$(EXEEXT)/' `; \ 326 | test -n "$$list" || exit 0; \ 327 | echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ 328 | cd "$(DESTDIR)$(bindir)" && rm -f $$files 329 | 330 | clean-binPROGRAMS: 331 | @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ 332 | echo " rm -f" $$list; \ 333 | rm -f $$list || exit $$?; \ 334 | test -n "$(EXEEXT)" || exit 0; \ 335 | list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ 336 | echo " rm -f" $$list; \ 337 | rm -f $$list 338 | sipgrep$(EXEEXT): $(sipgrep_OBJECTS) $(sipgrep_DEPENDENCIES) $(EXTRA_sipgrep_DEPENDENCIES) 339 | @rm -f sipgrep$(EXEEXT) 340 | $(LINK) $(sipgrep_OBJECTS) $(sipgrep_LDADD) $(LIBS) 341 | 342 | mostlyclean-compile: 343 | -rm -f *.$(OBJEXT) 344 | 345 | distclean-compile: 346 | -rm -f *.tab.c 347 | 348 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipreasm.Po@am__quote@ 349 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@ 350 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sipgrep.Po@am__quote@ 351 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sipparse.Po@am__quote@ 352 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcpreasm.Po@am__quote@ 353 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transport_hep.Po@am__quote@ 354 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/user_interface.Po@am__quote@ 355 | 356 | .c.o: 357 | @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 358 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 359 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 360 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 361 | @am__fastdepCC_FALSE@ $(COMPILE) -c $< 362 | 363 | .c.obj: 364 | @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` 365 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po 366 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ 367 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 368 | @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` 369 | 370 | .c.lo: 371 | @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< 372 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo 373 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ 374 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 375 | @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< 376 | 377 | mostlyclean-libtool: 378 | -rm -f *.lo 379 | 380 | clean-libtool: 381 | -rm -rf .libs _libs 382 | 383 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) 384 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ 385 | unique=`for i in $$list; do \ 386 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 387 | done | \ 388 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 389 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 390 | mkid -fID $$unique 391 | tags: TAGS 392 | 393 | TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ 394 | $(TAGS_FILES) $(LISP) 395 | set x; \ 396 | here=`pwd`; \ 397 | list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ 398 | unique=`for i in $$list; do \ 399 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 400 | done | \ 401 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 402 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 403 | shift; \ 404 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ 405 | test -n "$$unique" || unique=$$empty_fix; \ 406 | if test $$# -gt 0; then \ 407 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 408 | "$$@" $$unique; \ 409 | else \ 410 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 411 | $$unique; \ 412 | fi; \ 413 | fi 414 | ctags: CTAGS 415 | CTAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ 416 | $(TAGS_FILES) $(LISP) 417 | list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ 418 | unique=`for i in $$list; do \ 419 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 420 | done | \ 421 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ 422 | END { if (nonempty) { for (i in files) print i; }; }'`; \ 423 | test -z "$(CTAGS_ARGS)$$unique" \ 424 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 425 | $$unique 426 | 427 | GTAGS: 428 | here=`$(am__cd) $(top_builddir) && pwd` \ 429 | && $(am__cd) $(top_srcdir) \ 430 | && gtags -i $(GTAGS_ARGS) "$$here" 431 | 432 | distclean-tags: 433 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 434 | 435 | distdir: $(DISTFILES) 436 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 437 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 438 | list='$(DISTFILES)'; \ 439 | dist_files=`for file in $$list; do echo $$file; done | \ 440 | sed -e "s|^$$srcdirstrip/||;t" \ 441 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 442 | case $$dist_files in \ 443 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 444 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 445 | sort -u` ;; \ 446 | esac; \ 447 | for file in $$dist_files; do \ 448 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 449 | if test -d $$d/$$file; then \ 450 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 451 | if test -d "$(distdir)/$$file"; then \ 452 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 453 | fi; \ 454 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 455 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ 456 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 457 | fi; \ 458 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ 459 | else \ 460 | test -f "$(distdir)/$$file" \ 461 | || cp -p $$d/$$file "$(distdir)/$$file" \ 462 | || exit 1; \ 463 | fi; \ 464 | done 465 | check-am: all-am 466 | check: check-am 467 | all-am: Makefile $(PROGRAMS) config.h 468 | installdirs: 469 | for dir in "$(DESTDIR)$(bindir)"; do \ 470 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ 471 | done 472 | install: install-am 473 | install-exec: install-exec-am 474 | install-data: install-data-am 475 | uninstall: uninstall-am 476 | 477 | install-am: all-am 478 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 479 | 480 | installcheck: installcheck-am 481 | install-strip: 482 | if test -z '$(STRIP)'; then \ 483 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 484 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 485 | install; \ 486 | else \ 487 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 488 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 489 | "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ 490 | fi 491 | mostlyclean-generic: 492 | 493 | clean-generic: 494 | 495 | distclean-generic: 496 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 497 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 498 | 499 | maintainer-clean-generic: 500 | @echo "This command is intended for maintainers to use" 501 | @echo "it deletes files that may require special tools to rebuild." 502 | clean: clean-am 503 | 504 | clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am 505 | 506 | distclean: distclean-am 507 | -rm -rf ./$(DEPDIR) 508 | -rm -f Makefile 509 | distclean-am: clean-am distclean-compile distclean-generic \ 510 | distclean-hdr distclean-tags 511 | 512 | dvi: dvi-am 513 | 514 | dvi-am: 515 | 516 | html: html-am 517 | 518 | html-am: 519 | 520 | info: info-am 521 | 522 | info-am: 523 | 524 | install-data-am: 525 | 526 | install-dvi: install-dvi-am 527 | 528 | install-dvi-am: 529 | 530 | install-exec-am: install-binPROGRAMS 531 | 532 | install-html: install-html-am 533 | 534 | install-html-am: 535 | 536 | install-info: install-info-am 537 | 538 | install-info-am: 539 | 540 | install-man: 541 | 542 | install-pdf: install-pdf-am 543 | 544 | install-pdf-am: 545 | 546 | install-ps: install-ps-am 547 | 548 | install-ps-am: 549 | 550 | installcheck-am: 551 | 552 | maintainer-clean: maintainer-clean-am 553 | -rm -rf ./$(DEPDIR) 554 | -rm -f Makefile 555 | maintainer-clean-am: distclean-am maintainer-clean-generic 556 | 557 | mostlyclean: mostlyclean-am 558 | 559 | mostlyclean-am: mostlyclean-compile mostlyclean-generic \ 560 | mostlyclean-libtool 561 | 562 | pdf: pdf-am 563 | 564 | pdf-am: 565 | 566 | ps: ps-am 567 | 568 | ps-am: 569 | 570 | uninstall-am: uninstall-binPROGRAMS 571 | 572 | .MAKE: all install-am install-strip 573 | 574 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ 575 | clean-generic clean-libtool ctags distclean distclean-compile \ 576 | distclean-generic distclean-hdr distclean-libtool \ 577 | distclean-tags distdir dvi dvi-am html html-am info info-am \ 578 | install install-am install-binPROGRAMS install-data \ 579 | install-data-am install-dvi install-dvi-am install-exec \ 580 | install-exec-am install-html install-html-am install-info \ 581 | install-info-am install-man install-pdf install-pdf-am \ 582 | install-ps install-ps-am install-strip installcheck \ 583 | installcheck-am installdirs maintainer-clean \ 584 | maintainer-clean-generic mostlyclean mostlyclean-compile \ 585 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ 586 | tags uninstall uninstall-am uninstall-binPROGRAMS 587 | 588 | 589 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 590 | # Otherwise a system limit (for SysV at least) may be exceeded. 591 | .NOEXPORT: 592 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | /* src/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_DLFCN_H 5 | 6 | /* Define to 1 if you have the `fork' function. */ 7 | #undef HAVE_FORK 8 | 9 | /* Define to 1 if you have the `gettimeofday' function. */ 10 | #undef HAVE_GETTIMEOFDAY 11 | 12 | /* no HEP support */ 13 | #undef HAVE_HEP 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_INTTYPES_H 17 | 18 | /* Define to 1 if you have the `dl' library (-ldl). */ 19 | #undef HAVE_LIBDL 20 | 21 | /* Define to 1 if you have the `hiredis' library (-lhiredis). */ 22 | #undef HAVE_LIBHIREDIS 23 | 24 | /* Define to 1 if you have the `ncurses' library (-lncurses). */ 25 | #undef HAVE_LIBNCURSES 26 | 27 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 28 | #undef HAVE_LIBNSL 29 | 30 | /* Define to 1 if you have the `pcap' library (-lpcap). */ 31 | #undef HAVE_LIBPCAP 32 | 33 | /* Define to 1 if you have the `pcre' library (-lpcre). */ 34 | #undef HAVE_LIBPCRE 35 | 36 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 37 | #undef HAVE_LIBPTHREAD 38 | 39 | /* Define to 1 if you have the `socket' library (-lsocket). */ 40 | #undef HAVE_LIBSOCKET 41 | 42 | /* Define to 1 if you have the `ssl' library (-lssl). */ 43 | #undef HAVE_LIBSSL 44 | 45 | /* Define to 1 if you have the `wpcap' library (-lwpcap). */ 46 | #undef HAVE_LIBWPCAP 47 | 48 | /* Define to 1 if you have the `z' library (-lz). */ 49 | #undef HAVE_LIBZ 50 | 51 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 52 | to 0 otherwise. */ 53 | #undef HAVE_MALLOC 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_MEMORY_H 57 | 58 | /* Define to 1 if you have the `memset' function. */ 59 | #undef HAVE_MEMSET 60 | 61 | /* Define to 1 if you have the `select' function. */ 62 | #undef HAVE_SELECT 63 | 64 | /* Define to 1 if you have the `socket' function. */ 65 | #undef HAVE_SOCKET 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #undef HAVE_STDINT_H 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #undef HAVE_STDLIB_H 72 | 73 | /* Define to 1 if you have the `strdup' function. */ 74 | #undef HAVE_STRDUP 75 | 76 | /* Define to 1 if you have the `strerror' function. */ 77 | #undef HAVE_STRERROR 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #undef HAVE_STRINGS_H 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #undef HAVE_STRING_H 84 | 85 | /* Define to 1 if you have the `strndup' function. */ 86 | #undef HAVE_STRNDUP 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #undef HAVE_SYS_STAT_H 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #undef HAVE_SYS_TYPES_H 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #undef HAVE_UNISTD_H 96 | 97 | /* Define to 1 if you have the `vfork' function. */ 98 | #undef HAVE_VFORK 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #undef HAVE_VFORK_H 102 | 103 | /* Define to 1 if `fork' works. */ 104 | #undef HAVE_WORKING_FORK 105 | 106 | /* Define to 1 if `vfork' works. */ 107 | #undef HAVE_WORKING_VFORK 108 | 109 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 110 | */ 111 | #undef LT_OBJDIR 112 | 113 | /* Define to 1 if Operating System is Darwin */ 114 | #undef OS_DARWIN 115 | 116 | /* Define to 1 if Operating System is FreeBSD */ 117 | #undef OS_FREEBSD 118 | 119 | /* Define to 1 if Operating System is Linux */ 120 | #undef OS_LINUX 121 | 122 | /* Define to 1 if Operating System is NETBSD */ 123 | #undef OS_NETBSD 124 | 125 | /* Define to 1 if Operating System is SOLARIS */ 126 | #undef OS_SOLARIS 127 | 128 | /* Name of package */ 129 | #undef PACKAGE 130 | 131 | /* Define to the address where bug reports for this package should be sent. */ 132 | #undef PACKAGE_BUGREPORT 133 | 134 | /* Define to the full name of this package. */ 135 | #undef PACKAGE_NAME 136 | 137 | /* Define to the full name and version of this package. */ 138 | #undef PACKAGE_STRING 139 | 140 | /* Define to the one symbol short name of this package. */ 141 | #undef PACKAGE_TARNAME 142 | 143 | /* Define to the home page for this package. */ 144 | #undef PACKAGE_URL 145 | 146 | /* Define to the version of this package. */ 147 | #undef PACKAGE_VERSION 148 | 149 | /* Define to 1 if you have the ANSI C header files. */ 150 | #undef STDC_HEADERS 151 | 152 | /* Use NCURSES library */ 153 | #undef USE_NCURSES 154 | 155 | /* Use PCRE2 library */ 156 | #undef USE_PCRE2 157 | 158 | /* Use REDIS library */ 159 | #undef USE_REDIS 160 | 161 | /* Use OpenSSL SSL library */ 162 | #undef USE_SSL 163 | 164 | /* Use ZIP library */ 165 | #undef USE_ZLIB 166 | 167 | /* Version number of package */ 168 | #undef VERSION 169 | 170 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 171 | , or is not used. If the typedef were allowed, the 172 | #define below would cause a syntax error. */ 173 | #undef _UINT32_T 174 | 175 | /* Define for Solaris 2.5.1 so the uint8_t typedef from , 176 | , or is not used. If the typedef were allowed, the 177 | #define below would cause a syntax error. */ 178 | #undef _UINT8_T 179 | 180 | /* Define to the type of a signed integer type of width exactly 32 bits if 181 | such a type exists and the standard includes do not define it. */ 182 | #undef int32_t 183 | 184 | /* Define to the type of a signed integer type of width exactly 8 bits if such 185 | a type exists and the standard includes do not define it. */ 186 | #undef int8_t 187 | 188 | /* Define to rpl_malloc if the replacement function should be used. */ 189 | #undef malloc 190 | 191 | /* Define to `int' if does not define. */ 192 | #undef pid_t 193 | 194 | /* Define to the type of an unsigned integer type of width exactly 16 bits if 195 | such a type exists and the standard includes do not define it. */ 196 | #undef uint16_t 197 | 198 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 199 | such a type exists and the standard includes do not define it. */ 200 | #undef uint32_t 201 | 202 | /* Define to the type of an unsigned integer type of width exactly 8 bits if 203 | such a type exists and the standard includes do not define it. */ 204 | #undef uint8_t 205 | 206 | /* Define as `fork' if `vfork' does not work. */ 207 | #undef vfork 208 | -------------------------------------------------------------------------------- /src/include/core_hep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * sipgrep - Monitoring tools 5 | * 6 | * Author: Alexandr Dubovikov 7 | * (C) Homer Project 2014 (http://www.sipcapture.org) 8 | * 9 | * Sipgrep is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 3 of the License, or 12 | * (at your option) any later version 13 | * 14 | * Sipgrep is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | * 23 | */ 24 | 25 | 26 | #ifndef _core_hep_H_ 27 | #define _core_hep_H_ 28 | 29 | #ifdef USE_IPV6 30 | #include 31 | #endif /* USE_IPV6 */ 32 | 33 | /* HEPv3 types */ 34 | 35 | struct hep_chunk { 36 | uint16_t vendor_id; 37 | uint16_t type_id; 38 | uint16_t length; 39 | } __attribute__((packed)); 40 | 41 | typedef struct hep_chunk hep_chunk_t; 42 | 43 | struct hep_chunk_uint8 { 44 | hep_chunk_t chunk; 45 | uint8_t data; 46 | } __attribute__((packed)); 47 | 48 | typedef struct hep_chunk_uint8 hep_chunk_uint8_t; 49 | 50 | struct hep_chunk_uint16 { 51 | hep_chunk_t chunk; 52 | uint16_t data; 53 | } __attribute__((packed)); 54 | 55 | typedef struct hep_chunk_uint16 hep_chunk_uint16_t; 56 | 57 | struct hep_chunk_uint32 { 58 | hep_chunk_t chunk; 59 | uint32_t data; 60 | } __attribute__((packed)); 61 | 62 | typedef struct hep_chunk_uint32 hep_chunk_uint32_t; 63 | 64 | struct hep_chunk_str { 65 | hep_chunk_t chunk; 66 | char *data; 67 | } __attribute__((packed)); 68 | 69 | typedef struct hep_chunk_str hep_chunk_str_t; 70 | 71 | struct hep_chunk_ip4 { 72 | hep_chunk_t chunk; 73 | struct in_addr data; 74 | } __attribute__((packed)); 75 | 76 | typedef struct hep_chunk_ip4 hep_chunk_ip4_t; 77 | 78 | struct hep_chunk_ip6 { 79 | hep_chunk_t chunk; 80 | struct in6_addr data; 81 | } __attribute__((packed)); 82 | 83 | typedef struct hep_chunk_ip6 hep_chunk_ip6_t; 84 | 85 | struct hep_ctrl { 86 | char id[4]; 87 | uint16_t length; 88 | } __attribute__((packed)); 89 | 90 | typedef struct hep_ctrl hep_ctrl_t; 91 | 92 | struct hep_chunk_payload { 93 | hep_chunk_t chunk; 94 | char *data; 95 | } __attribute__((packed)); 96 | 97 | typedef struct hep_chunk_payload hep_chunk_payload_t; 98 | 99 | /* Structure of HEP */ 100 | 101 | struct hep_generic { 102 | hep_ctrl_t header; 103 | hep_chunk_uint8_t ip_family; 104 | hep_chunk_uint8_t ip_proto; 105 | hep_chunk_uint16_t src_port; 106 | hep_chunk_uint16_t dst_port; 107 | hep_chunk_uint32_t time_sec; 108 | hep_chunk_uint32_t time_usec; 109 | hep_chunk_uint8_t proto_t; 110 | hep_chunk_uint32_t capt_id; 111 | } __attribute__((packed)); 112 | 113 | typedef struct hep_generic hep_generic_t; 114 | 115 | struct hep_hdr{ 116 | uint8_t hp_v; /* version */ 117 | uint8_t hp_l; /* length */ 118 | uint8_t hp_f; /* family */ 119 | uint8_t hp_p; /* protocol */ 120 | uint16_t hp_sport; /* source port */ 121 | uint16_t hp_dport; /* destination port */ 122 | }; 123 | 124 | struct hep_timehdr{ 125 | uint32_t tv_sec; /* seconds */ 126 | uint32_t tv_usec; /* useconds */ 127 | uint16_t captid; /* Capture ID node */ 128 | }; 129 | 130 | struct hep_iphdr{ 131 | struct in_addr hp_src; 132 | struct in_addr hp_dst; /* source and dest address */ 133 | }; 134 | 135 | #ifdef USE_IPV6 136 | struct hep_ip6hdr { 137 | struct in6_addr hp6_src; /* source address */ 138 | struct in6_addr hp6_dst; /* destination address */ 139 | }; 140 | #endif 141 | 142 | #endif /* _core_hep_H_ */ 143 | 144 | -------------------------------------------------------------------------------- /src/include/ipreasm.h: -------------------------------------------------------------------------------- 1 | #ifndef _IPREASM_H 2 | #define _IPREASM_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | 9 | /* 10 | * This is an abstract time stamp. ipreasm doesn't care whether it is 11 | * in seconds, milliseconds, or nanodecades. All it does it add the 12 | * configured timeout value to it, and then compare it to the timstamps 13 | * of subsequent packets to decide whether a fragment has expired. 14 | */ 15 | typedef uint64_t reasm_time_t; 16 | 17 | struct reasm_ip; 18 | 19 | /* 20 | * Functions to create and destroy the reassembly environment. 21 | */ 22 | struct reasm_ip *reasm_ip_new (void); 23 | void reasm_ip_free (struct reasm_ip *reasm); 24 | 25 | /* 26 | * This is the main packet processing function. It inputs one packet, 27 | * and MAY output one packet in turn. If the input was not a fragment, 28 | * it is passed unmodified. If the input was a fragment that completed 29 | * reassembly of a packet, the reassembled packet is output. 30 | * If more fragments are required for reassembly, or the input packet 31 | * is invalid for some reason, a NULL pointer is returned. 32 | * 33 | * The input must be a pointer allocated by malloc(). The output will 34 | * be a pointer allocated by malloc(). 35 | * 36 | * Note that in the case of an IPv6 fragment, the input buffer will be 37 | * modified in-place. This is considered a bug and should be fixed in 38 | * the future. 39 | */ 40 | unsigned char *reasm_ip_next (struct reasm_ip *reasm, unsigned char *packet, unsigned len, reasm_time_t timestamp, unsigned *output_len); 41 | 42 | /* 43 | * Set the timeout after which a noncompleted reassembly expires, in 44 | * abstract time units (see above for the definition of reasm_time_t). 45 | */ 46 | bool reasm_ip_set_timeout (struct reasm_ip *reasm, reasm_time_t timeout); 47 | 48 | /* 49 | * Query certain information about the current state. 50 | */ 51 | unsigned reasm_ip_waiting (const struct reasm_ip *reasm); 52 | unsigned reasm_ip_max_waiting (const struct reasm_ip *reasm); 53 | unsigned reasm_ip_timed_out (const struct reasm_ip *reasm); 54 | unsigned reasm_ip_dropped_frags (const struct reasm_ip *reasm); 55 | 56 | 57 | #endif /* _IPREASM_H */ 58 | -------------------------------------------------------------------------------- /src/include/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * sipgrep - Monitoring tools 4 | * 5 | * Author: Alexandr Dubovikov 6 | * (C) Homer Project 2014-16 (http://www.sipcapture.org) 7 | * 8 | * sipgrep is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 3 of the License, or 11 | * (at your option) any later version 12 | * 13 | * Homer capture agent is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | * 22 | */ 23 | 24 | #ifndef LOG_H_ 25 | #define LOG_H_ 26 | 27 | #include 28 | 29 | void init_log(char *_prgname, int _use_syslog); 30 | 31 | void set_log_level(int level); 32 | 33 | void destroy_log(void); 34 | 35 | void data_log(int priority, const char * fmt, ...); 36 | 37 | #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b))); 38 | 39 | #define LEMERG(fmt, args...) data_log(LOG_EMERG, "[DEBUG] %s:%d " fmt, __FILE__, __LINE__, ## args) 40 | #define LALERT(fmt, args...) data_log(LOG_ALERT, "[ALERT] %s:%d " fmt, __FILE__, __LINE__, ## args) 41 | #define LCRIT(fmt, args...) data_log(LOG_CRIT, "[CRIT] %s:%d " fmt, __FILE__, __LINE__, ## args) 42 | #define LERR(fmt, args...) data_log(LOG_ERR, "[ERR] %s:%d " fmt, __FILE__, __LINE__, ## args) 43 | #define LWARNING(fmt, args...) data_log(LOG_WARNING, "[WARNING] %s:%d " fmt, __FILE__, __LINE__, ## args) 44 | #define LNOTICE(fmt, args...) data_log(LOG_NOTICE, "[NOTICE] " fmt, ## args) 45 | #define LINFO(fmt, args...) data_log(LOG_INFO, "[INFO] %s:%d " fmt, __FILE__, __LINE__, ## args) 46 | #define LDEBUG(fmt, args...) data_log(LOG_DEBUG, "[DEBUG] %s:%d " fmt, __FILE__, __LINE__, ## args) 47 | 48 | #endif /* LOG_H_ */ 49 | -------------------------------------------------------------------------------- /src/include/sipgrep.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIPGREP_H 2 | #define _SIPGREP_H 3 | 4 | /* 5 | * sipgrep.h, v 2.0 2014/03/18 6 | * 7 | * Copyright (c) 2013-14 Alexandr Dubovikov 8 | * 9 | */ 10 | 11 | /* 12 | * We cache the standard frame sizes here to save us time and 13 | * additional dependencies on more operating system include files. 14 | */ 15 | 16 | #define ETHHDR_SIZE 14 17 | #define TOKENRING_SIZE 22 18 | #define PPPHDR_SIZE 4 19 | #define SLIPHDR_SIZE 16 20 | #define RAWHDR_SIZE 0 21 | #define LOOPHDR_SIZE 4 22 | #define FDDIHDR_SIZE 21 23 | #define ISDNHDR_SIZE 16 24 | #define IEEE80211HDR_SIZE 32 25 | 26 | /* 27 | * Default patterns for BPF and regular expression filters. 28 | */ 29 | 30 | #if USE_IPv6 31 | #define BPF_FILTER_IP "(ip or ip6)" 32 | #else 33 | #define BPF_FILTER_IP "(ip)" 34 | #endif 35 | 36 | #define BPF_FILTER_OTHER " and ( %s)" 37 | #define BPF_MAIN_FILTER BPF_FILTER_IP BPF_FILTER_OTHER 38 | 39 | #define BPF_FILTER_PORTRANGE " and ( portrange %s)" 40 | #define BPF_MAIN_PORTRANGE_FILTER BPF_FILTER_IP BPF_FILTER_PORTRANGE 41 | 42 | #define BPF_DEFRAGMENTION_FILTER BPF_MAIN_PORTRANGE_FILTER " or (udp and ip[6:2] & 0x3fff != 0)" 43 | 44 | #define WORD_REGEX "((^%s\\W)|(\\W%s$)|(\\W%s\\W))" 45 | 46 | /* 47 | * For retarded operating systems like Solaris that don't have this, 48 | * when everyone else does. Good job, Sun! 49 | */ 50 | 51 | #ifndef IP_OFFMASK 52 | #define IP_OFFMASK 0x1fff 53 | #endif 54 | 55 | /* 56 | * "Newer" flags that older operating systems don't yet recognize. 57 | */ 58 | 59 | #ifndef TH_ECE 60 | #define TH_ECE 0x40 61 | #endif 62 | 63 | #ifndef TH_CWR 64 | #define TH_CWR 0x80 65 | #endif 66 | 67 | #define SIP_FROM_MATCH "(From:|f:) (.*)%s(.*)" 68 | #define SIP_TO_MATCH "(To:|t:) (.*)%s(.*)" 69 | #define SIP_CONTACT_MATCH "(Contact:|c:) (.*)%s(.*)" 70 | #define SIP_REPLY_MATCH "^SIP/2.0 %s" 71 | #define SIP_FROM_TO_MATCH "(" SIP_FROM_MATCH "|" SIP_TO_MATCH ")" 72 | 73 | /* colors */ 74 | #define RESET "\033[0m" 75 | #define BLACK "\033[30m" /* Black */ 76 | #define RED "\033[31m" /* Red */ 77 | #define GREEN "\033[32m" /* Green */ 78 | #define YELLOW "\033[33m" /* Yellow */ 79 | #define BLUE "\033[34m" /* Blue */ 80 | #define MAGENTA "\033[35m" /* Magenta */ 81 | #define CYAN "\033[36m" /* Cyan */ 82 | #define WHITE "\033[37m" /* White */ 83 | #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ 84 | #define BOLDRED "\033[1m\033[31m" /* Bold Red */ 85 | #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ 86 | #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ 87 | #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ 88 | #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ 89 | #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ 90 | #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ 91 | 92 | #define DURATION_SPLIT 1 93 | #define FILESIZE_SPLIT 2 94 | 95 | /* 96 | * Single-char packet "ident" flags. 97 | */ 98 | 99 | typedef enum { 100 | TCP = 'T', UDP = 'U', ICMP = 'I', ICMPv6 = 'I', IGMP = 'G', UNKNOWN = '?' 101 | } netident_t; 102 | 103 | /* 104 | * Prototypes function signatures. 105 | */ 106 | 107 | void process(u_char *, struct pcap_pkthdr *, u_char *); 108 | 109 | void version(void); 110 | void usage(int8_t); 111 | void clean_exit(int32_t); 112 | 113 | void dump_packet(struct pcap_pkthdr *, u_char *, uint8_t, unsigned char *, uint32_t, 114 | const char *, const char *, uint16_t, uint16_t, uint8_t, 115 | uint16_t, uint8_t, uint16_t, uint32_t, uint32_t); 116 | 117 | void dump_unwrapped(unsigned char *, uint32_t); 118 | void dump_formatted(unsigned char *, uint32_t); 119 | void dump_byline (unsigned char *, uint32_t); 120 | 121 | void dump_delay_proc_init(struct pcap_pkthdr *); 122 | void dump_delay_proc (struct pcap_pkthdr *); 123 | 124 | int8_t re_match_func (unsigned char *, uint32_t); 125 | int8_t bin_match_func (unsigned char *, uint32_t); 126 | int8_t blank_match_func(unsigned char *, uint32_t); 127 | 128 | void print_time_absolute(struct pcap_pkthdr *); 129 | void print_time_diff (struct pcap_pkthdr *); 130 | 131 | char *get_filter_from_string(char *); 132 | char *get_filter_from_argv (char **); 133 | char *get_filter_from_portrange(char *); 134 | 135 | void create_dump(unsigned int now); 136 | 137 | /* Call ID extract */ 138 | int extract_callid(char *msg, int len); 139 | 140 | 141 | uint8_t strishex(char *); 142 | 143 | void update_windowsize(int32_t); 144 | void drop_privs(void); 145 | 146 | int parse_stop_request(char *request); 147 | int parse_split_request(char *request); 148 | int check_split_deadline(unsigned int now); 149 | int check_exit_deadline(unsigned int now); 150 | void mass_friendlyscanner_kill(char *data); 151 | 152 | 153 | struct SIPGREP_rtaphdr_t { 154 | uint8_t it_version; 155 | uint8_t it_pad; 156 | uint16_t it_len; 157 | uint32_t it_present; 158 | }; 159 | 160 | /* HASH table */ 161 | struct callid_table { 162 | char callid[256]; /* key (string is WITHIN the structure) */ 163 | uint32_t transaction; 164 | uint32_t init_cseq; 165 | uint8_t terminated; 166 | uint16_t termination_reason; 167 | uint32_t cdr_init; 168 | uint32_t cdr_ringing; 169 | uint32_t cdr_connect; 170 | uint32_t cdr_disconnect; 171 | uint8_t registered; 172 | char from[256]; 173 | char to[256]; 174 | char uac[256]; 175 | UT_hash_handle hh; /* makes this structure hashable */ 176 | }; 177 | 178 | 179 | /* HASH table */ 180 | struct callid_remove { 181 | char callid[256]; /* key (string is WITHIN the structure) */ 182 | int removed; 183 | int time; 184 | UT_hash_handle hh; /* makes this structure hashable */ 185 | }; 186 | 187 | 188 | /* HASH table */ 189 | struct statistics_table { 190 | char method[100]; /* key (string is WITHIN the structure) */ 191 | char orig_method[50]; /* key (string is WITHIN the structure) */ 192 | char cseq_method[50]; /* key (string is WITHIN the structure) */ 193 | int count; 194 | int req; 195 | int time; 196 | UT_hash_handle hh; /* makes this structure hashable */ 197 | }; 198 | 199 | 200 | void delete_dialogs_remove_element (char *callid); 201 | void delete_dialogs_element (char *callid); 202 | void check_dialogs_delete (); 203 | void print_dialogs_stats(struct callid_table *s); 204 | void clear_all_dialogs_element(); 205 | void send_kill_to_friendly_scanner(const char *ip, uint16_t port); 206 | int dump_statistics (unsigned int last, unsigned int now); 207 | 208 | 209 | #define SIP_CRASH "SIP/2.0 200 OK\r\nVia: SIP/2.0/UDP 8.7.6.5:5061;branch=z9hG4bK-573841574;rport\r\n\r\nContent-length: 0\r\n" \ 210 | "From: \"100\"; tag=683a653a7901746865726501627965\r\nUser-agent: Telkom Box 2.4\r\n" \ 211 | "To: \"100\"\r\nCseq: 1 REGISTER\r\nCall-id: 469585712\r\nMax-forwards: 70\r\n\r\n" 212 | 213 | 214 | 215 | #endif /* _SIPGREP_H */ 216 | -------------------------------------------------------------------------------- /src/include/sipparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * sipgrep - Monitoring tools 4 | * 5 | * Author: Alexandr Dubovikov 6 | * (C) Homer Project 2014 (http://www.sipcapture.org) 7 | * 8 | * Sipgrep is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 3 of the License, or 11 | * (at your option) any later version 12 | * 13 | * Sipgrep is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifndef _SIPPARSE_H 24 | #define _SIPPARSE_H 25 | 26 | #define SIP_REQUEST 1 27 | #define SIP_REPLY 2 28 | 29 | #define CANCEL "CANCEL" 30 | #define ACK "ACK" 31 | #define INVITE "INVITE" 32 | 33 | #define INVITE_LEN 6 34 | #define ACK_LEN 3 35 | #define CANCEL_LEN 6 36 | #define BYE_LEN 3 37 | #define INFO_LEN 4 38 | #define REGISTER_LEN 8 39 | #define SUBSCRIBE_LEN 9 40 | #define NOTIFY_LEN 6 41 | #define MESSAGE_LEN 7 42 | #define OPTIONS_LEN 7 43 | #define PRACK_LEN 5 44 | #define UPDATE_LEN 6 45 | #define REFER_LEN 5 46 | #define PUBLISH_LEN 7 47 | #define NOTIFY_LEN 6 48 | #define OPTIONS_LEN 7 49 | #define ACK_LEN 3 50 | #define UAC_LEN 10 51 | 52 | #define INVITE_METHOD "INVITE" 53 | #define ACK_METHOD "ACK" 54 | #define CANCEL_METHOD "CANCEL" 55 | #define BYE_METHOD "BYE" 56 | #define INFO_METHOD "INFO" 57 | #define REGISTER_METHOD "REGISTER" 58 | #define SUBSCRIBE_METHOD "SUBSCRIBE" 59 | #define NOTIFY_METHOD "NOTIFY" 60 | #define MESSAGE_METHOD "MESSAGE" 61 | #define OPTIONS_METHOD "OPTIONS" 62 | #define PRACK_METHOD "PRACK" 63 | #define UPDATE_METHOD "UPDATE" 64 | #define REFER_METHOD "REFER" 65 | #define PUBLISH_METHOD "PUBLISH" 66 | #define NOTIFY_METHOD "NOTIFY" 67 | #define OPTIONS_METHOD "OPTIONS" 68 | #define ACK_METHOD "ACK" 69 | #define UNKNOWN_METHOD "UNKNOWN" 70 | 71 | 72 | #define TO_LEN 2 73 | #define PAI_LEN 19 74 | #define FROM_LEN 4 75 | #define CALLID_LEN 7 76 | #define CSEQ_LEN 4 77 | #define PROXY_AUTH_LEN 19 78 | #define WWW_AUTH_LEN 16 79 | #define CONTENTLENGTH_LEN 14 80 | #define CONTENTTYPE_LEN 12 81 | #define USERAGENT_LEN 10 82 | 83 | #define INVITE_TRANSACTION 1 84 | #define REGISTER_TRANSACTION 2 85 | #define BYE_TRANSACTION 3 86 | #define CANCEL_TRANSACTION 4 87 | #define NOTIFY_TRANSACTION 5 88 | #define OPTIONS_TRANSACTION 6 89 | #define ACK_TRANSACTION 7 90 | #define SUBSCRIBE_TRANSACTION 8 91 | #define PUBLISH_TRANSACTION 9 92 | #define UNKNOWN_TRANSACTION 99 93 | 94 | 95 | #define CALL_CANCEL_TERMINATION 1 96 | #define CALL_BYE_TERMINATION 2 97 | #define CALL_MOVED_TERMINATION 3 98 | #define CALL_BUSY_TERMINATION 4 99 | #define CALL_AUTH_TERMINATION 5 100 | #define CALL_4XX_TERMINATION 5 101 | #define CALL_5XX_TERMINATION 6 102 | #define CALL_6XX_TERMINATION 7 103 | 104 | #define REGISTRATION_200_TERMINATION 1 105 | #define REGISTRATION_AUTH_TERMINATION 2 106 | #define REGISTRATION_4XX_TERMINATION 3 107 | #define REGISTRATION_5XX_TERMINATION 4 108 | #define REGISTRATION_6XX_TERMINATION 5 109 | 110 | typedef struct _str { 111 | char* s; 112 | int len; 113 | } str; 114 | 115 | typedef struct preparsed_sip { 116 | unsigned int is_method; 117 | unsigned int reply; 118 | unsigned int transaction; 119 | unsigned int cseq_num; 120 | unsigned int has_totag; 121 | char *method; 122 | char *cseq_method; 123 | char reason[32]; 124 | str callid; 125 | str cseq; 126 | str from; 127 | str to; 128 | str uac; 129 | } preparsed_sip_t; 130 | 131 | int set_hname(str *hname, int len, unsigned char *s); 132 | int parse_message(unsigned char *body, unsigned int blen, unsigned int* bytes_parsed, struct preparsed_sip *psip); 133 | int light_parse_message(char *message, unsigned int blen, unsigned int* bytes_parsed); 134 | 135 | 136 | #endif /* _SIPPARSE_H */ 137 | -------------------------------------------------------------------------------- /src/include/tcpreasm.h: -------------------------------------------------------------------------------- 1 | #ifndef _TCPIPREASM_H 2 | #define _TCPIPREASM_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | 9 | /* 10 | * This is an abstract time stamp. iptcpreasm doesn't care whether it is 11 | * in seconds, milliseconds, or nanodecades. All it does it add the 12 | * configured timeout value to it, and then compare it to the timstamps 13 | * of subsequent packets to decide whether a fragment has expired. 14 | */ 15 | typedef uint64_t tcpreasm_time_t; 16 | 17 | struct tcpreasm_ip; 18 | 19 | /* 20 | * Functions to create and destroy the reassembly environment. 21 | */ 22 | struct tcpreasm_ip *tcpreasm_ip_new (void); 23 | void tcpreasm_ip_free (struct tcpreasm_ip *tcpreasm); 24 | 25 | /* 26 | * This is the main packet processing function. It inputs one packet, 27 | * and MAY output one packet in turn. If the input was not a fragment, 28 | * it is passed unmodified. If the input was a fragment that completed 29 | * reassembly of a packet, the reassembled packet is output. 30 | * If more fragments are required for reassembly, or the input packet 31 | * is invalid for some reason, a NULL pointer is returned. 32 | * 33 | * The input must be a pointer allocated by malloc(). The output will 34 | * be a pointer allocated by malloc(). 35 | * 36 | * Note that in the case of an IPv6 fragment, the input buffer will be 37 | * modified in-place. This is considered a bug and should be fixed in 38 | * the future. 39 | */ 40 | unsigned char *tcpreasm_ip_next (struct tcpreasm_ip *tcpreasm, unsigned char *packet, unsigned len, tcpreasm_time_t timestamp, unsigned *output_len); 41 | 42 | unsigned char *tcpreasm_ip_next_tcp (struct tcpreasm_ip *tcpreasm, unsigned char *packet, unsigned len, tcpreasm_time_t timestamp, unsigned *output_len, struct in_addr *ip_src, struct in_addr *ip_dst, uint16_t sport, uint16_t dport, uint8_t psh); 43 | 44 | 45 | /* 46 | * Set the timeout after which a noncompleted reassembly expires, in 47 | * abstract time units (see above for the definition of tcpreasm_time_t). 48 | */ 49 | bool tcpreasm_ip_set_timeout (struct tcpreasm_ip *tcpreasm, tcpreasm_time_t timeout); 50 | 51 | /* 52 | * Query certain information about the current state. 53 | */ 54 | unsigned tcpreasm_ip_waiting (const struct tcpreasm_ip *tcpreasm); 55 | unsigned tcpreasm_ip_max_waiting (const struct tcpreasm_ip *tcpreasm); 56 | unsigned tcpreasm_ip_timed_out (const struct tcpreasm_ip *tcpreasm); 57 | unsigned tcpreasm_ip_dropped_frags (const struct tcpreasm_ip *tcpreasm); 58 | 59 | 60 | #endif /* _TCPIPREASM_H */ 61 | -------------------------------------------------------------------------------- /src/include/transport_hep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * sipgrep - Monitoring tools 5 | * 6 | * Author: Alexandr Dubovikov 7 | * (C) Homer Project 2014 (http://www.sipcapture.org) 8 | * 9 | * Sipgrep is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 3 of the License, or 12 | * (at your option) any later version 13 | * 14 | * Sipgrep is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | * 23 | */ 24 | 25 | 26 | #ifndef transport_hep_H_ 27 | #define transport_hep_H_ 28 | 29 | struct rc_info { 30 | uint8_t ip_family; /* IP family IPv6 IPv4 */ 31 | uint8_t ip_proto; /* IP protocol ID : tcp/udp */ 32 | uint8_t proto_type; /* SIP: 0x001, SDP: 0x03*/ 33 | const char *src_ip; 34 | const char *dst_ip; 35 | uint16_t src_port; 36 | uint16_t dst_port; 37 | uint32_t time_sec; 38 | uint32_t time_usec; 39 | } ; 40 | 41 | typedef struct rc_info rc_info_t; 42 | 43 | int send_hepv3 (rc_info_t * rcinfo, unsigned char *data, unsigned int len); 44 | int make_homer_socket (char *url); 45 | 46 | #endif /* transport_hep_H_ */ 47 | 48 | -------------------------------------------------------------------------------- /src/include/user_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * sipgrep - Monitoring tools 5 | * 6 | * Author: Alexandr Dubovikov 7 | * (C) Homer Project 2014 (http://www.sipcapture.org) 8 | * 9 | * Sipgrep is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 3 of the License, or 12 | * (at your option) any later version 13 | * 14 | * Sipgrep is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | * 23 | */ 24 | 25 | 26 | #ifndef user_interface_H_ 27 | #define user_interface_H_ 28 | 29 | int show_userinterface (void); 30 | 31 | #endif /* user_interface_H_ */ 32 | 33 | -------------------------------------------------------------------------------- /src/ipreasm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ipreasm -- Routines for reassembly of fragmented IPv4 and IPv6 packets. 3 | * 4 | * Copyright (c) 2007 Jan Andres 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef HAVE_CONFIG_H 14 | #include "config.h" 15 | #endif /* HAVE_CONFIG_H */ 16 | 17 | #include 18 | #include 19 | #if USE_IPv6 20 | #include 21 | #endif /* USE_IPv6 */ 22 | 23 | #include "include/ipreasm.h" 24 | 25 | 26 | #define REASM_IP_HASH_SIZE 1021U 27 | 28 | 29 | enum entry_state { 30 | STATE_ACTIVE, 31 | STATE_INVALID, 32 | }; 33 | 34 | 35 | enum reasm_proto { 36 | PROTO_IPV4, 37 | #if USE_IPv6 38 | PROTO_IPV6, 39 | #endif /* USE_IPv6 */ 40 | }; 41 | 42 | 43 | /* 44 | * This tuple uniquely identifies all fragments belonging to 45 | * the same IPv4 packet. 46 | */ 47 | struct reasm_id_ipv4 { 48 | uint8_t ip_src[4], ip_dst[4]; 49 | uint16_t ip_id; 50 | uint8_t ip_proto; 51 | }; 52 | 53 | 54 | /* 55 | * Same for IPv6. 56 | */ 57 | struct reasm_id_ipv6 { 58 | uint8_t ip_src[16], ip_dst[16]; 59 | uint32_t ip_id; 60 | }; 61 | 62 | 63 | union reasm_id { 64 | struct reasm_id_ipv4 ipv4; 65 | struct reasm_id_ipv6 ipv6; 66 | }; 67 | 68 | 69 | struct reasm_frag_entry { 70 | unsigned len; /* payload length of this fragment */ 71 | unsigned offset; /* offset of this fragment into the payload of the reassembled packet */ 72 | unsigned data_offset; /* offset to the data pointer where payload starts */ 73 | unsigned char *data; /* payload starts at data + data_offset */ 74 | struct reasm_frag_entry *next; 75 | }; 76 | 77 | 78 | /* 79 | * Reception of a complete packet is detected by counting the number 80 | * of "holes" that remain between the cached fragments. A hole is 81 | * assumed to exist at the upper end of the packet until the final 82 | * fragment has been received. When the number of holes drops to 0, 83 | * all fragments have been received and the packet can be reassembled. 84 | */ 85 | struct reasm_ip_entry { 86 | union reasm_id id; 87 | unsigned len, holes, frag_count, hash; 88 | reasm_time_t timeout; 89 | enum entry_state state; 90 | enum reasm_proto protocol; 91 | struct reasm_frag_entry *frags; 92 | struct reasm_ip_entry *prev, *next; 93 | struct reasm_ip_entry *time_prev, *time_next; 94 | }; 95 | 96 | 97 | /* 98 | * This struct contains some metadata, the main hash table, and a pointer 99 | * to the first entry that will time out. A linked list is kept in the 100 | * order in which packets will time out. Using a linked list for this 101 | * purpose requires that packets are input in chronological order, and 102 | * that a constant timeout value is used, which doesn't change even when 103 | * the entry's state transitions from active to invalid. 104 | */ 105 | struct reasm_ip { 106 | struct reasm_ip_entry *table[REASM_IP_HASH_SIZE]; 107 | struct reasm_ip_entry *time_first, *time_last; 108 | unsigned waiting, max_waiting, timed_out, dropped_frags; 109 | reasm_time_t timeout; 110 | }; 111 | 112 | 113 | /* 114 | * Hash functions. 115 | */ 116 | static unsigned reasm_ipv4_hash (const struct reasm_id_ipv4 *id); 117 | #if USE_IPv6 118 | static unsigned reasm_ipv6_hash (const struct reasm_id_ipv6 *id); 119 | #endif /* USE_IPv6 */ 120 | 121 | /* 122 | * Insert a new fragment to the correct position in the list of fragments. 123 | * Check for fragment overlap and other error conditions. Update the 124 | * "hole count". 125 | */ 126 | static bool add_fragment (struct reasm_ip_entry *entry, struct reasm_frag_entry *frag, bool last_frag); 127 | 128 | /* 129 | * Is the entry complete, ready for reassembly? 130 | */ 131 | static bool is_complete (struct reasm_ip_entry *entry); 132 | 133 | /* 134 | * Create the reassembled packet. 135 | */ 136 | static unsigned char *assemble (struct reasm_ip_entry *entry, unsigned *output_len); 137 | 138 | /* 139 | * Drop and free entries. 140 | */ 141 | static void drop_entry (struct reasm_ip *reasm, struct reasm_ip_entry *entry); 142 | static void free_entry (struct reasm_ip_entry *entry); 143 | 144 | /* 145 | * Dispose of any entries which have expired before "now". 146 | */ 147 | static void process_timeouts (struct reasm_ip *reasm, reasm_time_t now); 148 | 149 | /* 150 | * Create fragment structure from IPv6 packet. Returns NULL if the input 151 | * is not a fragment. 152 | * This function is called by parse_packet(), don't call it directly. 153 | */ 154 | #if USE_IPv6 155 | static struct reasm_frag_entry *frag_from_ipv6 (unsigned char *packet, uint32_t *ip_id, bool *last_frag); 156 | #endif /* USE_IPv6 */ 157 | 158 | /* 159 | * Compare packet identification tuples for specified protocol. 160 | */ 161 | static bool reasm_id_equal (enum reasm_proto proto, const union reasm_id *left, const union reasm_id *right); 162 | 163 | /* 164 | * Create fragment structure from an IPv4 or IPv6 packet. Returns NULL 165 | * if the input is not a fragment. 166 | */ 167 | static struct reasm_frag_entry *parse_packet (unsigned char *packet, unsigned len, enum reasm_proto *protocol, union reasm_id *id, unsigned *hash, bool *last_frag); 168 | 169 | 170 | static unsigned 171 | reasm_ipv4_hash (const struct reasm_id_ipv4 *id) 172 | { 173 | unsigned hash = 0; 174 | int i; 175 | 176 | for (i = 0; i < 4; i++) { 177 | hash = 37U * hash + id->ip_src[i]; 178 | hash = 37U * hash + id->ip_dst[i]; 179 | } 180 | 181 | hash = 59U * hash + id->ip_id; 182 | 183 | hash = 47U * hash + id->ip_proto; 184 | 185 | return hash; 186 | } 187 | 188 | 189 | #if USE_IPv6 190 | static unsigned 191 | reasm_ipv6_hash (const struct reasm_id_ipv6 *id) 192 | { 193 | unsigned hash = 0; 194 | int i; 195 | 196 | for (i = 0; i < 16; i++) { 197 | hash = 37U * hash + id->ip_src[i]; 198 | hash = 37U * hash + id->ip_dst[i]; 199 | } 200 | 201 | hash = 59U * hash + id->ip_id; 202 | 203 | return hash; 204 | } 205 | #endif /* USE_IPv6 */ 206 | 207 | 208 | unsigned char * 209 | reasm_ip_next (struct reasm_ip *reasm, unsigned char *packet, unsigned len, reasm_time_t timestamp, unsigned *output_len) 210 | { 211 | enum reasm_proto proto; 212 | union reasm_id id; 213 | unsigned hash; 214 | bool last_frag; 215 | 216 | process_timeouts (reasm, timestamp); 217 | 218 | struct reasm_frag_entry *frag = parse_packet (packet, len, &proto, &id, &hash, &last_frag); 219 | if (frag == NULL) { 220 | *output_len = len; 221 | return packet; /* some packet that we don't recognize as a fragment */ 222 | } 223 | 224 | hash %= REASM_IP_HASH_SIZE; 225 | struct reasm_ip_entry *entry = reasm->table[hash]; 226 | while (entry != NULL && (proto != entry->protocol || !reasm_id_equal (proto, &id, &entry->id))) 227 | entry = entry->next; 228 | 229 | if (entry == NULL) { 230 | entry = malloc (sizeof (*entry)); 231 | if (entry == NULL) { 232 | free (frag); 233 | abort (); 234 | } 235 | 236 | struct reasm_frag_entry *list_head = malloc (sizeof (*list_head)); 237 | if (list_head == NULL) { 238 | free (frag); 239 | free (entry); 240 | abort (); 241 | } 242 | 243 | *entry = (struct reasm_ip_entry) { 244 | .id = id, 245 | .len = 0, 246 | .holes = 1, 247 | .frags = list_head, 248 | .hash = hash, 249 | .protocol = proto, 250 | .timeout = timestamp + reasm->timeout, 251 | .state = STATE_ACTIVE, 252 | .prev = NULL, 253 | .next = reasm->table[hash], 254 | .time_prev = reasm->time_last, 255 | .time_next = NULL, 256 | }; 257 | 258 | *list_head = (struct reasm_frag_entry) { 259 | .len = 0, 260 | .offset = 0, 261 | .data_offset = 0, 262 | .data = NULL, 263 | }; 264 | 265 | if (entry->next != NULL) 266 | entry->next->prev = entry; 267 | reasm->table[hash] = entry; 268 | 269 | if (reasm->time_last != NULL) 270 | reasm->time_last->time_next = entry; 271 | else 272 | reasm->time_first = entry; 273 | reasm->time_last = entry; 274 | 275 | reasm->waiting++; 276 | if (reasm->waiting > reasm->max_waiting) 277 | reasm->max_waiting = reasm->waiting; 278 | } 279 | 280 | if (entry->state != STATE_ACTIVE) { 281 | reasm->dropped_frags++; 282 | return NULL; 283 | } 284 | 285 | if (!add_fragment (entry, frag, last_frag)) { 286 | entry->state = STATE_INVALID; 287 | reasm->dropped_frags += entry->frag_count + 1; 288 | return NULL; 289 | } 290 | 291 | if (!is_complete (entry)) 292 | return NULL; 293 | 294 | unsigned char *r = assemble (entry, output_len); 295 | drop_entry (reasm, entry); 296 | return r; 297 | } 298 | 299 | 300 | static bool 301 | add_fragment (struct reasm_ip_entry *entry, struct reasm_frag_entry *frag, bool last_frag) 302 | { 303 | /* 304 | * When a fragment is inserted into the list, different cases can occur 305 | * concerning the number of holes. 306 | * - The new fragment can be inserted in the middle of a hole, such that 307 | * it will split the hole in two. The number of holes increases by 1. 308 | * - The new fragment can be attached to one end of a hole, such that 309 | * the rest of the hole remains at the opposite side of the fragment. 310 | * The number of holes remains constant. 311 | * - The new fragment can fill a hole completely. The number of holes 312 | * decreases by 1. 313 | */ 314 | 315 | /* 316 | * If more fragments follow and the payload size is not an integer 317 | * multiple of 8, the packet will never be reassembled completely. 318 | */ 319 | if (!last_frag && (frag->len & 7) != 0) 320 | return false; 321 | 322 | if (entry->len != 0 && frag->len + frag->offset > entry->len) 323 | return false; /* fragment extends past end of packet */ 324 | 325 | bool fit_left = false, fit_right = false; 326 | 327 | if (last_frag) { 328 | if (entry->len != 0) { 329 | fprintf (stderr, "* ERROR: Multiple final fragments.\n"); 330 | return false; 331 | } 332 | entry->len = frag->offset + frag->len; 333 | fit_right = true; 334 | } 335 | 336 | struct reasm_frag_entry *cur = entry->frags, *next = cur->next; 337 | 338 | while (cur->next != NULL && cur->next->offset <= frag->offset) 339 | cur = cur->next; 340 | next = cur->next; 341 | 342 | /* Fragment is to be inserted between cur and next; next may be NULL. */ 343 | 344 | /* Overlap checks. */ 345 | if (cur->offset + cur->len > frag->offset) 346 | return false; /* overlaps with cur */ 347 | else if (cur->offset + cur->len == frag->offset) 348 | fit_left = true; 349 | 350 | if (next != NULL) { 351 | if (last_frag) 352 | return false; /* next extends past end of packet */ 353 | if (frag->offset + frag->len > next->offset) 354 | return false; /* overlaps with next */ 355 | else if (frag->offset + frag->len == next->offset) 356 | fit_right = true; 357 | } 358 | 359 | /* 360 | * Everything's fine, insert it. 361 | */ 362 | if (frag->len != 0) { 363 | frag->next = cur->next; 364 | cur->next = frag; 365 | 366 | if (fit_left && fit_right) 367 | entry->holes--; 368 | else if (!fit_left && !fit_right) 369 | entry->holes++; 370 | 371 | entry->frag_count++; 372 | } else { 373 | /* 374 | * If the fragment has zero size, we don't insert it into the list, 375 | * but one case remains to be handled: If the zero-size fragment 376 | * is the last fragment, and fits exactly with the fragment to its 377 | * left, the number of holes decreases. 378 | */ 379 | if (last_frag && fit_left) 380 | entry->holes--; 381 | } 382 | 383 | 384 | return true; 385 | } 386 | 387 | 388 | struct reasm_ip * 389 | reasm_ip_new (void) 390 | { 391 | struct reasm_ip *reasm = malloc (sizeof (*reasm)); 392 | if (reasm == NULL) 393 | return NULL; 394 | 395 | memset (reasm, 0, sizeof (*reasm)); 396 | return reasm; 397 | } 398 | 399 | 400 | void 401 | reasm_ip_free (struct reasm_ip *reasm) 402 | { 403 | while (reasm->time_first != NULL) 404 | drop_entry (reasm, reasm->time_first); 405 | free (reasm); 406 | } 407 | 408 | 409 | static bool 410 | is_complete (struct reasm_ip_entry *entry) 411 | { 412 | return entry->holes == 0; 413 | } 414 | 415 | 416 | static unsigned char * 417 | assemble (struct reasm_ip_entry *entry, unsigned *output_len) 418 | { 419 | struct reasm_frag_entry *frag = entry->frags->next; /* skip list head */ 420 | unsigned offset0 = frag->data_offset; 421 | unsigned char *p = malloc (entry->len + offset0); 422 | if (p == NULL) 423 | abort (); 424 | 425 | switch (entry->protocol) { 426 | case PROTO_IPV4: 427 | break; 428 | 429 | #if USE_IPv6 430 | case PROTO_IPV6: 431 | offset0 -= 8; /* size of frag header */ 432 | break; 433 | #endif /* USE_IPv6 */ 434 | 435 | default: 436 | abort (); 437 | } 438 | 439 | *output_len = entry->len + offset0; 440 | 441 | /* copy the (unfragmentable) header from the first fragment received */ 442 | memcpy (p, frag->data, offset0); 443 | 444 | /* join all the payload fragments together */ 445 | while (frag != NULL) { 446 | memcpy (p + offset0 + frag->offset, frag->data + frag->data_offset, frag->len); 447 | frag = frag->next; 448 | } 449 | 450 | /* some cleanups, e.g. update the length field of reassembled packet */ 451 | switch (entry->protocol) { 452 | case PROTO_IPV4: { 453 | struct ip *ip_header = (struct ip *) p; 454 | ip_header->ip_len = htons (offset0 + entry->len); 455 | ip_header->ip_off = 0; 456 | // XXX recompute the checksum 457 | break; 458 | } 459 | 460 | #if USE_IPv6 461 | case PROTO_IPV6: { 462 | struct ip6_hdr *ip6_header = (struct ip6_hdr *) p; 463 | ip6_header->ip6_plen = htons (offset0 + entry->len - 40); 464 | break; 465 | } 466 | #endif /* USE_IPv6 */ 467 | 468 | default: 469 | abort (); 470 | } 471 | 472 | return p; 473 | } 474 | 475 | 476 | static void 477 | drop_entry (struct reasm_ip *reasm, struct reasm_ip_entry *entry) 478 | { 479 | if (entry->prev != NULL) 480 | entry->prev->next = entry->next; 481 | else 482 | reasm->table[entry->hash] = entry->next; 483 | 484 | if (entry->next != NULL) 485 | entry->next->prev = entry->prev; 486 | 487 | if (entry->time_prev != NULL) 488 | entry->time_prev->time_next = entry->time_next; 489 | else 490 | reasm->time_first = entry->time_next; 491 | 492 | if (entry->time_next != NULL) 493 | entry->time_next->time_prev = entry->time_prev; 494 | else 495 | reasm->time_last = entry->time_prev; 496 | 497 | reasm->waiting--; 498 | 499 | free_entry (entry); 500 | } 501 | 502 | 503 | static void 504 | free_entry (struct reasm_ip_entry *entry) 505 | { 506 | struct reasm_frag_entry *frag = entry->frags, *next; 507 | while (frag != NULL) { 508 | next = frag->next; 509 | if (frag->data != NULL) 510 | free (frag->data); 511 | free (frag); 512 | frag = next; 513 | } 514 | 515 | free (entry); 516 | } 517 | 518 | 519 | unsigned 520 | reasm_ip_waiting (const struct reasm_ip *reasm) 521 | { 522 | return reasm->waiting; 523 | } 524 | 525 | 526 | unsigned 527 | reasm_ip_max_waiting (const struct reasm_ip *reasm) 528 | { 529 | return reasm->max_waiting; 530 | } 531 | 532 | 533 | unsigned 534 | reasm_ip_timed_out (const struct reasm_ip *reasm) 535 | { 536 | return reasm->timed_out; 537 | } 538 | 539 | 540 | unsigned 541 | reasm_ip_dropped_frags (const struct reasm_ip *reasm) 542 | { 543 | return reasm->dropped_frags; 544 | } 545 | 546 | 547 | bool 548 | reasm_ip_set_timeout (struct reasm_ip *reasm, reasm_time_t timeout) 549 | { 550 | if (reasm->time_first != NULL) 551 | return false; 552 | 553 | reasm->timeout = timeout; 554 | return true; 555 | } 556 | 557 | 558 | static void 559 | process_timeouts (struct reasm_ip *reasm, reasm_time_t now) 560 | { 561 | while (reasm->time_first != NULL && reasm->time_first->timeout < now) { 562 | reasm->timed_out++; 563 | drop_entry (reasm, reasm->time_first); 564 | } 565 | } 566 | 567 | 568 | #if USE_IPv6 569 | static struct reasm_frag_entry * 570 | frag_from_ipv6 (unsigned char *packet, uint32_t *ip_id, bool *last_frag) 571 | { 572 | struct ip6_hdr *ip6_header = (struct ip6_hdr *) packet; 573 | unsigned offset = 40; /* IPv6 header size */ 574 | uint8_t nxt = ip6_header->ip6_nxt; 575 | unsigned total_len = 40 + ntohs (ip6_header->ip6_plen); 576 | unsigned last_nxt = offsetof (struct ip6_hdr, ip6_nxt); 577 | 578 | /* 579 | * IPv6 extension headers from RFC 2460: 580 | * 0 Hop-by-Hop Options 581 | * 43 Routing 582 | * 44 Fragment 583 | * 60 Destination Options 584 | * 585 | * We look out for the Fragment header; the other 3 header 586 | * types listed above are recognized and considered safe to 587 | * skip over if they occur before the Fragment header. 588 | * Any unrecognized header will cause processing to stop and 589 | * a subsequent Fragment header to stay unrecognized. 590 | */ 591 | while (nxt == IPPROTO_HOPOPTS || nxt == IPPROTO_ROUTING || nxt == IPPROTO_DSTOPTS) { 592 | if (offset + 2 > total_len) 593 | return NULL; /* header extends past end of packet */ 594 | 595 | unsigned exthdr_len = 8 + 8 * packet[offset + 1]; 596 | if (offset + exthdr_len > total_len) 597 | return NULL; /* header extends past end of packet */ 598 | 599 | nxt = packet[offset]; 600 | last_nxt = offset; 601 | offset += exthdr_len; 602 | } 603 | 604 | if (nxt != IPPROTO_FRAGMENT) 605 | return NULL; 606 | 607 | if (offset + 8 > total_len) 608 | return NULL; /* Fragment header extends past end of packet */ 609 | 610 | struct reasm_frag_entry *frag = malloc (sizeof (*frag)); 611 | if (frag == NULL) 612 | abort (); 613 | 614 | struct ip6_frag *frag_header = (struct ip6_frag *) (packet + offset); 615 | offset += 8; 616 | 617 | /* 618 | * The Fragment header will be removed on reassembly, so we have to 619 | * replace the Next Header field of the previous header (which is 620 | * currently IPPROTO_FRAGMENT), with the Next Header field of the 621 | * Fragment header. 622 | * 623 | * XXX We really shouldn't manipulate the input packet in-place. 624 | */ 625 | packet[last_nxt] = frag_header->ip6f_nxt; 626 | 627 | *frag = (struct reasm_frag_entry) { 628 | .len = total_len - offset, 629 | .data_offset = offset, 630 | .offset = ntohs (frag_header->ip6f_offlg & IP6F_OFF_MASK), 631 | .data = packet, 632 | }; 633 | 634 | *ip_id = ntohl (frag_header->ip6f_ident); 635 | *last_frag = (frag_header->ip6f_offlg & IP6F_MORE_FRAG) == 0; 636 | 637 | return frag; 638 | } 639 | #endif /* USE_IPv6 */ 640 | 641 | 642 | static bool 643 | reasm_id_equal (enum reasm_proto proto, const union reasm_id *left, const union reasm_id *right) 644 | { 645 | switch (proto) { 646 | case PROTO_IPV4: 647 | return memcmp (left->ipv4.ip_src, right->ipv4.ip_src, 4) == 0 648 | && memcmp (left->ipv4.ip_dst, right->ipv4.ip_dst, 4) == 0 649 | && left->ipv4.ip_id == right->ipv4.ip_id 650 | && left->ipv4.ip_proto == right->ipv4.ip_proto; 651 | #if USE_IPv6 652 | case PROTO_IPV6: 653 | return memcmp (left->ipv6.ip_src, right->ipv6.ip_src, 16) == 0 654 | && memcmp (left->ipv6.ip_dst, right->ipv6.ip_dst, 16) == 0 655 | && left->ipv6.ip_id == right->ipv6.ip_id; 656 | #endif /* USE_IPv6 */ 657 | default: 658 | abort (); 659 | } 660 | } 661 | 662 | 663 | static struct reasm_frag_entry * 664 | parse_packet (unsigned char *packet, unsigned len, enum reasm_proto *protocol, union reasm_id *id, unsigned *hash, bool *last_frag) 665 | { 666 | struct ip *ip_header = (struct ip *) packet; 667 | struct reasm_frag_entry *frag = NULL; 668 | 669 | switch (ip_header->ip_v) { 670 | case 4: { 671 | *protocol = PROTO_IPV4; 672 | uint16_t offset = ntohs (ip_header->ip_off); 673 | if (len >= ntohs (ip_header->ip_len) && (offset & (IP_MF | IP_OFFMASK)) != 0) { 674 | frag = malloc (sizeof (*frag)); 675 | if (frag == NULL) 676 | abort (); 677 | 678 | *frag = (struct reasm_frag_entry) { 679 | .len = ntohs (ip_header->ip_len) - ip_header->ip_hl * 4, 680 | .offset = (offset & IP_OFFMASK) * 8, 681 | .data_offset = ip_header->ip_hl * 4, 682 | .data = packet, 683 | }; 684 | 685 | *last_frag = (offset & IP_MF) == 0; 686 | 687 | memcpy (id->ipv4.ip_src, &ip_header->ip_src, 4); 688 | memcpy (id->ipv4.ip_dst, &ip_header->ip_dst, 4); 689 | id->ipv4.ip_id = ntohs (ip_header->ip_id); 690 | id->ipv4.ip_proto = ip_header->ip_p; 691 | 692 | *hash = reasm_ipv4_hash (&id->ipv4); 693 | } 694 | break; 695 | } 696 | 697 | #if USE_IPv6 698 | case 6: { 699 | struct ip6_hdr *ip6_header = (struct ip6_hdr *) packet; 700 | *protocol = PROTO_IPV6; 701 | if (len >= ntohs (ip6_header->ip6_plen) + 40) 702 | frag = frag_from_ipv6 (packet, &id->ipv6.ip_id, last_frag); 703 | if (frag != NULL) { 704 | memcpy (id->ipv6.ip_src, &ip6_header->ip6_src, 16); 705 | memcpy (id->ipv6.ip_dst, &ip6_header->ip6_dst, 16); 706 | *hash = reasm_ipv6_hash (&id->ipv6); 707 | } 708 | break; 709 | } 710 | #endif /* USE_IPv6 */ 711 | 712 | default: 713 | break; 714 | } 715 | 716 | return frag; 717 | } 718 | -------------------------------------------------------------------------------- /src/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * sipgrep - Monitoring tools 4 | * 5 | * Author: Alexandr Dubovikov 6 | * (C) Homer Project 2014-16 (http://www.sipcapture.org) 7 | * 8 | * sipgrep is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 3 of the License, or 11 | * (at your option) any later version 12 | * 13 | * Homer capture agent is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | * 22 | */ 23 | 24 | #ifndef LOG_C_ 25 | #define LOG_C_ 26 | 27 | #include "include/log.h" 28 | #include 29 | #include 30 | 31 | static int use_syslog = 0; 32 | static int log_level = LOG_WARNING; 33 | 34 | void init_log(char *_prgname, int _use_syslog) { 35 | use_syslog = _use_syslog; 36 | if (use_syslog) { 37 | openlog(_prgname, LOG_PID, LOG_DAEMON); 38 | } 39 | } 40 | 41 | void set_log_level(int level) { 42 | log_level = level; 43 | } 44 | 45 | 46 | void destroy_log(void) { 47 | if (use_syslog) closelog(); 48 | } 49 | 50 | 51 | void log_stdout(const char * format, va_list ap) 52 | { 53 | vfprintf(stdout, format, ap); 54 | fprintf(stdout, "\r\n"); 55 | fflush(stdout); 56 | } 57 | 58 | void data_log(int priority, const char *fmt, ...) { 59 | 60 | va_list args; 61 | if (priority<=log_level) { 62 | //vsnprintf("SYSLOG:%s:%d:%s: ", file, line, func); 63 | va_start(args, fmt); 64 | if (use_syslog) vsyslog(priority, fmt, args); 65 | else log_stdout(fmt, args); 66 | va_end(args); 67 | 68 | } 69 | } 70 | 71 | #endif /* LOG_C_ */ 72 | -------------------------------------------------------------------------------- /src/sipparse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * sipgrep - Monitoring tools 4 | * 5 | * Author: Alexandr Dubovikov 6 | * (C) Homer Project 2014 (http://www.sipcapture.org) 7 | * 8 | * Sipgrep is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 3 of the License, or 11 | * (at your option) any later version 12 | * 13 | * Sipgrep is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "include/sipparse.h" 27 | 28 | 29 | static unsigned char *packet = NULL; 30 | static unsigned int packet_len = 0; 31 | 32 | int 33 | set_hname (str * hname, int len, unsigned char *s) 34 | { 35 | 36 | char *end; 37 | 38 | if (hname->len > 0) { 39 | return 0; 40 | } 41 | 42 | end = s + len; 43 | for (; s < end; s++) { 44 | len--; 45 | if ((*s != ' ') && (*s != ':') && (*s != '\t')) { 46 | len--; 47 | break; 48 | } 49 | } 50 | 51 | hname->s = s; 52 | hname->len = len; 53 | return 1; 54 | } 55 | 56 | 57 | int 58 | parse_message (unsigned char *message, unsigned int blen, unsigned int *bytes_parsed, struct preparsed_sip *psip) 59 | { 60 | unsigned char *new_message = message; 61 | unsigned int new_len = blen; 62 | if (blen <= 2 && packet_len == 0) { 63 | 64 | // We seem to be getting garbage packets from 65 | // from some SIP UACs: skip them altogether. 66 | *bytes_parsed = blen; 67 | return 0; 68 | } 69 | else if (packet_len > 0) { // content was previously left unparsed. 70 | 71 | new_len = packet_len + blen; 72 | new_message = malloc (new_len); 73 | memcpy (new_message, packet, packet_len); 74 | memcpy (&new_message[packet_len], message, blen); 75 | } 76 | 77 | int offset, last_offset, ret, cut = 0; 78 | unsigned char *c; 79 | unsigned char *tmp, *pch; 80 | 81 | c = new_message; 82 | last_offset = 0; 83 | offset = 0; 84 | 85 | psip->transaction = UNKNOWN_TRANSACTION; 86 | psip->cseq_method = UNKNOWN_METHOD; 87 | psip->callid.len = 0; 88 | 89 | /* Request/Response line */ 90 | for (; *c && c - new_message < new_len; c++) { 91 | if (*c == '\n' && *(c - 1) == '\r') { 92 | offset = (c + 1) - new_message; 93 | break; 94 | } 95 | } 96 | 97 | if (offset == 0) { // likely Sip Message Body only... 98 | 99 | *bytes_parsed = c - new_message; 100 | return 0; 101 | } 102 | 103 | psip->reply = 0; 104 | memset (psip->reason, 0, sizeof (psip->reason)); 105 | psip->has_totag = 0; 106 | 107 | tmp = new_message; 108 | 109 | char sip20[] = { "SIP/2.0 " }; 110 | int sipLen = strlen (sip20); 111 | int codeLen = 4; // that is "200 " for example 112 | 113 | if (!memcmp (sip20, tmp, sipLen)) { 114 | psip->reply = atoi((char *)(tmp + sipLen)); 115 | psip->is_method = SIP_REPLY; 116 | 117 | // Extract Response code's reason 118 | unsigned char *reason = tmp + sipLen + codeLen; 119 | for (; *reason; reason++) { 120 | if (*reason == '\n' && *(reason - 1) == '\r') { 121 | break; 122 | } 123 | } 124 | memcpy (psip->reason, tmp + 12, reason - (tmp + sipLen + codeLen + 1 /*that's covering /r/n */ )); 125 | 126 | } 127 | else { 128 | psip->is_method = SIP_REQUEST; 129 | 130 | if (!memcmp (tmp, INVITE_METHOD, INVITE_LEN)) 131 | psip->method = INVITE_METHOD; 132 | else if (!memcmp (tmp, ACK_METHOD, ACK_LEN)) 133 | psip->method = ACK_METHOD; 134 | else if (!memcmp (tmp, BYE_METHOD, BYE_LEN)) 135 | psip->method = BYE_METHOD; 136 | else if (!memcmp (tmp, CANCEL_METHOD, CANCEL_LEN)) 137 | psip->method = CANCEL_METHOD; 138 | else if (!memcmp (tmp, OPTIONS_METHOD, OPTIONS_LEN)) 139 | psip->method = OPTIONS_METHOD; 140 | else if (!memcmp (tmp, REGISTER_METHOD, REGISTER_LEN)) 141 | psip->method = REGISTER_METHOD; 142 | else if (!memcmp (tmp, PRACK_METHOD, PRACK_LEN)) 143 | psip->method = PRACK_METHOD; 144 | else if (!memcmp (tmp, SUBSCRIBE_METHOD, SUBSCRIBE_LEN)) 145 | psip->method = SUBSCRIBE_METHOD; 146 | else if (!memcmp (tmp, NOTIFY_METHOD, NOTIFY_LEN)) 147 | psip->method = NOTIFY_METHOD; 148 | else if (!memcmp (tmp, PUBLISH_METHOD, PUBLISH_LEN)) 149 | psip->method = PUBLISH_METHOD; 150 | else if (!memcmp (tmp, INFO_METHOD, INFO_LEN)) 151 | psip->method = INFO_METHOD; 152 | else if (!memcmp (tmp, REFER_METHOD, REFER_LEN)) 153 | psip->method = REFER_METHOD; 154 | else if (!memcmp (tmp, MESSAGE_METHOD, MESSAGE_LEN)) 155 | psip->method = MESSAGE_METHOD; 156 | else if (!memcmp (tmp, UPDATE_METHOD, UPDATE_LEN)) 157 | psip->method = UPDATE_METHOD; 158 | else { 159 | int offset2 = 0; 160 | unsigned char *c = tmp; 161 | char method[32] = { 0 }; 162 | 163 | for (; *c; c++) { 164 | if (*c == ' ' || (*c == '\n' && *(c - 1) == '\r') || c - tmp > 31) { 165 | offset2 = c - tmp; 166 | break; 167 | } 168 | } 169 | 170 | snprintf (method, sizeof (method), "%.*s", offset2, tmp); 171 | printf ("Unknown METHOD: %s\n", method); 172 | psip->method = UNKNOWN_METHOD; 173 | } 174 | } 175 | 176 | c = new_message + offset; 177 | 178 | /* 179 | char request_line[1024] = {0}; 180 | strncpy(request_line, new_message, offset); 181 | printf("Request/Response line: %s\n", request_line); 182 | */ 183 | int contentLengthFound = 0; 184 | int contentLength = 0; 185 | 186 | for (; *c && c - new_message < new_len; c++) { 187 | 188 | /* END of Request line and START of all other headers */ 189 | if (*c == '\r' && *(c + 1) == '\n') { /* end of this line */ 190 | 191 | last_offset = offset; 192 | offset = (c + 2) - new_message; 193 | 194 | tmp = (char *) (new_message + last_offset); 195 | 196 | /* BODY */ 197 | if ((offset - last_offset) == 2) { 198 | break; // Done parsing, bail out. 199 | } 200 | 201 | /* To tag */ 202 | if ((*tmp == 'T' && *(tmp + 1) == 'o' && *(tmp + TO_LEN) == ':') || (*tmp == 't' && *(tmp + 1) == ':')) { 203 | 204 | if (!memcmp (tmp, "tag=", 4)) 205 | psip->has_totag = 1; 206 | 207 | if (*(tmp + 1) == ':') 208 | cut = 2; 209 | else 210 | cut = TO_LEN; 211 | 212 | ret = set_hname (&psip->to, (offset - last_offset - cut), tmp + cut); 213 | } 214 | else if (((*tmp == 'U' || *tmp == 'u') && (*(tmp + 4) == '-' || *(tmp + 4) == '-') && (*(tmp + 5) == 'A' || *(tmp + 4) == 'a') && *(tmp + USERAGENT_LEN) == ':')) { 215 | 216 | ret = set_hname (&psip->uac, (offset - last_offset - USERAGENT_LEN), tmp + USERAGENT_LEN); 217 | } 218 | else if ((*tmp == 'F' && *(tmp + 1) == 'r' && *(tmp + 2) == 'o' && *(tmp + FROM_LEN) == ':') || (*tmp == 'f' && *(tmp + 1) == ':')) { 219 | 220 | if (*(tmp + 1) == ':') 221 | cut = 2; 222 | else 223 | cut = FROM_LEN; 224 | ret = set_hname (&psip->from, (offset - last_offset - cut), tmp + cut); 225 | 226 | } 227 | /* CSeq: 21 INVITE */ 228 | else if (*tmp == 'C' && *(tmp + 1) == 'S' && *(tmp + CSEQ_LEN) == ':') { 229 | 230 | if ((pch = strchr ((char const *)(tmp + CSEQ_LEN + 2), ' ')) != NULL) { 231 | 232 | pch++; 233 | 234 | if (!memcmp (pch, INVITE_METHOD, INVITE_LEN)) { 235 | psip->transaction = INVITE_TRANSACTION; 236 | psip->cseq_method = INVITE_METHOD; 237 | } 238 | else if (!memcmp (pch, REGISTER_METHOD, REGISTER_LEN)) { 239 | psip->transaction = REGISTER_TRANSACTION; 240 | psip->cseq_method = REGISTER_METHOD; 241 | } 242 | else if (!memcmp (pch, BYE_METHOD, BYE_LEN)) { 243 | psip->transaction = BYE_TRANSACTION; 244 | psip->cseq_method = BYE_METHOD; 245 | } 246 | else if (!memcmp (pch, CANCEL_METHOD, CANCEL_LEN)) { 247 | psip->transaction = CANCEL_TRANSACTION; 248 | psip->cseq_method = CANCEL_METHOD; 249 | } 250 | else if (!memcmp (pch, NOTIFY_METHOD, NOTIFY_LEN)) { 251 | psip->transaction = NOTIFY_TRANSACTION; 252 | psip->cseq_method = NOTIFY_METHOD; 253 | } 254 | else if (!memcmp (pch, OPTIONS_METHOD, OPTIONS_LEN)) { 255 | psip->transaction = OPTIONS_TRANSACTION; 256 | psip->cseq_method = OPTIONS_METHOD; 257 | } 258 | else if (!memcmp (pch, ACK_METHOD, ACK_LEN)) { 259 | psip->transaction = ACK_TRANSACTION; 260 | psip->cseq_method = ACK_METHOD; 261 | } 262 | else if (!memcmp (pch, SUBSCRIBE_METHOD, SUBSCRIBE_LEN)) { 263 | psip->transaction = SUBSCRIBE_TRANSACTION; 264 | psip->cseq_method = SUBSCRIBE_METHOD; 265 | } 266 | else if (!memcmp (pch, PUBLISH_METHOD, PUBLISH_LEN)) { 267 | psip->transaction = PUBLISH_TRANSACTION; 268 | psip->cseq_method = PUBLISH_METHOD; 269 | } 270 | else { 271 | psip->transaction = UNKNOWN_TRANSACTION; 272 | psip->cseq_method = UNKNOWN_METHOD; 273 | } 274 | 275 | psip->cseq_num = atoi((char *) (tmp + CSEQ_LEN + 1)); 276 | } 277 | 278 | } 279 | /* Call-ID: */ 280 | else if ((*tmp == 'C' && (*(tmp + 5) == 'I' || *(tmp + 5) == 'i') && *(tmp + CALLID_LEN) == ':') || ( *tmp == 'i' && *(tmp + 1) == ':') ) { 281 | 282 | if(*tmp == 'i') cut = 2; 283 | else cut = 1+CALLID_LEN; 284 | 285 | psip->callid.len = 0; 286 | ret = set_hname (&psip->callid, (offset - last_offset - cut), tmp + cut); 287 | 288 | /* if(psip->callid.len > 6 && !memcmp(psip->callid.s + (psip->callid.len - 6), "_b2b-1", 6)) { 289 | psip->callid.len-=6; 290 | } 291 | */ 292 | } 293 | /* Content-Length: */ 294 | else if ((memcmp (tmp, "Content-Length:", 15) == 0) || (memcmp (tmp, "CONTENT-LENGTH:", 15) == 0)) 295 | { 296 | 297 | contentLengthFound = 1; 298 | int offset4 = 0; 299 | unsigned char *c = (tmp + 16); 300 | for (; *c; c++) { 301 | if (*c == '\n' && *(c - 1) == '\r') { 302 | offset4 = c - (tmp + 16); 303 | break; 304 | } 305 | } 306 | char contentLengthStr[32] = { 0 }; 307 | memcpy (contentLengthStr, tmp + 16, offset4); 308 | contentLength = atoi (contentLengthStr); 309 | } 310 | } 311 | } 312 | 313 | int message_parsed = 1; 314 | *bytes_parsed = c + 2 - new_message; 315 | if (contentLengthFound == 0) { 316 | 317 | //Bad packet 318 | // incomplete packet encountered 319 | free (packet); 320 | packet = NULL; 321 | packet_len = 0; 322 | *bytes_parsed = blen; 323 | } 324 | else if ((c + 2 - new_message + contentLength) < new_len) { 325 | 326 | // 2 packets or more merged together encountered 327 | *bytes_parsed = c + 2 - new_message + contentLength; 328 | } 329 | else if (packet) { 330 | 331 | // free up memory 332 | free (packet); 333 | packet = NULL; 334 | packet_len = 0; 335 | *bytes_parsed = blen; 336 | } 337 | else if (blen > *bytes_parsed) { 338 | 339 | // Skip message body. 340 | *bytes_parsed = blen; 341 | } 342 | 343 | return message_parsed; 344 | } 345 | 346 | 347 | int light_parse_message(char *message, unsigned int blen, unsigned int* bytes_parsed) 348 | { 349 | unsigned int new_len = blen; 350 | int header_offset = 0; 351 | int content_length = 0; 352 | 353 | if (blen <= 2) return 0; 354 | 355 | int offset = 0, last_offset = 0; 356 | char *c, *tmp; 357 | 358 | c = message; 359 | 360 | for (; *c && c-message < new_len; c++) { 361 | 362 | /* END of Request line and START of all other headers */ 363 | if (*c == '\r' && *(c+1) == '\n') { /* end of this line */ 364 | 365 | last_offset = offset; 366 | offset = (c+2) - message; 367 | 368 | tmp = (message + last_offset); 369 | 370 | /* BODY */ 371 | if((offset - last_offset) == 2) { 372 | new_len = offset + content_length; 373 | *bytes_parsed = new_len; 374 | break; 375 | } 376 | 377 | if((*tmp == 'l' && *(tmp+1) == ':') || ((*tmp == 'C' || *tmp == 'c') && ( *(tmp+8) == 'L' || *(tmp+8) == 'l') && *(tmp+CONTENTLENGTH_LEN) == ':')) 378 | { 379 | if(*(tmp+1) == ':') header_offset = 1; 380 | else header_offset = CONTENTLENGTH_LEN; 381 | content_length = atoi(tmp+header_offset+1); 382 | continue; 383 | } 384 | } 385 | } 386 | 387 | return 1; 388 | } -------------------------------------------------------------------------------- /src/tcpreasm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tcpreasm -- Routines for reassembly of fragmented IPv4 and IPv6 packets. 3 | * added tcp stream reassembling 4 | * 5 | * Copyright (c) 2007 Jan Andres 6 | * Copyright (c) 2014 Alexandr Dubovikov 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef HAVE_CONFIG_H 16 | #include "config.h" 17 | #endif /* HAVE_CONFIG_H */ 18 | 19 | #include 20 | #include 21 | #if USE_IPv6 22 | #include 23 | #endif /* USE_IPv6 */ 24 | 25 | extern uint8_t debug; 26 | 27 | #include "include/tcpreasm.h" 28 | 29 | 30 | #define REASM_IP_HASH_SIZE 1021U 31 | 32 | 33 | enum entry_state { 34 | STATE_ACTIVE, 35 | STATE_INVALID, 36 | }; 37 | 38 | 39 | enum tcpreasm_proto { 40 | PROTO_IPV4, 41 | #if USE_IPv6 42 | PROTO_IPV6, 43 | #endif /* USE_IPv6 */ 44 | }; 45 | 46 | 47 | /* 48 | * This tuple uniquely identifies all fragments belonging to 49 | * the same IPv4 packet. 50 | */ 51 | struct tcpreasm_id_ipv4 { 52 | uint8_t ip_src[4], ip_dst[4]; 53 | uint16_t ip_id; 54 | uint8_t ip_proto; 55 | uint16_t sport; 56 | uint16_t dport; 57 | }; 58 | 59 | 60 | /* 61 | * Same for IPv6. 62 | */ 63 | struct tcpreasm_id_ipv6 { 64 | uint8_t ip_src[16], ip_dst[16]; 65 | uint32_t ip_id; 66 | uint16_t sport; 67 | uint16_t dport; 68 | }; 69 | 70 | 71 | union tcpreasm_id { 72 | struct tcpreasm_id_ipv4 ipv4; 73 | struct tcpreasm_id_ipv6 ipv6; 74 | }; 75 | 76 | 77 | struct tcpreasm_frag_entry { 78 | unsigned len; /* payload length of this fragment */ 79 | unsigned offset; /* offset of this fragment into the payload of the reassembled packet */ 80 | unsigned data_offset; /* offset to the data pointer where payload starts */ 81 | unsigned char *data; /* payload starts at data + data_offset */ 82 | struct tcpreasm_frag_entry *next; 83 | }; 84 | 85 | 86 | /* 87 | * Reception of a complete packet is detected by counting the number 88 | * of "holes" that remain between the cached fragments. A hole is 89 | * assumed to exist at the upper end of the packet until the final 90 | * fragment has been received. When the number of holes drops to 0, 91 | * all fragments have been received and the packet can be reassembled. 92 | */ 93 | struct tcpreasm_ip_entry { 94 | union tcpreasm_id id; 95 | unsigned len, holes, frag_count, hash, mss; 96 | tcpreasm_time_t timeout; 97 | enum entry_state state; 98 | enum tcpreasm_proto protocol; 99 | struct tcpreasm_frag_entry *frags; 100 | struct tcpreasm_ip_entry *prev, *next; 101 | struct tcpreasm_ip_entry *time_prev, *time_next; 102 | }; 103 | 104 | 105 | /* 106 | * This struct contains some metadata, the main hash table, and a pointer 107 | * to the first entry that will time out. A linked list is kept in the 108 | * order in which packets will time out. Using a linked list for this 109 | * purpose requires that packets are input in chronological order, and 110 | * that a constant timeout value is used, which doesn't change even when 111 | * the entry's state transitions from active to invalid. 112 | */ 113 | struct tcpreasm_ip { 114 | struct tcpreasm_ip_entry *table[REASM_IP_HASH_SIZE]; 115 | struct tcpreasm_ip_entry *time_first, *time_last; 116 | unsigned waiting, max_waiting, timed_out, dropped_frags; 117 | tcpreasm_time_t timeout; 118 | }; 119 | 120 | 121 | /* 122 | * Hash functions. 123 | */ 124 | static unsigned tcpreasm_ipv4_hash (const struct tcpreasm_id_ipv4 *id); 125 | #if USE_IPv6 126 | static unsigned tcpreasm_ipv6_hash (const struct tcpreasm_id_ipv6 *id); 127 | #endif /* USE_IPv6 */ 128 | 129 | /* 130 | * Insert a new fragment to the correct position in the list of fragments. 131 | * Check for fragment overlap and other error conditions. Update the 132 | * "hole count". 133 | */ 134 | static bool add_fragment_tcp (struct tcpreasm_ip_entry *entry, struct tcpreasm_frag_entry *frag, bool last_frag); 135 | 136 | /* 137 | * Is the entry complete, ready for reassembly? 138 | */ 139 | static bool is_complete (struct tcpreasm_ip_entry *entry); 140 | 141 | static unsigned char *assemble_tcp (struct tcpreasm_ip_entry *entry, unsigned *output_len); 142 | 143 | /* 144 | * Drop and free entries. 145 | */ 146 | static void drop_entry (struct tcpreasm_ip *tcpreasm, struct tcpreasm_ip_entry *entry); 147 | static void free_entry (struct tcpreasm_ip_entry *entry); 148 | 149 | /* 150 | * Dispose of any entries which have expired before "now". 151 | */ 152 | static void process_timeouts (struct tcpreasm_ip *tcpreasm, tcpreasm_time_t now); 153 | 154 | /* 155 | * Create fragment structure from IPv6 packet. Returns NULL if the input 156 | * is not a fragment. 157 | * This function is called by parse_packet(), don't call it directly. 158 | */ 159 | #if USE_IPv6 160 | static struct tcpreasm_frag_entry *frag_from_ipv6 (unsigned char *packet, uint32_t *ip_id, bool *last_frag); 161 | #endif /* USE_IPv6 */ 162 | 163 | /* 164 | * Compare packet identification tuples for specified protocol. 165 | */ 166 | static bool tcpreasm_id_equal_tcp (enum tcpreasm_proto proto, const union tcpreasm_id *left, const union tcpreasm_id *right); 167 | 168 | 169 | static unsigned 170 | tcpreasm_ipv4_hash (const struct tcpreasm_id_ipv4 *id) 171 | { 172 | unsigned hash = 0; 173 | int i; 174 | 175 | for (i = 0; i < 4; i++) { 176 | hash = 37U * hash + id->ip_src[i]; 177 | hash = 37U * hash + id->ip_dst[i]; 178 | } 179 | 180 | hash = 59U * hash + id->ip_id; 181 | 182 | hash = 47U * hash + id->ip_proto; 183 | hash = 47U * hash + id->dport; 184 | hash = 47U * hash + id->sport; 185 | 186 | return hash; 187 | } 188 | 189 | 190 | #if USE_IPv6 191 | static unsigned 192 | tcpreasm_ipv6_hash (const struct tcpreasm_id_ipv6 *id) 193 | { 194 | unsigned hash = 0; 195 | int i; 196 | 197 | for (i = 0; i < 16; i++) { 198 | hash = 37U * hash + id->ip_src[i]; 199 | hash = 37U * hash + id->ip_dst[i]; 200 | } 201 | 202 | hash = 59U * hash + id->ip_id; 203 | hash = 47U * hash + id->dport; 204 | hash = 47U * hash + id->sport; 205 | return hash; 206 | } 207 | #endif /* USE_IPv6 */ 208 | 209 | 210 | unsigned char * 211 | tcpreasm_ip_next_tcp (struct tcpreasm_ip *tcpreasm, unsigned char *packet, unsigned len, tcpreasm_time_t timestamp, unsigned *output_len, struct in_addr *ip_src, struct in_addr *ip_dst, uint16_t sport, uint16_t dport, uint8_t psh) 212 | { 213 | enum tcpreasm_proto proto; 214 | union tcpreasm_id id; 215 | unsigned hash; 216 | bool last_frag; 217 | 218 | 219 | process_timeouts (tcpreasm, timestamp); 220 | 221 | struct tcpreasm_frag_entry *frag = NULL; 222 | frag = malloc (sizeof (*frag)); 223 | if (frag == NULL) 224 | return NULL; 225 | 226 | *frag = (struct tcpreasm_frag_entry) { 227 | .len = len, 228 | .offset = 10 * 8, 229 | .data_offset = len, 230 | .data = packet, 231 | }; 232 | 233 | proto = PROTO_IPV4; 234 | 235 | memcpy (id.ipv4.ip_src, ip_src, 4); 236 | memcpy (id.ipv4.ip_dst, ip_dst, 4); 237 | id.ipv4.ip_id = 200; 238 | id.ipv4.ip_proto = PROTO_IPV4; 239 | id.ipv4.sport = sport; 240 | id.ipv4.dport = dport; 241 | 242 | hash = tcpreasm_ipv4_hash (&id.ipv4); 243 | 244 | if(debug == 2) { 245 | 246 | printf("\nTCPREASM: Proto [%d], Hash:[%d] SPORT: [%d], DPORT: [%d]\n", proto, hash, sport, dport); 247 | } 248 | 249 | hash %= REASM_IP_HASH_SIZE; 250 | struct tcpreasm_ip_entry *entry = tcpreasm->table[hash]; 251 | 252 | while (entry != NULL && (!tcpreasm_id_equal_tcp (proto, &id, &entry->id))) 253 | entry = entry->next; 254 | 255 | /* no buffer, go out */ 256 | if(psh == 1 && entry == NULL) { 257 | free(frag); 258 | if(debug == 2) printf("RETURN PACKET BACK\n"); 259 | *output_len = len; 260 | return packet; 261 | } 262 | 263 | if (entry == NULL) { 264 | 265 | if(debug == 2) printf("EMPTY ENTRY\n"); 266 | 267 | entry = malloc (sizeof (*entry)); 268 | if (entry == NULL) { 269 | free (frag); 270 | return NULL; 271 | } 272 | 273 | struct tcpreasm_frag_entry *list_head = malloc (sizeof (*list_head)); 274 | if (list_head == NULL) { 275 | free (frag); 276 | free (entry); 277 | return NULL; 278 | } 279 | 280 | *entry = (struct tcpreasm_ip_entry) { 281 | .id = id, 282 | .len = 0, 283 | .holes = 1, 284 | .frags = list_head, 285 | .hash = hash, 286 | .protocol = proto, 287 | .mss = len, 288 | .timeout = timestamp + tcpreasm->timeout, 289 | .state = STATE_ACTIVE, 290 | .prev = NULL, 291 | .next = tcpreasm->table[hash], 292 | .time_prev = tcpreasm->time_last, 293 | .time_next = NULL, 294 | }; 295 | 296 | *list_head = (struct tcpreasm_frag_entry) { 297 | .len = 0, 298 | .offset = 0, 299 | .data_offset = 0, 300 | .data = NULL, 301 | }; 302 | 303 | if (entry->next != NULL) 304 | entry->next->prev = entry; 305 | tcpreasm->table[hash] = entry; 306 | 307 | if (tcpreasm->time_last != NULL) 308 | tcpreasm->time_last->time_next = entry; 309 | else 310 | tcpreasm->time_first = entry; 311 | tcpreasm->time_last = entry; 312 | 313 | tcpreasm->waiting++; 314 | if (tcpreasm->waiting > tcpreasm->max_waiting) 315 | tcpreasm->max_waiting = tcpreasm->waiting; 316 | } 317 | 318 | if (entry->state != STATE_ACTIVE) { 319 | tcpreasm->dropped_frags++; 320 | return NULL; 321 | } 322 | 323 | 324 | 325 | if (!add_fragment_tcp (entry, frag, last_frag)) { 326 | entry->state = STATE_INVALID; 327 | tcpreasm->dropped_frags += entry->frag_count + 1; 328 | return NULL; 329 | } 330 | 331 | if(psh == 0) return NULL; 332 | 333 | /* workaround for ACK/PSH big messages */ 334 | if(entry->mss == len) return NULL; 335 | 336 | unsigned char *r = assemble_tcp (entry, output_len); 337 | 338 | //printf("TCP REASSEM: [%d]\n", *output_len); 339 | //printf("MESSAGE: [%s]\n", r); 340 | 341 | drop_entry (tcpreasm, entry); 342 | return r; 343 | } 344 | 345 | 346 | static bool 347 | add_fragment_tcp (struct tcpreasm_ip_entry *entry, struct tcpreasm_frag_entry *frag, bool last_frag) 348 | { 349 | /* 350 | * When a fragment is inserted into the list, different cases can occur 351 | * concerning the number of holes. 352 | * - The new fragment can be inserted in the middle of a hole, such that 353 | * it will split the hole in two. The number of holes increases by 1. 354 | * - The new fragment can be attached to one end of a hole, such that 355 | * the rest of the hole remains at the opposite side of the fragment. 356 | * The number of holes remains constant. 357 | * - The new fragment can fill a hole completely. The number of holes 358 | * decreases by 1. 359 | */ 360 | 361 | struct tcpreasm_frag_entry *cur = entry->frags, *next = cur->next; 362 | 363 | entry->len+=frag->len; 364 | 365 | while (cur->next != NULL) cur = cur->next; 366 | next = cur->next; 367 | 368 | /* Fragment is to be inserted between cur and next; next may be NULL. */ 369 | 370 | if (frag->len != 0) { 371 | frag->next = cur->next; 372 | cur->next = frag; 373 | entry->frag_count++; 374 | } 375 | 376 | return true; 377 | } 378 | 379 | 380 | 381 | struct tcpreasm_ip * 382 | tcpreasm_ip_new (void) 383 | { 384 | struct tcpreasm_ip *tcpreasm = malloc (sizeof (*tcpreasm)); 385 | if (tcpreasm == NULL) 386 | return NULL; 387 | 388 | memset (tcpreasm, 0, sizeof (*tcpreasm)); 389 | return tcpreasm; 390 | } 391 | 392 | 393 | void 394 | tcpreasm_ip_free (struct tcpreasm_ip *tcpreasm) 395 | { 396 | while (tcpreasm->time_first != NULL) 397 | drop_entry (tcpreasm, tcpreasm->time_first); 398 | free (tcpreasm); 399 | } 400 | 401 | 402 | static bool 403 | is_complete (struct tcpreasm_ip_entry *entry) 404 | { 405 | return entry->holes == 0; 406 | } 407 | 408 | 409 | static unsigned char * 410 | assemble_tcp (struct tcpreasm_ip_entry *entry, unsigned *output_len) 411 | { 412 | struct tcpreasm_frag_entry *frag = entry->frags->next; /* skip list head */ 413 | unsigned offset0 = frag->data_offset; 414 | unsigned char *p = malloc (entry->len + offset0); 415 | unsigned tlen = 0; 416 | 417 | //printf("TOTAL LEN: %d\n", entry->len); 418 | 419 | if (p == NULL) 420 | return NULL; 421 | 422 | switch (entry->protocol) { 423 | case PROTO_IPV4: 424 | break; 425 | 426 | #if USE_IPv6 427 | case PROTO_IPV6: 428 | offset0 -= 8; /* size of frag header */ 429 | break; 430 | #endif /* USE_IPv6 */ 431 | 432 | default: 433 | break; 434 | } 435 | 436 | *output_len = entry->len; 437 | 438 | /* join all the payload fragments together */ 439 | while (frag != NULL) { 440 | memcpy (p + tlen, frag->data, frag->len); 441 | tlen += frag->len; 442 | frag = frag->next; 443 | } 444 | 445 | return p; 446 | } 447 | 448 | 449 | static void 450 | drop_entry (struct tcpreasm_ip *tcpreasm, struct tcpreasm_ip_entry *entry) 451 | { 452 | if (entry->prev != NULL) 453 | entry->prev->next = entry->next; 454 | else 455 | tcpreasm->table[entry->hash] = entry->next; 456 | 457 | if (entry->next != NULL) 458 | entry->next->prev = entry->prev; 459 | 460 | if (entry->time_prev != NULL) 461 | entry->time_prev->time_next = entry->time_next; 462 | else 463 | tcpreasm->time_first = entry->time_next; 464 | 465 | if (entry->time_next != NULL) 466 | entry->time_next->time_prev = entry->time_prev; 467 | else 468 | tcpreasm->time_last = entry->time_prev; 469 | 470 | tcpreasm->waiting--; 471 | 472 | free_entry (entry); 473 | } 474 | 475 | 476 | static void 477 | free_entry (struct tcpreasm_ip_entry *entry) 478 | { 479 | struct tcpreasm_frag_entry *frag = entry->frags, *next; 480 | while (frag != NULL) { 481 | next = frag->next; 482 | if (frag->data != NULL) 483 | free (frag->data); 484 | free (frag); 485 | frag = next; 486 | } 487 | 488 | free (entry); 489 | } 490 | 491 | 492 | unsigned 493 | tcpreasm_ip_waiting (const struct tcpreasm_ip *tcpreasm) 494 | { 495 | return tcpreasm->waiting; 496 | } 497 | 498 | 499 | unsigned 500 | tcpreasm_ip_max_waiting (const struct tcpreasm_ip *tcpreasm) 501 | { 502 | return tcpreasm->max_waiting; 503 | } 504 | 505 | 506 | unsigned 507 | tcpreasm_ip_timed_out (const struct tcpreasm_ip *tcpreasm) 508 | { 509 | return tcpreasm->timed_out; 510 | } 511 | 512 | 513 | unsigned 514 | tcpreasm_ip_dropped_frags (const struct tcpreasm_ip *tcpreasm) 515 | { 516 | return tcpreasm->dropped_frags; 517 | } 518 | 519 | 520 | bool 521 | tcpreasm_ip_set_timeout (struct tcpreasm_ip *tcpreasm, tcpreasm_time_t timeout) 522 | { 523 | if (tcpreasm->time_first != NULL) 524 | return false; 525 | 526 | tcpreasm->timeout = timeout; 527 | return true; 528 | } 529 | 530 | 531 | static void 532 | process_timeouts (struct tcpreasm_ip *tcpreasm, tcpreasm_time_t now) 533 | { 534 | while (tcpreasm->time_first != NULL && tcpreasm->time_first->timeout < now) { 535 | tcpreasm->timed_out++; 536 | drop_entry (tcpreasm, tcpreasm->time_first); 537 | } 538 | } 539 | 540 | 541 | #if USE_IPv6 542 | static struct tcpreasm_frag_entry * 543 | frag_from_ipv6 (unsigned char *packet, uint32_t *ip_id, bool *last_frag) 544 | { 545 | struct ip6_hdr *ip6_header = (struct ip6_hdr *) packet; 546 | unsigned offset = 40; /* IPv6 header size */ 547 | uint8_t nxt = ip6_header->ip6_nxt; 548 | unsigned total_len = 40 + ntohs (ip6_header->ip6_plen); 549 | unsigned last_nxt = offsetof (struct ip6_hdr, ip6_nxt); 550 | 551 | /* 552 | * IPv6 extension headers from RFC 2460: 553 | * 0 Hop-by-Hop Options 554 | * 43 Routing 555 | * 44 Fragment 556 | * 60 Destination Options 557 | * 558 | * We look out for the Fragment header; the other 3 header 559 | * types listed above are recognized and considered safe to 560 | * skip over if they occur before the Fragment header. 561 | * Any unrecognized header will cause processing to stop and 562 | * a subsequent Fragment header to stay unrecognized. 563 | */ 564 | while (nxt == IPPROTO_HOPOPTS || nxt == IPPROTO_ROUTING || nxt == IPPROTO_DSTOPTS) { 565 | if (offset + 2 > total_len) 566 | return NULL; /* header extends past end of packet */ 567 | 568 | unsigned exthdr_len = 8 + 8 * packet[offset + 1]; 569 | if (offset + exthdr_len > total_len) 570 | return NULL; /* header extends past end of packet */ 571 | 572 | nxt = packet[offset]; 573 | last_nxt = offset; 574 | offset += exthdr_len; 575 | } 576 | 577 | if (nxt != IPPROTO_FRAGMENT) 578 | return NULL; 579 | 580 | if (offset + 8 > total_len) 581 | return NULL; /* Fragment header extends past end of packet */ 582 | 583 | struct tcpreasm_frag_entry *frag = malloc (sizeof (*frag)); 584 | if (frag == NULL) 585 | return NULL; 586 | 587 | struct ip6_frag *frag_header = (struct ip6_frag *) (packet + offset); 588 | offset += 8; 589 | 590 | /* 591 | * The Fragment header will be removed on reassembly, so we have to 592 | * replace the Next Header field of the previous header (which is 593 | * currently IPPROTO_FRAGMENT), with the Next Header field of the 594 | * Fragment header. 595 | * 596 | * XXX We really shouldn't manipulate the input packet in-place. 597 | */ 598 | packet[last_nxt] = frag_header->ip6f_nxt; 599 | 600 | *frag = (struct tcpreasm_frag_entry) { 601 | .len = total_len - offset, 602 | .data_offset = offset, 603 | .offset = ntohs (frag_header->ip6f_offlg & IP6F_OFF_MASK), 604 | .data = packet, 605 | }; 606 | 607 | *ip_id = ntohl (frag_header->ip6f_ident); 608 | *last_frag = (frag_header->ip6f_offlg & IP6F_MORE_FRAG) == 0; 609 | 610 | return frag; 611 | } 612 | #endif /* USE_IPv6 */ 613 | 614 | 615 | static bool 616 | tcpreasm_id_equal_tcp (enum tcpreasm_proto proto, const union tcpreasm_id *left, const union tcpreasm_id *right) 617 | { 618 | switch (proto) { 619 | case PROTO_IPV4: 620 | return memcmp (left->ipv4.ip_src, right->ipv4.ip_src, 4) == 0 621 | && memcmp (left->ipv4.ip_dst, right->ipv4.ip_dst, 4) == 0 622 | && left->ipv4.ip_id == right->ipv4.ip_id 623 | && left->ipv4.sport == right->ipv4.sport 624 | && left->ipv4.dport == right->ipv4.dport 625 | && left->ipv4.ip_proto == right->ipv4.ip_proto; 626 | #if USE_IPv6 627 | case PROTO_IPV6: 628 | return memcmp (left->ipv6.ip_src, right->ipv6.ip_src, 16) == 0 629 | && memcmp (left->ipv6.ip_dst, right->ipv6.ip_dst, 16) == 0 630 | && left->ipv6.sport == right->ipv6.sport 631 | && left->ipv6.dport == right->ipv6.dport 632 | && left->ipv6.ip_id == right->ipv6.ip_id; 633 | #endif /* USE_IPv6 */ 634 | default: 635 | return memcmp (left->ipv4.ip_src, right->ipv4.ip_src, 4) == 0 636 | && memcmp (left->ipv4.ip_dst, right->ipv4.ip_dst, 4) == 0 637 | && left->ipv4.ip_id == right->ipv4.ip_id 638 | && left->ipv4.sport == right->ipv4.sport 639 | && left->ipv4.dport == right->ipv4.dport 640 | && left->ipv4.ip_proto == right->ipv4.ip_proto; 641 | } 642 | } 643 | 644 | -------------------------------------------------------------------------------- /src/transport_hep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sipgrep - Monitoring tools 3 | * 4 | * Author: Alexandr Dubovikov 5 | * (C) Homer Project 2014-16 (http://www.sipcapture.org) 6 | * 7 | * Sipgrep is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version 11 | * 12 | * Sipgrep is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | * 21 | */ 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "include/core_hep.h" 33 | #include "include/transport_hep.h" 34 | 35 | int hep_version = 3; 36 | int usessl = 0; 37 | int pl_compress = 0; 38 | /* homer socket */ 39 | int homer_sock = 0; 40 | 41 | int send_hepv3 (rc_info_t * rcinfo, unsigned char *data, unsigned int len) 42 | { 43 | 44 | struct hep_generic *hg = NULL; 45 | void *buffer; 46 | unsigned int buflen = 0, iplen = 0, tlen = 0; 47 | hep_chunk_ip4_t src_ip4, dst_ip4; 48 | #ifdef USE_IPV6 49 | hep_chunk_ip6_t src_ip6, dst_ip6; 50 | #endif 51 | hep_chunk_t payload_chunk; 52 | hep_chunk_t authkey_chunk; 53 | //static int errors = 0; 54 | char *capt_password = NULL; 55 | 56 | hg = malloc (sizeof (struct hep_generic)); 57 | memset (hg, 0, sizeof (struct hep_generic)); 58 | 59 | /* header set */ 60 | memcpy (hg->header.id, "\x48\x45\x50\x33", 4); 61 | 62 | /* IP proto */ 63 | hg->ip_family.chunk.vendor_id = htons (0x0000); 64 | hg->ip_family.chunk.type_id = htons (0x0001); 65 | hg->ip_family.data = rcinfo->ip_family; 66 | hg->ip_family.chunk.length = htons (sizeof (hg->ip_family)); 67 | 68 | /* Proto ID */ 69 | hg->ip_proto.chunk.vendor_id = htons (0x0000); 70 | hg->ip_proto.chunk.type_id = htons (0x0002); 71 | hg->ip_proto.data = rcinfo->ip_proto; 72 | hg->ip_proto.chunk.length = htons (sizeof (hg->ip_proto)); 73 | 74 | 75 | /* IPv4 */ 76 | if (rcinfo->ip_family == AF_INET) { 77 | /* SRC IP */ 78 | src_ip4.chunk.vendor_id = htons (0x0000); 79 | src_ip4.chunk.type_id = htons (0x0003); 80 | inet_pton (AF_INET, rcinfo->src_ip, &src_ip4.data); 81 | src_ip4.chunk.length = htons (sizeof (src_ip4)); 82 | 83 | /* DST IP */ 84 | dst_ip4.chunk.vendor_id = htons (0x0000); 85 | dst_ip4.chunk.type_id = htons (0x0004); 86 | inet_pton (AF_INET, rcinfo->dst_ip, &dst_ip4.data); 87 | dst_ip4.chunk.length = htons (sizeof (dst_ip4)); 88 | 89 | iplen = sizeof (dst_ip4) + sizeof (src_ip4); 90 | } 91 | #ifdef USE_IPV6 92 | /* IPv6 */ 93 | else if (rcinfo->ip_family == AF_INET6) { 94 | /* SRC IPv6 */ 95 | src_ip6.chunk.vendor_id = htons (0x0000); 96 | src_ip6.chunk.type_id = htons (0x0005); 97 | inet_pton (AF_INET6, rcinfo->src_ip, &src_ip6.data); 98 | src_ip6.chunk.length = htons (sizeof (src_ip6)); 99 | 100 | /* DST IPv6 */ 101 | dst_ip6.chunk.vendor_id = htons (0x0000); 102 | dst_ip6.chunk.type_id = htons (0x0006); 103 | inet_pton (AF_INET6, rcinfo->dst_ip, &dst_ip6.data); 104 | dst_ip6.chunk.length = htons (sizeof (dst_ip6)); 105 | 106 | iplen = sizeof (dst_ip6) + sizeof (src_ip6); 107 | } 108 | #endif 109 | 110 | /* SRC PORT */ 111 | hg->src_port.chunk.vendor_id = htons (0x0000); 112 | hg->src_port.chunk.type_id = htons (0x0007); 113 | hg->src_port.data = htons (rcinfo->src_port); 114 | hg->src_port.chunk.length = htons (sizeof (hg->src_port)); 115 | 116 | /* DST PORT */ 117 | hg->dst_port.chunk.vendor_id = htons (0x0000); 118 | hg->dst_port.chunk.type_id = htons (0x0008); 119 | hg->dst_port.data = htons (rcinfo->dst_port); 120 | hg->dst_port.chunk.length = htons (sizeof (hg->dst_port)); 121 | 122 | 123 | /* TIMESTAMP SEC */ 124 | hg->time_sec.chunk.vendor_id = htons (0x0000); 125 | hg->time_sec.chunk.type_id = htons (0x0009); 126 | hg->time_sec.data = htonl (rcinfo->time_sec); 127 | hg->time_sec.chunk.length = htons (sizeof (hg->time_sec)); 128 | 129 | 130 | /* TIMESTAMP USEC */ 131 | hg->time_usec.chunk.vendor_id = htons (0x0000); 132 | hg->time_usec.chunk.type_id = htons (0x000a); 133 | hg->time_usec.data = htonl (rcinfo->time_usec); 134 | hg->time_usec.chunk.length = htons (sizeof (hg->time_usec)); 135 | 136 | /* Protocol TYPE */ 137 | hg->proto_t.chunk.vendor_id = htons (0x0000); 138 | hg->proto_t.chunk.type_id = htons (0x000b); 139 | hg->proto_t.data = rcinfo->proto_type; 140 | hg->proto_t.chunk.length = htons (sizeof (hg->proto_t)); 141 | 142 | /* Capture ID */ 143 | hg->capt_id.chunk.vendor_id = htons (0x0000); 144 | hg->capt_id.chunk.type_id = htons (0x000c); 145 | hg->capt_id.data = htons (101); 146 | hg->capt_id.chunk.length = htons (sizeof (hg->capt_id)); 147 | 148 | /* Payload */ 149 | payload_chunk.vendor_id = htons (0x0000); 150 | payload_chunk.type_id = htons (0x000f); 151 | payload_chunk.length = htons (sizeof (payload_chunk) + len); 152 | 153 | tlen = sizeof (struct hep_generic) + len + iplen + sizeof (hep_chunk_t); 154 | 155 | /* auth key */ 156 | if (capt_password != NULL) { 157 | 158 | tlen += sizeof (hep_chunk_t); 159 | /* Auth key */ 160 | authkey_chunk.vendor_id = htons (0x0000); 161 | authkey_chunk.type_id = htons (0x000e); 162 | authkey_chunk.length = htons (sizeof (authkey_chunk) + strlen (capt_password)); 163 | tlen += strlen (capt_password); 164 | } 165 | 166 | /* total */ 167 | hg->header.length = htons (tlen); 168 | 169 | buffer = (void *) malloc (tlen); 170 | if (buffer == 0) { 171 | fprintf (stderr, "ERROR: out of memory\n"); 172 | free (hg); 173 | return 1; 174 | } 175 | 176 | memcpy ((void *) buffer, hg, sizeof (struct hep_generic)); 177 | buflen = sizeof (struct hep_generic); 178 | 179 | /* IPv4 */ 180 | if (rcinfo->ip_family == AF_INET) { 181 | /* SRC IP */ 182 | memcpy ((void *) buffer + buflen, &src_ip4, sizeof (struct hep_chunk_ip4)); 183 | buflen += sizeof (struct hep_chunk_ip4); 184 | 185 | memcpy ((void *) buffer + buflen, &dst_ip4, sizeof (struct hep_chunk_ip4)); 186 | buflen += sizeof (struct hep_chunk_ip4); 187 | } 188 | #ifdef USE_IPV6 189 | /* IPv6 */ 190 | else if (rcinfo->ip_family == AF_INET6) { 191 | /* SRC IPv6 */ 192 | memcpy ((void *) buffer + buflen, &src_ip4, sizeof (struct hep_chunk_ip6)); 193 | buflen += sizeof (struct hep_chunk_ip6); 194 | 195 | memcpy ((void *) buffer + buflen, &dst_ip6, sizeof (struct hep_chunk_ip6)); 196 | buflen += sizeof (struct hep_chunk_ip6); 197 | } 198 | #endif 199 | 200 | /* AUTH KEY CHUNK */ 201 | if (capt_password != NULL) { 202 | 203 | memcpy ((void *) buffer + buflen, &authkey_chunk, sizeof (struct hep_chunk)); 204 | buflen += sizeof (struct hep_chunk); 205 | 206 | /* Now copying payload self */ 207 | memcpy ((void *) buffer + buflen, capt_password, strlen (capt_password)); 208 | buflen += strlen (capt_password); 209 | } 210 | 211 | /* PAYLOAD CHUNK */ 212 | memcpy ((void *) buffer + buflen, &payload_chunk, sizeof (struct hep_chunk)); 213 | buflen += sizeof (struct hep_chunk); 214 | 215 | /* Now copying payload self */ 216 | memcpy ((void *) buffer + buflen, data, len); 217 | buflen += len; 218 | 219 | /* send this packet out of our socket */ 220 | if (send (homer_sock, buffer, buflen, 0) == -1) { 221 | printf ("send error\n"); 222 | } 223 | 224 | /* FREE */ 225 | if (buffer) 226 | free (buffer); 227 | if (hg) 228 | free (hg); 229 | 230 | return 1; 231 | } 232 | 233 | int make_homer_socket (char *url) 234 | { 235 | 236 | char *ip, *tmp; 237 | char port[20]; 238 | struct addrinfo *ai, hints[1] = { {0} }; 239 | int i; 240 | 241 | ip = strchr (url, ':'); 242 | if (ip != NULL) { 243 | ip++; 244 | tmp = strchr (ip, ':'); 245 | if (tmp != NULL) { 246 | i = (tmp - ip); 247 | tmp++; 248 | snprintf (port, 20, "%s", tmp); 249 | ip[i] = '\0'; 250 | } 251 | else 252 | return 2; 253 | } 254 | else 255 | return 2; 256 | 257 | hints->ai_flags = AI_NUMERICSERV; 258 | hints->ai_family = AF_UNSPEC; 259 | hints->ai_socktype = SOCK_DGRAM; 260 | hints->ai_protocol = IPPROTO_UDP; 261 | 262 | if (getaddrinfo (ip, port, hints, &ai)) { 263 | fprintf (stderr, "capture: getaddrinfo() error"); 264 | return 2; 265 | } 266 | 267 | homer_sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol); 268 | if (homer_sock < 0) { 269 | fprintf (stderr, "Sender socket creation failed: %s\n", strerror (errno)); 270 | return 3; 271 | } 272 | 273 | if (connect (homer_sock, ai->ai_addr, (socklen_t) (ai->ai_addrlen)) == -1) { 274 | if (errno != EINPROGRESS) { 275 | fprintf (stderr, "Sender socket creation failed: %s\n", strerror (errno)); 276 | return 4; 277 | } 278 | } 279 | return 0; 280 | } 281 | 282 | 283 | 284 | -------------------------------------------------------------------------------- /src/user_interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sipgrep - Monitoring tools 3 | * 4 | * Author: Alexandr Dubovikov 5 | * (C) Homer Project 2014-16 (http://www.sipcapture.org) 6 | * 7 | * Sipgrep is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version 11 | * 12 | * Sipgrep is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | * 21 | */ 22 | 23 | #include "include/user_interface.h" 24 | 25 | int show_userinterface (void) 26 | { 27 | 28 | return 1; 29 | } 30 | 31 | 32 | 33 | --------------------------------------------------------------------------------