diff --git a/include/tins/dns.h b/include/tins/dns.h index 742a0ddf..23b7a8a5 100644 --- a/include/tins/dns.h +++ b/include/tins/dns.h @@ -963,7 +963,7 @@ class TINS_API DNS : public PDU { * \param domain_name The domain name to encode. * \return The encoded domain name. */ - static std::string encode_domain_name(const std::string& domain_name); + static std::string encode_domain_name(const std::string& dn); /** * \brief Decodes a domain name diff --git a/include/tins/dot11/dot11_mgmt.h b/include/tins/dot11/dot11_mgmt.h index 7367bd42..0e09591d 100644 --- a/include/tins/dot11/dot11_mgmt.h +++ b/include/tins/dot11/dot11_mgmt.h @@ -818,7 +818,7 @@ class TINS_API Dot11ManagementFrame : public Dot11 { * * \param elements The new list of elements. */ - void request_information(const request_info_type elements); + void request_information(const request_info_type& elements); /** * \brief Helper method to set the FH parameter set tagged option. diff --git a/include/tins/eapol.h b/include/tins/eapol.h index 2fd3aacc..bc75e2aa 100644 --- a/include/tins/eapol.h +++ b/include/tins/eapol.h @@ -131,25 +131,25 @@ class TINS_API EAPOL : public PDU { * \brief Sets the version field. * \param value The new version to be set. */ - void version(uint8_t value); + void version(uint8_t new_version); /** * \brief Sets the packet type field. * \param value The new packet type to be set. */ - void packet_type(uint8_t value); + void packet_type(uint8_t new_ptype); /** * \brief Sets the length field. * \param value The new length to be set. */ - void length(uint16_t value); + void length(uint16_t new_length); /** * \brief Sets the type field. * \param value The new type to be set. */ - void type(uint8_t value); + void type(uint8_t new_type); /** * \brief Getter for the PDU's type. @@ -297,7 +297,7 @@ class TINS_API RC4EAPOL : public EAPOL { * \brief Sets the key length field. * \param value The new key length to be set. */ - void key_length(uint16_t value); + void key_length(uint16_t length); /** * \brief Sets the replay counter field. @@ -309,31 +309,31 @@ class TINS_API RC4EAPOL : public EAPOL { * \brief Sets the key IV field. * \param value The new key IV to be set. */ - void key_iv(const uint8_t* value); + void key_iv(const uint8_t* ptr); /** * \brief Sets the key flag field. * \param value The new key flag to be set. */ - void key_flag(small_uint<1> value); + void key_flag(small_uint<1> flag); /** * \brief Sets the key index field. * \param value The new key index to be set. */ - void key_index(small_uint<7> value); + void key_index(small_uint<7> new_key_index); /** * \brief Sets the key signature field. * \param value The new key signature to be set. */ - void key_sign(const uint8_t* value); + void key_sign(const uint8_t* ptr); /** * \brief Sets the key field. * \param value The new key to be set. */ - void key(const key_type& value); + void key(const key_type& new_key); /* Virtual method override. */ @@ -618,13 +618,13 @@ class TINS_API RSNEAPOL : public EAPOL { * \brief Sets the key length field. * \param value The new key length to be set. */ - void key_length(uint16_t value); + void key_length(uint16_t length); /** * \brief Sets the replay counter field. * \param value The new replay counter to be set. */ - void replay_counter(uint64_t value); + void replay_counter(uint64_t new_replay_counter); /** * \brief Sets the key IV field. @@ -692,13 +692,13 @@ class TINS_API RSNEAPOL : public EAPOL { * \brief Setter for the key_mic field. * \param value The new to be set. */ - void key_mic(small_uint<1> value); + void key_mic(small_uint<1> flag); /** * \brief Setter for the secure field. * \param value The new to be set. */ - void secure(small_uint<1> value); + void secure(small_uint<1> flag); /** * \brief Setter for the error field. @@ -722,7 +722,7 @@ class TINS_API RSNEAPOL : public EAPOL { * \brief Setter for the key_descriptor field. * \param value The new to be set. */ - void key_descriptor(small_uint<3> value); + void key_descriptor(small_uint<3> new_key_descriptor); /** * \brief Setter for the key_t field. diff --git a/src/address_range.cpp b/src/address_range.cpp index e03d0628..70ac5de1 100644 --- a/src/address_range.cpp +++ b/src/address_range.cpp @@ -49,4 +49,4 @@ IPv6Range operator/(const IPv6Address& addr, int mask) { return IPv6Range::from_mask(addr, IPv6Address::from_prefix_length(mask)); } -} // Tins +} // namespace Tins diff --git a/src/arp.cpp b/src/arp.cpp index 63b49379..fbc8e5e1 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -52,8 +52,8 @@ ARP::ARP(ipaddress_type target_ip, const hwaddress_type& target_hw, const hwaddress_type& sender_hw) : header_() { - hw_addr_format((uint16_t)Constants::ARP::ETHER); - prot_addr_format((uint16_t)Constants::Ethernet::IP); + hw_addr_format(static_cast(Constants::ARP::ETHER)); + prot_addr_format(static_cast(Constants::Ethernet::IP)); hw_addr_length(Tins::EthernetII::address_type::address_size); prot_addr_length(4 /* IP address size */); sender_ip_addr(sender_ip); @@ -119,7 +119,7 @@ bool ARP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const arp_header* arp_ptr = (const arp_header*)ptr; + const arp_header* arp_ptr = reinterpret_cast(ptr); return arp_ptr->sender_ip_address == header_.target_ip_address && arp_ptr->target_ip_address == header_.sender_ip_address; } @@ -150,4 +150,4 @@ EthernetII ARP::make_arp_reply(ipaddress_type target, return EthernetII(hw_tgt, hw_snd) / arp; } -} // Tins +} // namespace Tins diff --git a/src/bootp.cpp b/src/bootp.cpp index 343a6b7f..e22be805 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -124,8 +124,8 @@ bool BootP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(bootp_)) { return false; } - const bootp_header* bootp_ptr = (const bootp_header *)ptr; + const bootp_header* bootp_ptr = reinterpret_cast(ptr); return bootp_ptr->xid == bootp_.xid; } -} // Tins +} // namespace Tins diff --git a/src/crypto.cpp b/src/crypto.cpp index cf335303..df9f778b 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -100,7 +100,7 @@ class byte_array { uint8_t data[n]; }; -} // Internals +} // namespace Internals namespace Crypto { @@ -228,7 +228,7 @@ struct RC4Key { static RC4Key from_packet(const Dot11Data& dot11, const RawPDU& raw, const vector& ptk) { const RawPDU::payload_type& pload = raw.payload(); - const uint8_t* tk = &ptk[0] + 32; + const uint8_t* tk = ptk.data() + 32; Internals::byte_array<16> rc4_key; uint16_t ppk[6]; const Dot11::address_type addr = dot11.addr2(); @@ -367,7 +367,7 @@ PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) { RC4Key key(key_buffer_.begin(), key_buffer_.begin() + password.size() + 3); rc4(pload.begin() + 4, pload.end(), key, pload.begin()); uint32_t payload_size = static_cast(pload.size() - 8); - uint32_t crc = Utils::crc32(&pload[0], payload_size); + uint32_t crc = Utils::crc32(pload.data(), payload_size); if (pload[pload.size() - 8] != (crc & 0xff) || pload[pload.size() - 7] != ((crc >> 8) & 0xff) || pload[pload.size() - 6] != ((crc >> 16) & 0xff) || @@ -376,7 +376,7 @@ PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) { } try { - return new SNAP(&pload[0], payload_size); + return new SNAP(pload.data(), payload_size); } catch (exception_base&) { return 0; @@ -448,16 +448,16 @@ SessionKeys::SessionKeys(const RSNHandshake& hs, const pmk_type& pmk) } for (int i(0); i < 4; ++i) { PKE[99] = i; - HMAC(EVP_sha1(), &pmk[0], pmk.size(), PKE, 100, &ptk_[0] + i * 20, 0); + HMAC(EVP_sha1(), pmk.data(), pmk.size(), PKE, 100, (ptk_).data() + i * 20, 0); } RSNEAPOL& last_hs = const_cast(hs.handshake()[3]); PDU::serialization_type buffer = last_hs.serialize(); fill(buffer.begin() + 81, buffer.begin() + 81 + 16, 0); if (is_ccmp_) { - HMAC(EVP_sha1(), &ptk_[0], 16, &buffer[0], buffer.size(), MIC, 0); + HMAC(EVP_sha1(), ptk_.data(), 16, buffer.data(), buffer.size(), MIC, 0); } else { - HMAC(EVP_md5(), &ptk_[0], 16, &buffer[0], buffer.size(), MIC, 0); + HMAC(EVP_md5(), ptk_.data(), 16, buffer.data(), buffer.size(), MIC, 0); } if (!equal(MIC, MIC + RSNEAPOL::mic_size, last_hs.mic())) { @@ -479,7 +479,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con uint8_t AAD[32] = {0}; AAD[0] = 0; - AAD[1] = 22 + 6 * int(dot11.from_ds() && dot11.to_ds()); + AAD[1] = 22 + 6 * static_cast(dot11.from_ds() && dot11.to_ds()); if (dot11.subtype() == Dot11::QOS_DATA_DATA) { AAD[1] += 2; } @@ -498,7 +498,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con } AES_KEY ctx; - AES_set_encrypt_key(&ptk_[0] + 32, 128, &ctx); + AES_set_encrypt_key(ptk_.data() + 32, 128, &ctx); uint8_t crypted_block[16]; size_t total_sz = raw.payload_size() - 16, offset = 8, blocks = (total_sz + 15) / 16; @@ -544,7 +544,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con offset += block_sz; } if (equal(nice_MIC, nice_MIC + sizeof(nice_MIC), MIC)) { - return new SNAP(&pload[0], total_sz); + return new SNAP(pload.data(), total_sz); } else { return 0; @@ -560,7 +560,7 @@ SNAP* SessionKeys::tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con RawPDU::payload_type& pload = raw.payload(); rc4(pload.begin() + 8, pload.end(), key, pload.begin()); - uint32_t crc = Utils::crc32(&pload[0], pload.size() - 12); + uint32_t crc = Utils::crc32(pload.data(), pload.size() - 12); if (pload[pload.size() - 12] != (crc & 0xff) || pload[pload.size() - 11] != ((crc >> 8) & 0xff) || pload[pload.size() - 10] != ((crc >> 16) & 0xff) || @@ -568,7 +568,7 @@ SNAP* SessionKeys::tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con return 0; } - return new SNAP(&pload[0], pload.size() - 20); + return new SNAP(pload.data(), pload.size() - 20); } SNAP* SessionKeys::decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const { @@ -596,7 +596,7 @@ SupplicantData::SupplicantData(const string& psk, const string& ssid) ssid.size(), 4096, pmk_.size(), - &pmk_[0] + pmk_.data() ); } diff --git a/src/detail/address_helpers.cpp b/src/detail/address_helpers.cpp index 811d5969..5c7ad2c5 100644 --- a/src/detail/address_helpers.cpp +++ b/src/detail/address_helpers.cpp @@ -74,5 +74,5 @@ IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask) { return addr; } -} // Internals -} // Tins +} // namespace Internals +} // namespace Tins diff --git a/src/detail/icmp_extension_helpers.cpp b/src/detail/icmp_extension_helpers.cpp index 2293a2da..b98a1f45 100644 --- a/src/detail/icmp_extension_helpers.cpp +++ b/src/detail/icmp_extension_helpers.cpp @@ -82,5 +82,5 @@ void try_parse_icmp_extensions(InputMemoryStream& stream, } } -} // Internals -} // Tins +} // namespace Internals +} // namespace Tins diff --git a/src/detail/pdu_helpers.cpp b/src/detail/pdu_helpers.cpp index bb8f4e54..d378ae7b 100644 --- a/src/detail/pdu_helpers.cpp +++ b/src/detail/pdu_helpers.cpp @@ -299,5 +299,5 @@ PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) { }; } -} // Internals -} // Tins +} // namespace Internals +} // namespace Tins diff --git a/src/detail/sequence_number_helpers.cpp b/src/detail/sequence_number_helpers.cpp index b7c4d227..19817ec3 100644 --- a/src/detail/sequence_number_helpers.cpp +++ b/src/detail/sequence_number_helpers.cpp @@ -46,5 +46,5 @@ int seq_compare(uint32_t seq1, uint32_t seq2) { } } -} // Internals -} // Tins +} // namespace Internals +} // namespace Tins diff --git a/src/dhcp.cpp b/src/dhcp.cpp index f513099f..9b872d82 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -69,7 +69,7 @@ DHCP::DHCP(const uint8_t* buffer, uint32_t total_sz) while (stream) { OptionTypes option_type; uint8_t option_length = 0; - option_type = (OptionTypes)stream.read(); + option_type = static_cast(stream.read()); // We should only read the length if it's not END nor PAD if (option_type != END && option_type != PAD) { option_length = stream.read(); @@ -131,7 +131,7 @@ uint8_t DHCP::type() const { void DHCP::server_identifier(ipaddress_type ip) { uint32_t ip_int = ip; - add_option(option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), (const uint8_t*)&ip_int)); + add_option(option(DHCP_SERVER_IDENTIFIER, sizeof(uint32_t), reinterpret_cast(&ip_int))); } DHCP::ipaddress_type DHCP::server_identifier() const { @@ -140,7 +140,7 @@ DHCP::ipaddress_type DHCP::server_identifier() const { void DHCP::lease_time(uint32_t time) { time = Endian::host_to_be(time); - add_option(option(DHCP_LEASE_TIME, sizeof(uint32_t), (const uint8_t*)&time)); + add_option(option(DHCP_LEASE_TIME, sizeof(uint32_t), reinterpret_cast(&time))); } uint32_t DHCP::lease_time() const { @@ -149,7 +149,7 @@ uint32_t DHCP::lease_time() const { void DHCP::renewal_time(uint32_t time) { time = Endian::host_to_be(time); - add_option(option(DHCP_RENEWAL_TIME, sizeof(uint32_t), (const uint8_t*)&time)); + add_option(option(DHCP_RENEWAL_TIME, sizeof(uint32_t), reinterpret_cast(&time))); } uint32_t DHCP::renewal_time() const { @@ -158,7 +158,7 @@ uint32_t DHCP::renewal_time() const { void DHCP::subnet_mask(ipaddress_type mask) { uint32_t mask_int = mask; - add_option(option(SUBNET_MASK, sizeof(uint32_t), (const uint8_t*)&mask_int)); + add_option(option(SUBNET_MASK, sizeof(uint32_t), reinterpret_cast(&mask_int))); } DHCP::ipaddress_type DHCP::subnet_mask() const { @@ -185,7 +185,7 @@ vector DHCP::domain_name_servers() const { void DHCP::broadcast(ipaddress_type addr) { uint32_t int_addr = addr; - add_option(option(BROADCAST_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr)); + add_option(option(BROADCAST_ADDRESS, sizeof(uint32_t), reinterpret_cast(&int_addr))); } DHCP::ipaddress_type DHCP::broadcast() const { @@ -194,7 +194,7 @@ DHCP::ipaddress_type DHCP::broadcast() const { void DHCP::requested_ip(ipaddress_type addr) { uint32_t int_addr = addr; - add_option(option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), (uint8_t*)&int_addr)); + add_option(option(DHCP_REQUESTED_ADDRESS, sizeof(uint32_t), reinterpret_cast(&int_addr))); } DHCP::ipaddress_type DHCP::requested_ip() const { @@ -202,7 +202,7 @@ DHCP::ipaddress_type DHCP::requested_ip() const { } void DHCP::domain_name(const string& name) { - add_option(option(DOMAIN_NAME, name.size(), (const uint8_t*)name.c_str())); + add_option(option(DOMAIN_NAME, name.size(), reinterpret_cast(name.c_str()))); } string DHCP::domain_name() const { @@ -210,7 +210,7 @@ string DHCP::domain_name() const { } void DHCP::hostname(const string& name) { - add_option(option(HOST_NAME, name.size(), (const uint8_t*)name.c_str())); + add_option(option(HOST_NAME, name.size(), reinterpret_cast(name.c_str()))); } string DHCP::hostname() const { @@ -219,7 +219,7 @@ string DHCP::hostname() const { void DHCP::rebind_time(uint32_t time) { time = Endian::host_to_be(time); - add_option(option(DHCP_REBINDING_TIME, sizeof(uint32_t), (uint8_t*)&time)); + add_option(option(DHCP_REBINDING_TIME, sizeof(uint32_t), reinterpret_cast(&time))); } uint32_t DHCP::rebind_time() const { @@ -228,7 +228,7 @@ uint32_t DHCP::rebind_time() const { PDU::serialization_type DHCP::serialize_list(const vector& ip_list) { serialization_type buffer(ip_list.size() * sizeof(uint32_t)); - uint32_t* ptr = (uint32_t*)&buffer[0]; + uint32_t* ptr = reinterpret_cast(buffer.data()); typedef vector::const_iterator iterator; for (iterator it = ip_list.begin(); it != ip_list.end(); ++it) { *(ptr++) = *it; @@ -245,7 +245,7 @@ void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz) { vend_type& result = BootP::vend(); result.resize(size_); // Build a stream over the vend vector - OutputMemoryStream stream(&result[0], result.size()); + OutputMemoryStream stream(result.data(), result.size()); // Magic cookie stream.write(Endian::host_to_be(0x63825363)); for (options_type::const_iterator it = options_.begin(); it != options_.end(); ++it) { @@ -257,4 +257,4 @@ void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz) { BootP::write_serialization(buffer, total_sz); } -} // Tins +} // namespace Tins diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index 196e851f..2236ec68 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -88,7 +88,7 @@ OutputType option2class_option_data(const uint8_t* ptr, uint32_t total_sz) { return output; } -} // Internals +} // namespace Internals PDU::metadata DHCPv6::extract_metadata(const uint8_t* /*buffer*/, uint32_t total_sz) { if (TINS_UNLIKELY(total_sz < 2)) { @@ -109,7 +109,7 @@ DHCPv6::DHCPv6(const uint8_t* buffer, uint32_t total_sz) throw malformed_packet(); } // Relay Agent/Server Messages - const MessageType message_type = (MessageType)*stream.pointer(); + const MessageType message_type = static_cast(*stream.pointer()); bool is_relay_msg = (message_type == RELAY_FORWARD || message_type == RELAY_REPLY); uint32_t required_size = is_relay_msg ? 2 : 4; stream.read(&header_data_, required_size); @@ -349,7 +349,7 @@ void DHCPv6::preference(uint8_t value) { void DHCPv6::elapsed_time(uint16_t value) { value = Endian::host_to_be(value); - add_option(option(ELAPSED_TIME, 2, (const uint8_t*)&value)); + add_option(option(ELAPSED_TIME, 2, reinterpret_cast(&value))); } void DHCPv6::relay_message(const relay_msg_type& value) { diff --git a/src/dns.cpp b/src/dns.cpp index abd8046c..7e65c403 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -69,7 +69,7 @@ DNS::DNS(const uint8_t* buffer, uint32_t total_sz) skip_to_dname_end(stream); stream.skip(sizeof(uint16_t) * 2); } - const uint8_t* base_offset = &records_data_[0]; + const uint8_t* base_offset = records_data_.data(); answers_idx_ = static_cast(stream.pointer() - base_offset); skip_to_section_end(stream, answers_count()); authority_idx_ = static_cast(stream.pointer() - base_offset); @@ -171,7 +171,7 @@ void DNS::add_query(const query& query) { new_str.insert(new_str.end(), sizeof(uint16_t) * 2, ' '); // Build a stream at the end OutputMemoryStream stream( - (uint8_t*)&new_str[0] + previous_length, + reinterpret_cast(const_cast(new_str.data())) + previous_length, sizeof(uint16_t) * 2 ); stream.write_be(query.query_type()); @@ -240,7 +240,7 @@ void DNS::add_record(const resource& resource, const sections_type& sections) { offset, 0 ); - OutputMemoryStream stream(&records_data_[0] + threshold, offset); + OutputMemoryStream stream(records_data_.data() + threshold, offset); stream.write(buffer.begin(), buffer.end()); stream.write_be(resource.query_type()); stream.write_be(resource.query_class()); @@ -300,7 +300,7 @@ string DNS::decode_domain_name(const string& domain_name) { if (domain_name.empty()) { return output; } - const uint8_t* ptr = (const uint8_t*)&domain_name[0]; + const uint8_t* ptr = reinterpret_cast(domain_name.data()); const uint8_t* end = ptr + domain_name.size(); while (*ptr) { // We can't handle offsets @@ -333,7 +333,7 @@ string DNS::decode_domain_name(const string& domain_name) { // unsafe but a lot faster. uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const { const uint8_t* start_ptr = ptr; - const uint8_t* end = &records_data_[0] + records_data_.size(); + const uint8_t* end = records_data_.data() + records_data_.size(); const uint8_t* end_ptr = 0; char* current_out_ptr = out_ptr; uint8_t pointer_counter = 0; @@ -350,7 +350,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const { memcpy(&index, ptr, sizeof(uint16_t)); 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) { + if (index < 0x0c || (records_data_.data() + (index - 0x0c)) >= end) { throw dns_decompression_pointer_out_of_bounds(); } // We've probably found the end of the original domain name. Save it. @@ -554,14 +554,14 @@ void DNS::update_records(uint32_t& section_start, DNS::queries_type DNS::queries() const { queries_type output; if (!records_data_.empty()) { - InputMemoryStream stream(&records_data_[0], answers_idx_); + InputMemoryStream stream(records_data_.data(), answers_idx_); char buffer[256]; while (stream) { stream.skip(compose_name(stream.pointer(), buffer)); uint16_t query_type = stream.read_be(); uint16_t query_class = stream.read_be(); #if TINS_IS_CXX11 - output.emplace_back(buffer, (QueryType)query_type, (QueryClass)query_class); + output.emplace_back(buffer, static_cast(query_type), static_cast(query_class)); #else output.push_back( query(buffer, (QueryType)query_type, (QueryClass)query_class) @@ -576,8 +576,8 @@ DNS::resources_type DNS::answers() const { resources_type res; if (answers_idx_ < records_data_.size()) { convert_records( - &records_data_[0] + answers_idx_, - &records_data_[0] + authority_idx_, + records_data_.data() + answers_idx_, + records_data_.data() + authority_idx_, res, answers_count() ); @@ -589,8 +589,8 @@ DNS::resources_type DNS::authority() const { resources_type res; if (authority_idx_ < records_data_.size()) { convert_records( - &records_data_[0] + authority_idx_, - &records_data_[0] + additional_idx_, + records_data_.data() + authority_idx_, + records_data_.data() + additional_idx_, res, authority_count() ); @@ -602,8 +602,8 @@ DNS::resources_type DNS::additional() const { resources_type res; if (additional_idx_ < records_data_.size()) { convert_records( - &records_data_[0] + additional_idx_, - &records_data_[0] + records_data_.size(), + records_data_.data() + additional_idx_, + records_data_.data() + records_data_.size(), res, additional_count() ); @@ -615,7 +615,7 @@ bool DNS::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const dns_header* hdr = (const dns_header*)ptr; + const dns_header* hdr = reinterpret_cast(ptr); return hdr->id == header_.id; } @@ -643,7 +643,7 @@ DNS::soa_record::soa_record(const uint8_t* buffer, uint32_t total_sz) { } DNS::soa_record::soa_record(const DNS::resource& resource) { - init((const uint8_t*)&resource.data()[0], resource.data().size()); + init(reinterpret_cast(resource.data().data()), resource.data().size()); } void DNS::soa_record::mname(const string& value) { @@ -693,10 +693,10 @@ PDU::serialization_type DNS::soa_record::serialize() const { void DNS::soa_record::init(const uint8_t* buffer, uint32_t total_sz) { InputMemoryStream stream(buffer, total_sz); - string domain = (const char*)stream.pointer(); + string domain = reinterpret_cast(stream.pointer()); mname_ = DNS::decode_domain_name(domain); stream.skip(domain.size() + 1); - domain = (const char*)stream.pointer(); + domain = reinterpret_cast(stream.pointer()); stream.skip(domain.size() + 1); rname_ = DNS::decode_domain_name(domain); serial_ = stream.read_be(); @@ -706,4 +706,4 @@ void DNS::soa_record::init(const uint8_t* buffer, uint32_t total_sz) { minimum_ttl_ = stream.read_be(); } -} // Tins +} // namespace Tins diff --git a/src/dot11/dot11_assoc.cpp b/src/dot11/dot11_assoc.cpp index 48da516a..d286af17 100644 --- a/src/dot11/dot11_assoc.cpp +++ b/src/dot11/dot11_assoc.cpp @@ -190,6 +190,6 @@ void Dot11ReAssocResponse::write_fixed_parameters(OutputMemoryStream& stream) { stream.write(body_); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_auth.cpp b/src/dot11/dot11_auth.cpp index a67817e9..8e3cedc2 100644 --- a/src/dot11/dot11_auth.cpp +++ b/src/dot11/dot11_auth.cpp @@ -102,6 +102,6 @@ void Dot11Deauthentication::write_fixed_parameters(OutputMemoryStream& stream) { stream.write(body_); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index cc324442..5640fa2b 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -95,7 +95,7 @@ void Dot11::parse_tagged_parameters(InputMemoryStream& stream) { void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t* val) { uint32_t opt_size = len + sizeof(uint8_t) * 2; - options_.push_back(option((uint8_t)opt, val, val + len)); + options_.push_back(option(static_cast(opt), val, val + len)); options_size_ += opt_size; } @@ -204,7 +204,7 @@ void Dot11::send(PacketSender& sender, const NetworkInterface& iface) { addr.sll_halen = 6; addr.sll_ifindex = iface.id(); memcpy(&(addr.sll_addr), header_.addr1, 6); - sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr), iface); + sender.send_l2(*this, reinterpret_cast(&addr), static_cast(sizeof(addr)), iface); #else sender.send_l2(*this, 0, 0, iface); #endif @@ -230,7 +230,7 @@ Dot11* Dot11::from_bytes(const uint8_t* buffer, uint32_t total_sz) { if (total_sz < 2) { throw malformed_packet(); } - const dot11_header* hdr = (const dot11_header*)buffer; + const dot11_header* hdr = reinterpret_cast(buffer); if (hdr->control.type == MANAGEMENT) { switch (hdr->control.subtype) { case BEACON: @@ -289,6 +289,6 @@ Dot11* Dot11::from_bytes(const uint8_t* buffer, uint32_t total_sz) { return new Dot11(buffer, total_sz); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_beacon.cpp b/src/dot11/dot11_beacon.cpp index 602c524f..e9725cb4 100644 --- a/src/dot11/dot11_beacon.cpp +++ b/src/dot11/dot11_beacon.cpp @@ -70,6 +70,6 @@ void Dot11Beacon::write_fixed_parameters(OutputMemoryStream& stream) { stream.write(body_); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_control.cpp b/src/dot11/dot11_control.cpp index eb2d1b91..68641e1f 100644 --- a/src/dot11/dot11_control.cpp +++ b/src/dot11/dot11_control.cpp @@ -248,6 +248,6 @@ uint32_t Dot11BlockAck::header_size() const { sizeof(start_sequence_) + sizeof(bitmap_); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_data.cpp b/src/dot11/dot11_data.cpp index 775f9268..10092be5 100644 --- a/src/dot11/dot11_data.cpp +++ b/src/dot11/dot11_data.cpp @@ -159,6 +159,6 @@ void Dot11QoSData::write_fixed_parameters(OutputMemoryStream& stream) { stream.write(qos_control_); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot11/dot11_mgmt.cpp b/src/dot11/dot11_mgmt.cpp index 0579f7d3..6d04cc50 100644 --- a/src/dot11/dot11_mgmt.cpp +++ b/src/dot11/dot11_mgmt.cpp @@ -114,18 +114,18 @@ void Dot11ManagementFrame::ssid(const string& new_ssid) { add_tagged_option( Dot11::SSID, static_cast(new_ssid.size()), - (const uint8_t*)new_ssid.c_str() + reinterpret_cast(new_ssid.c_str()) ); } void Dot11ManagementFrame::rsn_information(const RSNInformation& info) { RSNInformation::serialization_type buffer = info.serialize(); - add_tagged_option(RSN, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(RSN, static_cast(buffer.size()), buffer.data()); } vector Dot11ManagementFrame::serialize_rates(const rates_type& rates) { vector buffer(rates.size()); - uint8_t* ptr = &buffer[0]; + uint8_t* ptr = buffer.data(); for (rates_type::const_iterator it = rates.begin(); it != rates.end(); ++it) { uint8_t result = static_cast(*it * 2); if (result == 2 || result == 4 || result == 11 || result == 22) { @@ -140,19 +140,19 @@ Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const o rates_type output; const uint8_t* ptr = opt->data_ptr(), *end = ptr + opt->data_size(); while (ptr != end) { - output.push_back(float(*(ptr++) & 0x7f) / 2); + output.push_back(static_cast(*(ptr++) & 0x7f) / 2); } return output; } void Dot11ManagementFrame::supported_rates(const rates_type& new_rates) { vector buffer = serialize_rates(new_rates); - add_tagged_option(SUPPORTED_RATES, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(SUPPORTED_RATES, static_cast(buffer.size()), buffer.data()); } void Dot11ManagementFrame::extended_supported_rates(const rates_type& new_rates) { vector buffer = serialize_rates(new_rates); - add_tagged_option(EXT_SUPPORTED_RATES, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(EXT_SUPPORTED_RATES, static_cast(buffer.size()), buffer.data()); } void Dot11ManagementFrame::qos_capability(qos_capability_type new_qos_capability) { @@ -168,12 +168,12 @@ void Dot11ManagementFrame::power_capability(uint8_t min_power, uint8_t max_power void Dot11ManagementFrame::supported_channels(const channels_type& new_channels) { vector buffer(new_channels.size() * 2); - uint8_t* ptr = &buffer[0]; + uint8_t* ptr = buffer.data(); for (channels_type::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) { *(ptr++) = it->first; *(ptr++) = it->second; } - add_tagged_option(SUPPORTED_CHANNELS, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(SUPPORTED_CHANNELS, static_cast(buffer.size()), buffer.data()); } void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { @@ -188,8 +188,8 @@ void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, ui add_tagged_option(EDCA, sizeof(buffer), buffer); } -void Dot11ManagementFrame::request_information(const request_info_type elements) { - add_tagged_option(REQUEST_INFORMATION, static_cast(elements.size()), &elements[0]); +void Dot11ManagementFrame::request_information(const request_info_type& elements) { + add_tagged_option(REQUEST_INFORMATION, static_cast(elements.size()), elements.data()); } void Dot11ManagementFrame::fh_parameter_set(const fh_params_set& fh_params) { @@ -218,7 +218,7 @@ void Dot11ManagementFrame::cf_parameter_set(const cf_params_set& params) { void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) { atim_window = Endian::host_to_le(atim_window); - add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window); + add_tagged_option(IBSS_SET, 2, reinterpret_cast(&atim_window)); } void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params& params) { @@ -233,7 +233,7 @@ void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params& params) { stream.write(it->second); } - add_tagged_option(IBSS_DFS, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(IBSS_DFS, static_cast(buffer.size()), buffer.data()); } void Dot11ManagementFrame::country(const country_params& params) { @@ -250,13 +250,13 @@ void Dot11ManagementFrame::country(const country_params& params) { sz++; } vector buffer(sz); - uint8_t* ptr = copy(params.country.begin(), params.country.end(), &buffer[0]); + uint8_t* ptr = copy(params.country.begin(), params.country.end(), buffer.data()); for (size_t i(0); i < params.first_channel.size(); ++i) { *(ptr++) = params.first_channel[i]; *(ptr++) = params.number_channels[i]; *(ptr++) = params.max_transmit_power[i]; } - add_tagged_option(COUNTRY, static_cast(sz), &buffer[0]); + add_tagged_option(COUNTRY, static_cast(sz), buffer.data()); } void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { @@ -268,7 +268,7 @@ void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_cha void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type& params) { vector data(sizeof(uint8_t) * 4 + params.random_table.size()); - uint8_t* ptr = &data[0]; + uint8_t* ptr = data.data(); *(ptr++) = params.flag; *(ptr++) = params.number_of_sets; *(ptr++) = params.modulus; @@ -277,7 +277,7 @@ void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type& params) { for (; it != params.random_table.end(); ++it) { *(ptr++) = *it; } - add_tagged_option(HOPPING_PATTERN_TABLE, static_cast(data.size()), &data[0]); + add_tagged_option(HOPPING_PATTERN_TABLE, static_cast(data.size()), data.data()); } void Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) { @@ -351,14 +351,14 @@ void Dot11ManagementFrame::tim(const tim_type& data) { data.partial_virtual_bitmap.begin(), data.partial_virtual_bitmap.end() ); - add_tagged_option(TIM, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(TIM, static_cast(buffer.size()), buffer.data()); } void Dot11ManagementFrame::challenge_text(const string& text) { add_tagged_option( CHALLENGE_TEXT, static_cast(text.size()), - (const uint8_t*)text.c_str() + reinterpret_cast(text.c_str()) ); } @@ -369,7 +369,7 @@ void Dot11ManagementFrame::vendor_specific(const vendor_specific_type& data) { data.data.end(), data.oui.copy(buffer.begin()) ); - add_tagged_option(VENDOR_SPECIFIC, static_cast(buffer.size()), &buffer[0]); + add_tagged_option(VENDOR_SPECIFIC, static_cast(buffer.size()), buffer.data()); } // Getters @@ -639,6 +639,6 @@ Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim_type::from_option(const return output; } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/dot1q.cpp b/src/dot1q.cpp index 462a4a38..7e85f99c 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -58,7 +58,7 @@ Dot1Q::Dot1Q(const uint8_t* buffer, uint32_t total_sz) if (stream) { inner_pdu( Internals::pdu_from_flag( - (Constants::Ethernet::e)payload_type(), + static_cast(payload_type()), stream.pointer(), stream.size() ) @@ -146,7 +146,7 @@ bool Dot1Q::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const dot1q_header* dot1q_ptr = (const dot1q_header*)ptr; + const dot1q_header* dot1q_ptr = reinterpret_cast(ptr); if (get_id(dot1q_ptr) == get_id(&header_)) { ptr += sizeof(header_); total_sz -= sizeof(header_); @@ -156,4 +156,4 @@ bool Dot1Q::matches_response(const uint8_t* ptr, uint32_t total_sz) const { } -} // Tins +} // namespace Tins diff --git a/src/dot3.cpp b/src/dot3.cpp index a0b247e9..5bdefe1e 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -119,7 +119,7 @@ bool Dot3::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const dot3_header* eth_ptr = (const dot3_header*)ptr; + const dot3_header* eth_ptr = reinterpret_cast(ptr); if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac)) { if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac) || dst_addr() == BROADCAST) { @@ -152,7 +152,7 @@ PDU* Dot3::recv_response(PacketSender& sender, const NetworkInterface& iface) { addr.sll_ifindex = iface.id(); memcpy(&(addr.sll_addr), header_.dst_mac, sizeof(header_.dst_mac)); - return sender.recv_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr)); + return sender.recv_l2(*this, reinterpret_cast(&addr), static_cast(sizeof(addr))); #else return sender.recv_l2(*this, 0, 0, iface); #endif @@ -160,4 +160,4 @@ PDU* Dot3::recv_response(PacketSender& sender, const NetworkInterface& iface) { #endif // _WIN32 -} // Tins +} // namespace Tins diff --git a/src/eapol.cpp b/src/eapol.cpp index 7d8aa05f..0253d525 100644 --- a/src/eapol.cpp +++ b/src/eapol.cpp @@ -45,7 +45,7 @@ PDU::metadata EAPOL::extract_metadata(const uint8_t *buffer, uint32_t total_sz) if (TINS_UNLIKELY(total_sz < sizeof(eapol_header))) { throw malformed_packet(); } - const eapol_header* header = (const eapol_header*)buffer; + const eapol_header* header = reinterpret_cast(buffer); uint32_t advertised_size = Endian::be_to_host(header->length) + 4; const uint32_t actual_size = (total_sz < advertised_size) ? total_sz : advertised_size; return metadata(actual_size, pdu_flag, PDU::UNKNOWN); @@ -55,7 +55,7 @@ EAPOL::EAPOL(uint8_t packet_type, EAPOLTYPE type) : header_() { header_.version = 1; header_.packet_type = packet_type; - header_.type = (uint8_t)type; + header_.type = static_cast(type); } EAPOL::EAPOL(const uint8_t* buffer, uint32_t total_sz) { @@ -67,7 +67,7 @@ EAPOL* EAPOL::from_bytes(const uint8_t* buffer, uint32_t total_sz) { if (TINS_UNLIKELY(total_sz < sizeof(eapol_header))) { throw malformed_packet(); } - const eapol_header* ptr = (const eapol_header*)buffer; + const eapol_header* ptr = reinterpret_cast(buffer); uint32_t data_len = Endian::be_to_host(ptr->length); // at least 4 for fields always present data_len += 4; @@ -161,7 +161,7 @@ uint32_t RC4EAPOL::header_size() const { } void RC4EAPOL::write_body(OutputMemoryStream& stream) { - if (key_.size()) { + if (!key_.empty()) { header_.key_length = Endian::host_to_be(static_cast(key_.size())); } stream.write(header_); @@ -270,12 +270,12 @@ uint32_t RSNEAPOL::header_size() const { } void RSNEAPOL::write_body(OutputMemoryStream& stream) { - if (key_.size()) { + if (!key_.empty()) { if (!header_.key_t && header_.install) { header_.key_length = Endian::host_to_be(32); wpa_length(static_cast(key_.size())); } - else if (key_.size()) { + else if (!key_.empty()) { wpa_length(static_cast(key_.size())); } } @@ -283,4 +283,4 @@ void RSNEAPOL::write_body(OutputMemoryStream& stream) { stream.write(key_.begin(), key_.end()); } -} // Tins +} // namespace Tins diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index b3b0688d..b9af196a 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -58,7 +58,7 @@ PDU::metadata EthernetII::extract_metadata(const uint8_t *buffer, uint32_t total if (TINS_UNLIKELY(total_sz < sizeof(ethernet_header))) { throw malformed_packet(); } - const ethernet_header* header = (const ethernet_header*)buffer; + const ethernet_header* header = reinterpret_cast(buffer); PDUType next_type = Internals::ether_type_to_pdu_flag( static_cast(Endian::be_to_host(header->payload_type))); return metadata(sizeof(ethernet_header), pdu_flag, next_type); @@ -78,7 +78,7 @@ EthernetII::EthernetII(const uint8_t* buffer, uint32_t total_sz) { if (stream) { inner_pdu( Internals::pdu_from_flag( - (Constants::Ethernet::e)payload_type(), + static_cast(payload_type()), stream.pointer(), stream.size() ) @@ -141,7 +141,7 @@ bool EthernetII::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const ethernet_header* eth_ptr = (const ethernet_header*)ptr; + const ethernet_header* eth_ptr = reinterpret_cast(ptr); if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac)) { if (address_type(header_.src_mac) == address_type(eth_ptr->dst_mac) || !dst_addr().is_unicast()) { @@ -208,11 +208,11 @@ PDU* EthernetII::recv_response(PacketSender& sender, const NetworkInterface& ifa addr.sll_ifindex = iface.id(); memcpy(&(addr.sll_addr), header_.dst_mac, address_type::address_size); - return sender.recv_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr)); + return sender.recv_l2(*this, reinterpret_cast(&addr), static_cast(sizeof(addr))); #else return sender.recv_l2(*this, 0, 0, iface); #endif } #endif // _WIN32 -} // Tins +} // namespace Tins diff --git a/src/handshake_capturer.cpp b/src/handshake_capturer.cpp index 384f74ee..d144b7bc 100644 --- a/src/handshake_capturer.cpp +++ b/src/handshake_capturer.cpp @@ -102,6 +102,6 @@ bool RSNHandshakeCapturer::do_insert(const handshake_map::key_type& key, return false; } -} // namespace Tins; +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/hw_address.cpp b/src/hw_address.cpp index 691428d9..3fb97b69 100644 --- a/src/hw_address.cpp +++ b/src/hw_address.cpp @@ -121,5 +121,5 @@ bool hw_address_gt_compare(const uint8_t* start1, const uint8_t* end1, return lexicographical_compare(start2, end2, start1, end1); } -} // Internals -} // Tins +} // namespace Internals +} // namespace Tins diff --git a/src/icmp.cpp b/src/icmp.cpp index 2b1dd8b2..34ae178f 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -300,7 +300,7 @@ bool ICMP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(icmp_header)) { return false; } - const icmp_header* icmp_ptr = (const icmp_header*)ptr; + const icmp_header* icmp_ptr = reinterpret_cast(ptr); if ((header_.type == ECHO_REQUEST && icmp_ptr->type == ECHO_REPLY) || (header_.type == TIMESTAMP_REQUEST && icmp_ptr->type == TIMESTAMP_REPLY) || (header_.type == ADDRESS_MASK_REQUEST && icmp_ptr->type == ADDRESS_MASK_REPLY)) { diff --git a/src/icmp_extension.cpp b/src/icmp_extension.cpp index 480fa342..bdfac875 100644 --- a/src/icmp_extension.cpp +++ b/src/icmp_extension.cpp @@ -93,7 +93,7 @@ void ICMPExtension::serialize(uint8_t* buffer, uint32_t buffer_size) const { ICMPExtension::serialization_type ICMPExtension::serialize() const { serialization_type output(size()); - serialize(&output[0], output.size()); + serialize(output.data(), output.size()); return output; } @@ -187,8 +187,8 @@ void ICMPExtensionsStructure::serialize(uint8_t* buffer, uint32_t buffer_size) { ICMPExtensionsStructure::serialization_type ICMPExtensionsStructure::serialize() { serialization_type output(size()); - serialize(&output[0], output.size()); + serialize(output.data(), output.size()); return output; } -} // Tins +} // namespace Tins diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 449e01bb..a2349f32 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -274,7 +274,7 @@ bool ICMPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const icmp6_header* hdr_ptr = (const icmp6_header*)ptr; + const icmp6_header* hdr_ptr = reinterpret_cast(ptr); if (type() == ECHO_REQUEST && hdr_ptr->type == ECHO_REPLY) { return hdr_ptr->u_echo.identifier == header_.u_echo.identifier && hdr_ptr->u_echo.sequence == header_.u_echo.sequence; @@ -1104,5 +1104,4 @@ uint32_t ICMPv6::multicast_address_record::size() const { aux_data.size(); } -} // Tins - +} // namespace Tins diff --git a/src/ip.cpp b/src/ip.cpp index 897ebed0..35f23bc2 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -61,7 +61,7 @@ PDU::metadata IP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) { if (TINS_UNLIKELY(total_sz < sizeof(ip_header))) { throw malformed_packet(); } - const ip_header* header = (const ip_header*)buffer; + const ip_header* header = reinterpret_cast(buffer); PDUType next_type = Internals::ip_type_to_pdu_flag( static_cast(header->protocol)); return metadata(header->ihl * 4, pdu_flag, next_type); @@ -86,7 +86,7 @@ IP::IP(const uint8_t* buffer, uint32_t total_sz) { // While the end of the options is not reached read an option while (stream.pointer() < options_end) { - option_identifier opt_type = (option_identifier)stream.read(); + option_identifier opt_type = option_identifier(stream.read()); if (opt_type.number > NOOP) { // Multibyte options with length as second byte const uint32_t option_size = stream.read(); @@ -124,7 +124,7 @@ IP::IP(const uint8_t* buffer, uint32_t total_sz) { // Don't avoid consuming more than we should if tot_len is 0, // since this is the case when using TCP segmentation offload if (tot_len() != 0) { - const uint32_t advertised_length = (uint32_t)tot_len() - head_len() * sizeof(uint32_t); + const uint32_t advertised_length = static_cast(tot_len()) - head_len() * sizeof(uint32_t); const uint32_t stream_size = static_cast(stream.size()); total_sz = (stream_size < advertised_length) ? stream_size : advertised_length; } @@ -263,7 +263,7 @@ void IP::stream_identifier(uint16_t stream_id) { option( 136, sizeof(uint16_t), - (const uint8_t*)&stream_id + reinterpret_cast(&stream_id) ) ); } @@ -285,7 +285,7 @@ void IP::add_route_option(option_identifier id, const generic_route_option_type& option( id, opt_data.size(), - &opt_data[0] + opt_data.data() ) ); } @@ -400,7 +400,7 @@ void IP::send(PacketSender& sender, const NetworkInterface &) { type = pdu_type_to_sender_type(inner_pdu()->pdu_type()); } - sender.send_l3(*this, (struct sockaddr*)&link_addr, sizeof(link_addr), type); + sender.send_l3(*this, reinterpret_cast(&link_addr), sizeof(link_addr), type); } PDU* IP::recv_response(PacketSender& sender, const NetworkInterface &) { @@ -468,14 +468,14 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz) { check = (check & 0xffff) + (check >> 16); } checksum(~check); - ((ip_header*)buffer)->check = header_.check; + (reinterpret_cast(buffer))->check = header_.check; } bool IP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const ip_header* ip_ptr = (const ip_header*)ptr; + const ip_header* ip_ptr = reinterpret_cast(ptr); // dest unreachable? if (ip_ptr->protocol == Constants::IP::PROTO_ICMP) { const uint8_t* pkt_ptr = ptr + sizeof(ip_header); @@ -538,4 +538,4 @@ IP::generic_route_option_type IP::generic_route_option_type::from_option(const o return output; } -} // Tins +} // namespace Tins diff --git a/src/ip_address.cpp b/src/ip_address.cpp index a091429c..095c50bd 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -161,4 +161,4 @@ IPv4Address IPv4Address::operator~() const { return IPv4Address(Endian::be_to_host(~ip_addr_)); } -} // Tins +} // namespace Tins diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index 744b4c30..b8af06b0 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -91,7 +91,7 @@ PDU* IPv4Stream::allocate_pdu() const { } return Internals::pdu_from_flag( static_cast(first_fragment_.protocol()), - buffer.empty() ? 0 :& buffer[0], + buffer.empty() ? 0 : buffer.data(), static_cast(buffer.size()) ); } @@ -104,7 +104,7 @@ uint16_t IPv4Stream::extract_offset(const IP* ip) { return ip->fragment_offset() * 8; } -} // Internals +} // namespace Internals IPv4Reassembler::IPv4Reassembler() : technique_(NONE) { @@ -178,4 +178,4 @@ void IPv4Reassembler::remove_stream(uint16_t id, IPv4Address addr1, IPv4Address ); } -} // Tins +} // namespace Tins diff --git a/src/ipsec.cpp b/src/ipsec.cpp index 7f69c3f4..d51f3e6e 100644 --- a/src/ipsec.cpp +++ b/src/ipsec.cpp @@ -136,4 +136,4 @@ void IPSecESP::write_serialization(uint8_t* buffer, uint32_t total_sz) { output.write(header_); } -} // Tins +} // namespace Tins diff --git a/src/ipv6.cpp b/src/ipv6.cpp index 416065b9..21fc5240 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -59,7 +59,7 @@ PDU::metadata IPv6::extract_metadata(const uint8_t *buffer, uint32_t total_sz) { throw malformed_packet(); } InputMemoryStream stream(buffer, total_sz); - const ipv6_header* header = (const ipv6_header*)buffer; + const ipv6_header* header = reinterpret_cast(buffer); uint32_t header_size = sizeof(ipv6_header); uint8_t current_header = header->next_header; stream.skip(sizeof(ipv6_header)); @@ -295,7 +295,7 @@ bool IPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(ipv6_header)) { return false; } - const ipv6_header* hdr_ptr = (const ipv6_header*)ptr; + const ipv6_header* hdr_ptr = reinterpret_cast(ptr); // checks for ff02 multicast if (src_addr() == hdr_ptr->dst_addr && (dst_addr() == hdr_ptr->src_addr || (header_.dst_addr[0] == 0xff && header_.dst_addr[1] == 0x02))) { @@ -379,8 +379,8 @@ void IPv6::send(PacketSender& sender, const NetworkInterface& interface) { 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); + memcpy(reinterpret_cast(&link_addr.sin6_addr), header_.dst_addr, address_type::address_size); + sender.send_l3(*this, reinterpret_cast(&link_addr), sizeof(link_addr), type); } PDU* IPv6::recv_response(PacketSender& sender, const NetworkInterface &) { @@ -440,4 +440,4 @@ void IPv6::write_header(const ext_header& header, OutputMemoryStream& stream) { stream.fill(get_padding_size(header), 0); } -} // Tins +} // namespace Tins diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index 82722131..bbcc12b5 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -176,4 +176,4 @@ IPv6Address IPv6Address::operator~() const { return result; } -} // Tins +} // namespace Tins diff --git a/src/llc.cpp b/src/llc.cpp index bcb27035..01f70d10 100644 --- a/src/llc.cpp +++ b/src/llc.cpp @@ -69,7 +69,7 @@ LLC::LLC(const uint8_t* buffer, uint32_t total_sz) { // TODO: Create information fields if corresponding. } else { - type((Format)(*stream.pointer() & 0x03)); + type(static_cast(*stream.pointer() & 0x03)); control_field_length_ = 2; stream.read(control_field.info); } @@ -219,4 +219,4 @@ void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz) { } } -} // Tins +} // namespace Tins diff --git a/src/loopback.cpp b/src/loopback.cpp index 0c0b4d6b..b75ac169 100644 --- a/src/loopback.cpp +++ b/src/loopback.cpp @@ -128,4 +128,4 @@ void Loopback::send(PacketSender& sender, const NetworkInterface& iface) { } #endif // _WIN32 -} // Tins +} // namespace Tins diff --git a/src/memory_helpers.cpp b/src/memory_helpers.cpp index d609a56f..f39a5cb8 100644 --- a/src/memory_helpers.cpp +++ b/src/memory_helpers.cpp @@ -81,5 +81,5 @@ void OutputMemoryStream::write(const IPv6Address& address) { write(address.begin(), address.end()); } -} // Memory -} // Tins +} // namespace Memory +} // namespace Tins diff --git a/src/mpls.cpp b/src/mpls.cpp index c43860fb..7a914513 100644 --- a/src/mpls.cpp +++ b/src/mpls.cpp @@ -107,4 +107,4 @@ void MPLS::write_serialization(uint8_t* buffer, uint32_t total_sz) { stream.write(header_); } -} // Tins +} // namespace Tins diff --git a/src/network_interface.cpp b/src/network_interface.cpp index 6b061b6a..c8df74cb 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -89,7 +89,7 @@ struct InterfaceInfoCollector { #else #define TINS_BROADCAST_ADDR(addr) (addr->ifa_broadaddr) #define TINS_BROADCAST_FLAGS (IFF_BROADCAST) - const struct sockaddr_ll* addr_ptr = ((struct sockaddr_ll*)addr->ifa_addr); + const struct sockaddr_ll* addr_ptr = (reinterpret_cast(addr->ifa_addr)); if (!addr->ifa_addr) { return false; @@ -102,11 +102,11 @@ struct InterfaceInfoCollector { #endif else if (!std::strcmp(addr->ifa_name, iface_name)) { if (addr->ifa_addr->sa_family == AF_INET) { - info->ip_addr = IPv4Address(((struct sockaddr_in *)addr->ifa_addr)->sin_addr.s_addr); - info->netmask = IPv4Address(((struct sockaddr_in *)addr->ifa_netmask)->sin_addr.s_addr); + info->ip_addr = IPv4Address((reinterpret_cast(addr->ifa_addr))->sin_addr.s_addr); + info->netmask = IPv4Address((reinterpret_cast(addr->ifa_netmask))->sin_addr.s_addr); if ((addr->ifa_flags & (TINS_BROADCAST_FLAGS))) { info->bcast_addr = IPv4Address( - ((struct sockaddr_in *)TINS_BROADCAST_ADDR(addr))->sin_addr.s_addr); + (reinterpret_castTINS_BROADCAST_ADDR(addr))->sin_addr.s_addr); } else { info->bcast_addr = 0; @@ -115,8 +115,8 @@ struct InterfaceInfoCollector { } else if (addr->ifa_addr->sa_family == AF_INET6) { Tins::NetworkInterface::IPv6Prefix prefix; - prefix.address = ((struct sockaddr_in6 *)addr->ifa_addr)->sin6_addr.s6_addr; - Tins::IPv6Address mask = ((struct sockaddr_in6 *)addr->ifa_netmask)->sin6_addr.s6_addr; + prefix.address = (reinterpret_cast(addr->ifa_addr))->sin6_addr.s6_addr; + Tins::IPv6Address mask = (reinterpret_cast(addr->ifa_netmask))->sin6_addr.s6_addr; prefix.prefix_length = 0; for (Tins::IPv6Address::iterator iter = mask.begin(); iter != mask.end(); ++iter) { if (*iter == 255) { @@ -196,7 +196,7 @@ namespace Tins { // static NetworkInterface NetworkInterface::default_interface() { - return NetworkInterface(IPv4Address(uint32_t(0))); + return NetworkInterface(IPv4Address(static_cast(0))); } vector NetworkInterface::all() { @@ -406,4 +406,4 @@ NetworkInterface::id_type NetworkInterface::resolve_index(const char* name) { #endif // _WIN32 } -} // Tins +} // namespace Tins diff --git a/src/offline_packet_filter.cpp b/src/offline_packet_filter.cpp index c57b8276..144eb21e 100644 --- a/src/offline_packet_filter.cpp +++ b/src/offline_packet_filter.cpp @@ -27,10 +27,10 @@ * */ -#include +#include +#include #include #include -#include using std::string; @@ -82,7 +82,7 @@ bool OfflinePacketFilter::matches_filter(const uint8_t* buffer, uint32_t total_s bool OfflinePacketFilter::matches_filter(PDU& pdu) const { PDU::serialization_type buffer = pdu.serialize(); - return matches_filter(&buffer[0], static_cast(buffer.size())); + return matches_filter(buffer.data(), static_cast(buffer.size())); } -} // Tins +} // namespace Tins diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index 96f7649e..f314b95a 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -45,9 +45,9 @@ #include #include #endif + #include #include #include - #include #else #include #include @@ -368,7 +368,7 @@ void PacketSender::send_l2(PDU& pdu, open_l2_socket(iface); pcap_t* handle = pcap_handles_[iface]; const int buf_size = static_cast(buffer.size()); - if (pcap_sendpacket(handle, (u_char*)&buffer[0], buf_size) != 0) { + if (pcap_sendpacket(handle, static_cast(buffer.data()), buf_size) != 0) { throw pcap_error("Failed to send packet: " + string(pcap_geterr(handle))); } #else // TINS_HAVE_PACKET_SENDER_PCAP_SENDPACKET @@ -424,7 +424,7 @@ void PacketSender::send_l3(PDU& pdu, int sock = sockets_[type]; PDU::serialization_type buffer = pdu.serialize(); const int buf_size = static_cast(buffer.size()); - if (sendto(sock, (const char*)&buffer[0], buf_size, 0, link_addr, len_addr) == -1) { + if (sendto(sock, reinterpret_cast(buffer.data()), buf_size, 0, link_addr, len_addr) == -1) { throw socket_write_error(make_error_string()); } } @@ -491,7 +491,7 @@ PDU* PacketSender::recv_match_loop(const vector& sockets, } else { socket_len_type length = addrlen; - size = ::recvfrom(*it, (char*)buffer, buffer_size, 0, link_addr, &length); + size = ::recvfrom(*it, reinterpret_cast(buffer), buffer_size, 0, link_addr, &length); if (pdu.matches_response(buffer, size)) { return Internals::pdu_from_flag(pdu.pdu_type(), buffer, size); } @@ -548,4 +548,4 @@ int PacketSender::find_type(SocketType type) { } } -} // Tins +} // namespace Tins diff --git a/src/packet_writer.cpp b/src/packet_writer.cpp index f0072d8f..b7b17e87 100644 --- a/src/packet_writer.cpp +++ b/src/packet_writer.cpp @@ -30,11 +30,11 @@ #ifndef _WIN32 #include #endif -#include -#include +#include +#include #include +#include #include -#include using std::string; @@ -76,7 +76,7 @@ void PacketWriter::write(PDU& pdu, const struct timeval& tv) { header.len = static_cast(pdu.advertised_size()); PDU::serialization_type buffer = pdu.serialize(); header.caplen = static_cast(buffer.size()); - pcap_dump((u_char*)dumper_, &header, &buffer[0]); + pcap_dump(reinterpret_cast(dumper_), &header, buffer.data()); } void PacketWriter::init(const string& file_name, int link_type) { @@ -92,4 +92,4 @@ void PacketWriter::init(const string& file_name, int link_type) { } } -} // Tins +} // namespace Tins diff --git a/src/pdu.cpp b/src/pdu.cpp index 832d6eab..73450fe8 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -128,7 +128,7 @@ PDU* PDU::release_inner_pdu() { PDU::serialization_type PDU::serialize() { vector buffer(size()); - serialize(&buffer[0], static_cast(buffer.size())); + serialize(buffer.data(), static_cast(buffer.size())); return buffer; } @@ -149,4 +149,4 @@ void PDU::parent_pdu(PDU* parent) { parent_pdu_ = parent; } -} // Tins +} // namespace Tins diff --git a/src/pdu_iterator.cpp b/src/pdu_iterator.cpp index 55cfa004..1a1d318f 100644 --- a/src/pdu_iterator.cpp +++ b/src/pdu_iterator.cpp @@ -101,4 +101,4 @@ PDUIteratorRange iterate_pdus(const Packet& packet) { return PDUIteratorRange(packet.pdu(), 0); } -} // Tins +} // namespace Tins diff --git a/src/pdu_option.cpp b/src/pdu_option.cpp index ae2554a4..53926f5d 100644 --- a/src/pdu_option.cpp +++ b/src/pdu_option.cpp @@ -204,7 +204,7 @@ vector convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type, vector output; const uint8_t* end = ptr + data_size; while (ptr != end) { - output.push_back(float(*(ptr++) & 0x7f) / 2); + output.push_back(static_cast(*(ptr++) & 0x7f) / 2); } return output; } @@ -279,6 +279,6 @@ pair convert(const uint8_t* ptr, uint32_t data_size, PDU::en return convert_pair(ptr, data_size, endian); } -} // Converters -} // Internals -} // Tins +} // namespace Converters +} // namespace Internals +} // namespace Tins diff --git a/src/pktap.cpp b/src/pktap.cpp index 40edd9a7..68fce5fa 100644 --- a/src/pktap.cpp +++ b/src/pktap.cpp @@ -68,4 +68,4 @@ void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/) { throw pdu_not_serializable(); } -} // Tins +} // namespace Tins diff --git a/src/ppi.cpp b/src/ppi.cpp index fbab9227..66b63b19 100644 --- a/src/ppi.cpp +++ b/src/ppi.cpp @@ -113,4 +113,4 @@ void PPI::parse_80211(const uint8_t* buffer, uint32_t total_sz) { #endif // TINS_HAVE_DOT11 } -} // Tins +} // namespace Tins diff --git a/src/pppoe.cpp b/src/pppoe.cpp index 35416630..a56ee3af 100644 --- a/src/pppoe.cpp +++ b/src/pppoe.cpp @@ -155,7 +155,7 @@ void PPPoE::ac_cookie(const byte_array& value) { void PPPoE::vendor_specific(const vendor_spec_type& value) { vector buffer(sizeof(uint32_t) + value.data.size()); uint32_t tmp_vendor_id = Endian::host_to_be(value.vendor_id); - memcpy(&buffer[0], &tmp_vendor_id, sizeof(uint32_t)); + memcpy(buffer.data(), &tmp_vendor_id, sizeof(uint32_t)); copy( value.data.begin(), value.data.end(), diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 009c2ebe..32c4007c 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -133,7 +133,7 @@ void RadioTap::tsft(uint64_t new_tsft) { } void RadioTap::flags(FrameFlags new_flags) { - add_integral_option(*this, FLAGS, (uint8_t)new_flags); + add_integral_option(*this, FLAGS, static_cast(new_flags)); } void RadioTap::rate(uint8_t new_rate) { @@ -338,7 +338,7 @@ void RadioTap::send(PacketSender& sender, const NetworkInterface& iface) { std::copy(dot11_addr.begin(), dot11_addr.end(), addr.sll_addr); } - sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr), iface); + sender.send_l2(*this, reinterpret_cast(&addr), static_cast(sizeof(addr)), iface); #else sender.send_l2(*this, 0, 0, iface); #endif @@ -349,7 +349,7 @@ bool RadioTap::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (sizeof(header_) < total_sz) { return false; } - const radiotap_header* radio_ptr = (const radiotap_header*)ptr; + const radiotap_header* radio_ptr = reinterpret_cast(ptr); if (radio_ptr->it_len <= total_sz) { ptr += radio_ptr->it_len; total_sz -= radio_ptr->it_len; @@ -382,6 +382,6 @@ RadioTap::option RadioTap::do_find_option(PresentFlags type) const { return parser.current_option(); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/rawpdu.cpp b/src/rawpdu.cpp index 9b1655fd..7ebcc9a2 100644 --- a/src/rawpdu.cpp +++ b/src/rawpdu.cpp @@ -60,4 +60,4 @@ bool RawPDU::matches_response(const uint8_t* /*ptr*/, uint32_t /*total_sz*/) con return true; } -} // Tins +} // namespace Tins diff --git a/src/rsn_information.cpp b/src/rsn_information.cpp index 93fa1a80..f3b6f970 100644 --- a/src/rsn_information.cpp +++ b/src/rsn_information.cpp @@ -48,7 +48,7 @@ RSNInformation::RSNInformation() } RSNInformation::RSNInformation(const serialization_type& buffer) { - init(&buffer[0], static_cast(buffer.size())); + init(buffer.data(), static_cast(buffer.size())); } RSNInformation::RSNInformation(const uint8_t* buffer, uint32_t total_sz) { @@ -58,20 +58,20 @@ RSNInformation::RSNInformation(const uint8_t* buffer, uint32_t total_sz) { void RSNInformation::init(const uint8_t* buffer, uint32_t total_sz) { InputMemoryStream stream(buffer, total_sz); version(stream.read_le()); - group_suite((RSNInformation::CypherSuites)stream.read_le()); + group_suite(static_cast(stream.read_le())); int pairwise_cyphers_size = stream.read_le(); if (!stream.can_read(pairwise_cyphers_size)) { throw malformed_packet(); } while (pairwise_cyphers_size--) { - add_pairwise_cypher((RSNInformation::CypherSuites)stream.read_le()); + add_pairwise_cypher(static_cast(stream.read_le())); } int akm_cyphers_size = stream.read_le(); if (!stream.can_read(akm_cyphers_size)) { throw malformed_packet(); } while (akm_cyphers_size--) { - add_akm_cypher((RSNInformation::AKMSuites)stream.read_le()); + add_akm_cypher(static_cast(stream.read_le())); } capabilities(stream.read_le()); } @@ -105,7 +105,7 @@ RSNInformation::serialization_type RSNInformation::serialize() const { const uint16_t akm_cyphers_size = Endian::host_to_le(akm_cyphers_.size()); serialization_type buffer(size); - OutputMemoryStream stream(&buffer[0], buffer.size()); + OutputMemoryStream stream(buffer.data(), buffer.size()); stream.write(version_); stream.write(group_suite_); stream.write(pairwise_cyphers_size); @@ -135,6 +135,6 @@ RSNInformation RSNInformation::from_option(const PDUOption& opt) return RSNInformation(opt.data_ptr(), static_cast(opt.data_size())); } -} // Tins +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/sll.cpp b/src/sll.cpp index 135986d2..1021ffa9 100644 --- a/src/sll.cpp +++ b/src/sll.cpp @@ -48,7 +48,7 @@ SLL::SLL(const uint8_t* buffer, uint32_t total_sz) { if (stream) { inner_pdu( Internals::pdu_from_flag( - (Constants::Ethernet::e)protocol(), + static_cast(protocol()), stream.pointer(), stream.size() ) @@ -91,4 +91,4 @@ void SLL::write_serialization(uint8_t* buffer, uint32_t total_sz) { stream.write(header_); } -} // Tins +} // namespace Tins diff --git a/src/snap.cpp b/src/snap.cpp index c23930da..b2e272c2 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -55,7 +55,7 @@ SNAP::SNAP(const uint8_t* buffer, uint32_t total_sz) { if (stream) { inner_pdu( Internals::pdu_from_flag( - (Constants::Ethernet::e)eth_type(), + static_cast(eth_type()), stream.pointer(), stream.size() ) @@ -100,4 +100,4 @@ void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz) { stream.write(snap_); } -} // Tins +} // namespace Tins diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 0b0d19b5..76bd3f56 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -93,7 +93,7 @@ sniff_data() : tv(), pdu(0), packet_processed(true) { } template T* safe_alloc(const u_char* bytes, bpf_u_int32 len) { try { - return new T((const uint8_t*)bytes, len); + return new T(static_cast(bytes), len); } catch (malformed_packet&) { return 0; @@ -102,21 +102,21 @@ T* safe_alloc(const u_char* bytes, bpf_u_int32 len) { template void sniff_loop_handler(u_char* user, const struct pcap_pkthdr* h, const u_char* bytes) { - sniff_data* data = (sniff_data*)user; + sniff_data* data = reinterpret_cast(user); data->packet_processed = true; data->tv = h->ts; data->pdu = safe_alloc(bytes, h->caplen); } void sniff_loop_eth_handler(u_char* user, const struct pcap_pkthdr* h, const u_char* bytes) { - sniff_data* data = (sniff_data*)user; + sniff_data* data = reinterpret_cast(user); data->packet_processed = true; data->tv = h->ts; - if (Internals::is_dot3((const uint8_t*)bytes, h->caplen)) { - data->pdu = safe_alloc((const uint8_t*)bytes, h->caplen); + if (Internals::is_dot3(static_cast(bytes), h->caplen)) { + data->pdu = safe_alloc(static_cast(bytes), h->caplen); } else { - data->pdu = safe_alloc((const uint8_t*)bytes, h->caplen); + data->pdu = safe_alloc(static_cast(bytes), h->caplen); } } @@ -132,23 +132,23 @@ void sniff_loop_raw_handler(u_char* user, const struct pcap_pkthdr* h, const u_c #endif } TINS_END_PACK; - sniff_data* data = (sniff_data*)user; - const base_ip_header* header = (const base_ip_header*)bytes; + sniff_data* data = reinterpret_cast(user); + const base_ip_header* header = reinterpret_cast(bytes); data->packet_processed = true; data->tv = h->ts; switch (header->version) { case 4: - data->pdu = safe_alloc((const uint8_t*)bytes, h->caplen); + data->pdu = safe_alloc(static_cast(bytes), h->caplen); break; case 6: - data->pdu = safe_alloc((const uint8_t*)bytes, h->caplen); + data->pdu = safe_alloc(static_cast(bytes), h->caplen); break; }; } #ifdef TINS_HAVE_DOT11 void sniff_loop_dot11_handler(u_char* user, const struct pcap_pkthdr* h, const u_char* bytes) { - sniff_data* data = (sniff_data*)user; + sniff_data* data = reinterpret_cast(user); data->packet_processed = true; data->tv = h->ts; try { @@ -212,7 +212,7 @@ PtrPacket BaseSniffer::next_packet() { // keep calling pcap_loop until a well-formed packet is found. while (data.pdu == 0 && data.packet_processed) { data.packet_processed = false; - if (pcap_sniffing_method_(handle_, 1, handler, (u_char*)&data) < 0) { + if (pcap_sniffing_method_(handle_, 1, handler, reinterpret_cast(&data)) < 0) { return PtrPacket(0, Timestamp()); } } @@ -527,4 +527,4 @@ void SnifferConfiguration::set_direction(pcap_direction_t direction) { flags_ |= DIRECTION; } -} // Tins +} // namespace Tins diff --git a/src/stp.cpp b/src/stp.cpp index 094451f0..f7b9355b 100644 --- a/src/stp.cpp +++ b/src/stp.cpp @@ -135,4 +135,4 @@ STP::pvt_bpdu_id STP::convert(const bpdu_id_type& id) { return result; } -} // Tins +} // namespace Tins diff --git a/src/tcp.cpp b/src/tcp.cpp index 81507f0e..5cf1d7b7 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -51,7 +51,7 @@ PDU::metadata TCP::extract_metadata(const uint8_t *buffer, uint32_t total_sz) { if (TINS_UNLIKELY(total_sz < sizeof(tcp_header))) { throw malformed_packet(); } - const tcp_header* header = (const tcp_header*)buffer; + const tcp_header* header = reinterpret_cast(buffer); return metadata(header->doff * 4, pdu_flag, PDU::UNKNOWN); } @@ -80,7 +80,7 @@ TCP::TCP(const uint8_t* buffer, uint32_t total_sz) { } while (stream.pointer() < header_end) { - const OptionTypes option_type = (OptionTypes)stream.read(); + const OptionTypes option_type = static_cast(stream.read()); if (option_type == EOL) { stream.skip(header_end - stream.pointer()); break; @@ -156,7 +156,7 @@ void TCP::data_offset(small_uint<4> new_doff) { void TCP::mss(uint16_t value) { value = Endian::host_to_be(value); - add_option(option(MSS, 2, (uint8_t*)&value)); + add_option(option(MSS, 2, reinterpret_cast(&value))); } uint16_t TCP::mss() const { @@ -181,13 +181,13 @@ bool TCP::has_sack_permitted() const { void TCP::sack(const sack_type& edges) { vector value(edges.size() * sizeof(uint32_t)); - if (edges.size()) { + if (!edges.empty()) { OutputMemoryStream stream(value); for (sack_type::const_iterator it = edges.begin(); it != edges.end(); ++it) { stream.write_be(*it); } } - add_option(option(SACK, (uint8_t)value.size(), &value[0])); + add_option(option(SACK, static_cast(value.size()), value.data())); } TCP::sack_type TCP::sack() const { @@ -199,9 +199,9 @@ TCP::sack_type TCP::sack() const { } void TCP::timestamp(uint32_t value, uint32_t reply) { - uint64_t buffer = (uint64_t(value) << 32) | reply; + uint64_t buffer = (static_cast(value) << 32) | reply; buffer = Endian::host_to_be(buffer); - add_option(option(TSOPT, 8, (uint8_t*)&buffer)); + add_option(option(TSOPT, 8, reinterpret_cast(&buffer))); } pair TCP::timestamp() const { @@ -346,7 +346,7 @@ void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz) { check = (check & 0xffff) + (check >> 16); } checksum(Endian::host_to_be(~check)); - ((tcp_header*)buffer)->check = header_.check; + (reinterpret_cast(buffer))->check = header_.check; } const TCP::option* TCP::search_option(OptionTypes type) const { @@ -412,7 +412,7 @@ bool TCP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(header_)) { return false; } - const tcp_header* tcp_ptr = (const tcp_header*)ptr; + const tcp_header* tcp_ptr = reinterpret_cast(ptr); if (tcp_ptr->sport == header_.dport && tcp_ptr->dport == header_.sport) { const uint32_t data_offset = tcp_ptr->doff * sizeof(uint32_t); uint32_t sz = (total_sz < data_offset) ? total_sz : data_offset; @@ -422,4 +422,4 @@ bool TCP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -} // Tins +} // namespace Tins diff --git a/src/tcp_stream.cpp b/src/tcp_stream.cpp index 50189628..146c006c 100644 --- a/src/tcp_stream.cpp +++ b/src/tcp_stream.cpp @@ -266,4 +266,4 @@ bool TCPStream::StreamInfo::operator<(const StreamInfo& rhs) const { } } -} // Tins +} // namespace Tins diff --git a/src/timestamp.cpp b/src/timestamp.cpp index 262b15ae..c9ec3542 100644 --- a/src/timestamp.cpp +++ b/src/timestamp.cpp @@ -81,4 +81,4 @@ Timestamp::microseconds_type Timestamp::microseconds() const { return timestamp_ % MICROSECONDS_IN_SECOND; } -} // Tins +} // namespace Tins diff --git a/src/udp.cpp b/src/udp.cpp index b068e4c8..8791a6fd 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -109,7 +109,7 @@ uint32_t pseudoheader_checksum(IPv4Address source_ip, IPv4Address dest_ip, uint3 stream.write(dest_ip); stream.write(Endian::host_to_be(flag)); stream.write(Endian::host_to_be(len)); - uint16_t* ptr = (uint16_t*)buffer, *end = (uint16_t*)(buffer + sizeof(buffer)); + uint16_t* ptr = reinterpret_cast(buffer), *end = reinterpret_cast(buffer + sizeof(buffer)); while (ptr < end) { checksum += *ptr++; } @@ -154,14 +154,14 @@ void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz) { header_.check = ~checksum; // If checksum is 0, it has to be set to 0xffff header_.check = (header_.check == 0) ? 0xffff : header_.check; - ((udp_header*)buffer)->check = header_.check; + (reinterpret_cast(buffer))->check = header_.check; } bool UDP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { if (total_sz < sizeof(udp_header)) { return false; } - const udp_header* udp_ptr = (const udp_header*)ptr; + const udp_header* udp_ptr = reinterpret_cast(ptr); if (udp_ptr->sport == header_.dport && udp_ptr->dport == header_.sport) { if (inner_pdu()) { return inner_pdu()->matches_response( @@ -176,4 +176,4 @@ bool UDP::matches_response(const uint8_t* ptr, uint32_t total_sz) const { return false; } -} // Tins +} // namespace Tins diff --git a/src/utils/checksum_utils.cpp b/src/utils/checksum_utils.cpp index 56772638..e4c858ee 100644 --- a/src/utils/checksum_utils.cpp +++ b/src/utils/checksum_utils.cpp @@ -126,6 +126,5 @@ uint32_t crc32(const uint8_t* data, uint32_t data_size) { return crc; } - -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins diff --git a/src/utils/frequency_utils.cpp b/src/utils/frequency_utils.cpp index 05f1e3ff..02ff19f9 100644 --- a/src/utils/frequency_utils.cpp +++ b/src/utils/frequency_utils.cpp @@ -40,5 +40,5 @@ uint16_t mhz_to_channel(uint16_t mhz) { return (mhz - 2407) / 5; } -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins diff --git a/src/utils/pdu_utils.cpp b/src/utils/pdu_utils.cpp index 3714e32f..6b555096 100644 --- a/src/utils/pdu_utils.cpp +++ b/src/utils/pdu_utils.cpp @@ -97,5 +97,5 @@ string to_string(PDU::PDUType pduType) { #undef ENUM_TEXT } -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins diff --git a/src/utils/radiotap_parser.cpp b/src/utils/radiotap_parser.cpp index a7519d4c..1b8bd740 100644 --- a/src/utils/radiotap_parser.cpp +++ b/src/utils/radiotap_parser.cpp @@ -236,7 +236,7 @@ bool RadioTapParser::has_fields() const { bool RadioTapParser::has_field(RadioTap::PresentFlags flag) const { const uint8_t* ptr = start_; while (ptr + sizeof(uint32_t) < end_) { - const RadioTapFlags* flags = (const RadioTapFlags*)ptr; + const RadioTapFlags* flags = reinterpret_cast(ptr); if (is_field_set(flag, flags)) { return true; } @@ -324,7 +324,7 @@ bool RadioTapParser::is_field_set(uint32_t bit, const RadioTapFlags* flags) cons } const RadioTapFlags* RadioTapParser::get_flags_ptr() const { - return (const RadioTapFlags*)(start_ + sizeof(uint32_t) * namespace_index_); + return reinterpret_cast(start_ + sizeof(uint32_t) * namespace_index_); } void RadioTapParser::load_current_flags() { @@ -332,7 +332,7 @@ void RadioTapParser::load_current_flags() { current_flags_ = Endian::le_to_host(current_flags_); } -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/utils/radiotap_writer.cpp b/src/utils/radiotap_writer.cpp index 4bb34654..8eb31c92 100644 --- a/src/utils/radiotap_writer.cpp +++ b/src/utils/radiotap_writer.cpp @@ -169,7 +169,7 @@ void RadioTapWriter::update_paddings(const vector& paddings, uint32_t o } } -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins #endif // TINS_HAVE_DOT11 diff --git a/src/utils/resolve_utils.cpp b/src/utils/resolve_utils.cpp index 1be8fced..62790260 100644 --- a/src/utils/resolve_utils.cpp +++ b/src/utils/resolve_utils.cpp @@ -82,14 +82,14 @@ namespace Utils { IPv4Address resolve_domain(const string& to_resolve) { addrinfo* result = ::resolve_domain(to_resolve, AF_INET); - IPv4Address addr(((sockaddr_in*)result->ai_addr)->sin_addr.s_addr); + IPv4Address addr((reinterpret_cast(result->ai_addr))->sin_addr.s_addr); freeaddrinfo(result); return addr; } IPv6Address resolve_domain6(const string& to_resolve) { addrinfo* result = ::resolve_domain(to_resolve, AF_INET6); - IPv6Address addr((const uint8_t*)&((sockaddr_in6*)result->ai_addr)->sin6_addr); + IPv6Address addr(reinterpret_cast(&(reinterpret_cast(result->ai_addr))->sin6_addr)); freeaddrinfo(result); return addr; } @@ -127,6 +127,5 @@ HWAddress<6> resolve_hwaddr(IPv4Address ip, PacketSender& sender) { return resolve_hwaddr(sender.default_interface(), ip, sender); } - -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins diff --git a/src/utils/routing_utils.cpp b/src/utils/routing_utils.cpp index 889d2647..e21c944e 100644 --- a/src/utils/routing_utils.cpp +++ b/src/utils/routing_utils.cpp @@ -376,11 +376,11 @@ vector route6_entries() { } input >> flags >> entry.interface; from_hex(destination, temporary); - entry.destination = IPv6Address((const uint8_t*)&temporary[0]); + entry.destination = IPv6Address(reinterpret_cast(temporary.data())); from_hex(mask_length, temporary_int); entry.mask = IPv6Address::from_prefix_length(temporary_int); from_hex(next_hop, temporary); - entry.gateway = IPv6Address((const uint8_t*)&temporary[0]); + entry.gateway = IPv6Address(reinterpret_cast(temporary.data())); from_hex(metric, temporary_int); entry.metric = temporary_int; // Process flags @@ -456,5 +456,5 @@ bool gateway_from_ip(IPv6Address ip, IPv6Address& gw_addr) { return false; } -} // Utils -} // Tins +} // namespace Utils +} // namespace Tins