mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 10:45:57 +01:00
Compare commits
297 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
142b6f62cb | ||
|
|
dfd2701ee4 | ||
|
|
850bb9b642 | ||
|
|
b7e61f4c76 | ||
|
|
e2a14d8898 | ||
|
|
ba0c820852 | ||
|
|
df509e7e36 | ||
|
|
fa87e1b6f6 | ||
|
|
812be7966d | ||
|
|
f89cc9f076 | ||
|
|
638bf9b34b | ||
|
|
eb997f5438 | ||
|
|
18cbab4fc7 | ||
|
|
7cd2b2c396 | ||
|
|
2601493752 | ||
|
|
7204fbd688 | ||
|
|
c302e659d7 | ||
|
|
54e4e4b0f4 | ||
|
|
6a17e59032 | ||
|
|
e3aedc56ed | ||
|
|
3b006c15db | ||
|
|
177d0b4621 | ||
|
|
24ac038c30 | ||
|
|
a619e4ff98 | ||
|
|
14bb185d7a | ||
|
|
137b56d5a7 | ||
|
|
ed2b3c12d5 | ||
|
|
1650b60234 | ||
|
|
c20c82bcb5 | ||
|
|
5858132261 | ||
|
|
16f5795243 | ||
|
|
e90e377b73 | ||
|
|
222611b377 | ||
|
|
b447c664e1 | ||
|
|
468159e6d2 | ||
|
|
cd40b232e7 | ||
|
|
1166094a2f | ||
|
|
b3d874d6a8 | ||
|
|
553b1fb255 | ||
|
|
94939dd0fa | ||
|
|
0774a8dcad | ||
|
|
f46dee9f19 | ||
|
|
5b082a82b2 | ||
|
|
07012648fb | ||
|
|
ce409dbc7e | ||
|
|
16e77146ab | ||
|
|
a87c4a64f5 | ||
|
|
9e61286a59 | ||
|
|
8da102fb48 | ||
|
|
750c3556d9 | ||
|
|
28663b0e93 | ||
|
|
731e36e373 | ||
|
|
608b48f25c | ||
|
|
de247fcbc8 | ||
|
|
7bc4d38470 | ||
|
|
a926b75224 | ||
|
|
064439236c | ||
|
|
0c40a0714b | ||
|
|
d74520768b | ||
|
|
3385df9cc9 | ||
|
|
18c31b20f5 | ||
|
|
7387912ca1 | ||
|
|
0d52763a61 | ||
|
|
86b505f998 | ||
|
|
62a803c55c | ||
|
|
0573808aeb | ||
|
|
22b4435c81 | ||
|
|
b803959e11 | ||
|
|
2f16497bf8 | ||
|
|
78aa7d1787 | ||
|
|
ba2216e6e9 | ||
|
|
74e3d909e6 | ||
|
|
5e52091ecf | ||
|
|
dafb299ea3 | ||
|
|
659bec56d7 | ||
|
|
8c1bea6f84 | ||
|
|
d8d1dc003b | ||
|
|
c2bb52b82f | ||
|
|
1f5456b18b | ||
|
|
dc702f4fd6 | ||
|
|
2a8101eef3 | ||
|
|
20702ddaff | ||
|
|
f4e2701705 | ||
|
|
776ae4e83b | ||
|
|
2158c7a92e | ||
|
|
b53bad7b29 | ||
|
|
6c92bcdad1 | ||
|
|
b949e56d15 | ||
|
|
18ff3e7b6a | ||
|
|
559b1fb89a | ||
|
|
1e78ef0752 | ||
|
|
602ada7820 | ||
|
|
57ac099703 | ||
|
|
eb7628eca4 | ||
|
|
c26e4943c2 | ||
|
|
7e90c8be6a | ||
|
|
3659d89c25 | ||
|
|
db992d42e5 | ||
|
|
5571a270d4 | ||
|
|
b18c2cefec | ||
|
|
3f204321ce | ||
|
|
63603b8ac8 | ||
|
|
fa79582b89 | ||
|
|
342e2c77a7 | ||
|
|
7848e28b62 | ||
|
|
544aa1b339 | ||
|
|
de4791f0c7 | ||
|
|
915f506f3a | ||
|
|
f29566d6d9 | ||
|
|
e4f747164c | ||
|
|
683550b297 | ||
|
|
971fdf7d1c | ||
|
|
1038c6f7f3 | ||
|
|
8efc0271f5 | ||
|
|
9ac5e597e6 | ||
|
|
f7fc5fae1d | ||
|
|
f44b253a42 | ||
|
|
8f85a6e557 | ||
|
|
8fd25e23a6 | ||
|
|
a3dd057147 | ||
|
|
e16fe46d7a | ||
|
|
39f3b24058 | ||
|
|
8e50756afa | ||
|
|
c07cd40234 | ||
|
|
d2addea9cf | ||
|
|
f88c024b2f | ||
|
|
983325bfdf | ||
|
|
f4635a696e | ||
|
|
c439eccdf8 | ||
|
|
04e29858ee | ||
|
|
ab2850e22e | ||
|
|
6429dcd03f | ||
|
|
b43d2f74e4 | ||
|
|
2aab4cf126 | ||
|
|
f2766db829 | ||
|
|
db0fb7f20d | ||
|
|
a6817528bc | ||
|
|
a7dd867503 | ||
|
|
e48f64daac | ||
|
|
171067eb22 | ||
|
|
78b94fa350 | ||
|
|
c84652af40 | ||
|
|
19fd9a7c1d | ||
|
|
5df1c354f0 | ||
|
|
eb0d82ce89 | ||
|
|
f89e922d72 | ||
|
|
ecacd4aee5 | ||
|
|
a17ec89332 | ||
|
|
7003541284 | ||
|
|
87c0e3a337 | ||
|
|
cfb9b646cc | ||
|
|
eed8229a04 | ||
|
|
3e6e25d0aa | ||
|
|
77ca5c2701 | ||
|
|
ca3127ffbc | ||
|
|
77d965784e | ||
|
|
edd289c645 | ||
|
|
2f528876ad | ||
|
|
aa64e34880 | ||
|
|
5fcde41023 | ||
|
|
63e22fc349 | ||
|
|
7af1ec0984 | ||
|
|
4e95797710 | ||
|
|
a641589b09 | ||
|
|
b8e4c7248b | ||
|
|
d29296935e | ||
|
|
1da2c1dcdc | ||
|
|
76395370de | ||
|
|
7589a0a108 | ||
|
|
34072f733c | ||
|
|
9442233a8a | ||
|
|
993831709d | ||
|
|
4def995185 | ||
|
|
fa85aa3f8b | ||
|
|
8021112fea | ||
|
|
80f424b6b3 | ||
|
|
1ef5be352a | ||
|
|
1a83801722 | ||
|
|
3c2f40ec02 | ||
|
|
b47dc3f77c | ||
|
|
f1e726f503 | ||
|
|
afb6ad488c | ||
|
|
5d68211af2 | ||
|
|
887bccf0af | ||
|
|
7eb067338f | ||
|
|
6896cc6346 | ||
|
|
de2f29b797 | ||
|
|
1ec6006f33 | ||
|
|
d9f92c46c4 | ||
|
|
9677c06036 | ||
|
|
a07b3e8a3a | ||
|
|
58a4d336b9 | ||
|
|
86da3818ff | ||
|
|
815889bd22 | ||
|
|
be48947ead | ||
|
|
3e7188edf7 | ||
|
|
3d4f9285c9 | ||
|
|
e556f4147f | ||
|
|
4e4f7a2390 | ||
|
|
35e65d018c | ||
|
|
714b8d9810 | ||
|
|
d061fced7e | ||
|
|
36fedf4f65 | ||
|
|
89202c5dd5 | ||
|
|
110adc58dc | ||
|
|
6f32a1982a | ||
|
|
c50c4c105c | ||
|
|
ac69278676 | ||
|
|
af325f00d9 | ||
|
|
28fa1b2f7e | ||
|
|
ab51787323 | ||
|
|
92bda42ac1 | ||
|
|
730e69463c | ||
|
|
07f000f65a | ||
|
|
3e7d30e01c | ||
|
|
22c72955f5 | ||
|
|
6f681f6519 | ||
|
|
c7273ddd30 | ||
|
|
2c6ef2a5c0 | ||
|
|
4eb4dfe5fa | ||
|
|
8838ddf921 | ||
|
|
6b3875ae39 | ||
|
|
ab763f25a4 | ||
|
|
550eea98b1 | ||
|
|
ecfed8db44 | ||
|
|
fe6e575158 | ||
|
|
d0b4383a0d | ||
|
|
83e2c8dc47 | ||
|
|
57787649d7 | ||
|
|
c9e7237184 | ||
|
|
52be4b0e8a | ||
|
|
e1571e19a8 | ||
|
|
8c7bf7d779 | ||
|
|
406e458c3a | ||
|
|
3f26974563 | ||
|
|
988f2382c4 | ||
|
|
b983fe0bb3 | ||
|
|
5a3f3e43a6 | ||
|
|
49d6e42324 | ||
|
|
d7a7877bfe | ||
|
|
d8ead95070 | ||
|
|
5404e9f004 | ||
|
|
f0aaec98f3 | ||
|
|
348371e43c | ||
|
|
4763486523 | ||
|
|
7250c7a03d | ||
|
|
cedd127e8f | ||
|
|
fcad90b5e9 | ||
|
|
64778f5412 | ||
|
|
a5766a19c2 | ||
|
|
c6f4e816aa | ||
|
|
ce6ef3186b | ||
|
|
6a66008153 | ||
|
|
6c6b345ba0 | ||
|
|
734b874dab | ||
|
|
6d573d8327 | ||
|
|
11eca1816a | ||
|
|
b0d66a01d2 | ||
|
|
bd0db1354e | ||
|
|
01475679d1 | ||
|
|
b2173ffb86 | ||
|
|
3f2f6438fd | ||
|
|
60b5f3e6e4 | ||
|
|
82e97addb1 | ||
|
|
19ae1f366b | ||
|
|
a9747a349a | ||
|
|
fe38bba477 | ||
|
|
a20f9d3e81 | ||
|
|
39e9f0542d | ||
|
|
1c2c5d7dd4 | ||
|
|
1c2ac61bb0 | ||
|
|
f764f68e9c | ||
|
|
2453e57436 | ||
|
|
500ef1088b | ||
|
|
c83cff36d8 | ||
|
|
589adba798 | ||
|
|
6e1d1d3dc4 | ||
|
|
ec59194232 | ||
|
|
7de4474996 | ||
|
|
95626a867e | ||
|
|
c072ffe421 | ||
|
|
ac797a836e | ||
|
|
0cda2287a8 | ||
|
|
6bfc0c84f0 | ||
|
|
1bd0cd504e | ||
|
|
a3e863942b | ||
|
|
f88cf9b025 | ||
|
|
1ad245238f | ||
|
|
4c54a69e64 | ||
|
|
77a31ca6b5 | ||
|
|
c06787ca22 | ||
|
|
15a353c123 | ||
|
|
1b4d22314d | ||
|
|
35383ac359 | ||
|
|
d2b00990fe | ||
|
|
97a11073d4 | ||
|
|
95b6261324 |
28
.github/workflows/tests.yaml
vendored
Normal file
28
.github/workflows/tests.yaml
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Tests
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
Ubuntu-Tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install libpcap
|
||||
run: sudo apt-get install -y libpcap-dev
|
||||
|
||||
- name: Initialize submodules
|
||||
run: git submodule init && git submodule update
|
||||
|
||||
- name: Initialize build system
|
||||
run: mkdir build && cd build && cmake ..
|
||||
|
||||
- name: Build tests
|
||||
run: cmake --build build --target tests
|
||||
|
||||
- name: Run tests
|
||||
run: ctest build
|
||||
222
CHANGES.md
222
CHANGES.md
@@ -1,3 +1,175 @@
|
||||
##### v4.5 - Sun Aug 20 04:46:53 PM UTC 2023
|
||||
|
||||
- Add VXLAN support (#501)
|
||||
|
||||
- Add `FileSniffer` constructor taking a `FILE*` (#499).
|
||||
|
||||
- Remove use of deprecated `std::iterator` (#481).
|
||||
|
||||
- Add missing `algorithm` header include (#497).
|
||||
|
||||
- Validate high order two bits of first dns label octet (#494).
|
||||
|
||||
- Use `CMAKE_INSTALL_LIBDIR` in `CONF_CMAKE_INSTALL_DIR` (#472).
|
||||
|
||||
- Ignore IPv6 packets with payload after one with no Next Header (#500).
|
||||
|
||||
- Fix unqualified `std::move` call warnings on clang (#488).
|
||||
|
||||
- Fix incorrect IP address range calculation when using /0 prefix (#484) (#486).
|
||||
|
||||
- Fall back to system GTest if available (#473).
|
||||
|
||||
- Fix compilation issue on android (#471).
|
||||
|
||||
- Fix DNS parser reading garbage on misreported packet size (#468).
|
||||
|
||||
- Fix DNS parser misinterpreting bad label size (#466).
|
||||
|
||||
##### v4.4 - Thu Feb 17 14:41:59 UTC 2022
|
||||
|
||||
- Add RFC8335 extended echo types to `ICMP` and `ICMPv6` (#426)
|
||||
|
||||
- Handle loops in DNS name decompression (#444)
|
||||
|
||||
- Fix Windows' `interface` macro colliding with uses of that identifier in the code (#458)
|
||||
|
||||
- Sending IPv6 packets to a link-scope destination address now uses the right interface index (#448)
|
||||
|
||||
- Fix incorrect endian being used for ICMP's `gateway` and `address_mask` (#437)
|
||||
|
||||
- Socket in `PacketSender::open_l3_socket` is now closed if `setsockopt` fails (#433)
|
||||
|
||||
- Fix various incorrect doxygen documentation comments (#439).
|
||||
|
||||
- Fix infinite loop when querying the routing table in \*BSD (#427)
|
||||
|
||||
##### v4.3 - Fri Sep 18 03:08:33 UTC 2020
|
||||
|
||||
- Assign a PDUType to `Dot11ControlTA` (#420)
|
||||
|
||||
- Don't consider IPv6 ESP header a normal extension header (#374)
|
||||
|
||||
- Don't include non-existing headers when installed without libpcap (#382)
|
||||
|
||||
- Add `IPv6Address::is_local_unicast` (#369)
|
||||
|
||||
- Fix memory leak in `PacketWriter` (#343)
|
||||
|
||||
- Fix memory leaks in `OfflinePacketFilter` (#343)
|
||||
|
||||
- Fix detection of new TCP stream (#335)
|
||||
|
||||
- Introduce `TCP::has_flags` (#334)
|
||||
|
||||
- Fix padding calculations in RadioTapWriter (#333)
|
||||
|
||||
##### v4.2 - Fri Mar 8 04:15:13 UTC 2019
|
||||
|
||||
- Updated location of installed CMake files in unix systems (#331)
|
||||
|
||||
- Fix check to detect cross compilation (#330)
|
||||
|
||||
- Allow getting a PDU's advertised size and use it in `PacketWriter` (#324)
|
||||
|
||||
- Install DLLs in right directory (#326)
|
||||
|
||||
- Add missing Dot11 tagged option types (#305)
|
||||
|
||||
- Add support for DLT_RAW (#313)
|
||||
|
||||
- Fix potential invalid memory accesses when parsing RadioTap (#322)
|
||||
|
||||
##### v4.1 - Tue Dec 11 02:08:48 UTC 2018
|
||||
|
||||
- Fix serialization for QinQ (#316)
|
||||
|
||||
- Added base class access specifier for socket_close_error (#306)
|
||||
|
||||
- Rewrote hw_address_to_string to not require a stringstream (#299)
|
||||
|
||||
- Make RadioTapParser::skip_to_field check for end of buffer (#296)
|
||||
|
||||
- Ensure local include directory comes before system. (#293)
|
||||
|
||||
- Calculate IP option sizes properly (#288)
|
||||
|
||||
- Add parsing of well known IPv6 extension headers (#287)
|
||||
|
||||
- Add missing operators to address classes (#275)
|
||||
|
||||
- Add version macros in config.h
|
||||
|
||||
- Don't assume IPv6 uses ICMPv6 underneath
|
||||
|
||||
- Allow users to specify library install dir
|
||||
|
||||
- Use Sleep windows function passing milliseconds as parameter
|
||||
|
||||
- Implement IPv6::recv_response
|
||||
|
||||
- Don't use nullptr in non C++11 code
|
||||
|
||||
- Ignore (possibly malformed) options after EOL (#281)
|
||||
|
||||
- Don't include dot11.h in tins.h if it is not configured in the library (#277)
|
||||
|
||||
- Fix memory leak in PDU's move assignment operator
|
||||
|
||||
- Append padding to IPv6 options
|
||||
|
||||
##### v4.0 - Mon Dec 4 00:04:30 UTC 2017
|
||||
|
||||
- Add parent PDU to each PDU.
|
||||
|
||||
- Removed parent PDU parameter on `PDU::write_serialization`.
|
||||
|
||||
- Split `utils.h` into multiple files under the `utils` directory.
|
||||
|
||||
- Split `internals.h` into multiple files under the `detail` directory.
|
||||
|
||||
- Improve compilation times by removing useless include directives.
|
||||
|
||||
- Refactor `PDUOption` conversions so that heavy headers are not included in source file.
|
||||
|
||||
- Use `std::vector` instead of `std::list` in `TCP`, `IP`, `IPv6`, `DHCP`, `DHCPv6`, `DNS`, `LLC`, `Dot11` and `PPPoE`.
|
||||
|
||||
- Improve performance on `IP`, `IPv6` and `TCP` by compiting option sizes during serialization.
|
||||
|
||||
- Minor performance improvements in `DNS`.
|
||||
|
||||
- Fix `IPv6` next header handling. Now each one contains its own type and the next type is only set during serialization for ease of use.
|
||||
|
||||
- Refactor `RadioTap` parsing and serialization using a generic parser/writer.
|
||||
|
||||
- Add `BaseSniffer::set_pcap_sniffing_method` to specify whether `pcap_loop` or `pcap_dispatch` should be used when sniffing.
|
||||
|
||||
- Use `IFF_POINTOPOINT` on BSD when getting broadcast address for an interface.
|
||||
|
||||
- Added cipher and akm suites from 802.11-2016.
|
||||
|
||||
- Add IPv6 layer parsing on `Loopback` packets.
|
||||
|
||||
- Allow serializing `Loopback` on Windows.
|
||||
|
||||
- Use the right flag on `Loopback` for `IPv6`.
|
||||
|
||||
- Use the first fragment as a base when reassembling `IP` packets in `IPv4Reassembler`.
|
||||
|
||||
- Restructure CMake files removing useless `CMakeLists.txt` in `include` paths.
|
||||
|
||||
- Add getter/setter for "more data" field in `Dot11Base`.
|
||||
|
||||
- Implemented matching for ND protocol related ICMPv6 messages.
|
||||
|
||||
- Ensure TCP::OptionTypes has 8-bit range.
|
||||
|
||||
- Add header files into CMake sources so IDE can pick them up.
|
||||
|
||||
- Add MPLS "experimental" field.
|
||||
|
||||
- Fix dhcpv6::duid_type constructor from duid_ll.
|
||||
|
||||
##### v3.5 - Sat Apr 1 09:11:58 PDT 2017
|
||||
|
||||
- Added Utils::route6_entries
|
||||
@@ -126,7 +298,7 @@
|
||||
|
||||
- Move implementations on utils.h to utils.cpp
|
||||
|
||||
- Add ICMPv6 Multicast Listener Query Messages support
|
||||
- Add ICMPv6 Multicast Listener Query Messages support
|
||||
|
||||
- Add ICMPv6 Multicast Listener Report Message support
|
||||
|
||||
@@ -270,7 +442,7 @@
|
||||
|
||||
- Added RadioTap channel map type
|
||||
|
||||
- Made rsn_information() a const member function to make Dot11ManagementFrame
|
||||
- Made rsn_information() a const member function to make Dot11ManagementFrame
|
||||
immutable
|
||||
|
||||
- Ensure HAVE_CXX11 is checked when defining TINS_IS_CXX11
|
||||
@@ -320,7 +492,7 @@ its value.
|
||||
|
||||
- Removed obsolete autotools files.
|
||||
|
||||
- Fixed exception thrown when an interface didn't have an IP address
|
||||
- Fixed exception thrown when an interface didn't have an IP address
|
||||
on NetworkInterface.
|
||||
|
||||
- Added NetworkInterface::is_loopback.
|
||||
@@ -364,7 +536,7 @@ conversion on integral constant.
|
||||
|
||||
- Added DataLinkType class.
|
||||
|
||||
- IPv4Address now uses inet_pton when constructing from string.
|
||||
- IPv4Address now uses inet_pton when constructing from string.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
@@ -385,8 +557,8 @@ conversion on integral constant.
|
||||
- Packets can now be constructed from a PDU pointer and take ownership
|
||||
of it.
|
||||
|
||||
- All protocols now set the next layer protocol flag, regardless if
|
||||
it was already set. This was not done in some protocols,
|
||||
- All protocols now set the next layer protocol flag, regardless if
|
||||
it was already set. This was not done in some protocols,
|
||||
like EthernetII, and as a consequence if the network layer protocol
|
||||
was replaced by other, the packet would be serialized incorrectly.
|
||||
|
||||
@@ -427,7 +599,7 @@ TCPStreamFollower::follow_streams.
|
||||
|
||||
- Added DHCP::hostname to extract the hostname options.
|
||||
|
||||
- Removed extra qualifier on SessionKeys::decrypt_unicast which
|
||||
- Removed extra qualifier on SessionKeys::decrypt_unicast which
|
||||
produced compilation errors on some platforms.
|
||||
|
||||
- PacketSender::send now uses PDU::matches_flag to match specific
|
||||
@@ -443,9 +615,9 @@ PDU types.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
##### v2.0 - Thu Jan 23 11:09:38 ART 2014
|
||||
##### v2.0 - Thu Jan 23 11:09:38 ART 2014
|
||||
|
||||
- DNSResourceRecord was removed. Now DNS records are added using
|
||||
- DNSResourceRecord was removed. Now DNS records are added using
|
||||
DNS::Resource.
|
||||
|
||||
- tins.h now includes ppi.h.
|
||||
@@ -454,21 +626,21 @@ DNS::Resource.
|
||||
|
||||
- Added PDUOption<>::to<> which converts a PDUOption to a specific type.
|
||||
|
||||
- Layer 3 packets sent using PacketSender::send_recv for which the
|
||||
- Layer 3 packets sent using PacketSender::send_recv for which the
|
||||
answer is a different PDU type.
|
||||
|
||||
- ICMP::gateway now uses IPv4Address.
|
||||
|
||||
- Added support for ICMP address mask request/reply.
|
||||
|
||||
- Fixed bug in PacketSender when using send_recv and a layer 2 PDU. The
|
||||
interface in which the packet was sent was not the default_interface
|
||||
- Fixed bug in PacketSender when using send_recv and a layer 2 PDU. The
|
||||
interface in which the packet was sent was not the default_interface
|
||||
set when the sender was constructed.
|
||||
|
||||
- IP packets sent using PacketSender::send_recv now match ICMP
|
||||
- IP packets sent using PacketSender::send_recv now match ICMP
|
||||
responses.
|
||||
|
||||
- Added support for ICMP timestamp request/reply packets.
|
||||
- Added support for ICMP timestamp request/reply packets.
|
||||
ICMP::matches_response now works with these types of packets as well.
|
||||
|
||||
- Added support for reassembling of fragmented IP packets via the
|
||||
@@ -476,20 +648,20 @@ IPv4Reassembler class.
|
||||
|
||||
- Fragmented IP packet's inner_pdu PDUs are not decoded now.
|
||||
|
||||
- Added 1000ms as the default read timeout used when calling
|
||||
- Added 1000ms as the default read timeout used when calling
|
||||
pcap_open_live. Added BaseSniffer::set_timeout to modify this parameter.
|
||||
|
||||
- Added the --disable-dot11 configure switch.
|
||||
|
||||
- Added support for IPSec.
|
||||
|
||||
- Fixed bug triggered when ifaddrs::ifa_addr was null in
|
||||
- Fixed bug triggered when ifaddrs::ifa_addr was null in
|
||||
NetworkInterface::addresses.
|
||||
|
||||
- Added another overload of Utils::route_entries which returns the
|
||||
result either than storing it in a parameter.
|
||||
|
||||
- Added ARP monitor, WPS detector, DNS queries sniffer and DNS spoofer
|
||||
- Added ARP monitor, WPS detector, DNS queries sniffer and DNS spoofer
|
||||
examples.
|
||||
|
||||
- Added another Sniffer constructor which doesn't expect the maximum
|
||||
@@ -508,10 +680,10 @@ doesn't work well on some linux distributions.
|
||||
|
||||
- Added PPI PDU class.
|
||||
|
||||
- Fixed a bug in EthernetII triggered when the size of the whole frame
|
||||
- Fixed a bug in EthernetII triggered when the size of the whole frame
|
||||
was lower than 60 bytes.
|
||||
|
||||
- Added AddressRange class and IPv4Address, IPv6Address and
|
||||
- Added AddressRange class and IPv4Address, IPv6Address and
|
||||
HWAddress<>::operator/.
|
||||
|
||||
- Added is_broadcast, is_multicast and is_unicast to IPv4, IPv6
|
||||
@@ -521,7 +693,7 @@ and HWAddress.
|
||||
|
||||
- Done some optimizations on TCP's constructor from buffer.
|
||||
|
||||
- Added helper functions to Dot11Data to retrieve the source,
|
||||
- Added helper functions to Dot11Data to retrieve the source,
|
||||
destination and BSSID addresses.
|
||||
|
||||
- Fixed bugs in DNS triggered when parsing MX and unknown records.
|
||||
@@ -541,7 +713,7 @@ types.
|
||||
|
||||
- Added WPA2Decrypter class.
|
||||
|
||||
- IEEE 802.11 frames are not parsed if the RadioTap FAILED_FCS flag
|
||||
- IEEE 802.11 frames are not parsed if the RadioTap FAILED_FCS flag
|
||||
is on.
|
||||
|
||||
- RadioTap now calculates its size everytime it's serialized.
|
||||
@@ -558,13 +730,13 @@ v1.0 - Tue Apr 23 20:40:57 ART 2013
|
||||
- Link layer protocol PDUs now don't hold a NetworkInterface. This led
|
||||
to changes in their constructors.
|
||||
|
||||
- Removed the obsolete PDU* parameter taken by several classes'
|
||||
- Removed the obsolete PDU* parameter taken by several classes'
|
||||
constructors.
|
||||
|
||||
- IP now sets the sender's address automatically when no link layer
|
||||
PDU is used.
|
||||
|
||||
- IP, TCP and UDP now calculate the checksum everytime they're
|
||||
- IP, TCP and UDP now calculate the checksum everytime they're
|
||||
serialized.
|
||||
|
||||
- Added PDU::rfind_pdu.
|
||||
@@ -575,7 +747,7 @@ serialized.
|
||||
|
||||
- PacketSender is now movable.
|
||||
|
||||
- Added an overload of add_option that takes an rvalue-reference in IP,
|
||||
- Added an overload of add_option that takes an rvalue-reference in IP,
|
||||
TCP, DHCP, ICMPv6 and Dot11.
|
||||
|
||||
- Added support for GNU/kFreeBSD.
|
||||
@@ -618,7 +790,7 @@ pseudo protocol.
|
||||
|
||||
##### v0.2 - Sat Oct 20 11:26:40 2012
|
||||
|
||||
- Added support for big endian architectures.
|
||||
- Added support for big endian architectures.
|
||||
|
||||
- Simplified several interfaces.
|
||||
|
||||
|
||||
101
CMakeLists.txt
101
CMakeLists.txt
@@ -1,6 +1,9 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
|
||||
PROJECT(libtins)
|
||||
|
||||
OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON)
|
||||
OPTION(LIBTINS_BUILD_TESTS "Build tests" ON)
|
||||
|
||||
# Compile in release mode by default
|
||||
IF(NOT CMAKE_BUILD_TYPE)
|
||||
MESSAGE(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
|
||||
@@ -42,9 +45,10 @@ ELSE(LIBTINS_BUILD_SHARED)
|
||||
ENDIF(LIBTINS_BUILD_SHARED)
|
||||
|
||||
# The version number.
|
||||
SET(LIBTINS_VERSION_MAJOR 3)
|
||||
SET(LIBTINS_VERSION_MINOR 5)
|
||||
SET(LIBTINS_VERSION "${LIBTINS_VERSION_MAJOR}.${LIBTINS_VERSION_MINOR}")
|
||||
SET(TINS_VERSION_MAJOR 4)
|
||||
SET(TINS_VERSION_MINOR 5)
|
||||
SET(TINS_VERSION_PATCH 0)
|
||||
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
|
||||
|
||||
# Required Packages
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||
@@ -221,18 +225,22 @@ IF(DOXYGEN_FOUND)
|
||||
)
|
||||
ENDIF(DOXYGEN_FOUND)
|
||||
|
||||
# The library output directory
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
# Configuration file
|
||||
CONFIGURE_FILE(
|
||||
"${PROJECT_SOURCE_DIR}/include/tins/config.h.in"
|
||||
"${PROJECT_SOURCE_DIR}/include/tins/config.h"
|
||||
)
|
||||
|
||||
IF (NOT CMAKE_INSTALL_LIBDIR)
|
||||
SET(CMAKE_INSTALL_LIBDIR lib)
|
||||
ENDIF()
|
||||
IF (NOT CMAKE_INSTALL_BINDIR)
|
||||
SET(CMAKE_INSTALL_BINDIR bin)
|
||||
ENDIF()
|
||||
# The library output directory
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
# Support for pkg-config
|
||||
SET(CMAKE_INSTALL_LIBDIR lib)
|
||||
SET(pkgconfig_prefix ${CMAKE_INSTALL_PREFIX})
|
||||
SET(pkgconfig_exec_prefix ${CMAKE_INSTALL_PREFIX})
|
||||
SET(pkgconfig_libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
|
||||
@@ -260,44 +268,61 @@ ADD_CUSTOM_TARGET(uninstall
|
||||
# ******************
|
||||
# Add subdirectories
|
||||
# ******************
|
||||
ADD_SUBDIRECTORY(include)
|
||||
ADD_SUBDIRECTORY(src)
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
ADD_SUBDIRECTORY(examples)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Not building examples as pcap support is disabled")
|
||||
|
||||
IF(LIBTINS_BUILD_EXAMPLES)
|
||||
IF(LIBTINS_ENABLE_PCAP)
|
||||
ADD_SUBDIRECTORY(examples)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Not building examples as pcap support is disabled")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Only include googletest if the git submodule has been fetched
|
||||
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
|
||||
# Enable tests and add the test directory
|
||||
MESSAGE(STATUS "Tests have been enabled")
|
||||
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
|
||||
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
|
||||
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
|
||||
IF(LIBTINS_BUILD_TESTS)
|
||||
# Only include googletest if the git submodule has been fetched
|
||||
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
|
||||
# Enable tests and add the test directory
|
||||
MESSAGE(STATUS "Tests have been enabled")
|
||||
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
|
||||
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
|
||||
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
|
||||
|
||||
ExternalProject_Add(
|
||||
googletest
|
||||
DOWNLOAD_COMMAND ""
|
||||
SOURCE_DIR ${GOOGLETEST_ROOT}
|
||||
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
|
||||
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
|
||||
"-Dgtest_force_shared_crt:bool=ON"
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
# Make sure we build googletest before anything else
|
||||
ADD_DEPENDENCIES(tins googletest)
|
||||
ENABLE_TESTING()
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
|
||||
ExternalProject_Add(
|
||||
googletest
|
||||
DOWNLOAD_COMMAND ""
|
||||
SOURCE_DIR ${GOOGLETEST_ROOT}
|
||||
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
|
||||
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
|
||||
"-Dgtest_force_shared_crt:bool=ON"
|
||||
"-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER}"
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
# Make sure we build googletest before anything else
|
||||
ADD_DEPENDENCIES(tins googletest)
|
||||
ENABLE_TESTING()
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
ELSE()
|
||||
FIND_PACKAGE(GTest QUIET)
|
||||
IF(${GTest_FOUND})
|
||||
ENABLE_TESTING()
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# **********************************
|
||||
# CMake project configuration export
|
||||
# **********************************
|
||||
|
||||
if(UNIX)
|
||||
set(CONF_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/libtins")
|
||||
else()
|
||||
set(CONF_CMAKE_INSTALL_DIR CMake)
|
||||
endif()
|
||||
|
||||
# Add all targets to the build-tree export set
|
||||
EXPORT(
|
||||
TARGETS tins
|
||||
@@ -324,13 +349,13 @@ INSTALL(
|
||||
FILES
|
||||
"${PROJECT_BINARY_DIR}/libtinsConfig.cmake"
|
||||
"${PROJECT_BINARY_DIR}/libtinsConfigVersion.cmake"
|
||||
DESTINATION CMake
|
||||
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
|
||||
COMPONENT dev
|
||||
)
|
||||
|
||||
# Install the export set for use with the install-tree
|
||||
INSTALL(
|
||||
EXPORT libtinsTargets
|
||||
DESTINATION CMake
|
||||
DESTINATION ${CONF_CMAKE_INSTALL_DIR}
|
||||
COMPONENT dev
|
||||
)
|
||||
|
||||
@@ -22,9 +22,6 @@ easier.
|
||||
|
||||
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
|
||||
* Notice that your code will be compiled and tests will be run automatically by the travis and
|
||||
appveyor CI tools. If your code has issues on any of the tested platforms (GNU/Linux, Windows
|
||||
and OSX), please fix it or otherwise the PR won't be merged.
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2012-2014, Matias Fontanini
|
||||
Copyright (c) 2012-2017, Matias Fontanini
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -49,7 +49,7 @@ _build/lib_ directory.
|
||||
|
||||
### C++11 support
|
||||
|
||||
libtins is noticeable faster if you enable _C++11_ support. Therefore,
|
||||
libtins is noticeably 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:
|
||||
|
||||
@@ -144,4 +144,4 @@ 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.
|
||||
the [contributing](CONTRIBUTING.md) file before doing so.
|
||||
|
||||
@@ -79,14 +79,14 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
||||
set(_SRCFILE_FAIL "${_SRCFILE_BASE}_fail.cpp")
|
||||
set(_SRCFILE_FAIL_COMPILE "${_SRCFILE_BASE}_fail_compile.cpp")
|
||||
|
||||
if (CROSS_COMPILING)
|
||||
if (CMAKE_CROSSCOMPILING)
|
||||
try_compile(${RESULT_VAR} "${_bindir}" "${_SRCFILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
try_compile(${RESULT_VAR} "${_bindir}_fail" "${_SRCFILE_FAIL}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
else (CROSS_COMPILING)
|
||||
else (CMAKE_CROSSCOMPILING)
|
||||
try_run(_RUN_RESULT_VAR _COMPILE_RESULT_VAR
|
||||
"${_bindir}" "${_SRCFILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
@@ -105,7 +105,7 @@ function(cxx11_check_feature FEATURE_NAME RESULT_VAR)
|
||||
set(${RESULT_VAR} FALSE)
|
||||
endif (_COMPILE_RESULT_VAR AND _RUN_RESULT_VAR)
|
||||
endif (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL})
|
||||
endif (CROSS_COMPILING)
|
||||
endif (CMAKE_CROSSCOMPILING)
|
||||
if (${RESULT_VAR} AND EXISTS ${_SRCFILE_FAIL_COMPILE})
|
||||
try_compile(_TMP_RESULT "${_bindir}_fail_compile" "${_SRCFILE_FAIL_COMPILE}"
|
||||
COMPILE_DEFINITIONS "${CXX11_COMPILER_FLAGS}")
|
||||
|
||||
@@ -9,7 +9,7 @@ environment:
|
||||
matrix:
|
||||
- compiler: vs2013
|
||||
- compiler: vs2015
|
||||
BOOST_ROOT: C:\Libraries\boost
|
||||
BOOST_ROOT: C:/Libraries/boost
|
||||
clone_depth: 1
|
||||
install:
|
||||
- git clone https://github.com/mfontanini/winpcap-installer.git
|
||||
|
||||
@@ -1366,7 +1366,8 @@ INCLUDE_FILE_PATTERNS =
|
||||
# instead of the = operator.
|
||||
|
||||
PREDEFINED = "TINS_IS_CXX11=1" \
|
||||
"TINS_HAVE_WPA2_CALLBACKS=1"
|
||||
"TINS_HAVE_WPA2_CALLBACKS=1" \
|
||||
"TINS_HAVE_DOT11=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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -88,7 +88,7 @@ void do_arp_spoofing(NetworkInterface iface,
|
||||
sender.send(to_gw, iface);
|
||||
sender.send(to_victim, iface);
|
||||
#ifdef _WIN32
|
||||
Sleep(5);
|
||||
Sleep(5000);
|
||||
#else
|
||||
sleep(5);
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
|
||||
cout << "Usage: " <<* argv << " <interface>" << endl;
|
||||
return 1;
|
||||
}
|
||||
// Sniff on the provided interface in promiscuos mode
|
||||
// Sniff on the provided interface in promiscuous mode
|
||||
SnifferConfiguration config;
|
||||
config.set_promisc_mode(true);
|
||||
// Only capture udp packets sent to port 53
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -90,7 +90,7 @@ int main(int argc, char* argv[]) {
|
||||
cout << "Usage: " <<* argv << " <interface>" << endl;
|
||||
return 1;
|
||||
}
|
||||
// Sniff on the provided interface in promiscuos mode
|
||||
// Sniff on the provided interface in promiscuous mode
|
||||
SnifferConfiguration config;
|
||||
config.set_promisc_mode(true);
|
||||
// Use immediate mode so we get the packets as fast as we can
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -116,7 +116,7 @@ bool Scanner::callback(PDU& pdu) {
|
||||
cout << "Port: " << setw(5) << tcp.sport() << " closed\n";
|
||||
}
|
||||
// Is SYN flag on? Then port is open!
|
||||
else if(tcp.flags() == (TCP::SYN | TCP::ACK)) {
|
||||
else if(tcp.has_flags(TCP::SYN | TCP::ACK)) {
|
||||
cout << "Port: " << setw(5) << tcp.sport() << " open\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -94,6 +94,7 @@ string stream_identifier(const Stream& stream) {
|
||||
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;
|
||||
@@ -114,13 +115,34 @@ void on_connection_closed(Stream& stream) {
|
||||
|
||||
// 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;
|
||||
if (stream.is_partial_stream()) {
|
||||
// We found a partial stream. This means this connection/stream had
|
||||
// been established before we started capturing traffic.
|
||||
//
|
||||
// In this case, we need to allow for the stream to catch up, as we
|
||||
// may have just captured an out of order packet and if we keep waiting
|
||||
// for the holes to be filled, we may end up waiting forever.
|
||||
//
|
||||
// Calling enable_recovery_mode will skip out of order packets that
|
||||
// fall withing the range of the given window size.
|
||||
// See Stream::enable_recover_mode for more information
|
||||
cout << "[+] New connection " << stream_identifier(stream) << endl;
|
||||
|
||||
// Enable recovery mode using a window of 10kb
|
||||
stream.enable_recovery_mode(10 * 1024);
|
||||
}
|
||||
else {
|
||||
// Print some information about the new connection
|
||||
cout << "[+] New connection " << stream_identifier(stream) << endl;
|
||||
}
|
||||
|
||||
// Now configure the callbacks on it.
|
||||
// First, we want on_client_data to be called every time there's new client data
|
||||
stream.client_data_callback(&on_client_data);
|
||||
|
||||
// Same thing for server data, but calling on_server_data
|
||||
stream.server_data_callback(&on_server_data);
|
||||
|
||||
// When the connection is closed, call on_connection_closed
|
||||
stream.stream_closed_callback(&on_connection_closed);
|
||||
}
|
||||
@@ -134,8 +156,10 @@ int main(int argc, char* argv[]) {
|
||||
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);
|
||||
|
||||
@@ -143,11 +167,17 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Now construct the stream follower
|
||||
StreamFollower follower;
|
||||
|
||||
// We just need to specify the callback to be executed when a new
|
||||
// stream is captured. In this stream, you should define which callbacks
|
||||
// will be executed whenever new data is sent on that stream
|
||||
// (see on_new_connection)
|
||||
follower.new_stream_callback(&on_new_connection);
|
||||
|
||||
// Allow following partial TCP streams (e.g. streams that were
|
||||
// open before the sniffer started running)
|
||||
follower.follow_partial_streams(true);
|
||||
|
||||
// Now start capturing. Every time there's a new packet, call
|
||||
// follower.process_packet
|
||||
sniffer.sniff_loop([&](PDU& packet) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
const IP& ip = pdu.rfind_pdu<IP>();
|
||||
const TCP& tcp = pdu.rfind_pdu<TCP>();
|
||||
// We'll only close a connection when seeing a SYN|ACK
|
||||
if (tcp.flags() == (TCP::SYN | TCP::ACK)) {
|
||||
if (tcp.has_flags(TCP::SYN | TCP::ACK)) {
|
||||
// Create an ethernet header flipping the addresses
|
||||
EthernetII packet(eth.src_addr(), eth.dst_addr());
|
||||
// Do the same for IP
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,6 +35,7 @@
|
||||
#define _GLIBCXX_USE_NANOSLEEP
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
ADD_SUBDIRECTORY(tins)
|
||||
@@ -1,8 +0,0 @@
|
||||
FILE(GLOB INCLUDE_FILES "*.h")
|
||||
INSTALL(
|
||||
FILES ${INCLUDE_FILES}
|
||||
DESTINATION include/tins
|
||||
COMPONENT Headers
|
||||
)
|
||||
ADD_SUBDIRECTORY(dot11)
|
||||
ADD_SUBDIRECTORY(tcp_ip)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,19 +30,23 @@
|
||||
#ifndef TINS_ADDRESS_RANGE
|
||||
#define TINS_ADDRESS_RANGE
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
#include "endianness.h"
|
||||
#include "internals.h"
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/exceptions.h>
|
||||
#include <tins/detail/address_helpers.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
* \brief AddressRange iterator class.
|
||||
*/
|
||||
template<typename Address>
|
||||
class AddressRangeIterator : public std::iterator<std::forward_iterator_tag, const Address> {
|
||||
class AddressRangeIterator {
|
||||
public:
|
||||
typedef typename std::iterator<std::forward_iterator_tag, const Address>::value_type value_type;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef const Address value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef const Address* pointer;
|
||||
typedef const Address& reference;
|
||||
|
||||
struct end_iterator {
|
||||
|
||||
@@ -198,7 +202,7 @@ public:
|
||||
AddressRange(const address_type& first, const address_type& last, bool only_hosts = false)
|
||||
: first_(first), last_(last), only_hosts_(only_hosts){
|
||||
if (last_ < first_) {
|
||||
throw std::runtime_error("Invalid address range");
|
||||
throw exception_base("Invalid address range");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,11 +31,11 @@
|
||||
#ifndef TINS_ARP_H
|
||||
#define TINS_ARP_H
|
||||
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include "ip_address.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/ip_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -334,7 +334,7 @@ private:
|
||||
uint32_t target_ip_address;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
arp_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,13 +31,12 @@
|
||||
#define TINS_BOOTP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "ip_address.h"
|
||||
#include "hw_address.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/hw_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -268,15 +267,14 @@ public:
|
||||
*/
|
||||
template<size_t n>
|
||||
void chaddr(const HWAddress<n>& new_chaddr) {
|
||||
// Copy the new addr
|
||||
uint8_t* end = std::copy(
|
||||
new_chaddr.begin(),
|
||||
new_chaddr.begin() + std::min(n, sizeof(bootp_.chaddr)),
|
||||
bootp_.chaddr
|
||||
);
|
||||
// Fill what's left with zeros
|
||||
if (end < bootp_.chaddr + chaddr_type::address_size) {
|
||||
std::fill(end, bootp_.chaddr + chaddr_type::address_size, 0);
|
||||
size_t copy_threshold = std::min(n, sizeof(bootp_.chaddr));
|
||||
for (size_t i = 0; i < copy_threshold; ++i) {
|
||||
if (i < copy_threshold) {
|
||||
bootp_.chaddr[i] = new_chaddr[i];
|
||||
}
|
||||
else {
|
||||
bootp_.chaddr[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +330,7 @@ protected:
|
||||
*/
|
||||
vend_type& vend() { return vend_; }
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
* Struct that represents the Bootp datagram.
|
||||
|
||||
@@ -31,4 +31,9 @@
|
||||
/* Have libpcap */
|
||||
#cmakedefine TINS_HAVE_PCAP
|
||||
|
||||
/* Version macros */
|
||||
#define TINS_VERSION_MAJOR ${TINS_VERSION_MAJOR}
|
||||
#define TINS_VERSION_MINOR ${TINS_VERSION_MINOR}
|
||||
#define TINS_VERSION_PATCH ${TINS_VERSION_PATCH}
|
||||
|
||||
#endif // TINS_CONFIG_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,34 +27,30 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#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"
|
||||
#include "macros.h"
|
||||
#include "handshake_capturer.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/handshake_capturer.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class PDU;
|
||||
class Dot11;
|
||||
class Dot11Data;
|
||||
class SNAP;
|
||||
class RawPDU;
|
||||
|
||||
namespace Crypto {
|
||||
|
||||
struct RC4Key;
|
||||
|
||||
#ifdef TINS_HAVE_WPA2_DECRYPTION
|
||||
namespace WPA2 {
|
||||
|
||||
@@ -131,7 +127,6 @@ public:
|
||||
private:
|
||||
SNAP* ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
||||
SNAP* tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const;
|
||||
RC4Key generate_rc4_key(const Dot11Data& dot11, const RawPDU& raw) const;
|
||||
|
||||
ptk_type ptk_;
|
||||
bool is_ccmp_;
|
||||
@@ -177,27 +172,6 @@ private:
|
||||
} // WPA2
|
||||
#endif // TINS_HAVE_WPA2_DECRYPTION
|
||||
|
||||
/**
|
||||
* \brief RC4 Key abstraction.
|
||||
*/
|
||||
struct RC4Key {
|
||||
static const size_t data_size = 256;
|
||||
|
||||
/**
|
||||
* \brief Initializes the key using the provided iterator range.
|
||||
*
|
||||
* \param start The start of the range.
|
||||
* \param end The end of the range.
|
||||
*/
|
||||
template<typename ForwardIterator>
|
||||
RC4Key(ForwardIterator start, ForwardIterator end);
|
||||
|
||||
/**
|
||||
* The actual key data.
|
||||
*/
|
||||
uint8_t data[data_size];
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Decrypts WEP-encrypted traffic.
|
||||
*/
|
||||
@@ -499,20 +473,6 @@ private:
|
||||
decrypter_type decrypter_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Performs RC4 encription/decryption of the given byte range,
|
||||
* using the provided key.
|
||||
*
|
||||
* The decrypted range will be copied to the OutputIterator provided.
|
||||
*
|
||||
* \param start The beginning of the range.
|
||||
* \param start The end of the range.
|
||||
* \param key The key to be used.
|
||||
* \param output The iterator in which to write the output.
|
||||
*/
|
||||
template<typename ForwardIterator, typename OutputIterator>
|
||||
void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output);
|
||||
|
||||
/**
|
||||
* \brief Wrapper function to create a DecrypterProxy using a
|
||||
* WEPDecrypter as the Decrypter template parameter.
|
||||
@@ -570,35 +530,6 @@ DecrypterProxy<Functor, WEPDecrypter> make_wep_decrypter_proxy(const Functor& fu
|
||||
return DecrypterProxy<Functor, WEPDecrypter>(functor);
|
||||
}
|
||||
|
||||
// RC4 stuff
|
||||
|
||||
template<typename ForwardIterator>
|
||||
RC4Key::RC4Key(ForwardIterator start, ForwardIterator end) {
|
||||
for (size_t i = 0; i < data_size; ++i) {
|
||||
data[i] = static_cast<uint8_t>(i);
|
||||
}
|
||||
size_t j = 0;
|
||||
ForwardIterator iter = start;
|
||||
for (size_t i = 0; i < data_size; ++i) {
|
||||
j = (j + data[i] + *iter++) % 256;
|
||||
if(iter == end) {
|
||||
iter = start;
|
||||
}
|
||||
std::swap(data[i], data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename OutputIterator>
|
||||
void rc4(ForwardIterator start, ForwardIterator end, RC4Key& key, OutputIterator output) {
|
||||
size_t i = 0, j = 0;
|
||||
while (start != end) {
|
||||
i = (i + 1) % RC4Key::data_size;
|
||||
j = (j + key.data[i]) % RC4Key::data_size;
|
||||
std::swap(key.data[i], key.data[j]);
|
||||
*output++ = *start++ ^ key.data[(key.data[i] + key.data[j]) % RC4Key::data_size];
|
||||
}
|
||||
}
|
||||
|
||||
} // Crypto
|
||||
} // Tins
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,9 +30,7 @@
|
||||
#ifndef TINS_CXXSTD_H
|
||||
#define TINS_CXXSTD_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tins/config.h>
|
||||
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
#define TINS_CXXSTD_GCC_FIX 1
|
||||
@@ -48,15 +46,6 @@
|
||||
|
||||
namespace Tins{
|
||||
namespace Internals {
|
||||
template<typename T>
|
||||
struct smart_ptr {
|
||||
#if TINS_IS_CXX11
|
||||
typedef std::unique_ptr<T> type;
|
||||
#else
|
||||
typedef std::auto_ptr<T> type;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class T> void unused(const T&) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,6 +41,7 @@ class Dot3;
|
||||
class SLL;
|
||||
class Loopback;
|
||||
class PPI;
|
||||
class IP;
|
||||
|
||||
/**
|
||||
* \struct DataLinkType
|
||||
@@ -73,6 +74,7 @@ TINS_MAKE_DATA_LINK_TYPE(Loopback, DLT_LOOP)
|
||||
TINS_MAKE_DATA_LINK_TYPE(PPI, DLT_PPI)
|
||||
TINS_MAKE_DATA_LINK_TYPE(Dot11, DLT_IEEE802_11)
|
||||
TINS_MAKE_DATA_LINK_TYPE(RadioTap, DLT_IEEE802_11_RADIO)
|
||||
TINS_MAKE_DATA_LINK_TYPE(IP, DLT_RAW)
|
||||
|
||||
#undef TINS_MAKE_DATA_LINK_TYPE
|
||||
|
||||
|
||||
106
include/tins/detail/address_helpers.h
Normal file
106
include/tins/detail/address_helpers.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_ADDRESS_HELPERS_H
|
||||
#define TINS_ADDRESS_HELPERS_H
|
||||
|
||||
#include <tins/hw_address.h>
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
namespace Tins {
|
||||
|
||||
class IPv4Address;
|
||||
class IPv6Address;
|
||||
|
||||
namespace Internals {
|
||||
|
||||
template<typename T>
|
||||
bool increment_buffer(T& addr) {
|
||||
typename T::iterator it = addr.end() - 1;
|
||||
while (it >= addr.begin() && *it == 0xff) {
|
||||
*it = 0;
|
||||
--it;
|
||||
}
|
||||
// reached end
|
||||
if (it < addr.begin()) {
|
||||
return true;
|
||||
}
|
||||
(*it)++;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool decrement_buffer(T& addr) {
|
||||
typename T::iterator it = addr.end() - 1;
|
||||
while (it >= addr.begin() && *it == 0) {
|
||||
*it = 0xff;
|
||||
--it;
|
||||
}
|
||||
// reached end
|
||||
if (it < addr.begin()) {
|
||||
return true;
|
||||
}
|
||||
(*it)--;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool increment(IPv4Address& addr);
|
||||
bool increment(IPv6Address& addr);
|
||||
bool decrement(IPv4Address& addr);
|
||||
bool decrement(IPv6Address& addr);
|
||||
template<size_t n>
|
||||
bool increment(HWAddress<n>& addr) {
|
||||
return increment_buffer(addr);
|
||||
}
|
||||
template<size_t n>
|
||||
bool decrement(HWAddress<n>& addr) {
|
||||
return decrement_buffer(addr);
|
||||
}
|
||||
|
||||
IPv4Address last_address_from_mask(IPv4Address addr, IPv4Address mask);
|
||||
IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask);
|
||||
template<size_t n>
|
||||
HWAddress<n> last_address_from_mask(HWAddress<n> addr, const HWAddress<n>& mask) {
|
||||
typename HWAddress<n>::iterator addr_iter = addr.begin();
|
||||
for (typename HWAddress<n>::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) {
|
||||
*addr_iter = *addr_iter | ~*it;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
|
||||
#endif // TINS_ADDRESS_HELPERS_H
|
||||
61
include/tins/detail/icmp_extension_helpers.h
Normal file
61
include/tins/detail/icmp_extension_helpers.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_ICMP_EXTENSION_HELPERS_H
|
||||
#define TINS_ICMP_EXTENSION_HELPERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
namespace Tins {
|
||||
|
||||
class PDU;
|
||||
class ICMPExtensionsStructure;
|
||||
|
||||
namespace Memory {
|
||||
class InputMemoryStream;
|
||||
} // Memory
|
||||
|
||||
namespace Internals {
|
||||
|
||||
uint32_t get_padded_icmp_inner_pdu_size(const PDU* inner_pdu, uint32_t pad_alignment);
|
||||
void try_parse_icmp_extensions(Memory::InputMemoryStream& stream, uint32_t payload_length,
|
||||
ICMPExtensionsStructure& extensions);
|
||||
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
|
||||
#endif // TINS_ICMP_EXTENSION_HELPERS_H
|
||||
70
include/tins/detail/pdu_helpers.h
Normal file
70
include/tins/detail/pdu_helpers.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_PDU_HELPERS_H
|
||||
#define TINS_PDU_HELPERS_H
|
||||
|
||||
#include <tins/constants.h>
|
||||
#include <tins/config.h>
|
||||
#include <tins/pdu.h>
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
|
||||
PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
PDU* pdu_from_dlt_flag(int flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
#endif // TINS_HAVE_PCAP
|
||||
PDU* pdu_from_flag(PDU::PDUType type, const uint8_t* buffer, uint32_t size);
|
||||
|
||||
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
|
||||
PDU::PDUType ether_type_to_pdu_flag(Constants::Ethernet::e flag);
|
||||
Constants::IP::e pdu_flag_to_ip_type(PDU::PDUType flag);
|
||||
PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag);
|
||||
|
||||
inline bool is_dot3(const uint8_t* ptr, size_t sz) {
|
||||
return (sz >= 13 && ptr[12] < 8);
|
||||
}
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
|
||||
#endif // TINS_PDU_HELPERS_H
|
||||
49
include/tins/detail/sequence_number_helpers.h
Normal file
49
include/tins/detail/sequence_number_helpers.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||
#define TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
|
||||
// Compares sequence numbers as defined by RFC 1982.
|
||||
int seq_compare(uint32_t seq1, uint32_t seq2);
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace Tins
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
|
||||
#endif // TINS_SEQUENCE_NUMBER_HELPERS_H
|
||||
51
include/tins/detail/smart_ptr.h
Normal file
51
include/tins/detail/smart_ptr.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_SMART_PTR_H
|
||||
#define TINS_SMART_PTR_H
|
||||
|
||||
#include <memory>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
|
||||
template<typename T>
|
||||
struct smart_ptr {
|
||||
#if TINS_IS_CXX11
|
||||
typedef std::unique_ptr<T> type;
|
||||
#else
|
||||
typedef std::auto_ptr<T> type;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_SMART_PTR_H
|
||||
127
include/tins/detail/type_traits.h
Normal file
127
include/tins/detail/type_traits.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_TYPE_TRAITS_H
|
||||
#define TINS_TYPE_TRAITS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#if TINS_IS_CXX11
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
|
||||
template<bool, typename T = void>
|
||||
struct enable_if {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct enable_if<false, T> {
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct type_to_type {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_unsigned_integral {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint8_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint16_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint32_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint64_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
#if TINS_IS_CXX11 && !defined(_MSC_VER)
|
||||
|
||||
// Template metaprogramming trait to determine if a functor can accept another parameter as an argument
|
||||
template <typename T, typename P, typename=void>
|
||||
struct accepts_type : std::false_type { };
|
||||
|
||||
template <typename T, typename P>
|
||||
struct accepts_type<T, P,
|
||||
typename std::enable_if<
|
||||
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
|
||||
>::type
|
||||
> : std::true_type { };
|
||||
|
||||
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||
typename std::enable_if<accepts_type<Functor, Packet>::value, bool>::type* = 0) {
|
||||
return f(std::move(p));
|
||||
}
|
||||
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||
typename std::enable_if<!accepts_type<Functor, Packet>::value && accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(p);
|
||||
}
|
||||
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p,
|
||||
typename std::enable_if<!accepts_type<Functor, Packet>::value && !accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(*p.pdu());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_TYPE_TRAITS_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,13 +30,12 @@
|
||||
#ifndef TINS_DHCP_H
|
||||
#define TINS_DHCP_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "bootp.h"
|
||||
#include "macros.h"
|
||||
#include "pdu_option.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/bootp.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -170,7 +169,7 @@ public:
|
||||
/**
|
||||
* The type used to store the DHCP options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||
@@ -436,8 +435,7 @@ public:
|
||||
* If the option is not found, an option_not_found exception
|
||||
* is thrown.
|
||||
*
|
||||
* \return std::list<ipaddress_type> Contanining the DNS servers
|
||||
* provided.
|
||||
* \return The list of DNS servers provided.
|
||||
*/
|
||||
std::vector<ipaddress_type> domain_name_servers() const;
|
||||
|
||||
@@ -509,7 +507,7 @@ public:
|
||||
private:
|
||||
static const uint32_t MAX_DHCP_SIZE;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
template <typename T>
|
||||
T search_and_convert(OptionTypes opt) const {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,13 +31,12 @@
|
||||
#define TINS_DHCPV6_H
|
||||
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include "ipv6_address.h"
|
||||
#include "pdu_option.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/ipv6_address.h>
|
||||
#include <tins/pdu_option.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -163,7 +162,7 @@ public:
|
||||
/**
|
||||
* The type used to store the DHCPv6 options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* The type used to store IP addresses.
|
||||
@@ -392,7 +391,7 @@ public:
|
||||
: id(duid_en::duid_id), data(identifier.serialize()) {}
|
||||
|
||||
duid_type(const duid_ll& identifier)
|
||||
: id(duid_en::duid_id), data(identifier.serialize()) {}
|
||||
: id(duid_ll::duid_id), data(identifier.serialize()) {}
|
||||
|
||||
static duid_type from_option(const option& opt);
|
||||
};
|
||||
@@ -890,7 +889,7 @@ public:
|
||||
return new DHCPv6(*this);
|
||||
}
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void write_option(const option& option, Memory::OutputMemoryStream& stream) const;
|
||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||
options_type::iterator search_option_iterator(OptionTypes type);
|
||||
@@ -917,54 +916,8 @@ private:
|
||||
uint32_t options_size_;
|
||||
ipaddress_type link_addr_, peer_addr_;
|
||||
options_type options_;
|
||||
};
|
||||
};
|
||||
|
||||
namespace Internals {
|
||||
|
||||
template<typename InputIterator>
|
||||
void class_option_data2option(InputIterator start,
|
||||
InputIterator end,
|
||||
std::vector<uint8_t>& buffer,
|
||||
size_t start_index = 0) {
|
||||
size_t index = start_index;
|
||||
uint16_t uint16_t_buffer;
|
||||
while (start != end) {
|
||||
buffer.resize(buffer.size() + sizeof(uint16_t) + start->size());
|
||||
uint16_t_buffer = Endian::host_to_be(static_cast<uint16_t>(start->size()));
|
||||
std::memcpy(&buffer[index], &uint16_t_buffer, sizeof(uint16_t));
|
||||
index += sizeof(uint16_t);
|
||||
std::copy(start->begin(), start->end(), buffer.begin() + index);
|
||||
index += start->size();
|
||||
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename OutputType>
|
||||
OutputType option2class_option_data(const uint8_t* ptr, uint32_t total_sz) {
|
||||
typedef typename OutputType::value_type value_type;
|
||||
OutputType output;
|
||||
size_t index = 0;
|
||||
while (index + 2 < total_sz) {
|
||||
uint16_t size;
|
||||
std::memcpy(&size, ptr + index, sizeof(uint16_t));
|
||||
size = Endian::be_to_host(size);
|
||||
index += sizeof(uint16_t);
|
||||
if (index + size > total_sz) {
|
||||
throw option_not_found();
|
||||
}
|
||||
output.push_back(
|
||||
value_type(ptr + index, ptr + index + size)
|
||||
);
|
||||
index += size;
|
||||
}
|
||||
if (index != total_sz) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
} // Internals
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_DHCPV6_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,14 +31,13 @@
|
||||
#define TINS_DNS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
// Undefining some macros that conflict with some symbols here.
|
||||
// Eventually, the conflicting names will be removed, but until then
|
||||
@@ -184,8 +183,13 @@ public:
|
||||
* \param tp The query type.
|
||||
* \param cl The query class.
|
||||
*/
|
||||
#if TINS_IS_CXX11
|
||||
query(std::string nm, QueryType tp, QueryClass cl)
|
||||
: name_(std::move(nm)), type_(tp), qclass_(cl) {}
|
||||
#else
|
||||
query(const std::string& nm, QueryType tp, QueryClass cl)
|
||||
: name_(nm), type_(tp), qclass_(cl) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Default constructs this Query.
|
||||
@@ -449,6 +453,16 @@ public:
|
||||
* \param rclass The class of this record.
|
||||
* \param ttl The time-to-live of this record.
|
||||
*/
|
||||
#if TINS_IS_CXX11
|
||||
resource(std::string dname,
|
||||
std::string data,
|
||||
uint16_t type,
|
||||
uint16_t rclass,
|
||||
uint32_t ttl,
|
||||
uint16_t preference = 0)
|
||||
: dname_(std::move(dname)), data_(std::move(data)), type_(type),
|
||||
qclass_(rclass), ttl_(ttl), preference_(preference) {}
|
||||
#else
|
||||
resource(const std::string& dname,
|
||||
const std::string& data,
|
||||
uint16_t type,
|
||||
@@ -457,6 +471,7 @@ public:
|
||||
uint16_t preference = 0)
|
||||
: dname_(dname), data_(data), type_(type), qclass_(rclass),
|
||||
ttl_(ttl), preference_(preference) {}
|
||||
#endif
|
||||
|
||||
resource() : type_(), qclass_(), ttl_(), preference_() {}
|
||||
|
||||
@@ -602,8 +617,8 @@ public:
|
||||
TINS_DEPRECATED(typedef query Query);
|
||||
TINS_DEPRECATED(typedef resource Resource);
|
||||
|
||||
typedef std::list<query> queries_type;
|
||||
typedef std::list<resource> resources_type;
|
||||
typedef std::vector<query> queries_type;
|
||||
typedef std::vector<resource> resources_type;
|
||||
typedef IPv4Address address_type;
|
||||
typedef IPv6Address address_v6_type;
|
||||
|
||||
@@ -637,7 +652,7 @@ public:
|
||||
// Getters
|
||||
|
||||
/**
|
||||
* \brief Setter for the id field.
|
||||
* \brief Getter for the id field.
|
||||
*
|
||||
* \return uint16_t containing the value of the id field.
|
||||
*/
|
||||
@@ -646,7 +661,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the query response field.
|
||||
* \brief Getter for the query response field.
|
||||
*
|
||||
* \return QRType containing the value of the query response
|
||||
* field.
|
||||
@@ -656,7 +671,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the opcode field.
|
||||
* \brief Getter for the opcode field.
|
||||
*
|
||||
* \return uint8_t containing the value of the opcode field.
|
||||
*/
|
||||
@@ -665,7 +680,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the authoritative answer field.
|
||||
* \brief Getter for the authoritative answer field.
|
||||
*
|
||||
* \return uint8_t containing the value of the authoritative
|
||||
* answer field.
|
||||
@@ -675,7 +690,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the truncated field.
|
||||
* \brief Getter for the truncated field.
|
||||
*
|
||||
* \return uint8_t containing the value of the truncated field.
|
||||
*/
|
||||
@@ -684,7 +699,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the recursion desired field.
|
||||
* \brief Getter for the recursion desired field.
|
||||
*
|
||||
* \return uint8_t containing the value of the recursion
|
||||
* desired field.
|
||||
@@ -694,7 +709,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the recursion available field.
|
||||
* \brief Getter for the recursion available field.
|
||||
*
|
||||
* \return uint8_t containing the value of the recursion
|
||||
* available field.
|
||||
@@ -704,7 +719,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the z desired field.
|
||||
* \brief Getter for the z desired field.
|
||||
*
|
||||
* \return uint8_t containing the value of the z field.
|
||||
*/
|
||||
@@ -713,7 +728,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the authenticated data field.
|
||||
* \brief Getter for the authenticated data field.
|
||||
*
|
||||
* \return uint8_t containing the value of the authenticated
|
||||
* data field.
|
||||
@@ -723,7 +738,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the checking disabled field.
|
||||
* \brief Getter for the checking disabled field.
|
||||
*
|
||||
* \return uint8_t containing the value of the checking
|
||||
* disabled field.
|
||||
@@ -733,7 +748,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the rcode field.
|
||||
* \brief Getter for the rcode field.
|
||||
*
|
||||
* \return uint8_t containing the value of the rcode field.
|
||||
*/
|
||||
@@ -742,7 +757,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the questions field.
|
||||
* \brief Getter for the questions field.
|
||||
*
|
||||
* \return uint16_t containing the value of the questions field.
|
||||
*/
|
||||
@@ -751,7 +766,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the answers field.
|
||||
* \brief Getter for the answers field.
|
||||
*
|
||||
* \return uint16_t containing the value of the answers field.
|
||||
*/
|
||||
@@ -760,7 +775,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the authority field.
|
||||
* \brief Getter for the authority field.
|
||||
*
|
||||
* \return uint16_t containing the value of the authority field.
|
||||
*/
|
||||
@@ -769,7 +784,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Setter for the additional field.
|
||||
* \brief Getter for the additional field.
|
||||
*
|
||||
* \return uint16_t containing the value of the additional field.
|
||||
*/
|
||||
@@ -1019,7 +1034,8 @@ private:
|
||||
uint32_t compose_name(const uint8_t* ptr, char* out_ptr) const;
|
||||
void convert_records(const uint8_t* ptr,
|
||||
const uint8_t* end,
|
||||
resources_type& res) const;
|
||||
resources_type& res,
|
||||
const uint16_t rr_count) const;
|
||||
void skip_to_section_end(Memory::InputMemoryStream& stream,
|
||||
const uint32_t num_records) const;
|
||||
void skip_to_dname_end(Memory::InputMemoryStream& stream) const;
|
||||
@@ -1030,7 +1046,7 @@ private:
|
||||
uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
|
||||
static void inline_convert_v4(uint32_t value, char* output);
|
||||
static bool contains_dname(uint16_t type);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void add_record(const resource& resource, const sections_type& sections);
|
||||
|
||||
dns_header header_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,18 +27,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT_11) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT_11
|
||||
|
||||
#include "dot11/dot11_base.h"
|
||||
#include "dot11/dot11_data.h"
|
||||
#include "dot11/dot11_mgmt.h"
|
||||
#include "dot11/dot11_beacon.h"
|
||||
#include "dot11/dot11_assoc.h"
|
||||
#include "dot11/dot11_auth.h"
|
||||
#include "dot11/dot11_probe.h"
|
||||
#include "dot11/dot11_control.h"
|
||||
#include <tins/dot11/dot11_base.h>
|
||||
#include <tins/dot11/dot11_data.h>
|
||||
#include <tins/dot11/dot11_mgmt.h>
|
||||
#include <tins/dot11/dot11_beacon.h>
|
||||
#include <tins/dot11/dot11_assoc.h>
|
||||
#include <tins/dot11/dot11_auth.h>
|
||||
#include <tins/dot11/dot11_probe.h>
|
||||
#include <tins/dot11/dot11_control.h>
|
||||
|
||||
#endif // TINS_DOT_11
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
FILE(GLOB INCLUDE_FILES "*.h")
|
||||
INSTALL(
|
||||
FILES ${INCLUDE_FILES}
|
||||
DESTINATION include/tins/dot11
|
||||
COMPONENT Headers
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,13 +27,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_ASSOC_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT11_DOT11_ASSOC_H
|
||||
|
||||
#include "../dot11/dot11_mgmt.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_mgmt.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,13 +27,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_AUTH_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT11_DOT11_AUTH_H
|
||||
|
||||
#include "../dot11/dot11_mgmt.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_mgmt.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,19 +27,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT11_DOT11_H
|
||||
|
||||
#include <list>
|
||||
#include "../pdu.h"
|
||||
#include "../pdu_option.h"
|
||||
#include "../small_uint.h"
|
||||
#include "../hw_address.h"
|
||||
#include "../endianness.h"
|
||||
#include "../cxxstd.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -67,7 +66,7 @@ public:
|
||||
/**
|
||||
* The type used to store tagged options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* \brief This PDU's flag.
|
||||
@@ -128,9 +127,148 @@ public:
|
||||
ERP_INFORMATION,
|
||||
TS_DELAY,
|
||||
TCLAS_PROCESSING,
|
||||
QOS_CAPABILITY = 46,
|
||||
HT_CAPABILITY,
|
||||
QOS_CAPABILITY,
|
||||
RSN = 48,
|
||||
EXT_SUPPORTED_RATES = 50,
|
||||
AP_CHANNEL_REPORT,
|
||||
NEIGHBOR_REPORT,
|
||||
RCPI,
|
||||
MOBILITY_DOMAIN_MDE,
|
||||
FAST_BSS_TRANSITION_FTE,
|
||||
TIMEOUT_INTERVAL,
|
||||
RIC_DATA_RDE,
|
||||
DSE_REG_LOC,
|
||||
SUPPORTED_OP_CLASSES,
|
||||
EXT_CH_SWITCH_ANNOUNCEMENT,
|
||||
HT_OPERATION,
|
||||
SEC_CH_OFFSET,
|
||||
BSS_AVG_ACCESS_DELAY,
|
||||
ANTENNA,
|
||||
RSNI,
|
||||
MEASUREMENT_PILOT_TRANSMISSION,
|
||||
BSS_AVAIL_ADMISSION_CAPACITY,
|
||||
BSS_AC_ACCESS_DELAY,
|
||||
TIME_ADVERTISEMENT,
|
||||
RM_ENABLED_CAP,
|
||||
MULTIPLE_BSSID,
|
||||
BSS_2040_COEX,
|
||||
BSS_2040_INTOLERANT_CH_REPORT,
|
||||
OVERLAPPING_BSS_SCAN_PARAM,
|
||||
RIC_DESCRIPTOR,
|
||||
MGMT_MIC,
|
||||
EVENT_REQ = 78,
|
||||
EVENT_REPORT,
|
||||
DIAG_REQ,
|
||||
DIAG_REPORT,
|
||||
LOCATION_PARAMS,
|
||||
NONTRANSMITTED_BSSID_CAP,
|
||||
SSID_LIST,
|
||||
MULTIPLE_BSSID_INDEX,
|
||||
FMS_DESCRIPTOR,
|
||||
FMS_REQ,
|
||||
FMS_RESP,
|
||||
QOS_TRAFFIC_CAP,
|
||||
BSS_MAX_IDLE_PERIOD,
|
||||
TFS_REQ,
|
||||
TFS_RESP,
|
||||
WNM_SLEEP_MODE,
|
||||
TIM_BROADCAST_REQ,
|
||||
TIM_BROADCAST_RESP,
|
||||
COLLOCATED_INTERFERENCE_REPORT,
|
||||
CH_USAGE,
|
||||
TIME_ZONE,
|
||||
DMS_REQ,
|
||||
DMS_RESP,
|
||||
LINK_ID,
|
||||
WAKEUP_SCHEDULE,
|
||||
CH_SWITCH_TIMING,
|
||||
PTI_CONTROL,
|
||||
TPU_BUFFER_STATUS,
|
||||
INTERWORKING,
|
||||
ADVERTISEMENT_PROTOCOL,
|
||||
EXPEDITED_BANDWIDTH_REQ,
|
||||
QOS_MAP,
|
||||
ROAMING_CONSORTIUM,
|
||||
EMERG_ALERT_ID,
|
||||
MESH_CONFIG,
|
||||
MESH_ID,
|
||||
MESH_LINK_METRIC_REPORT,
|
||||
CONGESTION_NOTIFICATION,
|
||||
MESH_PEERING_MGMT,
|
||||
MESH_CH_SWITCH_PARAMS,
|
||||
MESH_AWAKE_WINDOW,
|
||||
BEACON_TIMING,
|
||||
MCCAOP_SETUP_REQ,
|
||||
MCCAOP_SETUP_REPLY,
|
||||
MCCAOP_ADVERTISEMENT,
|
||||
MCCAOP_TEARDOWN,
|
||||
GANN,
|
||||
RANN,
|
||||
EXT_CAP,
|
||||
PREQ = 130,
|
||||
PREP,
|
||||
PERR,
|
||||
PXU = 137,
|
||||
PXUC,
|
||||
AUTH_MESH_PEER_EX,
|
||||
MIC,
|
||||
DEST_URI,
|
||||
UAPSD_COEX,
|
||||
DMG_WAKEUP_SCHEDULE,
|
||||
EXT_SCHEDULE,
|
||||
STA_AVAIL,
|
||||
DMG_TSPEC,
|
||||
NEXT_DMG_ATI,
|
||||
DMG_CAP,
|
||||
DMG_OP = 151,
|
||||
DMG_BSS_PARAM_CHG,
|
||||
DMG_BEAM_REFINEMENT,
|
||||
CH_MEASUREMENT_FEEDBACK,
|
||||
AWAKE_WINDOW = 157,
|
||||
MULTIBAND,
|
||||
ADDBA_ESXT,
|
||||
NEXTPCP_LIST,
|
||||
PCP_HANDOVER,
|
||||
DMG_LINK_MARGIN,
|
||||
SWITCHING_STREAM,
|
||||
SESSION_TRANSITION,
|
||||
DYNAMIC_TONE_PAIRING_REPORT,
|
||||
CLUSTER_REPORT,
|
||||
RELAY_CAP,
|
||||
RELAY_TRANSFER_PARAM_SET,
|
||||
BEAMLINK_MAINTENANCE,
|
||||
MULTIPLE_MAC_SUBLAYERS,
|
||||
UPID,
|
||||
DMG_LINK_ADAPTATION_ACK,
|
||||
MCCAOP_ADV_OVERVIEW = 174,
|
||||
QUIET_PERIOD_REQ,
|
||||
QUIET_PERIOD_RESP = 177,
|
||||
QMF_POLICY = 181,
|
||||
ECAPC_POLICY = 182,
|
||||
CLUSTER_TIME_OFFSET,
|
||||
INTRA_ACCESS_CAT_PRIORITY,
|
||||
SCS_DESCRIPTOR,
|
||||
QLOAD_REPORT,
|
||||
HCCA_TXOP_UPDATE_COUNT,
|
||||
HIGHER_LAYER_STREAM_ID,
|
||||
GCR_GROUP_ADDR,
|
||||
ANTENNA_SECTOR_ID_PATTERN,
|
||||
VHT_CAP,
|
||||
VHT_OP,
|
||||
EXT_BSS_LOAD,
|
||||
WIDE_BANDWIDTH_CH_SWITCH,
|
||||
TRANSMIT_POWER_ENVELOPE,
|
||||
CH_SWITCH_WRAPPER,
|
||||
AID,
|
||||
QUIET_CHANNEL,
|
||||
OP_MODE_NOTIFY,
|
||||
UPSIM,
|
||||
REDUCED_NEIGHBOR_REPORT,
|
||||
TVHT_OP,
|
||||
DEV_LOC = 204,
|
||||
WHITE_SPACE_MAP,
|
||||
FINE_TUNING_MEASUREMENT_PARAMS,
|
||||
VENDOR_SPECIFIC = 221
|
||||
};
|
||||
|
||||
@@ -280,6 +418,15 @@ public:
|
||||
return header_.control.power_mgmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the More Data field.
|
||||
*
|
||||
* \return The stored More Data field.
|
||||
*/
|
||||
small_uint<1> more_data() const {
|
||||
return header_.control.more_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the WEP field.
|
||||
*
|
||||
@@ -374,6 +521,13 @@ public:
|
||||
*/
|
||||
void power_mgmt(small_uint<1> new_value);
|
||||
|
||||
/**
|
||||
* \brief Setter for the More Data field.
|
||||
*
|
||||
* \param new_value The new More Data field value.
|
||||
*/
|
||||
void more_data(small_uint<1> new_value);
|
||||
|
||||
/**
|
||||
* \brief Setter for the WEP field.
|
||||
*
|
||||
@@ -554,7 +708,7 @@ private:
|
||||
Dot11(const dot11_header* header_ptr);
|
||||
|
||||
void internal_add_option(const option& opt);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||
options_type::iterator search_option_iterator(OptionTypes type);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,13 +27,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_BEACON_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT11_DOT11_BEACON_H
|
||||
|
||||
#include "../dot11/dot11_mgmt.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_mgmt.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -27,14 +27,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_CONTROL_H) && defined(TINS_HAVE_DOT11)
|
||||
|
||||
#define TINS_DOT11_DOT11_CONTROL_H
|
||||
|
||||
#include "../dot11/dot11_base.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_base.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
@@ -46,11 +46,11 @@ public:
|
||||
* \brief This PDU's flag.
|
||||
*/
|
||||
static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 control frame PDU
|
||||
*
|
||||
* Constructs a 802.11 Control PDU taking the destination and
|
||||
* Constructs a 802.11 Control PDU taking the destination and
|
||||
* source hardware addresses.
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
@@ -59,15 +59,15 @@ public:
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11Control object from a buffer and
|
||||
* adds all identifiable PDUs found in the buffer as children
|
||||
* adds all identifiable PDUs found in the buffer as children
|
||||
* of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -97,6 +97,11 @@ public:
|
||||
*/
|
||||
class TINS_API Dot11ControlTA : public Dot11Control {
|
||||
public:
|
||||
/**
|
||||
* \brief This PDU's flag.
|
||||
*/
|
||||
static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL_TA;
|
||||
|
||||
/**
|
||||
* \brief Getter for the target address field.
|
||||
*/
|
||||
@@ -109,30 +114,39 @@ public:
|
||||
* \param addr The new target address.
|
||||
*/
|
||||
void target_addr(const address_type& addr);
|
||||
|
||||
/**
|
||||
* \brief Check whether this PDU matches the specified flag.
|
||||
* \param flag The flag to match
|
||||
* \sa PDU::matches_flag
|
||||
*/
|
||||
bool matches_flag(PDUType flag) const {
|
||||
return flag == pdu_flag || Dot11::matches_flag(flag);
|
||||
}
|
||||
protected:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 control frame TA PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11ControlTA(const address_type& dst_addr = address_type(),
|
||||
Dot11ControlTA(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11ControlTA object from a buffer and
|
||||
* adds all identifiable PDUs found in the buffer as children
|
||||
* adds all identifiable PDUs found in the buffer as children
|
||||
* of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -149,8 +163,8 @@ protected:
|
||||
/**
|
||||
* \brief Getter for the control ta additional fields size.
|
||||
*/
|
||||
uint32_t controlta_size() const {
|
||||
return static_cast<uint32_t>(taddr_.size() + sizeof(dot11_header));
|
||||
uint32_t controlta_size() const {
|
||||
return static_cast<uint32_t>(taddr_.size() + sizeof(dot11_header));
|
||||
}
|
||||
|
||||
void write_ext_header(Memory::OutputMemoryStream& stream);
|
||||
@@ -178,19 +192,19 @@ public:
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11RTS(const address_type& dst_addr = address_type(),
|
||||
Dot11RTS(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11RTS object from a buffer and adds all
|
||||
* \brief Constructs a Dot11RTS object from a buffer and adds all
|
||||
* identifiable PDUs found in the buffer as children of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -233,26 +247,26 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 PS-Poll frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11PSPoll(const address_type& dst_addr = address_type(),
|
||||
Dot11PSPoll(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11PSPoll object from a buffer and
|
||||
* adds all identifiable PDUs found in the buffer as children of
|
||||
* adds all identifiable PDUs found in the buffer as children of
|
||||
* this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -295,26 +309,26 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 CF-End frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11CFEnd(const address_type& dst_addr = address_type(),
|
||||
Dot11CFEnd(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11CFEnd object from a buffer and adds
|
||||
* all identifiable PDUs found in the buffer as children of this
|
||||
* \brief Constructs a Dot11CFEnd object from a buffer and adds
|
||||
* all identifiable PDUs found in the buffer as children of this
|
||||
* one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -357,26 +371,26 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 End-CF-Ack frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11EndCFAck(const address_type& dst_addr = address_type(),
|
||||
Dot11EndCFAck(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11EndCFAck frame object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* \brief Constructs a Dot11EndCFAck frame object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -419,7 +433,7 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 Ack frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
@@ -428,15 +442,15 @@ public:
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11Ack frame object from a buffer and
|
||||
* adds all identifiable PDUs found in the buffer as children of
|
||||
* adds all identifiable PDUs found in the buffer as children of
|
||||
* this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -482,26 +496,26 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 Block Ack request frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11BlockAckRequest(const address_type& dst_addr = address_type(),
|
||||
Dot11BlockAckRequest(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11BlockAckRequest object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* \brief Constructs a Dot11BlockAckRequest object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -513,11 +527,11 @@ public:
|
||||
* \brief Getter for the bar control field.
|
||||
* \return The stored bar control field.
|
||||
*/
|
||||
small_uint<4> bar_control() const {
|
||||
small_uint<4> bar_control() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return bar_control_ & 0xf;
|
||||
return bar_control_ & 0xf;
|
||||
#else
|
||||
return (bar_control_ >> 8) & 0xf;
|
||||
return (bar_control_ >> 8) & 0xf;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -525,26 +539,26 @@ public:
|
||||
* \brief Getter for the start sequence field.
|
||||
* \return The stored start sequence.
|
||||
*/
|
||||
small_uint<12> start_sequence() const {
|
||||
small_uint<12> start_sequence() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return (start_sequence_ >> 4) & 0xfff;
|
||||
return (start_sequence_ >> 4) & 0xfff;
|
||||
#else
|
||||
return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
|
||||
return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Getter for the fragment number field.
|
||||
* \return The stored fragment number field.
|
||||
*/
|
||||
small_uint<4> fragment_number() const {
|
||||
small_uint<4> fragment_number() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return start_sequence_ & 0xf;
|
||||
return start_sequence_ & 0xf;
|
||||
#else
|
||||
return (start_sequence_ >> 8) & 0xf;
|
||||
return (start_sequence_ >> 8) & 0xf;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Returns the 802.11 frame's header length.
|
||||
*
|
||||
@@ -566,7 +580,7 @@ public:
|
||||
* \param bar The start sequence field to be set.
|
||||
*/
|
||||
void start_sequence(small_uint<12> seq);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Setter for the fragment number field.
|
||||
* \param frag The fragment number field to be set.
|
||||
@@ -614,7 +628,7 @@ public:
|
||||
* \brief This PDU's flag.
|
||||
*/
|
||||
static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK;
|
||||
|
||||
|
||||
/**
|
||||
* The size of the bitmap field.
|
||||
*/
|
||||
@@ -623,26 +637,26 @@ public:
|
||||
/**
|
||||
* \brief Constructor for creating a 802.11 Block Ack frame PDU
|
||||
*
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* Constructs a 802.11 PDU taking the destination and source
|
||||
* hardware addresses.
|
||||
*
|
||||
*
|
||||
* \param dst_addr The destination hardware address.
|
||||
* \param target_addr The source hardware address.
|
||||
*/
|
||||
Dot11BlockAck(const address_type& dst_addr = address_type(),
|
||||
Dot11BlockAck(const address_type& dst_addr = address_type(),
|
||||
const address_type& target_addr = address_type());
|
||||
|
||||
/**
|
||||
* \brief Constructs a Dot11BlockAck frame object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* \brief Constructs a Dot11BlockAck frame object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as children
|
||||
* of this one.
|
||||
*
|
||||
*
|
||||
* If the next PDU is not recognized, then a RawPDU is used.
|
||||
*
|
||||
*
|
||||
* If there is not enough size for the header in the buffer
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* or the input data is malformed, a malformed_packet exception
|
||||
* is thrown.
|
||||
*
|
||||
*
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
@@ -654,11 +668,11 @@ public:
|
||||
* \brief Getter for the bar control field.
|
||||
* \return The stored bar control field.
|
||||
*/
|
||||
small_uint<4> bar_control() const {
|
||||
small_uint<4> bar_control() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return bar_control_ & 0xf;
|
||||
return bar_control_ & 0xf;
|
||||
#else
|
||||
return (bar_control_ >> 8) & 0xf;
|
||||
return (bar_control_ >> 8) & 0xf;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -666,26 +680,26 @@ public:
|
||||
* \brief Getter for the start sequence field.
|
||||
* \return The stored start sequence.
|
||||
*/
|
||||
small_uint<12> start_sequence() const {
|
||||
small_uint<12> start_sequence() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return (start_sequence_ >> 4) & 0xfff;
|
||||
return (start_sequence_ >> 4) & 0xfff;
|
||||
#else
|
||||
return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
|
||||
return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Getter for the fragment number field.
|
||||
* \return The stored fragment number field.
|
||||
*/
|
||||
small_uint<4> fragment_number() const {
|
||||
small_uint<4> fragment_number() const {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
return start_sequence_ & 0xf;
|
||||
return start_sequence_ & 0xf;
|
||||
#else
|
||||
return (start_sequence_ >> 8) & 0xf;
|
||||
return (start_sequence_ >> 8) & 0xf;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Returns the 802.11 frame's header length.
|
||||
*
|
||||
@@ -707,7 +721,7 @@ public:
|
||||
* \param bar The start sequence field to be set.
|
||||
*/
|
||||
void start_sequence(small_uint<12> seq);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Setter for the fragment number field.
|
||||
* \param frag The fragment number field to be set.
|
||||
@@ -716,9 +730,9 @@ public:
|
||||
|
||||
/**
|
||||
* \brief Getter for the bitmap field.
|
||||
*
|
||||
*
|
||||
* The returned pointer <b>must not</b> be free'd.
|
||||
*
|
||||
*
|
||||
* \return The bitmap field.
|
||||
*/
|
||||
const uint8_t* bitmap() const {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,13 +27,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_DATA_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_DOT11_DOT11_DATA_H
|
||||
|
||||
#include "../dot11/dot11_base.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_base.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,7 +27,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_MGMT_H) && defined(TINS_HAVE_DOT11)
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include "../dot11/dot11_base.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_base.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,14 +27,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_DOT11_DOT11_PROBE_H) && defined(TINS_HAVE_DOT11)
|
||||
|
||||
#define TINS_DOT11_DOT11_PROBE_H
|
||||
|
||||
#include "../dot11/dot11_mgmt.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/dot11/dot11_mgmt.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,10 +30,10 @@
|
||||
#ifndef TINS_DOT1Q_H
|
||||
#define TINS_DOT1Q_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -197,7 +197,7 @@ public:
|
||||
*/
|
||||
bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
TINS_BEGIN_PACK
|
||||
struct dot1q_header {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,11 +31,11 @@
|
||||
#define TINS_DOT3_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "config.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/config.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/hw_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -199,7 +199,7 @@ private:
|
||||
uint16_t length;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
dot3_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,10 +31,10 @@
|
||||
#define TINS_EAPOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "small_uint.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -185,13 +185,7 @@ protected:
|
||||
*/
|
||||
virtual void write_body(Memory::OutputMemoryStream& stream) = 0;
|
||||
private:
|
||||
/**
|
||||
* \brief Serialices this EAPOL PDU.
|
||||
* \param buffer The buffer in which the PDU will be serialized.
|
||||
* \param total_sz The size available in the buffer.
|
||||
* \param parent The PDU that's one level below this one on the stack.
|
||||
*/
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
eapol_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
#define TINS_ENDIANNESS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include <tins/macros.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,11 +31,11 @@
|
||||
#define TINS_ETHERNET_II_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "config.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/config.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/hw_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -208,7 +208,7 @@ private:
|
||||
uint16_t payload_type;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
ethernet_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -64,8 +64,26 @@ public:
|
||||
class malformed_packet : public exception_base {
|
||||
public:
|
||||
malformed_packet() : exception_base("Malformed packet") { }
|
||||
malformed_packet(const std::string& message) : exception_base(message) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when a DNS decompression pointer is out of bounds.
|
||||
*/
|
||||
class dns_decompression_pointer_out_of_bounds : public malformed_packet {
|
||||
public:
|
||||
dns_decompression_pointer_out_of_bounds() : malformed_packet("DNS decompression: pointer out of bounds") { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when a DNS decompression pointer loops.
|
||||
*/
|
||||
class dns_decompression_pointer_loops : public malformed_packet {
|
||||
public:
|
||||
dns_decompression_pointer_loops() : malformed_packet("DNS decompression: pointer loops") { }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when serializing a packet fails.
|
||||
*/
|
||||
@@ -100,6 +118,14 @@ public:
|
||||
invalid_address() : exception_base("Invalid address") { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when a PDU option is set using an incorrect value
|
||||
*/
|
||||
class invalid_option_value : public exception_base {
|
||||
public:
|
||||
invalid_option_value() : exception_base("Invalid option value") { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when a field is not present in frame.
|
||||
*/
|
||||
@@ -120,7 +146,7 @@ public:
|
||||
/**
|
||||
* \brief Exception thrown when PacketSender fails to close a socket.
|
||||
*/
|
||||
class socket_close_error : exception_base {
|
||||
class socket_close_error : public exception_base {
|
||||
public:
|
||||
socket_close_error(const std::string& msg)
|
||||
: exception_base(msg) { }
|
||||
@@ -196,6 +222,15 @@ public:
|
||||
option_payload_too_large() : exception_base("Option payload too large") { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Exception thrown when an IPv6 extension header is being
|
||||
* created from invalid data
|
||||
*/
|
||||
class invalid_ipv6_extension_header : public exception_base {
|
||||
public:
|
||||
invalid_ipv6_extension_header() : exception_base("Invalid IPv6 extension header") { }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Generic pcap error
|
||||
*/
|
||||
@@ -204,6 +239,10 @@ public:
|
||||
pcap_error(const char* message) : exception_base(message) {
|
||||
|
||||
}
|
||||
|
||||
pcap_error(const std::string& message) : exception_base(message) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,7 +27,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_HANDSHAKE_CAPTURER_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_HANDSHAKE_CAPTURER_H
|
||||
@@ -35,9 +35,9 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include "hw_address.h"
|
||||
#include "macros.h"
|
||||
#include "eapol.h"
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/eapol.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,15 +31,41 @@
|
||||
#define TINS_HWADDRESS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "cxxstd.h"
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
#if TINS_IS_CXX11
|
||||
// std::hash
|
||||
#include <memory>
|
||||
#endif // TINS_IS_CXX11
|
||||
|
||||
namespace Tins {
|
||||
namespace Internals {
|
||||
|
||||
// Defined in hw_address.cpp
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
TINS_API std::string hw_address_to_string(const uint8_t* ptr, size_t count);
|
||||
|
||||
TINS_API void string_to_hw_address(const std::string& hw_addr, uint8_t* output,
|
||||
size_t output_size);
|
||||
|
||||
TINS_API bool hw_address_equal_compare(const uint8_t* start1, const uint8_t* end1,
|
||||
const uint8_t* start2);
|
||||
|
||||
TINS_API bool hw_address_lt_compare(const uint8_t* start1, const uint8_t* end1,
|
||||
const uint8_t* start2, const uint8_t* end2);
|
||||
|
||||
TINS_API bool hw_address_gt_compare(const uint8_t* start1, const uint8_t* end1,
|
||||
const uint8_t* start2, const uint8_t* end2);
|
||||
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
} // Internals
|
||||
|
||||
/**
|
||||
* \class HWAddress
|
||||
@@ -61,15 +87,13 @@ namespace Tins {
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
template<size_t n, typename Storage = uint8_t>
|
||||
template<size_t n>
|
||||
class HWAddress {
|
||||
public:
|
||||
/**
|
||||
* \brief The type of the elements stored in the hardware address.
|
||||
*
|
||||
* This is the same as the template parameter Storage.
|
||||
*/
|
||||
typedef Storage storage_type;
|
||||
typedef uint8_t storage_type;
|
||||
|
||||
/**
|
||||
* \brief The random access iterator type.
|
||||
@@ -90,7 +114,7 @@ public:
|
||||
/**
|
||||
* \brief The broadcast address.
|
||||
*/
|
||||
static const HWAddress<n, Storage> broadcast;
|
||||
static const HWAddress<n> broadcast;
|
||||
|
||||
/**
|
||||
* \brief Constructor from a const storage_type*.
|
||||
@@ -109,10 +133,10 @@ public:
|
||||
*/
|
||||
HWAddress(const storage_type* ptr = 0) {
|
||||
if (ptr) {
|
||||
std::copy(ptr, ptr + address_size, buffer_);
|
||||
std::memcpy(buffer_, ptr, address_size);
|
||||
}
|
||||
else {
|
||||
std::fill(begin(), end(), storage_type());
|
||||
std::memset(buffer_, 0, address_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +152,7 @@ public:
|
||||
* \param address The hex-notation address to be parsed.
|
||||
*/
|
||||
HWAddress(const std::string& address) {
|
||||
convert(address, buffer_);
|
||||
Internals::string_to_hw_address(address, buffer_, n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +170,7 @@ public:
|
||||
*/
|
||||
template<size_t i>
|
||||
HWAddress(const char (&address)[i]) {
|
||||
convert(address, buffer_);
|
||||
Internals::string_to_hw_address(address, buffer_, n);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,18 +187,15 @@ public:
|
||||
*/
|
||||
template<size_t i>
|
||||
HWAddress(const HWAddress<i>& rhs) {
|
||||
// Fill extra bytes
|
||||
std::fill(
|
||||
// Copy as most as we can
|
||||
std::copy(
|
||||
rhs.begin(),
|
||||
rhs.begin() + std::min(i, n),
|
||||
begin()
|
||||
),
|
||||
end(),
|
||||
0
|
||||
);
|
||||
|
||||
size_t copy_threshold = i < n ? i : n;
|
||||
for (size_t index = 0; index < n; ++index) {
|
||||
if (index < copy_threshold) {
|
||||
buffer_[index] = rhs[index];
|
||||
}
|
||||
else {
|
||||
buffer_[index] = storage_type();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +246,7 @@ public:
|
||||
* \return bool indicating whether addresses are equal.
|
||||
*/
|
||||
bool operator==(const HWAddress& rhs) const {
|
||||
return std::equal(begin(), end(), rhs.begin());
|
||||
return Internals::hw_address_equal_compare(begin(), end(), rhs.begin());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +268,40 @@ public:
|
||||
* \return bool indicating whether this address is less-than rhs.
|
||||
*/
|
||||
bool operator<(const HWAddress& rhs) const {
|
||||
return std::lexicographical_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||
return Internals::hw_address_lt_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this HWAddress for less-than equality.
|
||||
*
|
||||
* \param rhs The HWAddress to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or less-than rhs.
|
||||
*/
|
||||
bool operator<=(const HWAddress& rhs) const {
|
||||
return !operator>(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this HWAddress for greater-than inequality.
|
||||
*
|
||||
* \param rhs The HWAddress to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is greater-than rhs.
|
||||
*/
|
||||
bool operator>(const HWAddress& rhs) const {
|
||||
return Internals::hw_address_gt_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this HWAddress for greater-than equality.
|
||||
*
|
||||
* \param rhs The HWAddress to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or greater-than rhs.
|
||||
*/
|
||||
bool operator>=(const HWAddress& rhs) const {
|
||||
return !operator<(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,7 +317,33 @@ public:
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Apply a mask to this address
|
||||
*
|
||||
* \param mask The mask to be applied
|
||||
* \return The result of applying the mask to this address
|
||||
*/
|
||||
HWAddress operator|(const HWAddress& mask) const {
|
||||
HWAddress<n> output = *this;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
output[i] = output[i] | mask[i];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief not operator
|
||||
* \return The result of applying the mask to this address
|
||||
*/
|
||||
HWAddress operator~() const {
|
||||
HWAddress<n> output = *this;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
output[i] = ~output[i];
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieves the size of this address.
|
||||
*
|
||||
@@ -300,9 +380,7 @@ public:
|
||||
* \return std::string containing the hex-notation address.
|
||||
*/
|
||||
std::string to_string() const {
|
||||
std::ostringstream oss;
|
||||
oss <<* this;
|
||||
return oss.str();
|
||||
return Internals::hw_address_to_string(buffer_, size());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,13 +409,7 @@ public:
|
||||
* \return std::ostream& pointing to the os parameter.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const HWAddress& addr) {
|
||||
std::transform(
|
||||
addr.begin(),
|
||||
addr.end() - 1,
|
||||
std::ostream_iterator<std::string>(os, ":"),
|
||||
&HWAddress::storage_to_string
|
||||
);
|
||||
return os << storage_to_string(addr.begin()[HWAddress::address_size - 1]);
|
||||
return os << addr.to_string();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,9 +435,6 @@ public:
|
||||
return output;
|
||||
}
|
||||
private:
|
||||
template<typename OutputIterator>
|
||||
static void convert(const std::string& hw_addr, OutputIterator output);
|
||||
|
||||
static HWAddress<n> make_broadcast_address() {
|
||||
// Build a buffer made of n 0xff bytes
|
||||
uint8_t buffer[n];
|
||||
@@ -375,65 +444,11 @@ private:
|
||||
return HWAddress<n>(buffer);
|
||||
}
|
||||
|
||||
static std::string storage_to_string(storage_type element) {
|
||||
std::ostringstream oss;
|
||||
oss << std::hex;
|
||||
if (element < 0x10) {
|
||||
oss << '0';
|
||||
}
|
||||
oss << (unsigned)element;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
storage_type buffer_[n];
|
||||
};
|
||||
|
||||
template<size_t n, typename Storage>
|
||||
template<typename OutputIterator>
|
||||
void HWAddress<n, Storage>::convert(const std::string& hw_addr,
|
||||
OutputIterator output) {
|
||||
unsigned i(0);
|
||||
size_t count(0);
|
||||
storage_type tmp;
|
||||
while (i < hw_addr.size() && count < n) {
|
||||
const unsigned end = i+2;
|
||||
tmp = storage_type();
|
||||
while (i < end) {
|
||||
if (hw_addr[i] >= 'a' && hw_addr[i] <= 'f') {
|
||||
tmp = (tmp << 4) | (hw_addr[i] - 'a' + 10);
|
||||
}
|
||||
else if (hw_addr[i] >= 'A' && hw_addr[i] <= 'F') {
|
||||
tmp = (tmp << 4) | (hw_addr[i] - 'A' + 10);
|
||||
}
|
||||
else if (hw_addr[i] >= '0' && hw_addr[i] <= '9') {
|
||||
tmp = (tmp << 4) | (hw_addr[i] - '0');
|
||||
}
|
||||
else if (hw_addr[i] == ':') {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Invalid byte found");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
*(output++) = tmp;
|
||||
count++;
|
||||
if (i < hw_addr.size()) {
|
||||
if (hw_addr[i] == ':') {
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Invalid separator");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (count++ < n) {
|
||||
*(output++) = storage_type();
|
||||
}
|
||||
}
|
||||
|
||||
template<size_t n, typename Storage>
|
||||
const HWAddress<n, Storage> HWAddress<n, Storage>::broadcast = make_broadcast_address();
|
||||
template<size_t n>
|
||||
const HWAddress<n> HWAddress<n>::broadcast = make_broadcast_address();
|
||||
|
||||
} // namespace Tins
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,11 +42,11 @@
|
||||
#endif // TIMESTAMP_REPLY
|
||||
#endif // _WIN32
|
||||
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "ip_address.h"
|
||||
#include "icmp_extension.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/icmp_extension.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -89,7 +89,9 @@ public:
|
||||
INFO_REQUEST = 15,
|
||||
INFO_REPLY = 16,
|
||||
ADDRESS_MASK_REQUEST = 17,
|
||||
ADDRESS_MASK_REPLY = 18
|
||||
ADDRESS_MASK_REPLY = 18,
|
||||
EXTENDED_ECHO_REQUEST = 42,
|
||||
EXTENDED_ECHO_REPLY = 43
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -318,7 +320,7 @@ public:
|
||||
* \return Returns the gateway field value.
|
||||
*/
|
||||
address_type gateway() const {
|
||||
return address_type(Endian::be_to_host(header_.un.gateway));
|
||||
return address_type(header_.un.gateway);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,7 +383,7 @@ public:
|
||||
* \return Returns the address mask value.
|
||||
*/
|
||||
address_type address_mask() const {
|
||||
return address_type(Endian::be_to_host(orig_timestamp_or_address_mask_));
|
||||
return address_type(orig_timestamp_or_address_mask_);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,15 +495,8 @@ private:
|
||||
} un;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void checksum(uint16_t new_check);
|
||||
|
||||
/** \brief Serialices this ICMP PDU.
|
||||
* \param buffer The buffer in which the PDU will be serialized.
|
||||
* \param total_sz The size available in the buffer.
|
||||
* \param parent The PDU that's one level below this one on the stack.
|
||||
*/
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
|
||||
void checksum(uint16_t new_check);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
uint32_t get_adjusted_inner_pdu_size() const;
|
||||
void try_parse_extensions(Memory::InputMemoryStream& stream);
|
||||
bool are_extensions_allowed() const;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,11 +31,10 @@
|
||||
#define TINS_ICMP_EXTENSION_H
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include "small_uint.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -176,7 +175,7 @@ public:
|
||||
/**
|
||||
* The type used to store the list of ICMP extensions in this structure
|
||||
*/
|
||||
typedef std::list<ICMPExtension> extensions_type;
|
||||
typedef std::vector<ICMPExtension> extensions_type;
|
||||
|
||||
/**
|
||||
* \brief Default constructor
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,18 +30,18 @@
|
||||
#ifndef TINS_ICMPV6_H
|
||||
#define TINS_ICMPV6_H
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "ipv6_address.h"
|
||||
#include "pdu_option.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include "hw_address.h"
|
||||
#include "small_uint.h"
|
||||
#include "icmp_extension.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/ipv6_address.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/icmp_extension.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -93,7 +93,9 @@ public:
|
||||
MULTICAST_ROUTER_ADVERT = 151,
|
||||
MULTICAST_ROUTER_SOLICIT = 152,
|
||||
MULTICAST_ROUTER_TERMINATE = 153,
|
||||
RPL_CONTROL_MSG = 155
|
||||
RPL_CONTROL_MSG = 155,
|
||||
EXTENDED_ECHO_REQUEST = 160,
|
||||
EXTENDED_ECHO_REPLY = 161
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -155,7 +157,7 @@ public:
|
||||
/**
|
||||
* The type used to store options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* \brief The type used to store the new home agent information
|
||||
@@ -174,7 +176,7 @@ public:
|
||||
|
||||
addr_list_type(const addresses_type& addresses = addresses_type())
|
||||
: addresses(addresses) {
|
||||
std::fill(reserved, reserved + sizeof(reserved), 0);
|
||||
std::fill(reserved, reserved + sizeof(reserved), static_cast<uint8_t>(0));
|
||||
}
|
||||
|
||||
static addr_list_type from_option(const option& opt);
|
||||
@@ -200,7 +202,7 @@ public:
|
||||
|
||||
naack_type(uint8_t code = 0, uint8_t status = 0)
|
||||
: code(code), status(status) {
|
||||
std::fill(reserved, reserved + 4, 0);
|
||||
std::fill(reserved, reserved + 4, static_cast<uint8_t>(0));
|
||||
}
|
||||
|
||||
static naack_type from_option(const option& opt);
|
||||
@@ -324,7 +326,7 @@ public:
|
||||
* The key_hash member will be 0-initialized.
|
||||
*/
|
||||
rsa_sign_type() {
|
||||
std::fill(key_hash, key_hash + sizeof(key_hash), 0);
|
||||
std::fill(key_hash, key_hash + sizeof(key_hash), static_cast<uint8_t>(0));
|
||||
}
|
||||
|
||||
static rsa_sign_type from_option(const option& opt);
|
||||
@@ -490,7 +492,7 @@ public:
|
||||
|
||||
timestamp_type(uint64_t timestamp = 0)
|
||||
: timestamp(timestamp) {
|
||||
std::fill(reserved, reserved + sizeof(reserved), 0);
|
||||
std::fill(reserved, reserved + sizeof(reserved), static_cast<uint8_t>(0));
|
||||
}
|
||||
|
||||
static timestamp_type from_option(const option& opt);
|
||||
@@ -548,13 +550,13 @@ public:
|
||||
/*
|
||||
* The type used to store all multicast address records in a packet
|
||||
*/
|
||||
typedef std::list<multicast_address_record> multicast_address_records_list;
|
||||
typedef std::vector<multicast_address_record> multicast_address_records_list;
|
||||
|
||||
/*
|
||||
* The type used to store all source address (from Multicast
|
||||
* Listener Query messages) in a packet
|
||||
*/
|
||||
typedef std::list<ipaddress_type> sources_list;
|
||||
typedef std::vector<ipaddress_type> sources_list;
|
||||
|
||||
/**
|
||||
* \brief Constructs an ICMPv6 object.
|
||||
@@ -1559,7 +1561,7 @@ private:
|
||||
} TINS_END_PACK;
|
||||
|
||||
void internal_add_option(const option& option);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
bool has_options() const;
|
||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||
void parse_options(Memory::InputMemoryStream& stream);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef TINS_IEEE802_3_H
|
||||
#define TINS_IEEE802_3_H
|
||||
|
||||
#include "dot3.h"
|
||||
#include <tins/dot3.h>
|
||||
|
||||
namespace Tins {
|
||||
typedef Dot3 IEEE802_3;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,236 +30,11 @@
|
||||
#ifndef TINS_INTERNALS_H
|
||||
#define TINS_INTERNALS_H
|
||||
|
||||
#if TINS_IS_CXX11
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "constants.h"
|
||||
#include "pdu.h"
|
||||
#include "hw_address.h"
|
||||
#include "macros.h"
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
|
||||
class InputMemoryStream;
|
||||
} // Memory
|
||||
class IPv4Address;
|
||||
class IPv6Address;
|
||||
class ICMPExtensionsStructure;
|
||||
|
||||
namespace Internals {
|
||||
|
||||
template<size_t n>
|
||||
class byte_array {
|
||||
public:
|
||||
typedef uint8_t* iterator;
|
||||
typedef const uint8_t* const_iterator;
|
||||
|
||||
byte_array() {
|
||||
std::fill(begin(), end(), 0);
|
||||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
byte_array(InputIterator start, InputIterator last) {
|
||||
std::copy(start, last, data);
|
||||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
byte_array(InputIterator start) {
|
||||
std::copy(start, n, data);
|
||||
}
|
||||
|
||||
uint8_t& operator[](size_t i) {
|
||||
return data[i];
|
||||
}
|
||||
|
||||
uint8_t operator[](size_t i) const{
|
||||
return data[i];
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
return data;
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
return data + n;
|
||||
}
|
||||
|
||||
const_iterator begin() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
return data + n;
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
return n;
|
||||
}
|
||||
private:
|
||||
uint8_t data[n];
|
||||
};
|
||||
|
||||
void skip_line(std::istream& input);
|
||||
bool from_hex(const std::string& str, uint32_t& result);
|
||||
bool from_hex(const std::string& str, std::string& result);
|
||||
|
||||
template<bool, typename T = void>
|
||||
struct enable_if {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct enable_if<false, T> {
|
||||
|
||||
};
|
||||
|
||||
PDU* pdu_from_flag(Constants::Ethernet::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
PDU* pdu_from_flag(Constants::IP::e flag, const uint8_t* buffer,
|
||||
uint32_t size, bool rawpdu_on_no_match = true);
|
||||
#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,
|
||||
uint32_t payload_length, ICMPExtensionsStructure& extensions);
|
||||
|
||||
template<typename T>
|
||||
bool increment_buffer(T& addr) {
|
||||
typename T::iterator it = addr.end() - 1;
|
||||
while (it >= addr.begin() && *it == 0xff) {
|
||||
*it = 0;
|
||||
--it;
|
||||
}
|
||||
// reached end
|
||||
if (it < addr.begin()) {
|
||||
return true;
|
||||
}
|
||||
(*it)++;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool decrement_buffer(T& addr) {
|
||||
typename T::iterator it = addr.end() - 1;
|
||||
while (it >= addr.begin() && *it == 0) {
|
||||
*it = 0xff;
|
||||
--it;
|
||||
}
|
||||
// reached end
|
||||
if (it < addr.begin()) {
|
||||
return true;
|
||||
}
|
||||
(*it)--;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool increment(IPv4Address& addr);
|
||||
bool increment(IPv6Address& addr);
|
||||
bool decrement(IPv4Address& addr);
|
||||
bool decrement(IPv6Address& addr);
|
||||
template<size_t n>
|
||||
bool increment(HWAddress<n>& addr) {
|
||||
return increment_buffer(addr);
|
||||
}
|
||||
template<size_t n>
|
||||
bool decrement(HWAddress<n>& addr) {
|
||||
return decrement_buffer(addr);
|
||||
}
|
||||
|
||||
// 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>
|
||||
HWAddress<n> last_address_from_mask(HWAddress<n> addr, const HWAddress<n>& mask) {
|
||||
typename HWAddress<n>::iterator addr_iter = addr.begin();
|
||||
for (typename HWAddress<n>::const_iterator it = mask.begin(); it != mask.end(); ++it, ++addr_iter) {
|
||||
*addr_iter = *addr_iter | ~*it;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
inline bool is_dot3(const uint8_t* ptr, size_t sz) {
|
||||
return (sz >= 13 && ptr[12] < 8);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct is_unsigned_integral {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint8_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint16_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint32_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_unsigned_integral<uint64_t> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
#if TINS_IS_CXX11 && !defined(_MSC_VER)
|
||||
|
||||
// Template metaprogramming trait to determine if a functor can accept another parameter as an argument
|
||||
template <typename T, typename P, typename=void>
|
||||
struct accepts_type : std::false_type { };
|
||||
|
||||
template <typename T, typename P>
|
||||
struct accepts_type<T, P,
|
||||
typename std::enable_if<
|
||||
std::is_same< decltype( std::declval<T>()(std::declval<P>()) ), bool>::value
|
||||
>::type
|
||||
> : std::true_type { };
|
||||
|
||||
// use enable_if to invoke the Packet&& version of the sniff_loop handler if possible - otherwise fail to old behavior
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<accepts_type<Functor, Packet>::value, bool>::type* = 0) {
|
||||
return f(std::move(p));
|
||||
}
|
||||
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(p);
|
||||
}
|
||||
|
||||
template <typename Functor, typename Packet>
|
||||
bool invoke_loop_cb(Functor& f, Packet& p, typename std::enable_if<!accepts_type<Functor, Packet>::value && !accepts_type<Functor, Packet&>::value, bool>::type* = 0) {
|
||||
return f(*p.pdu());
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Internals
|
||||
} // namespace Tins
|
||||
/**
|
||||
* \endcond
|
||||
*/
|
||||
#include <tins/detail/type_traits.h>
|
||||
#include <tins/detail/address_helpers.h>
|
||||
#include <tins/detail/icmp_extension_helpers.h>
|
||||
#include <tins/detail/smart_ptr.h>
|
||||
#include <tins/detail/pdu_helpers.h>
|
||||
#include <tins/detail/sequence_number_helpers.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,14 +30,13 @@
|
||||
#ifndef TINS_IP_H
|
||||
#define TINS_IP_H
|
||||
|
||||
#include <list>
|
||||
#include "pdu.h"
|
||||
#include "small_uint.h"
|
||||
#include "endianness.h"
|
||||
#include "ip_address.h"
|
||||
#include "pdu_option.h"
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -175,9 +174,9 @@ public:
|
||||
option_identifier(OptionNumber number, OptionClass op_class,
|
||||
small_uint<1> copied)
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
: number(number), op_class(op_class), copied(copied) {}
|
||||
: number(static_cast<uint8_t>(number)), op_class(static_cast<uint8_t>(op_class)), copied(copied) {}
|
||||
#else
|
||||
: copied(copied), op_class(op_class), number(number) {}
|
||||
: copied(copied), op_class(static_cast<uint8_t>(op_class)), number(static_cast<uint8_t>(number)) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -244,7 +243,7 @@ public:
|
||||
/**
|
||||
* The type used to store IP options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* \brief Extracts metadata for this protocol based on the buffer provided
|
||||
@@ -282,6 +281,10 @@ public:
|
||||
|
||||
/* Getters */
|
||||
|
||||
uint32_t advertised_size() const {
|
||||
return static_cast<uint32_t>(tot_len());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the header length field.
|
||||
*
|
||||
@@ -410,7 +413,7 @@ public:
|
||||
* \return The stored options.
|
||||
*/
|
||||
const options_type& options() const {
|
||||
return ip_options_;
|
||||
return options_;
|
||||
}
|
||||
|
||||
/* Setters */
|
||||
@@ -524,8 +527,7 @@ public:
|
||||
* \param opt The option to be added.
|
||||
*/
|
||||
void add_option(option &&opt) {
|
||||
internal_add_option(opt);
|
||||
ip_options_.push_back(std::move(opt));
|
||||
options_.push_back(std::move(opt));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,8 +540,7 @@ public:
|
||||
*/
|
||||
template<typename... Args>
|
||||
void add_option(Args&&... args) {
|
||||
ip_options_.emplace_back(std::forward<Args>(args)...);
|
||||
internal_add_option(ip_options_.back());
|
||||
options_.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -756,21 +757,20 @@ private:
|
||||
void head_len(small_uint<4> new_head_len);
|
||||
void tot_len(uint16_t new_tot_len);
|
||||
|
||||
void prepare_for_serialize(const PDU* parent);
|
||||
void internal_add_option(const option& option);
|
||||
void prepare_for_serialize();
|
||||
uint32_t calculate_options_size() const;
|
||||
uint32_t pad_options_size(uint32_t size) const;
|
||||
void init_ip_fields();
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||
void add_route_option(option_identifier id, const generic_route_option_type& data);
|
||||
generic_route_option_type search_route_option(option_identifier id) const;
|
||||
void checksum(uint16_t new_check);
|
||||
options_type::const_iterator search_option_iterator(option_identifier id) const;
|
||||
options_type::iterator search_option_iterator(option_identifier id);
|
||||
void update_padded_options_size();
|
||||
|
||||
options_type options_;
|
||||
ip_header header_;
|
||||
uint16_t options_size_, padded_options_size_;
|
||||
options_type ip_options_;
|
||||
};
|
||||
|
||||
} // Tins
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,10 +31,11 @@
|
||||
#define TINS_IPADDRESS_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include "cxxstd.h"
|
||||
#include "macros.h"
|
||||
#include <iosfwd>
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
@@ -134,6 +135,38 @@ public:
|
||||
return ip_addr_ < rhs.ip_addr_;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this address for less-than equality.
|
||||
*
|
||||
* \param rhs The address to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or less-than rhs.
|
||||
*/
|
||||
bool operator<=(const IPv4Address& rhs) const {
|
||||
return !operator>(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compare this IPv4Address for greater-than inequality.
|
||||
*
|
||||
* \param rhs The address to be compared.
|
||||
* \return bool indicating whether this address is greater-than rhs.
|
||||
*/
|
||||
bool operator>(const IPv4Address& rhs) const {
|
||||
return ip_addr_ > rhs.ip_addr_;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this address for greater-than equality.
|
||||
*
|
||||
* \param rhs The address to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or greater-than rhs.
|
||||
*/
|
||||
bool operator>=(const IPv4Address& rhs) const {
|
||||
return !operator<(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Apply a mask to this address
|
||||
*
|
||||
@@ -141,6 +174,19 @@ public:
|
||||
* \return The result of applying the mask to this address
|
||||
*/
|
||||
IPv4Address operator&(const IPv4Address& mask) const;
|
||||
|
||||
/**
|
||||
* \brief Apply a mask to this address
|
||||
*
|
||||
* \param mask The mask to be applied
|
||||
* \return The result of applying the mask to this address
|
||||
*/
|
||||
IPv4Address operator|(const IPv4Address& mask) const;
|
||||
|
||||
/**
|
||||
* not operator (invert)
|
||||
*/
|
||||
IPv4Address operator~() const;
|
||||
|
||||
/**
|
||||
* \brief Returns true if this is a private IPv4 address.
|
||||
@@ -180,6 +226,15 @@ public:
|
||||
* \brief Returns true if this is a broadcast IPv4 address.
|
||||
*/
|
||||
bool is_broadcast() const;
|
||||
|
||||
/**
|
||||
* \brief Returns the size of an IPv4 Address.
|
||||
*
|
||||
* This returns the value of IPv4Address::address_size
|
||||
*/
|
||||
size_t size() const {
|
||||
return address_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes this address to a std::ostream.
|
||||
@@ -205,8 +260,9 @@ namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<Tins::IPv4Address> {
|
||||
size_t operator()(const Tins::IPv4Address& addr) const {
|
||||
return std::hash<uint32_t>()(addr);
|
||||
size_t operator()(const Tins::IPv4Address& addr) const
|
||||
{
|
||||
return std::hash<std::uint32_t>()(addr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,16 +32,16 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "ip_address.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/ip.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
class IP;
|
||||
namespace Internals {
|
||||
class IPv4Fragment {
|
||||
public:
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
void add_fragment(IP* ip);
|
||||
bool is_complete() const;
|
||||
PDU* allocate_pdu() const;
|
||||
const IP& first_fragment() const;
|
||||
private:
|
||||
typedef std::vector<IPv4Fragment> fragments_type;
|
||||
|
||||
@@ -81,9 +82,10 @@ private:
|
||||
bool extract_more_frag(const IP* ip);
|
||||
|
||||
fragments_type fragments_;
|
||||
size_t received_size_;
|
||||
size_t total_size_;
|
||||
IP first_fragment_;
|
||||
bool received_end_;
|
||||
uint8_t transport_proto_;
|
||||
size_t received_size_, total_size_;
|
||||
};
|
||||
} // namespace Internals
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,10 +30,10 @@
|
||||
#ifndef TINS_IPSEC_H
|
||||
#define TINS_IPSEC_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -168,7 +168,7 @@ private:
|
||||
uint32_t spi, seq_number;
|
||||
};
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
ipsec_header header_;
|
||||
byte_array icv_;
|
||||
@@ -258,7 +258,7 @@ private:
|
||||
uint32_t spi, seq_number;
|
||||
};
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
ipsec_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,14 +30,13 @@
|
||||
#ifndef TINS_IPV6_h
|
||||
#define TINS_IPV6_h
|
||||
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include "pdu_option.h"
|
||||
#include "ipv6_address.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/ipv6_address.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -72,7 +71,12 @@ public:
|
||||
/**
|
||||
* The type used to store the extension headers.
|
||||
*/
|
||||
typedef std::list<ext_header> headers_type;
|
||||
typedef std::vector<ext_header> headers_type;
|
||||
|
||||
/**
|
||||
* The type used to store an extension header option.
|
||||
*/
|
||||
typedef std::pair<uint8_t, std::vector<uint8_t> > header_option_type;
|
||||
|
||||
/**
|
||||
* The values used to identify extension headers.
|
||||
@@ -106,6 +110,46 @@ public:
|
||||
*/
|
||||
static metadata extract_metadata(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/*
|
||||
* \brief The type used to store Hop-By-Hop Extension Headers
|
||||
*/
|
||||
struct hop_by_hop_header {
|
||||
std::vector<header_option_type> options;
|
||||
|
||||
static hop_by_hop_header from_extension_header(const ext_header& hdr);
|
||||
};
|
||||
|
||||
/*
|
||||
* \brief The type used to store Destination Routing Extension Headers
|
||||
*/
|
||||
struct destination_routing_header {
|
||||
std::vector<header_option_type> options;
|
||||
|
||||
static destination_routing_header from_extension_header(const ext_header& hdr);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The type used to store Routing Extension headers
|
||||
*/
|
||||
struct routing_header {
|
||||
uint8_t routing_type;
|
||||
uint8_t segments_left;
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
static routing_header from_extension_header(const ext_header& hdr);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The type used to store Fragment Extension headers
|
||||
*/
|
||||
struct fragment_header {
|
||||
uint16_t fragment_offset;
|
||||
bool more_fragments;
|
||||
uint32_t identification;
|
||||
|
||||
static fragment_header from_extension_header(const ext_header& hdr);
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Constructs an IPv6 object.
|
||||
*
|
||||
@@ -299,15 +343,55 @@ public:
|
||||
* \sa PDU::send()
|
||||
*/
|
||||
void send(PacketSender& sender, const NetworkInterface &);
|
||||
|
||||
/**
|
||||
* \brief Receives a matching response for this packet.
|
||||
*
|
||||
* \sa PDU::recv_response
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
*/
|
||||
PDU* recv_response(PacketSender& sender, const NetworkInterface &);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Adds an extension header.
|
||||
*
|
||||
* \deprecated Use IPv6::add_header
|
||||
* \param header The extension header to be added.
|
||||
*/
|
||||
void add_ext_header(const ext_header& header);
|
||||
TINS_DEPRECATED(void add_ext_header(const ext_header& header));
|
||||
|
||||
/**
|
||||
* Adds an extension header
|
||||
*
|
||||
* \deprecated Use IPv6::add_header
|
||||
* \param header The extension header to be added.
|
||||
*/
|
||||
void add_header(const ext_header& header);
|
||||
|
||||
#if TINS_IS_CXX11
|
||||
|
||||
/**
|
||||
* Adds an extension header by moving it
|
||||
*
|
||||
* \param header The extension header to be added.
|
||||
*/
|
||||
void add_header(ext_header&& header) {
|
||||
ext_headers_.emplace_back(std::move(header));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an extension header by using the provided parameters
|
||||
*
|
||||
* \param header The extension header to be added.
|
||||
*/
|
||||
template <typename... Args>
|
||||
void add_header(Args&&... args) {
|
||||
ext_headers_.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#endif // TINS_IS_CXX11
|
||||
|
||||
/**
|
||||
* \brief Searchs for an extension header that matchs the given
|
||||
* flag.
|
||||
@@ -320,10 +404,13 @@ public:
|
||||
*/
|
||||
const ext_header* search_header(ExtensionHeader id) const;
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void set_last_next_header(uint8_t value);
|
||||
uint32_t calculate_headers_size() const;
|
||||
static void write_header(const ext_header& header, Memory::OutputMemoryStream& stream);
|
||||
static bool is_extension_header(uint8_t header_id);
|
||||
static uint32_t get_padding_size(const ext_header& header);
|
||||
static std::vector<header_option_type> parse_header_options(const uint8_t* data, size_t size);
|
||||
|
||||
TINS_BEGIN_PACK
|
||||
struct ipv6_header {
|
||||
@@ -347,7 +434,7 @@ private:
|
||||
|
||||
ipv6_header header_;
|
||||
headers_type ext_headers_;
|
||||
uint32_t headers_size_;
|
||||
uint8_t next_header_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,10 +31,11 @@
|
||||
#define TINS_IPV6_ADDRESS
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <iosfwd>
|
||||
#include <functional>
|
||||
#include <stdint.h>
|
||||
#include "cxxstd.h"
|
||||
#include "macros.h"
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -159,7 +160,40 @@ public:
|
||||
bool operator<(const IPv6Address& rhs) const {
|
||||
return std::lexicographical_compare(begin(), end(), rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Compares this address for less-than equality.
|
||||
*
|
||||
* \param rhs The address to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or less-than rhs.
|
||||
*/
|
||||
bool operator<=(const IPv6Address& rhs) const {
|
||||
return !operator>(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this address for greater-than inequality.
|
||||
*
|
||||
* \param rhs The address to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is greater-than rhs.
|
||||
*/
|
||||
bool operator>(const IPv6Address& rhs) const {
|
||||
return std::lexicographical_compare(rhs.begin(), rhs.end(), begin(), end());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compares this address for greater-than equality.
|
||||
*
|
||||
* \param rhs The address to be compared to.
|
||||
*
|
||||
* \return bool indicating whether this address is equal or greater-than rhs.
|
||||
*/
|
||||
bool operator>=(const IPv6Address& rhs) const {
|
||||
return !operator<(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Helper function which copies the address into an output
|
||||
* iterator.
|
||||
@@ -195,6 +229,23 @@ public:
|
||||
* ff00::/8, false otherwise.
|
||||
*/
|
||||
bool is_multicast() const;
|
||||
|
||||
/**
|
||||
* \brief Return true if this is a Link-Local unicast IPv6 address.
|
||||
*
|
||||
* This method returns true if this address is in the address range
|
||||
* fe80::/10, false otherwise
|
||||
*/
|
||||
bool is_local_unicast() const;
|
||||
|
||||
/**
|
||||
* \brief Returns the size of an IPv6 Address.
|
||||
*
|
||||
* This returns the value of IPv6Address::address_size
|
||||
*/
|
||||
size_t size() const {
|
||||
return address_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Writes this address in hex-notation to a std::ostream.
|
||||
@@ -203,15 +254,22 @@ public:
|
||||
* \param addr The parameter to be written.
|
||||
* \return std::ostream& pointing to the os parameter.
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr) {
|
||||
return os << addr.to_string();
|
||||
}
|
||||
|
||||
TINS_API friend std::ostream& operator<<(std::ostream& os, const IPv6Address& addr);
|
||||
|
||||
/**
|
||||
* Applies a mask to an address
|
||||
*/
|
||||
TINS_API friend IPv6Address operator&(const IPv6Address& lhs, const IPv6Address& rhs);
|
||||
IPv6Address operator&(const IPv6Address& rhs) const;
|
||||
|
||||
/**
|
||||
* or a mask to an address
|
||||
*/
|
||||
IPv6Address operator|(const IPv6Address& rhs) const;
|
||||
|
||||
/**
|
||||
* not operator (invert)
|
||||
*/
|
||||
IPv6Address operator~() const ;
|
||||
|
||||
private:
|
||||
void init(const char* addr);
|
||||
@@ -226,8 +284,14 @@ namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<Tins::IPv6Address> {
|
||||
// Implementation taken from boost.functional
|
||||
size_t operator()(const Tins::IPv6Address& addr) const {
|
||||
return std::hash<std::string>()(addr.to_string());
|
||||
std::size_t output = Tins::IPv6Address::address_size;
|
||||
Tins::IPv6Address::const_iterator iter = addr.begin();
|
||||
for (; iter != addr.end(); ++iter) {
|
||||
output ^= *iter + 0x9e3779b9 + (output << 6) + (output >> 2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,12 +30,11 @@
|
||||
#ifndef TINS_IEEE8022_H
|
||||
#define TINS_IEEE8022_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -237,7 +236,7 @@ public:
|
||||
* \return The LLC frame format.
|
||||
*/
|
||||
uint8_t type() {
|
||||
return type_;
|
||||
return static_cast<uint8_t>(type_);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +245,7 @@ public:
|
||||
* \return The sender send sequence number if format is INFORMATION else 0.
|
||||
*/
|
||||
uint8_t send_seq_number() {
|
||||
return (type() == INFORMATION) ? (control_field.info.send_seq_num) : 0;
|
||||
return static_cast<uint8_t>((type() == INFORMATION) ? (control_field.info.send_seq_num) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,9 +398,9 @@ private:
|
||||
#endif
|
||||
|
||||
typedef std::vector<uint8_t> field_type;
|
||||
typedef std::list<field_type> field_list;
|
||||
typedef std::vector<field_type> field_list;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
llchdr header_;
|
||||
uint8_t control_field_length_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,8 +30,8 @@
|
||||
#ifndef TINS_LOOPBACK_H
|
||||
#define TINS_LOOPBACK_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
void send(PacketSender& sender, const NetworkInterface& iface);
|
||||
#endif // BSD
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
uint32_t family_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,7 +34,7 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
// Check if this is Visual Studio
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,16 +32,17 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "exceptions.h"
|
||||
#include "ip_address.h"
|
||||
#include "ipv6_address.h"
|
||||
#include "hw_address.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/exceptions.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class IPv4Address;
|
||||
class IPv6Address;
|
||||
template <size_t n>
|
||||
class HWAddress;
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
@@ -71,20 +72,7 @@ public:
|
||||
: buffer_(buffer), size_(total_sz) {
|
||||
}
|
||||
|
||||
InputMemoryStream(const std::vector<uint8_t>& data)
|
||||
: buffer_(&data[0]), size_(data.size()) {
|
||||
}
|
||||
|
||||
void skip(size_t size) {
|
||||
if (TINS_UNLIKELY(size > size_)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
buffer_ += size;
|
||||
size_ -= size;
|
||||
}
|
||||
|
||||
bool can_read(size_t byte_count) const {
|
||||
return TINS_LIKELY(size_ >= byte_count);
|
||||
InputMemoryStream(const std::vector<uint8_t>& data) : buffer_(&data[0]), size_(data.size()) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -113,33 +101,16 @@ public:
|
||||
skip(sizeof(value));
|
||||
}
|
||||
|
||||
void read(std::vector<uint8_t>& value, size_t count) {
|
||||
if (!can_read(count)) {
|
||||
void skip(size_t size) {
|
||||
if (TINS_UNLIKELY(size > size_)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
value.assign(pointer(), pointer() + count);
|
||||
skip(count);
|
||||
buffer_ += size;
|
||||
size_ -= size;
|
||||
}
|
||||
|
||||
void read(IPv4Address& address) {
|
||||
address = IPv4Address(read<uint32_t>());
|
||||
}
|
||||
|
||||
void read(IPv6Address& address) {
|
||||
if (!can_read(IPv6Address::address_size)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
address = pointer();
|
||||
skip(IPv6Address::address_size);
|
||||
}
|
||||
|
||||
template <size_t n>
|
||||
void read(HWAddress<n>& address) {
|
||||
if (!can_read(HWAddress<n>::address_size)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
address = pointer();
|
||||
skip(HWAddress<n>::address_size);
|
||||
bool can_read(size_t byte_count) const {
|
||||
return TINS_LIKELY(size_ >= byte_count);
|
||||
}
|
||||
|
||||
void read(void* output_buffer, size_t output_buffer_size) {
|
||||
@@ -165,6 +136,11 @@ public:
|
||||
operator bool() const {
|
||||
return size_ > 0;
|
||||
}
|
||||
|
||||
void read(std::vector<uint8_t>& value, size_t count);
|
||||
void read(HWAddress<6>& address);
|
||||
void read(IPv4Address& address);
|
||||
void read(IPv6Address& address);
|
||||
private:
|
||||
const uint8_t* buffer_;
|
||||
size_t size_;
|
||||
@@ -180,14 +156,6 @@ public:
|
||||
: buffer_(&buffer[0]), size_(buffer.size()) {
|
||||
}
|
||||
|
||||
void skip(size_t size) {
|
||||
if (TINS_UNLIKELY(size > size_)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
buffer_ += size;
|
||||
size_ -= size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void write(const T& value) {
|
||||
if (TINS_UNLIKELY(size_ < sizeof(value))) {
|
||||
@@ -213,32 +181,31 @@ public:
|
||||
if (TINS_UNLIKELY(size_ < length)) {
|
||||
throw serialization_error();
|
||||
}
|
||||
std::copy(start, end, buffer_);
|
||||
// VC doesn't like dereferencing empty vector's iterators so check this here
|
||||
if (TINS_UNLIKELY(length == 0)) {
|
||||
return;
|
||||
}
|
||||
std::memcpy(buffer_, &*start, length);
|
||||
skip(length);
|
||||
}
|
||||
|
||||
void skip(size_t size) {
|
||||
if (TINS_UNLIKELY(size > size_)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
buffer_ += size;
|
||||
size_ -= size;
|
||||
}
|
||||
|
||||
void write(const uint8_t* ptr, size_t length) {
|
||||
write(ptr, ptr + length);
|
||||
}
|
||||
|
||||
void write(const IPv4Address& address) {
|
||||
write(static_cast<uint32_t>(address));
|
||||
}
|
||||
|
||||
void write(const IPv6Address& address) {
|
||||
write(address.begin(), address.end());
|
||||
}
|
||||
|
||||
template <size_t n>
|
||||
void write(const HWAddress<n>& address) {
|
||||
write(address.begin(), address.end());
|
||||
}
|
||||
|
||||
void fill(size_t size, uint8_t value) {
|
||||
if (TINS_UNLIKELY(size_ < size)) {
|
||||
throw serialization_error();
|
||||
}
|
||||
std::fill(buffer_, buffer_ + size, value);
|
||||
std::memset(buffer_, value, size);
|
||||
skip(size);
|
||||
}
|
||||
|
||||
@@ -249,6 +216,10 @@ public:
|
||||
size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
void write(const HWAddress<6>& address);
|
||||
void write(const IPv4Address& address);
|
||||
void write(const IPv6Address& address);
|
||||
private:
|
||||
uint8_t* buffer_;
|
||||
size_t size_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,10 +30,10 @@
|
||||
#ifndef TINS_MPLS_H
|
||||
#define TINS_MPLS_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include "macros.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -73,15 +73,22 @@ public:
|
||||
* \brief Getter for the label field.
|
||||
*/
|
||||
small_uint<20> label() const {
|
||||
return (Endian::be_to_host(header_.label_high) << 4) |
|
||||
((header_.label_low_and_bottom >> 4) & 0xf);
|
||||
return (Endian::be_to_host(header_.label_high) << 4) |
|
||||
((header_.label_low_exp_and_bottom >> 4) & 0xf);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the experimental field.
|
||||
*/
|
||||
small_uint<3> experimental() const {
|
||||
return (header_.label_low_exp_and_bottom >> 1) & 0x7;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter for the bottom of the stack field.
|
||||
*/
|
||||
small_uint<1> bottom_of_stack() const {
|
||||
return header_.label_low_and_bottom & 0x1;
|
||||
return header_.label_low_exp_and_bottom & 0x1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,11 +105,18 @@ public:
|
||||
*/
|
||||
void label(small_uint<20> value);
|
||||
|
||||
/**
|
||||
* \brief Setter for the experimental field
|
||||
*
|
||||
* \param value The new experimental field value
|
||||
*/
|
||||
void experimental(small_uint<3> value);
|
||||
|
||||
/**
|
||||
* \brief Setter for the bottom of the stack field
|
||||
*
|
||||
* Note that if this MPLS layer is somewhere between an Ethernet and IP
|
||||
* layers, the bottom of the stack field will be overriden and set
|
||||
* layers, the bottom of the stack field will be overriden and set
|
||||
* automatically. You should only set this field when constructing ICMP
|
||||
* extensions.
|
||||
*
|
||||
@@ -143,11 +157,11 @@ private:
|
||||
TINS_BEGIN_PACK
|
||||
struct mpls_header {
|
||||
uint16_t label_high;
|
||||
uint8_t label_low_and_bottom;
|
||||
uint8_t label_low_exp_and_bottom;
|
||||
uint8_t ttl;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
mpls_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,10 +33,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include "hw_address.h"
|
||||
#include "ip_address.h"
|
||||
#include "ipv6_address.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/ipv6_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -118,6 +118,17 @@ public:
|
||||
* \param ip The ip address being looked up.
|
||||
*/
|
||||
NetworkInterface(IPv4Address ip);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructs a NetworkInterface from an ipv6 address.
|
||||
*
|
||||
* This abstracted interface will be the one that would be the gateway
|
||||
* when sending a packet to the given ip.
|
||||
*
|
||||
* \param ip The ipv6 address being looked up.
|
||||
*/
|
||||
NetworkInterface(IPv6Address ipv6);
|
||||
|
||||
/**
|
||||
* \brief Getter for this interface's identifier.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,11 +32,11 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "macros.h"
|
||||
#include <tins/macros.h>
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
#include "data_link_type.h"
|
||||
#include <tins/data_link_type.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,10 +30,9 @@
|
||||
#ifndef TINS_PACKET_H
|
||||
#define TINS_PACKET_H
|
||||
|
||||
#include <algorithm>
|
||||
#include "cxxstd.h"
|
||||
#include "pdu.h"
|
||||
#include "timestamp.h"
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/timestamp.h>
|
||||
|
||||
/**
|
||||
* \namespace Tins
|
||||
@@ -234,7 +233,9 @@ public:
|
||||
*/
|
||||
Packet& operator=(Packet &&rhs) TINS_NOEXCEPT {
|
||||
if (this != &rhs) {
|
||||
std::swap(pdu_, rhs.pdu_);
|
||||
PDU* tmp = std::move(pdu_);
|
||||
pdu_ = std::move(rhs.pdu_);
|
||||
rhs.pdu_ = std::move(tmp);
|
||||
ts_ = rhs.timestamp();
|
||||
}
|
||||
return* this;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,17 +32,16 @@
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <map>
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
#ifdef TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
||||
#include <pcap.h>
|
||||
#endif // TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET
|
||||
#include "network_interface.h"
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/network_interface.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
struct timeval;
|
||||
struct sockaddr;
|
||||
@@ -66,7 +65,9 @@ class PDU;
|
||||
* - Those that don't contain a link layer PDU. In this case, the
|
||||
* kernel will be responsible for picking the appropriate network interface
|
||||
* based on the destination address.
|
||||
*
|
||||
* - Exception: <a href="https://datatracker.ietf.org/doc/html/rfc2553#section-3.3">RFC2553</a>
|
||||
* requires IPv6 link-scope address have a interface defined.
|
||||
* .
|
||||
* \par Note for Windows users:
|
||||
* Sending layer 3 PDUs (without a link layer protocol) is very restricted
|
||||
* on Windows (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx">link</a>).
|
||||
@@ -132,6 +133,7 @@ public:
|
||||
ARP_SOCKET,
|
||||
ICMP_SOCKET,
|
||||
IPV6_SOCKET,
|
||||
ICMPV6_SOCKET,
|
||||
SOCKETS_END
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,15 +30,14 @@
|
||||
#ifndef TINS_PACKET_WRITER_H
|
||||
#define TINS_PACKET_WRITER_H
|
||||
|
||||
#include "utils.h"
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/utils/pdu_utils.h>
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
#include <pcap.h>
|
||||
#include "data_link_type.h"
|
||||
#include <tins/data_link_type.h>
|
||||
|
||||
struct timeval;
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -26,16 +26,16 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TINS_PDU_H
|
||||
#define TINS_PDU_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
#include "exceptions.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/exceptions.h>
|
||||
|
||||
/** \brief The Tins namespace.
|
||||
*/
|
||||
@@ -49,22 +49,22 @@ class NetworkInterface;
|
||||
*/
|
||||
typedef std::vector<uint8_t> byte_array;
|
||||
|
||||
/**
|
||||
/**
|
||||
* \class PDU
|
||||
* \brief Base class for protocol data units.
|
||||
*
|
||||
* Every PDU implementation inherits from this class.
|
||||
* Every PDU implementation inherits from this class.
|
||||
*
|
||||
* PDUs can contain 0 or 1 inner PDU. By stacking several PDUs together,
|
||||
* you can construct packets. These are created upwards: upper layers
|
||||
* will be children of the lower ones.
|
||||
* you can construct packets. These are created upwards: upper layers
|
||||
* will be children of the lower ones.
|
||||
*
|
||||
* If you want to find a specific protocol within a PDU chain, you can use
|
||||
* PDU::find_pdu and PDU::rfind_pdu. Both of them take a template parameter
|
||||
* that indicates the PDU type you are looking for. The first one returns a
|
||||
* pointer to the first object of that type, and the second one returns a
|
||||
* reference (and throws if it is not found).
|
||||
*
|
||||
* that indicates the PDU type you are looking for. The first one returns a
|
||||
* pointer to the first object of that type, and the second one returns a
|
||||
* reference (and throws if it is not found).
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* \code
|
||||
@@ -86,7 +86,7 @@ typedef std::vector<uint8_t> byte_array;
|
||||
* stack into a vector of bytes. This process might modify some parameters
|
||||
* on packets depending on which protocols are used in it. For example:
|
||||
*
|
||||
* - If the lowest protocol layer is IP (this means that there is no
|
||||
* - If the lowest protocol layer is IP (this means that there is no
|
||||
* link layer protocol in the packet), then it calculates the source address
|
||||
* that should be used in that IP PDU. \sa IP
|
||||
* - If a protocol contains a checksum field, its value will be calculated
|
||||
@@ -170,6 +170,7 @@ public:
|
||||
ICMPv6,
|
||||
SLL,
|
||||
DHCPv6,
|
||||
DOT1AD,
|
||||
DOT1Q,
|
||||
PPPOE,
|
||||
STP,
|
||||
@@ -178,10 +179,12 @@ public:
|
||||
IPSEC_ESP,
|
||||
PKTAP,
|
||||
MPLS,
|
||||
DOT11_CONTROL_TA,
|
||||
VXLAN,
|
||||
UNKNOWN = 999,
|
||||
USER_DEFINED_PDU = 1000
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The endianness used by this PDU. This can be overriden
|
||||
* by subclasses.
|
||||
@@ -196,10 +199,10 @@ public:
|
||||
* \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);
|
||||
|
||||
@@ -219,34 +222,42 @@ public:
|
||||
PDUType next_pdu_type;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Default constructor.
|
||||
*/
|
||||
PDU();
|
||||
|
||||
|
||||
#if TINS_IS_CXX11
|
||||
/**
|
||||
* \brief Move constructor.
|
||||
*
|
||||
*
|
||||
* \param rhs The PDU to be moved.
|
||||
*/
|
||||
PDU(PDU &&rhs) TINS_NOEXCEPT
|
||||
: inner_pdu_(0) {
|
||||
PDU(PDU &&rhs) TINS_NOEXCEPT
|
||||
: inner_pdu_(0), parent_pdu_(0) {
|
||||
std::swap(inner_pdu_, rhs.inner_pdu_);
|
||||
if (inner_pdu_) {
|
||||
inner_pdu_->parent_pdu(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Move assignment operator.
|
||||
*
|
||||
*
|
||||
* \param rhs The PDU to be moved.
|
||||
*/
|
||||
PDU& operator=(PDU &&rhs) TINS_NOEXCEPT {
|
||||
delete inner_pdu_;
|
||||
inner_pdu_ = 0;
|
||||
std::swap(inner_pdu_, rhs.inner_pdu_);
|
||||
if (inner_pdu_) {
|
||||
inner_pdu_->parent_pdu(this);
|
||||
}
|
||||
return* this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief PDU destructor.
|
||||
*
|
||||
* Deletes the inner pdu, as a consequence every child pdu is
|
||||
@@ -272,25 +283,39 @@ public:
|
||||
*/
|
||||
uint32_t size() const;
|
||||
|
||||
/** \brief The whole chain of PDU's advertised size, including this one.
|
||||
*
|
||||
* Returns the sum of this and all children PDU's advertised size.
|
||||
*/
|
||||
virtual uint32_t advertised_size() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the inner PDU.
|
||||
* \return The current inner PDU. Might be 0.
|
||||
* \return The current inner PDU. Might be a null pointer.
|
||||
*/
|
||||
PDU* inner_pdu() const {
|
||||
return inner_pdu_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for the parent PDU
|
||||
* \return The current parent PDU. Might be a null pointer.
|
||||
*/
|
||||
PDU* parent_pdu() const {
|
||||
return parent_pdu_;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Releases the inner PDU.
|
||||
*
|
||||
*
|
||||
* This method makes this PDU to <b>no longer own</b> the inner
|
||||
* PDU. The current inner PDU is returned, and is <b>not</b>
|
||||
* destroyed. That means after calling this function, you are
|
||||
* destroyed. That means after calling this function, you are
|
||||
* responsible for using operator delete on the returned pointer.
|
||||
*
|
||||
*
|
||||
* Use this method if you want to somehow re-use a PDU that
|
||||
* is already owned by another PDU.
|
||||
*
|
||||
*
|
||||
* \return The current inner PDU. Might be 0.
|
||||
*/
|
||||
PDU* release_inner_pdu();
|
||||
@@ -300,27 +325,26 @@ public:
|
||||
*
|
||||
* When setting a new inner_pdu, the instance takesownership of
|
||||
* the object, therefore deleting it when it's no longer required.
|
||||
*
|
||||
*
|
||||
* \param next_pdu The new child PDU.
|
||||
*/
|
||||
void inner_pdu(PDU* next_pdu);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Sets the child PDU.
|
||||
*
|
||||
* The PDU parameter is cloned using PDU::clone.
|
||||
*
|
||||
*
|
||||
* \param next_pdu The new child PDU.
|
||||
*/
|
||||
void inner_pdu(const PDU& next_pdu);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Serializes the whole chain of PDU's, including this one.
|
||||
*
|
||||
* This allocates a std::vector of size size(), and fills it
|
||||
* with the serialization this PDU, and all of the inner ones'.
|
||||
*
|
||||
*
|
||||
* \return serialization_type containing the serialization
|
||||
* of the whole stack of PDUs.
|
||||
*/
|
||||
@@ -334,7 +358,7 @@ public:
|
||||
* If no PDU matches, 0 is returned.
|
||||
* \param flag The flag which being searched.
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename T>
|
||||
T* find_pdu(PDUType type = T::pdu_flag) {
|
||||
PDU* pdu = this;
|
||||
while (pdu) {
|
||||
@@ -345,24 +369,24 @@ public:
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Finds and returns the first PDU that matches the given flag.
|
||||
*
|
||||
* \param flag The flag which being searched.
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename T>
|
||||
const T* find_pdu(PDUType type = T::pdu_flag) const {
|
||||
return const_cast<PDU*>(this)->find_pdu<T>(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Finds and returns the first PDU that matches the given flag.
|
||||
*
|
||||
*
|
||||
* If the PDU is not found, a pdu_not_found exception is thrown.
|
||||
*
|
||||
*
|
||||
* \sa PDU::find_pdu
|
||||
*
|
||||
*
|
||||
* \param flag The flag which being searched.
|
||||
*/
|
||||
template<typename T>
|
||||
@@ -379,7 +403,7 @@ public:
|
||||
*
|
||||
* \param flag The flag which being searched.
|
||||
*/
|
||||
template<typename T>
|
||||
template<typename T>
|
||||
const T& rfind_pdu(PDUType type = T::pdu_flag) const {
|
||||
return const_cast<PDU*>(this)->rfind_pdu<T>(type);
|
||||
}
|
||||
@@ -394,36 +418,36 @@ public:
|
||||
*/
|
||||
virtual PDU* clone() const = 0;
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Send the stack of PDUs through a PacketSender.
|
||||
*
|
||||
* This method will be called only for the PDU on the bottom of the stack,
|
||||
* therefore it should only implement this method if it can be sent.
|
||||
*
|
||||
*
|
||||
* PacketSender implements specific methods to send packets which start
|
||||
* on every valid TCP/IP stack layer; this should only be a proxy for
|
||||
* those methods.
|
||||
*
|
||||
*
|
||||
* If this PDU does not represent a link layer protocol, then
|
||||
* the interface argument will be ignored.
|
||||
*
|
||||
*
|
||||
* \param sender The PacketSender which will send the packet.
|
||||
* \param iface The network interface in which this packet will
|
||||
* \param iface The network interface in which this packet will
|
||||
* be sent.
|
||||
*/
|
||||
virtual void send(PacketSender& sender, const NetworkInterface& iface);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Receives a matching response for this packet.
|
||||
*
|
||||
* This method should act as a proxy for PacketSender::recv_lX methods.
|
||||
*
|
||||
*
|
||||
* \param sender The packet sender which will receive the packet.
|
||||
* \param iface The interface in which to expect the response.
|
||||
*/
|
||||
virtual PDU* recv_response(PacketSender& sender, const NetworkInterface& iface);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Check whether ptr points to a valid response for this PDU.
|
||||
*
|
||||
* This method must check whether the buffer pointed by ptr is a valid
|
||||
@@ -472,56 +496,55 @@ protected:
|
||||
|
||||
/**
|
||||
* \brief Prepares this PDU for serialization.
|
||||
*
|
||||
*
|
||||
* This method is called before the inner PDUs are serialized.
|
||||
* It's useful in situations such as when serializing IP PDUs,
|
||||
* which don't contain any link layer encapsulation, and therefore
|
||||
* require to set the source IP address before the TCP/UDP checksum
|
||||
* is calculated.
|
||||
*
|
||||
*
|
||||
* By default, this method does nothing
|
||||
*
|
||||
* \param parent The parent PDU.
|
||||
*/
|
||||
virtual void prepare_for_serialize(const PDU* parent);
|
||||
virtual void prepare_for_serialize();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Serializes this PDU and propagates this action to child PDUs.
|
||||
*
|
||||
* \param buffer The buffer in which to store this PDU's serialization.
|
||||
* \param total_sz The total size of the buffer.
|
||||
* \param parent The parent PDU. Will be 0 if there's the parent does not exist.
|
||||
*/
|
||||
void serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void serialize(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Serializes this TCP PDU.
|
||||
*
|
||||
* Each PDU must override this method and implement it's own
|
||||
* serialization.
|
||||
* \param buffer The buffer in which the PDU will be serialized.
|
||||
* \param total_sz The size available in the buffer.
|
||||
* \param parent The PDU that's one level below this one on the stack. Might be 0.
|
||||
*/
|
||||
virtual void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) = 0;
|
||||
virtual void write_serialization(uint8_t* buffer, uint32_t total_sz) = 0;
|
||||
private:
|
||||
void parent_pdu(PDU* parent);
|
||||
|
||||
PDU* inner_pdu_;
|
||||
PDU* parent_pdu_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Concatenation operator.
|
||||
*
|
||||
* This operator concatenates several PDUs. A copy of the right
|
||||
*
|
||||
* This operator concatenates several PDUs. A copy of the right
|
||||
* operand is set at the end of the left one's inner PDU chain.
|
||||
* This means that:
|
||||
*
|
||||
*
|
||||
* IP some_ip = IP("127.0.0.1") / TCP(12, 13) / RawPDU("bleh");
|
||||
*
|
||||
* Works as expected, meaning the output PDU will look like the
|
||||
*
|
||||
* Works as expected, meaning the output PDU will look like the
|
||||
* following:
|
||||
*
|
||||
*
|
||||
* IP - TCP - RawPDU
|
||||
*
|
||||
*
|
||||
* \param lop The left operand, which will be the one modified.
|
||||
* \param rop The right operand, the one which will be appended
|
||||
* to lop.
|
||||
@@ -538,7 +561,7 @@ T& operator/= (T& lop, const PDU& rop) {
|
||||
|
||||
/**
|
||||
* \brief Concatenation operator.
|
||||
*
|
||||
*
|
||||
* \sa operator/=
|
||||
*/
|
||||
template<typename T>
|
||||
@@ -549,7 +572,7 @@ T operator/ (T lop, const PDU& rop) {
|
||||
|
||||
/**
|
||||
* \brief Concatenation operator on PDU pointers.
|
||||
*
|
||||
*
|
||||
* \sa operator/=
|
||||
*/
|
||||
template<typename T>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
#define TINS_PDU_ALLOCATOR_H
|
||||
|
||||
#include <map>
|
||||
#include "pdu.h"
|
||||
#include <tins/pdu.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,9 +30,9 @@
|
||||
#ifndef TINS_PDU_CACHER_H
|
||||
#define TINS_PDU_CACHER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include <cstring>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
@@ -144,11 +144,11 @@ public:
|
||||
return cached_.pdu_type();
|
||||
}
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||
if (cached_serialization_.size() != total_sz) {
|
||||
cached_serialization_ = cached_.serialize();
|
||||
}
|
||||
std::copy(cached_serialization_.begin(), cached_serialization_.end(), buffer);
|
||||
std::memcpy(buffer, &*cached_serialization_.begin(), cached_serialization_.size());
|
||||
}
|
||||
|
||||
cached_type cached_;
|
||||
|
||||
312
include/tins/pdu_iterator.h
Normal file
312
include/tins/pdu_iterator.h
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TINS_PDU_ITERATOR_H
|
||||
#define TINS_PDU_ITERATOR_H
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class PDU;
|
||||
class Packet;
|
||||
|
||||
/**
|
||||
* Base class for PDU iterators
|
||||
*/
|
||||
template <typename Concrete>
|
||||
class PDUIteratorBase {
|
||||
public:
|
||||
/**
|
||||
* Iterator's category
|
||||
*/
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
/**
|
||||
* Iterator difference type
|
||||
*/
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
/**
|
||||
* Advances this iterator
|
||||
*/
|
||||
Concrete& operator++() {
|
||||
advance();
|
||||
return static_cast<Concrete&>(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances this iterator
|
||||
*/
|
||||
Concrete operator++(int) {
|
||||
Concrete output = static_cast<Concrete&>(*this);
|
||||
advance();
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves this iterator back
|
||||
*/
|
||||
Concrete& operator--() {
|
||||
retreat();
|
||||
return static_cast<Concrete&>(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves this iterator back
|
||||
*/
|
||||
Concrete operator--(int) {
|
||||
Concrete output = static_cast<Concrete&>(*this);
|
||||
retreat();
|
||||
return output;
|
||||
}
|
||||
private:
|
||||
void advance() {
|
||||
Concrete& self = static_cast<Concrete&>(*this);
|
||||
self = Concrete(self->inner_pdu());
|
||||
}
|
||||
|
||||
void retreat() {
|
||||
Concrete& self = static_cast<Concrete&>(*this);
|
||||
self = Concrete(self->parent_pdu());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Compares iterators for equality
|
||||
*
|
||||
* \param lhs The left hand side iterator to be compared
|
||||
* \param rhs The right hand side iterator to be compared
|
||||
*/
|
||||
template <typename Concrete>
|
||||
bool operator==(const PDUIteratorBase<Concrete>& lhs, const PDUIteratorBase<Concrete>& rhs) {
|
||||
const PDU* lhs_pdu = static_cast<const Concrete&>(lhs).operator->();
|
||||
const PDU* rhs_pdu = static_cast<const Concrete&>(rhs).operator->();
|
||||
return lhs_pdu == rhs_pdu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares iterators for equality
|
||||
*
|
||||
* \param lhs The left hand side iterator to be compared
|
||||
* \param rhs The right hand side iterator to be compared
|
||||
*/
|
||||
template <typename Concrete>
|
||||
bool operator!=(const PDUIteratorBase<Concrete>& lhs, const PDUIteratorBase<Concrete>& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator class for PDUs
|
||||
*/
|
||||
class PDUIterator : public PDUIteratorBase<PDUIterator> {
|
||||
public:
|
||||
/**
|
||||
* The used pointer type
|
||||
*/
|
||||
typedef PDU* pointer;
|
||||
|
||||
/**
|
||||
* The used reference type
|
||||
*/
|
||||
typedef PDU& reference;
|
||||
|
||||
/**
|
||||
* The used value type
|
||||
*/
|
||||
typedef PDU& value_type;
|
||||
|
||||
/**
|
||||
* Constructs an iterator using a PDU
|
||||
*
|
||||
* \param pdu The PDU to be used for iteration
|
||||
*/
|
||||
PDUIterator(pointer pdu);
|
||||
|
||||
/**
|
||||
* Get the stored PDU pointer
|
||||
*/
|
||||
pointer operator->();
|
||||
|
||||
/**
|
||||
* Get the stored PDU pointer
|
||||
*/
|
||||
pointer operator->() const;
|
||||
|
||||
/**
|
||||
* Dereference and get the stored PDU
|
||||
*/
|
||||
PDU& operator*();
|
||||
|
||||
/**
|
||||
* Dereference and get the stored PDU
|
||||
*/
|
||||
const PDU& operator*() const;
|
||||
private:
|
||||
pointer pdu_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Const iterator class for PDUs
|
||||
*/
|
||||
class ConstPDUIterator : public PDUIteratorBase<PDUIterator> {
|
||||
public:
|
||||
/**
|
||||
* The used pointer type
|
||||
*/
|
||||
typedef const PDU* pointer;
|
||||
|
||||
/**
|
||||
* The used reference type
|
||||
*/
|
||||
typedef const PDU& reference;
|
||||
|
||||
/**
|
||||
* The used value type
|
||||
*/
|
||||
typedef const PDU& value_type;
|
||||
|
||||
/**
|
||||
* Constructs an iterator using a PDU
|
||||
*
|
||||
* \param pdu The PDU to be used for iteration
|
||||
*/
|
||||
ConstPDUIterator(pointer pdu);
|
||||
|
||||
/**
|
||||
* Construct from a PDU iterator
|
||||
*/
|
||||
ConstPDUIterator(PDUIterator iterator);
|
||||
|
||||
/**
|
||||
* Get the stored PDU pointer
|
||||
*/
|
||||
pointer operator->() const;
|
||||
|
||||
/**
|
||||
* Dereference and get the stored PDU
|
||||
*/
|
||||
value_type operator*() const;
|
||||
private:
|
||||
pointer pdu_;
|
||||
};
|
||||
|
||||
/*
|
||||
* \brief PDU iterator class
|
||||
*
|
||||
* This class allows iterating all PDUs in a packet.
|
||||
*
|
||||
* Note that this keeps pointers to the original PDUs so you need to guarantee that they're
|
||||
* still in scope while you iterate them.
|
||||
*/
|
||||
template <typename Iterator>
|
||||
class PDUIteratorRange {
|
||||
public:
|
||||
/**
|
||||
* Constructs a PDU iterator range
|
||||
*
|
||||
* \param start The beginning of the range
|
||||
* \param end The end of the range
|
||||
*/
|
||||
PDUIteratorRange(Iterator start, Iterator end)
|
||||
: start_(start), end_(end) {
|
||||
|
||||
}
|
||||
|
||||
template <typename OtherIterator>
|
||||
PDUIteratorRange(const PDUIteratorRange<OtherIterator>& other)
|
||||
: start_(other.begin().operator->()), end_(other.end().operator->()) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the beginning of the range
|
||||
*/
|
||||
Iterator begin() {
|
||||
return start_;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the beginning of the range
|
||||
*/
|
||||
Iterator begin() const {
|
||||
return start_;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the end of the range
|
||||
*/
|
||||
Iterator end() {
|
||||
return end_;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the end of the range
|
||||
*/
|
||||
Iterator end() const {
|
||||
return end_;
|
||||
}
|
||||
private:
|
||||
Iterator start_;
|
||||
Iterator end_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a PDU
|
||||
*/
|
||||
PDUIteratorRange<PDUIterator> iterate_pdus(PDU* pdu);
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a PDU
|
||||
*/
|
||||
PDUIteratorRange<PDUIterator> iterate_pdus(PDU& pdu);
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a PDU
|
||||
*/
|
||||
PDUIteratorRange<PDUIterator> iterate_pdus(Packet& packet);
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a PDU
|
||||
*/
|
||||
PDUIteratorRange<ConstPDUIterator> iterate_pdus(const PDU* pdu);
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a PDU
|
||||
*/
|
||||
PDUIteratorRange<ConstPDUIterator> iterate_pdus(const PDU& pdu);
|
||||
|
||||
/**
|
||||
* Creates an iterator range out of a packet
|
||||
*/
|
||||
PDUIteratorRange<ConstPDUIterator> iterate_pdus(const Packet& packet);
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // TINS_PDU_ITERATOR_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,20 +31,19 @@
|
||||
#define TINS_PDU_OPTION_H
|
||||
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include "exceptions.h"
|
||||
#include "endianness.h"
|
||||
#include "internals.h"
|
||||
#include "ip_address.h"
|
||||
#include "ipv6_address.h"
|
||||
#include "hw_address.h"
|
||||
#include <tins/exceptions.h>
|
||||
#include <tins/detail/type_traits.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
class IPv4Address;
|
||||
class IPv6Address;
|
||||
template <size_t n>
|
||||
class HWAddress;
|
||||
|
||||
/**
|
||||
* \cond
|
||||
*/
|
||||
@@ -52,251 +51,133 @@ template <typename OptionType, typename PDUType>
|
||||
class PDUOption;
|
||||
|
||||
namespace Internals {
|
||||
template <typename T, typename X, typename PDUType>
|
||||
T convert_to_integral(const PDUOption<X, PDUType> & opt) {
|
||||
if (opt.data_size() != sizeof(T)) {
|
||||
throw malformed_option();
|
||||
}
|
||||
T data = *(T*)opt.data_ptr();
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
data = Endian::be_to_host(data);
|
||||
}
|
||||
else {
|
||||
data = Endian::le_to_host(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
namespace Converters {
|
||||
uint8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<uint8_t>);
|
||||
int8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<int8_t>);
|
||||
uint16_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<uint16_t>);
|
||||
uint32_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<uint32_t>);
|
||||
uint64_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<uint64_t>);
|
||||
HWAddress<6> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian, type_to_type<HWAddress<6> >);
|
||||
IPv4Address convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian, type_to_type<IPv4Address>);
|
||||
IPv6Address convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian,
|
||||
type_to_type<IPv6Address>);
|
||||
std::string convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian, type_to_type<std::string>);
|
||||
std::vector<float> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian, type_to_type<std::vector<float> >);
|
||||
std::vector<uint8_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian, type_to_type<std::vector<uint8_t> >);
|
||||
std::vector<uint16_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::vector<uint16_t> >);
|
||||
std::vector<uint32_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::vector<uint32_t> >);
|
||||
std::vector<IPv4Address> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::vector<IPv4Address> >);
|
||||
std::vector<IPv6Address> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::vector<IPv6Address> >);
|
||||
std::vector<std::pair<uint8_t, uint8_t> > convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::vector<std::pair<uint8_t, uint8_t> > >);
|
||||
std::pair<uint8_t, uint8_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::pair<uint8_t, uint8_t> >);
|
||||
std::pair<uint16_t, uint32_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::pair<uint16_t, uint32_t> >);
|
||||
std::pair<uint32_t, uint32_t> convert(const uint8_t* ptr, uint32_t data_size,
|
||||
PDU::endian_type endian,
|
||||
type_to_type<std::pair<uint32_t, uint32_t> >);
|
||||
} // Converters
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct converter {
|
||||
template <typename X, typename PDUType>
|
||||
static T convert(const PDUOption<X, PDUType>& opt) {
|
||||
template <typename T, typename X, typename PDUType>
|
||||
static T do_convert(const PDUOption<X, PDUType>& opt, type_to_type<T>) {
|
||||
return T::from_option(opt);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct converter<uint8_t> {
|
||||
template <typename X, typename PDUType>
|
||||
static uint8_t convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != 1) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return* opt.data_ptr();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<uint16_t> {
|
||||
template<typename X, typename PDUType>
|
||||
static uint16_t convert(const PDUOption<X, PDUType>& opt) {
|
||||
return convert_to_integral<uint16_t>(opt);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<uint32_t> {
|
||||
template<typename X, typename PDUType>
|
||||
static uint32_t convert(const PDUOption<X, PDUType>& opt) {
|
||||
return convert_to_integral<uint32_t>(opt);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<uint64_t> {
|
||||
template<typename X, typename PDUType>
|
||||
static uint64_t convert(const PDUOption<X, PDUType>& opt) {
|
||||
return convert_to_integral<uint64_t>(opt);
|
||||
}
|
||||
};
|
||||
|
||||
template<size_t n>
|
||||
struct converter<HWAddress<n> > {
|
||||
template<typename X, typename PDUType>
|
||||
static HWAddress<n> convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != n) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return HWAddress<n>(opt.data_ptr());
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<uint8_t> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<IPv4Address> {
|
||||
template<typename X, typename PDUType>
|
||||
static IPv4Address convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != sizeof(uint32_t)) {
|
||||
throw malformed_option();
|
||||
}
|
||||
const uint32_t* ptr = (const uint32_t*)opt.data_ptr();
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
return IPv4Address(*ptr);
|
||||
}
|
||||
else {
|
||||
return IPv4Address(Endian::change_endian(*ptr));
|
||||
}
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<int8_t> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<IPv6Address> {
|
||||
template<typename X, typename PDUType>
|
||||
static IPv6Address convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != IPv6Address::address_size) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return IPv6Address(opt.data_ptr());
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<uint16_t> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<std::string> {
|
||||
template<typename X, typename PDUType>
|
||||
static std::string convert(const PDUOption<X, PDUType>& opt) {
|
||||
return std::string(
|
||||
opt.data_ptr(),
|
||||
opt.data_ptr() + opt.data_size()
|
||||
);
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<uint32_t> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<std::vector<float> > {
|
||||
template<typename X, typename PDUType>
|
||||
static std::vector<float> convert(const PDUOption<X, PDUType>& opt) {
|
||||
std::vector<float> output;
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
while (ptr != end) {
|
||||
output.push_back(float(*(ptr++) & 0x7f) / 2);
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<uint64_t> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct converter<std::vector<T>, typename enable_if<is_unsigned_integral<T>::value>::type> {
|
||||
template<typename X, typename PDUType>
|
||||
static std::vector<T> convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() % sizeof(T) != 0) {
|
||||
throw malformed_option();
|
||||
}
|
||||
const T* ptr = (const T*)opt.data_ptr();
|
||||
const T* end = (const T*)(opt.data_ptr() + opt.data_size());
|
||||
|
||||
std::vector<T> output(std::distance(ptr, end));
|
||||
typename std::vector<T>::iterator it = output.begin();
|
||||
while (ptr < end) {
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
*it++ = Endian::be_to_host(*ptr++);
|
||||
}
|
||||
else {
|
||||
*it++ = Endian::le_to_host(*ptr++);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<HWAddress<6> > type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
struct converter<
|
||||
std::vector<std::pair<T, U> >,
|
||||
typename enable_if<
|
||||
is_unsigned_integral<T>::value && is_unsigned_integral<U>::value
|
||||
>::type
|
||||
> {
|
||||
template<typename X, typename PDUType>
|
||||
static std::vector<std::pair<T, U> > convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() % (sizeof(T) + sizeof(U)) != 0) {
|
||||
throw malformed_option();
|
||||
}
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
|
||||
std::vector<std::pair<T, U> > output;
|
||||
while (ptr < end) {
|
||||
std::pair<T, U> data;
|
||||
data.first = *(const T*)ptr;
|
||||
ptr += sizeof(T);
|
||||
data.second = *(const U*)ptr;
|
||||
ptr += sizeof(U);
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
data.first = Endian::be_to_host(data.first);
|
||||
data.second = Endian::be_to_host(data.second);
|
||||
}
|
||||
else {
|
||||
data.first = Endian::le_to_host(data.first);
|
||||
data.second = Endian::le_to_host(data.second);
|
||||
}
|
||||
output.push_back(data);
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<IPv4Address> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<std::vector<IPv4Address> > {
|
||||
template<typename X, typename PDUType>
|
||||
static std::vector<IPv4Address> convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() % 4 != 0) {
|
||||
throw malformed_option();
|
||||
}
|
||||
const uint32_t* ptr = (const uint32_t*)opt.data_ptr();
|
||||
const uint32_t* end = (const uint32_t*)(opt.data_ptr() + opt.data_size());
|
||||
|
||||
std::vector<IPv4Address> output(std::distance(ptr, end));
|
||||
std::vector<IPv4Address>::iterator it = output.begin();
|
||||
while (ptr < end) {
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
*it++ = IPv4Address(*ptr++);
|
||||
}
|
||||
else {
|
||||
*it++ = IPv4Address(Endian::change_endian(*ptr++));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt, type_to_type<IPv6Address> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct converter<std::vector<IPv6Address> > {
|
||||
template<typename X, typename PDUType>
|
||||
static std::vector<IPv6Address> convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() % IPv6Address::address_size != 0) {
|
||||
throw malformed_option();
|
||||
}
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = opt.data_ptr() + opt.data_size();
|
||||
std::vector<IPv6Address> output;
|
||||
while (ptr < end) {
|
||||
output.push_back(IPv6Address(ptr));
|
||||
ptr += IPv6Address::address_size;
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt,
|
||||
type_to_type<std::string> type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
struct converter<
|
||||
std::pair<T, U>,
|
||||
typename enable_if<
|
||||
is_unsigned_integral<T>::value && is_unsigned_integral<U>::value
|
||||
>::type
|
||||
> {
|
||||
template<typename X, typename PDUType>
|
||||
static std::pair<T, U> convert(const PDUOption<X, PDUType>& opt) {
|
||||
if (opt.data_size() != sizeof(T) + sizeof(U)) {
|
||||
throw malformed_option();
|
||||
}
|
||||
std::pair<T, U> output;
|
||||
std::memcpy(&output.first, opt.data_ptr(), sizeof(T));
|
||||
std::memcpy(&output.second, opt.data_ptr() + sizeof(T), sizeof(U));
|
||||
if (PDUType::endianness == PDUType::BE) {
|
||||
output.first = Endian::be_to_host(output.first);
|
||||
output.second = Endian::be_to_host(output.second);
|
||||
}
|
||||
else {
|
||||
output.first = Endian::le_to_host(output.first);
|
||||
output.second = Endian::le_to_host(output.second);
|
||||
}
|
||||
return output;
|
||||
|
||||
template <typename U, typename X, typename PDUType, typename Z>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt,
|
||||
type_to_type<std::vector<Z> > type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
|
||||
template <typename U, typename X, typename PDUType, typename Z, typename W>
|
||||
static U do_convert(const PDUOption<X, PDUType>& opt,
|
||||
type_to_type<std::pair<Z, W> > type) {
|
||||
return Converters::convert(opt.data_ptr(), opt.data_size(),
|
||||
PDUType::endianness, type);
|
||||
}
|
||||
|
||||
template <typename T, typename X, typename PDUType>
|
||||
static T convert(const PDUOption<X, PDUType>& opt) {
|
||||
return do_convert<T>(opt, type_to_type<T>());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -353,7 +234,7 @@ public:
|
||||
* \brief Move constructor.
|
||||
* \param rhs The PDUOption to be moved.
|
||||
*/
|
||||
PDUOption(PDUOption&& rhs) {
|
||||
PDUOption(PDUOption&& rhs) TINS_NOEXCEPT {
|
||||
real_size_ = 0;
|
||||
*this = std::move(rhs);
|
||||
}
|
||||
@@ -362,7 +243,7 @@ public:
|
||||
* \brief Move assignment operator.
|
||||
* \param rhs The PDUOption to be moved.
|
||||
*/
|
||||
PDUOption& operator=(PDUOption&& rhs) {
|
||||
PDUOption& operator=(PDUOption&& rhs) TINS_NOEXCEPT {
|
||||
option_ = rhs.option_;
|
||||
size_ = rhs.size_;
|
||||
if (real_size_ > small_buffer_size) {
|
||||
@@ -375,13 +256,9 @@ public:
|
||||
rhs.real_size_ = 0;
|
||||
}
|
||||
else {
|
||||
std::copy(
|
||||
rhs.data_ptr(),
|
||||
rhs.data_ptr() + rhs.data_size(),
|
||||
payload_.small_buffer
|
||||
);
|
||||
std::memcpy(payload_.small_buffer, rhs.data_ptr(), rhs.data_size());
|
||||
}
|
||||
return* this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // TINS_IS_CXX11
|
||||
@@ -510,22 +387,20 @@ public:
|
||||
*/
|
||||
template<typename T>
|
||||
T to() const {
|
||||
return Internals::converter<T>::convert(*this);
|
||||
return Internals::converter::convert<T>(*this);
|
||||
}
|
||||
private:
|
||||
template<typename ForwardIterator>
|
||||
void set_payload_contents(ForwardIterator start, ForwardIterator end) {
|
||||
size_t total_size = std::distance(start, end);
|
||||
if (total_size > std::numeric_limits<uint16_t>::max()) {
|
||||
if (total_size > 65535) {
|
||||
throw option_payload_too_large();
|
||||
}
|
||||
real_size_ = static_cast<uint16_t>(total_size);
|
||||
if (real_size_ <= small_buffer_size) {
|
||||
std::copy(
|
||||
start,
|
||||
end,
|
||||
payload_.small_buffer
|
||||
);
|
||||
if (total_size > 0) {
|
||||
std::memcpy(payload_.small_buffer, &*start, total_size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
payload_.big_buffer_ptr = new data_type[real_size_];
|
||||
@@ -547,22 +422,36 @@ private:
|
||||
};
|
||||
|
||||
namespace Internals {
|
||||
/*
|
||||
* \cond
|
||||
*/
|
||||
template <typename Option>
|
||||
struct option_type_equality_comparator {
|
||||
option_type_equality_comparator(typename Option::option_type type) : type(type) { }
|
||||
/*
|
||||
* \cond
|
||||
*/
|
||||
|
||||
bool operator()(const Option& opt) const {
|
||||
return opt.option() == type;
|
||||
template <typename Option, typename Container>
|
||||
typename Container::iterator find_option(Container& cont, typename Option::option_type type) {
|
||||
typename Container::iterator iter;
|
||||
for (iter = cont.begin(); iter != cont.end(); ++iter) {
|
||||
if (iter->option() == type) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
typename Option::option_type type;
|
||||
};
|
||||
/*
|
||||
* \endcond
|
||||
*/
|
||||
template <typename Option, typename Container>
|
||||
typename Container::const_iterator find_option_const(const Container& cont,
|
||||
typename Option::option_type type) {
|
||||
typename Container::const_iterator iter;
|
||||
for (iter = cont.begin(); iter != cont.end(); ++iter) {
|
||||
if (iter->option() == type) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
/*
|
||||
* \endcond
|
||||
*/
|
||||
} // Internals
|
||||
|
||||
} // namespace Tins
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,8 +30,8 @@
|
||||
#ifndef TINS_PKTAP_H
|
||||
#define TINS_PKTAP_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
// This class is only available if pcap is enabled
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
@@ -107,7 +107,7 @@ private:
|
||||
uint8_t ecommand[20];
|
||||
};
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
pktap_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,10 +30,10 @@
|
||||
#ifndef TINS_PPI_H
|
||||
#define TINS_PPI_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
return new PPI(*this);
|
||||
}
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void parse_80211(const uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
struct ppi_header {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,15 +30,14 @@
|
||||
#ifndef TINS_PPPoE_H
|
||||
#define TINS_PPPoE_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include "pdu_option.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
@@ -82,7 +81,7 @@ public:
|
||||
/**
|
||||
* The type used to store the options.
|
||||
*/
|
||||
typedef std::list<tag> tags_type;
|
||||
typedef std::vector<tag> tags_type;
|
||||
|
||||
/**
|
||||
* The type used to store the Vendor-Specific tag's value.
|
||||
@@ -390,7 +389,7 @@ public:
|
||||
*/
|
||||
std::string generic_error() const;
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
template<typename T>
|
||||
void add_tag_iterable(TagTypes id, const T& data) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,14 +27,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_RADIOTAP_H) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_RADIOTAP_H
|
||||
|
||||
#include "macros.h"
|
||||
#include "pdu.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/pdu_option.h>
|
||||
|
||||
namespace Tins {
|
||||
class PacketSender;
|
||||
@@ -54,6 +55,11 @@ public:
|
||||
*/
|
||||
static const PDU::PDUType pdu_flag = PDU::RADIOTAP;
|
||||
|
||||
/**
|
||||
* RadioTap is little endian
|
||||
*/
|
||||
static const endian_type endianness = LE;
|
||||
|
||||
/**
|
||||
* \brief Enumeration of the different channel type flags.
|
||||
*
|
||||
@@ -77,7 +83,8 @@ public:
|
||||
* \sa RadioTap::present()
|
||||
*/
|
||||
enum PresentFlags {
|
||||
TSTF = 1 << 0,
|
||||
TSFT = 1 << 0,
|
||||
TSTF = 1 << 0, ///< Deprecated (typo), use TSFT
|
||||
FLAGS = 1 << 1,
|
||||
RATE = 1 << 2,
|
||||
CHANNEL = 1 << 3,
|
||||
@@ -94,6 +101,7 @@ public:
|
||||
RX_FLAGS = 1 << 14,
|
||||
TX_FLAGS = 1 << 15,
|
||||
DATA_RETRIES = 1 << 17,
|
||||
XCHANNEL = 1 << 18,
|
||||
CHANNEL_PLUS = 1 << 18,
|
||||
MCS = 1 << 19
|
||||
};
|
||||
@@ -121,7 +129,28 @@ public:
|
||||
uint8_t flags;
|
||||
uint8_t mcs;
|
||||
} TINS_END_PACK;
|
||||
|
||||
/**
|
||||
* \brief The type used to represent the XChannel field
|
||||
*/
|
||||
TINS_BEGIN_PACK
|
||||
struct xchannel_type {
|
||||
uint32_t flags;
|
||||
uint16_t frequency;
|
||||
uint8_t channel;
|
||||
uint8_t max_power;
|
||||
} TINS_END_PACK;
|
||||
|
||||
/**
|
||||
* The type used to store RadioTap options
|
||||
*/
|
||||
typedef PDUOption<RadioTap::PresentFlags, RadioTap> option;
|
||||
|
||||
/**
|
||||
* The type used to store the options payload
|
||||
*/
|
||||
typedef std::vector<uint8_t> options_payload_type;
|
||||
|
||||
/**
|
||||
* \brief Default constructor.
|
||||
*/
|
||||
@@ -233,6 +262,12 @@ public:
|
||||
*/
|
||||
void tx_flags(uint16_t new_tx_flag);
|
||||
|
||||
/**
|
||||
* \brief Setter for the xchannel field.
|
||||
* \param new_xchannel The xchannel field
|
||||
*/
|
||||
void xchannel(xchannel_type new_xchannel);
|
||||
|
||||
/**
|
||||
* \brief Setter for the data retries field.
|
||||
* \param new_rx_flag The data retries.
|
||||
@@ -326,10 +361,10 @@ public:
|
||||
uint8_t db_signal() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the channel+ field.
|
||||
* \return The channel+ field.
|
||||
* \brief Getter for the XChannel field.
|
||||
* \return The XChannel field.
|
||||
*/
|
||||
uint32_t channel_plus() const;
|
||||
xchannel_type xchannel() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the data retries field
|
||||
@@ -364,10 +399,7 @@ public:
|
||||
* will be undefined. It is only safe to use the getter of a field
|
||||
* if its corresponding bit flag is set in the present field.
|
||||
*/
|
||||
PresentFlags present() const {
|
||||
//return (PresentFlags)*(uint32_t*)(&radio_.it_len + 1);
|
||||
return (PresentFlags)Endian::le_to_host(radio_.flags_32);
|
||||
}
|
||||
PresentFlags present() const;
|
||||
|
||||
/** \brief Check whether ptr points to a valid response for this PDU.
|
||||
*
|
||||
@@ -391,6 +423,22 @@ public:
|
||||
*/
|
||||
uint32_t trailer_size() const;
|
||||
|
||||
/**
|
||||
* Adds the given option
|
||||
*
|
||||
* \param option The option to be added.
|
||||
*/
|
||||
void add_option(const option& opt);
|
||||
|
||||
/**
|
||||
* \brief Gets the options payload
|
||||
*
|
||||
* Use Utils::RadioTapParser to iterate these options and extract fields manually,
|
||||
* in case you want to have deeper access into the option types/values stored in
|
||||
* a RadioTap frame.
|
||||
*/
|
||||
const options_payload_type& options_payload() const;
|
||||
|
||||
/**
|
||||
* \sa PDU::clone
|
||||
*/
|
||||
@@ -407,70 +455,7 @@ public:
|
||||
}
|
||||
private:
|
||||
TINS_BEGIN_PACK
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
struct flags_type {
|
||||
uint32_t
|
||||
tsft:1,
|
||||
flags:1,
|
||||
rate:1,
|
||||
channel:1,
|
||||
fhss:1,
|
||||
dbm_signal:1,
|
||||
dbm_noise:1,
|
||||
lock_quality:1,
|
||||
|
||||
tx_attenuation:1,
|
||||
db_tx_attenuation:1,
|
||||
dbm_tx_power:1,
|
||||
antenna:1,
|
||||
db_signal:1,
|
||||
db_noise:1,
|
||||
rx_flags:1,
|
||||
tx_flags:1,
|
||||
|
||||
reserved1:1,
|
||||
data_retries:1,
|
||||
channel_plus:1,
|
||||
mcs:1,
|
||||
reserved2:4,
|
||||
|
||||
reserved3:7,
|
||||
ext:1;
|
||||
} TINS_END_PACK;
|
||||
#else
|
||||
struct flags_type {
|
||||
uint32_t
|
||||
lock_quality:1,
|
||||
dbm_noise:1,
|
||||
dbm_signal:1,
|
||||
fhss:1,
|
||||
channel:1,
|
||||
rate:1,
|
||||
flags:1,
|
||||
tsft:1,
|
||||
|
||||
tx_flags:1,
|
||||
rx_flags:1,
|
||||
db_noise:1,
|
||||
db_signal:1,
|
||||
antenna:1,
|
||||
dbm_tx_power:1,
|
||||
db_tx_attenuation:1,
|
||||
tx_attenuation:1,
|
||||
|
||||
reserved2:4,
|
||||
mcs:1,
|
||||
channel_plus:1,
|
||||
data_retries:1,
|
||||
reserved1:1,
|
||||
|
||||
ext:1,
|
||||
reserved3:7;
|
||||
} TINS_END_PACK;
|
||||
#endif
|
||||
|
||||
TINS_BEGIN_PACK
|
||||
struct radiotap_hdr {
|
||||
struct radiotap_header {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
uint8_t it_version;
|
||||
uint8_t it_pad;
|
||||
@@ -479,48 +464,13 @@ private:
|
||||
uint8_t it_version;
|
||||
#endif // TINS_IS_LITTLE_ENDIAN
|
||||
uint16_t it_len;
|
||||
union {
|
||||
flags_type flags;
|
||||
uint32_t flags_32;
|
||||
};
|
||||
} TINS_END_PACK;
|
||||
|
||||
void init();
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
uint32_t find_extra_flag_fields_size(const uint8_t* buffer, uint32_t total_sz);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
option do_find_option(PresentFlags type) const;
|
||||
|
||||
template <size_t n>
|
||||
void align_buffer(const uint8_t* buffer_start, const uint8_t*& buffer, uint32_t& size) {
|
||||
uint32_t offset = ((buffer - buffer_start) % n);
|
||||
if (offset) {
|
||||
offset = n - offset;
|
||||
if (offset > size) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
buffer += offset;
|
||||
size -= offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
radiotap_hdr radio_;
|
||||
// present fields...
|
||||
uint64_t tsft_;
|
||||
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_;
|
||||
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_;
|
||||
radiotap_header header_;
|
||||
options_payload_type options_payload_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,9 +32,9 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -96,6 +96,16 @@ public:
|
||||
RawPDU(ForwardIterator start, ForwardIterator end)
|
||||
: payload_(start, end) { }
|
||||
|
||||
/**
|
||||
* \brief Creates an instance of RawPDU from a payload_type.
|
||||
*
|
||||
* The payload is copied into the RawPDU's internal buffer.
|
||||
*
|
||||
* \param data The payload to use.
|
||||
*/
|
||||
RawPDU(const payload_type & data)
|
||||
: payload_(data) { }
|
||||
|
||||
#if TINS_IS_CXX11
|
||||
/**
|
||||
* \brief Creates an instance of RawPDU from a payload_type.
|
||||
@@ -105,7 +115,7 @@ public:
|
||||
* \param data The payload to use.
|
||||
*/
|
||||
RawPDU(payload_type&& data)
|
||||
: payload_(move(data)) { }
|
||||
: payload_(std::move(data)) { }
|
||||
#endif // TINS_IS_CXX11
|
||||
|
||||
/**
|
||||
@@ -201,7 +211,7 @@ public:
|
||||
return new RawPDU(*this);
|
||||
}
|
||||
private:
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
payload_type payload_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,15 +27,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#if !defined(TINS_RSN_INFORMATION) && defined(TINS_HAVE_DOT11)
|
||||
#define TINS_RSN_INFORMATION
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
|
||||
namespace Tins{
|
||||
class Dot11;
|
||||
@@ -50,18 +50,36 @@ public:
|
||||
* \brief Enum that represents the different cypher suites.
|
||||
*/
|
||||
enum CypherSuites {
|
||||
WEP_40 = 0x01ac0f00,
|
||||
TKIP = 0x02ac0f00,
|
||||
CCMP = 0x04ac0f00,
|
||||
WEP_104 = 0x05ac0f00
|
||||
WEP_40 = 0x01ac0f00,
|
||||
TKIP = 0x02ac0f00,
|
||||
CCMP = 0x04ac0f00,
|
||||
WEP_104 = 0x05ac0f00,
|
||||
BIP_CMAC_128 = 0x06ac0f00,
|
||||
GCMP_128 = 0x08ac0f00,
|
||||
GCMP_256 = 0x09ac0f00,
|
||||
CCMP_256 = 0x10ac0f00,
|
||||
BIP_GMAC_128 = 0x11ac0f00,
|
||||
BIP_GMAC_256 = 0x12ac0f00,
|
||||
BIP_CMAC_256 = 0x13ac0f00
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Enum that represents the different akm suites.
|
||||
*/
|
||||
enum AKMSuites {
|
||||
PMKSA = 0x01ac0f00,
|
||||
PSK = 0x02ac0f00
|
||||
EAP = 0x01ac0f00,
|
||||
PSK = 0x02ac0f00,
|
||||
EAP_FT = 0x03ac0f00,
|
||||
PSK_FT = 0x04ac0f00,
|
||||
EAP_SHA256 = 0x05ac0f00,
|
||||
PSK_SHA256 = 0x06ac0f00,
|
||||
TDLS = 0x07ac0f00,
|
||||
SAE_SHA256 = 0x08ac0f00,
|
||||
SAE_FT = 0x09ac0f00,
|
||||
APPEERKEY = 0x10ac0f00,
|
||||
EAP_SHA256_FIPSB = 0x11ac0f00,
|
||||
EAP_SHA384_FIPSB = 0x12ac0f00,
|
||||
EAP_SHA384 = 0x13ac0f00
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,10 +31,10 @@
|
||||
#define TINS_SLL_H
|
||||
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/hw_address.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -174,7 +174,7 @@ private:
|
||||
uint16_t protocol;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
sll_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,12 +30,11 @@
|
||||
#ifndef TINS_SNAP_H
|
||||
#define TINS_SNAP_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -177,7 +176,7 @@ private:
|
||||
uint16_t eth_type;
|
||||
} TINS_END_PACK;
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
snap_header snap_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,19 +33,19 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <iterator>
|
||||
#include "pdu.h"
|
||||
#include "packet.h"
|
||||
#include "cxxstd.h"
|
||||
#include "macros.h"
|
||||
#include "exceptions.h"
|
||||
#include "internals.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/packet.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/exceptions.h>
|
||||
#include <tins/detail/type_traits.h>
|
||||
|
||||
#ifdef TINS_HAVE_PCAP
|
||||
|
||||
#include <pcap.h>
|
||||
|
||||
|
||||
namespace Tins {
|
||||
class SnifferIterator;
|
||||
class SnifferConfiguration;
|
||||
@@ -73,7 +73,8 @@ public:
|
||||
* This constructor is available only in C++11.
|
||||
*/
|
||||
BaseSniffer(BaseSniffer &&rhs) TINS_NOEXCEPT
|
||||
: handle_(0), mask_(), extract_raw_(false) {
|
||||
: handle_(0), mask_(), extract_raw_(false),
|
||||
pcap_sniffing_method_(pcap_loop) {
|
||||
*this = std::move(rhs);
|
||||
}
|
||||
|
||||
@@ -86,6 +87,7 @@ public:
|
||||
swap(handle_, rhs.handle_);
|
||||
swap(mask_, rhs.mask_);
|
||||
swap(extract_raw_, rhs.extract_raw_);
|
||||
swap(pcap_sniffing_method_, rhs.pcap_sniffing_method_);
|
||||
return* this;
|
||||
}
|
||||
#endif
|
||||
@@ -238,6 +240,35 @@ public:
|
||||
*/
|
||||
void set_extract_raw_pdus(bool value);
|
||||
|
||||
/**
|
||||
* \brief function pointer for the sniffing method
|
||||
*
|
||||
* By default, libtins uses `pcap_loop` to sniff packets. With
|
||||
* `set_pcap_sniffing_method` it is possible to specify an alternative
|
||||
* sniffing method, for example `pcap_dispatch`, or a custom function.
|
||||
* This function pointer has the same interface as `pcap_loop` and
|
||||
* `pcap_dispatch`.
|
||||
*
|
||||
* \sa set_pcap_sniffing_method
|
||||
*/
|
||||
typedef int(*PcapSniffingMethod)(pcap_t*, int, pcap_handler, u_char*);
|
||||
|
||||
/**
|
||||
* \brief set sniffing method to either pcap_loop or pcap_dispatch.
|
||||
*
|
||||
* By default, packets are sniffed with `pcap_loop`, which only returns if
|
||||
* a packet is received, thus ignoring timeout expiration, if any is set.
|
||||
* With this method it is possible to pass an alternative sniffer function,
|
||||
* e.g. `pcap_dispatch`, that honors timeouts, or a custom function with
|
||||
* the same signature.
|
||||
*
|
||||
* See the relevant manual pages for pcap_loop and pcap_dispatch for more
|
||||
* information on their behavior
|
||||
*
|
||||
* \sa PcapSniffingMethod
|
||||
*/
|
||||
void set_pcap_sniffing_method(PcapSniffingMethod method);
|
||||
|
||||
/**
|
||||
* \brief Retrieves this sniffer's link type.
|
||||
*
|
||||
@@ -283,6 +314,7 @@ private:
|
||||
pcap_t* handle_;
|
||||
bpf_u_int32 mask_;
|
||||
bool extract_raw_;
|
||||
PcapSniffingMethod pcap_sniffing_method_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -300,13 +332,18 @@ public:
|
||||
PROMISC
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of Sniffer
|
||||
*
|
||||
* \param device The device from which to capture packets
|
||||
*/
|
||||
Sniffer(const std::string& device);
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of Sniffer using the provided configuration.
|
||||
*
|
||||
* This constructor was added as a way to improve the parameter bloat
|
||||
* introduced by the other ones available. You should create an instance
|
||||
* of SnifferConfiguration, set the desired parameters, and then use it
|
||||
* when constructing a Sniffer object.
|
||||
* Use the SnifferConfiguration object to specify how you want to configure
|
||||
* the properties of this sniffer
|
||||
*
|
||||
* \sa SnifferConfiguration
|
||||
*
|
||||
@@ -329,8 +366,8 @@ public:
|
||||
* \param filter A capture filter to be used on the sniffing session.(optional);
|
||||
* \param rfmon Indicates if the interface should be put in monitor mode.(optional);
|
||||
*/
|
||||
Sniffer(const std::string& device, unsigned max_packet_size,
|
||||
bool promisc = false, const std::string& filter = "", bool rfmon = false);
|
||||
TINS_DEPRECATED(Sniffer(const std::string& device, unsigned max_packet_size,
|
||||
bool promisc = false, const std::string& filter = "", bool rfmon = false));
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of Sniffer.
|
||||
@@ -345,12 +382,13 @@ public:
|
||||
* \param filter A capture filter to be used on the sniffing session.(optional);
|
||||
* \param rfmon Indicates if the interface should be put in monitor mode.(optional);
|
||||
*/
|
||||
Sniffer(const std::string& device, promisc_type promisc = NON_PROMISC,
|
||||
const std::string& filter = "", bool rfmon = false);
|
||||
TINS_DEPRECATED(Sniffer(const std::string& device, promisc_type promisc,
|
||||
const std::string& filter = "", bool rfmon = false));
|
||||
|
||||
private:
|
||||
friend class SnifferConfiguration;
|
||||
|
||||
void init(const std::string& device, const SnifferConfiguration& configuration);
|
||||
void set_snap_len(unsigned snap_len);
|
||||
void set_buffer_size(unsigned buffer_size);
|
||||
void set_promisc_mode(bool promisc_enabled);
|
||||
@@ -368,10 +406,17 @@ private:
|
||||
*/
|
||||
class TINS_API FileSniffer : public BaseSniffer {
|
||||
public:
|
||||
/**
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param fp The pcap file which will be parsed.
|
||||
* \param configuration A SnifferConfiguration to be used on the file.
|
||||
*/
|
||||
FileSniffer(FILE *fp, const SnifferConfiguration& configuration);
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param file_name The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file.(optional);
|
||||
* \param configuration A SnifferConfiguration to be used on the file.
|
||||
*/
|
||||
FileSniffer(const std::string& file_name, const SnifferConfiguration& configuration);
|
||||
|
||||
@@ -380,9 +425,18 @@ public:
|
||||
*
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param file_name The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file.(optional);
|
||||
* \param filter A capture filter to be used on the file. (optional)
|
||||
*/
|
||||
FileSniffer(const std::string& file_name, const std::string& filter = "");
|
||||
|
||||
/**
|
||||
* \deprecated Use the constructor that takes a SnifferConfiguration instead.
|
||||
*
|
||||
* \brief Constructs an instance of FileSniffer.
|
||||
* \param fp The pcap file which will be parsed.
|
||||
* \param filter A capture filter to be used on the file. (optional)
|
||||
*/
|
||||
FileSniffer(FILE *fp, const std::string& filter = "");
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -411,8 +465,14 @@ HandlerProxy<T> make_sniffer_handler(T* ptr,
|
||||
/**
|
||||
* \brief Iterates over packets sniffed by a BaseSniffer.
|
||||
*/
|
||||
class SnifferIterator : public std::iterator<std::forward_iterator_tag, Packet> {
|
||||
class SnifferIterator {
|
||||
public:
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef Packet value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef Packet* pointer;
|
||||
typedef Packet& reference;
|
||||
|
||||
/**
|
||||
* Constructs a SnifferIterator.
|
||||
* \param sniffer The sniffer to iterate.
|
||||
@@ -562,6 +622,12 @@ public:
|
||||
*/
|
||||
void set_filter(const std::string& filter);
|
||||
|
||||
/**
|
||||
* Sets the pcap sniffing method to use.
|
||||
* \param method The sniffing method to be used.
|
||||
*/
|
||||
void set_pcap_sniffing_method(BaseSniffer::PcapSniffingMethod method);
|
||||
|
||||
/**
|
||||
* Sets the rfmon option.
|
||||
* \param enabled The rfmon option value.
|
||||
@@ -603,6 +669,7 @@ protected:
|
||||
IMMEDIATE_MODE = 16,
|
||||
DIRECTION = 32,
|
||||
TIMESTAMP_PRECISION = 64,
|
||||
PCAP_SNIFFING_METHOD = 128,
|
||||
};
|
||||
|
||||
void configure_sniffer_pre_activation(Sniffer& sniffer) const;
|
||||
@@ -614,6 +681,7 @@ protected:
|
||||
unsigned snap_len_;
|
||||
unsigned buffer_size_;
|
||||
std::string filter_;
|
||||
BaseSniffer::PcapSniffingMethod pcap_sniffing_method_;
|
||||
unsigned timeout_;
|
||||
bool promisc_;
|
||||
bool rfmon_;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,11 +30,11 @@
|
||||
#ifndef TINS_STP_H
|
||||
#define TINS_STP_H
|
||||
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "hw_address.h"
|
||||
#include "small_uint.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/hw_address.h>
|
||||
#include <tins/small_uint.h>
|
||||
|
||||
namespace Tins {
|
||||
/**
|
||||
@@ -305,7 +305,7 @@ private:
|
||||
static bpdu_id_type convert(const pvt_bpdu_id& id);
|
||||
static pvt_bpdu_id convert(const bpdu_id_type& id);
|
||||
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
|
||||
stp_header header_;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,18 +30,15 @@
|
||||
#ifndef TINS_TCP_H
|
||||
#define TINS_TCP_H
|
||||
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include "pdu.h"
|
||||
#include "macros.h"
|
||||
#include "endianness.h"
|
||||
#include "small_uint.h"
|
||||
#include "pdu_option.h"
|
||||
#include "cxxstd.h"
|
||||
#include <tins/pdu.h>
|
||||
#include <tins/macros.h>
|
||||
#include <tins/endianness.h>
|
||||
#include <tins/small_uint.h>
|
||||
#include <tins/pdu_option.h>
|
||||
#include <tins/cxxstd.h>
|
||||
|
||||
namespace Tins {
|
||||
namespace Memory {
|
||||
@@ -112,7 +109,9 @@ public:
|
||||
SACK_OK = 4,
|
||||
SACK = 5,
|
||||
TSOPT = 8,
|
||||
ALTCHK = 14
|
||||
ALTCHK = 14,
|
||||
RFC_EXPERIMENT_1 = 253,
|
||||
RFC_EXPERIMENT_2 = 254
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -132,7 +131,7 @@ public:
|
||||
/**
|
||||
* The type used to store the options.
|
||||
*/
|
||||
typedef std::list<option> options_type;
|
||||
typedef std::vector<option> options_type;
|
||||
|
||||
/**
|
||||
* The type used to store the sack option.
|
||||
@@ -289,13 +288,29 @@ public:
|
||||
* \code
|
||||
* TCP tcp = ...;
|
||||
* if(tcp.flags() == (TCP::SYN | TCP::ACK)) {
|
||||
* // It's a SYN+ACK!
|
||||
* // It's a SYN+ACK, but not SYN+ACK+ECN!
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \return The value of the flags field.
|
||||
*/
|
||||
small_uint<12> flags() const;
|
||||
|
||||
/**
|
||||
* \brief Check if the given flags are set.
|
||||
*
|
||||
* \code
|
||||
* TCP tcp = ...;
|
||||
* if(tcp.has_flags(TCP::SYN | TCP::ACK)) {
|
||||
* // It's a SYN+ACK, but it also possible that other flags are set!
|
||||
* // it is equivalent to: (tpc.flags() & (TCP::SYN | TCP::ACK)) == (TCP::SYN | TCP::ACK)
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* \param check_flags
|
||||
* \return true if all check_flags are set
|
||||
*/
|
||||
bool has_flags(small_uint<12> check_flags) const;
|
||||
|
||||
/* Setters */
|
||||
|
||||
@@ -478,7 +493,6 @@ public:
|
||||
* \param option The option to be added.
|
||||
*/
|
||||
void add_option(option &&opt) {
|
||||
internal_add_option(opt);
|
||||
options_.push_back(std::move(opt));
|
||||
}
|
||||
|
||||
@@ -493,7 +507,6 @@ public:
|
||||
template <typename... Args>
|
||||
void add_option(Args&&... args) {
|
||||
options_.emplace_back(std::forward<Args>(args)...);
|
||||
internal_add_option(options_.back());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -609,18 +622,17 @@ private:
|
||||
return opt->to<T>();
|
||||
}
|
||||
|
||||
void internal_add_option(const option& option);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
||||
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||
void checksum(uint16_t new_check);
|
||||
void update_options_size();
|
||||
uint32_t calculate_options_size() const;
|
||||
uint32_t pad_options_size(uint32_t size) const;
|
||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||
options_type::iterator search_option_iterator(OptionTypes type);
|
||||
|
||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||
|
||||
tcp_header header_;
|
||||
uint16_t options_size_, total_options_size_;
|
||||
options_type options_;
|
||||
tcp_header header_;
|
||||
};
|
||||
|
||||
} // Tins
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
FILE(GLOB INCLUDE_FILES "*.h")
|
||||
INSTALL(
|
||||
FILES ${INCLUDE_FILES}
|
||||
DESTINATION include/tins/tcp_ip
|
||||
COMPONENT Headers
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,13 +30,13 @@
|
||||
#ifndef TINS_TCP_IP_ACK_TRACKER_H
|
||||
#define TINS_TCP_IP_ACK_TRACKER_H
|
||||
|
||||
#include "../config.h"
|
||||
#include <tins/config.h>
|
||||
|
||||
#ifdef TINS_HAVE_ACK_TRACKER
|
||||
|
||||
#include <vector>
|
||||
#include <boost/icl/interval_set.hpp>
|
||||
#include "../macros.h"
|
||||
#include <tins/macros.h>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Matias Fontanini
|
||||
* Copyright (c) 2017, Matias Fontanini
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,8 +33,8 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include "../config.h"
|
||||
#include "../macros.h"
|
||||
#include <tins/config.h>
|
||||
#include <tins/macros.h>
|
||||
|
||||
#ifdef TINS_HAVE_TCPIP
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user