mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 20:44:26 +01:00
Modified some examples fixed some doxygen documentation.
This commit is contained in:
@@ -159,14 +159,13 @@ void Dot11ManagementFrame::power_capability(uint8_t min_power, uint8_t max_power
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::supported_channels(const channels_type &new_channels) {
|
||||
uint8_t* buffer = new uint8_t[new_channels.size() * 2];
|
||||
uint8_t* ptr = buffer;
|
||||
std::vector<uint8_t> buffer(new_channels.size() * 2);
|
||||
uint8_t* ptr = &buffer[0];
|
||||
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, new_channels.size() * 2, buffer);
|
||||
delete[] buffer;
|
||||
add_tagged_option(SUPPORTED_CHANNELS, 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) {
|
||||
@@ -182,16 +181,13 @@ void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, ui
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::request_information(const request_info_type elements) {
|
||||
uint8_t *buffer = new uint8_t[elements.size()], *ptr = buffer;
|
||||
for (request_info_type::const_iterator it = elements.begin(); it != elements.end(); ++it)
|
||||
*(ptr++) = *it;
|
||||
add_tagged_option(REQUEST_INFORMATION, elements.size(), buffer);
|
||||
delete[] buffer;
|
||||
add_tagged_option(REQUEST_INFORMATION, elements.size(), &elements[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::fh_parameter_set(const fh_params_set &fh_params) {
|
||||
uint8_t data[5];
|
||||
*(uint16_t*)data = Endian::host_to_le(fh_params.dwell_time);
|
||||
uint16_t dwell = Endian::host_to_le(fh_params.dwell_time);
|
||||
std::memcpy(data, &dwell, sizeof(dwell));
|
||||
data[2] = fh_params.hop_set;
|
||||
data[3] = fh_params.hop_pattern;
|
||||
data[4] = fh_params.hop_index;
|
||||
@@ -207,12 +203,10 @@ void Dot11ManagementFrame::cf_parameter_set(const cf_params_set ¶ms) {
|
||||
uint8_t data[6];
|
||||
data[0] = params.cfp_count;
|
||||
data[1] = params.cfp_period;
|
||||
*(uint16_t*)&data[2] = Endian::host_to_le(params.cfp_max_duration);
|
||||
*(uint16_t*)&data[4] = Endian::host_to_le(params.cfp_dur_remaining);
|
||||
/*params.cfp_count = params.cfp_count;
|
||||
params.cfp_period = params.cfp_period;
|
||||
params.cfp_max_duration = Endian::host_to_le(params.cfp_max_duration);
|
||||
params.cfp_dur_remaining = Endian::host_to_le(params.cfp_dur_remaining);*/
|
||||
uint16_t dummy = Endian::host_to_le(params.cfp_max_duration);
|
||||
std::memcpy(data + 2, &dummy, sizeof(uint16_t));
|
||||
dummy = Endian::host_to_le(params.cfp_dur_remaining);
|
||||
std::memcpy(data + 4, &dummy, sizeof(uint16_t));
|
||||
add_tagged_option(CF_SET, sizeof(data), data);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,8 +140,7 @@ bool EthernetII::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
|
||||
const size_t addr_sz = address_type::address_size;
|
||||
const ethhdr *eth_ptr = (const ethhdr*)ptr;
|
||||
if(std::equal(_eth.src_mac, _eth.src_mac + addr_sz, eth_ptr->dst_mac)) {
|
||||
if(std::equal(_eth.src_mac, _eth.src_mac + addr_sz, eth_ptr->dst_mac) || dst_addr() == BROADCAST ||
|
||||
(_eth.src_mac[0] == 0x33 && _eth.src_mac[1] == 0x33))
|
||||
if(std::equal(_eth.src_mac, _eth.src_mac + addr_sz, eth_ptr->dst_mac) || !dst_addr().is_unicast())
|
||||
{
|
||||
return (inner_pdu()) ? inner_pdu()->matches_response(ptr + sizeof(_eth), total_sz - sizeof(_eth)) : true;
|
||||
}
|
||||
|
||||
@@ -447,8 +447,8 @@ bool IP::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
|
||||
return false;
|
||||
const iphdr *ip_ptr = (const iphdr*)ptr;
|
||||
// checks for broadcast addr
|
||||
if((_ip.saddr == ip_ptr->daddr && (_ip.daddr == ip_ptr->saddr || _ip.daddr == 0xffffffff)) ||
|
||||
(_ip.daddr == 0xffffffff && _ip.saddr == 0)) {
|
||||
if((_ip.saddr == ip_ptr->daddr && (_ip.daddr == ip_ptr->saddr || dst_addr().is_broadcast())) ||
|
||||
(dst_addr().is_broadcast() && _ip.saddr == 0)) {
|
||||
uint32_t sz = std::min<uint32_t>(_ip.ihl * sizeof(uint32_t), total_sz);
|
||||
return inner_pdu() ? inner_pdu()->matches_response(ptr + sz, total_sz - sz) : true;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
using std::string;
|
||||
|
||||
namespace Tins{
|
||||
const IPv4Address IPv4Address::broadcast("255.255.255.255");
|
||||
|
||||
const AddressRange<IPv4Address> private_ranges[] = {
|
||||
IPv4Address("192.168.0.0") / 16,
|
||||
IPv4Address("10.0.0.0") / 8,
|
||||
@@ -122,4 +124,12 @@ bool IPv4Address::is_loopback() const {
|
||||
bool IPv4Address::is_multicast() const {
|
||||
return multicast_range.contains(*this);
|
||||
}
|
||||
|
||||
bool IPv4Address::is_unicast() const {
|
||||
return !is_multicast() && !is_broadcast();
|
||||
}
|
||||
|
||||
bool IPv4Address::is_broadcast() const {
|
||||
return *this == broadcast;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ void PacketSender::default_interface(const NetworkInterface &iface) {
|
||||
default_iface = iface;
|
||||
}
|
||||
|
||||
const NetworkInterface& PacketSender::default_interface() {
|
||||
const NetworkInterface& PacketSender::default_interface() const {
|
||||
return default_iface;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,10 +197,6 @@ TCP::AltChecksums TCP::altchecksum() const {
|
||||
return static_cast<AltChecksums>(generic_search<uint8_t>(ALTCHK));
|
||||
}
|
||||
|
||||
small_uint<1> TCP::get_flag(Flags tcp_flag) {
|
||||
return static_cast<const TCP&>(*this).get_flag(tcp_flag);
|
||||
}
|
||||
|
||||
small_uint<1> TCP::get_flag(Flags tcp_flag) const {
|
||||
switch(tcp_flag) {
|
||||
case FIN:
|
||||
|
||||
Reference in New Issue
Block a user