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

Merge branch 'develop'

Ugh
This commit is contained in:
Matias Fontanini
2017-12-20 07:05:32 -08:00
5 changed files with 26 additions and 1 deletions

View File

@@ -356,6 +356,7 @@ private:
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);
TINS_BEGIN_PACK
struct ipv6_header {

View File

@@ -244,8 +244,9 @@ public:
* \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_);
rhs.inner_pdu_ = 0;
if (inner_pdu_) {
inner_pdu_->parent_pdu(this);
}

View File

@@ -164,6 +164,11 @@ bool IPv6::is_extension_header(uint8_t header_id) {
|| header_id == MOBILITY || header_id == NO_NEXT_HEADER;
}
uint32_t IPv6::get_padding_size(const ext_header& header) {
const uint32_t padding = (header.data_size() + sizeof(uint8_t) * 2) % 8;
return padding == 0 ? 0 : (8 - padding);
}
void IPv6::version(small_uint<4> new_version) {
header_.version = new_version;
}
@@ -337,6 +342,8 @@ uint32_t IPv6::calculate_headers_size() const {
uint32_t output = 0;
for (const_iterator iter = ext_headers_.begin(); iter != ext_headers_.end(); ++iter) {
output += static_cast<uint32_t>(iter->data_size() + sizeof(uint8_t) * 2);
output += get_padding_size(*iter);
}
return output;
}
@@ -346,6 +353,8 @@ void IPv6::write_header(const ext_header& header, OutputMemoryStream& stream) {
stream.write(header.option());
stream.write(length);
stream.write(header.data_ptr(), header.data_size());
// Append padding
stream.fill(get_padding_size(header), 0);
}
} // Tins

View File

@@ -360,3 +360,9 @@ TEST_F(IPv6Test, OptionAddition) {
EXPECT_TRUE(ipv6.search_header(IPv6::ROUTING) != 0);
EXPECT_TRUE(ipv6.search_header(IPv6::AUTHENTICATION) != 0);
}
TEST_F(IPv6Test, HopByHopPadding) {
IPv6 ipv6_header;
ipv6_header.add_header(IPv6::ExtensionHeader::HOP_BY_HOP);
EXPECT_EQ(48UL, ipv6_header.serialize().size());
}

View File

@@ -83,6 +83,14 @@ TEST_F(PDUTest, OperatorConcatOnPacket) {
EXPECT_TRUE(std::equal(raw->payload().begin(), raw->payload().end(), raw_payload.begin()));
}
#if TINS_IS_CXX11
TEST_F(PDUTest, MoveAssignment) {
IP packet = IP("192.168.0.1") / TCP(22, 52);
packet = IP("1.2.3.4");
EXPECT_TRUE(packet.inner_pdu() == 0);
}
#endif // TINS_IS_CXX11
TEST_F(PDUTest, TinsCast) {
PDU* null_pdu = 0;
TCP tcp;