1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 10:45:57 +01:00

147 Commits
v3.3 ... v3.5

Author SHA1 Message Date
Matias Fontanini
37c92fcf5c Bump minor version 2017-04-01 09:21:33 -07:00
Matias Fontanini
18281e614d Add release notes for v3.5 2017-04-01 09:12:28 -07:00
Matias Fontanini
7f8644cb39 Merge branch 'develop' 2017-03-23 19:31:10 -07:00
Matias Fontanini
799ba2b4b6 Allow disabling pcap packet capture 2017-03-21 19:04:33 -07:00
Matias Fontanini
ad0a1ca97d Use QoS TID when building AAD for CCMP decryption
Fixes #190
2017-03-11 10:43:12 -08:00
Matias Fontanini
7607610cf9 Merge branch 'develop' 2017-01-31 21:37:41 -08:00
Kyle Fazzari
a71a3d29ff Fix -Wextra compiler warnings. (#184)
* Fix -Wextra compiler warnings.

Fix #183.

Signed-off-by: Kyle Fazzari <github@status.e4ward.com>

* Comment out unused parameters.

This is done everywhere possible instead of using Internals::unused().
Note that this involved moving some implementations into the
corresponding .cpp file.

Signed-off-by: Kyle Fazzari <github@status.e4ward.com>

* Fix warnings in tests as well.

Signed-off-by: Kyle Fazzari <github@status.e4ward.com>

* Leave IPv4Reassembler alone, it's growing.

Signed-off-by: Kyle Fazzari <github@status.e4ward.com>
2017-01-25 13:26:11 -08:00
Ed Catmur
9051197603 Use actual payload length to construct inner PDU. (#179)
Fixes #178
2017-01-16 09:36:33 -08:00
Matias Fontanini
94e5ac2109 Check expected size properly on DNS::extract_metadata
Thanks @shshzi for finding this one
2017-01-15 09:04:19 -08:00
Matias Fontanini
84cb686928 Use markdown for CHANGES file 2016-12-11 10:11:05 -08:00
Matias Fontanini
da07ad3b13 Remove AUTHORS file
This file is very outdated. Check contributions on github to
see the actual contributors.
2016-12-11 10:02:48 -08:00
Matias Fontanini
d5cba00ce0 Use immediate mode on DNS spoof example 2016-11-04 08:00:13 -07:00
Matias Fontanini
ba9d0b34c6 Fix build issue on FreeBSD 11
This fixes #174 temporarily, so at least it won't fail to build
2016-11-04 07:55:58 -07:00
Matias Fontanini
f2850cc0b9 Execute original ooo callback first on recovery mode 2016-11-01 07:35:56 -07:00
Matias Fontanini
c69ea0c1fb Keep original out of order callback on recovery mode 2016-10-30 13:08:17 -07:00
Matias Fontanini
a63387f85e Add Stream recovery mode 2016-10-30 11:38:50 -07:00
Matias Fontanini
df7e7b391d Add flag to Stream to know whether it was attached 2016-10-30 10:31:16 -07:00
Matias Fontanini
5d6431d2d9 Allow enabling attachment to partial streams 2016-10-30 10:21:58 -07:00
Matias Fontanini
a61a361eb1 Add check for noexcept when checking C++11 features 2016-10-23 11:34:10 -07:00
Matias Fontanini
9dbad2a26f Cleanup tests names and CMake script 2016-10-23 10:21:58 -07:00
Patrick Michel
aaba3dd46a Feature - Skipping ahead in TCP flows. (#163)
* Skipping forward in TCP streams, from an out-of-order callback.

- Added the ability to skip forward in a flow to a sequence number, with the intention of doing so in an out of order callback.
- Re-ordered Flow packet processing, to allow skipTo in out of order callback on stream start (flow sequence number is 0).
- Fixed missing seq_compare in flow code.

* Renamed skipTo to advance_sequence.
2016-10-23 09:47:56 -07:00
Matias Fontanini
2e013847d9 Use proper IPv6 flag when opening l3 socket
Fixes #166
2016-10-21 07:34:20 -07:00
Matias Fontanini
22e569d430 Fix buffer length check issue on Dot11QosData
Fixes #167
2016-10-18 07:24:11 -07:00
Matias Fontanini
2847039ffe Set last next protocol to 0 if no inner_pdu on IPv6 2016-09-29 07:37:46 -07:00
Matias Fontanini
54ce11629c Set payload type to 0 if no inner_pdu on Dot1Q 2016-09-29 07:37:46 -07:00
Matias Fontanini
8dcfd6aae0 Set protocol to 0 if no inner_pdu on IP 2016-09-29 07:37:46 -07:00
Patrick Michel
838a4a5cb9 Refactored code related to stream/flow initialization. (#170)
- Removed client_flow().process_packet() in Stream constructor, in favor of processing on SYN in stream follower.
- Moved +1 to seq on SYN/ACK.
2016-09-28 07:30:16 -07:00
Matias Fontanini
e82b72e931 Use relative include for config.h 2016-09-27 22:06:09 -07:00
Matias Fontanini
fdc6ccdf5c Only enable TCP stream's custom data if boost.any is found 2016-09-27 21:46:38 -07:00
Patrick Michel
52b389afe8 Allow setting custom user data to each TCP stream 2016-09-27 21:33:10 -07:00
Matias Fontanini
552006c876 Set EthernetII payload type to UNKNOWN if no inner_pdu 2016-09-27 07:47:32 -07:00
Matias Fontanini
f0b32edaa9 Use boost include paths/libs on appveyor build 2016-09-26 20:29:14 -07:00
Matias Fontanini
5a901ca155 Merge branch 'develop' 2016-09-26 19:52:12 -07:00
Jim Hague
9593cf4cf6 Correct typo preventing user buffer management for server TCP streams. (#160) 2016-08-31 09:13:43 -07:00
Huemac
64725e2ed9 Fix Cppcheck 1.75 warnings (#159)
- The scope of the variable 'last_index' & 'index' could be reduced.
- Prefer prefix ++/-- operators for non-primitive types.
2016-08-14 12:29:53 -07:00
Vikas Kumar
9260f9374a Variable Boost_INCLUDE_DIRS incorrectly used in cmake file (#158)
`s/Boost_INCLUDE_DIRS/${Boost_INCLUDE_DIRS}/ inside `INCLUDE_DIRECTORIES`
2016-08-13 13:41:25 -07:00
Sergey Kovalevich
2ccf50db3e Allow including libtins using add_subdirectory via CMake 2016-07-20 09:12:48 -07:00
ps790
e843ee7117 Added cmake compiling support for MinGW (#155)
* Added cmake compiling support for MinGW

These modificaitons allow to build Libtins on Windows with cmake directly by running 
cmake ../ -DPCAP_ROOT_DIR="PATH_TO_WpdPack" -DLIBTINS_ENABLE_WPA2=0 -DLIBTINS_BUILD_SHARED=0 -G "MinGW Makefiles"

* Update CMakeLists.txt
2016-06-24 18:00:09 -07:00
Matias Fontanini
a192e814bf Allow configuring pcap timestamp precision 2016-06-17 09:20:43 -07:00
Matias Fontanini
ccda631708 Fix timestamp integer overflow issue 2016-06-16 17:12:04 -07:00
Jacob Parker
1552e33c67 Add helper function to create StreamIdentifier from const Stream& (#152) 2016-06-07 13:19:55 -07:00
Wouter Overmeire
8afc784956 Fix typo in arp.h comment (#151) 2016-06-06 10:36:36 -07:00
Rolf Winter
5b00916f83 fixed: superfluous includes, docu (#148) 2016-05-26 09:11:48 -07:00
Matias Fontanini
6b7bc76603 Forward NetworkInterface argument when calling PacketSender::send_l2 2016-05-08 20:46:11 -07:00
Matias Fontanini
732c665af5 Fix compilation warning on VC 2016-05-08 10:34:49 -07:00
Matias Fontanini
8cf367d68c Make Timestamp::current_time work on Windows 2016-05-08 10:26:57 -07:00
Matias Fontanini
d070978a54 Add TINS_API to DataTracker and AckTracker classes 2016-05-08 09:38:52 -07:00
Matias Fontanini
7f30efab38 Fix typo in macros.h
[ci skip]
2016-05-05 12:40:11 -07:00
Matias Fontanini
d7fed87ebb Use recvfrom on BSD/OSX when capturing layer 3 packets
Fixes #147
2016-05-03 19:35:24 -07:00
Matias Fontanini
269ac164ed Use exception strings on std::runtime_error's constructor
Fixes #146
2016-05-03 14:50:28 -07:00
Matias Fontanini
55edf31aa6 Move TCP data tracking into a separate class 2016-05-03 14:50:28 -07:00
Patrick Michel
364782b8af Don't set Dot1Q's payload type if next proto type is UNKNOWN 2016-04-12 07:56:31 -07:00
Matias Fontanini
d3c576f6de Properly handle out of order SACKs on AckTracker 2016-04-03 09:39:11 -07:00
Matias Fontanini
8d52d73968 Allow disabling TCPIP classes 2016-04-02 09:35:42 -07:00
Matias Fontanini
48022d3a3f Rename and undef symbols that conflict with macro names on DNS
The undefs are a temporary fix until we get rid of the old,
conflicting, names

Fixes #141
Fixes #58
2016-04-02 09:16:28 -07:00
Matias Fontanini
ec1634d6d8 Move stream_id into a new file and rename it to StreamIdentifier 2016-03-28 21:38:43 -07:00
Matias Fontanini
688bb7094e Rename BSD enum value so it doesn't conflict with macro 2016-03-28 20:31:48 -07:00
Matias Fontanini
928e66eb27 Fix issue considering an interface down when it's up 2016-03-27 08:21:05 -07:00
Matias Fontanini
d80c27de29 Add active test for TCP over ethernet 2016-03-26 16:11:03 -07:00
Matias Fontanini
6aac22fa74 Make Utils::resolve_hwaddress work on Windows 2016-03-22 20:34:06 -07:00
Matias Fontanini
7bc1ab41f7 Add TCP and Utils::resolve_hwaddress active tests
[ci skip]
2016-03-22 19:49:26 -07:00
Matias Fontanini
068e304baa Fix active tests build issues 2016-03-20 19:01:58 -07:00
Matias Fontanini
5dc7b20a43 Add active tests for IPv4 2016-03-20 16:27:43 -07:00
Matias Fontanini
a70ce10bed Add IPv4Address::from_prefix_length 2016-03-19 16:26:00 -07:00
Matias Fontanini
3773443fc8 Allow masking IPv4/6 and HW addresses 2016-03-19 15:44:55 -07:00
Matias Fontanini
1f4be63d08 Properly handle MLDv1 on ICMP 2016-03-17 21:49:06 -07:00
Matias Fontanini
6a69d1ff6c Export proper artifacts for VS 2015 2016-03-17 21:46:56 -07:00
Matias Fontanini
85102b4546 Merge pull request #140 from asjadsyed/develop
don't set key_t to 0 when setting a key, because the two fields are unrelated
2016-03-17 21:07:15 -07:00
Asjad Syed
f188ea4d2a don't set key_t to 0 when setting a key, because the two fields are unrelated 2016-03-17 22:26:16 -04:00
Matias Fontanini
a75dd9e3f9 Add Visual Studio 2015 to appveyor build 2016-03-16 22:51:50 -07:00
Matias Fontanini
dda673cad4 Merge branch 'develop' 2016-03-16 21:01:27 -07:00
Matias Fontanini
8b125d31f2 Add TINS_API to operator<< for IPv4Address 2016-03-16 20:51:37 -07:00
Matias Fontanini
67ee3e8a7d Merge pull request #137 from stubbfel/pullrequest/first_address_from_mask
calc the complete addressrange of a network when call AddressRange::from_mask
2016-03-16 20:51:03 -07:00
stubbfel
d70536f9ab add first_address_from_mask in internals and call them from addressrange::from_mask 2016-03-16 22:28:21 +01:00
Matias Fontanini
bfe9f9f4a5 Update changelog 2016-03-09 20:25:09 -08:00
Matias Fontanini
97e24131c6 Fix issues pointed out by scan.coverity 2016-03-07 20:29:12 -08:00
Matias Fontanini
42b6c40433 Add Utils::route6_entries on OSX/BSD 2016-03-07 19:40:38 -08:00
Matias Fontanini
4dcef0f15d Add Utils::route6_entries 2016-03-06 19:18:33 -08:00
Matias Fontanini
c082dfad67 Minor changes on TCPIP::StreamFollower 2016-03-06 13:40:10 -08:00
Matias Fontanini
331bc57b44 Update version 2016-03-05 16:07:11 -08:00
Matias Fontanini
b7e20f550e Use proper bssid/client hw when calling handshake captured callback 2016-03-05 10:56:03 -08:00
Matias Fontanini
e15ef0d837 Add info members directly into NetworkInterface 2016-03-05 10:33:50 -08:00
Matias Fontanini
08fd9e2d69 Check the secure bit on HandshakeCapturer to detect 2nd packet 2016-03-05 09:37:22 -08:00
Matias Fontanini
3a99213c0b Rename IPv6AddressPrefix to IPv6Prefix 2016-03-02 21:34:21 -08:00
Matias Fontanini
ad71158268 Add IPv6 addresses to NetworkInterface::Info 2016-03-02 21:13:50 -08:00
Matias Fontanini
186d23c920 Set OPENSSL_* variables to empty string if not found 2016-02-28 08:51:44 -08:00
Matias Fontanini
cfbf88bb5f Make *MemoryStream use size_t rather than uint32_t 2016-02-28 08:12:05 -08:00
Matias Fontanini
1681981fe8 Add WPA2Decrypter callback interface 2016-02-28 08:01:04 -08:00
Matias Fontanini
3e84b07a01 Set MACOSX_RPATH to ON 2016-02-27 07:57:07 -08:00
Matias Fontanini
b087c964d4 Don't fail configuration if openssl is missing 2016-02-27 07:50:56 -08:00
Matias Fontanini
bf70a94921 Build layer 5 as RawPDU if IPv6 has fragment header 2016-02-22 20:37:48 -08:00
Matias Fontanini
e5282f8a3c Fix compilation warnings 2016-02-21 18:50:47 -08:00
Matias Fontanini
5920185288 Add defragmenter example 2016-02-21 18:28:59 -08:00
Matias Fontanini
92f0249d2b Cleanup IPv4Reassembler 2016-02-21 18:20:06 -08:00
Matias Fontanini
016cfeecc6 Don't build examples on travis
Clang on OSX uses gcc 4.6's headers and apparently the chrono header
fails to build
2016-02-21 15:12:00 -08:00
Matias Fontanini
8bf0c355f4 Fix examples so they build on gcc 4.6 2016-02-21 14:59:19 -08:00
Matias Fontanini
fa4178de09 Fix flag value for sniffer's immediate mode 2016-02-21 14:42:24 -08:00
Matias Fontanini
04578b109f Build examples on travis 2016-02-21 09:44:00 -08:00
Matias Fontanini
9dabb6f570 Fix IP fragment reassemble when packet has flags DF+MF 2016-02-21 09:23:44 -08:00
Matias Fontanini
8812153491 Remove extra include on tins.h 2016-02-21 09:14:14 -08:00
Matias Fontanini
17da10d76e Add extract_metadata to main PDU classes 2016-02-20 22:19:12 -08:00
Matias Fontanini
dae25b3381 Fix examples to make them work on Windows 2016-02-20 11:13:04 -08:00
Matias Fontanini
745071af65 Use Utils::sum_range straight into ICMP checksum value 2016-02-20 11:02:20 -08:00
Matias Fontanini
f3448f1797 Use timercmp/sub and std::chrono to subtract timevals 2016-02-20 10:51:35 -08:00
Matias Fontanini
dad6091706 Build examples against local libtins build 2016-02-20 09:55:48 -08:00
Matias Fontanini
6d6eb9c5d7 Add uninstall target 2016-02-20 09:19:42 -08:00
Matias Fontanini
64b84fa91d Prefix HAVE_ config.h macros with TINS_ 2016-02-20 09:10:48 -08:00
Matias Fontanini
bac8388cec Merge pull request #130 from jopann/develop
Fixed comment spelling
2016-02-19 09:02:14 -08:00
Josh Hunter
e69d0d7ce9 Fixed comment spelling 2016-02-19 10:27:56 -06:00
Matias Fontanini
b326546229 Add checks for std::chrono and std::function 2016-02-18 20:52:18 -08:00
Matias Fontanini
5c22cc7985 Use compiler intrinsics to swap bytes 2016-02-18 20:35:37 -08:00
Matias Fontanini
bd31b3648f Change CheckCXX11Features into CheckCXXFeatures 2016-02-18 20:11:36 -08:00
Matias Fontanini
3c595e6225 Merge pull request #129 from einarjon/master
Add missing TINS_API to PDU classes. Fix ICMPv6 enums
2016-02-18 14:55:33 -08:00
Einar Gunnarsson
ed40dd423d Merge remote-tracking branch 'upstream/master' 2016-02-18 15:34:32 +01:00
Matias Fontanini
0e5d7d7ae0 Use C++11 mode by default 2016-02-17 21:04:28 -08:00
Matias Fontanini
9ef6f7a612 Initialize ACK tracker correctly 2016-02-17 20:10:22 -08:00
Matias Fontanini
da923aa63c Update Doxygen file to enable C++11 support flag 2016-02-17 20:02:07 -08:00
Einar Jón
f88d94cbaa Remove TINS_API from template PDU class 2016-02-17 19:16:15 +01:00
Einar Gunnarsson
6403d1908d add missing TINS_API to PDU classes. Extend/fix ICMPv6 enum values and unify naming 2016-02-17 17:51:54 +01:00
Matias Fontanini
423dbf2404 Return an empty string for dot11 ssid, if ssid is present but empty
References issue mentioned in #128
2016-02-16 21:28:59 -08:00
Matias Fontanini
af6b0fdbb2 Update README.md for TCP ACK tracker disabling 2016-02-15 18:19:38 -08:00
Matias Fontanini
8e7eb25558 Implement new TCP stream follower mechanism 2016-02-15 18:10:33 -08:00
Matias Fontanini
91a724fe2d Add HTTP requests example 2016-02-15 08:29:14 -08:00
Matias Fontanini
eb1c43d293 Throw proper exceptions 2016-02-14 16:51:10 -08:00
Matias Fontanini
4123764a48 Execute out of order callback even for seq < current_seq 2016-02-14 08:56:25 -08:00
Matias Fontanini
abe94ece52 Allow asking whether segment was acked 2016-02-13 22:45:11 -08:00
Matias Fontanini
2498ebf7d6 Fix ACK tracker tests build 2016-02-13 21:26:46 -08:00
Matias Fontanini
f8445c2e5c Fix travis build script 2016-02-13 20:34:39 -08:00
Matias Fontanini
116eb9f1c1 Add initial ACK tracking code 2016-02-13 20:24:15 -08:00
Matias Fontanini
48c068b84a Add callbacks for stream termination events 2016-02-13 11:23:08 -08:00
Matias Fontanini
20a3868e82 Track Stream timestamps and add timeout to StreamFollower 2016-02-11 21:18:48 -08:00
Matias Fontanini
85d7401520 Store MSS value on Flows 2016-02-10 21:24:15 -08:00
Matias Fontanini
3b848060aa Change tcp_ip directory structure 2016-02-10 20:56:13 -08:00
Matias Fontanini
69fc5ff54b Add support for out of order data packet detection 2016-02-10 20:56:13 -08:00
Matias Fontanini
8db6032303 Add hardware addresses to Stream 2016-02-10 20:56:13 -08:00
Matias Fontanini
549c0e97d0 Add Flow::ignore_data_packets 2016-02-10 20:56:13 -08:00
Matias Fontanini
c3861cf54e Fill address arrays with 0x00 2016-02-10 20:56:13 -08:00
Matias Fontanini
7c1453662f Fix compilation issues 2016-02-10 20:56:13 -08:00
Matias Fontanini
5b60b79fd8 Document new TCP stream classes 2016-02-10 20:56:13 -08:00
Matias Fontanini
07b5d74179 Refactor TCP stream code and add http_dump example 2016-02-10 20:56:13 -08:00
Matias Fontanini
76b0c919b9 Add initial code for new TCP reassembly mechanism 2016-02-10 20:56:13 -08:00
Matias Fontanini
785ee7b47b Use ExternalProject_Add rather than including the gtest directory 2016-02-09 20:35:15 -08:00
Matias Fontanini
64b267c7ea Add friendly name to interface info example 2016-02-06 16:04:51 -08:00
Matias Fontanini
0832184896 Add CONTRIBUTING.md file 2016-02-06 16:04:07 -08:00
Matias Fontanini
5d41316b9a Rename IP header member to header_ 2016-02-04 20:37:24 -08:00
Matias Fontanini
602ead5de5 Fix invalid private method name on PacketSender 2016-02-04 20:27:51 -08:00
Matias Fontanini
72e038b9bf Fix invalid endian on IP fragment offset on OSX 2016-02-04 20:20:14 -08:00
250 changed files with 8471 additions and 1125 deletions

View File

@@ -15,6 +15,7 @@ addons:
packages:
- libpcap-dev
- libssl-dev
- libboost-all-dev
before_script:
- mkdir build

View File

@@ -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>

View File

@@ -1,4 +1,126 @@
v3.3 - Sun Jan 31 21:06:04 PST 2016
##### 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
@@ -163,7 +285,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.
@@ -246,7 +368,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.
@@ -256,7 +378,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.
@@ -321,7 +443,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
DNS::Resource.
@@ -377,7 +499,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.
@@ -473,7 +595,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.
@@ -494,7 +616,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.

View File

@@ -4,7 +4,7 @@ PROJECT(libtins)
# Compile in release mode by default
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
ELSE(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.")
ENDIF(NOT CMAKE_BUILD_TYPE)
@@ -18,14 +18,19 @@ IF(MSVC)
ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS=1")
ADD_DEFINITIONS("-DNOGDI=1")
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()
# Build output checks
OPTION(LIBTINS_BUILD_SHARED "Build libtins as a shared library." ON)
IF(LIBTINS_BUILD_SHARED)
MESSAGE(
STATUS
STATUS
"Build will generate a shared library. "
"Use LIBTINS_BUILD_SHARED=0 to perform a static build"
)
@@ -38,14 +43,20 @@ ENDIF(LIBTINS_BUILD_SHARED)
# The version number.
SET(LIBTINS_VERSION_MAJOR 3)
SET(LIBTINS_VERSION_MINOR 3)
SET(LIBTINS_VERSION_MINOR 5)
SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}")
# 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
FIND_PACKAGE(PCAP REQUIRED)
IF(LIBTINS_ENABLE_PCAP)
FIND_PACKAGE(PCAP REQUIRED)
SET(TINS_HAVE_PCAP ON)
ENDIF()
# Set some Windows specific flags
IF(WIN32)
@@ -54,26 +65,54 @@ IF(WIN32)
# Add the NOMINMAX macro to avoid Windows' min and max macros.
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)
INCLUDE(ExternalProject)
# *******************
# 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
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)
SET(HAVE_CXX11 ON)
INCLUDE(CheckCXX11Features)
IF(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
# We only use declval and decltype on gcc/clang as VC fails to build that code,
# at least on VC2013
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")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
ELSE(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
MESSAGE(FATAL_ERROR "C++11 features requested but the compiler does not support them.")
ENDIF(HAS_CXX11_NULLPTR AND HAS_CXX11_RVALUE_REFERENCES)
ELSE()
MESSAGE(WARNING "The compiler doesn't support the necessary C++11 features. "
"Disabling C++11 on this build")
ENDIF()
ELSE(LIBTINS_ENABLE_CXX11)
MESSAGE(
WARNING
WARNING
"Disabling C++11 features. Use LIBTINS_ENABLE_CXX11=1 to enable them. "
"Unless you are using an old compiler, you should enable this option, "
"as it increases the library's performance")
@@ -83,17 +122,75 @@ ENDIF(LIBTINS_ENABLE_CXX11)
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)
IF(LIBTINS_ENABLE_DOT11)
SET(HAVE_DOT11 ON)
SET(TINS_HAVE_DOT11 ON)
MESSAGE(STATUS "Enabling IEEE 802.11 support.")
IF(LIBTINS_ENABLE_WPA2)
FIND_PACKAGE(OpenSSL REQUIRED)
SET(HAVE_WPA2_DECRYPTION ON)
MESSAGE(STATUS "Enabling WPA2 decryption support.")
FIND_PACKAGE(OpenSSL)
IF(OPENSSL_FOUND)
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)
MESSAGE(STATUS "Disabling WPA2 decryption support.")
ENDIF(LIBTINS_ENABLE_WPA2)
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
IF(WIN32)
SET(USE_PCAP_SENDPACKET_DEFAULT ON)
@@ -103,17 +200,17 @@ ENDIF(WIN32)
OPTION(LIBTINS_USE_PCAP_SENDPACKET "Use pcap_sendpacket to send l2 packets"
${USE_PCAP_SENDPACKET_DEFAULT})
IF(LIBTINS_USE_PCAP_SENDPACKET)
SET(HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
IF(LIBTINS_ENABLE_PCAP AND LIBTINS_USE_PCAP_SENDPACKET)
SET(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET ON)
MESSAGE(STATUS "Using pcap_sendpacket to send l2 packets.")
ENDIF(LIBTINS_USE_PCAP_SENDPACKET)
ENDIF()
# Add a target to generate API documentation using Doxygen
FIND_PACKAGE(Doxygen QUIET)
IF(DOXYGEN_FOUND)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
@ONLY
)
ADD_CUSTOM_TARGET(
@@ -149,22 +246,49 @@ INSTALL(
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_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(src)
IF(LIBTINS_ENABLE_PCAP)
ADD_SUBDIRECTORY(examples)
ELSE()
MESSAGE(STATUS "Not building examples as pcap support is disabled")
ENDIF()
# Only include googletest if the git submodule has been fetched
IF(EXISTS "${CMAKE_SOURCE_DIR}/googletest/CMakeLists.txt")
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
# Enable tests and add the test directory
MESSAGE(STATUS "Tests have been enabled")
SET(gtest_force_shared_crt ON CACHE BOOL "Always use /MD")
SET(BUILD_GMOCK OFF)
SET(BUILD_GTEST ON)
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"
INSTALL_COMMAND ""
)
# Make sure we build googletest before anything else
ADD_DEPENDENCIES(tins googletest)
ENABLE_TESTING()
ADD_SUBDIRECTORY(googletest)
ADD_SUBDIRECTORY(tests)
ELSE()
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")

30
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,30 @@
# 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:
* Base your PR branch on the `develop` branch. This is **almost always** pointing to the
same commit as `master`, so you shouldn't have any issues changing the destination branch
to `develop` at the time you try to do the pull request if you based your code on `master`.
* 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.

View File

@@ -36,6 +36,7 @@ cmake ../
make
```
### Static/shared build
Note that by default, only the shared object is compiled. If you would
like to generate a static library file, run:
@@ -46,6 +47,8 @@ cmake ../ -DLIBTINS_BUILD_SHARED=0
The generated static/shared library files will be located in the
_build/lib_ directory.
### C++11 support
libtins is noticeable faster if you enable _C++11_ support. Therefore,
if your compiler supports this standard, then you should enable it.
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
```
### 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
openssl as a dependency for compilation, use the
_LIBTINS_ENABLE_WPA2_ switch:
@@ -62,6 +81,8 @@ _LIBTINS_ENABLE_WPA2_ switch:
cmake ../ -DLIBTINS_ENABLE_WPA2=0
```
### IEEE 802.11 support
If you want to disable IEEE 802.11 support(this will also disable
RadioTap and WPA2 decryption), which will reduce the size of the
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:
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.

View File

@@ -10,6 +10,7 @@
# HAS_CXX11_CONSTEXPR - constexpr keyword
# HAS_CXX11_CSTDINT_H - cstdint header
# HAS_CXX11_DECLTYPE - decltype keyword
# HAS_CXX11_DECLVAL - declval feature
# HAS_CXX11_FUNC - __func__ preprocessor constant
# HAS_CXX11_INITIALIZER_LIST - initializer list
# HAS_CXX11_LAMBDA - lambdas
@@ -68,11 +69,11 @@ endif ()
function(cxx11_check_feature FEATURE_NAME 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}\"")
message(STATUS "Checking C++11 support for ${_LOG_NAME}")
message(STATUS "Checking C++ support for ${_LOG_NAME}")
set(_SRCFILE "${_SRCFILE_BASE}.cpp")
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
@@ -116,27 +117,19 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
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})
message(STATUS "Checking C++11 support for ${_LOG_NAME}: not supported")
message(STATUS "Checking C++ support for ${_LOG_NAME}: not supported")
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})
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("declval" HAS_CXX11_DECLVAL)
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("sizeof_member" HAS_CXX11_SIZEOF_MEMBER)
cxx11_check_feature("static_assert" HAS_CXX11_STATIC_ASSERT)
cxx11_check_feature("variadic_templates" HAS_CXX11_VARIADIC_TEMPLATES)
cxx11_check_feature("functional" HAS_CXX11_FUNCTIONAL)
cxx11_check_feature("chrono" HAS_CXX11_CHRONO)
cxx11_check_feature("noexcept" HAS_CXX11_NOEXCEPT)
cxx11_check_feature("builtin-swap" HAS_GCC_BUILTIN_SWAP)

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,7 @@
int foo() noexcept {
return 0;
}
int main() {
return foo();
}

View File

@@ -75,6 +75,7 @@ include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
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_tstamp_precision HAVE_PCAP_TIMESTAMP_PRECISION)
set(CMAKE_REQUIRED_LIBRARIES)
mark_as_advanced(

View File

@@ -5,6 +5,11 @@ configuration:
platform:
- Win32
- x64
environment:
matrix:
- compiler: vs2013
- compiler: vs2015
BOOST_ROOT: C:\Libraries\boost
clone_depth: 1
install:
- git clone https://github.com/mfontanini/winpcap-installer.git
@@ -18,8 +23,12 @@ install:
before_build:
- mkdir build
- cd build
- if "%platform%"=="x64" ( set GENERATOR="Visual Studio 12 Win64" ) else ( set GENERATOR="Visual Studio 12" )
- cmake .. -G %GENERATOR% -DPCAP_ROOT_DIR=c:\WpdPack -DLIBTINS_BUILD_SHARED=0 -DLIBTINS_ENABLE_WPA2=0 -DLIBTINS_ENABLE_CXX11=1
- if "%compiler%"=="vs2013" (set VS_VERSION=12) else (set VS_VERSION=14)
- 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:
project: C:/projects/libtins/build/libtins.sln
verbosity: minimal
@@ -34,11 +43,11 @@ after_build:
- del include\tins\config.h.in
- del include\tins\dot11\CMakeLists.txt
- cd ..\
- 7z a libtins-%platform%-%Configuration%.zip libtins
- 7z a libtins-%compiler%-%platform%-%Configuration%.zip libtins
test_script:
- cd c:\projects\libtins\build
- ctest -C %Configuration%
- ctest -C %Configuration% -V
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:
message: /Update documentation.*/

View 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)

View File

@@ -1365,7 +1365,8 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED =
PREDEFINED = "TINS_IS_CXX11=1" \
"TINS_HAVE_WPA2_CALLBACKS=1"
# 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.

View File

@@ -1,73 +1,81 @@
FIND_PACKAGE(libtins QUIET)
FIND_PACKAGE(Threads QUIET)
FIND_PACKAGE(Boost COMPONENTS regex)
IF(libtins_FOUND)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
INCLUDE_DIRECTORIES(
${LIBTINS_INCLUDE_DIRS}
${PCAP_INCLUDE_DIR}
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../include
${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(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()
IF(Boost_REGEX_FOUND)
SET(LIBTINS_CXX11_EXAMPLES ${LIBTINS_CXX11_EXAMPLES} http_requests)
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()
ELSE(libtins_FOUND)
MESSAGE(
WARNING
"Disabling examples since libtins is not installed. "
"Run cmake again once it is installed in order to compile them."
)
ENDIF(libtins_FOUND)
ELSE(TINS_HAVE_CXX11)
MESSAGE(WARNING "Disabling some examples since C++11 support is disabled.")
ENDIF(TINS_HAVE_CXX11)
ADD_CUSTOM_TARGET(
examples DEPENDS
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()

118
examples/defragmenter.cpp Normal file
View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2016, 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;
}
}

View File

@@ -56,7 +56,7 @@ bool callback(const PDU& pdu) {
if (query.query_type() == DNS::A) {
// Here's one! Let's add an answer.
dns.add_answer(
DNS::Resource(
DNS::resource(
query.dname(),
"127.0.0.1",
DNS::A,
@@ -93,6 +93,8 @@ int main(int argc, char* argv[]) {
// Sniff on the provided interface in promiscuos mode
SnifferConfiguration config;
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
config.set_filter("udp and dst port 53");
Sniffer sniffer(argv[1], config);

View File

@@ -31,6 +31,9 @@
#define NOMINMAX
#endif // _WIN32
// Fix for gcc 4.6
#define _GLIBCXX_USE_NANOSLEEP
#include <iostream>
#include <mutex>
#include <chrono>
@@ -65,8 +68,8 @@ using namespace Tins;
template<typename Duration>
class statistics {
public:
using duration_type = Duration;
using locker_type = lock_guard<mutex>;
typedef Duration duration_type;
typedef lock_guard<mutex> locker_type;
struct information {
duration_type average, worst;
@@ -108,18 +111,18 @@ private:
class dns_monitor {
public:
// The response times are measured in milliseconds
using duration_type = milliseconds;
typedef milliseconds duration_type;
// The statistics type used.
using statistics_type = statistics<duration_type>;
typedef statistics<duration_type> statistics_type;
void run(BaseSniffer& sniffer);
const statistics_type& stats() const {
return m_stats;
}
private:
using packet_info = tuple<IPv4Address, IPv4Address, uint16_t>;
using clock_type = system_clock;
using time_point_type = clock_type::time_point;
typedef tuple<IPv4Address, IPv4Address, uint16_t> packet_info;
typedef system_clock clock_type;
typedef clock_type::time_point time_point_type;
bool callback(const PDU& pdu);
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);

147
examples/http_requests.cpp Normal file
View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2016, 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;
}
}

View File

@@ -29,11 +29,14 @@
#include <string>
#include <iostream>
#include <sstream>
#include <tins/network_interface.h>
using std::cout;
using std::wcout;
using std::endl;
using std::string;
using std::ostringstream;
using namespace Tins;
@@ -50,12 +53,35 @@ int main() {
NetworkInterface::Info info = iface.info();
// Now print all of this info.
cout << name << ": " << endl;
cout << " HW address: " << info.hw_addr << endl
<< " IP address: " << info.ip_addr << endl
<< " Netmask: " << info.netmask << endl
<< " Broadcast: " << info.bcast_addr << endl
<< " Iface index: " << iface.id() << endl
<< " Status: " << "interface " << status << endl << endl;
cout << name;
#ifdef _WIN32
// If this is running on Windows, also print the friendly name
wcout << " (" << iface.friendly_name() << ")";
#endif // _WIN32
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;
}
}

View File

@@ -40,13 +40,30 @@ using std::vector;
using namespace Tins;
int main() {
vector<Utils::RouteEntry> entries = Utils::route_entries();
for (size_t i = 0; i < entries.size(); ++i) {
vector<Utils::RouteEntry> v4_entries = Utils::route_entries();
cout << "IPv4 route table entries: " << endl
<< "========================= " << endl;
for (size_t i = 0; i < v4_entries.size(); ++i) {
cout << "Entry " << setw(2) << i << ": " << endl
<< "Interface: " << entries[i].interface << endl
<< "Destination: " << entries[i].destination << endl
<< "Gateway: " << entries[i].gateway << endl
<< "Genmask: " << entries[i].mask << endl
<< "Metric: " << entries[i].metric << endl << endl;
<< "Interface: " << v4_entries[i].interface << endl
<< "Destination: " << v4_entries[i].destination << endl
<< "Gateway: " << v4_entries[i].gateway << endl
<< "Genmask: " << v4_entries[i].mask << 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;
}
}
}

162
examples/stream_dump.cpp Normal file
View File

@@ -0,0 +1,162 @@
/*
* Copyright (c) 2016, 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) {
// 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);
// 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;
}
}

View File

@@ -29,6 +29,7 @@
#include <iostream>
#include <string>
#include <functional>
#include <tins/tins.h>
using std::string;

View File

@@ -31,6 +31,9 @@
#define NOMINMAX
#endif // _WIN32
// Fix for gcc 4.6
#define _GLIBCXX_USE_NANOSLEEP
#include <iostream>
#include <chrono>
#include <thread>
@@ -128,7 +131,7 @@ private:
}
sender.send(ip);
// Give him a little time
// Give it a little time
sleep_for(milliseconds(100));
}
running = false;

View File

@@ -5,3 +5,4 @@ INSTALL(
COMPONENT Headers
)
ADD_SUBDIRECTORY(dot11)
ADD_SUBDIRECTORY(tcp_ip)

View File

@@ -5,14 +5,14 @@
* 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
@@ -125,10 +125,10 @@ private:
* \brief Represents a range of addresses.
*
* This class provides a begin()/end() interface which allows
* iterating through every address stored in it.
* iterating through every address stored in it.
*
* Note that when iterating a range that was created using
* operator/(IPv4Address, int) and the analog for IPv6, the
* operator/(IPv4Address, int) and the analog for IPv6, the
* network and broadcast addresses are discarded:
*
* \code
@@ -139,12 +139,12 @@ private:
* }
*
* // That's only valid for iteration, not for AddressRange<>::contains
*
*
* assert(range.contains("192.168.5.0")); // works
* assert(range.contains("192.168.5.255")); // works
* \endcode
*
* Ranges created using AddressRange(address_type, address_type)
* Ranges created using AddressRange(address_type, address_type)
* will allow the iteration over the entire range:
*
* \code
@@ -153,11 +153,11 @@ private:
* // process 192.168.5.0-255, no addresses are discarded
* process(addr);
* }
*
*
* assert(range.contains("192.168.5.0")); // still valid
* assert(range.contains("192.168.5.255")); // still valid
* \endcode
*
*
*/
template<typename Address>
class AddressRange {
@@ -186,10 +186,10 @@ public:
* The range will consist of the addresses [first, last].
*
* If only_hosts is true, then the network and broadcast addresses
* will not be available when iterating the range.
* will not be available when iterating the range.
*
* If last < first, an std::runtime_error exception is thrown.
*
*
* \param first The first address in the range.
* \param last The last address(inclusive) in the range.
* \param only_hosts Indicates whether only host addresses
@@ -211,8 +211,8 @@ public:
*/
static AddressRange from_mask(const address_type& first, const address_type& mask) {
return AddressRange<address_type>(
first,
Internals::last_address_from_mask(first, mask),
first & mask,
Internals::last_address_from_mask(first, mask),
true
);
}
@@ -253,15 +253,15 @@ public:
/**
* \brief Indicates whether this range is iterable.
*
* Iterable ranges are those for which there is at least one
* Iterable ranges are those for which there is at least one
* address that could represent a host. For IPv4 ranges, a /31 or
* /32 ranges does not contain any, therefore it's not iterable.
* The same is true for /127 and /128 IPv6 ranges.
*
* If is_iterable returns false for a range, then iterating it
* through the iterators returned by begin() and end() is
* undefined.
*
* through the iterators returned by begin() and end() is
* undefined.
*
* \return bool indicating whether this range is iterable.
*/
bool is_iterable() const {

View File

@@ -72,6 +72,14 @@ public:
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.
*
@@ -290,7 +298,7 @@ public:
* \param sender The sender's IP address.
* \param hw_tgt The target'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,
ipaddress_type sender,

View File

@@ -333,7 +333,7 @@ protected:
vend_type& vend() { return vend_; }
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
private:
/**
* Struct that represents the Bootp datagram.
*/
@@ -355,6 +355,7 @@ private:
uint8_t file[128];
} TINS_END_PACK;
private:
bootp_header bootp_;
vend_type vend_;
};

View File

@@ -2,15 +2,33 @@
#define TINS_CONFIG_H
/* Define if the compiler supports basic C++11 syntax */
#cmakedefine HAVE_CXX11
#cmakedefine TINS_HAVE_CXX11
/* Have IEEE 802.11 support */
#cmakedefine HAVE_DOT11
#cmakedefine TINS_HAVE_DOT11
/* Have WPA2 decryption library */
#cmakedefine HAVE_WPA2_DECRYPTION
#cmakedefine TINS_HAVE_WPA2_DECRYPTION
/* 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
#endif // TINS_CONFIG_H

View File

@@ -29,13 +29,16 @@
#include "config.h"
#if !defined(TINS_CRYPTO_H) && defined(HAVE_DOT11)
#if !defined(TINS_CRYPTO_H) && defined(TINS_HAVE_DOT11)
#define TINS_CRYPTO_H
#include <map>
#include <string>
#include <algorithm>
#include <vector>
#ifdef TINS_HAVE_WPA2_CALLBACKS
#include <functional>
#endif // TINS_HAVE_WPA2_CALLBACKS
#include "utils.h"
#include "snap.h"
#include "rawpdu.h"
@@ -52,7 +55,7 @@ namespace Crypto {
struct RC4Key;
#ifdef HAVE_WPA2_DECRYPTION
#ifdef TINS_HAVE_WPA2_DECRYPTION
namespace WPA2 {
/**
@@ -160,12 +163,19 @@ public:
* \return The generated PMK.
*/
const pmk_type& pmk() const;
/**
* \brief Getter for the SSID
* \return The access point's SSID
*/
const std::string& ssid() const;
private:
pmk_type pmk_;
std::string ssid_;
};
} // WPA2
#endif // HAVE_WPA2_DECRYPTION
#endif // TINS_HAVE_WPA2_DECRYPTION
/**
* \brief RC4 Key abstraction.
@@ -240,7 +250,7 @@ private:
std::vector<uint8_t> key_buffer_;
};
#ifdef HAVE_WPA2_DECRYPTION
#ifdef TINS_HAVE_WPA2_DECRYPTION
/**
* \brief Decrypts WPA2-encrypted traffic.
*
@@ -275,6 +285,32 @@ public:
*/
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.
*
@@ -353,6 +389,30 @@ public:
*/
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
*
@@ -381,8 +441,12 @@ private:
pmks_map pmks_;
bssids_map aps_;
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
@@ -459,7 +523,7 @@ void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator
template<typename 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
* WPA2Decrypter as the Decrypter template parameter.
@@ -471,7 +535,7 @@ template<typename Functor>
DecrypterProxy<Functor, WPA2Decrypter> make_wpa2_decrypter_proxy(const Functor& functor) {
return DecrypterProxy<Functor, WPA2Decrypter>(functor);
}
#endif // HAVE_WPA2_DECRYPTION
#endif // TINS_HAVE_WPA2_DECRYPTION
// Implementation section

View File

@@ -40,7 +40,7 @@
#define TINS_CXXSTD_GCC_FIX 0
#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)
#elif !defined(TINS_IS_CXX11)
#define TINS_IS_CXX11 0
@@ -56,6 +56,8 @@ struct smart_ptr {
typedef std::auto_ptr<T> type;
#endif
};
template<class T> void unused(const T&) { }
}
}

View File

@@ -172,6 +172,14 @@ public:
*/
typedef std::list<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.
*

View File

@@ -412,6 +412,14 @@ public:
*/
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.
*/
@@ -854,7 +862,7 @@ public:
/**
* \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;

View File

@@ -40,6 +40,14 @@
#include "pdu.h"
#include "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 Memory {
@@ -130,7 +138,7 @@ public:
ATMA,
NAPTR,
KX,
CERT,
CERTIFICATE,
A6,
DNAM,
SINK,
@@ -144,13 +152,23 @@ public:
DNSKEY,
DHCID,
NSEC3,
NSEC3PARAM
NSEC3PARAM,
CERT = CERTIFICATE
};
enum QueryClass {
IN = 1,
CH = 3,
HS = 4,
INTERNET = 1,
CHAOS = 3,
HESIOD = 4,
/**
* \cond
*/
IN = INTERNET,
CH = CHAOS,
HS = HESIOD,
/**
* \endcond
*/
ANY = 255
};
@@ -589,6 +607,14 @@ public:
typedef IPv4Address address_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.
*

View File

@@ -29,7 +29,7 @@
#include "config.h"
#if !defined(TINS_DOT_11) && defined(HAVE_DOT11)
#if !defined(TINS_DOT_11) && defined(TINS_HAVE_DOT11)
#define TINS_DOT_11
#include "dot11/dot11_base.h"

View File

@@ -29,7 +29,7 @@
#include "../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
#include "../dot11/dot11_mgmt.h"

View File

@@ -29,7 +29,7 @@
#include "../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
#include "../dot11/dot11_mgmt.h"

View File

@@ -29,7 +29,7 @@
#include "../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
#include <list>
@@ -508,8 +508,8 @@ public:
*/
static Dot11* from_bytes(const uint8_t* buffer, uint32_t total_sz);
protected:
virtual void write_ext_header(Memory::OutputMemoryStream& stream) { }
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream) { }
virtual void write_ext_header(Memory::OutputMemoryStream& stream);
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream);
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val);
protected:

View File

@@ -29,7 +29,7 @@
#include "../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
#include "../dot11/dot11_mgmt.h"

View File

@@ -29,7 +29,7 @@
#include "../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

View File

@@ -29,7 +29,7 @@
#include "../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
#include "../dot11/dot11_base.h"

View File

@@ -29,7 +29,7 @@
#include "../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
@@ -463,7 +463,8 @@ public:
uint16_t dwell_time;
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,
uint8_t hop_set,
@@ -482,7 +483,8 @@ public:
uint8_t cfp_count, cfp_period;
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,
uint8_t cfp_period,
@@ -505,7 +507,7 @@ public:
uint8_t recovery_interval;
channel_map_type channel_map;
ibss_dfs_params() {}
ibss_dfs_params() : recovery_interval(0) {}
ibss_dfs_params(const address_type& addr,
uint8_t recovery_interval,
@@ -547,7 +549,8 @@ public:
uint8_t flag, number_of_sets, modulus, offset;
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,
uint8_t sets,
@@ -566,7 +569,8 @@ public:
struct channel_switch_type {
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,
uint8_t channel,
@@ -583,7 +587,8 @@ public:
uint8_t quiet_count, quiet_period;
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,
uint8_t period,
@@ -603,7 +608,8 @@ public:
uint16_t available_capacity;
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)
: station_count(count), available_capacity(capacity),
@@ -619,7 +625,8 @@ public:
uint8_t dtim_count, dtim_period, bitmap_control;
byte_array partial_virtual_bitmap;
tim_type() {}
tim_type()
: dtim_count(0), dtim_period(0), bitmap_control(0) {}
tim_type(uint8_t count,
uint8_t period,

View File

@@ -29,7 +29,7 @@
#include "../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

View File

@@ -48,6 +48,14 @@ public:
*/
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
*/
@@ -73,7 +81,7 @@ public:
/**
* \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;
@@ -192,7 +200,7 @@ private:
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
TINS_BEGIN_PACK
struct dot1q_hdr {
struct dot1q_header {
#if TINS_IS_BIG_ENDIAN
uint16_t priority:3,
cfi:1,
@@ -207,9 +215,9 @@ private:
#endif
} 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_;
};
}

View File

@@ -60,6 +60,14 @@ public:
*/
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
*
@@ -71,7 +79,7 @@ public:
* \param child The PDU which will be set as the inner PDU.
*/
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
@@ -145,12 +153,12 @@ public:
*/
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()
*/
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.

View File

@@ -69,6 +69,14 @@ public:
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
* based on a raw buffer.
@@ -338,7 +346,7 @@ public:
/**
* \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
@@ -603,7 +611,7 @@ public:
/**
* \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

View File

@@ -42,6 +42,7 @@
#define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
#define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN)
#elif defined(_WIN32)
#include <cstdlib>
// Assume windows == little endian. fixme later
#define TINS_IS_LITTLE_ENDIAN 1
#define TINS_IS_BIG_ENDIAN 0
@@ -51,6 +52,19 @@
#define TINS_IS_BIG_ENDIAN (__BYTE_ORDER == __BIG_ENDIAN)
#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 Endian {
@@ -70,7 +84,11 @@ inline uint8_t do_change_endian(uint8_t data) {
* \param data The data to convert.
*/
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.
*/
inline uint32_t do_change_endian(uint32_t data) {
return (((data & 0xff000000) >> 24) | ((data & 0x00ff0000) >> 8) |
((data & 0x0000ff00) << 8) | ((data & 0x000000ff) << 24));
#ifdef TINS_NO_BYTE_SWAP_INTRINSICS
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.
*/
inline uint64_t do_change_endian(uint64_t data) {
return (((uint64_t)(do_change_endian((uint32_t)(data & 0xffffffff))) << 32) |
(do_change_endian(((uint32_t)(data >> 32)))));
#ifdef TINS_NO_BYTE_SWAP_INTRINSICS
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
}
/**

View File

@@ -60,6 +60,14 @@ public:
*/
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.
*

View File

@@ -45,6 +45,9 @@ public:
exception_base(const std::string& 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 {
public:
// try to avoid allocations by doing this.
const char* what() const throw() {
return "Option not found";
}
option_not_found() : exception_base("Option not found") { }
};
/**
@@ -63,9 +63,7 @@ public:
*/
class malformed_packet : public exception_base {
public:
const char* what() const throw() {
return "Malformed packet";
}
malformed_packet() : exception_base("Malformed packet") { }
};
/**
@@ -73,9 +71,7 @@ public:
*/
class serialization_error : public exception_base {
public:
const char* what() const throw() {
return "Serialization error";
}
serialization_error() : exception_base("Serialization error") { }
};
/**
@@ -83,9 +79,7 @@ public:
*/
class pdu_not_found : public exception_base {
public:
const char* what() const throw() {
return "PDU not found";
}
pdu_not_found() : exception_base("PDU not found") { }
};
/**
@@ -94,9 +88,7 @@ public:
*/
class invalid_interface : public exception_base {
public:
const char* what() const throw() {
return "Invalid interface";
}
invalid_interface() : exception_base("Invalid interface") { }
};
/**
@@ -105,9 +97,7 @@ public:
*/
class invalid_address : public exception_base {
public:
const char* what() const throw() {
return "Invalid address";
}
invalid_address() : exception_base("Invalid address") { }
};
/**
@@ -115,9 +105,7 @@ public:
*/
class field_not_present : public exception_base {
public:
const char* what() const throw() {
return "Field not present";
}
field_not_present() : exception_base("Field not present") { }
};
/**
@@ -153,9 +141,7 @@ public:
*/
class invalid_socket_type : public exception_base {
public:
const char* what() const throw() {
return "The provided socket type is invalid";
}
invalid_socket_type() : exception_base("The provided socket type is invalid") { }
};
/**
@@ -164,9 +150,7 @@ public:
*/
class unknown_link_type : public exception_base {
public:
const char* what() const throw() {
return "The sniffed link layer PDU type is unknown";
}
unknown_link_type() : exception_base("The sniffed link layer PDU type is unknown") { }
};
/**
@@ -174,9 +158,7 @@ public:
*/
class malformed_option : public exception_base {
public:
const char* what() const throw() {
return "Malformed option";
}
malformed_option() : exception_base("Malformed option") { }
};
/**
@@ -184,9 +166,7 @@ public:
*/
class bad_tins_cast : public exception_base {
public:
const char* what() const throw() {
return "Bad Tins cast";
}
bad_tins_cast() : exception_base("Bad Tins cast") { }
};
/**
@@ -195,9 +175,16 @@ public:
*/
class protocol_disabled : public exception_base {
public:
const char* what() const throw() {
return "Protocol disabled";
}
protocol_disabled() : exception_base("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 +193,7 @@ public:
*/
class option_payload_too_large : public exception_base {
public:
const char* what() const throw() {
return "Option payload too large";
}
option_payload_too_large() : exception_base("Option payload too large") { }
};
/**
@@ -237,9 +222,7 @@ public:
*/
class pdu_not_serializable : public exception_base {
public:
const char* what() const throw() {
return "PDU not serializable";
}
pdu_not_serializable() : exception_base("PDU not serializable") { }
};
/**
@@ -247,9 +230,7 @@ public:
*/
class pcap_open_failed : public exception_base {
public:
const char* what() const throw() {
return "Failed to create pcap handle";
}
pcap_open_failed() : exception_base("Failed to create pcap handle") { }
};
/**
@@ -258,9 +239,7 @@ public:
*/
class unsupported_function : public exception_base {
public:
const char* what() const throw() {
return "Function is not supported on this OS";
}
unsupported_function() : exception_base("Function is not supported on this OS") { }
};
/**
@@ -268,9 +247,31 @@ public:
*/
class invalid_domain_name : public exception_base {
public:
const char* what() const throw() {
return "Invalid domain name";
}
invalid_domain_name() : exception_base("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 {
@@ -280,9 +281,7 @@ namespace WPA2 {
*/
class invalid_handshake : public exception_base {
public:
const char* what() const throw() {
return "Invalid WPA2 handshake";
}
invalid_handshake() : exception_base("Invalid WPA2 handshake") { }
};
} // WPA2
} // Crypto

View File

@@ -29,7 +29,7 @@
#include "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
#include <vector>

View File

@@ -249,13 +249,27 @@ public:
bool operator<(const HWAddress& rhs) const {
return std::lexicographical_compare(begin(), end(), rhs.begin(), rhs.end());
}
/**
* \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 Retrieves the size of this address.
*
* This effectively returns the address_size constant.
*/
const size_t size() const {
size_t size() const {
return address_size;
}
@@ -299,6 +313,15 @@ public:
storage_type operator[](size_t i) const {
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.

View File

@@ -92,6 +92,14 @@ public:
ADDRESS_MASK_REPLY = 18
};
/**
* \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.
*
@@ -379,7 +387,7 @@ public:
/**
* \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
@@ -389,7 +397,7 @@ public:
/**
* \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
*/
@@ -499,7 +507,9 @@ private:
bool are_extensions_allowed() const;
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_;
};

View File

@@ -80,14 +80,20 @@ public:
NEIGHBOUR_SOLICIT = 135,
NEIGHBOUR_ADVERT = 136,
REDIRECT = 137,
ROUTER_RENUMBER = 137,
ROUTER_RENUMBER = 138,
NI_QUERY = 139,
NI_REPLY = 140,
MLD2_REPORT = 143,
DHAAD_REQUEST = 144,
DHAAD_REPLY = 145,
MOBILE_PREFIX_SOL = 146,
MOBILE_PREFIX_ADV = 147
MOBILE_PREFIX_SOLICIT = 146,
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
};
/**
@@ -245,8 +251,8 @@ public:
uint8_t prefix_len;
small_uint<1> A, L;
uint32_t valid_lifetime,
preferred_lifetime,
reserved2;
preferred_lifetime,
reserved2;
ipaddress_type prefix;
prefix_info_type(uint8_t prefix_len = 0,
@@ -256,7 +262,7 @@ public:
uint32_t preferred_lifetime = 0,
const ipaddress_type& prefix = ipaddress_type())
: 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);
};
@@ -1027,7 +1033,7 @@ public:
/**
* \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
*/
uint32_t header_size() const;
@@ -1035,7 +1041,7 @@ public:
/**
* \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
*/
@@ -1109,6 +1115,17 @@ public:
ICMPv6* clone() const {
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
@@ -1584,6 +1601,7 @@ private:
multicast_listener_query_message_fields mlqm_;
sources_list sources_;
ICMPExtensionsStructure extensions_;
bool use_mldv2_;
};
} // Tins

View File

@@ -40,6 +40,7 @@
#include "constants.h"
#include "pdu.h"
#include "hw_address.h"
#include "macros.h"
/**
* \cond
@@ -108,6 +109,7 @@ private:
void skip_line(std::istream& input);
bool from_hex(const std::string& str, uint32_t& result);
bool from_hex(const std::string& str, std::string& result);
template<bool, typename T = void>
struct enable_if {
@@ -123,15 +125,19 @@ 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);
uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment);
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream,
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream,
uint32_t payload_length, ICMPExtensionsStructure& extensions);
template<typename T>
@@ -177,6 +183,9 @@ bool decrement(HWAddress<n>& addr) {
return decrement_buffer(addr);
}
// Compares sequence numbers as defined by RFC 1982.
int seq_compare(uint32_t seq1, uint32_t seq2);
IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask);
IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask);
template<size_t n>
@@ -224,10 +233,10 @@ template <typename T, typename P, typename=void>
struct accepts_type : std::false_type { };
template <typename T, typename P>
struct accepts_type<T, P,
struct accepts_type<T, P,
typename std::enable_if<
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
>::type
>::type
> : std::true_type { };
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior

View File

@@ -246,6 +246,14 @@ public:
*/
typedef std::list<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.
*
@@ -280,7 +288,7 @@ public:
* \return The number of dwords the header occupies in an uin8_t.
*/
small_uint<4> head_len() const {
return this->ip_.ihl;
return this->header_.ihl;
}
/**
@@ -289,7 +297,7 @@ public:
* \return The this IP PDU's type of service.
*/
uint8_t tos() const {
return ip_.tos;
return header_.tos;
}
/**
@@ -298,7 +306,7 @@ public:
* \return The total length of this IP PDU.
*/
uint16_t tot_len() const {
return Endian::be_to_host(ip_.tot_len);
return Endian::be_to_host(header_.tot_len);
}
/**
@@ -307,7 +315,7 @@ public:
* \return The id for this IP PDU.
*/
uint16_t id() const {
return Endian::be_to_host(ip_.id);
return Endian::be_to_host(header_.id);
}
/**
@@ -321,7 +329,7 @@ public:
* \sa IP::flags
*/
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 +341,7 @@ public:
* \return The fragment offset, measured in units of 8 byte blocks
*/
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 +350,7 @@ public:
* \return The IP flags field
*/
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 +359,7 @@ public:
* \return The time to live for this IP PDU.
*/
uint8_t ttl() const {
return ip_.ttl;
return header_.ttl;
}
/**
@@ -360,7 +368,7 @@ public:
* \return The protocol for this IP PDU.
*/
uint8_t protocol() const {
return ip_.protocol;
return header_.protocol;
}
/**
@@ -369,7 +377,7 @@ public:
* \return The checksum for this IP PDU.
*/
uint16_t checksum() const {
return Endian::be_to_host(ip_.check);
return Endian::be_to_host(header_.check);
}
/**
@@ -378,7 +386,7 @@ public:
* \return The source address for this IP PDU.
*/
address_type src_addr() const {
return address_type(ip_.saddr);
return address_type(header_.saddr);
}
/**
@@ -386,7 +394,7 @@ public:
* \return The destination address for this IP PDU.
*/
address_type dst_addr() const {
return address_type(ip_.daddr);
return address_type(header_.daddr);
}
/**
@@ -394,7 +402,7 @@ public:
* \return The version for this IP PDU.
*/
small_uint<4> version() const {
return ip_.version;
return header_.version;
}
/**
@@ -675,7 +683,7 @@ public:
/**
* \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;
@@ -760,7 +768,7 @@ private:
options_type::iterator search_option_iterator(option_identifier id);
void update_padded_options_size();
ip_header ip_;
ip_header header_;
uint16_t options_size_, padded_options_size_;
options_type ip_options_;
};

View File

@@ -53,6 +53,13 @@ public:
*/
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*.
*
@@ -123,9 +130,17 @@ public:
* \param rhs The address to be compared.
* \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_;
}
/**
* \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 Returns true if this is a private IPv4 address.
@@ -176,7 +191,7 @@ public:
* \param addr The IPv4Address to be written.
* \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:
uint32_t ip_to_int(const char* ip);

View File

@@ -93,32 +93,61 @@ private:
/**
* \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 {
public:
/**
* The status of each processed packet.
*/
enum packet_status {
NOT_FRAGMENTED,
FRAGMENTED,
REASSEMBLED
enum PacketStatus {
NOT_FRAGMENTED, ///< The given packet is not fragmented
FRAGMENTED, ///< The given packet is fragmented and can't be reassembled yet
REASSEMBLED ///< The given packet was fragmented but is now reassembled
};
TINS_DEPRECATED(typedef PacketStatus packet_status);
/**
* The type used to represent the overlapped segment reassembly
* technique to be used.
*/
enum OverlappingTechnique {
NONE
};
/**
* The type used to represent the overlapped segment
* reassembly technique to be used.
* Default constructor
*/
enum overlapping_technique {
NONE
};
IPv4Reassembler();
/**
* Constructs an IPV4Reassembler.
*
* \param technique The technique to be used for reassembling
* overlapped fragments.
*/
IPv4Reassembler(overlapping_technique technique = NONE);
IPv4Reassembler(OverlappingTechnique technique);
/**
* \brief Processes a PDU and tries to reassemble it.
@@ -134,7 +163,7 @@ public:
* fragmented or REASSEMBLED if the packet was fragmented
* but has now been reassembled.
*/
packet_status process(PDU& pdu);
PacketStatus process(PDU& pdu);
/**
* Removes all of the packets and data stored.
@@ -161,7 +190,7 @@ private:
address_pair make_address_pair(IPv4Address addr1, IPv4Address addr2) const;
streams_type streams_;
overlapping_technique technique_;
OverlappingTechnique technique_;
};
/**
@@ -190,10 +219,12 @@ public:
*/
bool operator()(PDU& pdu) {
// Forward it unless it's fragmented.
if(reassembler_.process(pdu) != IPv4Reassembler::FRAGMENTED)
if (reassembler_.process(pdu) != IPv4Reassembler::FRAGMENTED) {
return functor_(pdu);
else
}
else {
return true;
}
}
private:
IPv4Reassembler reassembler_;
@@ -210,7 +241,7 @@ template<typename Functor>
IPv4ReassemblerProxy<Functor> make_ipv4_reassembler_proxy(Functor func) {
return IPv4ReassemblerProxy<Functor>(func);
}
}
} // Tins
#endif // TINS_IP_REASSEMBLER_H

View File

@@ -146,7 +146,7 @@ public:
/**
* \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;
@@ -237,7 +237,7 @@ public:
/**
* \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;

View File

@@ -89,6 +89,23 @@ public:
NO_NEXT_HEADER = 59
};
/**
* The values used to identify Hop-By-Hop Options and Destination Options.
*/
enum OptionType {
PAD_1 = 0,
PAD_N = 1,
JUMBO_PAYLOAD = 0xC2,
};
/**
* \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 IPv6 object.
*
@@ -251,7 +268,7 @@ public:
/**
* \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;

View File

@@ -55,6 +55,13 @@ public:
*/
typedef const uint8_t* const_iterator;
/**
* \brief Constructs an IPv6 address from a prefix length
*
* \param prefix_length The length of the prefix
*/
static IPv6Address from_prefix_length(uint32_t prefix_length);
/**
* \brief Default constructor.
* Initializes this IPv6 address to "::"
@@ -199,6 +206,13 @@ public:
friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr) {
return os << addr.to_string();
}
/**
* Applies a mask to an address
*/
TINS_API friend IPv6Address operator&(const IPv6Address& lhs, const IPv6Address& rhs);
private:
void init(const char* addr);

View File

@@ -35,7 +35,6 @@
#include <stdint.h>
#include "macros.h"
#include "pdu.h"
#include "macros.h"
#include "endianness.h"
namespace Tins {

View File

@@ -47,7 +47,7 @@
#define TINS_LIKELY(x) (x)
#define TINS_UNLIKELY(x) (x)
#else
// Not Vistual Studio. Assume this is gcc compatible
// Not Visual Studio. Assume this is gcc compatible
#define TINS_BEGIN_PACK
#define TINS_END_PACK __attribute__((packed))
#define TINS_PACKED(DECLARATION) DECLARATION __attribute__((packed))

View File

@@ -47,7 +47,7 @@ namespace Tins {
*/
namespace Memory {
inline void read_data(const uint8_t* buffer, uint8_t* output_buffer, uint32_t size) {
inline void read_data(const uint8_t* buffer, uint8_t* output_buffer, size_t size) {
std::memcpy(output_buffer, buffer, size);
}
@@ -56,7 +56,7 @@ void read_value(const uint8_t* buffer, T& value) {
std::memcpy(&value, buffer, sizeof(value));
}
inline void write_data(uint8_t* buffer, const uint8_t* ptr, uint32_t size) {
inline void write_data(uint8_t* buffer, const uint8_t* ptr, size_t size) {
std::memcpy(buffer, ptr, size);
}
@@ -67,7 +67,7 @@ void write_value(uint8_t* buffer, const T& value) {
class InputMemoryStream {
public:
InputMemoryStream(const uint8_t* buffer, uint32_t total_sz)
InputMemoryStream(const uint8_t* buffer, size_t total_sz)
: buffer_(buffer), size_(total_sz) {
}
@@ -75,7 +75,7 @@ public:
: buffer_(&data[0]), size_(data.size()) {
}
void skip(uint32_t size) {
void skip(size_t size) {
if (TINS_UNLIKELY(size > size_)) {
throw malformed_packet();
}
@@ -83,7 +83,7 @@ public:
size_ -= size;
}
bool can_read(uint32_t byte_count) const {
bool can_read(size_t byte_count) const {
return TINS_LIKELY(size_ >= byte_count);
}
@@ -142,7 +142,7 @@ public:
skip(HWAddress<n>::address_size);
}
void read(void* output_buffer, uint32_t output_buffer_size) {
void read(void* output_buffer, size_t output_buffer_size) {
if (!can_read(output_buffer_size)) {
throw malformed_packet();
}
@@ -154,11 +154,11 @@ public:
return buffer_;
}
uint32_t size() const {
size_t size() const {
return size_;
}
void size(uint32_t new_size) {
void size(size_t new_size) {
size_ = new_size;
}
@@ -167,12 +167,12 @@ public:
}
private:
const uint8_t* buffer_;
uint32_t size_;
size_t size_;
};
class OutputMemoryStream {
public:
OutputMemoryStream(uint8_t* buffer, uint32_t total_sz)
OutputMemoryStream(uint8_t* buffer, size_t total_sz)
: buffer_(buffer), size_(total_sz) {
}
@@ -180,7 +180,7 @@ public:
: buffer_(&buffer[0]), size_(buffer.size()) {
}
void skip(uint32_t size) {
void skip(size_t size) {
if (TINS_UNLIKELY(size > size_)) {
throw malformed_packet();
}
@@ -209,7 +209,7 @@ public:
template <typename ForwardIterator>
void write(ForwardIterator start, ForwardIterator end) {
const uint32_t length = std::distance(start, end);
const size_t length = std::distance(start, end);
if (TINS_UNLIKELY(size_ < length)) {
throw serialization_error();
}
@@ -217,7 +217,7 @@ public:
skip(length);
}
void write(const uint8_t* ptr, uint32_t length) {
void write(const uint8_t* ptr, size_t length) {
write(ptr, ptr + length);
}
@@ -234,7 +234,7 @@ public:
write(address.begin(), address.end());
}
void fill(uint32_t size, uint8_t value) {
void fill(size_t size, uint8_t value) {
if (TINS_UNLIKELY(size_ < size)) {
throw serialization_error();
}
@@ -246,12 +246,12 @@ public:
return buffer_;
}
uint32_t size() const {
size_t size() const {
return size_;
}
private:
uint8_t* buffer_;
uint32_t size_;
size_t size_;
};
/**

View File

@@ -40,9 +40,10 @@ namespace Tins {
class ICMPExtension;
/**
* \class MPLS
* \brief Represents an MPLS PDU
*/
class MPLS : public PDU {
class TINS_API MPLS : public PDU {
public:
/**
* \brief This PDU's flag.

View File

@@ -36,6 +36,7 @@
#include "macros.h"
#include "hw_address.h"
#include "ip_address.h"
#include "ipv6_address.h"
namespace Tins {
@@ -55,11 +56,20 @@ public:
*/
typedef HWAddress<6> address_type;
/**
*
*/
struct IPv6Prefix {
IPv6Address address;
uint32_t prefix_length;
};
/**
* \brief Struct that holds an interface's addresses.
*/
struct Info {
IPv4Address ip_addr, netmask, bcast_addr;
std::vector<IPv6Prefix> ipv6_addrs;
address_type hw_addr;
bool is_up;
};
@@ -191,6 +201,31 @@ public:
*/
bool is_up() const;
/**
* \brief Retrieves the hardware address for this interface.
*/
address_type hw_address() const;
/**
* \brief Retrieves the IPv4 address for this interface.
*/
IPv4Address ipv4_address() const;
/**
* \brief Retrieves the IPv4 netmask for this interface.
*/
IPv4Address ipv4_mask() const;
/**
* \brief Retrieves the broadcast IPv4 address for this interface.
*/
IPv4Address ipv4_broadcast() const;
/**
* \brief Retrieves the IPv6 addresses for this interface.
*/
std::vector<IPv6Prefix> ipv6_addresses() const;
/**
* \brief Compares this interface for equality.
*

View File

@@ -32,9 +32,12 @@
#include <string>
#include <stdint.h>
#include "data_link_type.h"
#include "macros.h"
#ifdef TINS_HAVE_PCAP
#include "data_link_type.h"
namespace Tins {
class PDU;
@@ -154,6 +157,9 @@ private:
mutable bpf_program filter_;
std::string string_filter_;
};
} // Tins
#endif // TINS_HAVE_PCAP
#endif // TINS_OFFLINE_PACKET_FILTER_H

View File

@@ -148,11 +148,19 @@ public:
/**
* \brief Constructs a Packet from a PDU* and a Timestamp.
*
* The PDU* is cloned using PDU::clone.
* The PDU is cloned using PDU::clone.
*/
Packet(const PDU* apdu, const Timestamp& tstamp)
: pdu_(apdu->clone()), ts_(tstamp) { }
/**
* \brief Constructs a Packet from a PDU& and a Timestamp.
*
* The PDU is cloned using PDU::clone.
*/
Packet(const PDU& apdu, const Timestamp& tstamp)
: pdu_(apdu.clone()), ts_(tstamp) { }
/**
* \brief Constructs a Packet from a PDU* and a Timestamp.
*

View File

@@ -37,9 +37,9 @@
#include <stdint.h>
#include <map>
#include "config.h"
#ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
#include <pcap.h>
#endif // HAVE_PACKET_SENDER_PCAP_SENDPACKET
#endif // TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
#include "network_interface.h"
#include "macros.h"
#include "cxxstd.h"
@@ -184,14 +184,14 @@ public:
*/
~PacketSender();
#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET)
#if !defined(_WIN32) || defined(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET)
/**
* \brief Opens a layer 2 socket.
*
* If this operation fails, then a socket_open_error will be thrown.
*/
void open_l2_socket(const NetworkInterface& iface = NetworkInterface());
#endif // !_WIN32 || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET)
#endif // !_WIN32 || defined(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET)
/**
* \brief Opens a layer 3 socket, using the corresponding protocol
@@ -324,7 +324,7 @@ public:
#endif // _WIN32
#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET)
#if !defined(_WIN32) || defined(TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET)
/**
* \brief Sends a level 2 PDU.
*
@@ -342,7 +342,7 @@ public:
*/
void send_l2(PDU& pdu, struct sockaddr* link_addr, uint32_t len_addr,
const NetworkInterface& iface = NetworkInterface());
#endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET
#endif // !_WIN32 || TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
/**
* \brief Receives a layer 3 PDU response to a previously sent PDU.
@@ -384,23 +384,23 @@ private:
PacketSender(const PacketSender&);
PacketSender& operator=(const PacketSender&);
int find_type(SocketType type);
int timeval_subtract (struct timeval* result, struct timeval* x, struct timeval* y);
#ifndef _WIN32
bool ether_socket_initialized(const NetworkInterface& iface = NetworkInterface()) const;
int getether_socket_(const NetworkInterface& iface = NetworkInterface());
int get_ether_socket(const NetworkInterface& iface = NetworkInterface());
#endif
template<typename T>
void send(PDU& pdu, const NetworkInterface& iface) {
static_cast<T&>(pdu).send(*this, iface);
}
#ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
pcap_t* make_pcap_handle(const NetworkInterface& iface) const;
#endif // HAVE_PACKET_SENDER_PCAP_SENDPACKET
#endif // TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
PDU* recv_match_loop(const std::vector<int>& sockets,
PDU& pdu,
struct sockaddr* link_addr,
uint32_t addrlen);
uint32_t addrlen,
bool is_layer_3);
std::vector<int> sockets_;
#ifndef _WIN32
@@ -418,10 +418,10 @@ private:
#if defined(BSD) || defined(__FreeBSD_kernel__)
int buffer_size_;
#endif // BSD
#ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
typedef std::map<NetworkInterface, pcap_t*> PcapHandleMap;
PcapHandleMap pcap_handles_;
#endif // HAVE_PACKET_SENDER_PCAP_SENDPACKET
#endif // TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
};
} // Tins

View File

@@ -33,11 +33,13 @@
#include "utils.h"
#include <string>
#include <iterator>
#include <pcap.h>
#include "data_link_type.h"
#include "macros.h"
#include "cxxstd.h"
#ifdef TINS_HAVE_PCAP
#include <pcap.h>
#include "data_link_type.h"
struct timeval;
namespace Tins {
@@ -220,6 +222,9 @@ private:
pcap_t* handle_;
pcap_dumper_t* dumper_;
};
}
} // Tins
#endif // TINS_HAVE_PCAP
#endif // TINS_PACKET_WRITER_H

View File

@@ -36,7 +36,6 @@
#include "macros.h"
#include "cxxstd.h"
#include "exceptions.h"
#include "macros.h"
/** \brief The Tins namespace.
*/
@@ -179,6 +178,7 @@ public:
IPSEC_ESP,
PKTAP,
MPLS,
UNKNOWN = 999,
USER_DEFINED_PDU = 1000
};
@@ -188,6 +188,37 @@ public:
*/
static const endian_type endianness = BE;
/**
* \brief Type used to store a PDU header's data.
*/
struct metadata {
/**
* \brief Default constructor
*/
metadata();
/**
* \brief Constructs an instance of metadata using the given values
*/
metadata(uint32_t header_size, PDUType current_type, PDUType next_type);
/**
* The total header size for the current protocol
*/
uint32_t header_size;
/**
* The current PDU type
*/
PDUType current_pdu_type;
/**
* The next PDU type
*/
PDUType next_pdu_type;
};
/**
* \brief Default constructor.
*/
@@ -322,7 +353,7 @@ public:
*/
template<typename T>
const T* find_pdu(PDUType type = T::pdu_flag) const {
return const_cast<PDU*>(this)->find_pdu<T>();
return const_cast<PDU*>(this)->find_pdu<T>(type);
}
/**
@@ -350,7 +381,7 @@ public:
*/
template<typename T>
const T& rfind_pdu(PDUType type = T::pdu_flag) const {
return const_cast<PDU*>(this)->rfind_pdu<T>();
return const_cast<PDU*>(this)->rfind_pdu<T>(type);
}
/**
@@ -402,9 +433,7 @@ public:
* \param ptr The pointer to the buffer.
* \param total_sz The size of the buffer.
*/
virtual bool matches_response(const uint8_t* ptr, uint32_t total_sz) const {
return false;
}
virtual bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
/**
* \brief Check whether this PDU matches the specified flag.
@@ -454,7 +483,7 @@ protected:
*
* \param parent The parent PDU.
*/
virtual void prepare_for_serialize(const PDU* parent) { }
virtual void prepare_for_serialize(const PDU* parent);
/**
* \brief Serializes this PDU and propagates this action to child PDUs.

View File

@@ -333,8 +333,10 @@ public:
PDUOption(option_type opt = option_type(),
size_t length = 0,
const data_type* data = 0)
: option_(opt), size_(static_cast<uint16_t>(length)) {
set_payload_contents(data, data + (data ? length : 0));
: option_(opt), size_(static_cast<uint16_t>(length)), real_size_(0) {
if (data != 0) {
set_payload_contents(data, data + length);
}
}
/**
@@ -368,7 +370,7 @@ public:
}
real_size_ = rhs.real_size_;
if (real_size_ > small_buffer_size) {
payload_.big_buffer_ptr = nullptr;
payload_.big_buffer_ptr = 0;
std::swap(payload_.big_buffer_ptr, rhs.payload_.big_buffer_ptr);
rhs.real_size_ = 0;
}

View File

@@ -33,6 +33,9 @@
#include "pdu.h"
#include "macros.h"
// This class is only available if pcap is enabled
#ifdef TINS_HAVE_PCAP
namespace Tins {
/**
@@ -74,7 +77,7 @@ public:
/**
* \brief Returns the header size.
*
* This metod overrides PDU::header_size.
* This method overrides PDU::header_size.
* \sa PDU::header_size
*/
uint32_t header_size() const;
@@ -111,4 +114,6 @@ private:
} // Tins
#endif // TINS_HAVE_PCAP
#endif // TINS_PKTAP_H

View File

@@ -35,6 +35,8 @@
#include "endianness.h"
#include "small_uint.h"
#ifdef TINS_HAVE_PCAP
namespace Tins {
/**
@@ -102,7 +104,7 @@ public:
/**
* \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;
@@ -135,6 +137,9 @@ private:
ppi_header header_;
byte_array data_;
};
}
} // Tins
#endif // TINS_HAVE_PCAP
#endif // TINS_PPI_H

View File

@@ -167,7 +167,7 @@ public:
/**
* \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;

View File

@@ -29,7 +29,7 @@
#include "config.h"
#if !defined(TINS_RADIOTAP_H) && defined(HAVE_DOT11)
#if !defined(TINS_RADIOTAP_H) && defined(TINS_HAVE_DOT11)
#define TINS_RADIOTAP_H
#include "macros.h"
@@ -506,10 +506,21 @@ private:
radiotap_hdr radio_;
// present fields...
uint64_t tsft_;
uint16_t channel_type_, channel_freq_, rx_flags_, signal_quality_, tx_flags_;
uint16_t channel_type_;
uint16_t channel_freq_;
uint16_t rx_flags_;
uint16_t signal_quality_;
uint16_t tx_flags_;
mcs_type mcs_;
uint8_t antenna_, flags_, rate_, channel_, max_power_, db_signal_, data_retries_;
int8_t dbm_signal_, dbm_noise_;
uint8_t antenna_;
uint8_t flags_;
uint8_t rate_;
uint8_t channel_;
uint8_t max_power_;
uint8_t db_signal_;
uint8_t data_retries_;
int8_t dbm_signal_;
int8_t dbm_noise_;
};
}

View File

@@ -152,7 +152,7 @@ public:
*
* This returns the same as RawPDU::payload_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;

View File

@@ -29,7 +29,7 @@
#include "config.h"
#if !defined(TINS_RSN_INFORMATION) && defined(HAVE_DOT11)
#if !defined(TINS_RSN_INFORMATION) && defined(TINS_HAVE_DOT11)
#define TINS_RSN_INFORMATION
#include <stdint.h>

Some files were not shown because too many files have changed in this diff Show More