mirror of
https://github.com/mfontanini/libtins
synced 2026-01-26 12:01:34 +01:00
Compare commits
451 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67c81199fb | ||
|
|
fe22186623 | ||
|
|
bbac2ece52 | ||
|
|
ba9a2155ca | ||
|
|
00619e0500 | ||
|
|
64da67ca56 | ||
|
|
3943700830 | ||
|
|
142b6f62cb | ||
|
|
dfd2701ee4 | ||
|
|
850bb9b642 | ||
|
|
b7e61f4c76 | ||
|
|
e2a14d8898 | ||
|
|
ba0c820852 | ||
|
|
df509e7e36 | ||
|
|
fa87e1b6f6 | ||
|
|
812be7966d | ||
|
|
f89cc9f076 | ||
|
|
638bf9b34b | ||
|
|
eb997f5438 | ||
|
|
18cbab4fc7 | ||
|
|
7cd2b2c396 | ||
|
|
2601493752 | ||
|
|
7204fbd688 | ||
|
|
c302e659d7 | ||
|
|
54e4e4b0f4 | ||
|
|
6a17e59032 | ||
|
|
e3aedc56ed | ||
|
|
3b006c15db | ||
|
|
177d0b4621 | ||
|
|
24ac038c30 | ||
|
|
a619e4ff98 | ||
|
|
14bb185d7a | ||
|
|
137b56d5a7 | ||
|
|
ed2b3c12d5 | ||
|
|
1650b60234 | ||
|
|
c20c82bcb5 | ||
|
|
5858132261 | ||
|
|
16f5795243 | ||
|
|
e90e377b73 | ||
|
|
222611b377 | ||
|
|
b447c664e1 | ||
|
|
468159e6d2 | ||
|
|
cd40b232e7 | ||
|
|
1166094a2f | ||
|
|
b3d874d6a8 | ||
|
|
553b1fb255 | ||
|
|
94939dd0fa | ||
|
|
0774a8dcad | ||
|
|
f46dee9f19 | ||
|
|
5b082a82b2 | ||
|
|
07012648fb | ||
|
|
ce409dbc7e | ||
|
|
16e77146ab | ||
|
|
a87c4a64f5 | ||
|
|
9e61286a59 | ||
|
|
8da102fb48 | ||
|
|
750c3556d9 | ||
|
|
28663b0e93 | ||
|
|
731e36e373 | ||
|
|
608b48f25c | ||
|
|
de247fcbc8 | ||
|
|
7bc4d38470 | ||
|
|
a926b75224 | ||
|
|
064439236c | ||
|
|
0c40a0714b | ||
|
|
d74520768b | ||
|
|
3385df9cc9 | ||
|
|
18c31b20f5 | ||
|
|
7387912ca1 | ||
|
|
0d52763a61 | ||
|
|
86b505f998 | ||
|
|
62a803c55c | ||
|
|
0573808aeb | ||
|
|
22b4435c81 | ||
|
|
b803959e11 | ||
|
|
2f16497bf8 | ||
|
|
78aa7d1787 | ||
|
|
ba2216e6e9 | ||
|
|
74e3d909e6 | ||
|
|
5e52091ecf | ||
|
|
dafb299ea3 | ||
|
|
659bec56d7 | ||
|
|
8c1bea6f84 | ||
|
|
d8d1dc003b | ||
|
|
c2bb52b82f | ||
|
|
1f5456b18b | ||
|
|
dc702f4fd6 | ||
|
|
2a8101eef3 | ||
|
|
20702ddaff | ||
|
|
f4e2701705 | ||
|
|
776ae4e83b | ||
|
|
2158c7a92e | ||
|
|
b53bad7b29 | ||
|
|
6c92bcdad1 | ||
|
|
b949e56d15 | ||
|
|
18ff3e7b6a | ||
|
|
559b1fb89a | ||
|
|
1e78ef0752 | ||
|
|
602ada7820 | ||
|
|
57ac099703 | ||
|
|
eb7628eca4 | ||
|
|
c26e4943c2 | ||
|
|
7e90c8be6a | ||
|
|
3659d89c25 | ||
|
|
db992d42e5 | ||
|
|
5571a270d4 | ||
|
|
b18c2cefec | ||
|
|
3f204321ce | ||
|
|
63603b8ac8 | ||
|
|
fa79582b89 | ||
|
|
342e2c77a7 | ||
|
|
7848e28b62 | ||
|
|
544aa1b339 | ||
|
|
de4791f0c7 | ||
|
|
915f506f3a | ||
|
|
f29566d6d9 | ||
|
|
e4f747164c | ||
|
|
683550b297 | ||
|
|
971fdf7d1c | ||
|
|
1038c6f7f3 | ||
|
|
8efc0271f5 | ||
|
|
9ac5e597e6 | ||
|
|
f7fc5fae1d | ||
|
|
f44b253a42 | ||
|
|
8f85a6e557 | ||
|
|
8fd25e23a6 | ||
|
|
a3dd057147 | ||
|
|
e16fe46d7a | ||
|
|
39f3b24058 | ||
|
|
8e50756afa | ||
|
|
c07cd40234 | ||
|
|
d2addea9cf | ||
|
|
f88c024b2f | ||
|
|
983325bfdf | ||
|
|
f4635a696e | ||
|
|
c439eccdf8 | ||
|
|
04e29858ee | ||
|
|
ab2850e22e | ||
|
|
6429dcd03f | ||
|
|
b43d2f74e4 | ||
|
|
2aab4cf126 | ||
|
|
f2766db829 | ||
|
|
db0fb7f20d | ||
|
|
a6817528bc | ||
|
|
a7dd867503 | ||
|
|
e48f64daac | ||
|
|
171067eb22 | ||
|
|
78b94fa350 | ||
|
|
c84652af40 | ||
|
|
19fd9a7c1d | ||
|
|
5df1c354f0 | ||
|
|
eb0d82ce89 | ||
|
|
f89e922d72 | ||
|
|
ecacd4aee5 | ||
|
|
a17ec89332 | ||
|
|
7003541284 | ||
|
|
87c0e3a337 | ||
|
|
cfb9b646cc | ||
|
|
eed8229a04 | ||
|
|
3e6e25d0aa | ||
|
|
77ca5c2701 | ||
|
|
ca3127ffbc | ||
|
|
77d965784e | ||
|
|
edd289c645 | ||
|
|
2f528876ad | ||
|
|
aa64e34880 | ||
|
|
5fcde41023 | ||
|
|
63e22fc349 | ||
|
|
7af1ec0984 | ||
|
|
4e95797710 | ||
|
|
a641589b09 | ||
|
|
b8e4c7248b | ||
|
|
d29296935e | ||
|
|
1da2c1dcdc | ||
|
|
76395370de | ||
|
|
7589a0a108 | ||
|
|
34072f733c | ||
|
|
9442233a8a | ||
|
|
993831709d | ||
|
|
4def995185 | ||
|
|
fa85aa3f8b | ||
|
|
8021112fea | ||
|
|
80f424b6b3 | ||
|
|
1ef5be352a | ||
|
|
1a83801722 | ||
|
|
3c2f40ec02 | ||
|
|
b47dc3f77c | ||
|
|
f1e726f503 | ||
|
|
afb6ad488c | ||
|
|
5d68211af2 | ||
|
|
887bccf0af | ||
|
|
7eb067338f | ||
|
|
6896cc6346 | ||
|
|
de2f29b797 | ||
|
|
1ec6006f33 | ||
|
|
d9f92c46c4 | ||
|
|
9677c06036 | ||
|
|
a07b3e8a3a | ||
|
|
58a4d336b9 | ||
|
|
86da3818ff | ||
|
|
815889bd22 | ||
|
|
be48947ead | ||
|
|
3e7188edf7 | ||
|
|
3d4f9285c9 | ||
|
|
e556f4147f | ||
|
|
4e4f7a2390 | ||
|
|
35e65d018c | ||
|
|
714b8d9810 | ||
|
|
d061fced7e | ||
|
|
36fedf4f65 | ||
|
|
89202c5dd5 | ||
|
|
110adc58dc | ||
|
|
6f32a1982a | ||
|
|
c50c4c105c | ||
|
|
ac69278676 | ||
|
|
af325f00d9 | ||
|
|
28fa1b2f7e | ||
|
|
ab51787323 | ||
|
|
92bda42ac1 | ||
|
|
730e69463c | ||
|
|
07f000f65a | ||
|
|
3e7d30e01c | ||
|
|
22c72955f5 | ||
|
|
6f681f6519 | ||
|
|
c7273ddd30 | ||
|
|
2c6ef2a5c0 | ||
|
|
4eb4dfe5fa | ||
|
|
8838ddf921 | ||
|
|
6b3875ae39 | ||
|
|
ab763f25a4 | ||
|
|
550eea98b1 | ||
|
|
ecfed8db44 | ||
|
|
fe6e575158 | ||
|
|
d0b4383a0d | ||
|
|
83e2c8dc47 | ||
|
|
57787649d7 | ||
|
|
c9e7237184 | ||
|
|
52be4b0e8a | ||
|
|
e1571e19a8 | ||
|
|
8c7bf7d779 | ||
|
|
406e458c3a | ||
|
|
3f26974563 | ||
|
|
988f2382c4 | ||
|
|
b983fe0bb3 | ||
|
|
5a3f3e43a6 | ||
|
|
49d6e42324 | ||
|
|
d7a7877bfe | ||
|
|
d8ead95070 | ||
|
|
5404e9f004 | ||
|
|
f0aaec98f3 | ||
|
|
348371e43c | ||
|
|
4763486523 | ||
|
|
7250c7a03d | ||
|
|
cedd127e8f | ||
|
|
fcad90b5e9 | ||
|
|
64778f5412 | ||
|
|
a5766a19c2 | ||
|
|
c6f4e816aa | ||
|
|
ce6ef3186b | ||
|
|
6a66008153 | ||
|
|
6c6b345ba0 | ||
|
|
734b874dab | ||
|
|
6d573d8327 | ||
|
|
11eca1816a | ||
|
|
b0d66a01d2 | ||
|
|
bd0db1354e | ||
|
|
01475679d1 | ||
|
|
b2173ffb86 | ||
|
|
3f2f6438fd | ||
|
|
60b5f3e6e4 | ||
|
|
82e97addb1 | ||
|
|
19ae1f366b | ||
|
|
a9747a349a | ||
|
|
fe38bba477 | ||
|
|
a20f9d3e81 | ||
|
|
39e9f0542d | ||
|
|
1c2c5d7dd4 | ||
|
|
1c2ac61bb0 | ||
|
|
f764f68e9c | ||
|
|
2453e57436 | ||
|
|
500ef1088b | ||
|
|
c83cff36d8 | ||
|
|
589adba798 | ||
|
|
6e1d1d3dc4 | ||
|
|
ec59194232 | ||
|
|
7de4474996 | ||
|
|
95626a867e | ||
|
|
c072ffe421 | ||
|
|
ac797a836e | ||
|
|
0cda2287a8 | ||
|
|
6bfc0c84f0 | ||
|
|
1bd0cd504e | ||
|
|
a3e863942b | ||
|
|
f88cf9b025 | ||
|
|
1ad245238f | ||
|
|
4c54a69e64 | ||
|
|
77a31ca6b5 | ||
|
|
c06787ca22 | ||
|
|
15a353c123 | ||
|
|
1b4d22314d | ||
|
|
35383ac359 | ||
|
|
d2b00990fe | ||
|
|
97a11073d4 | ||
|
|
95b6261324 | ||
|
|
37c92fcf5c | ||
|
|
18281e614d | ||
|
|
7f8644cb39 | ||
|
|
799ba2b4b6 | ||
|
|
ad0a1ca97d | ||
|
|
7607610cf9 | ||
|
|
a71a3d29ff | ||
|
|
9051197603 | ||
|
|
94e5ac2109 | ||
|
|
84cb686928 | ||
|
|
da07ad3b13 | ||
|
|
d5cba00ce0 | ||
|
|
ba9d0b34c6 | ||
|
|
f2850cc0b9 | ||
|
|
c69ea0c1fb | ||
|
|
a63387f85e | ||
|
|
df7e7b391d | ||
|
|
5d6431d2d9 | ||
|
|
a61a361eb1 | ||
|
|
9dbad2a26f | ||
|
|
aaba3dd46a | ||
|
|
2e013847d9 | ||
|
|
22e569d430 | ||
|
|
2847039ffe | ||
|
|
54ce11629c | ||
|
|
8dcfd6aae0 | ||
|
|
838a4a5cb9 | ||
|
|
e82b72e931 | ||
|
|
fdc6ccdf5c | ||
|
|
52b389afe8 | ||
|
|
552006c876 | ||
|
|
f0b32edaa9 | ||
|
|
5a901ca155 | ||
|
|
9593cf4cf6 | ||
|
|
64725e2ed9 | ||
|
|
9260f9374a | ||
|
|
2ccf50db3e | ||
|
|
e843ee7117 | ||
|
|
a192e814bf | ||
|
|
ccda631708 | ||
|
|
1552e33c67 | ||
|
|
8afc784956 | ||
|
|
5b00916f83 | ||
|
|
6b7bc76603 | ||
|
|
732c665af5 | ||
|
|
8cf367d68c | ||
|
|
d070978a54 | ||
|
|
7f30efab38 | ||
|
|
d7fed87ebb | ||
|
|
269ac164ed | ||
|
|
55edf31aa6 | ||
|
|
364782b8af | ||
|
|
d3c576f6de | ||
|
|
8d52d73968 | ||
|
|
48022d3a3f | ||
|
|
ec1634d6d8 | ||
|
|
688bb7094e | ||
|
|
928e66eb27 | ||
|
|
d80c27de29 | ||
|
|
6aac22fa74 | ||
|
|
7bc1ab41f7 | ||
|
|
068e304baa | ||
|
|
5dc7b20a43 | ||
|
|
a70ce10bed | ||
|
|
3773443fc8 | ||
|
|
1f4be63d08 | ||
|
|
6a69d1ff6c | ||
|
|
85102b4546 | ||
|
|
f188ea4d2a | ||
|
|
a75dd9e3f9 | ||
|
|
dda673cad4 | ||
|
|
8b125d31f2 | ||
|
|
67ee3e8a7d | ||
|
|
d70536f9ab | ||
|
|
bfe9f9f4a5 | ||
|
|
97e24131c6 | ||
|
|
42b6c40433 | ||
|
|
4dcef0f15d | ||
|
|
c082dfad67 | ||
|
|
331bc57b44 | ||
|
|
b7e20f550e | ||
|
|
e15ef0d837 | ||
|
|
08fd9e2d69 | ||
|
|
3a99213c0b | ||
|
|
ad71158268 | ||
|
|
186d23c920 | ||
|
|
cfbf88bb5f | ||
|
|
1681981fe8 | ||
|
|
3e84b07a01 | ||
|
|
b087c964d4 | ||
|
|
bf70a94921 | ||
|
|
e5282f8a3c | ||
|
|
5920185288 | ||
|
|
92f0249d2b | ||
|
|
016cfeecc6 | ||
|
|
8bf0c355f4 | ||
|
|
fa4178de09 | ||
|
|
04578b109f | ||
|
|
9dabb6f570 | ||
|
|
8812153491 | ||
|
|
17da10d76e | ||
|
|
dae25b3381 | ||
|
|
745071af65 | ||
|
|
f3448f1797 | ||
|
|
dad6091706 | ||
|
|
6d6eb9c5d7 | ||
|
|
64b84fa91d | ||
|
|
bac8388cec | ||
|
|
e69d0d7ce9 | ||
|
|
b326546229 | ||
|
|
5c22cc7985 | ||
|
|
bd31b3648f | ||
|
|
3c595e6225 | ||
|
|
ed40dd423d | ||
|
|
0e5d7d7ae0 | ||
|
|
9ef6f7a612 | ||
|
|
da923aa63c | ||
|
|
f88d94cbaa | ||
|
|
6403d1908d | ||
|
|
423dbf2404 | ||
|
|
af6b0fdbb2 | ||
|
|
8e7eb25558 | ||
|
|
91a724fe2d | ||
|
|
eb1c43d293 | ||
|
|
4123764a48 | ||
|
|
abe94ece52 | ||
|
|
2498ebf7d6 | ||
|
|
f8445c2e5c | ||
|
|
116eb9f1c1 | ||
|
|
48c068b84a | ||
|
|
20a3868e82 | ||
|
|
85d7401520 | ||
|
|
3b848060aa | ||
|
|
69fc5ff54b | ||
|
|
8db6032303 | ||
|
|
549c0e97d0 | ||
|
|
c3861cf54e | ||
|
|
7c1453662f | ||
|
|
5b60b79fd8 | ||
|
|
07b5d74179 | ||
|
|
76b0c919b9 | ||
|
|
785ee7b47b | ||
|
|
64b267c7ea | ||
|
|
0832184896 | ||
|
|
5d41316b9a | ||
|
|
602ead5de5 | ||
|
|
72e038b9bf |
28
.github/workflows/tests.yaml
vendored
Normal file
28
.github/workflows/tests.yaml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: Tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
jobs:
|
||||||
|
Ubuntu-Tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install libpcap
|
||||||
|
run: sudo apt-get install -y libpcap-dev
|
||||||
|
|
||||||
|
- name: Initialize submodules
|
||||||
|
run: git submodule init && git submodule update
|
||||||
|
|
||||||
|
- name: Initialize build system
|
||||||
|
run: mkdir build && cd build && cmake ..
|
||||||
|
|
||||||
|
- name: Build tests
|
||||||
|
run: cmake --build build --target tests
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: ctest build
|
||||||
@@ -15,6 +15,7 @@ addons:
|
|||||||
packages:
|
packages:
|
||||||
- libpcap-dev
|
- libpcap-dev
|
||||||
- libssl-dev
|
- libssl-dev
|
||||||
|
- libboost-all-dev
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
|
|||||||
9
AUTHORS
9
AUTHORS
@@ -1,9 +0,0 @@
|
|||||||
# Below is a list of people and organizations that have contributed source
|
|
||||||
# code to libtins. Names are listed using the following format:
|
|
||||||
#
|
|
||||||
# Name/Organization <email address>
|
|
||||||
|
|
||||||
Matias Fontanini <matias.fontanini@gmail.com>
|
|
||||||
Santiago Alessandri <san.lt.ss@gmail.com>
|
|
||||||
Bruno Nery <brunonery@brunonery.com>
|
|
||||||
Piotr Haber <piotr.haber@sens.us>
|
|
||||||
@@ -1,4 +1,298 @@
|
|||||||
v3.3 - Sun Jan 31 21:06:04 PST 2016
|
##### v4.5 - Sun Aug 20 04:46:53 PM UTC 2023
|
||||||
|
|
||||||
|
- Add VXLAN support (#501)
|
||||||
|
|
||||||
|
- Add `FileSniffer` constructor taking a `FILE*` (#499).
|
||||||
|
|
||||||
|
- Remove use of deprecated `std::iterator` (#481).
|
||||||
|
|
||||||
|
- Add missing `algorithm` header include (#497).
|
||||||
|
|
||||||
|
- Validate high order two bits of first dns label octet (#494).
|
||||||
|
|
||||||
|
- Use `CMAKE_INSTALL_LIBDIR` in `CONF_CMAKE_INSTALL_DIR` (#472).
|
||||||
|
|
||||||
|
- Ignore IPv6 packets with payload after one with no Next Header (#500).
|
||||||
|
|
||||||
|
- Fix unqualified `std::move` call warnings on clang (#488).
|
||||||
|
|
||||||
|
- Fix incorrect IP address range calculation when using /0 prefix (#484) (#486).
|
||||||
|
|
||||||
|
- Fall back to system GTest if available (#473).
|
||||||
|
|
||||||
|
- Fix compilation issue on android (#471).
|
||||||
|
|
||||||
|
- Fix DNS parser reading garbage on misreported packet size (#468).
|
||||||
|
|
||||||
|
- Fix DNS parser misinterpreting bad label size (#466).
|
||||||
|
|
||||||
|
##### v4.4 - Thu Feb 17 14:41:59 UTC 2022
|
||||||
|
|
||||||
|
- Add RFC8335 extended echo types to `ICMP` and `ICMPv6` (#426)
|
||||||
|
|
||||||
|
- Handle loops in DNS name decompression (#444)
|
||||||
|
|
||||||
|
- Fix Windows' `interface` macro colliding with uses of that identifier in the code (#458)
|
||||||
|
|
||||||
|
- Sending IPv6 packets to a link-scope destination address now uses the right interface index (#448)
|
||||||
|
|
||||||
|
- Fix incorrect endian being used for ICMP's `gateway` and `address_mask` (#437)
|
||||||
|
|
||||||
|
- Socket in `PacketSender::open_l3_socket` is now closed if `setsockopt` fails (#433)
|
||||||
|
|
||||||
|
- Fix various incorrect doxygen documentation comments (#439).
|
||||||
|
|
||||||
|
- Fix infinite loop when querying the routing table in \*BSD (#427)
|
||||||
|
|
||||||
|
##### v4.3 - Fri Sep 18 03:08:33 UTC 2020
|
||||||
|
|
||||||
|
- Assign a PDUType to `Dot11ControlTA` (#420)
|
||||||
|
|
||||||
|
- Don't consider IPv6 ESP header a normal extension header (#374)
|
||||||
|
|
||||||
|
- Don't include non-existing headers when installed without libpcap (#382)
|
||||||
|
|
||||||
|
- Add `IPv6Address::is_local_unicast` (#369)
|
||||||
|
|
||||||
|
- Fix memory leak in `PacketWriter` (#343)
|
||||||
|
|
||||||
|
- Fix memory leaks in `OfflinePacketFilter` (#343)
|
||||||
|
|
||||||
|
- Fix detection of new TCP stream (#335)
|
||||||
|
|
||||||
|
- Introduce `TCP::has_flags` (#334)
|
||||||
|
|
||||||
|
- Fix padding calculations in RadioTapWriter (#333)
|
||||||
|
|
||||||
|
##### v4.2 - Fri Mar 8 04:15:13 UTC 2019
|
||||||
|
|
||||||
|
- Updated location of installed CMake files in unix systems (#331)
|
||||||
|
|
||||||
|
- Fix check to detect cross compilation (#330)
|
||||||
|
|
||||||
|
- Allow getting a PDU's advertised size and use it in `PacketWriter` (#324)
|
||||||
|
|
||||||
|
- Install DLLs in right directory (#326)
|
||||||
|
|
||||||
|
- Add missing Dot11 tagged option types (#305)
|
||||||
|
|
||||||
|
- Add support for DLT_RAW (#313)
|
||||||
|
|
||||||
|
- Fix potential invalid memory accesses when parsing RadioTap (#322)
|
||||||
|
|
||||||
|
##### v4.1 - Tue Dec 11 02:08:48 UTC 2018
|
||||||
|
|
||||||
|
- Fix serialization for QinQ (#316)
|
||||||
|
|
||||||
|
- Added base class access specifier for socket_close_error (#306)
|
||||||
|
|
||||||
|
- Rewrote hw_address_to_string to not require a stringstream (#299)
|
||||||
|
|
||||||
|
- Make RadioTapParser::skip_to_field check for end of buffer (#296)
|
||||||
|
|
||||||
|
- Ensure local include directory comes before system. (#293)
|
||||||
|
|
||||||
|
- Calculate IP option sizes properly (#288)
|
||||||
|
|
||||||
|
- Add parsing of well known IPv6 extension headers (#287)
|
||||||
|
|
||||||
|
- Add missing operators to address classes (#275)
|
||||||
|
|
||||||
|
- Add version macros in config.h
|
||||||
|
|
||||||
|
- Don't assume IPv6 uses ICMPv6 underneath
|
||||||
|
|
||||||
|
- Allow users to specify library install dir
|
||||||
|
|
||||||
|
- Use Sleep windows function passing milliseconds as parameter
|
||||||
|
|
||||||
|
- Implement IPv6::recv_response
|
||||||
|
|
||||||
|
- Don't use nullptr in non C++11 code
|
||||||
|
|
||||||
|
- Ignore (possibly malformed) options after EOL (#281)
|
||||||
|
|
||||||
|
- Don't include dot11.h in tins.h if it is not configured in the library (#277)
|
||||||
|
|
||||||
|
- Fix memory leak in PDU's move assignment operator
|
||||||
|
|
||||||
|
- Append padding to IPv6 options
|
||||||
|
|
||||||
|
##### v4.0 - Mon Dec 4 00:04:30 UTC 2017
|
||||||
|
|
||||||
|
- Add parent PDU to each PDU.
|
||||||
|
|
||||||
|
- Removed parent PDU parameter on `PDU::write_serialization`.
|
||||||
|
|
||||||
|
- Split `utils.h` into multiple files under the `utils` directory.
|
||||||
|
|
||||||
|
- Split `internals.h` into multiple files under the `detail` directory.
|
||||||
|
|
||||||
|
- Improve compilation times by removing useless include directives.
|
||||||
|
|
||||||
|
- Refactor `PDUOption` conversions so that heavy headers are not included in source file.
|
||||||
|
|
||||||
|
- Use `std::vector` instead of `std::list` in `TCP`, `IP`, `IPv6`, `DHCP`, `DHCPv6`, `DNS`, `LLC`, `Dot11` and `PPPoE`.
|
||||||
|
|
||||||
|
- Improve performance on `IP`, `IPv6` and `TCP` by compiting option sizes during serialization.
|
||||||
|
|
||||||
|
- Minor performance improvements in `DNS`.
|
||||||
|
|
||||||
|
- Fix `IPv6` next header handling. Now each one contains its own type and the next type is only set during serialization for ease of use.
|
||||||
|
|
||||||
|
- Refactor `RadioTap` parsing and serialization using a generic parser/writer.
|
||||||
|
|
||||||
|
- Add `BaseSniffer::set_pcap_sniffing_method` to specify whether `pcap_loop` or `pcap_dispatch` should be used when sniffing.
|
||||||
|
|
||||||
|
- Use `IFF_POINTOPOINT` on BSD when getting broadcast address for an interface.
|
||||||
|
|
||||||
|
- Added cipher and akm suites from 802.11-2016.
|
||||||
|
|
||||||
|
- Add IPv6 layer parsing on `Loopback` packets.
|
||||||
|
|
||||||
|
- Allow serializing `Loopback` on Windows.
|
||||||
|
|
||||||
|
- Use the right flag on `Loopback` for `IPv6`.
|
||||||
|
|
||||||
|
- Use the first fragment as a base when reassembling `IP` packets in `IPv4Reassembler`.
|
||||||
|
|
||||||
|
- Restructure CMake files removing useless `CMakeLists.txt` in `include` paths.
|
||||||
|
|
||||||
|
- Add getter/setter for "more data" field in `Dot11Base`.
|
||||||
|
|
||||||
|
- Implemented matching for ND protocol related ICMPv6 messages.
|
||||||
|
|
||||||
|
- Ensure TCP::OptionTypes has 8-bit range.
|
||||||
|
|
||||||
|
- Add header files into CMake sources so IDE can pick them up.
|
||||||
|
|
||||||
|
- Add MPLS "experimental" field.
|
||||||
|
|
||||||
|
- Fix dhcpv6::duid_type constructor from duid_ll.
|
||||||
|
|
||||||
|
##### v3.5 - Sat Apr 1 09:11:58 PDT 2017
|
||||||
|
|
||||||
|
- Added Utils::route6_entries
|
||||||
|
|
||||||
|
- Allow masking IPv4/6 and hardware addresses via `operator&`
|
||||||
|
|
||||||
|
- Add IPv4Address::from_prefix_length
|
||||||
|
|
||||||
|
- Move `stream_id` into a new file and rename it `StreamIdentifier`
|
||||||
|
|
||||||
|
- Allow disabling TCPIP classes
|
||||||
|
|
||||||
|
- Properly handle out of order SACKs on `AckTracker`
|
||||||
|
|
||||||
|
- Move TCP data tracking into a separate class
|
||||||
|
|
||||||
|
- Allow constructing `StreamIdentifier` from a `Stream`
|
||||||
|
|
||||||
|
- Allow configuring pcap timestamp precision
|
||||||
|
|
||||||
|
- Allow building libtins using MinGW
|
||||||
|
|
||||||
|
- Allow including libtins using `add_subdirectory` via CMake
|
||||||
|
|
||||||
|
- Allow setting customer user data to each TCP stream
|
||||||
|
|
||||||
|
- Allow skipping data forward in TCP streams
|
||||||
|
|
||||||
|
- Allow attaching to already existing TCP streams
|
||||||
|
|
||||||
|
- Fix: AddressRange masks first address as well
|
||||||
|
|
||||||
|
- Fix: Add TINS_API to `IPv4Address::operator<<`, `DataTracker` and `AckTracker`
|
||||||
|
|
||||||
|
- Fix: Don't always set `key_t` to 0 on `RSNEAPOL`
|
||||||
|
|
||||||
|
- Fix: Handle MLDv1 properly on ICMP
|
||||||
|
|
||||||
|
- Fix: Make Utils::resolve_hwaddress work on Windows
|
||||||
|
|
||||||
|
- Fix: Interface was sometimes considered down when it was up (BSD/Linux)
|
||||||
|
|
||||||
|
- Fix: Don't set `Dot1Q`'s payload type if next protocol type is unknown
|
||||||
|
|
||||||
|
- Fix: Use recvfrom on BSD/OSX when capturing layer 3 packets
|
||||||
|
|
||||||
|
- Fix: Make `Timestamp::current_time` work on Windows
|
||||||
|
|
||||||
|
- Fix: Forward `NetworkInterface` argument when calling `PacketSender::send_l2`
|
||||||
|
|
||||||
|
- Fix: `Timestamp` overflow issue
|
||||||
|
|
||||||
|
- Fix: boost's include directories variable incorrectly used on build system
|
||||||
|
|
||||||
|
- Fix: Configuring auto cleanup of `Stream`'s server data not working
|
||||||
|
|
||||||
|
- Fix: Set `EthernetII` payload type to `UNKNOWN` if there's no inner PDU
|
||||||
|
|
||||||
|
- Fix: Set payload type to 0 if there's no inner PDU in `IP`, `Dot1Q` and `IPv6`
|
||||||
|
|
||||||
|
- Fix: Buffer length check issues on `Dot11QosData`
|
||||||
|
|
||||||
|
- Fix: Use AF_INET6 flag when opening L3 IPv6 socket
|
||||||
|
|
||||||
|
- Fix: Check expecter size properly on `DNS::extract_metadata`
|
||||||
|
|
||||||
|
- Fix: several unused parameter warnings
|
||||||
|
|
||||||
|
- Fix: CCMP decryption issue when `Dot11QoSData` has a TID != 0
|
||||||
|
|
||||||
|
##### v3.4 - Wed Mar 9 20:24:54 PST 2016
|
||||||
|
|
||||||
|
- Check the secure bit on HandshakeCapturer to detect 2nd packet
|
||||||
|
|
||||||
|
- Add info members directly into NetworkInterface
|
||||||
|
|
||||||
|
- Add IPv6 addresses to NetworkInterface::Info
|
||||||
|
|
||||||
|
- Make *MemoryStream use size_t rather than uint32_t
|
||||||
|
|
||||||
|
- Add WPA2Decrypter callback interface
|
||||||
|
|
||||||
|
- Set MACOSX_RPATH to ON
|
||||||
|
|
||||||
|
- Don't fail configuration if openssl is missing
|
||||||
|
|
||||||
|
- Build layer 5 as RawPDU if IPv6 has fragment header
|
||||||
|
|
||||||
|
- Fix examples so they build on gcc 4.6
|
||||||
|
|
||||||
|
- Fix flag value for sniffer's immediate mode
|
||||||
|
|
||||||
|
- Fix IP fragment reassemble when packet has flags DF+MF
|
||||||
|
|
||||||
|
- Add extract_metadata to main PDU classes
|
||||||
|
|
||||||
|
- Fix examples to make them work on Windows
|
||||||
|
|
||||||
|
- Use timercmp/sub and std::chrono to subtract timevals on PacketSender
|
||||||
|
|
||||||
|
- Build examples against local libtins build
|
||||||
|
|
||||||
|
- Add uninstall target
|
||||||
|
|
||||||
|
- Prefix HAVE_ config.h macros with TINS_
|
||||||
|
|
||||||
|
- Use compiler intrinsics to swap bytes
|
||||||
|
|
||||||
|
- Use C++11 mode by default
|
||||||
|
|
||||||
|
- Add missing TINS_API to PDU classes.
|
||||||
|
|
||||||
|
- Extend/fix ICMPv6 enum values and unify naming
|
||||||
|
|
||||||
|
- Return an empty string for dot11 ssid, if ssid is present but empty
|
||||||
|
|
||||||
|
- Implement new TCP stream follower mechanism
|
||||||
|
|
||||||
|
- Use ExternalProject_Add rather than including the gtest directory
|
||||||
|
|
||||||
|
- Fix invalid endian on IP fragment offset on OSX
|
||||||
|
|
||||||
|
##### v3.3 - Sun Jan 31 21:06:04 PST 2016
|
||||||
|
|
||||||
- Add TCP connection close example
|
- Add TCP connection close example
|
||||||
|
|
||||||
@@ -163,7 +457,7 @@ immutable
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v3.2 - Fri Mar 20 22:12:23 PST 2015
|
##### v3.2 - Fri Mar 20 22:12:23 PST 2015
|
||||||
|
|
||||||
- Added include guard for config.h.
|
- Added include guard for config.h.
|
||||||
|
|
||||||
@@ -246,7 +540,7 @@ conversion on integral constant.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v3.1 - Sun Aug 24 21:39:43 ART 2014
|
##### v3.1 - Sun Aug 24 21:39:43 ART 2014
|
||||||
|
|
||||||
- Fixed ICMPv6 checksum error on serialization.
|
- Fixed ICMPv6 checksum error on serialization.
|
||||||
|
|
||||||
@@ -256,7 +550,7 @@ v3.1 - Sun Aug 24 21:39:43 ART 2014
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v3.0 - Thu Aug 7 21:39:09 ART 2014
|
##### v3.0 - Thu Aug 7 21:39:09 ART 2014
|
||||||
|
|
||||||
- Timestamps can now be constructed from std::chrono::duration.
|
- Timestamps can now be constructed from std::chrono::duration.
|
||||||
|
|
||||||
@@ -321,7 +615,7 @@ PDU types.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v2.0 - Thu Jan 23 11:09:38 ART 2014
|
##### v2.0 - Thu Jan 23 11:09:38 ART 2014
|
||||||
|
|
||||||
- DNSResourceRecord was removed. Now DNS records are added using
|
- DNSResourceRecord was removed. Now DNS records are added using
|
||||||
DNS::Resource.
|
DNS::Resource.
|
||||||
@@ -377,7 +671,7 @@ capture size.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v1.2 - Mon oct 7 23:33:49 ART 2013
|
##### v1.2 - Mon oct 7 23:33:49 ART 2013
|
||||||
|
|
||||||
- Added BaseSniffer::begin and BaseSniffer::end.
|
- Added BaseSniffer::begin and BaseSniffer::end.
|
||||||
|
|
||||||
@@ -473,7 +767,7 @@ that used them.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v0.3 - Thu Jan 31 16:47:27 ART 2013
|
##### v0.3 - Thu Jan 31 16:47:27 ART 2013
|
||||||
|
|
||||||
- Added IPv6, ICMPv6 and DHCPv6 classes.
|
- Added IPv6, ICMPv6 and DHCPv6 classes.
|
||||||
|
|
||||||
@@ -494,7 +788,7 @@ pseudo protocol.
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
v0.2 - Sat Oct 20 11:26:40 2012
|
##### v0.2 - Sat Oct 20 11:26:40 2012
|
||||||
|
|
||||||
- Added support for big endian architectures.
|
- Added support for big endian architectures.
|
||||||
|
|
||||||
233
CMakeLists.txt
233
CMakeLists.txt
@@ -1,6 +1,9 @@
|
|||||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
|
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
|
||||||
PROJECT(libtins)
|
PROJECT(libtins)
|
||||||
|
|
||||||
|
OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON)
|
||||||
|
OPTION(LIBTINS_BUILD_TESTS "Build tests" ON)
|
||||||
|
|
||||||
# Compile in release mode by default
|
# Compile in release mode by default
|
||||||
IF(NOT CMAKE_BUILD_TYPE)
|
IF(NOT CMAKE_BUILD_TYPE)
|
||||||
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
|
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
|
||||||
@@ -18,7 +21,12 @@ IF(MSVC)
|
|||||||
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
|
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
|
||||||
ADD_DEFINITIONS("-DNOGDI=1")
|
ADD_DEFINITIONS("-DNOGDI=1")
|
||||||
ELSE()
|
ELSE()
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
IF(APPLE)
|
||||||
|
# This is set to ON as of policy CMP0042
|
||||||
|
SET(CMAKE_MACOSX_RPATH ON)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# Build output checks
|
# Build output checks
|
||||||
@@ -37,15 +45,22 @@ ELSE(LIBTINS_BUILD_SHARED)
|
|||||||
ENDIF(LIBTINS_BUILD_SHARED)
|
ENDIF(LIBTINS_BUILD_SHARED)
|
||||||
|
|
||||||
# The version number.
|
# The version number.
|
||||||
SET(LIBTINS_VERSION_MAJOR 3)
|
SET(TINS_VERSION_MAJOR 4)
|
||||||
SET(LIBTINS_VERSION_MINOR 3)
|
SET(TINS_VERSION_MINOR 6)
|
||||||
SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}")
|
SET(TINS_VERSION_PATCH 0)
|
||||||
|
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
|
||||||
|
|
||||||
# Required Packages
|
# Required Packages
|
||||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||||
|
|
||||||
|
# Allow disabling packet capture mechanism
|
||||||
|
OPTION(LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON)
|
||||||
|
|
||||||
# Look for libpcap
|
# Look for libpcap
|
||||||
FIND_PACKAGE(PCAP REQUIRED)
|
IF(LIBTINS_ENABLE_PCAP)
|
||||||
|
FIND_PACKAGE(PCAP REQUIRED)
|
||||||
|
SET(TINS_HAVE_PCAP ON)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
# Set some Windows specific flags
|
# Set some Windows specific flags
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
@@ -54,23 +69,51 @@ IF(WIN32)
|
|||||||
|
|
||||||
# Add the NOMINMAX macro to avoid Windows' min and max macros.
|
# Add the NOMINMAX macro to avoid Windows' min and max macros.
|
||||||
ADD_DEFINITIONS(-DNOMINMAX)
|
ADD_DEFINITIONS(-DNOMINMAX)
|
||||||
|
|
||||||
|
# MinWG need some extra definitions to compile properly (WIN32 for PCAP and WIN32_WINNT version for ws2tcpip.h)
|
||||||
|
IF(MINGW)
|
||||||
|
ADD_DEFINITIONS(-DWIN32)
|
||||||
|
MACRO(get_WIN32_WINNT version)
|
||||||
|
IF (WIN32 AND CMAKE_SYSTEM_VERSION)
|
||||||
|
SET(ver ${CMAKE_SYSTEM_VERSION})
|
||||||
|
STRING(REPLACE "." "" ver ${ver})
|
||||||
|
STRING(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
|
||||||
|
SET(${version} "0x${ver}")
|
||||||
|
ENDIF()
|
||||||
|
ENDMACRO()
|
||||||
|
get_WIN32_WINNT(ver)
|
||||||
|
ADD_DEFINITIONS(-D_WIN32_WINNT=${ver})
|
||||||
|
ENDIF(MINGW)
|
||||||
|
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
INCLUDE(ExternalProject)
|
||||||
|
|
||||||
# *******************
|
# *******************
|
||||||
# Compilation options
|
# Compilation options
|
||||||
# *******************
|
# *******************
|
||||||
|
|
||||||
|
# Always check for C++ features
|
||||||
|
INCLUDE(CheckCXXFeatures)
|
||||||
|
|
||||||
|
IF(HAS_GCC_BUILTIN_SWAP)
|
||||||
|
SET(TINS_HAVE_GCC_BUILTIN_SWAP ON)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
# C++11 support
|
# C++11 support
|
||||||
OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" OFF)
|
OPTION(LIBTINS_ENABLE_CXX11 "Compile libtins with c++11 features" ON)
|
||||||
IF(LIBTINS_ENABLE_CXX11)
|
IF(LIBTINS_ENABLE_CXX11)
|
||||||
SET(HAVE_CXX11 ON)
|
# We only use declval and decltype on gcc/clang as VC fails to build that code,
|
||||||
INCLUDE(CheckCXX11Features)
|
# at least on VC2013
|
||||||
IF(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
|
IF(HAS_CXX11_RVALUE_REFERENCES AND HAS_CXX11_FUNCTIONAL AND HAS_CXX11_CHRONO AND
|
||||||
|
HAS_CXX11_NOEXCEPT AND ((HAS_CXX11_DECLVAL AND HAS_CXX11_DECLTYPE) OR MSVC))
|
||||||
|
SET(TINS_HAVE_CXX11 ON)
|
||||||
MESSAGE(STATUS "Enabling C++11 features")
|
MESSAGE(STATUS "Enabling C++11 features")
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
|
||||||
ELSE(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
|
ELSE()
|
||||||
MESSAGE(FATAL_ERROR "C++11 features requested but the compiler does not support them.")
|
MESSAGE(WARNING "The compiler doesn't support the necessary C++11 features. "
|
||||||
ENDIF(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
|
"Disabling C++11 on this build")
|
||||||
|
ENDIF()
|
||||||
ELSE(LIBTINS_ENABLE_CXX11)
|
ELSE(LIBTINS_ENABLE_CXX11)
|
||||||
MESSAGE(
|
MESSAGE(
|
||||||
WARNING
|
WARNING
|
||||||
@@ -83,17 +126,75 @@ ENDIF(LIBTINS_ENABLE_CXX11)
|
|||||||
OPTION(LIBTINS_ENABLE_DOT11 "Compile libtins with IEEE 802.11 support" ON)
|
OPTION(LIBTINS_ENABLE_DOT11 "Compile libtins with IEEE 802.11 support" ON)
|
||||||
OPTION(LIBTINS_ENABLE_WPA2 "Compile libtins with WPA2 decryption features (requires OpenSSL)" ON)
|
OPTION(LIBTINS_ENABLE_WPA2 "Compile libtins with WPA2 decryption features (requires OpenSSL)" ON)
|
||||||
IF(LIBTINS_ENABLE_DOT11)
|
IF(LIBTINS_ENABLE_DOT11)
|
||||||
SET(HAVE_DOT11 ON)
|
SET(TINS_HAVE_DOT11 ON)
|
||||||
MESSAGE(STATUS "Enabling IEEE 802.11 support.")
|
MESSAGE(STATUS "Enabling IEEE 802.11 support.")
|
||||||
IF(LIBTINS_ENABLE_WPA2)
|
IF(LIBTINS_ENABLE_WPA2)
|
||||||
FIND_PACKAGE(OpenSSL REQUIRED)
|
FIND_PACKAGE(OpenSSL)
|
||||||
SET(HAVE_WPA2_DECRYPTION ON)
|
IF(OPENSSL_FOUND)
|
||||||
MESSAGE(STATUS "Enabling WPA2 decryption support.")
|
SET(TINS_HAVE_WPA2_DECRYPTION ON)
|
||||||
|
MESSAGE(STATUS "Enabling WPA2 decryption support.")
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "Disabling WPA2 decryption support since OpenSSL was not found")
|
||||||
|
# Default this to empty strings
|
||||||
|
SET(OPENSSL_INCLUDE_DIR "")
|
||||||
|
SET(OPENSSL_LIBRARIES "")
|
||||||
|
ENDIF()
|
||||||
ELSE(LIBTINS_ENABLE_WPA2)
|
ELSE(LIBTINS_ENABLE_WPA2)
|
||||||
MESSAGE(STATUS "Disabling WPA2 decryption support.")
|
MESSAGE(STATUS "Disabling WPA2 decryption support.")
|
||||||
ENDIF(LIBTINS_ENABLE_WPA2)
|
ENDIF(LIBTINS_ENABLE_WPA2)
|
||||||
ENDIF(LIBTINS_ENABLE_DOT11)
|
ENDIF(LIBTINS_ENABLE_DOT11)
|
||||||
|
|
||||||
|
# Optionally enable TCPIP classes (on by default)
|
||||||
|
OPTION(LIBTINS_ENABLE_TCPIP "Enable TCPIP classes" ON)
|
||||||
|
IF(LIBTINS_ENABLE_TCPIP AND TINS_HAVE_CXX11)
|
||||||
|
SET(TINS_HAVE_TCPIP ON)
|
||||||
|
MESSAGE(STATUS "Enabling TCPIP classes")
|
||||||
|
ELSE()
|
||||||
|
SET(TINS_HAVE_TCPIP OFF)
|
||||||
|
MESSAGE(STATUS "Disabling TCPIP classes")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
# Search for libboost
|
||||||
|
FIND_PACKAGE(Boost)
|
||||||
|
|
||||||
|
# Optionally enable the ACK tracker (on by default)
|
||||||
|
OPTION(LIBTINS_ENABLE_ACK_TRACKER "Enable TCP ACK tracking support" ON)
|
||||||
|
IF(LIBTINS_ENABLE_ACK_TRACKER AND TINS_HAVE_CXX11)
|
||||||
|
IF (Boost_FOUND)
|
||||||
|
MESSAGE(STATUS "Enabling TCP ACK tracking support.")
|
||||||
|
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||||||
|
SET(TINS_HAVE_ACK_TRACKER ON)
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "Disabling ACK tracking support as boost.icl was not found")
|
||||||
|
SET(TINS_HAVE_ACK_TRACKER OFF)
|
||||||
|
ENDIF()
|
||||||
|
ELSE()
|
||||||
|
SET(TINS_HAVE_ACK_TRACKER OFF)
|
||||||
|
MESSAGE(STATUS "Disabling ACK tracking support")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
# Optionally enable the TCP stream custom data (on by default)
|
||||||
|
OPTION(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA "Enable TCP stream custom data support" ON)
|
||||||
|
IF(LIBTINS_ENABLE_TCP_STREAM_CUSTOM_DATA AND TINS_HAVE_CXX11)
|
||||||
|
IF (Boost_FOUND)
|
||||||
|
MESSAGE(STATUS "Enabling TCP stream custom data support.")
|
||||||
|
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||||||
|
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA ON)
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "Disabling TCP stream custom data support as boost.any was not found")
|
||||||
|
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
|
||||||
|
ENDIF()
|
||||||
|
ELSE()
|
||||||
|
SET(TINS_HAVE_TCP_STREAM_CUSTOM_DATA OFF)
|
||||||
|
MESSAGE(STATUS "Disabling TCP stream custom data support")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
OPTION(LIBTINS_ENABLE_WPA2_CALLBACKS "Enable WPA2 callback interface" ON)
|
||||||
|
IF(LIBTINS_ENABLE_WPA2_CALLBACKS AND TINS_HAVE_WPA2_DECRYPTION AND TINS_HAVE_CXX11)
|
||||||
|
SET(STATUS "Enabling WPA2 callback interface")
|
||||||
|
SET(TINS_HAVE_WPA2_CALLBACKS ON)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
# Use pcap_sendpacket to send l2 packets rather than raw sockets
|
# Use pcap_sendpacket to send l2 packets rather than raw sockets
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
SET(USE_PCAP_SENDPACKET_DEFAULT ON)
|
SET(USE_PCAP_SENDPACKET_DEFAULT ON)
|
||||||
@@ -103,10 +204,10 @@ ENDIF(WIN32)
|
|||||||
|
|
||||||
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
|
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
|
||||||
${USE_PCAP_SENDPACKET_DEFAULT})
|
${USE_PCAP_SENDPACKET_DEFAULT})
|
||||||
IF(LIBTINS_USE_PCAP_SENDPACKET)
|
IF(LIBTINS_ENABLE_PCAP AND LIBTINS_USE_PCAP_SENDPACKET)
|
||||||
SET(HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
|
SET(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
|
||||||
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
|
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
|
||||||
ENDIF(LIBTINS_USE_PCAP_SENDPACKET)
|
ENDIF()
|
||||||
|
|
||||||
# Add a target to generate API documentation using Doxygen
|
# Add a target to generate API documentation using Doxygen
|
||||||
FIND_PACKAGE(Doxygen QUIET)
|
FIND_PACKAGE(Doxygen QUIET)
|
||||||
@@ -124,18 +225,22 @@ IF(DOXYGEN_FOUND)
|
|||||||
)
|
)
|
||||||
ENDIF(DOXYGEN_FOUND)
|
ENDIF(DOXYGEN_FOUND)
|
||||||
|
|
||||||
# The library output directory
|
|
||||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
|
||||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
|
||||||
|
|
||||||
# Configuration file
|
# Configuration file
|
||||||
CONFIGURE_FILE(
|
CONFIGURE_FILE(
|
||||||
"${PROJECT_SOURCE_DIR}/include/tins/config.h.in"
|
"${PROJECT_SOURCE_DIR}/include/tins/config.h.in"
|
||||||
"${PROJECT_SOURCE_DIR}/include/tins/config.h"
|
"${PROJECT_SOURCE_DIR}/include/tins/config.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
IF (NOT CMAKE_INSTALL_LIBDIR)
|
||||||
|
SET(CMAKE_INSTALL_LIBDIR lib)
|
||||||
|
ENDIF()
|
||||||
|
IF (NOT CMAKE_INSTALL_BINDIR)
|
||||||
|
SET(CMAKE_INSTALL_BINDIR bin)
|
||||||
|
ENDIF()
|
||||||
|
# The library output directory
|
||||||
|
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||||
|
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||||
# Support for pkg-config
|
# Support for pkg-config
|
||||||
SET(CMAKE_INSTALL_LIBDIR lib)
|
|
||||||
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
|
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
|
||||||
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
|
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
|
||||||
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
|
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
|
||||||
@@ -149,31 +254,75 @@ INSTALL(
|
|||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Confiugure the uninstall script
|
||||||
|
CONFIGURE_FILE(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||||
|
IMMEDIATE @ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add uninstall target
|
||||||
|
ADD_CUSTOM_TARGET(uninstall
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
||||||
|
|
||||||
# ******************
|
# ******************
|
||||||
# Add subdirectories
|
# Add subdirectories
|
||||||
# ******************
|
# ******************
|
||||||
ADD_SUBDIRECTORY(include)
|
|
||||||
ADD_SUBDIRECTORY(examples)
|
|
||||||
ADD_SUBDIRECTORY(src)
|
ADD_SUBDIRECTORY(src)
|
||||||
|
|
||||||
# Only include googletest if the git submodule has been fetched
|
IF(LIBTINS_BUILD_EXAMPLES)
|
||||||
IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt")
|
IF(LIBTINS_ENABLE_PCAP)
|
||||||
# Enable tests and add the test directory
|
ADD_SUBDIRECTORY(examples)
|
||||||
MESSAGE(STATUS "Tests have been enabled")
|
ELSE()
|
||||||
SET(gtest_force_shared_crt ON CACHE BOOL "Always use /MD")
|
MESSAGE(STATUS "Not building examples as pcap support is disabled")
|
||||||
SET(BUILD_GMOCK OFF)
|
ENDIF()
|
||||||
SET(BUILD_GTEST ON)
|
ENDIF()
|
||||||
ENABLE_TESTING()
|
|
||||||
ADD_SUBDIRECTORY(googletest)
|
IF(LIBTINS_BUILD_TESTS)
|
||||||
ADD_SUBDIRECTORY(tests)
|
# Only include googletest if the git submodule has been fetched
|
||||||
ELSE()
|
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
|
||||||
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
|
# Enable tests and add the test directory
|
||||||
|
MESSAGE(STATUS "Tests have been enabled")
|
||||||
|
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||||
|
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
|
||||||
|
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
|
||||||
|
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
|
||||||
|
|
||||||
|
ExternalProject_Add(
|
||||||
|
googletest
|
||||||
|
DOWNLOAD_COMMAND ""
|
||||||
|
SOURCE_DIR ${GOOGLETEST_ROOT}
|
||||||
|
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
|
||||||
|
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
|
||||||
|
"-Dgtest_force_shared_crt:bool=ON"
|
||||||
|
"-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER}"
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
)
|
||||||
|
# Make sure we build googletest before anything else
|
||||||
|
ADD_DEPENDENCIES(tins googletest)
|
||||||
|
ENABLE_TESTING()
|
||||||
|
ADD_SUBDIRECTORY(tests)
|
||||||
|
ELSE()
|
||||||
|
FIND_PACKAGE(GTest QUIET)
|
||||||
|
IF(${GTest_FOUND})
|
||||||
|
ENABLE_TESTING()
|
||||||
|
ADD_SUBDIRECTORY(tests)
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# **********************************
|
# **********************************
|
||||||
# CMake project configuration export
|
# CMake project configuration export
|
||||||
# **********************************
|
# **********************************
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
set(CONF_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/libtins")
|
||||||
|
else()
|
||||||
|
set(CONF_CMAKE_INSTALL_DIR CMake)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Add all targets to the build-tree export set
|
# Add all targets to the build-tree export set
|
||||||
EXPORT(
|
EXPORT(
|
||||||
TARGETS tins
|
TARGETS tins
|
||||||
@@ -200,13 +349,13 @@ INSTALL(
|
|||||||
FILES
|
FILES
|
||||||
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
|
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
|
||||||
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake"
|
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake"
|
||||||
DESTINATION CMake
|
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
|
||||||
COMPONENT dev
|
COMPONENT dev
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install the export set for use with the install-tree
|
# Install the export set for use with the install-tree
|
||||||
INSTALL(
|
INSTALL(
|
||||||
EXPORT libtinsTargets
|
EXPORT libtinsTargets
|
||||||
DESTINATION CMake
|
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
|
||||||
COMPONENT dev
|
COMPONENT dev
|
||||||
)
|
)
|
||||||
|
|||||||
27
CONTRIBUTING.md
Normal file
27
CONTRIBUTING.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Bug reports and enhancements to the library are really valued and appreciated!
|
||||||
|
|
||||||
|
# Bug reports
|
||||||
|
|
||||||
|
If you find a bug, please report it! Bugs on the library are taken seriously
|
||||||
|
and a patch for them is usually pushed on the same day.
|
||||||
|
|
||||||
|
When reporting a bug, please make sure to indicate the platform (e.g. GNU/Linux, Windows, OSX)
|
||||||
|
in which you came across the issue, as this is essential to finding the cause.
|
||||||
|
|
||||||
|
## Packet parsing bugs
|
||||||
|
|
||||||
|
If you find a bug related to packet parsing (e.g. a field on a packet contains an
|
||||||
|
invalid value), please try to provide a pcap file that contains the packet that
|
||||||
|
was incorrectly parsed. Doing this will make it very simple to find the issue, plus
|
||||||
|
you will be asked to provide this file anyway, so this just makes things
|
||||||
|
easier.
|
||||||
|
|
||||||
|
# Pull requests
|
||||||
|
|
||||||
|
Pull requests are very welcomed. When doing a pull request please:
|
||||||
|
|
||||||
|
* Notice that your code will be compiled and tests will be run automatically by the travis and
|
||||||
|
appveyor CI tools. If your code has issues on any of the tested platforms (GNU/Linux, Windows
|
||||||
|
and OSX), please fix it or otherwise the PR won't be merged.
|
||||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2012-2014, Matias Fontanini
|
Copyright (c) 2012-2017, Matias Fontanini
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
28
README.md
28
README.md
@@ -36,6 +36,7 @@ cmake ../
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Static/shared build
|
||||||
Note that by default, only the shared object is compiled. If you would
|
Note that by default, only the shared object is compiled. If you would
|
||||||
like to generate a static library file, run:
|
like to generate a static library file, run:
|
||||||
|
|
||||||
@@ -46,7 +47,9 @@ cmake ../ -DLIBTINS_BUILD_SHARED=0
|
|||||||
The generated static/shared library files will be located in the
|
The generated static/shared library files will be located in the
|
||||||
_build/lib_ directory.
|
_build/lib_ directory.
|
||||||
|
|
||||||
libtins is noticeable faster if you enable _C++11_ support. Therefore,
|
### C++11 support
|
||||||
|
|
||||||
|
libtins is noticeably faster if you enable _C++11_ support. Therefore,
|
||||||
if your compiler supports this standard, then you should enable it.
|
if your compiler supports this standard, then you should enable it.
|
||||||
In order to do so, use the _LIBTINS_ENABLE_CXX11_ switch:
|
In order to do so, use the _LIBTINS_ENABLE_CXX11_ switch:
|
||||||
|
|
||||||
@@ -54,6 +57,22 @@ In order to do so, use the _LIBTINS_ENABLE_CXX11_ switch:
|
|||||||
cmake ../ -DLIBTINS_ENABLE_CXX11=1
|
cmake ../ -DLIBTINS_ENABLE_CXX11=1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### TCP ACK tracker
|
||||||
|
|
||||||
|
The TCP ACK tracker feature requires the boost.icl library (header only).
|
||||||
|
This feature is enabled by default but will be disabled if the boost
|
||||||
|
headers are not found. You can disable this feature by using:
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
cmake ../ -DLIBTINS_ENABLE_ACK_TRACKER=0
|
||||||
|
```
|
||||||
|
|
||||||
|
If your boost installation is on some non-standard path, use
|
||||||
|
the parameters shown on the
|
||||||
|
[CMake FindBoost help](https://cmake.org/cmake/help/v3.0/module/FindBoost.html)
|
||||||
|
|
||||||
|
### WPA2 decryption
|
||||||
|
|
||||||
If you want to disable _WPA2_ decryption support, which will remove
|
If you want to disable _WPA2_ decryption support, which will remove
|
||||||
openssl as a dependency for compilation, use the
|
openssl as a dependency for compilation, use the
|
||||||
_LIBTINS_ENABLE_WPA2_ switch:
|
_LIBTINS_ENABLE_WPA2_ switch:
|
||||||
@@ -62,6 +81,8 @@ _LIBTINS_ENABLE_WPA2_ switch:
|
|||||||
cmake ../ -DLIBTINS_ENABLE_WPA2=0
|
cmake ../ -DLIBTINS_ENABLE_WPA2=0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### IEEE 802.11 support
|
||||||
|
|
||||||
If you want to disable IEEE 802.11 support(this will also disable
|
If you want to disable IEEE 802.11 support(this will also disable
|
||||||
RadioTap and WPA2 decryption), which will reduce the size of the
|
RadioTap and WPA2 decryption), which will reduce the size of the
|
||||||
resulting library in around 20%, use the _LIBTINS_ENABLE_DOT11_ switch:
|
resulting library in around 20%, use the _LIBTINS_ENABLE_DOT11_ switch:
|
||||||
@@ -119,3 +140,8 @@ You might want to have a look at the examples located in the "examples"
|
|||||||
directory. The same samples can be found online at:
|
directory. The same samples can be found online at:
|
||||||
|
|
||||||
http://libtins.github.io/examples/
|
http://libtins.github.io/examples/
|
||||||
|
|
||||||
|
## Contributing ##
|
||||||
|
|
||||||
|
If you want to report a bug or make a pull request, please have a look at
|
||||||
|
the [contributing](CONTRIBUTING.md) file before doing so.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
# HAS_CXX11_CONSTEXPR - constexpr keyword
|
# HAS_CXX11_CONSTEXPR - constexpr keyword
|
||||||
# HAS_CXX11_CSTDINT_H - cstdint header
|
# HAS_CXX11_CSTDINT_H - cstdint header
|
||||||
# HAS_CXX11_DECLTYPE - decltype keyword
|
# HAS_CXX11_DECLTYPE - decltype keyword
|
||||||
|
# HAS_CXX11_DECLVAL - declval feature
|
||||||
# HAS_CXX11_FUNC - __func__ preprocessor constant
|
# HAS_CXX11_FUNC - __func__ preprocessor constant
|
||||||
# HAS_CXX11_INITIALIZER_LIST - initializer list
|
# HAS_CXX11_INITIALIZER_LIST - initializer list
|
||||||
# HAS_CXX11_LAMBDA - lambdas
|
# HAS_CXX11_LAMBDA - lambdas
|
||||||
@@ -49,7 +50,7 @@ if (NOT CMAKE_CXX_COMPILER_LOADED)
|
|||||||
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
|
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8.3)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
#
|
#
|
||||||
### Check for needed compiler flags
|
### Check for needed compiler flags
|
||||||
@@ -68,24 +69,24 @@ endif ()
|
|||||||
|
|
||||||
function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
||||||
if (NOT DEFINED ${RESULT_VAR})
|
if (NOT DEFINED ${RESULT_VAR})
|
||||||
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11_${FEATURE_NAME}")
|
set(_bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${FEATURE_NAME}")
|
||||||
|
|
||||||
set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXX11Features/cxx11-test-${FEATURE_NAME})
|
set(_SRCFILE_BASE ${CMAKE_CURRENT_LIST_DIR}/CheckCXXFeatures/cxx-test-${FEATURE_NAME})
|
||||||
set(_LOG_NAME "\"${FEATURE_NAME}\"")
|
set(_LOG_NAME "\"${FEATURE_NAME}\"")
|
||||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}")
|
message(STATUS "Checking C++ support for ${_LOG_NAME}")
|
||||||
|
|
||||||
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
|
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
|
||||||
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
|
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
|
||||||
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
|
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
|
||||||
|
|
||||||
if (CROSS_COMPILING)
|
if (CMAKE_CROSSCOMPILING)
|
||||||
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
|
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
|
||||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||||
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
|
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
|
||||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||||
else (CROSS_COMPILING)
|
else (CMAKE_CROSSCOMPILING)
|
||||||
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
|
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
|
||||||
"${_bindir}" "${_SRCFILE}"
|
"${_bindir}" "${_SRCFILE}"
|
||||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||||
@@ -104,7 +105,7 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
|||||||
set(${RESULT_VAR} FALSE)
|
set(${RESULT_VAR} FALSE)
|
||||||
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
||||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||||
endif (CROSS_COMPILING)
|
endif (CMAKE_CROSSCOMPILING)
|
||||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
||||||
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
|
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
|
||||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||||
@@ -116,27 +117,19 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
|||||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
||||||
|
|
||||||
if (${RESULT_VAR})
|
if (${RESULT_VAR})
|
||||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}: works")
|
message(STATUS "Checking C++ support for ${_LOG_NAME}: works")
|
||||||
else (${RESULT_VAR})
|
else (${RESULT_VAR})
|
||||||
message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
|
message(STATUS "Checking C++ support for ${_LOG_NAME}: not supported")
|
||||||
endif (${RESULT_VAR})
|
endif (${RESULT_VAR})
|
||||||
set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++11 support for ${_LOG_NAME}")
|
set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++ support for ${_LOG_NAME}")
|
||||||
endif (NOT DEFINED ${RESULT_VAR})
|
endif (NOT DEFINED ${RESULT_VAR})
|
||||||
endfunction(cxx11_check_feature)
|
endfunction(cxx11_check_feature)
|
||||||
|
|
||||||
cxx11_check_feature("__func__" HAS_CXX11_FUNC)
|
|
||||||
cxx11_check_feature("auto" HAS_CXX11_AUTO)
|
|
||||||
cxx11_check_feature("auto_ret_type" HAS_CXX11_AUTO_RET_TYPE)
|
|
||||||
cxx11_check_feature("class_override_final" HAS_CXX11_CLASS_OVERRIDE)
|
|
||||||
cxx11_check_feature("constexpr" HAS_CXX11_CONSTEXPR)
|
|
||||||
cxx11_check_feature("cstdint" HAS_CXX11_CSTDINT_H)
|
|
||||||
cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
|
cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
|
||||||
|
cxx11_check_feature("declval" HAS_CXX11_DECLVAL)
|
||||||
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
|
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
|
||||||
cxx11_check_feature("lambda" HAS_CXX11_LAMBDA)
|
|
||||||
cxx11_check_feature("long_long" HAS_CXX11_LONG_LONG)
|
|
||||||
cxx11_check_feature("nullptr" HAS_CXX11_NULLPTR)
|
|
||||||
cxx11_check_feature("regex" HAS_CXX11_LIB_REGEX)
|
|
||||||
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
|
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
|
||||||
cxx11_check_feature("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
|
cxx11_check_feature("functional" HAS_CXX11_FUNCTIONAL)
|
||||||
cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
|
cxx11_check_feature("chrono" HAS_CXX11_CHRONO)
|
||||||
cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)
|
cxx11_check_feature("noexcept" HAS_CXX11_NOEXCEPT)
|
||||||
|
cxx11_check_feature("builtin-swap" HAS_GCC_BUILTIN_SWAP)
|
||||||
8
cmake/Modules/CheckCXXFeatures/cxx-test-builtin-swap.cpp
Normal file
8
cmake/Modules/CheckCXXFeatures/cxx-test-builtin-swap.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
uint16_t u16 = __builtin_bswap16(0x9812U);
|
||||||
|
uint32_t u32 = __builtin_bswap32(0x9812ad81U);
|
||||||
|
uint64_t u64 = __builtin_bswap64(0x9812ad81f61a890dU);
|
||||||
|
return (u16 > 0 && u32 > 0 && u64 > 0) ? 0 : 1;
|
||||||
|
}
|
||||||
9
cmake/Modules/CheckCXXFeatures/cxx-test-chrono.cpp
Normal file
9
cmake/Modules/CheckCXXFeatures/cxx-test-chrono.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
system_clock::time_point tp = system_clock::now();
|
||||||
|
milliseconds ms = duration_cast<milliseconds>(tp.time_since_epoch());
|
||||||
|
return (ms.count() > 0) ? 0 : 1;
|
||||||
|
}
|
||||||
19
cmake/Modules/CheckCXXFeatures/cxx-test-declval.cpp
Normal file
19
cmake/Modules/CheckCXXFeatures/cxx-test-declval.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Example code taken from http://en.cppreference.com/w/cpp/utility/declval
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
struct Default { int foo() const { return 1; } };
|
||||||
|
|
||||||
|
struct NonDefault
|
||||||
|
{
|
||||||
|
NonDefault(const NonDefault&) { }
|
||||||
|
int foo() const { return 1; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
decltype(Default().foo()) n1 = 1; // type of n1 is int
|
||||||
|
decltype(std::declval<NonDefault>().foo()) n2 = n1; // type of n2 is int
|
||||||
|
return (n1 == 1 && n2 == 1) ? 0 : 1;
|
||||||
|
}
|
||||||
11
cmake/Modules/CheckCXXFeatures/cxx-test-functional.cpp
Normal file
11
cmake/Modules/CheckCXXFeatures/cxx-test-functional.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <functional>
|
||||||
|
|
||||||
|
int add(int x, int y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::function<int(int, int)> func;
|
||||||
|
func = std::bind(&add, std::placeholders::_1, std::placeholders::_2);
|
||||||
|
return (func(2, 2) == 4) ? 0 : 1;
|
||||||
|
}
|
||||||
7
cmake/Modules/CheckCXXFeatures/cxx-test-noexcept.cpp
Normal file
7
cmake/Modules/CheckCXXFeatures/cxx-test-noexcept.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
int foo() noexcept {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
return foo();
|
||||||
|
}
|
||||||
@@ -75,6 +75,7 @@ include(CheckFunctionExists)
|
|||||||
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
|
||||||
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
|
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
|
||||||
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
|
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
|
||||||
|
check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_TIMESTAMP_PRECISION)
|
||||||
set(CMAKE_REQUIRED_LIBRARIES)
|
set(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ configuration:
|
|||||||
platform:
|
platform:
|
||||||
- Win32
|
- Win32
|
||||||
- x64
|
- x64
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- compiler: vs2013
|
||||||
|
- compiler: vs2015
|
||||||
|
BOOST_ROOT: C:/Libraries/boost
|
||||||
clone_depth: 1
|
clone_depth: 1
|
||||||
install:
|
install:
|
||||||
- git clone https://github.com/mfontanini/winpcap-installer.git
|
- git clone https://github.com/mfontanini/winpcap-installer.git
|
||||||
@@ -18,8 +23,12 @@ install:
|
|||||||
before_build:
|
before_build:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd build
|
- cd build
|
||||||
- if "%platform%"=="x64" ( set GENERATOR="Visual Studio 12 Win64" ) else ( set GENERATOR="Visual Studio 12" )
|
- if "%compiler%"=="vs2013" (set VS_VERSION=12) else (set VS_VERSION=14)
|
||||||
- cmake .. -G %GENERATOR% -DPCAP_ROOT_DIR=c:\WpdPack -DLIBTINS_BUILD_SHARED=0 -DLIBTINS_ENABLE_WPA2=0 -DLIBTINS_ENABLE_CXX11=1
|
- set VS=Visual Studio %VS_VERSION%
|
||||||
|
- if "%platform%"=="Win32" (set GENERATOR="%VS%" & set ARCH_BITS=32)
|
||||||
|
- if "%platform%"=="x64" (set GENERATOR="%VS% Win64" & set ARCH_BITS=64)
|
||||||
|
- set BOOST_LIBRARYDIR=C:\Libraries\boost\lib%ARCH_BITS%-msvc-%VS_VERSION%.0
|
||||||
|
- cmake .. -G %GENERATOR% -DPCAP_ROOT_DIR=c:\WpdPack -DLIBTINS_BUILD_SHARED=0 -DLIBTINS_ENABLE_WPA2=0 -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DBoost_USE_STATIC_LIBS="ON"
|
||||||
build:
|
build:
|
||||||
project: C:/projects/libtins/build/libtins.sln
|
project: C:/projects/libtins/build/libtins.sln
|
||||||
verbosity: minimal
|
verbosity: minimal
|
||||||
@@ -34,11 +43,11 @@ after_build:
|
|||||||
- del include\tins\config.h.in
|
- del include\tins\config.h.in
|
||||||
- del include\tins\dot11\CMakeLists.txt
|
- del include\tins\dot11\CMakeLists.txt
|
||||||
- cd ..\
|
- cd ..\
|
||||||
- 7z a libtins-%platform%-%Configuration%.zip libtins
|
- 7z a libtins-%compiler%-%platform%-%Configuration%.zip libtins
|
||||||
test_script:
|
test_script:
|
||||||
- cd c:\projects\libtins\build
|
- cd c:\projects\libtins\build
|
||||||
- ctest -C %Configuration%
|
- ctest -C %Configuration% -V
|
||||||
deploy_script:
|
deploy_script:
|
||||||
- ps: Push-AppveyorArtifact "install\libtins-$env:Platform-$env:Configuration.zip"
|
- ps: Push-AppveyorArtifact "install\libtins-$env:Compiler-$env:Platform-$env:Configuration.zip"
|
||||||
skip_commits:
|
skip_commits:
|
||||||
message: /Update documentation.*/
|
message: /Update documentation.*/
|
||||||
|
|||||||
23
cmake/cmake_uninstall.cmake.in
Normal file
23
cmake/cmake_uninstall.cmake.in
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Taken from https://cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
|
||||||
|
|
||||||
|
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||||
|
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||||
|
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||||
|
|
||||||
|
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
|
||||||
|
string(REGEX REPLACE "\n" ";" files "${files}")
|
||||||
|
foreach(file ${files})
|
||||||
|
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
|
||||||
|
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
exec_program(
|
||||||
|
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||||
|
OUTPUT_VARIABLE rm_out
|
||||||
|
RETURN_VALUE rm_retval
|
||||||
|
)
|
||||||
|
if(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
|
||||||
|
endif(NOT "${rm_retval}" STREQUAL 0)
|
||||||
|
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
|
||||||
|
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
|
||||||
|
endforeach(file)
|
||||||
@@ -1365,7 +1365,9 @@ INCLUDE_FILE_PATTERNS =
|
|||||||
# undefined via #undef or recursively expanded use the := operator
|
# undefined via #undef or recursively expanded use the := operator
|
||||||
# instead of the = operator.
|
# instead of the = operator.
|
||||||
|
|
||||||
PREDEFINED =
|
PREDEFINED = "TINS_IS_CXX11=1" \
|
||||||
|
"TINS_HAVE_WPA2_CALLBACKS=1" \
|
||||||
|
"TINS_HAVE_DOT11=1"
|
||||||
|
|
||||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||||
# this tag can be used to specify a list of macro names that should be expanded.
|
# this tag can be used to specify a list of macro names that should be expanded.
|
||||||
|
|||||||
@@ -1,73 +1,81 @@
|
|||||||
FIND_PACKAGE(libtins QUIET)
|
|
||||||
FIND_PACKAGE(Threads QUIET)
|
FIND_PACKAGE(Threads QUIET)
|
||||||
|
FIND_PACKAGE(Boost COMPONENTS regex)
|
||||||
|
|
||||||
IF(libtins_FOUND)
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
INCLUDE_DIRECTORIES(
|
||||||
INCLUDE_DIRECTORIES(
|
${CMAKE_CURRENT_SOURCE_DIR}/../include
|
||||||
${LIBTINS_INCLUDE_DIRS}
|
${PCAP_INCLUDE_DIR}
|
||||||
${PCAP_INCLUDE_DIR}
|
)
|
||||||
|
LINK_LIBRARIES(tins)
|
||||||
|
|
||||||
|
IF(TINS_HAVE_CXX11)
|
||||||
|
SET(LIBTINS_CXX11_EXAMPLES
|
||||||
|
arpmonitor
|
||||||
|
dns_queries
|
||||||
|
dns_spoof
|
||||||
|
dns_stats
|
||||||
|
stream_dump
|
||||||
|
icmp_responses
|
||||||
|
interfaces_info
|
||||||
|
tcp_connection_close
|
||||||
|
traceroute
|
||||||
|
wps_detect
|
||||||
)
|
)
|
||||||
LINK_LIBRARIES(${LIBTINS_LIBRARIES})
|
IF(Boost_REGEX_FOUND)
|
||||||
|
SET(LIBTINS_CXX11_EXAMPLES ${LIBTINS_CXX11_EXAMPLES} http_requests)
|
||||||
IF(HAVE_CXX11)
|
|
||||||
SET(LIBTINS_CXX11_EXAMPLES
|
|
||||||
arpmonitor
|
|
||||||
dns_queries
|
|
||||||
dns_spoof
|
|
||||||
dns_stats
|
|
||||||
icmp_responses
|
|
||||||
interfaces_info
|
|
||||||
tcp_connection_close
|
|
||||||
traceroute
|
|
||||||
wps_detect
|
|
||||||
)
|
|
||||||
ELSE(HAVE_CXX11)
|
|
||||||
MESSAGE(WARNING "Disabling some examples since C++11 support is disabled.")
|
|
||||||
ENDIF(HAVE_CXX11)
|
|
||||||
|
|
||||||
ADD_CUSTOM_TARGET(
|
|
||||||
examples DEPENDS
|
|
||||||
arpspoofing
|
|
||||||
${LIBTINS_CXX11_EXAMPLES}
|
|
||||||
beacon_display
|
|
||||||
portscan
|
|
||||||
route_table
|
|
||||||
)
|
|
||||||
|
|
||||||
ADD_EXECUTABLE(arpspoofing EXCLUDE_FROM_ALL arpspoofing.cpp)
|
|
||||||
ADD_EXECUTABLE(route_table EXCLUDE_FROM_ALL route_table.cpp)
|
|
||||||
IF(HAVE_CXX11)
|
|
||||||
ADD_EXECUTABLE(arpmonitor EXCLUDE_FROM_ALL arpmonitor.cpp)
|
|
||||||
ADD_EXECUTABLE(dns_queries EXCLUDE_FROM_ALL dns_queries.cpp)
|
|
||||||
ADD_EXECUTABLE(dns_spoof EXCLUDE_FROM_ALL dns_spoof.cpp)
|
|
||||||
ADD_EXECUTABLE(icmp_responses EXCLUDE_FROM_ALL icmp_responses.cpp)
|
|
||||||
ADD_EXECUTABLE(interfaces_info EXCLUDE_FROM_ALL interfaces_info.cpp)
|
|
||||||
ADD_EXECUTABLE(tcp_connection_close EXCLUDE_FROM_ALL tcp_connection_close.cpp)
|
|
||||||
ADD_EXECUTABLE(wps_detect EXCLUDE_FROM_ALL wps_detect.cpp)
|
|
||||||
ENDIF(HAVE_CXX11)
|
|
||||||
|
|
||||||
ADD_EXECUTABLE(beacon_display EXCLUDE_FROM_ALL beacon_display.cpp)
|
|
||||||
|
|
||||||
if(THREADS_FOUND)
|
|
||||||
IF(HAVE_CXX11)
|
|
||||||
ADD_EXECUTABLE(traceroute EXCLUDE_FROM_ALL traceroute.cpp)
|
|
||||||
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
|
|
||||||
TARGET_LINK_LIBRARIES(traceroute ${CMAKE_THREAD_LIBS_INIT})
|
|
||||||
TARGET_LINK_LIBRARIES(dns_stats ${CMAKE_THREAD_LIBS_INIT})
|
|
||||||
ENDIF(HAVE_CXX11)
|
|
||||||
IF(WIN32)
|
|
||||||
MESSAGE(WARNING "Disabling portscan example since it doesn't compile on Windows.")
|
|
||||||
ELSE()
|
|
||||||
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
|
|
||||||
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
|
|
||||||
ENDIF()
|
|
||||||
ELSE()
|
ELSE()
|
||||||
MESSAGE(WARNING "Disabling portscan and traceroute examples since pthreads library was not found.")
|
MESSAGE(WARNING "Disabling HTTP requests example since boost.regex was not found")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ELSE(libtins_FOUND)
|
ELSE(TINS_HAVE_CXX11)
|
||||||
MESSAGE(
|
MESSAGE(WARNING "Disabling some examples since C++11 support is disabled.")
|
||||||
WARNING
|
ENDIF(TINS_HAVE_CXX11)
|
||||||
"Disabling examples since libtins is not installed. "
|
|
||||||
"Run cmake again once it is installed in order to compile them."
|
ADD_CUSTOM_TARGET(
|
||||||
)
|
examples DEPENDS
|
||||||
ENDIF(libtins_FOUND)
|
arpspoofing
|
||||||
|
${LIBTINS_CXX11_EXAMPLES}
|
||||||
|
beacon_display
|
||||||
|
portscan
|
||||||
|
route_table
|
||||||
|
defragmenter
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure we first build libtins
|
||||||
|
ADD_DEPENDENCIES(examples tins)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(arpspoofing EXCLUDE_FROM_ALL arpspoofing.cpp)
|
||||||
|
ADD_EXECUTABLE(route_table EXCLUDE_FROM_ALL route_table.cpp)
|
||||||
|
ADD_EXECUTABLE(defragmenter EXCLUDE_FROM_ALL defragmenter.cpp)
|
||||||
|
IF(TINS_HAVE_CXX11)
|
||||||
|
ADD_EXECUTABLE(arpmonitor EXCLUDE_FROM_ALL arpmonitor.cpp)
|
||||||
|
ADD_EXECUTABLE(dns_queries EXCLUDE_FROM_ALL dns_queries.cpp)
|
||||||
|
ADD_EXECUTABLE(dns_spoof EXCLUDE_FROM_ALL dns_spoof.cpp)
|
||||||
|
ADD_EXECUTABLE(stream_dump EXCLUDE_FROM_ALL stream_dump.cpp)
|
||||||
|
ADD_EXECUTABLE(icmp_responses EXCLUDE_FROM_ALL icmp_responses.cpp)
|
||||||
|
ADD_EXECUTABLE(interfaces_info EXCLUDE_FROM_ALL interfaces_info.cpp)
|
||||||
|
ADD_EXECUTABLE(tcp_connection_close EXCLUDE_FROM_ALL tcp_connection_close.cpp)
|
||||||
|
ADD_EXECUTABLE(wps_detect EXCLUDE_FROM_ALL wps_detect.cpp)
|
||||||
|
IF (Boost_REGEX_FOUND)
|
||||||
|
ADD_EXECUTABLE(http_requests EXCLUDE_FROM_ALL http_requests.cpp)
|
||||||
|
TARGET_LINK_LIBRARIES(http_requests ${Boost_LIBRARIES})
|
||||||
|
ENDIF()
|
||||||
|
ENDIF(TINS_HAVE_CXX11)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(beacon_display EXCLUDE_FROM_ALL beacon_display.cpp)
|
||||||
|
|
||||||
|
if(THREADS_FOUND)
|
||||||
|
IF(TINS_HAVE_CXX11)
|
||||||
|
ADD_EXECUTABLE(traceroute EXCLUDE_FROM_ALL traceroute.cpp)
|
||||||
|
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
|
||||||
|
TARGET_LINK_LIBRARIES(traceroute ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
TARGET_LINK_LIBRARIES(dns_stats ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
ENDIF(TINS_HAVE_CXX11)
|
||||||
|
IF(WIN32)
|
||||||
|
MESSAGE(WARNING "Disabling portscan example since it doesn't compile on Windows.")
|
||||||
|
ELSE()
|
||||||
|
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
|
||||||
|
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
ENDIF()
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(WARNING "Disabling portscan and traceroute examples since pthreads library was not found.")
|
||||||
|
ENDIF()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -88,7 +88,7 @@ void do_arp_spoofing(NetworkInterface iface,
|
|||||||
sender.send(to_gw, iface);
|
sender.send(to_gw, iface);
|
||||||
sender.send(to_victim, iface);
|
sender.send(to_victim, iface);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep(5);
|
Sleep(5000);
|
||||||
#else
|
#else
|
||||||
sleep(5);
|
sleep(5);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
118
examples/defragmenter.cpp
Normal file
118
examples/defragmenter.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include "tins/ip.h"
|
||||||
|
#include "tins/ip_reassembler.h"
|
||||||
|
#include "tins/sniffer.h"
|
||||||
|
#include "tins/packet_writer.h"
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::cerr;
|
||||||
|
using std::endl;
|
||||||
|
using std::string;
|
||||||
|
using std::exception;
|
||||||
|
|
||||||
|
using Tins::IPv4Reassembler;
|
||||||
|
using Tins::IP;
|
||||||
|
using Tins::Packet;
|
||||||
|
using Tins::FileSniffer;
|
||||||
|
using Tins::PacketWriter;
|
||||||
|
using Tins::DataLinkType;
|
||||||
|
|
||||||
|
// This example reads packets from a pcap file and writes them to a new file.
|
||||||
|
// If any IPv4 fragmented packets are found in the input file, then they will
|
||||||
|
// be reassembled before writing them, so instead of the individual fragments
|
||||||
|
// it will write the whole packet.
|
||||||
|
|
||||||
|
class Defragmenter {
|
||||||
|
public:
|
||||||
|
// Construct the sniffer and the packet writer using the sniffer's
|
||||||
|
// data link type
|
||||||
|
Defragmenter(const string& input_file, const string& output_file)
|
||||||
|
: sniffer_(input_file),
|
||||||
|
writer_(output_file, (PacketWriter::LinkType)sniffer_.link_type()),
|
||||||
|
total_reassembled_(0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void run() {
|
||||||
|
Packet packet;
|
||||||
|
// Read packets and keep going until there's no more packets to read
|
||||||
|
while (packet = sniffer_.next_packet()) {
|
||||||
|
// Try to reassemble the packet
|
||||||
|
IPv4Reassembler::PacketStatus status = reassembler_.process(*packet.pdu());
|
||||||
|
|
||||||
|
// If we did reassemble it, increase this counter
|
||||||
|
if (status == IPv4Reassembler::REASSEMBLED) {
|
||||||
|
total_reassembled_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regardless, we'll write it into the output file unless it's fragmented
|
||||||
|
// (and not yet reassembled)
|
||||||
|
if (status != IPv4Reassembler::FRAGMENTED) {
|
||||||
|
writer_.write(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t total_packets_reassembled() const {
|
||||||
|
return total_reassembled_;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
FileSniffer sniffer_;
|
||||||
|
IPv4Reassembler reassembler_;
|
||||||
|
PacketWriter writer_;
|
||||||
|
uint64_t total_reassembled_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc != 3) {
|
||||||
|
cout << "Usage: " << argv[0] << " <input-file> <output-file>" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Build the defragmented
|
||||||
|
Defragmenter defragmenter(argv[1], argv[2]);
|
||||||
|
cout << "Processing " << argv[1] << endl;
|
||||||
|
cout << "Writing results to " << argv[2] << endl;
|
||||||
|
|
||||||
|
// Run!
|
||||||
|
defragmenter.run();
|
||||||
|
cout << "Done" << endl;
|
||||||
|
cout << "Reassembled: " << defragmenter.total_packets_reassembled()
|
||||||
|
<< " packet(s)" << endl;
|
||||||
|
}
|
||||||
|
catch (exception& ex) {
|
||||||
|
cerr << "Error: " << ex.what() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
|
|||||||
cout << "Usage: " <<* argv << " <interface>" << endl;
|
cout << "Usage: " <<* argv << " <interface>" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Sniff on the provided interface in promiscuos mode
|
// Sniff on the provided interface in promiscuous mode
|
||||||
SnifferConfiguration config;
|
SnifferConfiguration config;
|
||||||
config.set_promisc_mode(true);
|
config.set_promisc_mode(true);
|
||||||
// Only capture udp packets sent to port 53
|
// Only capture udp packets sent to port 53
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -56,7 +56,7 @@ bool callback(const PDU& pdu) {
|
|||||||
if (query.query_type() == DNS::A) {
|
if (query.query_type() == DNS::A) {
|
||||||
// Here's one! Let's add an answer.
|
// Here's one! Let's add an answer.
|
||||||
dns.add_answer(
|
dns.add_answer(
|
||||||
DNS::Resource(
|
DNS::resource(
|
||||||
query.dname(),
|
query.dname(),
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
DNS::A,
|
DNS::A,
|
||||||
@@ -90,9 +90,11 @@ int main(int argc, char* argv[]) {
|
|||||||
cout << "Usage: " <<* argv << " <interface>" << endl;
|
cout << "Usage: " <<* argv << " <interface>" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Sniff on the provided interface in promiscuos mode
|
// Sniff on the provided interface in promiscuous mode
|
||||||
SnifferConfiguration config;
|
SnifferConfiguration config;
|
||||||
config.set_promisc_mode(true);
|
config.set_promisc_mode(true);
|
||||||
|
// Use immediate mode so we get the packets as fast as we can
|
||||||
|
config.set_immediate_mode(true);
|
||||||
// Only capture udp packets sent to port 53
|
// Only capture udp packets sent to port 53
|
||||||
config.set_filter("udp and dst port 53");
|
config.set_filter("udp and dst port 53");
|
||||||
Sniffer sniffer(argv[1], config);
|
Sniffer sniffer(argv[1], config);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,6 +31,9 @@
|
|||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
// Fix for gcc 4.6
|
||||||
|
#define _GLIBCXX_USE_NANOSLEEP
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -65,8 +68,8 @@ using namespace Tins;
|
|||||||
template<typename Duration>
|
template<typename Duration>
|
||||||
class statistics {
|
class statistics {
|
||||||
public:
|
public:
|
||||||
using duration_type = Duration;
|
typedef Duration duration_type;
|
||||||
using locker_type = lock_guard<mutex>;
|
typedef lock_guard<mutex> locker_type;
|
||||||
|
|
||||||
struct information {
|
struct information {
|
||||||
duration_type average, worst;
|
duration_type average, worst;
|
||||||
@@ -108,18 +111,18 @@ private:
|
|||||||
class dns_monitor {
|
class dns_monitor {
|
||||||
public:
|
public:
|
||||||
// The response times are measured in milliseconds
|
// The response times are measured in milliseconds
|
||||||
using duration_type = milliseconds;
|
typedef milliseconds duration_type;
|
||||||
// The statistics type used.
|
// The statistics type used.
|
||||||
using statistics_type = statistics<duration_type>;
|
typedef statistics<duration_type> statistics_type;
|
||||||
|
|
||||||
void run(BaseSniffer& sniffer);
|
void run(BaseSniffer& sniffer);
|
||||||
const statistics_type& stats() const {
|
const statistics_type& stats() const {
|
||||||
return m_stats;
|
return m_stats;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
using packet_info = tuple<IPv4Address, IPv4Address, uint16_t>;
|
typedef tuple<IPv4Address, IPv4Address, uint16_t> packet_info;
|
||||||
using clock_type = system_clock;
|
typedef system_clock clock_type;
|
||||||
using time_point_type = clock_type::time_point;
|
typedef clock_type::time_point time_point_type;
|
||||||
|
|
||||||
bool callback(const PDU& pdu);
|
bool callback(const PDU& pdu);
|
||||||
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);
|
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);
|
||||||
|
|||||||
147
examples/http_requests.cpp
Normal file
147
examples/http_requests.cpp
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
#include "tins/tcp_ip/stream_follower.h"
|
||||||
|
#include "tins/sniffer.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::cout;
|
||||||
|
using std::cerr;
|
||||||
|
using std::endl;
|
||||||
|
using std::exception;
|
||||||
|
|
||||||
|
using boost::regex;
|
||||||
|
using boost::match_results;
|
||||||
|
|
||||||
|
using Tins::PDU;
|
||||||
|
using Tins::Sniffer;
|
||||||
|
using Tins::SnifferConfiguration;
|
||||||
|
using Tins::TCPIP::Stream;
|
||||||
|
using Tins::TCPIP::StreamFollower;
|
||||||
|
|
||||||
|
// This example captures and follows TCP streams seen on port 80. It will
|
||||||
|
// wait until both the client and server send data and then apply a regex
|
||||||
|
// to both payloads, extrating some information and printing it.
|
||||||
|
|
||||||
|
// Don't buffer more than 3kb of data in either request/response
|
||||||
|
const size_t MAX_PAYLOAD = 3 * 1024;
|
||||||
|
// The regex to be applied on the request. This will extract the HTTP
|
||||||
|
// method being used, the request's path and the Host header value.
|
||||||
|
regex request_regex("([\\w]+) ([^ ]+).+\r\nHost: ([\\d\\w\\.-]+)\r\n");
|
||||||
|
// The regex to be applied on the response. This finds the response code.
|
||||||
|
regex response_regex("HTTP/[^ ]+ ([\\d]+)");
|
||||||
|
|
||||||
|
void on_server_data(Stream& stream) {
|
||||||
|
match_results<Stream::payload_type::const_iterator> client_match;
|
||||||
|
match_results<Stream::payload_type::const_iterator> server_match;
|
||||||
|
const Stream::payload_type& client_payload = stream.client_payload();
|
||||||
|
const Stream::payload_type& server_payload = stream.server_payload();
|
||||||
|
// Run the regexes on client/server payloads
|
||||||
|
bool valid = regex_search(server_payload.begin(), server_payload.end(),
|
||||||
|
server_match, response_regex) &&
|
||||||
|
regex_search(client_payload.begin(), client_payload.end(),
|
||||||
|
client_match, request_regex);
|
||||||
|
// If we matched both the client and the server regexes
|
||||||
|
if (valid) {
|
||||||
|
// Extract all fields
|
||||||
|
string method = string(client_match[1].first, client_match[1].second);
|
||||||
|
string url = string(client_match[2].first, client_match[2].second);
|
||||||
|
string host = string(client_match[3].first, client_match[3].second);
|
||||||
|
string response_code = string(server_match[1].first, server_match[1].second);
|
||||||
|
// Now print them
|
||||||
|
cout << method << " http://" << host << url << " -> " << response_code << endl;
|
||||||
|
|
||||||
|
// Once we've seen the first request on this stream, ignore it
|
||||||
|
stream.ignore_client_data();
|
||||||
|
stream.ignore_server_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just in case the server returns invalid data, stop at 3kb
|
||||||
|
if (stream.server_payload().size() > MAX_PAYLOAD) {
|
||||||
|
stream.ignore_server_data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_client_data(Stream& stream) {
|
||||||
|
// Don't hold more than 3kb of data from the client's flow
|
||||||
|
if (stream.client_payload().size() > MAX_PAYLOAD) {
|
||||||
|
stream.ignore_client_data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_new_connection(Stream& stream) {
|
||||||
|
stream.client_data_callback(&on_client_data);
|
||||||
|
stream.server_data_callback(&on_server_data);
|
||||||
|
// Don't automatically cleanup the stream's data, as we'll manage
|
||||||
|
// the buffer ourselves and let it grow until we see a full request
|
||||||
|
// and response
|
||||||
|
stream.auto_cleanup_payloads(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc != 2) {
|
||||||
|
cout << "Usage: " << argv[0] << " <interface>" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Construct the sniffer configuration object
|
||||||
|
SnifferConfiguration config;
|
||||||
|
// Get packets as quickly as possible
|
||||||
|
config.set_immediate_mode(true);
|
||||||
|
// Only capture TCP traffic sent from/to port 80
|
||||||
|
config.set_filter("tcp port 80");
|
||||||
|
// Construct the sniffer we'll use
|
||||||
|
Sniffer sniffer(argv[1], config);
|
||||||
|
|
||||||
|
cout << "Starting capture on interface " << argv[1] << endl;
|
||||||
|
|
||||||
|
// Now construct the stream follower
|
||||||
|
StreamFollower follower;
|
||||||
|
// We just need to specify the callback to be executed when a new
|
||||||
|
// stream is captured. In this stream, you should define which callbacks
|
||||||
|
// will be executed whenever new data is sent on that stream
|
||||||
|
// (see on_new_connection)
|
||||||
|
follower.new_stream_callback(&on_new_connection);
|
||||||
|
// Now start capturing. Every time there's a new packet, call
|
||||||
|
// follower.process_packet
|
||||||
|
sniffer.sniff_loop([&](PDU& packet) {
|
||||||
|
follower.process_packet(packet);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (exception& ex) {
|
||||||
|
cerr << "Error: " << ex.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,11 +29,14 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <tins/network_interface.h>
|
#include <tins/network_interface.h>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
using std::wcout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::ostringstream;
|
||||||
|
|
||||||
using namespace Tins;
|
using namespace Tins;
|
||||||
|
|
||||||
@@ -50,12 +53,35 @@ int main() {
|
|||||||
NetworkInterface::Info info = iface.info();
|
NetworkInterface::Info info = iface.info();
|
||||||
|
|
||||||
// Now print all of this info.
|
// Now print all of this info.
|
||||||
cout << name << ": " << endl;
|
cout << name;
|
||||||
cout << " HW address: " << info.hw_addr << endl
|
|
||||||
<< " IP address: " << info.ip_addr << endl
|
#ifdef _WIN32
|
||||||
<< " Netmask: " << info.netmask << endl
|
// If this is running on Windows, also print the friendly name
|
||||||
<< " Broadcast: " << info.bcast_addr << endl
|
wcout << " (" << iface.friendly_name() << ")";
|
||||||
<< " Iface index: " << iface.id() << endl
|
#endif // _WIN32
|
||||||
<< " Status: " << "interface " << status << endl << endl;
|
cout << ": " << endl;
|
||||||
|
|
||||||
|
string ipv6_string;
|
||||||
|
if (info.ipv6_addrs.empty()) {
|
||||||
|
ipv6_string = "(none)";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ostringstream oss;
|
||||||
|
for (size_t i = 0; i < info.ipv6_addrs.size(); ++i) {
|
||||||
|
const NetworkInterface::IPv6Prefix& prefix = info.ipv6_addrs[i];
|
||||||
|
if (i > 0) {
|
||||||
|
oss << ", ";
|
||||||
|
}
|
||||||
|
oss << prefix.address << "/" << prefix.prefix_length;
|
||||||
|
}
|
||||||
|
ipv6_string = oss.str();
|
||||||
|
}
|
||||||
|
cout << " HW address: " << info.hw_addr << endl
|
||||||
|
<< " IP address: " << info.ip_addr << endl
|
||||||
|
<< " IPv6 addresses: " << ipv6_string << endl
|
||||||
|
<< " Netmask: " << info.netmask << endl
|
||||||
|
<< " Broadcast: " << info.bcast_addr << endl
|
||||||
|
<< " Iface index: " << iface.id() << endl
|
||||||
|
<< " Status: " << "interface " << status << endl << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -116,7 +116,7 @@ bool Scanner::callback(PDU& pdu) {
|
|||||||
cout << "Port: " << setw(5) << tcp.sport() << " closed\n";
|
cout << "Port: " << setw(5) << tcp.sport() << " closed\n";
|
||||||
}
|
}
|
||||||
// Is SYN flag on? Then port is open!
|
// Is SYN flag on? Then port is open!
|
||||||
else if(tcp.flags() == (TCP::SYN | TCP::ACK)) {
|
else if(tcp.has_flags(TCP::SYN | TCP::ACK)) {
|
||||||
cout << "Port: " << setw(5) << tcp.sport() << " open\n";
|
cout << "Port: " << setw(5) << tcp.sport() << " open\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,30 @@ using std::vector;
|
|||||||
using namespace Tins;
|
using namespace Tins;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vector<Utils::RouteEntry> entries = Utils::route_entries();
|
vector<Utils::RouteEntry> v4_entries = Utils::route_entries();
|
||||||
for (size_t i = 0; i < entries.size(); ++i) {
|
cout << "IPv4 route table entries: " << endl
|
||||||
|
<< "========================= " << endl;
|
||||||
|
for (size_t i = 0; i < v4_entries.size(); ++i) {
|
||||||
cout << "Entry " << setw(2) << i << ": " << endl
|
cout << "Entry " << setw(2) << i << ": " << endl
|
||||||
<< "Interface: " << entries[i].interface << endl
|
<< "Interface: " << v4_entries[i].interface << endl
|
||||||
<< "Destination: " << entries[i].destination << endl
|
<< "Destination: " << v4_entries[i].destination << endl
|
||||||
<< "Gateway: " << entries[i].gateway << endl
|
<< "Gateway: " << v4_entries[i].gateway << endl
|
||||||
<< "Genmask: " << entries[i].mask << endl
|
<< "Genmask: " << v4_entries[i].mask << endl
|
||||||
<< "Metric: " << entries[i].metric << endl << endl;
|
<< "Metric: " << v4_entries[i].metric << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Utils::Route6Entry> v6_entries = Utils::route6_entries();
|
||||||
|
if (!v6_entries.empty()) {
|
||||||
|
cout << endl
|
||||||
|
<< "IPv6 route table entries: " << endl
|
||||||
|
<< "========================= " << endl;
|
||||||
|
for (size_t i = 0; i < v6_entries.size(); ++i) {
|
||||||
|
cout << "Entry " << setw(2) << i << ": " << endl
|
||||||
|
<< "Interface: " << v6_entries[i].interface << endl
|
||||||
|
<< "Destination: " << v6_entries[i].destination << endl
|
||||||
|
<< "Gateway: " << v6_entries[i].gateway << endl
|
||||||
|
<< "Genmask: " << v6_entries[i].mask << endl
|
||||||
|
<< "Metric: " << v6_entries[i].metric << endl << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
192
examples/stream_dump.cpp
Normal file
192
examples/stream_dump.cpp
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "tins/tcp_ip/stream_follower.h"
|
||||||
|
#include "tins/sniffer.h"
|
||||||
|
#include "tins/packet.h"
|
||||||
|
#include "tins/ip_address.h"
|
||||||
|
#include "tins/ipv6_address.h"
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::cerr;
|
||||||
|
using std::endl;
|
||||||
|
using std::bind;
|
||||||
|
using std::string;
|
||||||
|
using std::to_string;
|
||||||
|
using std::ostringstream;
|
||||||
|
using std::exception;
|
||||||
|
|
||||||
|
using Tins::Sniffer;
|
||||||
|
using Tins::SnifferConfiguration;
|
||||||
|
using Tins::PDU;
|
||||||
|
using Tins::TCPIP::StreamFollower;
|
||||||
|
using Tins::TCPIP::Stream;
|
||||||
|
|
||||||
|
// This example takes an interface and a port as an argument and
|
||||||
|
// it listens for TCP streams on the given interface and port.
|
||||||
|
// It will reassemble TCP streams and show the traffic sent by
|
||||||
|
// both the client and the server.
|
||||||
|
|
||||||
|
// Convert the client endpoint to a readable string
|
||||||
|
string client_endpoint(const Stream& stream) {
|
||||||
|
ostringstream output;
|
||||||
|
// Use the IPv4 or IPv6 address depending on which protocol the
|
||||||
|
// connection uses
|
||||||
|
if (stream.is_v6()) {
|
||||||
|
output << stream.client_addr_v6();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output << stream.client_addr_v4();
|
||||||
|
}
|
||||||
|
output << ":" << stream.client_port();
|
||||||
|
return output.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the server endpoint to a readable string
|
||||||
|
string server_endpoint(const Stream& stream) {
|
||||||
|
ostringstream output;
|
||||||
|
if (stream.is_v6()) {
|
||||||
|
output << stream.server_addr_v6();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
output << stream.server_addr_v4();
|
||||||
|
}
|
||||||
|
output << ":" << stream.server_port();
|
||||||
|
return output.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concat both endpoints to get a readable stream identifier
|
||||||
|
string stream_identifier(const Stream& stream) {
|
||||||
|
ostringstream output;
|
||||||
|
output << client_endpoint(stream) << " - " << server_endpoint(stream);
|
||||||
|
return output.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whenever there's new client data on the stream, this callback is executed.
|
||||||
|
void on_client_data(Stream& stream) {
|
||||||
|
// Construct a string out of the contents of the client's payload
|
||||||
|
string data(stream.client_payload().begin(), stream.client_payload().end());
|
||||||
|
|
||||||
|
// Now print it, prepending some information about the stream
|
||||||
|
cout << client_endpoint(stream) << " >> "
|
||||||
|
<< server_endpoint(stream) << ": " << endl << data << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whenever there's new server data on the stream, this callback is executed.
|
||||||
|
// This does the same thing as on_client_data
|
||||||
|
void on_server_data(Stream& stream) {
|
||||||
|
string data(stream.server_payload().begin(), stream.server_payload().end());
|
||||||
|
cout << server_endpoint(stream) << " >> "
|
||||||
|
<< client_endpoint(stream) << ": " << endl << data << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When a connection is closed, this callback is executed.
|
||||||
|
void on_connection_closed(Stream& stream) {
|
||||||
|
cout << "[+] Connection closed: " << stream_identifier(stream) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When a new connection is captured, this callback will be executed.
|
||||||
|
void on_new_connection(Stream& stream) {
|
||||||
|
if (stream.is_partial_stream()) {
|
||||||
|
// We found a partial stream. This means this connection/stream had
|
||||||
|
// been established before we started capturing traffic.
|
||||||
|
//
|
||||||
|
// In this case, we need to allow for the stream to catch up, as we
|
||||||
|
// may have just captured an out of order packet and if we keep waiting
|
||||||
|
// for the holes to be filled, we may end up waiting forever.
|
||||||
|
//
|
||||||
|
// Calling enable_recovery_mode will skip out of order packets that
|
||||||
|
// fall withing the range of the given window size.
|
||||||
|
// See Stream::enable_recover_mode for more information
|
||||||
|
cout << "[+] New connection " << stream_identifier(stream) << endl;
|
||||||
|
|
||||||
|
// Enable recovery mode using a window of 10kb
|
||||||
|
stream.enable_recovery_mode(10 * 1024);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Print some information about the new connection
|
||||||
|
cout << "[+] New connection " << stream_identifier(stream) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now configure the callbacks on it.
|
||||||
|
// First, we want on_client_data to be called every time there's new client data
|
||||||
|
stream.client_data_callback(&on_client_data);
|
||||||
|
|
||||||
|
// Same thing for server data, but calling on_server_data
|
||||||
|
stream.server_data_callback(&on_server_data);
|
||||||
|
|
||||||
|
// When the connection is closed, call on_connection_closed
|
||||||
|
stream.stream_closed_callback(&on_connection_closed);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
if (argc != 3) {
|
||||||
|
cout << "Usage: " << argv[0] << " <interface> <port>" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Construct the sniffer configuration object
|
||||||
|
SnifferConfiguration config;
|
||||||
|
|
||||||
|
// Only capture TCP traffic sent from/to the given port
|
||||||
|
config.set_filter("tcp port " + to_string(stoi(string(argv[2]))));
|
||||||
|
|
||||||
|
// Construct the sniffer we'll use
|
||||||
|
Sniffer sniffer(argv[1], config);
|
||||||
|
|
||||||
|
cout << "Starting capture on interface " << argv[1] << endl;
|
||||||
|
|
||||||
|
// Now construct the stream follower
|
||||||
|
StreamFollower follower;
|
||||||
|
|
||||||
|
// We just need to specify the callback to be executed when a new
|
||||||
|
// stream is captured. In this stream, you should define which callbacks
|
||||||
|
// will be executed whenever new data is sent on that stream
|
||||||
|
// (see on_new_connection)
|
||||||
|
follower.new_stream_callback(&on_new_connection);
|
||||||
|
|
||||||
|
// Allow following partial TCP streams (e.g. streams that were
|
||||||
|
// open before the sniffer started running)
|
||||||
|
follower.follow_partial_streams(true);
|
||||||
|
|
||||||
|
// Now start capturing. Every time there's a new packet, call
|
||||||
|
// follower.process_packet
|
||||||
|
sniffer.sniff_loop([&](PDU& packet) {
|
||||||
|
follower.process_packet(packet);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (exception& ex) {
|
||||||
|
cerr << "Error: " << ex.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
#include <tins/tins.h>
|
#include <tins/tins.h>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -67,7 +68,7 @@ private:
|
|||||||
const IP& ip = pdu.rfind_pdu<IP>();
|
const IP& ip = pdu.rfind_pdu<IP>();
|
||||||
const TCP& tcp = pdu.rfind_pdu<TCP>();
|
const TCP& tcp = pdu.rfind_pdu<TCP>();
|
||||||
// We'll only close a connection when seeing a SYN|ACK
|
// We'll only close a connection when seeing a SYN|ACK
|
||||||
if (tcp.flags() == (TCP::SYN | TCP::ACK)) {
|
if (tcp.has_flags(TCP::SYN | TCP::ACK)) {
|
||||||
// Create an ethernet header flipping the addresses
|
// Create an ethernet header flipping the addresses
|
||||||
EthernetII packet(eth.src_addr(), eth.dst_addr());
|
EthernetII packet(eth.src_addr(), eth.dst_addr());
|
||||||
// Do the same for IP
|
// Do the same for IP
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,7 +31,11 @@
|
|||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
|
// Fix for gcc 4.6
|
||||||
|
#define _GLIBCXX_USE_NANOSLEEP
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -128,7 +132,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
sender.send(ip);
|
sender.send(ip);
|
||||||
// Give him a little time
|
// Give it a little time
|
||||||
sleep_for(milliseconds(100));
|
sleep_for(milliseconds(100));
|
||||||
}
|
}
|
||||||
running = false;
|
running = false;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
ADD_SUBDIRECTORY(tins)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
FILE(GLOB INCLUDE_FILES "*.h")
|
|
||||||
INSTALL(
|
|
||||||
FILES ${INCLUDE_FILES}
|
|
||||||
DESTINATION include/tins
|
|
||||||
COMPONENT Headers
|
|
||||||
)
|
|
||||||
ADD_SUBDIRECTORY(dot11)
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,19 +30,23 @@
|
|||||||
#ifndef TINS_ADDRESS_RANGE
|
#ifndef TINS_ADDRESS_RANGE
|
||||||
#define TINS_ADDRESS_RANGE
|
#define TINS_ADDRESS_RANGE
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "internals.h"
|
#include <tins/exceptions.h>
|
||||||
|
#include <tins/detail/address_helpers.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
* \brief AddressRange iterator class.
|
* \brief AddressRange iterator class.
|
||||||
*/
|
*/
|
||||||
template<typename Address>
|
template<typename Address>
|
||||||
class AddressRangeIterator : public std::iterator<std::forward_iterator_tag, const Address> {
|
class AddressRangeIterator {
|
||||||
public:
|
public:
|
||||||
typedef typename std::iterator<std::forward_iterator_tag, const Address>::value_type value_type;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
|
typedef const Address value_type;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef const Address* pointer;
|
||||||
|
typedef const Address& reference;
|
||||||
|
|
||||||
struct end_iterator {
|
struct end_iterator {
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ public:
|
|||||||
AddressRange(const address_type& first, const address_type& last, bool only_hosts = false)
|
AddressRange(const address_type& first, const address_type& last, bool only_hosts = false)
|
||||||
: first_(first), last_(last), only_hosts_(only_hosts){
|
: first_(first), last_(last), only_hosts_(only_hosts){
|
||||||
if (last_ < first_) {
|
if (last_ < first_) {
|
||||||
throw std::runtime_error("Invalid address range");
|
throw exception_base("Invalid address range");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +215,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
static AddressRange from_mask(const address_type& first, const address_type& mask) {
|
static AddressRange from_mask(const address_type& first, const address_type& mask) {
|
||||||
return AddressRange<address_type>(
|
return AddressRange<address_type>(
|
||||||
first,
|
first & mask,
|
||||||
Internals::last_address_from_mask(first, mask),
|
Internals::last_address_from_mask(first, mask),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,11 +31,11 @@
|
|||||||
#ifndef TINS_ARP_H
|
#ifndef TINS_ARP_H
|
||||||
#define TINS_ARP_H
|
#define TINS_ARP_H
|
||||||
|
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
#include "ip_address.h"
|
#include <tins/ip_address.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -72,6 +72,14 @@ public:
|
|||||||
REPLY = 0x0002
|
REPLY = 0x0002
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructs an ARP object using the provided addresses.
|
* \brief Constructs an ARP object using the provided addresses.
|
||||||
*
|
*
|
||||||
@@ -290,7 +298,7 @@ public:
|
|||||||
* \param sender The sender's IP address.
|
* \param sender The sender's IP address.
|
||||||
* \param hw_tgt The target's hardware address.
|
* \param hw_tgt The target's hardware address.
|
||||||
* \param hw_snd The sender's hardware address.
|
* \param hw_snd The sender's hardware address.
|
||||||
* \return EthetnetII containing the ARP Replay.
|
* \return EthernetII object containing the ARP Reply.
|
||||||
*/
|
*/
|
||||||
static EthernetII make_arp_reply(ipaddress_type target,
|
static EthernetII make_arp_reply(ipaddress_type target,
|
||||||
ipaddress_type sender,
|
ipaddress_type sender,
|
||||||
@@ -326,7 +334,7 @@ private:
|
|||||||
uint32_t target_ip_address;
|
uint32_t target_ip_address;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
arp_header header_;
|
arp_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,13 +31,12 @@
|
|||||||
#define TINS_BOOTP_H
|
#define TINS_BOOTP_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "ip_address.h"
|
#include <tins/ip_address.h>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -268,15 +267,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<size_t n>
|
template<size_t n>
|
||||||
void chaddr(const HWAddress<n>& new_chaddr) {
|
void chaddr(const HWAddress<n>& new_chaddr) {
|
||||||
// Copy the new addr
|
size_t copy_threshold = std::min(n, sizeof(bootp_.chaddr));
|
||||||
uint8_t* end = std::copy(
|
for (size_t i = 0; i < copy_threshold; ++i) {
|
||||||
new_chaddr.begin(),
|
if (i < copy_threshold) {
|
||||||
new_chaddr.begin() + std::min(n, sizeof(bootp_.chaddr)),
|
bootp_.chaddr[i] = new_chaddr[i];
|
||||||
bootp_.chaddr
|
}
|
||||||
);
|
else {
|
||||||
// Fill what's left with zeros
|
bootp_.chaddr[i] = 0;
|
||||||
if (end < bootp_.chaddr + chaddr_type::address_size) {
|
}
|
||||||
std::fill(end, bootp_.chaddr + chaddr_type::address_size, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,8 +330,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
vend_type& vend() { return vend_; }
|
vend_type& vend() { return vend_; }
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
private:
|
|
||||||
/**
|
/**
|
||||||
* Struct that represents the Bootp datagram.
|
* Struct that represents the Bootp datagram.
|
||||||
*/
|
*/
|
||||||
@@ -355,6 +353,7 @@ private:
|
|||||||
uint8_t file[128];
|
uint8_t file[128];
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
|
private:
|
||||||
bootp_header bootp_;
|
bootp_header bootp_;
|
||||||
vend_type vend_;
|
vend_type vend_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,15 +2,38 @@
|
|||||||
#define TINS_CONFIG_H
|
#define TINS_CONFIG_H
|
||||||
|
|
||||||
/* Define if the compiler supports basic C++11 syntax */
|
/* Define if the compiler supports basic C++11 syntax */
|
||||||
#cmakedefine HAVE_CXX11
|
#cmakedefine TINS_HAVE_CXX11
|
||||||
|
|
||||||
/* Have IEEE 802.11 support */
|
/* Have IEEE 802.11 support */
|
||||||
#cmakedefine HAVE_DOT11
|
#cmakedefine TINS_HAVE_DOT11
|
||||||
|
|
||||||
/* Have WPA2 decryption library */
|
/* Have WPA2 decryption library */
|
||||||
#cmakedefine HAVE_WPA2_DECRYPTION
|
#cmakedefine TINS_HAVE_WPA2_DECRYPTION
|
||||||
|
|
||||||
/* Use pcap_sendpacket to send l2 packets */
|
/* Use pcap_sendpacket to send l2 packets */
|
||||||
#cmakedefine HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
#cmakedefine TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
||||||
|
|
||||||
|
/* Have TCPIP classes */
|
||||||
|
#cmakedefine TINS_HAVE_TCPIP
|
||||||
|
|
||||||
|
/* Have TCP ACK tracking */
|
||||||
|
#cmakedefine TINS_HAVE_ACK_TRACKER
|
||||||
|
|
||||||
|
/* Have TCP stream custom data */
|
||||||
|
#cmakedefine TINS_HAVE_TCP_STREAM_CUSTOM_DATA
|
||||||
|
|
||||||
|
/* Have GCC builtin swap */
|
||||||
|
#cmakedefine TINS_HAVE_GCC_BUILTIN_SWAP
|
||||||
|
|
||||||
|
/* Have WPA2Decrypter callbacks */
|
||||||
|
#cmakedefine TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
|
||||||
|
/* Have libpcap */
|
||||||
|
#cmakedefine TINS_HAVE_PCAP
|
||||||
|
|
||||||
|
/* Version macros */
|
||||||
|
#define TINS_VERSION_MAJOR ${TINS_VERSION_MAJOR}
|
||||||
|
#define TINS_VERSION_MINOR ${TINS_VERSION_MINOR}
|
||||||
|
#define TINS_VERSION_PATCH ${TINS_VERSION_PATCH}
|
||||||
|
|
||||||
#endif // TINS_CONFIG_H
|
#endif // TINS_CONFIG_H
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,32 +27,31 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_CRYPTO_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_CRYPTO_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_CRYPTO_H
|
#define TINS_CRYPTO_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "utils.h"
|
#ifdef TINS_HAVE_WPA2_CALLBACKS
|
||||||
#include "snap.h"
|
#include <functional>
|
||||||
#include "rawpdu.h"
|
#endif // TINS_HAVE_WPA2_CALLBACKS
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "handshake_capturer.h"
|
#include <tins/handshake_capturer.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
class PDU;
|
class PDU;
|
||||||
class Dot11;
|
class Dot11;
|
||||||
class Dot11Data;
|
class Dot11Data;
|
||||||
|
class SNAP;
|
||||||
|
class RawPDU;
|
||||||
|
|
||||||
namespace Crypto {
|
namespace Crypto {
|
||||||
|
|
||||||
struct RC4Key;
|
#ifdef TINS_HAVE_WPA2_DECRYPTION
|
||||||
|
|
||||||
#ifdef HAVE_WPA2_DECRYPTION
|
|
||||||
namespace WPA2 {
|
namespace WPA2 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +127,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
SNAP* ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
SNAP* ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
||||||
SNAP* tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
SNAP* tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
||||||
RC4Key generate_rc4_key(const Dot11Data& dot11, const RawPDU& raw) const;
|
|
||||||
|
|
||||||
ptk_type ptk_;
|
ptk_type ptk_;
|
||||||
bool is_ccmp_;
|
bool is_ccmp_;
|
||||||
@@ -160,33 +158,19 @@ public:
|
|||||||
* \return The generated PMK.
|
* \return The generated PMK.
|
||||||
*/
|
*/
|
||||||
const pmk_type& pmk() const;
|
const pmk_type& pmk() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Getter for the SSID
|
||||||
|
* \return The access point's SSID
|
||||||
|
*/
|
||||||
|
const std::string& ssid() const;
|
||||||
private:
|
private:
|
||||||
pmk_type pmk_;
|
pmk_type pmk_;
|
||||||
|
std::string ssid_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // WPA2
|
} // WPA2
|
||||||
#endif // HAVE_WPA2_DECRYPTION
|
#endif // TINS_HAVE_WPA2_DECRYPTION
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief RC4 Key abstraction.
|
|
||||||
*/
|
|
||||||
struct RC4Key {
|
|
||||||
static const size_t data_size = 256;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Initializes the key using the provided iterator range.
|
|
||||||
*
|
|
||||||
* \param start The start of the range.
|
|
||||||
* \param end The end of the range.
|
|
||||||
*/
|
|
||||||
template<typename ForwardIterator>
|
|
||||||
RC4Key(ForwardIterator start, ForwardIterator end);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The actual key data.
|
|
||||||
*/
|
|
||||||
uint8_t data[data_size];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Decrypts WEP-encrypted traffic.
|
* \brief Decrypts WEP-encrypted traffic.
|
||||||
@@ -240,7 +224,7 @@ private:
|
|||||||
std::vector<uint8_t> key_buffer_;
|
std::vector<uint8_t> key_buffer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_WPA2_DECRYPTION
|
#ifdef TINS_HAVE_WPA2_DECRYPTION
|
||||||
/**
|
/**
|
||||||
* \brief Decrypts WPA2-encrypted traffic.
|
* \brief Decrypts WPA2-encrypted traffic.
|
||||||
*
|
*
|
||||||
@@ -275,6 +259,32 @@ public:
|
|||||||
*/
|
*/
|
||||||
typedef std::map<addr_pair, WPA2::SessionKeys> keys_map;
|
typedef std::map<addr_pair, WPA2::SessionKeys> keys_map;
|
||||||
|
|
||||||
|
#ifdef TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief The type used to store the callback type used when a new access
|
||||||
|
* point is found.
|
||||||
|
*
|
||||||
|
* The first argument to the function will be the access point's SSID and
|
||||||
|
* the second one its BSSID.
|
||||||
|
*/
|
||||||
|
typedef std::function<void(const std::string&,
|
||||||
|
const address_type&)> ap_found_callback_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type used to store the callback type used when a new handshake
|
||||||
|
* is captured.
|
||||||
|
*
|
||||||
|
* The first argument to the function will be the access point's SSID and
|
||||||
|
* the second one its BSSID. The third argument will be the client's hardware
|
||||||
|
* address.
|
||||||
|
*/
|
||||||
|
typedef std::function<void(const std::string&,
|
||||||
|
const address_type&,
|
||||||
|
const address_type&)> handshake_captured_callback_type;
|
||||||
|
|
||||||
|
#endif // TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Adds an access points's information.
|
* \brief Adds an access points's information.
|
||||||
*
|
*
|
||||||
@@ -353,6 +363,30 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool decrypt(PDU& pdu);
|
bool decrypt(PDU& pdu);
|
||||||
|
|
||||||
|
#ifdef TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
/**
|
||||||
|
* \brief Sets the handshake captured callback
|
||||||
|
*
|
||||||
|
* This callback will be executed every time a new handshake is captured.
|
||||||
|
*
|
||||||
|
* \sa handshake_captured_callback_type
|
||||||
|
* \param callback The new callback to be set
|
||||||
|
*/
|
||||||
|
void handshake_captured_callback(const handshake_captured_callback_type& callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sets the access point found callback
|
||||||
|
*
|
||||||
|
* This callback will be executed every time a new access point is found, that's
|
||||||
|
* advertising an SSID added when calling add_ap_data.
|
||||||
|
*
|
||||||
|
* \sa ap_found_callback_type
|
||||||
|
* \param callback The new callback to be set
|
||||||
|
*/
|
||||||
|
void ap_found_callback(const ap_found_callback_type& callback);
|
||||||
|
|
||||||
|
#endif // TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Getter for the keys on this decrypter
|
* \brief Getter for the keys on this decrypter
|
||||||
*
|
*
|
||||||
@@ -381,8 +415,12 @@ private:
|
|||||||
pmks_map pmks_;
|
pmks_map pmks_;
|
||||||
bssids_map aps_;
|
bssids_map aps_;
|
||||||
keys_map keys_;
|
keys_map keys_;
|
||||||
|
#ifdef TINS_HAVE_WPA2_CALLBACKS
|
||||||
|
handshake_captured_callback_type handshake_captured_callback_;
|
||||||
|
ap_found_callback_type ap_found_callback_;
|
||||||
|
#endif // TINS_HAVE_WPA2_CALLBACKS
|
||||||
};
|
};
|
||||||
#endif // HAVE_WPA2_DECRYPTION
|
#endif // TINS_HAVE_WPA2_DECRYPTION
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Pluggable decrypter object which can be used to decrypt
|
* \brief Pluggable decrypter object which can be used to decrypt
|
||||||
@@ -435,20 +473,6 @@ private:
|
|||||||
decrypter_type decrypter_;
|
decrypter_type decrypter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Performs RC4 encription/decryption of the given byte range,
|
|
||||||
* using the provided key.
|
|
||||||
*
|
|
||||||
* The decrypted range will be copied to the OutputIterator provided.
|
|
||||||
*
|
|
||||||
* \param start The beginning of the range.
|
|
||||||
* \param start The end of the range.
|
|
||||||
* \param key The key to be used.
|
|
||||||
* \param output The iterator in which to write the output.
|
|
||||||
*/
|
|
||||||
template<typename ForwardIterator, typename OutputIterator>
|
|
||||||
void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Wrapper function to create a DecrypterProxy using a
|
* \brief Wrapper function to create a DecrypterProxy using a
|
||||||
* WEPDecrypter as the Decrypter template parameter.
|
* WEPDecrypter as the Decrypter template parameter.
|
||||||
@@ -459,7 +483,7 @@ void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
DecrypterProxy<Functor, WEPDecrypter> make_wep_decrypter_proxy(const Functor& functor);
|
DecrypterProxy<Functor, WEPDecrypter> make_wep_decrypter_proxy(const Functor& functor);
|
||||||
|
|
||||||
#ifdef HAVE_WPA2_DECRYPTION
|
#ifdef TINS_HAVE_WPA2_DECRYPTION
|
||||||
/**
|
/**
|
||||||
* \brief Wrapper function to create a DecrypterProxy using a
|
* \brief Wrapper function to create a DecrypterProxy using a
|
||||||
* WPA2Decrypter as the Decrypter template parameter.
|
* WPA2Decrypter as the Decrypter template parameter.
|
||||||
@@ -471,7 +495,7 @@ template<typename Functor>
|
|||||||
DecrypterProxy<Functor, WPA2Decrypter> make_wpa2_decrypter_proxy(const Functor& functor) {
|
DecrypterProxy<Functor, WPA2Decrypter> make_wpa2_decrypter_proxy(const Functor& functor) {
|
||||||
return DecrypterProxy<Functor, WPA2Decrypter>(functor);
|
return DecrypterProxy<Functor, WPA2Decrypter>(functor);
|
||||||
}
|
}
|
||||||
#endif // HAVE_WPA2_DECRYPTION
|
#endif // TINS_HAVE_WPA2_DECRYPTION
|
||||||
|
|
||||||
// Implementation section
|
// Implementation section
|
||||||
|
|
||||||
@@ -506,35 +530,6 @@ DecrypterProxy<Functor, WEPDecrypter> make_wep_decrypter_proxy(const Functor& fu
|
|||||||
return DecrypterProxy<Functor, WEPDecrypter>(functor);
|
return DecrypterProxy<Functor, WEPDecrypter>(functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RC4 stuff
|
|
||||||
|
|
||||||
template<typename ForwardIterator>
|
|
||||||
RC4Key::RC4Key(ForwardIterator start, ForwardIterator end) {
|
|
||||||
for (size_t i = 0; i < data_size; ++i) {
|
|
||||||
data[i] = static_cast<uint8_t>(i);
|
|
||||||
}
|
|
||||||
size_t j = 0;
|
|
||||||
ForwardIterator iter = start;
|
|
||||||
for (size_t i = 0; i < data_size; ++i) {
|
|
||||||
j = (j + data[i] + *iter++) % 256;
|
|
||||||
if(iter == end) {
|
|
||||||
iter = start;
|
|
||||||
}
|
|
||||||
std::swap(data[i], data[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ForwardIterator, typename OutputIterator>
|
|
||||||
void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output) {
|
|
||||||
size_t i = 0, j = 0;
|
|
||||||
while (start != end) {
|
|
||||||
i = (i + 1) % RC4Key::data_size;
|
|
||||||
j = (j + key.data[i]) % RC4Key::data_size;
|
|
||||||
std::swap(key.data[i], key.data[j]);
|
|
||||||
*output++ = *start++ ^ key.data[(key.data[i] + key.data[j]) % RC4Key::data_size];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Crypto
|
} // Crypto
|
||||||
} // Tins
|
} // Tins
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,9 +30,7 @@
|
|||||||
#ifndef TINS_CXXSTD_H
|
#ifndef TINS_CXXSTD_H
|
||||||
#define TINS_CXXSTD_H
|
#define TINS_CXXSTD_H
|
||||||
|
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
#define TINS_CXXSTD_GCC_FIX 1
|
#define TINS_CXXSTD_GCC_FIX 1
|
||||||
@@ -40,7 +38,7 @@
|
|||||||
#define TINS_CXXSTD_GCC_FIX 0
|
#define TINS_CXXSTD_GCC_FIX 0
|
||||||
#endif // __GXX_EXPERIMENTAL_CXX0X__
|
#endif // __GXX_EXPERIMENTAL_CXX0X__
|
||||||
|
|
||||||
#if !defined(TINS_IS_CXX11) && defined(HAVE_CXX11)
|
#if !defined(TINS_IS_CXX11) && defined(TINS_HAVE_CXX11)
|
||||||
#define TINS_IS_CXX11 (__cplusplus > 199711L || TINS_CXXSTD_GCC_FIX == 1 || _MSC_VER >= 1800)
|
#define TINS_IS_CXX11 (__cplusplus > 199711L || TINS_CXXSTD_GCC_FIX == 1 || _MSC_VER >= 1800)
|
||||||
#elif !defined(TINS_IS_CXX11)
|
#elif !defined(TINS_IS_CXX11)
|
||||||
#define TINS_IS_CXX11 0
|
#define TINS_IS_CXX11 0
|
||||||
@@ -48,14 +46,7 @@
|
|||||||
|
|
||||||
namespace Tins{
|
namespace Tins{
|
||||||
namespace Internals {
|
namespace Internals {
|
||||||
template<typename T>
|
template<class T> void unused(const T&) { }
|
||||||
struct smart_ptr {
|
|
||||||
#if TINS_IS_CXX11
|
|
||||||
typedef std::unique_ptr<T> type;
|
|
||||||
#else
|
|
||||||
typedef std::auto_ptr<T> type;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -41,6 +41,7 @@ class Dot3;
|
|||||||
class SLL;
|
class SLL;
|
||||||
class Loopback;
|
class Loopback;
|
||||||
class PPI;
|
class PPI;
|
||||||
|
class IP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \struct DataLinkType
|
* \struct DataLinkType
|
||||||
@@ -73,6 +74,7 @@ TINS_MAKE_DATA_LINK_TYPE(Loopback, DLT_LOOP)
|
|||||||
TINS_MAKE_DATA_LINK_TYPE(PPI, DLT_PPI)
|
TINS_MAKE_DATA_LINK_TYPE(PPI, DLT_PPI)
|
||||||
TINS_MAKE_DATA_LINK_TYPE(Dot11, DLT_IEEE802_11)
|
TINS_MAKE_DATA_LINK_TYPE(Dot11, DLT_IEEE802_11)
|
||||||
TINS_MAKE_DATA_LINK_TYPE(RadioTap, DLT_IEEE802_11_RADIO)
|
TINS_MAKE_DATA_LINK_TYPE(RadioTap, DLT_IEEE802_11_RADIO)
|
||||||
|
TINS_MAKE_DATA_LINK_TYPE(IP, DLT_RAW)
|
||||||
|
|
||||||
#undef TINS_MAKE_DATA_LINK_TYPE
|
#undef TINS_MAKE_DATA_LINK_TYPE
|
||||||
|
|
||||||
|
|||||||
106
include/tins/detail/address_helpers.h
Normal file
106
include/tins/detail/address_helpers.h
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_ADDRESS_HELPERS_H
|
||||||
|
#define TINS_ADDRESS_HELPERS_H
|
||||||
|
|
||||||
|
#include <tins/hw_address.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
namespace Tins {
|
||||||
|
|
||||||
|
class IPv4Address;
|
||||||
|
class IPv6Address;
|
||||||
|
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool increment_buffer(T& addr) {
|
||||||
|
typename T::iterator it = addr.end() - 1;
|
||||||
|
while (it >= addr.begin() && *it == 0xff) {
|
||||||
|
*it = 0;
|
||||||
|
--it;
|
||||||
|
}
|
||||||
|
// reached end
|
||||||
|
if (it < addr.begin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
(*it)++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool decrement_buffer(T& addr) {
|
||||||
|
typename T::iterator it = addr.end() - 1;
|
||||||
|
while (it >= addr.begin() && *it == 0) {
|
||||||
|
*it = 0xff;
|
||||||
|
--it;
|
||||||
|
}
|
||||||
|
// reached end
|
||||||
|
if (it < addr.begin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
(*it)--;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool increment(IPv4Address& addr);
|
||||||
|
bool increment(IPv6Address& addr);
|
||||||
|
bool decrement(IPv4Address& addr);
|
||||||
|
bool decrement(IPv6Address& addr);
|
||||||
|
template<size_t n>
|
||||||
|
bool increment(HWAddress<n>& addr) {
|
||||||
|
return increment_buffer(addr);
|
||||||
|
}
|
||||||
|
template<size_t n>
|
||||||
|
bool decrement(HWAddress<n>& addr) {
|
||||||
|
return decrement_buffer(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask);
|
||||||
|
IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask);
|
||||||
|
template<size_t n>
|
||||||
|
HWAddress<n> last_address_from_mask(HWAddress<n> addr, const HWAddress<n>& mask) {
|
||||||
|
typename HWAddress<n>::iterator addr_iter = addr.begin();
|
||||||
|
for (typename HWAddress<n>::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) {
|
||||||
|
*addr_iter = *addr_iter | ~*it;
|
||||||
|
}
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Internals
|
||||||
|
} // Tins
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif // TINS_ADDRESS_HELPERS_H
|
||||||
61
include/tins/detail/icmp_extension_helpers.h
Normal file
61
include/tins/detail/icmp_extension_helpers.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_ICMP_EXTENSION_HELPERS_H
|
||||||
|
#define TINS_ICMP_EXTENSION_HELPERS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
namespace Tins {
|
||||||
|
|
||||||
|
class PDU;
|
||||||
|
class ICMPExtensionsStructure;
|
||||||
|
|
||||||
|
namespace Memory {
|
||||||
|
class InputMemoryStream;
|
||||||
|
} // Memory
|
||||||
|
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment);
|
||||||
|
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream, uint32_t payload_length,
|
||||||
|
ICMPExtensionsStructure& extensions);
|
||||||
|
|
||||||
|
|
||||||
|
} // Internals
|
||||||
|
} // Tins
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif // TINS_ICMP_EXTENSION_HELPERS_H
|
||||||
70
include/tins/detail/pdu_helpers.h
Normal file
70
include/tins/detail/pdu_helpers.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_PDU_HELPERS_H
|
||||||
|
#define TINS_PDU_HELPERS_H
|
||||||
|
|
||||||
|
#include <tins/constants.h>
|
||||||
|
#include <tins/config.h>
|
||||||
|
#include <tins/pdu.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tins {
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer,
|
||||||
|
uint32_t size, bool rawpdu_on_no_match = true);
|
||||||
|
PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer,
|
||||||
|
uint32_t size, bool rawpdu_on_no_match = true);
|
||||||
|
#ifdef TINS_HAVE_PCAP
|
||||||
|
PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer,
|
||||||
|
uint32_t size, bool rawpdu_on_no_match = true);
|
||||||
|
#endif // TINS_HAVE_PCAP
|
||||||
|
PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size);
|
||||||
|
|
||||||
|
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
|
||||||
|
PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag);
|
||||||
|
Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag);
|
||||||
|
PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag);
|
||||||
|
|
||||||
|
inline bool is_dot3(const uint8_t* ptr, size_t sz) {
|
||||||
|
return (sz >= 13 && ptr[12] < 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Internals
|
||||||
|
} // Tins
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif // TINS_PDU_HELPERS_H
|
||||||
49
include/tins/detail/sequence_number_helpers.h
Normal file
49
include/tins/detail/sequence_number_helpers.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||||
|
#define TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
namespace Tins {
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
// Compares sequence numbers as defined by RFC 1982.
|
||||||
|
int seq_compare(uint32_t seq1, uint32_t seq2);
|
||||||
|
|
||||||
|
} // namespace Internals
|
||||||
|
} // namespace Tins
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif // TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||||
51
include/tins/detail/smart_ptr.h
Normal file
51
include/tins/detail/smart_ptr.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_SMART_PTR_H
|
||||||
|
#define TINS_SMART_PTR_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <tins/cxxstd.h>
|
||||||
|
|
||||||
|
namespace Tins {
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct smart_ptr {
|
||||||
|
#if TINS_IS_CXX11
|
||||||
|
typedef std::unique_ptr<T> type;
|
||||||
|
#else
|
||||||
|
typedef std::auto_ptr<T> type;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Internals
|
||||||
|
} // Tins
|
||||||
|
|
||||||
|
#endif // TINS_SMART_PTR_H
|
||||||
127
include/tins/detail/type_traits.h
Normal file
127
include/tins/detail/type_traits.h
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TINS_TYPE_TRAITS_H
|
||||||
|
#define TINS_TYPE_TRAITS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <tins/cxxstd.h>
|
||||||
|
#if TINS_IS_CXX11
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Tins {
|
||||||
|
namespace Internals {
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<bool, typename T = void>
|
||||||
|
struct enable_if {
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct enable_if<false, T> {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct type_to_type {
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct is_unsigned_integral {
|
||||||
|
static const bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct is_unsigned_integral<uint8_t> {
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct is_unsigned_integral<uint16_t> {
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct is_unsigned_integral<uint32_t> {
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct is_unsigned_integral<uint64_t> {
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if TINS_IS_CXX11 && !defined(_MSC_VER)
|
||||||
|
|
||||||
|
// Template metaprogramming trait to determine if a functor can accept another parameter as an argument
|
||||||
|
template <typename T, typename P, typename=void>
|
||||||
|
struct accepts_type : std::false_type { };
|
||||||
|
|
||||||
|
template <typename T, typename P>
|
||||||
|
struct accepts_type<T, P,
|
||||||
|
typename std::enable_if<
|
||||||
|
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
|
||||||
|
>::type
|
||||||
|
> : std::true_type { };
|
||||||
|
|
||||||
|
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior
|
||||||
|
template <typename Functor, typename Packet>
|
||||||
|
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||||
|
typename std::enable_if<accepts_type<Functor, Packet>::value, bool>::type* = 0) {
|
||||||
|
return f(std::move(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Functor, typename Packet>
|
||||||
|
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||||
|
typename std::enable_if<!accepts_type<Functor, Packet>::value && accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||||
|
return f(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Functor, typename Packet>
|
||||||
|
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||||
|
typename std::enable_if<!accepts_type<Functor, Packet>::value && !accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||||
|
return f(*p.pdu());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
|
||||||
|
} // Internals
|
||||||
|
} // Tins
|
||||||
|
|
||||||
|
#endif // TINS_TYPE_TRAITS_H
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,13 +30,12 @@
|
|||||||
#ifndef TINS_DHCP_H
|
#ifndef TINS_DHCP_H
|
||||||
#define TINS_DHCP_H
|
#define TINS_DHCP_H
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "bootp.h"
|
#include <tins/bootp.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu_option.h"
|
#include <tins/pdu_option.h>
|
||||||
#include "cxxstd.h"
|
#include <tins/cxxstd.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -170,7 +169,15 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store the DHCP options.
|
* The type used to store the DHCP options.
|
||||||
*/
|
*/
|
||||||
typedef std::list<option> options_type;
|
typedef std::vector<option> options_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Creates an instance of DHCP.
|
* \brief Creates an instance of DHCP.
|
||||||
@@ -428,8 +435,7 @@ public:
|
|||||||
* If the option is not found, an option_not_found exception
|
* If the option is not found, an option_not_found exception
|
||||||
* is thrown.
|
* is thrown.
|
||||||
*
|
*
|
||||||
* \return std::list<ipaddress_type> Contanining the DNS servers
|
* \return The list of DNS servers provided.
|
||||||
* provided.
|
|
||||||
*/
|
*/
|
||||||
std::vector<ipaddress_type> domain_name_servers() const;
|
std::vector<ipaddress_type> domain_name_servers() const;
|
||||||
|
|
||||||
@@ -501,7 +507,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static const uint32_t MAX_DHCP_SIZE;
|
static const uint32_t MAX_DHCP_SIZE;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T search_and_convert(OptionTypes opt) const {
|
T search_and_convert(OptionTypes opt) const {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,13 +31,12 @@
|
|||||||
#define TINS_DHCPV6_H
|
#define TINS_DHCPV6_H
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <list>
|
#include <tins/pdu.h>
|
||||||
#include "pdu.h"
|
#include <tins/macros.h>
|
||||||
#include "macros.h"
|
#include <tins/endianness.h>
|
||||||
#include "endianness.h"
|
#include <tins/small_uint.h>
|
||||||
#include "small_uint.h"
|
#include <tins/ipv6_address.h>
|
||||||
#include "ipv6_address.h"
|
#include <tins/pdu_option.h>
|
||||||
#include "pdu_option.h"
|
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -163,7 +162,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store the DHCPv6 options.
|
* The type used to store the DHCPv6 options.
|
||||||
*/
|
*/
|
||||||
typedef std::list<option> options_type;
|
typedef std::vector<option> options_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type used to store IP addresses.
|
* The type used to store IP addresses.
|
||||||
@@ -392,7 +391,7 @@ public:
|
|||||||
: id(duid_en::duid_id), data(identifier.serialize()) {}
|
: id(duid_en::duid_id), data(identifier.serialize()) {}
|
||||||
|
|
||||||
duid_type(const duid_ll& identifier)
|
duid_type(const duid_ll& identifier)
|
||||||
: id(duid_en::duid_id), data(identifier.serialize()) {}
|
: id(duid_ll::duid_id), data(identifier.serialize()) {}
|
||||||
|
|
||||||
static duid_type from_option(const option& opt);
|
static duid_type from_option(const option& opt);
|
||||||
};
|
};
|
||||||
@@ -412,6 +411,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
typedef std::vector<uint8_t> interface_id_type;
|
typedef std::vector<uint8_t> interface_id_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
@@ -854,7 +861,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. \sa PDU::header_size
|
* This method overrides PDU::header_size. \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
uint32_t header_size() const;
|
uint32_t header_size() const;
|
||||||
|
|
||||||
@@ -882,7 +889,7 @@ public:
|
|||||||
return new DHCPv6(*this);
|
return new DHCPv6(*this);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void write_option(const option& option, Memory::OutputMemoryStream& stream) const;
|
void write_option(const option& option, Memory::OutputMemoryStream& stream) const;
|
||||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||||
options_type::iterator search_option_iterator(OptionTypes type);
|
options_type::iterator search_option_iterator(OptionTypes type);
|
||||||
@@ -911,52 +918,6 @@ private:
|
|||||||
options_type options_;
|
options_type options_;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Internals {
|
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
void class_option_data2option(InputIterator start,
|
|
||||||
InputIterator end,
|
|
||||||
std::vector<uint8_t>& buffer,
|
|
||||||
size_t start_index = 0) {
|
|
||||||
size_t index = start_index;
|
|
||||||
uint16_t uint16_t_buffer;
|
|
||||||
while (start != end) {
|
|
||||||
buffer.resize(buffer.size() + sizeof(uint16_t) + start->size());
|
|
||||||
uint16_t_buffer = Endian::host_to_be(static_cast<uint16_t>(start->size()));
|
|
||||||
std::memcpy(&buffer[index], &uint16_t_buffer, sizeof(uint16_t));
|
|
||||||
index += sizeof(uint16_t);
|
|
||||||
std::copy(start->begin(), start->end(), buffer.begin() + index);
|
|
||||||
index += start->size();
|
|
||||||
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename OutputType>
|
|
||||||
OutputType option2class_option_data(const uint8_t* ptr, uint32_t total_sz) {
|
|
||||||
typedef typename OutputType::value_type value_type;
|
|
||||||
OutputType output;
|
|
||||||
size_t index = 0;
|
|
||||||
while (index + 2 < total_sz) {
|
|
||||||
uint16_t size;
|
|
||||||
std::memcpy(&size, ptr + index, sizeof(uint16_t));
|
|
||||||
size = Endian::be_to_host(size);
|
|
||||||
index += sizeof(uint16_t);
|
|
||||||
if (index + size > total_sz) {
|
|
||||||
throw option_not_found();
|
|
||||||
}
|
|
||||||
output.push_back(
|
|
||||||
value_type(ptr + index, ptr + index + size)
|
|
||||||
);
|
|
||||||
index += size;
|
|
||||||
}
|
|
||||||
if (index != total_sz) {
|
|
||||||
throw malformed_option();
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Internals
|
|
||||||
} // Tins
|
} // Tins
|
||||||
|
|
||||||
#endif // TINS_DHCPV6_H
|
#endif // TINS_DHCPV6_H
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,14 +31,21 @@
|
|||||||
#define TINS_DNS_H
|
#define TINS_DNS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <list>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
|
|
||||||
|
// Undefining some macros that conflict with some symbols here.
|
||||||
|
// Eventually, the conflicting names will be removed, but until then
|
||||||
|
// this is the best we can do.
|
||||||
|
// - IN is defined by winsock2.h
|
||||||
|
// - CERT is defined by openssl
|
||||||
|
#undef IN
|
||||||
|
#undef CERT
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -130,7 +137,7 @@ public:
|
|||||||
ATMA,
|
ATMA,
|
||||||
NAPTR,
|
NAPTR,
|
||||||
KX,
|
KX,
|
||||||
CERT,
|
CERTIFICATE,
|
||||||
A6,
|
A6,
|
||||||
DNAM,
|
DNAM,
|
||||||
SINK,
|
SINK,
|
||||||
@@ -144,13 +151,23 @@ public:
|
|||||||
DNSKEY,
|
DNSKEY,
|
||||||
DHCID,
|
DHCID,
|
||||||
NSEC3,
|
NSEC3,
|
||||||
NSEC3PARAM
|
NSEC3PARAM,
|
||||||
|
CERT = CERTIFICATE
|
||||||
};
|
};
|
||||||
|
|
||||||
enum QueryClass {
|
enum QueryClass {
|
||||||
IN = 1,
|
INTERNET = 1,
|
||||||
CH = 3,
|
CHAOS = 3,
|
||||||
HS = 4,
|
HESIOD = 4,
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
IN = INTERNET,
|
||||||
|
CH = CHAOS,
|
||||||
|
HS = HESIOD,
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
ANY = 255
|
ANY = 255
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,8 +183,13 @@ public:
|
|||||||
* \param tp The query type.
|
* \param tp The query type.
|
||||||
* \param cl The query class.
|
* \param cl The query class.
|
||||||
*/
|
*/
|
||||||
|
#if TINS_IS_CXX11
|
||||||
|
query(std::string nm, QueryType tp, QueryClass cl)
|
||||||
|
: name_(std::move(nm)), type_(tp), qclass_(cl) {}
|
||||||
|
#else
|
||||||
query(const std::string& nm, QueryType tp, QueryClass cl)
|
query(const std::string& nm, QueryType tp, QueryClass cl)
|
||||||
: name_(nm), type_(tp), qclass_(cl) {}
|
: name_(nm), type_(tp), qclass_(cl) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Default constructs this Query.
|
* \brief Default constructs this Query.
|
||||||
@@ -431,6 +453,16 @@ public:
|
|||||||
* \param rclass The class of this record.
|
* \param rclass The class of this record.
|
||||||
* \param ttl The time-to-live of this record.
|
* \param ttl The time-to-live of this record.
|
||||||
*/
|
*/
|
||||||
|
#if TINS_IS_CXX11
|
||||||
|
resource(std::string dname,
|
||||||
|
std::string data,
|
||||||
|
uint16_t type,
|
||||||
|
uint16_t rclass,
|
||||||
|
uint32_t ttl,
|
||||||
|
uint16_t preference = 0)
|
||||||
|
: dname_(std::move(dname)), data_(std::move(data)), type_(type),
|
||||||
|
qclass_(rclass), ttl_(ttl), preference_(preference) {}
|
||||||
|
#else
|
||||||
resource(const std::string& dname,
|
resource(const std::string& dname,
|
||||||
const std::string& data,
|
const std::string& data,
|
||||||
uint16_t type,
|
uint16_t type,
|
||||||
@@ -439,6 +471,7 @@ public:
|
|||||||
uint16_t preference = 0)
|
uint16_t preference = 0)
|
||||||
: dname_(dname), data_(data), type_(type), qclass_(rclass),
|
: dname_(dname), data_(data), type_(type), qclass_(rclass),
|
||||||
ttl_(ttl), preference_(preference) {}
|
ttl_(ttl), preference_(preference) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
resource() : type_(), qclass_(), ttl_(), preference_() {}
|
resource() : type_(), qclass_(), ttl_(), preference_() {}
|
||||||
|
|
||||||
@@ -584,11 +617,19 @@ public:
|
|||||||
TINS_DEPRECATED(typedef query Query);
|
TINS_DEPRECATED(typedef query Query);
|
||||||
TINS_DEPRECATED(typedef resource Resource);
|
TINS_DEPRECATED(typedef resource Resource);
|
||||||
|
|
||||||
typedef std::list<query> queries_type;
|
typedef std::vector<query> queries_type;
|
||||||
typedef std::list<resource> resources_type;
|
typedef std::vector<resource> resources_type;
|
||||||
typedef IPv4Address address_type;
|
typedef IPv4Address address_type;
|
||||||
typedef IPv6Address address_v6_type;
|
typedef IPv6Address address_v6_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Default constructor.
|
* \brief Default constructor.
|
||||||
*
|
*
|
||||||
@@ -611,7 +652,7 @@ public:
|
|||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the id field.
|
* \brief Getter for the id field.
|
||||||
*
|
*
|
||||||
* \return uint16_t containing the value of the id field.
|
* \return uint16_t containing the value of the id field.
|
||||||
*/
|
*/
|
||||||
@@ -620,7 +661,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the query response field.
|
* \brief Getter for the query response field.
|
||||||
*
|
*
|
||||||
* \return QRType containing the value of the query response
|
* \return QRType containing the value of the query response
|
||||||
* field.
|
* field.
|
||||||
@@ -630,7 +671,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the opcode field.
|
* \brief Getter for the opcode field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the opcode field.
|
* \return uint8_t containing the value of the opcode field.
|
||||||
*/
|
*/
|
||||||
@@ -639,7 +680,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the authoritative answer field.
|
* \brief Getter for the authoritative answer field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the authoritative
|
* \return uint8_t containing the value of the authoritative
|
||||||
* answer field.
|
* answer field.
|
||||||
@@ -649,7 +690,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the truncated field.
|
* \brief Getter for the truncated field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the truncated field.
|
* \return uint8_t containing the value of the truncated field.
|
||||||
*/
|
*/
|
||||||
@@ -658,7 +699,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the recursion desired field.
|
* \brief Getter for the recursion desired field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the recursion
|
* \return uint8_t containing the value of the recursion
|
||||||
* desired field.
|
* desired field.
|
||||||
@@ -668,7 +709,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the recursion available field.
|
* \brief Getter for the recursion available field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the recursion
|
* \return uint8_t containing the value of the recursion
|
||||||
* available field.
|
* available field.
|
||||||
@@ -678,7 +719,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the z desired field.
|
* \brief Getter for the z desired field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the z field.
|
* \return uint8_t containing the value of the z field.
|
||||||
*/
|
*/
|
||||||
@@ -687,7 +728,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the authenticated data field.
|
* \brief Getter for the authenticated data field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the authenticated
|
* \return uint8_t containing the value of the authenticated
|
||||||
* data field.
|
* data field.
|
||||||
@@ -697,7 +738,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the checking disabled field.
|
* \brief Getter for the checking disabled field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the checking
|
* \return uint8_t containing the value of the checking
|
||||||
* disabled field.
|
* disabled field.
|
||||||
@@ -707,7 +748,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the rcode field.
|
* \brief Getter for the rcode field.
|
||||||
*
|
*
|
||||||
* \return uint8_t containing the value of the rcode field.
|
* \return uint8_t containing the value of the rcode field.
|
||||||
*/
|
*/
|
||||||
@@ -716,7 +757,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the questions field.
|
* \brief Getter for the questions field.
|
||||||
*
|
*
|
||||||
* \return uint16_t containing the value of the questions field.
|
* \return uint16_t containing the value of the questions field.
|
||||||
*/
|
*/
|
||||||
@@ -725,7 +766,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the answers field.
|
* \brief Getter for the answers field.
|
||||||
*
|
*
|
||||||
* \return uint16_t containing the value of the answers field.
|
* \return uint16_t containing the value of the answers field.
|
||||||
*/
|
*/
|
||||||
@@ -734,7 +775,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the authority field.
|
* \brief Getter for the authority field.
|
||||||
*
|
*
|
||||||
* \return uint16_t containing the value of the authority field.
|
* \return uint16_t containing the value of the authority field.
|
||||||
*/
|
*/
|
||||||
@@ -743,7 +784,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the additional field.
|
* \brief Getter for the additional field.
|
||||||
*
|
*
|
||||||
* \return uint16_t containing the value of the additional field.
|
* \return uint16_t containing the value of the additional field.
|
||||||
*/
|
*/
|
||||||
@@ -993,7 +1034,8 @@ private:
|
|||||||
uint32_t compose_name(const uint8_t* ptr, char* out_ptr) const;
|
uint32_t compose_name(const uint8_t* ptr, char* out_ptr) const;
|
||||||
void convert_records(const uint8_t* ptr,
|
void convert_records(const uint8_t* ptr,
|
||||||
const uint8_t* end,
|
const uint8_t* end,
|
||||||
resources_type& res) const;
|
resources_type& res,
|
||||||
|
const uint16_t rr_count) const;
|
||||||
void skip_to_section_end(Memory::InputMemoryStream& stream,
|
void skip_to_section_end(Memory::InputMemoryStream& stream,
|
||||||
const uint32_t num_records) const;
|
const uint32_t num_records) const;
|
||||||
void skip_to_dname_end(Memory::InputMemoryStream& stream) const;
|
void skip_to_dname_end(Memory::InputMemoryStream& stream) const;
|
||||||
@@ -1004,7 +1046,7 @@ private:
|
|||||||
uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
|
uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
|
||||||
static void inline_convert_v4(uint32_t value, char* output);
|
static void inline_convert_v4(uint32_t value, char* output);
|
||||||
static bool contains_dname(uint16_t type);
|
static bool contains_dname(uint16_t type);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void add_record(const resource& resource, const sections_type& sections);
|
void add_record(const resource& resource, const sections_type& sections);
|
||||||
|
|
||||||
dns_header header_;
|
dns_header header_;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,18 +27,18 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT_11) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT_11) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT_11
|
#define TINS_DOT_11
|
||||||
|
|
||||||
#include "dot11/dot11_base.h"
|
#include <tins/dot11/dot11_base.h>
|
||||||
#include "dot11/dot11_data.h"
|
#include <tins/dot11/dot11_data.h>
|
||||||
#include "dot11/dot11_mgmt.h"
|
#include <tins/dot11/dot11_mgmt.h>
|
||||||
#include "dot11/dot11_beacon.h"
|
#include <tins/dot11/dot11_beacon.h>
|
||||||
#include "dot11/dot11_assoc.h"
|
#include <tins/dot11/dot11_assoc.h>
|
||||||
#include "dot11/dot11_auth.h"
|
#include <tins/dot11/dot11_auth.h>
|
||||||
#include "dot11/dot11_probe.h"
|
#include <tins/dot11/dot11_probe.h>
|
||||||
#include "dot11/dot11_control.h"
|
#include <tins/dot11/dot11_control.h>
|
||||||
|
|
||||||
#endif // TINS_DOT_11
|
#endif // TINS_DOT_11
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
FILE(GLOB INCLUDE_FILES "*.h")
|
|
||||||
INSTALL(
|
|
||||||
FILES ${INCLUDE_FILES}
|
|
||||||
DESTINATION include/tins/dot11
|
|
||||||
COMPONENT Headers
|
|
||||||
)
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_ASSOC_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_ASSOC_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT11_DOT11_ASSOC_H
|
#define TINS_DOT11_DOT11_ASSOC_H
|
||||||
|
|
||||||
#include "../dot11/dot11_mgmt.h"
|
#include <tins/dot11/dot11_mgmt.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_AUTH_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_AUTH_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT11_DOT11_AUTH_H
|
#define TINS_DOT11_DOT11_AUTH_H
|
||||||
|
|
||||||
#include "../dot11/dot11_mgmt.h"
|
#include <tins/dot11/dot11_mgmt.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,19 +27,18 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT11_DOT11_H
|
#define TINS_DOT11_DOT11_H
|
||||||
|
|
||||||
#include <list>
|
#include <tins/pdu.h>
|
||||||
#include "../pdu.h"
|
#include <tins/pdu_option.h>
|
||||||
#include "../pdu_option.h"
|
#include <tins/small_uint.h>
|
||||||
#include "../small_uint.h"
|
#include <tins/hw_address.h>
|
||||||
#include "../hw_address.h"
|
#include <tins/endianness.h>
|
||||||
#include "../endianness.h"
|
#include <tins/cxxstd.h>
|
||||||
#include "../cxxstd.h"
|
#include <tins/macros.h>
|
||||||
#include "../macros.h"
|
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -67,7 +66,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store tagged options.
|
* The type used to store tagged options.
|
||||||
*/
|
*/
|
||||||
typedef std::list<option> options_type;
|
typedef std::vector<option> options_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This PDU's flag.
|
* \brief This PDU's flag.
|
||||||
@@ -128,9 +127,148 @@ public:
|
|||||||
ERP_INFORMATION,
|
ERP_INFORMATION,
|
||||||
TS_DELAY,
|
TS_DELAY,
|
||||||
TCLAS_PROCESSING,
|
TCLAS_PROCESSING,
|
||||||
QOS_CAPABILITY = 46,
|
HT_CAPABILITY,
|
||||||
|
QOS_CAPABILITY,
|
||||||
RSN = 48,
|
RSN = 48,
|
||||||
EXT_SUPPORTED_RATES = 50,
|
EXT_SUPPORTED_RATES = 50,
|
||||||
|
AP_CHANNEL_REPORT,
|
||||||
|
NEIGHBOR_REPORT,
|
||||||
|
RCPI,
|
||||||
|
MOBILITY_DOMAIN_MDE,
|
||||||
|
FAST_BSS_TRANSITION_FTE,
|
||||||
|
TIMEOUT_INTERVAL,
|
||||||
|
RIC_DATA_RDE,
|
||||||
|
DSE_REG_LOC,
|
||||||
|
SUPPORTED_OP_CLASSES,
|
||||||
|
EXT_CH_SWITCH_ANNOUNCEMENT,
|
||||||
|
HT_OPERATION,
|
||||||
|
SEC_CH_OFFSET,
|
||||||
|
BSS_AVG_ACCESS_DELAY,
|
||||||
|
ANTENNA,
|
||||||
|
RSNI,
|
||||||
|
MEASUREMENT_PILOT_TRANSMISSION,
|
||||||
|
BSS_AVAIL_ADMISSION_CAPACITY,
|
||||||
|
BSS_AC_ACCESS_DELAY,
|
||||||
|
TIME_ADVERTISEMENT,
|
||||||
|
RM_ENABLED_CAP,
|
||||||
|
MULTIPLE_BSSID,
|
||||||
|
BSS_2040_COEX,
|
||||||
|
BSS_2040_INTOLERANT_CH_REPORT,
|
||||||
|
OVERLAPPING_BSS_SCAN_PARAM,
|
||||||
|
RIC_DESCRIPTOR,
|
||||||
|
MGMT_MIC,
|
||||||
|
EVENT_REQ = 78,
|
||||||
|
EVENT_REPORT,
|
||||||
|
DIAG_REQ,
|
||||||
|
DIAG_REPORT,
|
||||||
|
LOCATION_PARAMS,
|
||||||
|
NONTRANSMITTED_BSSID_CAP,
|
||||||
|
SSID_LIST,
|
||||||
|
MULTIPLE_BSSID_INDEX,
|
||||||
|
FMS_DESCRIPTOR,
|
||||||
|
FMS_REQ,
|
||||||
|
FMS_RESP,
|
||||||
|
QOS_TRAFFIC_CAP,
|
||||||
|
BSS_MAX_IDLE_PERIOD,
|
||||||
|
TFS_REQ,
|
||||||
|
TFS_RESP,
|
||||||
|
WNM_SLEEP_MODE,
|
||||||
|
TIM_BROADCAST_REQ,
|
||||||
|
TIM_BROADCAST_RESP,
|
||||||
|
COLLOCATED_INTERFERENCE_REPORT,
|
||||||
|
CH_USAGE,
|
||||||
|
TIME_ZONE,
|
||||||
|
DMS_REQ,
|
||||||
|
DMS_RESP,
|
||||||
|
LINK_ID,
|
||||||
|
WAKEUP_SCHEDULE,
|
||||||
|
CH_SWITCH_TIMING,
|
||||||
|
PTI_CONTROL,
|
||||||
|
TPU_BUFFER_STATUS,
|
||||||
|
INTERWORKING,
|
||||||
|
ADVERTISEMENT_PROTOCOL,
|
||||||
|
EXPEDITED_BANDWIDTH_REQ,
|
||||||
|
QOS_MAP,
|
||||||
|
ROAMING_CONSORTIUM,
|
||||||
|
EMERG_ALERT_ID,
|
||||||
|
MESH_CONFIG,
|
||||||
|
MESH_ID,
|
||||||
|
MESH_LINK_METRIC_REPORT,
|
||||||
|
CONGESTION_NOTIFICATION,
|
||||||
|
MESH_PEERING_MGMT,
|
||||||
|
MESH_CH_SWITCH_PARAMS,
|
||||||
|
MESH_AWAKE_WINDOW,
|
||||||
|
BEACON_TIMING,
|
||||||
|
MCCAOP_SETUP_REQ,
|
||||||
|
MCCAOP_SETUP_REPLY,
|
||||||
|
MCCAOP_ADVERTISEMENT,
|
||||||
|
MCCAOP_TEARDOWN,
|
||||||
|
GANN,
|
||||||
|
RANN,
|
||||||
|
EXT_CAP,
|
||||||
|
PREQ = 130,
|
||||||
|
PREP,
|
||||||
|
PERR,
|
||||||
|
PXU = 137,
|
||||||
|
PXUC,
|
||||||
|
AUTH_MESH_PEER_EX,
|
||||||
|
MIC,
|
||||||
|
DEST_URI,
|
||||||
|
UAPSD_COEX,
|
||||||
|
DMG_WAKEUP_SCHEDULE,
|
||||||
|
EXT_SCHEDULE,
|
||||||
|
STA_AVAIL,
|
||||||
|
DMG_TSPEC,
|
||||||
|
NEXT_DMG_ATI,
|
||||||
|
DMG_CAP,
|
||||||
|
DMG_OP = 151,
|
||||||
|
DMG_BSS_PARAM_CHG,
|
||||||
|
DMG_BEAM_REFINEMENT,
|
||||||
|
CH_MEASUREMENT_FEEDBACK,
|
||||||
|
AWAKE_WINDOW = 157,
|
||||||
|
MULTIBAND,
|
||||||
|
ADDBA_ESXT,
|
||||||
|
NEXTPCP_LIST,
|
||||||
|
PCP_HANDOVER,
|
||||||
|
DMG_LINK_MARGIN,
|
||||||
|
SWITCHING_STREAM,
|
||||||
|
SESSION_TRANSITION,
|
||||||
|
DYNAMIC_TONE_PAIRING_REPORT,
|
||||||
|
CLUSTER_REPORT,
|
||||||
|
RELAY_CAP,
|
||||||
|
RELAY_TRANSFER_PARAM_SET,
|
||||||
|
BEAMLINK_MAINTENANCE,
|
||||||
|
MULTIPLE_MAC_SUBLAYERS,
|
||||||
|
UPID,
|
||||||
|
DMG_LINK_ADAPTATION_ACK,
|
||||||
|
MCCAOP_ADV_OVERVIEW = 174,
|
||||||
|
QUIET_PERIOD_REQ,
|
||||||
|
QUIET_PERIOD_RESP = 177,
|
||||||
|
QMF_POLICY = 181,
|
||||||
|
ECAPC_POLICY = 182,
|
||||||
|
CLUSTER_TIME_OFFSET,
|
||||||
|
INTRA_ACCESS_CAT_PRIORITY,
|
||||||
|
SCS_DESCRIPTOR,
|
||||||
|
QLOAD_REPORT,
|
||||||
|
HCCA_TXOP_UPDATE_COUNT,
|
||||||
|
HIGHER_LAYER_STREAM_ID,
|
||||||
|
GCR_GROUP_ADDR,
|
||||||
|
ANTENNA_SECTOR_ID_PATTERN,
|
||||||
|
VHT_CAP,
|
||||||
|
VHT_OP,
|
||||||
|
EXT_BSS_LOAD,
|
||||||
|
WIDE_BANDWIDTH_CH_SWITCH,
|
||||||
|
TRANSMIT_POWER_ENVELOPE,
|
||||||
|
CH_SWITCH_WRAPPER,
|
||||||
|
AID,
|
||||||
|
QUIET_CHANNEL,
|
||||||
|
OP_MODE_NOTIFY,
|
||||||
|
UPSIM,
|
||||||
|
REDUCED_NEIGHBOR_REPORT,
|
||||||
|
TVHT_OP,
|
||||||
|
DEV_LOC = 204,
|
||||||
|
WHITE_SPACE_MAP,
|
||||||
|
FINE_TUNING_MEASUREMENT_PARAMS,
|
||||||
VENDOR_SPECIFIC = 221
|
VENDOR_SPECIFIC = 221
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,6 +418,15 @@ public:
|
|||||||
return header_.control.power_mgmt;
|
return header_.control.power_mgmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Getter for the More Data field.
|
||||||
|
*
|
||||||
|
* \return The stored More Data field.
|
||||||
|
*/
|
||||||
|
small_uint<1> more_data() const {
|
||||||
|
return header_.control.more_data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Getter for the WEP field.
|
* \brief Getter for the WEP field.
|
||||||
*
|
*
|
||||||
@@ -374,6 +521,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
void power_mgmt(small_uint<1> new_value);
|
void power_mgmt(small_uint<1> new_value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Setter for the More Data field.
|
||||||
|
*
|
||||||
|
* \param new_value The new More Data field value.
|
||||||
|
*/
|
||||||
|
void more_data(small_uint<1> new_value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Setter for the WEP field.
|
* \brief Setter for the WEP field.
|
||||||
*
|
*
|
||||||
@@ -508,8 +662,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Dot11* from_bytes(const uint8_t* buffer, uint32_t total_sz);
|
static Dot11* from_bytes(const uint8_t* buffer, uint32_t total_sz);
|
||||||
protected:
|
protected:
|
||||||
virtual void write_ext_header(Memory::OutputMemoryStream& stream) { }
|
virtual void write_ext_header(Memory::OutputMemoryStream& stream);
|
||||||
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream) { }
|
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream);
|
||||||
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
|
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
|
||||||
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val);
|
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val);
|
||||||
protected:
|
protected:
|
||||||
@@ -554,7 +708,7 @@ private:
|
|||||||
Dot11(const dot11_header* header_ptr);
|
Dot11(const dot11_header* header_ptr);
|
||||||
|
|
||||||
void internal_add_option(const option& opt);
|
void internal_add_option(const option& opt);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||||
options_type::iterator search_option_iterator(OptionTypes type);
|
options_type::iterator search_option_iterator(OptionTypes type);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_BEACON_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_BEACON_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT11_DOT11_BEACON_H
|
#define TINS_DOT11_DOT11_BEACON_H
|
||||||
|
|
||||||
#include "../dot11/dot11_mgmt.h"
|
#include <tins/dot11/dot11_mgmt.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,14 +27,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_CONTROL_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_CONTROL_H) && defined(TINS_HAVE_DOT11)
|
||||||
|
|
||||||
#define TINS_DOT11_DOT11_CONTROL_H
|
#define TINS_DOT11_DOT11_CONTROL_H
|
||||||
|
|
||||||
#include "../dot11/dot11_base.h"
|
#include <tins/dot11/dot11_base.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
@@ -97,6 +97,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
class TINS_API Dot11ControlTA : public Dot11Control {
|
class TINS_API Dot11ControlTA : public Dot11Control {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* \brief This PDU's flag.
|
||||||
|
*/
|
||||||
|
static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL_TA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Getter for the target address field.
|
* \brief Getter for the target address field.
|
||||||
*/
|
*/
|
||||||
@@ -109,6 +114,15 @@ public:
|
|||||||
* \param addr The new target address.
|
* \param addr The new target address.
|
||||||
*/
|
*/
|
||||||
void target_addr(const address_type& addr);
|
void target_addr(const address_type& addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Check whether this PDU matches the specified flag.
|
||||||
|
* \param flag The flag to match
|
||||||
|
* \sa PDU::matches_flag
|
||||||
|
*/
|
||||||
|
bool matches_flag(PDUType flag) const {
|
||||||
|
return flag == pdu_flag || Dot11::matches_flag(flag);
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* \brief Constructor for creating a 802.11 control frame TA PDU
|
* \brief Constructor for creating a 802.11 control frame TA PDU
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_DATA_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_DATA_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_DOT11_DOT11_DATA_H
|
#define TINS_DOT11_DOT11_DATA_H
|
||||||
|
|
||||||
#include "../dot11/dot11_base.h"
|
#include <tins/dot11/dot11_base.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,16 +27,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_MGMT_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_MGMT_H) && defined(TINS_HAVE_DOT11)
|
||||||
|
|
||||||
#define TINS_DOT11_DOT11_MGMT_H
|
#define TINS_DOT11_DOT11_MGMT_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "../dot11/dot11_base.h"
|
#include <tins/dot11/dot11_base.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
@@ -463,7 +463,8 @@ public:
|
|||||||
uint16_t dwell_time;
|
uint16_t dwell_time;
|
||||||
uint8_t hop_set, hop_pattern, hop_index;
|
uint8_t hop_set, hop_pattern, hop_index;
|
||||||
|
|
||||||
fh_params_set() {}
|
fh_params_set()
|
||||||
|
: dwell_time(0), hop_set(0), hop_pattern(0), hop_index(0) {}
|
||||||
|
|
||||||
fh_params_set(uint16_t dwell_time,
|
fh_params_set(uint16_t dwell_time,
|
||||||
uint8_t hop_set,
|
uint8_t hop_set,
|
||||||
@@ -482,7 +483,8 @@ public:
|
|||||||
uint8_t cfp_count, cfp_period;
|
uint8_t cfp_count, cfp_period;
|
||||||
uint16_t cfp_max_duration, cfp_dur_remaining;
|
uint16_t cfp_max_duration, cfp_dur_remaining;
|
||||||
|
|
||||||
cf_params_set() {}
|
cf_params_set()
|
||||||
|
: cfp_count(0), cfp_period(0), cfp_max_duration(0), cfp_dur_remaining(0) {}
|
||||||
|
|
||||||
cf_params_set(uint8_t cfp_count,
|
cf_params_set(uint8_t cfp_count,
|
||||||
uint8_t cfp_period,
|
uint8_t cfp_period,
|
||||||
@@ -505,7 +507,7 @@ public:
|
|||||||
uint8_t recovery_interval;
|
uint8_t recovery_interval;
|
||||||
channel_map_type channel_map;
|
channel_map_type channel_map;
|
||||||
|
|
||||||
ibss_dfs_params() {}
|
ibss_dfs_params() : recovery_interval(0) {}
|
||||||
|
|
||||||
ibss_dfs_params(const address_type& addr,
|
ibss_dfs_params(const address_type& addr,
|
||||||
uint8_t recovery_interval,
|
uint8_t recovery_interval,
|
||||||
@@ -547,7 +549,8 @@ public:
|
|||||||
uint8_t flag, number_of_sets, modulus, offset;
|
uint8_t flag, number_of_sets, modulus, offset;
|
||||||
byte_array random_table;
|
byte_array random_table;
|
||||||
|
|
||||||
fh_pattern_type() {}
|
fh_pattern_type()
|
||||||
|
: flag(0), number_of_sets(0), modulus(0), offset(0) {}
|
||||||
|
|
||||||
fh_pattern_type(uint8_t flag,
|
fh_pattern_type(uint8_t flag,
|
||||||
uint8_t sets,
|
uint8_t sets,
|
||||||
@@ -566,7 +569,8 @@ public:
|
|||||||
struct channel_switch_type {
|
struct channel_switch_type {
|
||||||
uint8_t switch_mode, new_channel, switch_count;
|
uint8_t switch_mode, new_channel, switch_count;
|
||||||
|
|
||||||
channel_switch_type() {}
|
channel_switch_type()
|
||||||
|
: switch_mode(0), new_channel(0), switch_count(0) {}
|
||||||
|
|
||||||
channel_switch_type(uint8_t mode,
|
channel_switch_type(uint8_t mode,
|
||||||
uint8_t channel,
|
uint8_t channel,
|
||||||
@@ -583,7 +587,8 @@ public:
|
|||||||
uint8_t quiet_count, quiet_period;
|
uint8_t quiet_count, quiet_period;
|
||||||
uint16_t quiet_duration, quiet_offset;
|
uint16_t quiet_duration, quiet_offset;
|
||||||
|
|
||||||
quiet_type() {}
|
quiet_type()
|
||||||
|
: quiet_count(0), quiet_period(0), quiet_duration(0), quiet_offset(0) {}
|
||||||
|
|
||||||
quiet_type(uint8_t count,
|
quiet_type(uint8_t count,
|
||||||
uint8_t period,
|
uint8_t period,
|
||||||
@@ -603,7 +608,8 @@ public:
|
|||||||
uint16_t available_capacity;
|
uint16_t available_capacity;
|
||||||
uint8_t channel_utilization;
|
uint8_t channel_utilization;
|
||||||
|
|
||||||
bss_load_type() {}
|
bss_load_type()
|
||||||
|
: station_count(0), available_capacity(0), channel_utilization(0) {}
|
||||||
|
|
||||||
bss_load_type(uint16_t count, uint8_t utilization, uint16_t capacity)
|
bss_load_type(uint16_t count, uint8_t utilization, uint16_t capacity)
|
||||||
: station_count(count), available_capacity(capacity),
|
: station_count(count), available_capacity(capacity),
|
||||||
@@ -619,7 +625,8 @@ public:
|
|||||||
uint8_t dtim_count, dtim_period, bitmap_control;
|
uint8_t dtim_count, dtim_period, bitmap_control;
|
||||||
byte_array partial_virtual_bitmap;
|
byte_array partial_virtual_bitmap;
|
||||||
|
|
||||||
tim_type() {}
|
tim_type()
|
||||||
|
: dtim_count(0), dtim_period(0), bitmap_control(0) {}
|
||||||
|
|
||||||
tim_type(uint8_t count,
|
tim_type(uint8_t count,
|
||||||
uint8_t period,
|
uint8_t period,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,14 +27,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_DOT11_DOT11_PROBE_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_DOT11_DOT11_PROBE_H) && defined(TINS_HAVE_DOT11)
|
||||||
|
|
||||||
#define TINS_DOT11_DOT11_PROBE_H
|
#define TINS_DOT11_DOT11_PROBE_H
|
||||||
|
|
||||||
#include "../dot11/dot11_mgmt.h"
|
#include <tins/dot11/dot11_mgmt.h>
|
||||||
#include "../macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
#ifndef TINS_DOT1Q_H
|
#ifndef TINS_DOT1Q_H
|
||||||
#define TINS_DOT1Q_H
|
#define TINS_DOT1Q_H
|
||||||
|
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "small_uint.h"
|
#include <tins/small_uint.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -48,6 +48,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static const PDU::PDUType pdu_flag = PDU::DOT1Q;
|
static const PDU::PDUType pdu_flag = PDU::DOT1Q;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +81,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. \sa PDU::header_size
|
* This method overrides PDU::header_size. \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
uint32_t header_size() const;
|
uint32_t header_size() const;
|
||||||
|
|
||||||
@@ -189,10 +197,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
TINS_BEGIN_PACK
|
TINS_BEGIN_PACK
|
||||||
struct dot1q_hdr {
|
struct dot1q_header {
|
||||||
#if TINS_IS_BIG_ENDIAN
|
#if TINS_IS_BIG_ENDIAN
|
||||||
uint16_t priority:3,
|
uint16_t priority:3,
|
||||||
cfi:1,
|
cfi:1,
|
||||||
@@ -207,9 +215,9 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
static uint16_t get_id(const dot1q_hdr* hdr);
|
static uint16_t get_id(const dot1q_header* hdr);
|
||||||
|
|
||||||
dot1q_hdr header_;
|
dot1q_header header_;
|
||||||
bool append_padding_;
|
bool append_padding_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,11 +31,11 @@
|
|||||||
#define TINS_DOT3_H
|
#define TINS_DOT3_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -60,6 +60,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static const address_type BROADCAST;
|
static const address_type BROADCAST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructor for creating an Dot3 PDU
|
* \brief Constructor for creating an Dot3 PDU
|
||||||
*
|
*
|
||||||
@@ -71,7 +79,7 @@ public:
|
|||||||
* \param child The PDU which will be set as the inner PDU.
|
* \param child The PDU which will be set as the inner PDU.
|
||||||
*/
|
*/
|
||||||
Dot3(const address_type& dst_hw_addr = address_type(),
|
Dot3(const address_type& dst_hw_addr = address_type(),
|
||||||
const address_type& src_hw_addr = address_type());
|
const address_type& src_hw_addr = address_type());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructs a Dot3 object from a buffer and adds a
|
* \brief Constructs a Dot3 object from a buffer and adds a
|
||||||
@@ -145,12 +153,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint32_t header_size() const;
|
uint32_t header_size() const;
|
||||||
|
|
||||||
#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET)
|
#if !defined(_WIN32) || defined(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET)
|
||||||
/**
|
/**
|
||||||
* \sa PDU::send()
|
* \sa PDU::send()
|
||||||
*/
|
*/
|
||||||
void send(PacketSender& sender, const NetworkInterface& iface);
|
void send(PacketSender& sender, const NetworkInterface& iface);
|
||||||
#endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
#endif // !_WIN32 || TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Check whether ptr points to a valid response for this PDU.
|
* \brief Check whether ptr points to a valid response for this PDU.
|
||||||
@@ -191,7 +199,7 @@ private:
|
|||||||
uint16_t length;
|
uint16_t length;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
dot3_header header_;
|
dot3_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,10 +31,10 @@
|
|||||||
#define TINS_EAPOL_H
|
#define TINS_EAPOL_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "small_uint.h"
|
#include <tins/small_uint.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -69,6 +69,14 @@ public:
|
|||||||
EAPOL_WPA = 254
|
EAPOL_WPA = 254
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Static method to instantiate the correct EAPOL subclass
|
* \brief Static method to instantiate the correct EAPOL subclass
|
||||||
* based on a raw buffer.
|
* based on a raw buffer.
|
||||||
@@ -177,13 +185,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void write_body(Memory::OutputMemoryStream& stream) = 0;
|
virtual void write_body(Memory::OutputMemoryStream& stream) = 0;
|
||||||
private:
|
private:
|
||||||
/**
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
* \brief Serialices this EAPOL PDU.
|
|
||||||
* \param buffer The buffer in which the PDU will be serialized.
|
|
||||||
* \param total_sz The size available in the buffer.
|
|
||||||
* \param parent The PDU that's one level below this one on the stack.
|
|
||||||
*/
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
|
||||||
|
|
||||||
eapol_header header_;
|
eapol_header header_;
|
||||||
};
|
};
|
||||||
@@ -338,7 +340,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. This size includes the
|
* This method overrides PDU::header_size. This size includes the
|
||||||
* payload and options size.
|
* payload and options size.
|
||||||
*
|
*
|
||||||
* \sa PDU::header_size
|
* \sa PDU::header_size
|
||||||
@@ -603,7 +605,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. This size includes the
|
* This method overrides PDU::header_size. This size includes the
|
||||||
* payload and options size.
|
* payload and options size.
|
||||||
*
|
*
|
||||||
* \sa PDU::header_size
|
* \sa PDU::header_size
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
#define TINS_ENDIANNESS_H
|
#define TINS_ENDIANNESS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
#define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
|
#define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
|
||||||
#define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN)
|
#define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN)
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
#include <cstdlib>
|
||||||
// Assume windows == little endian. fixme later
|
// Assume windows == little endian. fixme later
|
||||||
#define TINS_IS_LITTLE_ENDIAN 1
|
#define TINS_IS_LITTLE_ENDIAN 1
|
||||||
#define TINS_IS_BIG_ENDIAN 0
|
#define TINS_IS_BIG_ENDIAN 0
|
||||||
@@ -51,6 +52,19 @@
|
|||||||
#define TINS_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN)
|
#define TINS_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Define macros to swap bytes using compiler intrinsics when possible
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define TINS_BYTE_SWAP_16(data) _byteswap_ushort(data)
|
||||||
|
#define TINS_BYTE_SWAP_32(data) _byteswap_ulong(data)
|
||||||
|
#define TINS_BYTE_SWAP_64(data) _byteswap_uint64(data)
|
||||||
|
#elif defined(TINS_HAVE_GCC_BUILTIN_SWAP)
|
||||||
|
#define TINS_BYTE_SWAP_16(data) __builtin_bswap16(data)
|
||||||
|
#define TINS_BYTE_SWAP_32(data) __builtin_bswap32(data)
|
||||||
|
#define TINS_BYTE_SWAP_64(data) __builtin_bswap64(data)
|
||||||
|
#else
|
||||||
|
#define TINS_NO_BYTE_SWAP_INTRINSICS
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Endian {
|
namespace Endian {
|
||||||
|
|
||||||
@@ -70,7 +84,11 @@ inline uint8_t do_change_endian(uint8_t data) {
|
|||||||
* \param data The data to convert.
|
* \param data The data to convert.
|
||||||
*/
|
*/
|
||||||
inline uint16_t do_change_endian(uint16_t data) {
|
inline uint16_t do_change_endian(uint16_t data) {
|
||||||
return ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
#ifdef TINS_NO_BYTE_SWAP_INTRINSICS
|
||||||
|
return ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
||||||
|
#else
|
||||||
|
return TINS_BYTE_SWAP_16(data);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,8 +97,12 @@ inline uint16_t do_change_endian(uint16_t data) {
|
|||||||
* \param data The data to convert.
|
* \param data The data to convert.
|
||||||
*/
|
*/
|
||||||
inline uint32_t do_change_endian(uint32_t data) {
|
inline uint32_t do_change_endian(uint32_t data) {
|
||||||
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
|
#ifdef TINS_NO_BYTE_SWAP_INTRINSICS
|
||||||
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
|
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
|
||||||
|
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
|
||||||
|
#else
|
||||||
|
return TINS_BYTE_SWAP_32(data);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,8 +111,12 @@ inline uint32_t do_change_endian(uint32_t data) {
|
|||||||
* \param data The data to convert.
|
* \param data The data to convert.
|
||||||
*/
|
*/
|
||||||
inline uint64_t do_change_endian(uint64_t data) {
|
inline uint64_t do_change_endian(uint64_t data) {
|
||||||
return (((uint64_t)(do_change_endian((uint32_t)(data & 0xffffffff))) << 32) |
|
#ifdef TINS_NO_BYTE_SWAP_INTRINSICS
|
||||||
(do_change_endian(((uint32_t)(data >> 32)))));
|
return (((uint64_t)(do_change_endian((uint32_t)(data & 0xffffffff))) << 32) |
|
||||||
|
(do_change_endian(((uint32_t)(data >> 32)))));
|
||||||
|
#else
|
||||||
|
return TINS_BYTE_SWAP_64(data);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,11 +31,11 @@
|
|||||||
#define TINS_ETHERNET_II_H
|
#define TINS_ETHERNET_II_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -60,6 +60,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static const address_type BROADCAST;
|
static const address_type BROADCAST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructs an ethernet II PDU.
|
* \brief Constructs an ethernet II PDU.
|
||||||
*
|
*
|
||||||
@@ -200,7 +208,7 @@ private:
|
|||||||
uint16_t payload_type;
|
uint16_t payload_type;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
ethernet_header header_;
|
ethernet_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -45,6 +45,9 @@ public:
|
|||||||
|
|
||||||
exception_base(const std::string& message)
|
exception_base(const std::string& message)
|
||||||
: std::runtime_error(message) { }
|
: std::runtime_error(message) { }
|
||||||
|
|
||||||
|
exception_base(const char* message)
|
||||||
|
: std::runtime_error(message) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,10 +55,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class option_not_found : public exception_base {
|
class option_not_found : public exception_base {
|
||||||
public:
|
public:
|
||||||
// try to avoid allocations by doing this.
|
option_not_found() : exception_base("Option not found") { }
|
||||||
const char* what() const throw() {
|
|
||||||
return "Option not found";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,19 +63,33 @@ public:
|
|||||||
*/
|
*/
|
||||||
class malformed_packet : public exception_base {
|
class malformed_packet : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
malformed_packet() : exception_base("Malformed packet") { }
|
||||||
return "Malformed packet";
|
malformed_packet(const std::string& message) : exception_base(message) { }
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a DNS decompression pointer is out of bounds.
|
||||||
|
*/
|
||||||
|
class dns_decompression_pointer_out_of_bounds : public malformed_packet {
|
||||||
|
public:
|
||||||
|
dns_decompression_pointer_out_of_bounds() : malformed_packet("DNS decompression: pointer out of bounds") { }
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a DNS decompression pointer loops.
|
||||||
|
*/
|
||||||
|
class dns_decompression_pointer_loops : public malformed_packet {
|
||||||
|
public:
|
||||||
|
dns_decompression_pointer_loops() : malformed_packet("DNS decompression: pointer loops") { }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Exception thrown when serializing a packet fails.
|
* \brief Exception thrown when serializing a packet fails.
|
||||||
*/
|
*/
|
||||||
class serialization_error : public exception_base {
|
class serialization_error : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
serialization_error() : exception_base("Serialization error") { }
|
||||||
return "Serialization error";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +97,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class pdu_not_found : public exception_base {
|
class pdu_not_found : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
pdu_not_found() : exception_base("PDU not found") { }
|
||||||
return "PDU not found";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,9 +106,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class invalid_interface : public exception_base {
|
class invalid_interface : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
invalid_interface() : exception_base("Invalid interface") { }
|
||||||
return "Invalid interface";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,9 +115,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
class invalid_address : public exception_base {
|
class invalid_address : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
invalid_address() : exception_base("Invalid address") { }
|
||||||
return "Invalid address";
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a PDU option is set using an incorrect value
|
||||||
|
*/
|
||||||
|
class invalid_option_value : public exception_base {
|
||||||
|
public:
|
||||||
|
invalid_option_value() : exception_base("Invalid option value") { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,9 +131,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class field_not_present : public exception_base {
|
class field_not_present : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
field_not_present() : exception_base("Field not present") { }
|
||||||
return "Field not present";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +146,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Exception thrown when PacketSender fails to close a socket.
|
* \brief Exception thrown when PacketSender fails to close a socket.
|
||||||
*/
|
*/
|
||||||
class socket_close_error : exception_base {
|
class socket_close_error : public exception_base {
|
||||||
public:
|
public:
|
||||||
socket_close_error(const std::string& msg)
|
socket_close_error(const std::string& msg)
|
||||||
: exception_base(msg) { }
|
: exception_base(msg) { }
|
||||||
@@ -153,9 +167,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class invalid_socket_type : public exception_base {
|
class invalid_socket_type : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
invalid_socket_type() : exception_base("The provided socket type is invalid") { }
|
||||||
return "The provided socket type is invalid";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,9 +176,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class unknown_link_type : public exception_base {
|
class unknown_link_type : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
unknown_link_type() : exception_base("The sniffed link layer PDU type is unknown") { }
|
||||||
return "The sniffed link layer PDU type is unknown";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,9 +184,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class malformed_option : public exception_base {
|
class malformed_option : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
malformed_option() : exception_base("Malformed option") { }
|
||||||
return "Malformed option";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,9 +192,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class bad_tins_cast : public exception_base {
|
class bad_tins_cast : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
bad_tins_cast() : exception_base("Bad Tins cast") { }
|
||||||
return "Bad Tins cast";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,9 +201,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
class protocol_disabled : public exception_base {
|
class protocol_disabled : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
protocol_disabled() : exception_base("Protocol disabled") { }
|
||||||
return "Protocol disabled";
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a feature has been disabled
|
||||||
|
* at compile time.
|
||||||
|
*/
|
||||||
|
class feature_disabled : public exception_base {
|
||||||
|
public:
|
||||||
|
feature_disabled() : exception_base("Feature disabled") { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,9 +219,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
class option_payload_too_large : public exception_base {
|
class option_payload_too_large : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
option_payload_too_large() : exception_base("Option payload too large") { }
|
||||||
return "Option payload too large";
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when an IPv6 extension header is being
|
||||||
|
* created from invalid data
|
||||||
|
*/
|
||||||
|
class invalid_ipv6_extension_header : public exception_base {
|
||||||
|
public:
|
||||||
|
invalid_ipv6_extension_header() : exception_base("Invalid IPv6 extension header") { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,6 +239,10 @@ public:
|
|||||||
pcap_error(const char* message) : exception_base(message) {
|
pcap_error(const char* message) : exception_base(message) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pcap_error(const std::string& message) : exception_base(message) {
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,9 +261,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class pdu_not_serializable : public exception_base {
|
class pdu_not_serializable : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
pdu_not_serializable() : exception_base("PDU not serializable") { }
|
||||||
return "PDU not serializable";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -247,9 +269,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class pcap_open_failed : public exception_base {
|
class pcap_open_failed : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
pcap_open_failed() : exception_base("Failed to create pcap handle") { }
|
||||||
return "Failed to create pcap handle";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,9 +278,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
class unsupported_function : public exception_base {
|
class unsupported_function : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
unsupported_function() : exception_base("Function is not supported on this OS") { }
|
||||||
return "Function is not supported on this OS";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,9 +286,31 @@ public:
|
|||||||
*/
|
*/
|
||||||
class invalid_domain_name : public exception_base {
|
class invalid_domain_name : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
invalid_domain_name() : exception_base("Invalid domain name") { }
|
||||||
return "Invalid domain name";
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a stream is not found
|
||||||
|
*/
|
||||||
|
class stream_not_found : public exception_base {
|
||||||
|
public:
|
||||||
|
stream_not_found() : exception_base("Stream not found") { }
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when a required callback for an object is not set
|
||||||
|
*/
|
||||||
|
class callback_not_set : public exception_base {
|
||||||
|
public:
|
||||||
|
callback_not_set() : exception_base("Callback not set") { }
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exception thrown when an invalid packet is provided to some function
|
||||||
|
*/
|
||||||
|
class invalid_packet : public exception_base {
|
||||||
|
public:
|
||||||
|
invalid_packet() : exception_base("Invalid packet") { }
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Crypto {
|
namespace Crypto {
|
||||||
@@ -280,9 +320,7 @@ namespace WPA2 {
|
|||||||
*/
|
*/
|
||||||
class invalid_handshake : public exception_base {
|
class invalid_handshake : public exception_base {
|
||||||
public:
|
public:
|
||||||
const char* what() const throw() {
|
invalid_handshake() : exception_base("Invalid WPA2 handshake") { }
|
||||||
return "Invalid WPA2 handshake";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} // WPA2
|
} // WPA2
|
||||||
} // Crypto
|
} // Crypto
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -27,17 +27,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include <tins/config.h>
|
||||||
|
|
||||||
#if !defined(TINS_HANDSHAKE_CAPTURER_H) && defined(HAVE_DOT11)
|
#if !defined(TINS_HANDSHAKE_CAPTURER_H) && defined(TINS_HAVE_DOT11)
|
||||||
#define TINS_HANDSHAKE_CAPTURER_H
|
#define TINS_HANDSHAKE_CAPTURER_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "eapol.h"
|
#include <tins/eapol.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,15 +31,41 @@
|
|||||||
#define TINS_HWADDRESS_H
|
#define TINS_HWADDRESS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdexcept>
|
#include <iosfwd>
|
||||||
#include <iterator>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <tins/cxxstd.h>
|
||||||
#include <iostream>
|
#include <tins/macros.h>
|
||||||
#include <sstream>
|
#if TINS_IS_CXX11
|
||||||
#include "cxxstd.h"
|
// std::hash
|
||||||
|
#include <memory>
|
||||||
|
#endif // TINS_IS_CXX11
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
namespace Internals {
|
||||||
|
|
||||||
|
// Defined in hw_address.cpp
|
||||||
|
/**
|
||||||
|
* \cond
|
||||||
|
*/
|
||||||
|
TINS_API std::string hw_address_to_string(const uint8_t* ptr, size_t count);
|
||||||
|
|
||||||
|
TINS_API void string_to_hw_address(const std::string& hw_addr, uint8_t* output,
|
||||||
|
size_t output_size);
|
||||||
|
|
||||||
|
TINS_API bool hw_address_equal_compare(const uint8_t* start1, const uint8_t* end1,
|
||||||
|
const uint8_t* start2);
|
||||||
|
|
||||||
|
TINS_API bool hw_address_lt_compare(const uint8_t* start1, const uint8_t* end1,
|
||||||
|
const uint8_t* start2, const uint8_t* end2);
|
||||||
|
|
||||||
|
TINS_API bool hw_address_gt_compare(const uint8_t* start1, const uint8_t* end1,
|
||||||
|
const uint8_t* start2, const uint8_t* end2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \endcond
|
||||||
|
*/
|
||||||
|
} // Internals
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class HWAddress
|
* \class HWAddress
|
||||||
@@ -61,15 +87,13 @@ namespace Tins {
|
|||||||
* }
|
* }
|
||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
template<size_t n, typename Storage = uint8_t>
|
template<size_t n>
|
||||||
class HWAddress {
|
class HWAddress {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \brief The type of the elements stored in the hardware address.
|
* \brief The type of the elements stored in the hardware address.
|
||||||
*
|
|
||||||
* This is the same as the template parameter Storage.
|
|
||||||
*/
|
*/
|
||||||
typedef Storage storage_type;
|
typedef uint8_t storage_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief The random access iterator type.
|
* \brief The random access iterator type.
|
||||||
@@ -90,7 +114,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief The broadcast address.
|
* \brief The broadcast address.
|
||||||
*/
|
*/
|
||||||
static const HWAddress<n, Storage> broadcast;
|
static const HWAddress<n> broadcast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructor from a const storage_type*.
|
* \brief Constructor from a const storage_type*.
|
||||||
@@ -109,10 +133,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
HWAddress(const storage_type* ptr = 0) {
|
HWAddress(const storage_type* ptr = 0) {
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
std::copy(ptr, ptr + address_size, buffer_);
|
std::memcpy(buffer_, ptr, address_size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::fill(begin(), end(), storage_type());
|
std::memset(buffer_, 0, address_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +152,7 @@ public:
|
|||||||
* \param address The hex-notation address to be parsed.
|
* \param address The hex-notation address to be parsed.
|
||||||
*/
|
*/
|
||||||
HWAddress(const std::string& address) {
|
HWAddress(const std::string& address) {
|
||||||
convert(address, buffer_);
|
Internals::string_to_hw_address(address, buffer_, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +170,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<size_t i>
|
template<size_t i>
|
||||||
HWAddress(const char (&address)[i]) {
|
HWAddress(const char (&address)[i]) {
|
||||||
convert(address, buffer_);
|
Internals::string_to_hw_address(address, buffer_, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,18 +187,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<size_t i>
|
template<size_t i>
|
||||||
HWAddress(const HWAddress<i>& rhs) {
|
HWAddress(const HWAddress<i>& rhs) {
|
||||||
// Fill extra bytes
|
size_t copy_threshold = i < n ? i : n;
|
||||||
std::fill(
|
for (size_t index = 0; index < n; ++index) {
|
||||||
// Copy as most as we can
|
if (index < copy_threshold) {
|
||||||
std::copy(
|
buffer_[index] = rhs[index];
|
||||||
rhs.begin(),
|
}
|
||||||
rhs.begin() + std::min(i, n),
|
else {
|
||||||
begin()
|
buffer_[index] = storage_type();
|
||||||
),
|
}
|
||||||
end(),
|
}
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,7 +246,7 @@ public:
|
|||||||
* \return bool indicating whether addresses are equal.
|
* \return bool indicating whether addresses are equal.
|
||||||
*/
|
*/
|
||||||
bool operator==(const HWAddress& rhs) const {
|
bool operator==(const HWAddress& rhs) const {
|
||||||
return std::equal(begin(), end(), rhs.begin());
|
return Internals::hw_address_equal_compare(begin(), end(), rhs.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -247,15 +268,88 @@ public:
|
|||||||
* \return bool indicating whether this address is less-than rhs.
|
* \return bool indicating whether this address is less-than rhs.
|
||||||
*/
|
*/
|
||||||
bool operator<(const HWAddress& rhs) const {
|
bool operator<(const HWAddress& rhs) const {
|
||||||
return std::lexicographical_compare(begin(), end(), rhs.begin(), rhs.end());
|
return Internals::hw_address_lt_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compares this HWAddress for less-than equality.
|
||||||
|
*
|
||||||
|
* \param rhs The HWAddress to be compared to.
|
||||||
|
*
|
||||||
|
* \return bool indicating whether this address is equal or less-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator<=(const HWAddress& rhs) const {
|
||||||
|
return !operator>(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compares this HWAddress for greater-than inequality.
|
||||||
|
*
|
||||||
|
* \param rhs The HWAddress to be compared to.
|
||||||
|
*
|
||||||
|
* \return bool indicating whether this address is greater-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator>(const HWAddress& rhs) const {
|
||||||
|
return Internals::hw_address_gt_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compares this HWAddress for greater-than equality.
|
||||||
|
*
|
||||||
|
* \param rhs The HWAddress to be compared to.
|
||||||
|
*
|
||||||
|
* \return bool indicating whether this address is equal or greater-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator>=(const HWAddress& rhs) const {
|
||||||
|
return !operator<(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Apply a mask to this address
|
||||||
|
*
|
||||||
|
* \param mask The mask to be applied
|
||||||
|
* \return The result of applying the mask to this address
|
||||||
|
*/
|
||||||
|
HWAddress operator&(const HWAddress& mask) const {
|
||||||
|
HWAddress<n> output = *this;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
output[i] = output[i] & mask[i];
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Apply a mask to this address
|
||||||
|
*
|
||||||
|
* \param mask The mask to be applied
|
||||||
|
* \return The result of applying the mask to this address
|
||||||
|
*/
|
||||||
|
HWAddress operator|(const HWAddress& mask) const {
|
||||||
|
HWAddress<n> output = *this;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
output[i] = output[i] | mask[i];
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief not operator
|
||||||
|
* \return The result of applying the mask to this address
|
||||||
|
*/
|
||||||
|
HWAddress operator~() const {
|
||||||
|
HWAddress<n> output = *this;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
output[i] = ~output[i];
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retrieves the size of this address.
|
* \brief Retrieves the size of this address.
|
||||||
*
|
*
|
||||||
* This effectively returns the address_size constant.
|
* This effectively returns the address_size constant.
|
||||||
*/
|
*/
|
||||||
const size_t size() const {
|
size_t size() const {
|
||||||
return address_size;
|
return address_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,9 +380,7 @@ public:
|
|||||||
* \return std::string containing the hex-notation address.
|
* \return std::string containing the hex-notation address.
|
||||||
*/
|
*/
|
||||||
std::string to_string() const {
|
std::string to_string() const {
|
||||||
std::ostringstream oss;
|
return Internals::hw_address_to_string(buffer_, size());
|
||||||
oss <<* this;
|
|
||||||
return oss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -300,6 +392,15 @@ public:
|
|||||||
return begin()[i];
|
return begin()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieves the i-th storage_type in this address.
|
||||||
|
*
|
||||||
|
* \param i The element to retrieve.
|
||||||
|
*/
|
||||||
|
storage_type& operator[](size_t i) {
|
||||||
|
return begin()[i];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Writes this HWAddress in hex-notation to a std::ostream.
|
* \brief Writes this HWAddress in hex-notation to a std::ostream.
|
||||||
*
|
*
|
||||||
@@ -308,13 +409,7 @@ public:
|
|||||||
* \return std::ostream& pointing to the os parameter.
|
* \return std::ostream& pointing to the os parameter.
|
||||||
*/
|
*/
|
||||||
friend std::ostream& operator<<(std::ostream& os, const HWAddress& addr) {
|
friend std::ostream& operator<<(std::ostream& os, const HWAddress& addr) {
|
||||||
std::transform(
|
return os << addr.to_string();
|
||||||
addr.begin(),
|
|
||||||
addr.end() - 1,
|
|
||||||
std::ostream_iterator<std::string>(os, ":"),
|
|
||||||
&HWAddress::storage_to_string
|
|
||||||
);
|
|
||||||
return os << storage_to_string(addr.begin()[HWAddress::address_size - 1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -340,9 +435,6 @@ public:
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
template<typename OutputIterator>
|
|
||||||
static void convert(const std::string& hw_addr, OutputIterator output);
|
|
||||||
|
|
||||||
static HWAddress<n> make_broadcast_address() {
|
static HWAddress<n> make_broadcast_address() {
|
||||||
// Build a buffer made of n 0xff bytes
|
// Build a buffer made of n 0xff bytes
|
||||||
uint8_t buffer[n];
|
uint8_t buffer[n];
|
||||||
@@ -352,65 +444,11 @@ private:
|
|||||||
return HWAddress<n>(buffer);
|
return HWAddress<n>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string storage_to_string(storage_type element) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << std::hex;
|
|
||||||
if (element < 0x10) {
|
|
||||||
oss << '0';
|
|
||||||
}
|
|
||||||
oss << (unsigned)element;
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
storage_type buffer_[n];
|
storage_type buffer_[n];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<size_t n, typename Storage>
|
template<size_t n>
|
||||||
template<typename OutputIterator>
|
const HWAddress<n> HWAddress<n>::broadcast = make_broadcast_address();
|
||||||
void HWAddress<n, Storage>::convert(const std::string& hw_addr,
|
|
||||||
OutputIterator output) {
|
|
||||||
unsigned i(0);
|
|
||||||
size_t count(0);
|
|
||||||
storage_type tmp;
|
|
||||||
while (i < hw_addr.size() && count < n) {
|
|
||||||
const unsigned end = i+2;
|
|
||||||
tmp = storage_type();
|
|
||||||
while (i < end) {
|
|
||||||
if (hw_addr[i] >= 'a' && hw_addr[i] <= 'f') {
|
|
||||||
tmp = (tmp << 4) | (hw_addr[i] - 'a' + 10);
|
|
||||||
}
|
|
||||||
else if (hw_addr[i] >= 'A' && hw_addr[i] <= 'F') {
|
|
||||||
tmp = (tmp << 4) | (hw_addr[i] - 'A' + 10);
|
|
||||||
}
|
|
||||||
else if (hw_addr[i] >= '0' && hw_addr[i] <= '9') {
|
|
||||||
tmp = (tmp << 4) | (hw_addr[i] - '0');
|
|
||||||
}
|
|
||||||
else if (hw_addr[i] == ':') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw std::runtime_error("Invalid byte found");
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
*(output++) = tmp;
|
|
||||||
count++;
|
|
||||||
if (i < hw_addr.size()) {
|
|
||||||
if (hw_addr[i] == ':') {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw std::runtime_error("Invalid separator");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (count++ < n) {
|
|
||||||
*(output++) = storage_type();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t n, typename Storage>
|
|
||||||
const HWAddress<n, Storage> HWAddress<n, Storage>::broadcast = make_broadcast_address();
|
|
||||||
|
|
||||||
} // namespace Tins
|
} // namespace Tins
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -42,11 +42,11 @@
|
|||||||
#endif // TIMESTAMP_REPLY
|
#endif // TIMESTAMP_REPLY
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "ip_address.h"
|
#include <tins/ip_address.h>
|
||||||
#include "icmp_extension.h"
|
#include <tins/icmp_extension.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -89,9 +89,19 @@ public:
|
|||||||
INFO_REQUEST = 15,
|
INFO_REQUEST = 15,
|
||||||
INFO_REPLY = 16,
|
INFO_REPLY = 16,
|
||||||
ADDRESS_MASK_REQUEST = 17,
|
ADDRESS_MASK_REQUEST = 17,
|
||||||
ADDRESS_MASK_REPLY = 18
|
ADDRESS_MASK_REPLY = 18,
|
||||||
|
EXTENDED_ECHO_REQUEST = 42,
|
||||||
|
EXTENDED_ECHO_REPLY = 43
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Creates an instance of ICMP.
|
* \brief Creates an instance of ICMP.
|
||||||
*
|
*
|
||||||
@@ -310,7 +320,7 @@ public:
|
|||||||
* \return Returns the gateway field value.
|
* \return Returns the gateway field value.
|
||||||
*/
|
*/
|
||||||
address_type gateway() const {
|
address_type gateway() const {
|
||||||
return address_type(Endian::be_to_host(header_.un.gateway));
|
return address_type(header_.un.gateway);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -373,13 +383,13 @@ public:
|
|||||||
* \return Returns the address mask value.
|
* \return Returns the address mask value.
|
||||||
*/
|
*/
|
||||||
address_type address_mask() const {
|
address_type address_mask() const {
|
||||||
return address_type(Endian::be_to_host(orig_timestamp_or_address_mask_));
|
return address_type(orig_timestamp_or_address_mask_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. This size includes the
|
* This method overrides PDU::header_size. This size includes the
|
||||||
* payload and options size.
|
* payload and options size.
|
||||||
*
|
*
|
||||||
* \sa PDU::header_size
|
* \sa PDU::header_size
|
||||||
@@ -389,7 +399,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the trailer size.
|
* \brief Returns the trailer size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::trailer_size. This size will hold the extensions size
|
* This method overrides PDU::trailer_size. This size will hold the extensions size
|
||||||
*
|
*
|
||||||
* \sa PDU::header_size
|
* \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
@@ -486,20 +496,15 @@ private:
|
|||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void checksum(uint16_t new_check);
|
void checksum(uint16_t new_check);
|
||||||
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
/** \brief Serialices this ICMP PDU.
|
|
||||||
* \param buffer The buffer in which the PDU will be serialized.
|
|
||||||
* \param total_sz The size available in the buffer.
|
|
||||||
* \param parent The PDU that's one level below this one on the stack.
|
|
||||||
*/
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
|
||||||
|
|
||||||
uint32_t get_adjusted_inner_pdu_size() const;
|
uint32_t get_adjusted_inner_pdu_size() const;
|
||||||
void try_parse_extensions(Memory::InputMemoryStream& stream);
|
void try_parse_extensions(Memory::InputMemoryStream& stream);
|
||||||
bool are_extensions_allowed() const;
|
bool are_extensions_allowed() const;
|
||||||
|
|
||||||
icmp_header header_;
|
icmp_header header_;
|
||||||
uint32_t orig_timestamp_or_address_mask_, recv_timestamp_, trans_timestamp_;
|
uint32_t orig_timestamp_or_address_mask_;
|
||||||
|
uint32_t recv_timestamp_;
|
||||||
|
uint32_t trans_timestamp_;
|
||||||
ICMPExtensionsStructure extensions_;
|
ICMPExtensionsStructure extensions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,11 +31,10 @@
|
|||||||
#define TINS_ICMP_EXTENSION_H
|
#define TINS_ICMP_EXTENSION_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "small_uint.h"
|
#include <tins/small_uint.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store the list of ICMP extensions in this structure
|
* The type used to store the list of ICMP extensions in this structure
|
||||||
*/
|
*/
|
||||||
typedef std::list<ICMPExtension> extensions_type;
|
typedef std::vector<ICMPExtension> extensions_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Default constructor
|
* \brief Default constructor
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,18 +30,18 @@
|
|||||||
#ifndef TINS_ICMPV6_H
|
#ifndef TINS_ICMPV6_H
|
||||||
#define TINS_ICMPV6_H
|
#define TINS_ICMPV6_H
|
||||||
|
|
||||||
#include <list>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "ipv6_address.h"
|
#include <tins/ipv6_address.h>
|
||||||
#include "pdu_option.h"
|
#include <tins/pdu_option.h>
|
||||||
#include "endianness.h"
|
#include <tins/endianness.h>
|
||||||
#include "small_uint.h"
|
#include <tins/small_uint.h>
|
||||||
#include "hw_address.h"
|
#include <tins/hw_address.h>
|
||||||
#include "small_uint.h"
|
#include <tins/small_uint.h>
|
||||||
#include "icmp_extension.h"
|
#include <tins/icmp_extension.h>
|
||||||
#include "cxxstd.h"
|
#include <tins/cxxstd.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -80,14 +80,22 @@ public:
|
|||||||
NEIGHBOUR_SOLICIT = 135,
|
NEIGHBOUR_SOLICIT = 135,
|
||||||
NEIGHBOUR_ADVERT = 136,
|
NEIGHBOUR_ADVERT = 136,
|
||||||
REDIRECT = 137,
|
REDIRECT = 137,
|
||||||
ROUTER_RENUMBER = 137,
|
ROUTER_RENUMBER = 138,
|
||||||
NI_QUERY = 139,
|
NI_QUERY = 139,
|
||||||
NI_REPLY = 140,
|
NI_REPLY = 140,
|
||||||
MLD2_REPORT = 143,
|
MLD2_REPORT = 143,
|
||||||
DHAAD_REQUEST = 144,
|
DHAAD_REQUEST = 144,
|
||||||
DHAAD_REPLY = 145,
|
DHAAD_REPLY = 145,
|
||||||
MOBILE_PREFIX_SOL = 146,
|
MOBILE_PREFIX_SOLICIT = 146,
|
||||||
MOBILE_PREFIX_ADV = 147
|
MOBILE_PREFIX_ADVERT = 147,
|
||||||
|
CERT_PATH_SOLICIT = 148,
|
||||||
|
CERT_PATH_ADVERT = 149,
|
||||||
|
MULTICAST_ROUTER_ADVERT = 151,
|
||||||
|
MULTICAST_ROUTER_SOLICIT = 152,
|
||||||
|
MULTICAST_ROUTER_TERMINATE = 153,
|
||||||
|
RPL_CONTROL_MSG = 155,
|
||||||
|
EXTENDED_ECHO_REQUEST = 160,
|
||||||
|
EXTENDED_ECHO_REPLY = 161
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +157,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store options.
|
* The type used to store options.
|
||||||
*/
|
*/
|
||||||
typedef std::list<option> options_type;
|
typedef std::vector<option> options_type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief The type used to store the new home agent information
|
* \brief The type used to store the new home agent information
|
||||||
@@ -168,7 +176,7 @@ public:
|
|||||||
|
|
||||||
addr_list_type(const addresses_type& addresses = addresses_type())
|
addr_list_type(const addresses_type& addresses = addresses_type())
|
||||||
: addresses(addresses) {
|
: addresses(addresses) {
|
||||||
std::fill(reserved, reserved + sizeof(reserved), 0);
|
std::fill(reserved, reserved + sizeof(reserved), static_cast<uint8_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static addr_list_type from_option(const option& opt);
|
static addr_list_type from_option(const option& opt);
|
||||||
@@ -194,7 +202,7 @@ public:
|
|||||||
|
|
||||||
naack_type(uint8_t code = 0, uint8_t status = 0)
|
naack_type(uint8_t code = 0, uint8_t status = 0)
|
||||||
: code(code), status(status) {
|
: code(code), status(status) {
|
||||||
std::fill(reserved, reserved + 4, 0);
|
std::fill(reserved, reserved + 4, static_cast<uint8_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static naack_type from_option(const option& opt);
|
static naack_type from_option(const option& opt);
|
||||||
@@ -245,8 +253,8 @@ public:
|
|||||||
uint8_t prefix_len;
|
uint8_t prefix_len;
|
||||||
small_uint<1> A, L;
|
small_uint<1> A, L;
|
||||||
uint32_t valid_lifetime,
|
uint32_t valid_lifetime,
|
||||||
preferred_lifetime,
|
preferred_lifetime,
|
||||||
reserved2;
|
reserved2;
|
||||||
ipaddress_type prefix;
|
ipaddress_type prefix;
|
||||||
|
|
||||||
prefix_info_type(uint8_t prefix_len = 0,
|
prefix_info_type(uint8_t prefix_len = 0,
|
||||||
@@ -256,7 +264,7 @@ public:
|
|||||||
uint32_t preferred_lifetime = 0,
|
uint32_t preferred_lifetime = 0,
|
||||||
const ipaddress_type& prefix = ipaddress_type())
|
const ipaddress_type& prefix = ipaddress_type())
|
||||||
: prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
|
: prefix_len(prefix_len), A(A), L(L), valid_lifetime(valid_lifetime),
|
||||||
preferred_lifetime(preferred_lifetime), prefix(prefix) { }
|
preferred_lifetime(preferred_lifetime), reserved2(0), prefix(prefix) { }
|
||||||
|
|
||||||
static prefix_info_type from_option(const option& opt);
|
static prefix_info_type from_option(const option& opt);
|
||||||
};
|
};
|
||||||
@@ -318,7 +326,7 @@ public:
|
|||||||
* The key_hash member will be 0-initialized.
|
* The key_hash member will be 0-initialized.
|
||||||
*/
|
*/
|
||||||
rsa_sign_type() {
|
rsa_sign_type() {
|
||||||
std::fill(key_hash, key_hash + sizeof(key_hash), 0);
|
std::fill(key_hash, key_hash + sizeof(key_hash), static_cast<uint8_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static rsa_sign_type from_option(const option& opt);
|
static rsa_sign_type from_option(const option& opt);
|
||||||
@@ -484,7 +492,7 @@ public:
|
|||||||
|
|
||||||
timestamp_type(uint64_t timestamp = 0)
|
timestamp_type(uint64_t timestamp = 0)
|
||||||
: timestamp(timestamp) {
|
: timestamp(timestamp) {
|
||||||
std::fill(reserved, reserved + sizeof(reserved), 0);
|
std::fill(reserved, reserved + sizeof(reserved), static_cast<uint8_t>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static timestamp_type from_option(const option& opt);
|
static timestamp_type from_option(const option& opt);
|
||||||
@@ -542,13 +550,13 @@ public:
|
|||||||
/*
|
/*
|
||||||
* The type used to store all multicast address records in a packet
|
* The type used to store all multicast address records in a packet
|
||||||
*/
|
*/
|
||||||
typedef std::list<multicast_address_record> multicast_address_records_list;
|
typedef std::vector<multicast_address_record> multicast_address_records_list;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The type used to store all source address (from Multicast
|
* The type used to store all source address (from Multicast
|
||||||
* Listener Query messages) in a packet
|
* Listener Query messages) in a packet
|
||||||
*/
|
*/
|
||||||
typedef std::list<ipaddress_type> sources_list;
|
typedef std::vector<ipaddress_type> sources_list;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructs an ICMPv6 object.
|
* \brief Constructs an ICMPv6 object.
|
||||||
@@ -1027,7 +1035,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. This size includes the
|
* This method overrides PDU::header_size. This size includes the
|
||||||
* payload and options size. \sa PDU::header_size
|
* payload and options size. \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
uint32_t header_size() const;
|
uint32_t header_size() const;
|
||||||
@@ -1035,7 +1043,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the trailer size.
|
* \brief Returns the trailer size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::trailer_size. This size will hold the extensions size
|
* This method overrides PDU::trailer_size. This size will hold the extensions size
|
||||||
*
|
*
|
||||||
* \sa PDU::header_size
|
* \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
@@ -1110,6 +1118,17 @@ public:
|
|||||||
return new ICMPv6(*this);
|
return new ICMPv6(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Indicates whether to use MLDv2
|
||||||
|
*
|
||||||
|
* If this is set to true, then MLDv2 will be used rather than MLDv1 when
|
||||||
|
* serializing Multicast Listener Discovery messages. By default,
|
||||||
|
* MLDv2 will be used.
|
||||||
|
*
|
||||||
|
* \param value The value to set
|
||||||
|
*/
|
||||||
|
void use_mldv2(bool value);
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
// Option setters
|
// Option setters
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
@@ -1542,7 +1561,7 @@ private:
|
|||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void internal_add_option(const option& option);
|
void internal_add_option(const option& option);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
bool has_options() const;
|
bool has_options() const;
|
||||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||||
void parse_options(Memory::InputMemoryStream& stream);
|
void parse_options(Memory::InputMemoryStream& stream);
|
||||||
@@ -1584,6 +1603,7 @@ private:
|
|||||||
multicast_listener_query_message_fields mlqm_;
|
multicast_listener_query_message_fields mlqm_;
|
||||||
sources_list sources_;
|
sources_list sources_;
|
||||||
ICMPExtensionsStructure extensions_;
|
ICMPExtensionsStructure extensions_;
|
||||||
|
bool use_mldv2_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Tins
|
} // Tins
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
#ifndef TINS_IEEE802_3_H
|
#ifndef TINS_IEEE802_3_H
|
||||||
#define TINS_IEEE802_3_H
|
#define TINS_IEEE802_3_H
|
||||||
|
|
||||||
#include "dot3.h"
|
#include <tins/dot3.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
typedef Dot3 IEEE802_3;
|
typedef Dot3 IEEE802_3;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,227 +30,11 @@
|
|||||||
#ifndef TINS_INTERNALS_H
|
#ifndef TINS_INTERNALS_H
|
||||||
#define TINS_INTERNALS_H
|
#define TINS_INTERNALS_H
|
||||||
|
|
||||||
#if TINS_IS_CXX11
|
#include <tins/detail/type_traits.h>
|
||||||
#include <type_traits>
|
#include <tins/detail/address_helpers.h>
|
||||||
#endif
|
#include <tins/detail/icmp_extension_helpers.h>
|
||||||
|
#include <tins/detail/smart_ptr.h>
|
||||||
#include <sstream>
|
#include <tins/detail/pdu_helpers.h>
|
||||||
#include <string>
|
#include <tins/detail/sequence_number_helpers.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include "constants.h"
|
|
||||||
#include "pdu.h"
|
|
||||||
#include "hw_address.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \cond
|
|
||||||
*/
|
|
||||||
namespace Tins {
|
|
||||||
namespace Memory {
|
|
||||||
|
|
||||||
class InputMemoryStream;
|
|
||||||
} // Memory
|
|
||||||
class IPv4Address;
|
|
||||||
class IPv6Address;
|
|
||||||
class ICMPExtensionsStructure;
|
|
||||||
|
|
||||||
namespace Internals {
|
|
||||||
|
|
||||||
template<size_t n>
|
|
||||||
class byte_array {
|
|
||||||
public:
|
|
||||||
typedef uint8_t* iterator;
|
|
||||||
typedef const uint8_t* const_iterator;
|
|
||||||
|
|
||||||
byte_array() {
|
|
||||||
std::fill(begin(), end(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
byte_array(InputIterator start, InputIterator last) {
|
|
||||||
std::copy(start, last, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename InputIterator>
|
|
||||||
byte_array(InputIterator start) {
|
|
||||||
std::copy(start, n, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t& operator[](size_t i) {
|
|
||||||
return data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t operator[](size_t i) const{
|
|
||||||
return data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator begin() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator end() {
|
|
||||||
return data + n;
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator begin() const {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator end() const {
|
|
||||||
return data + n;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size() const {
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
uint8_t data[n];
|
|
||||||
};
|
|
||||||
|
|
||||||
void skip_line(std::istream& input);
|
|
||||||
bool from_hex(const std::string& str, uint32_t& result);
|
|
||||||
|
|
||||||
template<bool, typename T = void>
|
|
||||||
struct enable_if {
|
|
||||||
typedef T type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct enable_if<false, T> {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer,
|
|
||||||
uint32_t size, bool rawpdu_on_no_match = true);
|
|
||||||
PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer,
|
|
||||||
uint32_t size, bool rawpdu_on_no_match = true);
|
|
||||||
PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer,
|
|
||||||
uint32_t size, bool rawpdu_on_no_match = true);
|
|
||||||
PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size);
|
|
||||||
|
|
||||||
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
|
|
||||||
Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag);
|
|
||||||
|
|
||||||
uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment);
|
|
||||||
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream,
|
|
||||||
uint32_t payload_length, ICMPExtensionsStructure& extensions);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool increment_buffer(T& addr) {
|
|
||||||
typename T::iterator it = addr.end() - 1;
|
|
||||||
while (it >= addr.begin() && *it == 0xff) {
|
|
||||||
*it = 0;
|
|
||||||
--it;
|
|
||||||
}
|
|
||||||
// reached end
|
|
||||||
if (it < addr.begin()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
(*it)++;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool decrement_buffer(T& addr) {
|
|
||||||
typename T::iterator it = addr.end() - 1;
|
|
||||||
while (it >= addr.begin() && *it == 0) {
|
|
||||||
*it = 0xff;
|
|
||||||
--it;
|
|
||||||
}
|
|
||||||
// reached end
|
|
||||||
if (it < addr.begin()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
(*it)--;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool increment(IPv4Address& addr);
|
|
||||||
bool increment(IPv6Address& addr);
|
|
||||||
bool decrement(IPv4Address& addr);
|
|
||||||
bool decrement(IPv6Address& addr);
|
|
||||||
template<size_t n>
|
|
||||||
bool increment(HWAddress<n>& addr) {
|
|
||||||
return increment_buffer(addr);
|
|
||||||
}
|
|
||||||
template<size_t n>
|
|
||||||
bool decrement(HWAddress<n>& addr) {
|
|
||||||
return decrement_buffer(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask);
|
|
||||||
IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask);
|
|
||||||
template<size_t n>
|
|
||||||
HWAddress<n> last_address_from_mask(HWAddress<n> addr, const HWAddress<n>& mask) {
|
|
||||||
typename HWAddress<n>::iterator addr_iter = addr.begin();
|
|
||||||
for (typename HWAddress<n>::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) {
|
|
||||||
*addr_iter = *addr_iter | ~*it;
|
|
||||||
}
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool is_dot3(const uint8_t* ptr, size_t sz) {
|
|
||||||
return (sz >= 13 && ptr[12] < 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct is_unsigned_integral {
|
|
||||||
static const bool value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct is_unsigned_integral<uint8_t> {
|
|
||||||
static const bool value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct is_unsigned_integral<uint16_t> {
|
|
||||||
static const bool value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct is_unsigned_integral<uint32_t> {
|
|
||||||
static const bool value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct is_unsigned_integral<uint64_t> {
|
|
||||||
static const bool value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if TINS_IS_CXX11 && !defined(_MSC_VER)
|
|
||||||
|
|
||||||
// Template metaprogramming trait to determine if a functor can accept another parameter as an argument
|
|
||||||
template <typename T, typename P, typename=void>
|
|
||||||
struct accepts_type : std::false_type { };
|
|
||||||
|
|
||||||
template <typename T, typename P>
|
|
||||||
struct accepts_type<T, P,
|
|
||||||
typename std::enable_if<
|
|
||||||
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
|
|
||||||
>::type
|
|
||||||
> : std::true_type { };
|
|
||||||
|
|
||||||
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior
|
|
||||||
template <typename Functor, typename Packet>
|
|
||||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<accepts_type<Functor, Packet>::value, bool>::type* = 0) {
|
|
||||||
return f(std::move(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Functor, typename Packet>
|
|
||||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
|
||||||
return f(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Functor, typename Packet>
|
|
||||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && !accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
|
||||||
return f(*p.pdu());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace Internals
|
|
||||||
} // namespace Tins
|
|
||||||
/**
|
|
||||||
* \endcond
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -30,14 +30,13 @@
|
|||||||
#ifndef TINS_IP_H
|
#ifndef TINS_IP_H
|
||||||
#define TINS_IP_H
|
#define TINS_IP_H
|
||||||
|
|
||||||
#include <list>
|
#include <tins/pdu.h>
|
||||||
#include "pdu.h"
|
#include <tins/small_uint.h>
|
||||||
#include "small_uint.h"
|
#include <tins/endianness.h>
|
||||||
#include "endianness.h"
|
#include <tins/ip_address.h>
|
||||||
#include "ip_address.h"
|
#include <tins/pdu_option.h>
|
||||||
#include "pdu_option.h"
|
#include <tins/macros.h>
|
||||||
#include "macros.h"
|
#include <tins/cxxstd.h>
|
||||||
#include "cxxstd.h"
|
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
@@ -175,9 +174,9 @@ public:
|
|||||||
option_identifier(OptionNumber number, OptionClass op_class,
|
option_identifier(OptionNumber number, OptionClass op_class,
|
||||||
small_uint<1> copied)
|
small_uint<1> copied)
|
||||||
#if TINS_IS_LITTLE_ENDIAN
|
#if TINS_IS_LITTLE_ENDIAN
|
||||||
: number(number), op_class(op_class), copied(copied) {}
|
: number(static_cast<uint8_t>(number)), op_class(static_cast<uint8_t>(op_class)), copied(copied) {}
|
||||||
#else
|
#else
|
||||||
: copied(copied), op_class(op_class), number(number) {}
|
: copied(copied), op_class(static_cast<uint8_t>(op_class)), number(static_cast<uint8_t>(number)) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,7 +243,15 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The type used to store IP options.
|
* The type used to store IP options.
|
||||||
*/
|
*/
|
||||||
typedef std::list<option> options_type;
|
typedef std::vector<option> options_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||||
|
*
|
||||||
|
* \param buffer Pointer to a buffer
|
||||||
|
* \param total_sz Size of the buffer pointed by buffer
|
||||||
|
*/
|
||||||
|
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructor for building the IP PDU.
|
* \brief Constructor for building the IP PDU.
|
||||||
@@ -274,13 +281,17 @@ public:
|
|||||||
|
|
||||||
/* Getters */
|
/* Getters */
|
||||||
|
|
||||||
|
uint32_t advertised_size() const {
|
||||||
|
return static_cast<uint32_t>(tot_len());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Getter for the header length field.
|
* \brief Getter for the header length field.
|
||||||
*
|
*
|
||||||
* \return The number of dwords the header occupies in an uin8_t.
|
* \return The number of dwords the header occupies in an uin8_t.
|
||||||
*/
|
*/
|
||||||
small_uint<4> head_len() const {
|
small_uint<4> head_len() const {
|
||||||
return this->ip_.ihl;
|
return this->header_.ihl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -289,7 +300,7 @@ public:
|
|||||||
* \return The this IP PDU's type of service.
|
* \return The this IP PDU's type of service.
|
||||||
*/
|
*/
|
||||||
uint8_t tos() const {
|
uint8_t tos() const {
|
||||||
return ip_.tos;
|
return header_.tos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,7 +309,7 @@ public:
|
|||||||
* \return The total length of this IP PDU.
|
* \return The total length of this IP PDU.
|
||||||
*/
|
*/
|
||||||
uint16_t tot_len() const {
|
uint16_t tot_len() const {
|
||||||
return Endian::be_to_host(ip_.tot_len);
|
return Endian::be_to_host(header_.tot_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -307,7 +318,7 @@ public:
|
|||||||
* \return The id for this IP PDU.
|
* \return The id for this IP PDU.
|
||||||
*/
|
*/
|
||||||
uint16_t id() const {
|
uint16_t id() const {
|
||||||
return Endian::be_to_host(ip_.id);
|
return Endian::be_to_host(header_.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -321,7 +332,7 @@ public:
|
|||||||
* \sa IP::flags
|
* \sa IP::flags
|
||||||
*/
|
*/
|
||||||
TINS_DEPRECATED(uint16_t frag_off() const) {
|
TINS_DEPRECATED(uint16_t frag_off() const) {
|
||||||
return Endian::be_to_host(ip_.frag_off);
|
return Endian::be_to_host(header_.frag_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -333,7 +344,7 @@ public:
|
|||||||
* \return The fragment offset, measured in units of 8 byte blocks
|
* \return The fragment offset, measured in units of 8 byte blocks
|
||||||
*/
|
*/
|
||||||
small_uint<13> fragment_offset() const {
|
small_uint<13> fragment_offset() const {
|
||||||
return Endian::be_to_host(ip_.frag_off) & 0x1fff;
|
return Endian::be_to_host(header_.frag_off) & 0x1fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -342,7 +353,7 @@ public:
|
|||||||
* \return The IP flags field
|
* \return The IP flags field
|
||||||
*/
|
*/
|
||||||
Flags flags() const {
|
Flags flags() const {
|
||||||
return static_cast<Flags>(Endian::be_to_host(ip_.frag_off) >> 13);
|
return static_cast<Flags>(Endian::be_to_host(header_.frag_off) >> 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -351,7 +362,7 @@ public:
|
|||||||
* \return The time to live for this IP PDU.
|
* \return The time to live for this IP PDU.
|
||||||
*/
|
*/
|
||||||
uint8_t ttl() const {
|
uint8_t ttl() const {
|
||||||
return ip_.ttl;
|
return header_.ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -360,7 +371,7 @@ public:
|
|||||||
* \return The protocol for this IP PDU.
|
* \return The protocol for this IP PDU.
|
||||||
*/
|
*/
|
||||||
uint8_t protocol() const {
|
uint8_t protocol() const {
|
||||||
return ip_.protocol;
|
return header_.protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -369,7 +380,7 @@ public:
|
|||||||
* \return The checksum for this IP PDU.
|
* \return The checksum for this IP PDU.
|
||||||
*/
|
*/
|
||||||
uint16_t checksum() const {
|
uint16_t checksum() const {
|
||||||
return Endian::be_to_host(ip_.check);
|
return Endian::be_to_host(header_.check);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -378,7 +389,7 @@ public:
|
|||||||
* \return The source address for this IP PDU.
|
* \return The source address for this IP PDU.
|
||||||
*/
|
*/
|
||||||
address_type src_addr() const {
|
address_type src_addr() const {
|
||||||
return address_type(ip_.saddr);
|
return address_type(header_.saddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,7 +397,7 @@ public:
|
|||||||
* \return The destination address for this IP PDU.
|
* \return The destination address for this IP PDU.
|
||||||
*/
|
*/
|
||||||
address_type dst_addr() const {
|
address_type dst_addr() const {
|
||||||
return address_type(ip_.daddr);
|
return address_type(header_.daddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,7 +405,7 @@ public:
|
|||||||
* \return The version for this IP PDU.
|
* \return The version for this IP PDU.
|
||||||
*/
|
*/
|
||||||
small_uint<4> version() const {
|
small_uint<4> version() const {
|
||||||
return ip_.version;
|
return header_.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -402,7 +413,7 @@ public:
|
|||||||
* \return The stored options.
|
* \return The stored options.
|
||||||
*/
|
*/
|
||||||
const options_type& options() const {
|
const options_type& options() const {
|
||||||
return ip_options_;
|
return options_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setters */
|
/* Setters */
|
||||||
@@ -516,8 +527,7 @@ public:
|
|||||||
* \param opt The option to be added.
|
* \param opt The option to be added.
|
||||||
*/
|
*/
|
||||||
void add_option(option &&opt) {
|
void add_option(option &&opt) {
|
||||||
internal_add_option(opt);
|
options_.push_back(std::move(opt));
|
||||||
ip_options_.push_back(std::move(opt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -530,8 +540,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void add_option(Args&&... args) {
|
void add_option(Args&&... args) {
|
||||||
ip_options_.emplace_back(std::forward<Args>(args)...);
|
options_.emplace_back(std::forward<Args>(args)...);
|
||||||
internal_add_option(ip_options_.back());
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -675,7 +684,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \brief Returns the header size.
|
* \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. \sa PDU::header_size
|
* This method overrides PDU::header_size. \sa PDU::header_size
|
||||||
*/
|
*/
|
||||||
uint32_t header_size() const;
|
uint32_t header_size() const;
|
||||||
|
|
||||||
@@ -748,21 +757,20 @@ private:
|
|||||||
void head_len(small_uint<4> new_head_len);
|
void head_len(small_uint<4> new_head_len);
|
||||||
void tot_len(uint16_t new_tot_len);
|
void tot_len(uint16_t new_tot_len);
|
||||||
|
|
||||||
void prepare_for_serialize(const PDU* parent);
|
void prepare_for_serialize();
|
||||||
void internal_add_option(const option& option);
|
uint32_t calculate_options_size() const;
|
||||||
|
uint32_t pad_options_size(uint32_t size) const;
|
||||||
void init_ip_fields();
|
void init_ip_fields();
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||||
void add_route_option(option_identifier id, const generic_route_option_type& data);
|
void add_route_option(option_identifier id, const generic_route_option_type& data);
|
||||||
generic_route_option_type search_route_option(option_identifier id) const;
|
generic_route_option_type search_route_option(option_identifier id) const;
|
||||||
void checksum(uint16_t new_check);
|
void checksum(uint16_t new_check);
|
||||||
options_type::const_iterator search_option_iterator(option_identifier id) const;
|
options_type::const_iterator search_option_iterator(option_identifier id) const;
|
||||||
options_type::iterator search_option_iterator(option_identifier id);
|
options_type::iterator search_option_iterator(option_identifier id);
|
||||||
void update_padded_options_size();
|
|
||||||
|
|
||||||
ip_header ip_;
|
options_type options_;
|
||||||
uint16_t options_size_, padded_options_size_;
|
ip_header header_;
|
||||||
options_type ip_options_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Tins
|
} // Tins
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -31,10 +31,11 @@
|
|||||||
#define TINS_IPADDRESS_H
|
#define TINS_IPADDRESS_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iosfwd>
|
||||||
#include <stdint.h>
|
#include <functional>
|
||||||
#include "cxxstd.h"
|
#include <cstdint>
|
||||||
#include "macros.h"
|
#include <tins/cxxstd.h>
|
||||||
|
#include <tins/macros.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +54,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
static const IPv4Address broadcast;
|
static const IPv4Address broadcast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Constructs an IPv4 address from a prefix length
|
||||||
|
*
|
||||||
|
* \param prefix_length The length of the prefix
|
||||||
|
*/
|
||||||
|
static IPv4Address from_prefix_length(uint32_t prefix_length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructor taking a const char*.
|
* \brief Constructor taking a const char*.
|
||||||
*
|
*
|
||||||
@@ -123,10 +131,63 @@ public:
|
|||||||
* \param rhs The address to be compared.
|
* \param rhs The address to be compared.
|
||||||
* \return bool indicating whether this address is less-than rhs.
|
* \return bool indicating whether this address is less-than rhs.
|
||||||
*/
|
*/
|
||||||
bool operator< (const IPv4Address& rhs) const {
|
bool operator<(const IPv4Address& rhs) const {
|
||||||
return ip_addr_ < rhs.ip_addr_;
|
return ip_addr_ < rhs.ip_addr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compares this address for less-than equality.
|
||||||
|
*
|
||||||
|
* \param rhs The address to be compared to.
|
||||||
|
*
|
||||||
|
* \return bool indicating whether this address is equal or less-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator<=(const IPv4Address& rhs) const {
|
||||||
|
return !operator>(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compare this IPv4Address for greater-than inequality.
|
||||||
|
*
|
||||||
|
* \param rhs The address to be compared.
|
||||||
|
* \return bool indicating whether this address is greater-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator>(const IPv4Address& rhs) const {
|
||||||
|
return ip_addr_ > rhs.ip_addr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Compares this address for greater-than equality.
|
||||||
|
*
|
||||||
|
* \param rhs The address to be compared to.
|
||||||
|
*
|
||||||
|
* \return bool indicating whether this address is equal or greater-than rhs.
|
||||||
|
*/
|
||||||
|
bool operator>=(const IPv4Address& rhs) const {
|
||||||
|
return !operator<(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Apply a mask to this address
|
||||||
|
*
|
||||||
|
* \param mask The mask to be applied
|
||||||
|
* \return The result of applying the mask to this address
|
||||||
|
*/
|
||||||
|
IPv4Address operator&(const IPv4Address& mask) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Apply a mask to this address
|
||||||
|
*
|
||||||
|
* \param mask The mask to be applied
|
||||||
|
* \return The result of applying the mask to this address
|
||||||
|
*/
|
||||||
|
IPv4Address operator|(const IPv4Address& mask) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* not operator (invert)
|
||||||
|
*/
|
||||||
|
IPv4Address operator~() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Returns true if this is a private IPv4 address.
|
* \brief Returns true if this is a private IPv4 address.
|
||||||
*
|
*
|
||||||
@@ -166,6 +227,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool is_broadcast() const;
|
bool is_broadcast() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns the size of an IPv4 Address.
|
||||||
|
*
|
||||||
|
* This returns the value of IPv4Address::address_size
|
||||||
|
*/
|
||||||
|
size_t size() const {
|
||||||
|
return address_size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Writes this address to a std::ostream.
|
* \brief Writes this address to a std::ostream.
|
||||||
*
|
*
|
||||||
@@ -176,7 +246,7 @@ public:
|
|||||||
* \param addr The IPv4Address to be written.
|
* \param addr The IPv4Address to be written.
|
||||||
* \return std::stream& pointing to output.
|
* \return std::stream& pointing to output.
|
||||||
*/
|
*/
|
||||||
friend std::ostream& operator<<(std::ostream& output, const IPv4Address& addr);
|
TINS_API friend std::ostream& operator<<(std::ostream& output, const IPv4Address& addr);
|
||||||
private:
|
private:
|
||||||
uint32_t ip_to_int(const char* ip);
|
uint32_t ip_to_int(const char* ip);
|
||||||
|
|
||||||
@@ -190,8 +260,9 @@ namespace std {
|
|||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct hash<Tins::IPv4Address> {
|
struct hash<Tins::IPv4Address> {
|
||||||
size_t operator()(const Tins::IPv4Address& addr) const {
|
size_t operator()(const Tins::IPv4Address& addr) const
|
||||||
return std::hash<uint32_t>()(addr);
|
{
|
||||||
|
return std::hash<std::uint32_t>()(addr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Matias Fontanini
|
* Copyright (c) 2017, Matias Fontanini
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -32,16 +32,16 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "pdu.h"
|
#include <tins/pdu.h>
|
||||||
#include "macros.h"
|
#include <tins/macros.h>
|
||||||
#include "ip_address.h"
|
#include <tins/ip_address.h>
|
||||||
|
#include <tins/ip.h>
|
||||||
|
|
||||||
namespace Tins {
|
namespace Tins {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \cond
|
* \cond
|
||||||
*/
|
*/
|
||||||
class IP;
|
|
||||||
namespace Internals {
|
namespace Internals {
|
||||||
class IPv4Fragment {
|
class IPv4Fragment {
|
||||||
public:
|
public:
|
||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
void add_fragment(IP* ip);
|
void add_fragment(IP* ip);
|
||||||
bool is_complete() const;
|
bool is_complete() const;
|
||||||
PDU* allocate_pdu() const;
|
PDU* allocate_pdu() const;
|
||||||
|
const IP& first_fragment() const;
|
||||||
private:
|
private:
|
||||||
typedef std::vector<IPv4Fragment> fragments_type;
|
typedef std::vector<IPv4Fragment> fragments_type;
|
||||||
|
|
||||||
@@ -81,9 +82,10 @@ private:
|
|||||||
bool extract_more_frag(const IP* ip);
|
bool extract_more_frag(const IP* ip);
|
||||||
|
|
||||||
fragments_type fragments_;
|
fragments_type fragments_;
|
||||||
|
size_t received_size_;
|
||||||
|
size_t total_size_;
|
||||||
|
IP first_fragment_;
|
||||||
bool received_end_;
|
bool received_end_;
|
||||||
uint8_t transport_proto_;
|
|
||||||
size_t received_size_, total_size_;
|
|
||||||
};
|
};
|
||||||
} // namespace Internals
|
} // namespace Internals
|
||||||
|
|
||||||
@@ -93,32 +95,61 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Reassembles fragmented IP packets.
|
* \brief Reassembles fragmented IP packets.
|
||||||
|
*
|
||||||
|
* This class is fairly simple: just feed packets into it using IPv4Reassembler::process.
|
||||||
|
* If the return value is IPv4Reassembler::FRAGMENTED, then the packet is fragmented
|
||||||
|
* and we haven't yet seen the missing fragments, hence we can't reassemble it.
|
||||||
|
* If the function returns either IPv4Reassembler::NOT_FRAGMENTED (meaning the
|
||||||
|
* packet wasn't fragmented) or IPv4Reassembler::REASSEMBLED (meaning the packet was
|
||||||
|
* fragmented but it's now reassembled), then you can process the packet normally.
|
||||||
|
*
|
||||||
|
* Simple example:
|
||||||
|
*
|
||||||
|
* \code
|
||||||
|
* IPv4Reassembler reassembler;
|
||||||
|
* Sniffer sniffer = ...;
|
||||||
|
* sniffer.sniff_loop([&](PDU& pdu) {
|
||||||
|
* // Process it in any case, unless it's fragmented (and can't be reassembled yet)
|
||||||
|
* if (reassembler.process(pdu) != IPv4Reassembler::FRAGMENTED) {
|
||||||
|
* // Now actually process the packet
|
||||||
|
* process_packet(pdu);
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
* \endcode
|
||||||
*/
|
*/
|
||||||
class TINS_API IPv4Reassembler {
|
class TINS_API IPv4Reassembler {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The status of each processed packet.
|
* The status of each processed packet.
|
||||||
*/
|
*/
|
||||||
enum packet_status {
|
enum PacketStatus {
|
||||||
NOT_FRAGMENTED,
|
NOT_FRAGMENTED, ///< The given packet is not fragmented
|
||||||
FRAGMENTED,
|
FRAGMENTED, ///< The given packet is fragmented and can't be reassembled yet
|
||||||
REASSEMBLED
|
REASSEMBLED ///< The given packet was fragmented but is now reassembled
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TINS_DEPRECATED(typedef PacketStatus packet_status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type used to represent the overlapped segment
|
* The type used to represent the overlapped segment reassembly
|
||||||
* reassembly technique to be used.
|
* technique to be used.
|
||||||
*/
|
*/
|
||||||
enum overlapping_technique {
|
enum OverlappingTechnique {
|
||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor
|
||||||
|
*/
|
||||||
|
IPv4Reassembler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an IPV4Reassembler.
|
* Constructs an IPV4Reassembler.
|
||||||
|
*
|
||||||
* \param technique The technique to be used for reassembling
|
* \param technique The technique to be used for reassembling
|
||||||
* overlapped fragments.
|
* overlapped fragments.
|
||||||
*/
|
*/
|
||||||
IPv4Reassembler(overlapping_technique technique = NONE);
|
IPv4Reassembler(OverlappingTechnique technique);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Processes a PDU and tries to reassemble it.
|
* \brief Processes a PDU and tries to reassemble it.
|
||||||
@@ -134,7 +165,7 @@ public:
|
|||||||
* fragmented or REASSEMBLED if the packet was fragmented
|
* fragmented or REASSEMBLED if the packet was fragmented
|
||||||
* but has now been reassembled.
|
* but has now been reassembled.
|
||||||
*/
|
*/
|
||||||
packet_status process(PDU& pdu);
|
PacketStatus process(PDU& pdu);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all of the packets and data stored.
|
* Removes all of the packets and data stored.
|
||||||
@@ -161,7 +192,7 @@ private:
|
|||||||
address_pair make_address_pair(IPv4Address addr1, IPv4Address addr2) const;
|
address_pair make_address_pair(IPv4Address addr1, IPv4Address addr2) const;
|
||||||
|
|
||||||
streams_type streams_;
|
streams_type streams_;
|
||||||
overlapping_technique technique_;
|
OverlappingTechnique technique_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,10 +221,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool operator()(PDU& pdu) {
|
bool operator()(PDU& pdu) {
|
||||||
// Forward it unless it's fragmented.
|
// Forward it unless it's fragmented.
|
||||||
if(reassembler_.process(pdu) != IPv4Reassembler::FRAGMENTED)
|
if (reassembler_.process(pdu) != IPv4Reassembler::FRAGMENTED) {
|
||||||
return functor_(pdu);
|
return functor_(pdu);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
IPv4Reassembler reassembler_;
|
IPv4Reassembler reassembler_;
|
||||||
@@ -210,7 +243,7 @@ template<typename Functor>
|
|||||||
IPv4ReassemblerProxy<Functor> make_ipv4_reassembler_proxy(Functor func) {
|
IPv4ReassemblerProxy<Functor> make_ipv4_reassembler_proxy(Functor func) {
|
||||||
return IPv4ReassemblerProxy<Functor>(func);
|
return IPv4ReassemblerProxy<Functor>(func);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
} // Tins
|
||||||
|
|
||||||
#endif // TINS_IP_REASSEMBLER_H
|
#endif // TINS_IP_REASSEMBLER_H
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user