Skip to content

2. Compilation And Installation Instructions

Chema García edited this page Dec 22, 2015 · 3 revisions

Dependencies

To successfully compile libntoh you need the following packages:

  • gcc
  • make
  • cmake
  • pkg-config
  • libpthread-dev

Debian-like OS:

$ sudo apt-get install cmake libpthread-dev gcc make build-essential pkg-config

If you want to generate the source code documentation, you will also need doxygen:

$ sudo apt-get install doxygen

Note: pkg-config isn't really needed but it helps. (See "ntohexample" compilation)


Libntoh compilation and installation instructions

Once you have downloaded the source code, go into "libntoh" directory and type the following commands to manually compile the library:

$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

The above commands will install libntoh under "/usr/local" prefix. If you want it to be installed in a different prefix (like /usr), you can do it by defining CMAKE_INSTALL_PREFIX when calling to cmake:

$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr

There is also a script to help you to compile the library:

$ cd libntoh/src
../src$ ./build.sh
[i] pkg-config found: /usr/bin/pkg-config
[i] cmake found: /usr/bin/cmake
[i] make found: /usr/bin/make
[i] PKG_CONFIG_PATH set to: /usr/local/lib/pkgconfig

-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/libntoh/src/build
Scanning dependencies of target ntoh
[ 16%] Building C object CMakeFiles/ntoh.dir/libntoh.c.o
[ 33%] Building C object CMakeFiles/ntoh.dir/tcpreassembly.c.o
[ 50%] Building C object CMakeFiles/ntoh.dir/ipv4defrag.c.o
[ 66%] Building C object CMakeFiles/ntoh.dir/ipv6defrag.c.o
[ 83%] Building C object CMakeFiles/ntoh.dir/common.c.o
[100%] Building C object CMakeFiles/ntoh.dir/sfhash.c.o
Linking C shared library libntoh.so
[100%] Built target ntoh
Do you want to perform the installation? [y/n]: y
[sudo] password for chema: 
[100%] Built target ntoh
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libntoh.so
-- Installing: /usr/local/include/libntoh/libntoh.h
-- Installing: /usr/local/include/libntoh/tcpreassembly.h
-- Installing: /usr/local/include/libntoh/sfhash.h
-- Installing: /usr/local/include/libntoh/ipv4defrag.h
-- Installing: /usr/local/include/libntoh/ipv6defrag.h
-- Installing: /usr/local/include/libntoh/common.h
-- Installing: /usr/local/lib/pkgconfig/ntoh.pc
$

Libntoh Examples

You can find a working source code example for each supported protocol in "examples" folder:

libntoh$ ls examples/ -R
examples/:
c

examples/c:
ipv4  ipv6  tcp_ipv4  tcp_ipv6

examples/c/ipv4:
build.sh  CMakeLists.txt  example.c

examples/c/ipv6:
build.sh  CMakeLists.txt  example.c

examples/c/tcp_ipv4:
build.sh  CMakeLists.txt  example.c

examples/c/tcp_ipv6:
build.sh  CMakeLists.txt  example.c

The default installation prefix for libntoh is "/usr/local", so if you plan to link against libntoh using pkg-config remember to add "/usr/local/lib/pkgconfig" to PKG_CONFIG_PATH:

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
$ pkg-config --libs --cflags ntoh -I/usr/local/include/libntoh  -L/usr/local/lib -lntoh

On the other hand you can change the installation prefix by defining CMAKE_INSTALL_PREFIX:

$ cmake ../ -DCMAKE_INSTALL_PREFIX=/usr

So the new installation prefix will be "/usr"

For more information, refer to the wiki page.

TCP/IPv4 Example Output:

$ sudo ./ntohexample 
###########################
#     libntoh Example     #
# ----------------------- #
# Written by Chema Garcia #
# ----------------------- #
#  http://safetybits.net  #
#   [email protected]  #
###########################

[i] libntoh version: 0.4a

[+] Usage: ./ntohexample <options>

+ Options:
	  -i | --iface <val> -----> Interface to read packets from
	  -f | --file <val> ------> File path to read packets from
 	  -F | --filter <val> ----> Capture filter (default: "ip and tcp")
	  -c | --client ----------> Receive client data only
	  -s | --server ----------> Receive server data only

$

Clone this wiki locally