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

Fix compilation warnings on Windows x64.

This commit is contained in:
Matias Fontanini
2015-05-17 17:30:54 -07:00
parent 5cd0c8e41b
commit c42cd0114f
47 changed files with 167 additions and 137 deletions

View File

@@ -52,7 +52,7 @@ BootP::BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field_size)
}
uint32_t BootP::header_size() const {
return sizeof(bootphdr) + _vend.size();
return static_cast<uint32_t>(sizeof(bootphdr) + _vend.size());
}
void BootP::opcode(uint8_t new_opcode) {

View File

@@ -96,7 +96,8 @@ PDU *WEPDecrypter::decrypt(RawPDU &raw, const std::string &password) {
// Generate the key
RC4Key key(key_buffer.begin(), key_buffer.begin() + password.size() + 3);
rc4(pload.begin() + 4, pload.end(), key, pload.begin());
uint32_t crc = Utils::crc32(&pload[0], pload.size() - 8);
uint32_t payload_size = static_cast<uint32_t>(pload.size() - 8);
uint32_t crc = Utils::crc32(&pload[0], payload_size);
if(pload[pload.size() - 8] != (crc & 0xff) ||
pload[pload.size() - 7] != ((crc >> 8) & 0xff) ||
pload[pload.size() - 6] != ((crc >> 16) & 0xff) ||
@@ -104,7 +105,7 @@ PDU *WEPDecrypter::decrypt(RawPDU &raw, const std::string &password) {
return 0;
try {
return new SNAP(&pload[0], pload.size() - 8);
return new SNAP(&pload[0], payload_size);
}
catch(std::runtime_error&) {
return 0;

View File

@@ -51,7 +51,7 @@ DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz)
: BootP(buffer, total_sz, 0), _size(sizeof(uint32_t))
{
buffer += BootP::header_size() - vend().size();
total_sz -= BootP::header_size() - vend().size();
total_sz -= static_cast<uint32_t>(BootP::header_size() - vend().size());
uint8_t args[2] = {0};
uint32_t uint32_t_buffer;
std::memcpy(&uint32_t_buffer, buffer, sizeof(uint32_t));
@@ -86,7 +86,7 @@ void DHCP::add_option(const option &opt) {
}
void DHCP::internal_add_option(const option &opt) {
_size += opt.data_size() + (sizeof(uint8_t) << 1);
_size += static_cast<uint32_t>(opt.data_size() + (sizeof(uint8_t) << 1));
}
const DHCP::option *DHCP::search_option(OptionTypes opt) const {
@@ -216,7 +216,7 @@ PDU::serialization_type DHCP::serialize_list(const std::vector<ipaddress_type> &
}
uint32_t DHCP::header_size() const {
return BootP::header_size() - vend().size() + _size;
return static_cast<uint32_t>(BootP::header_size() - vend().size() + _size);
}
void DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
@@ -231,7 +231,7 @@ void DHCP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
*((uint32_t*)&result[0]) = Endian::host_to_be<uint32_t>(0x63825363);
for(options_type::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(ptr++) = it->option();
*(ptr++) = it->length_field();
*(ptr++) = static_cast<uint8_t>(it->length_field());
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), ptr);
ptr += it->data_size();
}

View File

@@ -95,7 +95,7 @@ const DHCPv6::option *DHCPv6::search_option(OptionTypes id) const {
uint8_t* DHCPv6::write_option(const option &opt, uint8_t* buffer) const {
uint16_t uint16_t_buffer = Endian::host_to_be(opt.option());
std::memcpy(buffer, &uint16_t_buffer, sizeof(uint16_t));
uint16_t_buffer = Endian::host_to_be<uint16_t>(opt.length_field());
uint16_t_buffer = Endian::host_to_be(static_cast<uint16_t>(opt.length_field()));
std::memcpy(&buffer[sizeof(uint16_t)], &uint16_t_buffer, sizeof(uint16_t));
return std::copy(
opt.data_ptr(),
@@ -632,7 +632,7 @@ DHCPv6::vendor_class_type DHCPv6::vendor_class_type::from_option(const option &o
output.enterprise_number = Endian::be_to_host(output.enterprise_number);
output.vendor_class_data = Internals::option2class_option_data<data_type>(
opt.data_ptr() + sizeof(uint32_t),
opt.data_size() - sizeof(uint32_t)
static_cast<uint32_t>(opt.data_size() - sizeof(uint32_t))
);
return output;
@@ -660,7 +660,7 @@ DHCPv6::user_class_type DHCPv6::user_class_type::from_option(const option &opt)
throw malformed_option();
user_class_type output;
output.data = Internals::option2class_option_data<data_type>(
opt.data_ptr(), opt.data_size()
opt.data_ptr(), static_cast<uint32_t>(opt.data_size())
);
return output;
}

View File

@@ -72,9 +72,13 @@ DNS::DNS(const uint8_t *buffer, uint32_t total_sz)
throw malformed_packet();
buffer += sizeof(uint16_t) * 2;
}
answers_idx = buffer - prev_start;
authority_idx = find_section_end(&records_data[0] + answers_idx, answers_count()) - &records_data[0];
additional_idx = find_section_end(&records_data[0] + authority_idx, authority_count()) - &records_data[0];
answers_idx = static_cast<uint32_t>(buffer - prev_start);
authority_idx = static_cast<uint32_t>(
find_section_end(&records_data[0] + answers_idx, answers_count()) - &records_data[0]
);
additional_idx = static_cast<uint32_t>(
find_section_end(&records_data[0] + authority_idx, authority_count()) - &records_data[0]
);
}
}
@@ -118,7 +122,7 @@ const uint8_t *DNS::find_section_end(const uint8_t *ptr, const uint32_t num_reco
}
uint32_t DNS::header_size() const {
return sizeof(dns) + records_data.size();
return static_cast<uint32_t>(sizeof(dns) + records_data.size());
}
void DNS::id(uint16_t new_id) {
@@ -180,7 +184,7 @@ void DNS::add_query(const Query &query) {
uint16_t_buffer = Endian::host_to_be<uint16_t>(query.query_class());
std::memcpy(&new_str[new_str.size() - 2], &uint16_t_buffer, sizeof(uint16_t));
uint32_t offset = new_str.size(), threshold = answers_idx;
uint32_t offset = static_cast<uint32_t>(new_str.size()), threshold = answers_idx;
update_records(answers_idx, answers_count(), threshold, offset);
update_records(authority_idx, authority_count(), threshold, offset);
update_records(additional_idx, additional_count(), threshold, offset);
@@ -189,9 +193,7 @@ void DNS::add_query(const Query &query) {
new_str.begin(),
new_str.end()
);
dns.questions = Endian::host_to_be<uint16_t>(
questions_count() + 1
);
dns.questions = Endian::host_to_be(static_cast<uint16_t>(questions_count() + 1));
}
void DNS::add_answer(const Resource &resource) {
@@ -211,7 +213,7 @@ void DNS::add_record(const Resource &resource, const sections_type &sections) {
IPv6Address v6_addr;
std::string buffer = encode_domain_name(resource.dname()), encoded_data;
// By default the data size is the length of the data field.
uint32_t data_size = resource.data().size();
size_t data_size = resource.data().size();
if(resource.type() == A) {
v4_addr = resource.data();
data_size = 4;
@@ -224,14 +226,15 @@ void DNS::add_record(const Resource &resource, const sections_type &sections) {
encoded_data = encode_domain_name(resource.data());
data_size = encoded_data.size();
}
uint32_t offset = buffer.size() + sizeof(uint16_t) * 3 + sizeof(uint32_t) + data_size,
size_t offset = buffer.size() + sizeof(uint16_t) * 3 + sizeof(uint32_t) + data_size,
threshold = sections.empty() ? records_data.size() : *sections.front().first;
// Skip the preference field
if(resource.type() == MX) {
offset += sizeof(uint16_t);
}
for(size_t i = 0; i < sections.size(); ++i) {
update_records(*sections[i].first, sections[i].second, threshold, offset);
update_records(*sections[i].first, sections[i].second,
static_cast<uint32_t>(threshold), static_cast<uint32_t>(offset));
}
records_data.insert(
@@ -257,8 +260,8 @@ void DNS::add_record(const Resource &resource, const sections_type &sections) {
uint32_t_buffer = Endian::host_to_be(resource.ttl());
std::memcpy(ptr, &uint32_t_buffer, sizeof(uint32_t));
ptr += sizeof(uint32_t);
uint16_t_buffer = Endian::host_to_be<uint16_t>(
data_size + (resource.type() == MX ? 2 : 0)
uint16_t_buffer = Endian::host_to_be(
static_cast<uint16_t>(data_size + (resource.type() == MX ? 2 : 0))
);
std::memcpy(ptr, &uint16_t_buffer, sizeof(uint16_t));
ptr += sizeof(uint16_t);
@@ -301,11 +304,11 @@ std::string DNS::encode_domain_name(const std::string &dn) {
size_t last_index(0), index;
if(!dn.empty()) {
while((index = dn.find('.', last_index+1)) != string::npos) {
output.push_back(index - last_index);
output.push_back(static_cast<char>(index - last_index));
output.append(dn.begin() + last_index, dn.begin() + index);
last_index = index + 1; //skip dot
}
output.push_back(dn.size() - last_index);
output.push_back(static_cast<char>(dn.size() - last_index));
output.append(dn.begin() + last_index, dn.end());
}
output.push_back('\0');

View File

@@ -103,7 +103,7 @@ void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val)
}
void Dot11::internal_add_option(const option &opt) {
_options_size += opt.data_size() + sizeof(uint8_t) * 2;
_options_size += static_cast<uint32_t>(opt.data_size() + sizeof(uint8_t) * 2);
}
void Dot11::add_option(const option &opt) {
@@ -212,7 +212,7 @@ void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p
#endif
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = it->length_field();
*(buffer++) = static_cast<uint8_t>(it->length_field());
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer);
buffer += it->data_size();
}

View File

@@ -74,9 +74,9 @@ uint32_t Dot11Data::init(const uint8_t *buffer, uint32_t total_sz) {
throw malformed_packet();
_addr4 = buffer;
buffer += _addr4.size();
total_sz -= _addr4.size();
total_sz -= static_cast<uint32_t>(_addr4.size());
}
return buffer - start_ptr;
return static_cast<uint32_t>(buffer - start_ptr);
}
Dot11Data::Dot11Data(const address_type &dst_hw_addr,
@@ -128,7 +128,7 @@ uint32_t Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
memcpy(buffer, &_ext_header, sizeof(_ext_header));
buffer += sizeof(_ext_header);
if (from_ds() && to_ds()) {
written += _addr4.size();
written += static_cast<uint32_t>(_addr4.size());
_addr4.copy(buffer);
}
return written;

View File

@@ -109,12 +109,12 @@ uint32_t Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_
}
void Dot11ManagementFrame::ssid(const std::string &new_ssid) {
add_tagged_option(Dot11::SSID, new_ssid.size(), (const uint8_t*)new_ssid.c_str());
add_tagged_option(Dot11::SSID, static_cast<uint8_t>(new_ssid.size()), (const uint8_t*)new_ssid.c_str());
}
void Dot11ManagementFrame::rsn_information(const RSNInformation& info) {
RSNInformation::serialization_type buffer = info.serialize();
add_tagged_option(RSN, buffer.size(), &buffer[0]);
add_tagged_option(RSN, static_cast<uint8_t>(buffer.size()), &buffer[0]);
}
uint8_t *Dot11ManagementFrame::serialize_rates(const rates_type &rates) {
@@ -139,13 +139,13 @@ Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const o
void Dot11ManagementFrame::supported_rates(const rates_type &new_rates) {
uint8_t *buffer = serialize_rates(new_rates);
add_tagged_option(SUPPORTED_RATES, new_rates.size(), buffer);
add_tagged_option(SUPPORTED_RATES, static_cast<uint8_t>(new_rates.size()), buffer);
delete[] buffer;
}
void Dot11ManagementFrame::extended_supported_rates(const rates_type &new_rates) {
uint8_t *buffer = serialize_rates(new_rates);
add_tagged_option(EXT_SUPPORTED_RATES, new_rates.size(), buffer);
add_tagged_option(EXT_SUPPORTED_RATES, static_cast<uint8_t>(new_rates.size()), buffer);
delete[] buffer;
}
@@ -167,7 +167,7 @@ void Dot11ManagementFrame::supported_channels(const channels_type &new_channels)
*(ptr++) = it->first;
*(ptr++) = it->second;
}
add_tagged_option(SUPPORTED_CHANNELS, buffer.size(), &buffer[0]);
add_tagged_option(SUPPORTED_CHANNELS, static_cast<uint8_t>(buffer.size()), &buffer[0]);
}
void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) {
@@ -183,7 +183,7 @@ void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, ui
}
void Dot11ManagementFrame::request_information(const request_info_type elements) {
add_tagged_option(REQUEST_INFORMATION, elements.size(), &elements[0]);
add_tagged_option(REQUEST_INFORMATION, static_cast<uint8_t>(elements.size()), &elements[0]);
}
void Dot11ManagementFrame::fh_parameter_set(const fh_params_set &fh_params) {
@@ -218,9 +218,10 @@ void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) {
}
void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params &params) {
uint8_t sz = address_type::address_size + sizeof(uint8_t) + sizeof(uint8_t) * 2 * params.channel_map.size();
uint8_t* buffer = new uint8_t[sz];
uint8_t* ptr_buffer = buffer;
const size_t sz = address_type::address_size + sizeof(uint8_t) +
sizeof(uint8_t) * 2 * params.channel_map.size();
std::vector<uint8_t> buffer(sz);
uint8_t* ptr_buffer = &buffer[0];
ptr_buffer = params.dfs_owner.copy(ptr_buffer);
*(ptr_buffer++) = params.recovery_interval;
@@ -229,9 +230,7 @@ void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params &params) {
*(ptr_buffer++) = it->second;
}
add_tagged_option(IBSS_DFS, sz, buffer);
delete[] buffer;
add_tagged_option(IBSS_DFS, static_cast<uint8_t>(buffer.size()), &buffer[0]);
}
void Dot11ManagementFrame::country(const country_params &params) {
@@ -251,7 +250,7 @@ void Dot11ManagementFrame::country(const country_params &params) {
*(ptr++) = params.number_channels[i];
*(ptr++) = params.max_transmit_power[i];
}
add_tagged_option(COUNTRY, sz, &buffer[0]);
add_tagged_option(COUNTRY, static_cast<uint8_t>(sz), &buffer[0]);
}
void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) {
@@ -271,7 +270,7 @@ void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type &params) {
byte_array::const_iterator it(params.random_table.begin());
for(; it != params.random_table.end(); ++it)
*(ptr++) = *it;
add_tagged_option(HOPPING_PATTERN_TABLE, data.size(), &data[0]);
add_tagged_option(HOPPING_PATTERN_TABLE, static_cast<uint8_t>(data.size()), &data[0]);
}
void Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) {
@@ -296,7 +295,6 @@ void Dot11ManagementFrame::quiet(const quiet_type &data) {
ptr_buffer[0] = Endian::host_to_le(data.quiet_duration);
ptr_buffer[1] = Endian::host_to_le(data.quiet_offset);
add_tagged_option(QUIET, sizeof(buffer), buffer);
}
void Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) {
@@ -346,13 +344,13 @@ void Dot11ManagementFrame::tim(const tim_type &data) {
data.partial_virtual_bitmap.end(),
&buffer[3]
);
add_tagged_option(TIM, buffer.size(), &buffer[0]);
add_tagged_option(TIM, static_cast<uint8_t>(buffer.size()), &buffer[0]);
}
void Dot11ManagementFrame::challenge_text(const std::string &text) {
add_tagged_option(
CHALLENGE_TEXT,
text.size(),
static_cast<uint8_t>(text.size()),
(const uint8_t*)text.c_str()
);
}
@@ -364,7 +362,7 @@ void Dot11ManagementFrame::vendor_specific(const vendor_specific_type &data) {
data.data.end(),
data.oui.copy(buffer.begin())
);
add_tagged_option(VENDOR_SPECIFIC, buffer.size(), &buffer[0]);
add_tagged_option(VENDOR_SPECIFIC, static_cast<uint8_t>(buffer.size()), &buffer[0]);
}
// Getters
@@ -475,7 +473,8 @@ Dot11ManagementFrame::vendor_specific_type Dot11ManagementFrame::vendor_specific
const Dot11::option *option = search_option(VENDOR_SPECIFIC);
if(!option || option->data_size() < 3)
throw option_not_found();
return vendor_specific_type::from_bytes(option->data_ptr(), option->data_size());
return vendor_specific_type::from_bytes(option->data_ptr(),
static_cast<uint32_t>(option->data_size()));
}
Dot11ManagementFrame::vendor_specific_type

View File

@@ -130,7 +130,7 @@ void Dot3::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
_eth.length = Endian::host_to_be<uint16_t>(size() - sizeof(_eth));
_eth.length = Endian::host_to_be(static_cast<uint16_t>(size() - sizeof(_eth)));
memcpy(buffer, &_eth, sizeof(ethhdr));
}

View File

@@ -150,15 +150,16 @@ void RC4EAPOL::key(const key_type &new_key) {
}
uint32_t RC4EAPOL::header_size() const {
return sizeof(eapolhdr) + sizeof(_header) + _key.size();
return static_cast<uint32_t>(sizeof(eapolhdr) + sizeof(_header) + _key.size());
}
void RC4EAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_header) + _key.size());
#endif
if(_key.size())
_header.key_length = Endian::host_to_be(_key.size());
if(_key.size()) {
_header.key_length = Endian::host_to_be(static_cast<uint16_t>(_key.size()));
}
std::memcpy(buffer, &_header, sizeof(_header));
buffer += sizeof(_header);
std::copy(_key.begin(), _key.end(), buffer);
@@ -265,7 +266,7 @@ void RSNEAPOL::key_ack(small_uint<1> new_key_ack) {
}
uint32_t RSNEAPOL::header_size() const {
return sizeof(eapolhdr) + sizeof(_header) + _key.size();
return static_cast<uint32_t>(sizeof(eapolhdr) + sizeof(_header) + _key.size());
}
void RSNEAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
@@ -275,10 +276,10 @@ void RSNEAPOL::write_body(uint8_t *buffer, uint32_t total_sz) {
if(_key.size()) {
if(!_header.key_t) {
_header.key_length = Endian::host_to_be<uint16_t>(32);
wpa_length(_key.size());
wpa_length(static_cast<uint16_t>(_key.size()));
}
else if(_key.size()) {
wpa_length(_key.size());
wpa_length(static_cast<uint16_t>(_key.size()));
}
}
std::memcpy(buffer, &_header, sizeof(_header));

View File

@@ -260,12 +260,12 @@ void ICMPv6::add_option(const option &option) {
}
void ICMPv6::internal_add_option(const option &option) {
_options_size += option.data_size() + sizeof(uint8_t) * 2;
_options_size += static_cast<uint32_t>(option.data_size() + sizeof(uint8_t) * 2);
}
uint8_t *ICMPv6::write_option(const option &opt, uint8_t *buffer) {
*buffer++ = opt.option();
*buffer++ = (opt.length_field() + sizeof(uint8_t) * 2) / 8;
*buffer++ = static_cast<uint8_t>((opt.length_field() + sizeof(uint8_t) * 2) / 8);
return std::copy(opt.data_ptr(), opt.data_ptr() + opt.data_size(), buffer);
}
@@ -379,7 +379,7 @@ void ICMPv6::add_addr_list(uint8_t type, const addr_list_type &value) {
}
void ICMPv6::rsa_signature(const rsa_sign_type &value) {
uint32_t total_sz = 4 + sizeof(value.key_hash) + value.signature.size();
uint32_t total_sz = static_cast<uint32_t>(4 + sizeof(value.key_hash) + value.signature.size());
uint8_t padding = 8 - total_sz % 8;
if(padding == 8)
padding = 0;
@@ -492,7 +492,7 @@ void ICMPv6::handover_key_request(const handover_key_req_type &value) {
}
void ICMPv6::handover_key_reply(const handover_key_reply_type &value) {
const uint32_t data_size = value.key.size() + 2 + sizeof(uint16_t);
const uint32_t data_size = static_cast<uint32_t>(value.key.size() + 2 + sizeof(uint16_t));
uint8_t padding = 8 - (data_size+2) % 8;
if(padding == 8)
padding = 0;
@@ -511,7 +511,7 @@ void ICMPv6::handover_key_reply(const handover_key_reply_type &value) {
}
void ICMPv6::handover_assist_info(const handover_assist_info_type &value) {
const uint32_t data_size = value.hai.size() + 2;
const uint32_t data_size = static_cast<uint32_t>(value.hai.size() + 2);
uint8_t padding = 8 - (data_size+2) % 8;
if(padding == 8)
padding = 0;
@@ -528,7 +528,7 @@ void ICMPv6::handover_assist_info(const handover_assist_info_type &value) {
}
void ICMPv6::mobile_node_identifier(const mobile_node_id_type &value) {
const uint32_t data_size = value.mn.size() + 2;
const uint32_t data_size = static_cast<uint32_t>(value.mn.size() + 2);
uint8_t padding = 8 - (data_size+2) % 8;
if(padding == 8)
padding = 0;
@@ -555,7 +555,7 @@ void ICMPv6::dns_search_list(const dns_search_list_type &value) {
do {
index = it->find('.', prev);
std::string::const_iterator end = (index == std::string::npos) ? it->end() : (it->begin() + index);
buffer.push_back(end - (it->begin() + prev));
buffer.push_back(static_cast<uint8_t>(end - (it->begin() + prev)));
buffer.insert(buffer.end(), it->begin() + prev, end);
prev = index + 1;
} while(index != std::string::npos);

View File

@@ -101,7 +101,7 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
_ip_options.push_back(option(opt_type));
ptr_buffer += _ip_options.back().data_size() + 1;
_options_size += _ip_options.back().data_size() + 2;
_options_size += static_cast<uint16_t>(_ip_options.back().data_size() + 2);
}
else {
_ip_options.push_back(option(opt_type));
@@ -298,7 +298,7 @@ void IP::add_option(const option &opt) {
}
void IP::internal_add_option(const option &opt) {
_options_size += 1 + opt.data_size();
_options_size += static_cast<uint16_t>(1 + opt.data_size());
uint8_t padding = _options_size % 4;
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
}
@@ -317,7 +317,7 @@ uint8_t* IP::write_option(const option &opt, uint8_t* buffer) {
if(*buffer <= 1)
return ++buffer;
buffer++;
*buffer = opt.length_field();
*buffer = static_cast<uint8_t>(opt.length_field());
if(opt.data_size() == opt.length_field())
*buffer += 2;
buffer++;
@@ -394,7 +394,7 @@ void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* pare
total_sz = Endian::host_to_be<uint16_t>(total_sz);
#endif
tot_len(total_sz);
head_len(my_sz / sizeof(uint32_t));
head_len(static_cast<uint8_t>(my_sz / sizeof(uint32_t)));
memcpy(buffer, &_ip, sizeof(_ip));

View File

@@ -72,13 +72,13 @@ PDU *IPv4Stream::allocate_pdu() const {
for(fragments_type::const_iterator it = fragments.begin(); it != fragments.end(); ++it) {
if(expected != it->offset())
return 0;
expected = it->offset() + it->payload().size();
expected = static_cast<uint16_t>(it->offset() + it->payload().size());
buffer.insert(buffer.end(), it->payload().begin(), it->payload().end());
}
return Internals::pdu_from_flag(
static_cast<Constants::IP::e>(transport_proto),
buffer.empty() ? 0 : &buffer[0],
buffer.size()
static_cast<uint32_t>(buffer.size())
);
}

View File

@@ -83,7 +83,7 @@ void IPSecAH::icv(const byte_array &new_icv) {
}
uint32_t IPSecAH::header_size() const {
return sizeof(_header) + _icv.size();
return static_cast<uint32_t>(sizeof(_header) + _icv.size());
}
void IPSecAH::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {

View File

@@ -203,7 +203,7 @@ void IPv6::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
}
set_last_next_header(new_flag);
}
payload_length(total_sz - sizeof(_header));
payload_length(static_cast<uint16_t>(total_sz - sizeof(_header)));
std::memcpy(buffer, &_header, sizeof(_header));
buffer += sizeof(_header);
for(headers_type::const_iterator it = ext_headers.begin(); it != ext_headers.end(); ++it) {
@@ -227,7 +227,7 @@ void IPv6::send(PacketSender &sender, const NetworkInterface &) {
void IPv6::add_ext_header(const ext_header &header) {
ext_headers.push_back(header);
headers_size += header.data_size() + sizeof(uint8_t) * 2;
headers_size += static_cast<uint32_t>(header.data_size() + sizeof(uint8_t) * 2);
}
const IPv6::ext_header *IPv6::search_header(ExtensionHeader id) const {
@@ -251,7 +251,7 @@ void IPv6::set_last_next_header(uint8_t value) {
uint8_t *IPv6::write_header(const ext_header &header, uint8_t *buffer) {
*buffer++ = header.option();
*buffer++ = (header.length_field() > 8) ? (header.length_field() - 8) : 0;
*buffer++ = static_cast<uint8_t>((header.length_field() > 8) ? (header.length_field() - 8) : 0);
return std::copy(header.data_ptr(), header.data_ptr() + header.data_size(), buffer);
}

View File

@@ -190,7 +190,7 @@ void LLC::add_xid_information(uint8_t xid_id, uint8_t llc_type_class, uint8_t re
xid[0] = xid_id;
xid[1] = llc_type_class;
xid[2] = receive_window;
information_field_length += xid.size();
information_field_length += static_cast<uint8_t>(xid.size());
information_fields.push_back(xid);
}

View File

@@ -76,7 +76,7 @@ bool OfflinePacketFilter::matches_filter(const uint8_t* buffer,
bool OfflinePacketFilter::matches_filter(PDU& pdu) const
{
PDU::serialization_type buffer = pdu.serialize();
return matches_filter(&buffer[0], buffer.size());
return matches_filter(&buffer[0], static_cast<uint32_t>(buffer.size()));
}
} // Tins

View File

@@ -74,10 +74,14 @@ const int PacketSender::INVALID_RAW_SOCKET = -1;
const uint32_t PacketSender::DEFAULT_TIMEOUT = 2;
#ifndef _WIN32
typedef int socket_type;
const char *make_error_string() {
return strerror(errno);
}
#else
typedef SOCKET socket_type;
// fixme
const char *make_error_string() {
return "error";
@@ -226,7 +230,7 @@ void PacketSender::open_l3_socket(SocketType type) {
if(socktype == -1)
throw invalid_socket_type();
if(_sockets[type] == INVALID_RAW_SOCKET) {
int sockfd;
socket_type sockfd;
sockfd = socket((type == IPV6_SOCKET) ? AF_INET6 : AF_INET, SOCK_RAW, socktype);
if (sockfd < 0)
throw socket_open_error(make_error_string());
@@ -239,7 +243,7 @@ void PacketSender::open_l3_socket(SocketType type) {
#endif
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL,(option_ptr)&on,sizeof(on));
_sockets[type] = sockfd;
_sockets[type] = static_cast<int>(sockfd);
}
}
@@ -314,7 +318,7 @@ void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr,
#ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET
open_l2_socket(iface);
pcap_t* handle = pcap_handles[iface];
if (pcap_sendpacket(handle, (u_char*)&buffer[0], buffer.size()) != 0) {
if (pcap_sendpacket(handle, (u_char*)&buffer[0], static_cast<int>(buffer.size())) != 0) {
throw runtime_error("Failed to send packet: " + string(pcap_geterr(handle)));
}
#else // HAVE_PACKET_SENDER_PCAP_SENDPACKET
@@ -359,7 +363,7 @@ void PacketSender::send_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_ad
open_l3_socket(type);
int sock = _sockets[type];
PDU::serialization_type buffer = pdu.serialize();
if(sendto(sock, (const char*)&buffer[0], buffer.size(), 0, link_addr, len_addr) == -1)
if(sendto(sock, (const char*)&buffer[0], static_cast<int>(buffer.size()), 0, link_addr, len_addr) == -1)
throw socket_write_error(make_error_string());
}

View File

@@ -95,7 +95,7 @@ PDU *PDU::release_inner_pdu() {
PDU::serialization_type PDU::serialize() {
std::vector<uint8_t> buffer(size());
serialize(&buffer[0], buffer.size(), 0);
serialize(&buffer[0], static_cast<uint32_t>(buffer.size()), 0);
// Copy elision, do your magic
return buffer;

View File

@@ -57,7 +57,7 @@ PPI::PPI(const uint8_t *buffer, uint32_t total_sz) {
if(options_length > 0) {
_data.assign(buffer, buffer + options_length);
buffer += options_length;
total_sz -= options_length;
total_sz -= static_cast<uint32_t>(options_length);
}
if(total_sz > 0) {
switch(dlt()) {
@@ -92,7 +92,7 @@ PPI::PPI(const uint8_t *buffer, uint32_t total_sz) {
}
uint32_t PPI::header_size() const {
return sizeof(_header) + _data.size();
return static_cast<uint32_t>(sizeof(_header) + _data.size());
}
void PPI::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {

View File

@@ -132,7 +132,7 @@ void PPPoE::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
for(tags_type::const_iterator it = _tags.begin(); it != _tags.end(); ++it) {
uint16_t_buffer = it->option();
std::memcpy(buffer, &uint16_t_buffer, sizeof(uint16_t));
uint16_t_buffer = Endian::host_to_be<uint16_t>(it->length_field());
uint16_t_buffer = Endian::host_to_be(static_cast<uint16_t>(it->length_field()));
std::memcpy(buffer + sizeof(uint16_t), &uint16_t_buffer, sizeof(uint16_t));
std::copy(
it->data_ptr(),
@@ -144,7 +144,7 @@ void PPPoE::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
}
void PPPoE::add_tag(const tag &option) {
_tags_size += option.data_size() + sizeof(uint16_t) * 2;
_tags_size += static_cast<uint16_t>(option.data_size() + sizeof(uint16_t) * 2);
_tags.push_back(option);
}

View File

@@ -194,7 +194,7 @@ uint32_t RadioTap::find_extra_flag_fields_size(const uint8_t* buffer, uint32_t t
++ptr;
}
return (const uint8_t*)ptr - buffer;
return static_cast<uint32_t>((const uint8_t*)ptr - buffer);
}
// Setter for RadioTap fields

View File

@@ -47,7 +47,7 @@ RawPDU::RawPDU(const std::string &data)
}
uint32_t RawPDU::header_size() const {
return _payload.size();
return static_cast<uint32_t>(_payload.size());
}
void RawPDU::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {

View File

@@ -48,7 +48,7 @@ RSNInformation::RSNInformation() : _version(1), _capabilities(0) {
}
RSNInformation::RSNInformation(const serialization_type &buffer) {
init(&buffer[0], buffer.size());
init(&buffer[0], static_cast<uint32_t>(buffer.size()));
}
RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
@@ -124,12 +124,12 @@ void RSNInformation::capabilities(uint16_t cap) {
}
RSNInformation::serialization_type RSNInformation::serialize() const {
uint32_t size = sizeof(_version) + sizeof(_capabilities) + sizeof(uint32_t);
size_t size = sizeof(_version) + sizeof(_capabilities) + sizeof(uint32_t);
size += (sizeof(uint16_t) << 1); // 2 lists count.
size += sizeof(uint32_t) * (_akm_cyphers.size() + _pairwise_cyphers.size());
uint16_t pairwise_cyphers_size = _pairwise_cyphers.size();
uint16_t akm_cyphers_size = _akm_cyphers.size();
const size_t pairwise_cyphers_size = _pairwise_cyphers.size();
const size_t akm_cyphers_size = _akm_cyphers.size();
uint16_t capabilities = Endian::host_to_le(_capabilities);
uint16_t version = Endian::host_to_le(_version);
@@ -167,7 +167,7 @@ RSNInformation RSNInformation::wpa2_psk() {
RSNInformation RSNInformation::from_option(const PDUOption<uint8_t, Dot11> &opt) {
if(opt.data_size() < sizeof(uint16_t) * 2 + sizeof(uint32_t))
throw malformed_option();
return RSNInformation(opt.data_ptr(), opt.data_size());
return RSNInformation(opt.data_ptr(), static_cast<uint32_t>(opt.data_size()));
}
}

View File

@@ -59,7 +59,7 @@ TCP::TCP(const uint8_t *buffer, uint32_t total_sz)
if(data_offset() * sizeof(uint32_t) > total_sz || data_offset() * sizeof(uint32_t) < sizeof(tcphdr))
throw malformed_packet();
const uint8_t *header_end = buffer + (data_offset() * sizeof(uint32_t));
total_sz = total_sz - (header_end - buffer);
total_sz = static_cast<uint32_t>(total_sz - (header_end - buffer));
buffer += sizeof(tcphdr);
_total_options_size = 0;
@@ -338,7 +338,7 @@ uint8_t *TCP::write_option(const option &opt, uint8_t *buffer) {
}
else {
buffer[0] = opt.option();
buffer[1] = opt.length_field();
buffer[1] = static_cast<uint8_t>(opt.length_field());
// only add the identifier and size field sizes if the length
// field hasn't been spoofed.
if(opt.length_field() == opt.data_size())
@@ -355,7 +355,7 @@ void TCP::internal_add_option(const option &opt) {
if(opt.data_size() || opt.option() == SACK_OK)
_options_size += sizeof(uint8_t);
_options_size += opt.data_size();
_options_size += static_cast<uint16_t>(opt.data_size());
padding = _options_size & 3;
_total_options_size = (padding) ? _options_size - padding + 4 : _options_size;

View File

@@ -80,10 +80,12 @@ void UDP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par
assert(total_sz >= sizeof(udphdr));
#endif
_udp.check = 0;
if(inner_pdu())
length(sizeof(udphdr) + inner_pdu()->size());
else
length(sizeof(udphdr));
if(inner_pdu()) {
length(static_cast<uint16_t>(sizeof(udphdr) + inner_pdu()->size()));
}
else {
length(static_cast<uint16_t>(sizeof(udphdr)));
}
std::memcpy(buffer, &_udp, sizeof(udphdr));
const Tins::IP *ip_packet = tins_cast<const Tins::IP*>(parent);
if(ip_packet) {