mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 10:45:57 +01:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3aedc56ed | ||
|
|
3b006c15db | ||
|
|
177d0b4621 | ||
|
|
24ac038c30 | ||
|
|
a619e4ff98 | ||
|
|
14bb185d7a | ||
|
|
137b56d5a7 | ||
|
|
ed2b3c12d5 | ||
|
|
1650b60234 | ||
|
|
c20c82bcb5 | ||
|
|
5858132261 | ||
|
|
16f5795243 | ||
|
|
e90e377b73 | ||
|
|
222611b377 | ||
|
|
b447c664e1 | ||
|
|
468159e6d2 | ||
|
|
cd40b232e7 | ||
|
|
1166094a2f | ||
|
|
b3d874d6a8 | ||
|
|
553b1fb255 | ||
|
|
94939dd0fa | ||
|
|
0774a8dcad |
18
CHANGES.md
18
CHANGES.md
@@ -1,3 +1,21 @@
|
||||
##### 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)
|
||||
|
||||
@@ -46,7 +46,7 @@ ENDIF(LIBTINS_BUILD_SHARED)
|
||||
|
||||
# The version number.
|
||||
SET(TINS_VERSION_MAJOR 4)
|
||||
SET(TINS_VERSION_MINOR 3)
|
||||
SET(TINS_VERSION_MINOR 4)
|
||||
SET(TINS_VERSION_PATCH 0)
|
||||
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
|
||||
|
||||
|
||||
@@ -652,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.
|
||||
*/
|
||||
@@ -661,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.
|
||||
@@ -671,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.
|
||||
*/
|
||||
@@ -680,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.
|
||||
@@ -690,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.
|
||||
*/
|
||||
@@ -699,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.
|
||||
@@ -709,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.
|
||||
@@ -719,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.
|
||||
*/
|
||||
@@ -728,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.
|
||||
@@ -738,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.
|
||||
@@ -748,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.
|
||||
*/
|
||||
@@ -757,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.
|
||||
*/
|
||||
@@ -766,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.
|
||||
*/
|
||||
@@ -775,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.
|
||||
*/
|
||||
@@ -784,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.
|
||||
*/
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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_);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,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
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,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>).
|
||||
|
||||
@@ -336,7 +336,11 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
|
||||
const uint8_t* end = &records_data_[0] + records_data_.size();
|
||||
const uint8_t* end_ptr = 0;
|
||||
char* current_out_ptr = out_ptr;
|
||||
uint8_t pointer_counter = 0;
|
||||
while (*ptr) {
|
||||
if (pointer_counter++ > 30){
|
||||
throw dns_decompression_pointer_loops();
|
||||
}
|
||||
// It's an offset
|
||||
if ((*ptr & 0xc0)) {
|
||||
if (TINS_UNLIKELY(ptr + sizeof(uint16_t) > end)) {
|
||||
@@ -347,7 +351,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
|
||||
index = Endian::be_to_host(index) & 0x3fff;
|
||||
// Check that the offset is neither too low or too high
|
||||
if (index < 0x0c || (&records_data_[0] + (index - 0x0c)) >= end) {
|
||||
throw malformed_packet();
|
||||
throw dns_decompression_pointer_out_of_bounds();
|
||||
}
|
||||
// We've probably found the end of the original domain name. Save it.
|
||||
if (end_ptr == 0) {
|
||||
|
||||
@@ -98,7 +98,7 @@ void ICMP::sequence(uint16_t new_seq) {
|
||||
}
|
||||
|
||||
void ICMP::gateway(address_type new_gw) {
|
||||
header_.un.gateway = Endian::host_to_be(static_cast<uint32_t>(new_gw));
|
||||
header_.un.gateway = static_cast<uint32_t>(new_gw);
|
||||
}
|
||||
|
||||
void ICMP::mtu(uint16_t new_mtu) {
|
||||
@@ -122,7 +122,7 @@ void ICMP::transmit_timestamp(uint32_t new_timestamp) {
|
||||
}
|
||||
|
||||
void ICMP::address_mask(address_type new_mask) {
|
||||
orig_timestamp_or_address_mask_ = Endian::host_to_be(static_cast<uint32_t>(new_mask));
|
||||
orig_timestamp_or_address_mask_ = static_cast<uint32_t>(new_mask);
|
||||
}
|
||||
|
||||
uint32_t ICMP::header_size() const {
|
||||
|
||||
10
src/ipv6.cpp
10
src/ipv6.cpp
@@ -32,6 +32,9 @@
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <tins/ipv6.h>
|
||||
@@ -366,11 +369,16 @@ void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||
}
|
||||
|
||||
#ifndef BSD
|
||||
void IPv6::send(PacketSender& sender, const NetworkInterface &) {
|
||||
void IPv6::send(PacketSender& sender, const NetworkInterface& interface) {
|
||||
sockaddr_in6 link_addr;
|
||||
const PacketSender::SocketType type = PacketSender::IPV6_SOCKET;
|
||||
link_addr.sin6_family = AF_INET6;
|
||||
link_addr.sin6_port = 0;
|
||||
// Required to set sin6_scope_id to interface index as stated in RFC2553.
|
||||
// https://datatracker.ietf.org/doc/html/rfc2553#section-3.3
|
||||
if (IPv6Address(header_.dst_addr).is_local_unicast()) {
|
||||
link_addr.sin6_scope_id = interface.id();
|
||||
}
|
||||
memcpy((uint8_t*)&link_addr.sin6_addr, header_.dst_addr, address_type::address_size);
|
||||
sender.send_l3(*this, (struct sockaddr*)&link_addr, sizeof(link_addr), type);
|
||||
}
|
||||
|
||||
@@ -267,6 +267,11 @@ void PacketSender::open_l3_socket(SocketType type) {
|
||||
#endif
|
||||
const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP;
|
||||
if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) {
|
||||
#ifndef _WIN32
|
||||
::close(sockfd);
|
||||
#else
|
||||
::closesocket(sockfd);
|
||||
#endif
|
||||
throw socket_open_error(make_error_string());
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,7 @@ vector<char> query_route_table(int family) {
|
||||
throw exception_base("sysctl failed");
|
||||
}
|
||||
|
||||
buf.resize(len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user