summaryrefslogtreecommitdiff
path: root/README.md
blob: b4696b341847b9c2377b8f6346a2e954c5c373d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
[![Appveyor Status][]][Appveyor] [![GitHub Status][]][GitHub] [![CodeDocs Status][]][CodeDocs] <img align="right" src="doc/libnet.gif">

Packet Construction and Injection
=================================

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

Libnet is very handy with which to write network tools and network test
code.  Some projects, available in Debian/Ubuntu and OpenBSD, using
libnet are:

- [arping](https://github.com/ThomasHabets/arping)
- [ettercap](https://www.ettercap-project.org/)
- [ipguard](http://ipguard.deep.perm.ru/)
- [isic](http://isic.sourceforge.net/)
- [nemesis](https://github.com/libnet/nemesis/)
- [packit](http://packetfactory.openwall.net/projects/packit/)
- [tcptraceroute](https://web.archive.org/web/20130424094134/http://michael.toren.net/code/tcptraceroute/)
- [yersinia](https://web.archive.org/web/20180522141004/http://www.yersinia.net/)

See the man page and sample test code for more detailed information.
Online documentation is available at https://codedocs.xyz/libnet/libnet/

> **NOTE:** Legacy code written for *libnet-1.0.x* is unfortunately
>           **incompatible** with *libnet-1.1.x* and later.  
>           See the [Migration Guide](doc/MIGRATION.md) for porting help.


Building
--------

First download the [latest release][] from GitHub.  Libnet employs the
[GNU configure and build system][autotools].  The release tarballs and
zip files ship with a pre-built `configure` script:

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

To list available options, type <kbd>./configure --help</kbd>

### Building from GIT/GitHub

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

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

    sudo apt install autoconf automake libtool

### Using Conan

Libnet now is available on [Conan Center](https://conan.io/center/libnet).  
Please add `libnet/1.2` to your `conanfile.txt`  

### Building with Docker
```bash
# Build image
cd .devcontainer
docker build -t libnet-builder .

# Compile libnet with docker
cd ..
docker run -it --rm -v $(pwd):$(pwd) --workdir=$(pwd) libnet-builder

./autogen.sh
./configure
make
```

### Running Unit Tests with CMocka
```bash
# Running tests in the building Docker ^

./autogen.sh
./configure --enable-tests
make
sudo ./tests/libnet_unit_tests

# Approximate output:
builder$ ./tests/libnet_unit_tests
[==========] Running 1 test(s).
[ RUN      ] test_libnet_build_ethernet
[       OK ] test_libnet_build_ethernet
[==========] 1 test(s) run.
[  PASSED  ] 1 test(s).
builder$
```

### 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 a
few 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 part
of Visual Studio: http://go.microsoft.com/fwlink/p/?linkid=154968, on
UNIX and GNU/Linux systems, see `chmcmd`, which is available in the
[FreePascal](http://www.freepascal.org/) suite:

    sudo apt install fp-utils-3.0.4


Using -lnet
-----------

Libnet is installed as a library and a set of include files.  The main
include 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 standard `pkg-config` tool:

    $ 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 the
`configure` script to select a different prefix when installing libnet.

For GNU autotools based projects, use the following in `configure.ac`:

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

and in your `Makefile.am`:

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


Origin & References
-------------------

Libnet is widely used, but had been unmaintained for a long time and its
author unreachable.  This version was forked from the 1.1.3 release
candidate from [packetfactory.net][origin], bug fixed, developed, and
re-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

-------------------------------------------------------------------------
- v1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>  
  http://www.packetfactory.net/libnet
- v1.1.3 and later (c) 2009 - 2013 Sam Roberts <vieuxtech@gmail.com>  
  http://github.com/libnet/libnet
-------------------------------------------------------------------------

[latest release]:  https://github.com/libnet/libnet/releases
[autotools]:       https://autotools.io/
[origin]:          http://packetfactory.openwall.net/projects/libnet/
[Appveyor]:        https://ci.appveyor.com/project/troglobit/libnet
[Appveyor Status]: https://ci.appveyor.com/api/projects/status/fkw05hw8cysfl2p1?svg=true
[GitHub]:          https://github.com/libnet/libnet/actions/workflows/build.yml/
[GitHub Status]:   https://github.com/libnet/libnet/actions/workflows/build.yml/badge.svg
[CodeDocs]:        https://codedocs.xyz/libnet/libnet/
[CodeDocs Status]: https://codedocs.xyz/libnet/libnet.svg