mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Merge branch 'master' of ssh://git.code.sf.net/p/libtins/code
This commit is contained in:
370
include/dot11.h
370
include/dot11.h
File diff suppressed because it is too large
Load Diff
@@ -107,8 +107,6 @@ public:
|
||||
*/
|
||||
const data_type *data_ptr() const {
|
||||
return &*(++value_.begin());
|
||||
|
||||
//return &value_[1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -84,11 +84,16 @@ void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) {
|
||||
}
|
||||
|
||||
void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) {
|
||||
uint32_t opt_size = len + (sizeof(uint8_t) << 1);
|
||||
uint32_t opt_size = len + sizeof(uint8_t) * 2;
|
||||
_options.push_back(dot11_option((uint8_t)opt, len, val));
|
||||
_options_size += opt_size;
|
||||
}
|
||||
|
||||
void Dot11::add_tagged_option(const dot11_option &opt) {
|
||||
_options.push_back(opt);
|
||||
_options_size += opt.data_size() + sizeof(uint8_t) * 2;
|
||||
}
|
||||
|
||||
const Dot11::dot11_option *Dot11::search_option(TaggedOption opt) const {
|
||||
for(std::list<dot11_option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
|
||||
if(it->option() == (uint8_t)opt)
|
||||
@@ -243,15 +248,6 @@ Dot11 *Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) {
|
||||
ret = new Dot11(buffer, total_sz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Dot11::copy_80211_fields(const Dot11 *other) {
|
||||
std::memcpy(&_header, &other->_header, sizeof(_header));
|
||||
_iface = other->_iface;
|
||||
_options_size = other->_options_size;
|
||||
for(std::list<dot11_option>::const_iterator it = other->_options.begin(); it != other->_options.end(); ++it)
|
||||
_options.push_back(dot11_option(it->option(), it->data_size(), it->data_ptr()));
|
||||
}
|
||||
|
||||
/* Dot11ManagementFrame */
|
||||
|
||||
Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz)
|
||||
@@ -280,13 +276,6 @@ const address_type &src_hw_addr)
|
||||
addr2(src_hw_addr);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) {
|
||||
Dot11::copy_80211_fields(other);
|
||||
std::memcpy(&_ext_header, &other->_ext_header, sizeof(_ext_header));
|
||||
//std::memcpy(_addr4, other->_addr4, 6);
|
||||
_addr4 = other->_addr4;
|
||||
}
|
||||
|
||||
uint32_t Dot11ManagementFrame::header_size() const {
|
||||
uint32_t sz = Dot11::header_size() + sizeof(_ext_header);
|
||||
if (this->from_ds() && this->to_ds())
|
||||
|
||||
@@ -9,7 +9,7 @@ using Tins::Dot11Data;
|
||||
using Tins::Dot11ControlTA;
|
||||
|
||||
typedef Dot11::address_type address_type;
|
||||
typedef Dot11ManagementFrame::CapabilityInformation CapabilityInformation;
|
||||
typedef Dot11ManagementFrame::capability_information capability_information;
|
||||
|
||||
inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) {
|
||||
EXPECT_EQ(dot1.protocol(), dot2.protocol());
|
||||
@@ -51,7 +51,7 @@ inline void test_equals(const Dot11ControlTA& b1, const Dot11ControlTA& b2) {
|
||||
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
|
||||
}
|
||||
|
||||
inline void test_equals(const CapabilityInformation &info1, const CapabilityInformation &info2) {
|
||||
inline void test_equals(const capability_information &info1, const capability_information &info2) {
|
||||
EXPECT_EQ(info1.ess(), info2.ess());
|
||||
EXPECT_EQ(info1.ibss(), info2.ibss());
|
||||
EXPECT_EQ(info1.cf_poll(), info2.cf_poll());
|
||||
@@ -145,7 +145,7 @@ inline void test_equals_empty(const Dot11ControlTA &dot11) {
|
||||
EXPECT_EQ(dot11.addr1(), empty_addr);
|
||||
}
|
||||
|
||||
inline void test_equals_empty(const CapabilityInformation &info) {
|
||||
inline void test_equals_empty(const capability_information &info) {
|
||||
EXPECT_EQ(info.ess(), 0);
|
||||
EXPECT_EQ(info.ibss(), 0);
|
||||
EXPECT_EQ(info.cf_poll(), 0);
|
||||
|
||||
@@ -33,27 +33,27 @@ void DNSTest::test_equals(const DNS &dns1, const DNS &dns2) {
|
||||
EXPECT_EQ(dns1.authenticated_data(), dns2.authenticated_data());
|
||||
EXPECT_EQ(dns1.checking_disabled(), dns2.checking_disabled());
|
||||
EXPECT_EQ(dns1.rcode(), dns2.rcode());
|
||||
EXPECT_EQ(dns1.questions(), dns2.questions());
|
||||
EXPECT_EQ(dns1.answers(), dns2.answers());
|
||||
EXPECT_EQ(dns1.authority(), dns2.authority());
|
||||
EXPECT_EQ(dns1.additional(), dns2.additional());
|
||||
EXPECT_EQ(dns1.questions_count(), dns2.questions_count());
|
||||
EXPECT_EQ(dns1.answers_count(), dns2.answers_count());
|
||||
EXPECT_EQ(dns1.authority_count(), dns2.authority_count());
|
||||
EXPECT_EQ(dns1.additional_count(), dns2.additional_count());
|
||||
EXPECT_EQ(dns1.pdu_type(), dns2.pdu_type());
|
||||
EXPECT_EQ(dns1.header_size(), dns2.header_size());
|
||||
EXPECT_EQ(bool(dns1.inner_pdu()), bool(dns2.inner_pdu()));
|
||||
}
|
||||
|
||||
void DNSTest::test_equals(const DNS::Query &q1, const DNS::Query &q2) {
|
||||
EXPECT_EQ(q1.name, q2.name);
|
||||
EXPECT_EQ(q1.type, q2.type);
|
||||
EXPECT_EQ(q1.qclass, q2.qclass);
|
||||
EXPECT_EQ(q1.dname(), q2.dname());
|
||||
EXPECT_EQ(q1.type(), q2.type());
|
||||
EXPECT_EQ(q1.query_class(), q2.query_class());
|
||||
}
|
||||
|
||||
void DNSTest::test_equals(const DNS::Resource &q1, const DNS::Resource &q2) {
|
||||
EXPECT_EQ(q1.dname, q2.dname);
|
||||
EXPECT_EQ(q1.addr, q2.addr);
|
||||
EXPECT_EQ(q1.type, q2.type);
|
||||
EXPECT_EQ(q1.qclass, q2.qclass);
|
||||
EXPECT_EQ(q1.ttl, q2.ttl);
|
||||
EXPECT_EQ(q1.dname(), q2.dname());
|
||||
EXPECT_EQ(q1.data(), q2.data());
|
||||
EXPECT_EQ(q1.type(), q2.type());
|
||||
EXPECT_EQ(q1.query_class(), q2.query_class());
|
||||
EXPECT_EQ(q1.ttl(), q2.ttl());
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, ConstructorFromBuffer) {
|
||||
@@ -68,18 +68,25 @@ TEST_F(DNSTest, ConstructorFromBuffer) {
|
||||
EXPECT_EQ(dns.recursion_available(), 1);
|
||||
EXPECT_EQ(dns.z(), 0);
|
||||
EXPECT_EQ(dns.rcode(), 0xa);
|
||||
EXPECT_EQ(dns.questions(), 1);
|
||||
EXPECT_EQ(dns.answers(), 1);
|
||||
EXPECT_EQ(dns.questions_count(), 1);
|
||||
EXPECT_EQ(dns.answers_count(), 1);
|
||||
|
||||
std::list<DNS::Query> queries = dns.dns_queries();
|
||||
std::list<DNS::Query> queries = dns.queries();
|
||||
ASSERT_EQ(queries.size(), 1);
|
||||
test_equals(queries.front(), DNS::Query("www.example.com", DNS::A, DNS::IN));
|
||||
|
||||
std::list<DNS::Resource> answers = dns.dns_answers();
|
||||
std::list<DNS::Resource> answers = dns.answers();
|
||||
ASSERT_EQ(answers.size(), 1);
|
||||
test_equals(answers.front(), DNS::Resource("www.example.com", "192.168.0.1", DNS::A, DNS::IN, 0x1234));
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, Serialization) {
|
||||
DNS dns(expected_packet, sizeof(expected_packet));
|
||||
DNS::serialization_type buffer = dns.serialize();
|
||||
ASSERT_EQ(buffer.size(), sizeof(expected_packet));
|
||||
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, CopyConstructor) {
|
||||
DNS dns1(expected_packet, sizeof(expected_packet));
|
||||
DNS dns2(dns1);
|
||||
@@ -172,44 +179,44 @@ TEST_F(DNSTest, RCode) {
|
||||
|
||||
TEST_F(DNSTest, Question) {
|
||||
DNS dns;
|
||||
dns.add_query("www.example.com", DNS::A, DNS::IN);
|
||||
dns.add_query("www.example2.com", DNS::MX, DNS::IN);
|
||||
ASSERT_EQ(dns.questions(), 2);
|
||||
dns.add_query(DNS::Query("www.example.com", DNS::A, DNS::IN));
|
||||
dns.add_query(DNS::Query("www.example2.com", DNS::MX, DNS::IN));
|
||||
ASSERT_EQ(dns.questions_count(), 2);
|
||||
|
||||
DNS::queries_type queries(dns.dns_queries());
|
||||
DNS::queries_type queries(dns.queries());
|
||||
for(DNS::queries_type::const_iterator it = queries.begin(); it != queries.end(); ++it) {
|
||||
EXPECT_TRUE(it->name == "www.example.com" || it->name == "www.example2.com");
|
||||
if(it->name == "www.example.com") {
|
||||
EXPECT_EQ(it->type, DNS::A);
|
||||
EXPECT_EQ(it->qclass, DNS::IN);
|
||||
EXPECT_TRUE(it->dname() == "www.example.com" || it->dname() == "www.example2.com");
|
||||
if(it->dname() == "www.example.com") {
|
||||
EXPECT_EQ(it->type(), DNS::A);
|
||||
EXPECT_EQ(it->query_class(), DNS::IN);
|
||||
}
|
||||
else if(it->name == "www.example2.com") {
|
||||
EXPECT_EQ(it->type, DNS::MX);
|
||||
EXPECT_EQ(it->qclass, DNS::IN);
|
||||
else if(it->dname() == "www.example2.com") {
|
||||
EXPECT_EQ(it->type(), DNS::MX);
|
||||
EXPECT_EQ(it->query_class(), DNS::IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DNSTest, Answers) {
|
||||
DNS dns;
|
||||
dns.add_answer("www.example.com", DNS::A, DNS::IN, 0x762, IPv4Address("127.0.0.1"));
|
||||
dns.add_answer("www.example2.com", DNS::MX, DNS::IN, 0x762, IPv4Address("127.0.0.1"));
|
||||
ASSERT_EQ(dns.answers(), 2);
|
||||
dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.1"));
|
||||
dns.add_answer("www.example2.com", DNS::make_info(DNS::MX, DNS::IN, 0x762), IPv4Address("127.0.0.1"));
|
||||
ASSERT_EQ(dns.answers_count(), 2);
|
||||
|
||||
DNS::resources_type resources(dns.dns_answers());
|
||||
DNS::resources_type resources = dns.answers();
|
||||
for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
|
||||
EXPECT_TRUE(it->dname == "www.example.com" || it->dname == "www.example2.com");
|
||||
if(it->dname == "www.example.com") {
|
||||
EXPECT_EQ(it->type, DNS::A);
|
||||
EXPECT_EQ(it->ttl, 0x762);
|
||||
EXPECT_EQ(it->addr, "127.0.0.1");
|
||||
EXPECT_EQ(it->qclass, DNS::IN);
|
||||
EXPECT_TRUE(it->dname() == "www.example.com" || it->dname() == "www.example2.com");
|
||||
if(it->dname() == "www.example.com") {
|
||||
EXPECT_EQ(it->type(), DNS::A);
|
||||
EXPECT_EQ(it->ttl(), 0x762);
|
||||
EXPECT_EQ(it->data(), "127.0.0.1");
|
||||
EXPECT_EQ(it->query_class(), DNS::IN);
|
||||
}
|
||||
else if(it->dname == "www.example2.com") {
|
||||
EXPECT_EQ(it->type, DNS::MX);
|
||||
EXPECT_EQ(it->ttl, 0x762);
|
||||
EXPECT_EQ(it->addr, "127.0.0.1");
|
||||
EXPECT_EQ(it->qclass, DNS::IN);
|
||||
else if(it->dname() == "www.example2.com") {
|
||||
EXPECT_EQ(it->type(), DNS::MX);
|
||||
EXPECT_EQ(it->ttl(), 0x762);
|
||||
EXPECT_EQ(it->data(), "127.0.0.1");
|
||||
EXPECT_EQ(it->query_class(), DNS::IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void test_equals_expected(const Dot11Beacon &dot11) {
|
||||
EXPECT_EQ(dot11.timestamp(), 0x1fad2341289301faLL);
|
||||
EXPECT_EQ(dot11.interval(), 0x14fa);
|
||||
|
||||
const Dot11Beacon::CapabilityInformation &info = dot11.capabilities();
|
||||
const Dot11Beacon::capability_information &info = dot11.capabilities();
|
||||
EXPECT_EQ(info.ess(), 1);
|
||||
EXPECT_EQ(info.ibss(), 0);
|
||||
EXPECT_EQ(info.cf_poll(), 1);
|
||||
|
||||
@@ -151,7 +151,7 @@ TEST_F(Dot11Test, Addr1) {
|
||||
|
||||
TEST_F(Dot11Test, AddTaggedOption) {
|
||||
Dot11 dot11;
|
||||
dot11.add_tagged_option(Dot11::SSID, hwaddr.size(), hwaddr.begin());
|
||||
dot11.add_tagged_option(Dot11::dot11_option(Dot11::SSID, hwaddr.begin(), hwaddr.end()));
|
||||
const Dot11::dot11_option *option;
|
||||
ASSERT_TRUE((option = dot11.search_option(Dot11::SSID)));
|
||||
EXPECT_EQ(option->data_size(), hwaddr.size());
|
||||
|
||||
Reference in New Issue
Block a user