1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 12:01:34 +01:00

Code cleanup and use same syntax on the entire project

Initial code cleanup

More code cleanup

Cleanup more code

Cleanup Dot11 code

Fix OSX build issue

Cleanup examples

Fix ref and pointer declaration syntax

Fix braces
This commit is contained in:
Matias Fontanini
2016-01-02 08:17:59 -08:00
parent f5a82b1a17
commit d84f10cf08
177 changed files with 13203 additions and 12272 deletions

View File

@@ -38,17 +38,16 @@
#include "exceptions.h"
#include "memory_helpers.h"
using std::runtime_error;
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
ARP::ARP(ipaddress_type target_ip, ipaddress_type sender_ip,
const hwaddress_type &target_hw, const hwaddress_type &sender_hw)
: _arp()
{
ARP::ARP(ipaddress_type target_ip,
ipaddress_type sender_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_length(Tins::EthernetII::address_type::address_size);
@@ -59,89 +58,92 @@ const hwaddress_type &target_hw, const hwaddress_type &sender_hw)
target_hw_addr(target_hw);
}
ARP::ARP(const uint8_t *buffer, uint32_t total_sz)
{
ARP::ARP(const uint8_t* buffer, uint32_t total_sz) {
InputMemoryStream stream(buffer, total_sz);
stream.read(_arp);
stream.read(header_);
if (stream) {
inner_pdu(new RawPDU(stream.pointer(), stream.size()));
}
}
void ARP::sender_hw_addr(const hwaddress_type &new_snd_hw_addr) {
std::copy(new_snd_hw_addr.begin(), new_snd_hw_addr.end(), _arp.ar_sha);
void ARP::sender_hw_addr(const hwaddress_type& address) {
address.copy(header_.sender_hw_address);
}
void ARP::sender_ip_addr(ipaddress_type new_snd_ip_addr) {
this->_arp.ar_sip = new_snd_ip_addr;
void ARP::sender_ip_addr(ipaddress_type address) {
header_.sender_ip_address = address;
}
void ARP::target_hw_addr(const hwaddress_type &new_tgt_hw_addr) {
std::copy(new_tgt_hw_addr.begin(), new_tgt_hw_addr.end(), _arp.ar_tha);
void ARP::target_hw_addr(const hwaddress_type& address) {
address.copy(header_.target_hw_address);
}
void ARP::target_ip_addr(ipaddress_type new_tgt_ip_addr) {
this->_arp.ar_tip = new_tgt_ip_addr;
void ARP::target_ip_addr(ipaddress_type address) {
header_.target_ip_address = address;
}
void ARP::hw_addr_format(uint16_t new_hw_addr_fmt) {
this->_arp.ar_hrd = Endian::host_to_be(new_hw_addr_fmt);
void ARP::hw_addr_format(uint16_t format) {
header_.hw_address_format = Endian::host_to_be(format);
}
void ARP::prot_addr_format(uint16_t new_prot_addr_fmt) {
this->_arp.ar_pro = Endian::host_to_be(new_prot_addr_fmt);
void ARP::prot_addr_format(uint16_t format) {
header_.proto_address_format = Endian::host_to_be(format);
}
void ARP::hw_addr_length(uint8_t new_hw_addr_len) {
this->_arp.ar_hln = new_hw_addr_len;
void ARP::hw_addr_length(uint8_t length) {
header_.hw_address_length = length;
}
void ARP::prot_addr_length(uint8_t new_prot_addr_len) {
this->_arp.ar_pln = new_prot_addr_len;
void ARP::prot_addr_length(uint8_t length) {
header_.proto_address_length = length;
}
void ARP::opcode(Flags new_opcode) {
this->_arp.ar_op = Endian::host_to_be<uint16_t>(new_opcode);
void ARP::opcode(Flags code) {
header_.opcode = Endian::host_to_be<uint16_t>(code);
}
uint32_t ARP::header_size() const {
return sizeof(arphdr);
return sizeof(header_);
}
void ARP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
void ARP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
OutputMemoryStream stream(buffer, total_sz);
stream.write(_arp);
stream.write(header_);
}
bool ARP::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
if(total_sz < sizeof(arphdr))
bool ARP::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
if (total_sz < sizeof(header_)) {
return false;
const arphdr *arp_ptr = (const arphdr*)ptr;
return arp_ptr->ar_sip == _arp.ar_tip && arp_ptr->ar_tip == _arp.ar_sip;
}
const arp_header* arp_ptr = (const arp_header*)ptr;
return arp_ptr->sender_ip_address == header_.target_ip_address &&
arp_ptr->target_ip_address == header_.sender_ip_address;
}
EthernetII ARP::make_arp_request(ipaddress_type target, ipaddress_type sender,
const hwaddress_type &hw_snd)
{
/* Create ARP packet and set its attributes */
EthernetII ARP::make_arp_request(ipaddress_type target,
ipaddress_type sender,
const hwaddress_type& hw_snd) {
// Create ARP packet and set its attributes
ARP arp;
arp.target_ip_addr(target);
arp.sender_ip_addr(sender);
arp.sender_hw_addr(hw_snd);
arp.opcode(REQUEST);
/* Create the EthernetII PDU with the ARP PDU as its inner PDU */
// Create the EthernetII PDU with the ARP PDU as its inner PDU
return EthernetII(EthernetII::BROADCAST, hw_snd) / arp;
}
EthernetII ARP::make_arp_reply(ipaddress_type target, ipaddress_type sender,
const hwaddress_type &hw_tgt, const hwaddress_type &hw_snd)
{
/* Create ARP packet and set its attributes */
EthernetII ARP::make_arp_reply(ipaddress_type target,
ipaddress_type sender,
const hwaddress_type& hw_tgt,
const hwaddress_type& hw_snd) {
// Create ARP packet and set its attributes
ARP arp(target, sender, hw_tgt, hw_snd);
arp.opcode(REPLY);
/* Create the EthernetII PDU with the ARP PDU as its inner PDU */
// Create the EthernetII PDU with the ARP PDU as its inner PDU
return EthernetII(hw_tgt, hw_snd) / arp;
}
}
} // Tins