Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A portable framework for low-level network packet construction

License

NotificationsYou must be signed in to change notification settings

libnet/libnet

Repository files navigation

1b2b3bCodeDocs Status

Packet Construction and Injection

Libnet is an API to help with the construction and injection of networkpackets. It provides a portable framework for low-level network packetwriting and handling (use libnet in conjunction with libpcap and you canwrite some really cool stuff). Libnet includes packet creation at theIP layer and at the link layer as well as a host of supplementary andcomplementary functionality.

Libnet is very handy with which to write network tools and network testcode. Some projects, available in Debian/Ubuntu and OpenBSD, usinglibnet are:

NOTE: Legacy code written forlibnet-1.0.x is unfortunatelyincompatible withlibnet-1.1.x and later.
See theMigration Guide for porting help.

Using -lnet

Libnet is installed as a library and a set of include files. The maininclude file to use in your program is:

#include <libnet.h>

To get the correct search paths to both the header and library files,use the standardpkg-config tool (oldlibnet-config is deprecated):

$ pkg-config --libs --static --cflags libnet-I/usr/local/include -L/usr/local/lib -lnet

The prefix path/usr/local/ shown here is only the default. Use theconfigure script to select a different prefix when installing libnet.

For GNU autotools based projects, use the following inconfigure.ac:

# Check for required librariesPKG_CHECK_MODULES([libnet], [libnet >= 1.2])

and in yourMakefile.am:

proggy_CFLAGS = $(libnet_CFLAGS)proggy_LDADD  = $(libnet_LIBS)

Online docs available athttps://codedocs.xyz/libnet/libnet/. Seethe man page andsample test code for more information.

Building

First download thelatest release from GitHub. Libnet employs theGNU configure and build system. The release tarballs andzip files ship with a pre-builtconfigure script:

$ tar xf libnet-x.y.z.tar.gz$ cd libnet-x.y.z/$ ./configure && make$ sudo make install

To list available options, type./configure --help

Building from GIT/GitHub

When building from GIT, use./autogen.sh to generate theconfigure script. For this you need the full suite of the GNUautotools: autoconf (>=2.69), automake (>=1.14), libtool (>=2.4.2).

How to install the dependencies varies by system, but on many Debian derivedsystems,apt can be used:

$ sudo apt install autoconf automake libtool$ ./autogen.sh$ ./configure && make$ sudo make install

Using Conan

Libnet is available onConan Center. To use,addlibnet/1.2 to yourconanfile.txt

Building with Docker

First build the dev. contrainer:

$ cd .devcontainer$ docker build -t libnet-builder .

Then compile libnet with docker:

$ cd ..$ docker run -it --rm -v $(pwd):$(pwd) --workdir=$(pwd) libnet-builder$ ./autogen.sh                 # If you've cloned from GitHub$ ./configure$ make

Building with MSYS2

First install all the dependencies we need including the Npcap SDK.

Type in your MSYS2 terminal to install the dependencies:

pacman -S autoconf automake libtool unzip

Download the Npcap SDK and unzips it as anpcap directory to easily add it to theconfigure command:

wget https://npcap.com/dist/npcap-sdk-1.13.zip&& unzip npcap-sdk-1.13.zip -d npcap

Download the libnet from it'slatest release, unpack it and then generate a Makefiles:

cd libnet-x.y&& ./autogen.sh
CFLAGS="-I${HOME}/npcap/Include -Wno-incompatible-pointer-types" LDFLAGS="-L${HOME}/npcap/Lib/x64" ./configure --prefix=/ucrt64

Note

This is currently using a UCRT64 environment.

Build and then install:

make&& make install

Building Done. You can verify it's installation:

pkg-config --libs --cflags libnet

Running Unit Tests with CMocka

Running tests in the dev. container (above):

$ ./autogen.sh                 # If you've cloned from GitHub$ ./configure --enable-tests$ make checkmake  check-TESTSPASS: udld 1 - libnet_udld__checksum_calculationPASS: udld 2 - libnet_build_udld__pdu_header_onlyPASS: udld 3 - libnet_build_udld__tlv_device_idPASS: udld 4 - libnet_build_udld__tlv_port_idPASS: udld 5 - libnet_build_udld__tlv_echoPASS: udld 6 - libnet_build_udld__tlv_message_intervalPASS: udld 7 - libnet_build_udld__tlv_timeout_intervalPASS: udld 8 - libnet_build_udld__tlv_device_namePASS: udld 9 - libnet_build_udld__tlv_sequence_numberPASS: udld 10 - libnet_build_udld__build_whole_packet_with_checksumPASS: ethernet 1 - test_libnet_build_ethernet============================================================================Testsuite summary for libnet 1.3============================================================================# TOTAL: 11# PASS:  11# SKIP:  0# XFAIL: 0# FAIL:  0# XPASS: 0# ERROR: 0============================================================================

Note: on Linux the tests run in a separate network namespace(usingunshare), so no root (sudo) access is needed, but on othersystems you may need to to be root, or have to correct capabilitiesor permissions.

Building the Documentation

To build the documentation (optional) you need doxygen and pod2man:

$ sudo apt install doxygen$ sudo apt install pod2man || sudo apt install perl

For neat graphics in the HTML documentation, also install graphviz.There is also a PDF version of the docs, to build that you need quite afew more packages:

$ sudo apt install texlive-extra-utils texlive-latex-extra \                   texlive-fonts-recommended latex-xcolor  \                   texlive-font-utils

For Microsoft CHM docs you need the HTML Help Workshop, which is partof Visual Studio:http://go.microsoft.com/fwlink/p/?linkid=154968, onUNIX and GNU/Linux systems, seechmcmd, which is available in theFreePascal suite:

$ sudo apt install fp-utils-3.0.4

Origin & References

Libnet is widely used, but had been unmaintained for a long time and itsauthor unreachable. This version was forked from the 1.1.3 releasecandidate frompacketfactory.net, bug fixed, developed, andre-released.

Use GitHub issues and pull request feature for questions and patches:

http://github.com/libnet/libnet

Some old docs are available at:

http://packetfactory.openwall.net/projects/libnet/index.html




[8]ページ先頭

©2009-2025 Movatter.jp