mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 04:54:28 +01:00
EthernetII, IEEE802_3 and Dot11(and subclasses) now use NetworkInterface and HWAddress.
This commit is contained in:
@@ -128,7 +128,7 @@ PDU *ARP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
|
||||
return cloned;
|
||||
}
|
||||
|
||||
PDU* ARP::make_arp_request(const std::string& iface, IPv4Address target,
|
||||
PDU* ARP::make_arp_request(const NetworkInterface& iface, IPv4Address target,
|
||||
IPv4Address sender, const hwaddress_type &hw_snd)
|
||||
{
|
||||
/* Create ARP packet and set its attributes */
|
||||
@@ -142,7 +142,7 @@ PDU* ARP::make_arp_request(const std::string& iface, IPv4Address target,
|
||||
return new EthernetII(iface, EthernetII::BROADCAST, hw_snd, arp);
|
||||
}
|
||||
|
||||
PDU* ARP::make_arp_reply(const string& iface, IPv4Address target,
|
||||
PDU* ARP::make_arp_reply(const NetworkInterface& iface, IPv4Address target,
|
||||
IPv4Address sender, const hwaddress_type &hw_tgt,
|
||||
const hwaddress_type &hw_snd)
|
||||
{
|
||||
|
||||
157
src/dot11.cpp
157
src/dot11.cpp
@@ -49,7 +49,7 @@ Tins::Dot11::Dot11(const address_type &dst_hw_addr, PDU* child)
|
||||
addr1(dst_hw_addr);
|
||||
}
|
||||
|
||||
Tins::Dot11::Dot11(const std::string& iface,
|
||||
Tins::Dot11::Dot11(const NetworkInterface &iface,
|
||||
const address_type &dst_hw_addr, PDU* child)
|
||||
: PDU(ETHERTYPE_IP, child), _options_size(0)
|
||||
{
|
||||
@@ -58,16 +58,6 @@ Tins::Dot11::Dot11(const std::string& iface,
|
||||
this->iface(iface);
|
||||
}
|
||||
|
||||
|
||||
Tins::Dot11::Dot11(uint32_t iface_index,
|
||||
const address_type &dst_hw_addr, PDU* child)
|
||||
: PDU(ETHERTYPE_IP, child), _options_size(0)
|
||||
{
|
||||
memset(&_header, 0, sizeof(ieee80211_header));
|
||||
addr1(dst_hw_addr);
|
||||
this->iface(iface_index);
|
||||
}
|
||||
|
||||
Tins::Dot11::Dot11(const ieee80211_header *header_ptr)
|
||||
: PDU(ETHERTYPE_IP)
|
||||
{
|
||||
@@ -180,18 +170,11 @@ void Tins::Dot11::duration_id(uint16_t new_duration_id) {
|
||||
}
|
||||
|
||||
void Tins::Dot11::addr1(const address_type &new_addr1) {
|
||||
//memcpy(this->_header.addr1, new_addr1, 6);
|
||||
std::copy(new_addr1.begin(), new_addr1.end(), _header.addr1);
|
||||
}
|
||||
|
||||
void Tins::Dot11::iface(uint32_t new_iface_index) {
|
||||
this->_iface_index = new_iface_index;
|
||||
}
|
||||
|
||||
void Tins::Dot11::iface(const std::string& new_iface) {
|
||||
if (!Tins::Utils::interface_id(new_iface, this->_iface_index)) {
|
||||
throw std::runtime_error("Invalid interface name!");
|
||||
}
|
||||
void Tins::Dot11::iface(const NetworkInterface &new_iface) {
|
||||
this->_iface = new_iface;
|
||||
}
|
||||
|
||||
uint32_t Tins::Dot11::header_size() const {
|
||||
@@ -207,7 +190,7 @@ bool Tins::Dot11::send(PacketSender* sender) {
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = this->_iface_index;
|
||||
addr.sll_ifindex = this->_iface.id();
|
||||
memcpy(&(addr.sll_addr), this->_header.addr1, 6);
|
||||
|
||||
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
@@ -275,7 +258,7 @@ Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) {
|
||||
|
||||
void Tins::Dot11::copy_80211_fields(const Dot11 *other) {
|
||||
std::memcpy(&_header, &other->_header, sizeof(_header));
|
||||
_iface_index = other->_iface_index;
|
||||
_iface = other->_iface;
|
||||
_options_size = other->_options_size;
|
||||
for(std::list<Dot11Option>::const_iterator it = other->_options.begin(); it != other->_options.end(); ++it)
|
||||
_options.push_back(Dot11Option(it->option, it->length, it->value));
|
||||
@@ -301,7 +284,7 @@ Tins::Dot11ManagementFrame::Dot11ManagementFrame(
|
||||
addr2(src_hw_addr);
|
||||
}
|
||||
|
||||
Tins::Dot11ManagementFrame::Dot11ManagementFrame(const std::string &iface,
|
||||
Tins::Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11(iface, dst_hw_addr)
|
||||
{
|
||||
@@ -327,12 +310,10 @@ uint32_t Tins::Dot11ManagementFrame::header_size() const {
|
||||
}
|
||||
|
||||
void Tins::Dot11ManagementFrame::addr2(const address_type &new_addr2) {
|
||||
//memcpy(this->_ext_header.addr2, new_addr2, 6);
|
||||
std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2);
|
||||
}
|
||||
|
||||
void Tins::Dot11ManagementFrame::addr3(const address_type &new_addr3) {
|
||||
//memcpy(this->_ext_header.addr3, new_addr3, 6);
|
||||
std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3);
|
||||
}
|
||||
|
||||
@@ -628,7 +609,7 @@ Tins::Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11Beacon::Dot11Beacon(const std::string& iface,
|
||||
Tins::Dot11Beacon::Dot11Beacon(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -840,7 +821,7 @@ Tins::Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11Disassoc::Dot11Disassoc(const std::string& iface,
|
||||
Tins::Dot11Disassoc::Dot11Disassoc(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr){
|
||||
this->subtype(Dot11::DISASSOC);
|
||||
@@ -892,7 +873,7 @@ Tins::Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11AssocRequest::Dot11AssocRequest(const std::string& iface,
|
||||
Tins::Dot11AssocRequest::Dot11AssocRequest(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -973,7 +954,7 @@ Tins::Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11AssocResponse::Dot11AssocResponse(const std::string& iface,
|
||||
Tins::Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1044,7 +1025,7 @@ Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const std::string& iface,
|
||||
Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1131,7 +1112,7 @@ Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const std::string& iface,
|
||||
Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1200,7 +1181,7 @@ Tins::Dot11ProbeRequest::Dot11ProbeRequest(const address_type &dst_hw_addr,
|
||||
this->subtype(Dot11::PROBE_REQ);
|
||||
}
|
||||
|
||||
Tins::Dot11ProbeRequest::Dot11ProbeRequest(const std::string& iface,
|
||||
Tins::Dot11ProbeRequest::Dot11ProbeRequest(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1246,7 +1227,7 @@ Tins::Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr,
|
||||
memset(&this->_body, 0, sizeof(this->_body));
|
||||
}
|
||||
|
||||
Tins::Dot11ProbeResponse::Dot11ProbeResponse(const std::string& iface,
|
||||
Tins::Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1395,7 +1376,7 @@ Tins::Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr,
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11Authentication::Dot11Authentication(const std::string& iface,
|
||||
Tins::Dot11Authentication::Dot11Authentication(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1462,7 +1443,7 @@ Tins::Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_ad
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Tins::Dot11Deauthentication::Dot11Deauthentication(const std::string& iface,
|
||||
Tins::Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
@@ -1529,14 +1510,6 @@ Tins::Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz)
|
||||
inner_pdu(new Tins::SNAP(buffer, total_sz));
|
||||
}
|
||||
|
||||
Tins::Dot11Data::Dot11Data(uint32_t iface_index, const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr, PDU* child)
|
||||
: Dot11(iface_index, dst_hw_addr, child)
|
||||
{
|
||||
type(Dot11::DATA);
|
||||
addr2(src_hw_addr);
|
||||
}
|
||||
|
||||
Tins::Dot11Data::Dot11Data(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr, PDU* child)
|
||||
: Dot11(dst_hw_addr, child)
|
||||
@@ -1546,7 +1519,7 @@ Tins::Dot11Data::Dot11Data(const address_type &dst_hw_addr,
|
||||
}
|
||||
|
||||
|
||||
Tins::Dot11Data::Dot11Data(const std::string &iface,
|
||||
Tins::Dot11Data::Dot11Data(const NetworkInterface &iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: Dot11(iface, dst_hw_addr, child)
|
||||
@@ -1569,12 +1542,10 @@ uint32_t Tins::Dot11Data::header_size() const {
|
||||
}
|
||||
|
||||
void Tins::Dot11Data::addr2(const address_type &new_addr2) {
|
||||
//memcpy(this->_ext_header.addr2, new_addr2, 6);
|
||||
std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2);
|
||||
}
|
||||
|
||||
void Tins::Dot11Data::addr3(const address_type &new_addr3) {
|
||||
//memcpy(this->_ext_header.addr3, new_addr3, 6);
|
||||
std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3);
|
||||
}
|
||||
|
||||
@@ -1617,7 +1588,7 @@ Tins::Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr,
|
||||
|
||||
}
|
||||
|
||||
Tins::Dot11QoSData::Dot11QoSData(const std::string& iface,
|
||||
Tins::Dot11QoSData::Dot11QoSData(const NetworkInterface &iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: Dot11Data(iface, dst_hw_addr, src_hw_addr, child)
|
||||
@@ -1626,15 +1597,6 @@ Tins::Dot11QoSData::Dot11QoSData(const std::string& iface,
|
||||
this->_qos_control = 0;
|
||||
}
|
||||
|
||||
Tins::Dot11QoSData::Dot11QoSData(uint32_t iface_index,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: Dot11Data(iface_index, dst_hw_addr, src_hw_addr, child)
|
||||
{
|
||||
this->subtype(Dot11::QOS_DATA_DATA);
|
||||
this->_qos_control = 0;
|
||||
}
|
||||
|
||||
Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11Data(buffer, std::min(data_frame_size(), total_sz)) {
|
||||
uint32_t sz = data_frame_size();
|
||||
@@ -1693,20 +1655,13 @@ Tins::Dot11Control::Dot11Control(const address_type &dst_addr, PDU* child)
|
||||
type(CONTROL);
|
||||
}
|
||||
|
||||
Tins::Dot11Control::Dot11Control(const std::string& iface,
|
||||
Tins::Dot11Control::Dot11Control(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, PDU* child)
|
||||
: Dot11(iface, dst_addr, child)
|
||||
{
|
||||
type(CONTROL);
|
||||
}
|
||||
|
||||
Tins::Dot11Control::Dot11Control(uint32_t iface_index,
|
||||
const address_type &dst_addr, PDU* child)
|
||||
: Dot11(iface_index, dst_addr, child)
|
||||
{
|
||||
type(CONTROL);
|
||||
}
|
||||
|
||||
Tins::Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz) {
|
||||
|
||||
@@ -1720,20 +1675,13 @@ Tins::Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr,
|
||||
target_addr(target_address);
|
||||
}
|
||||
|
||||
Tins::Dot11ControlTA::Dot11ControlTA(const std::string& iface,
|
||||
Tins::Dot11ControlTA::Dot11ControlTA(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_address, PDU* child)
|
||||
: Dot11Control(iface, dst_addr, child)
|
||||
{
|
||||
target_addr(target_address);
|
||||
}
|
||||
|
||||
Tins::Dot11ControlTA::Dot11ControlTA(uint32_t iface_index,
|
||||
const address_type &dst_addr, const address_type &target_address, PDU* child)
|
||||
: Dot11Control(iface_index, dst_addr, child)
|
||||
{
|
||||
target_addr(target_address);
|
||||
}
|
||||
|
||||
Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
|
||||
buffer += sizeof(ieee80211_header);
|
||||
total_sz -= sizeof(ieee80211_header);
|
||||
@@ -1753,7 +1701,6 @@ uint32_t Tins::Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_
|
||||
}
|
||||
|
||||
void Tins::Dot11ControlTA::target_addr(const address_type &addr) {
|
||||
//std::memcpy(_taddr, addr, sizeof(_taddr));
|
||||
std::copy(addr.begin(), addr.end(), _taddr);
|
||||
}
|
||||
|
||||
@@ -1765,20 +1712,13 @@ Tins::Dot11RTS::Dot11RTS(const address_type &dst_addr ,
|
||||
subtype(RTS);
|
||||
}
|
||||
|
||||
Tins::Dot11RTS::Dot11RTS(const std::string& iface, const address_type &dst_addr,
|
||||
Tins::Dot11RTS::Dot11RTS(const NetworkInterface &iface, const address_type &dst_addr,
|
||||
const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(RTS);
|
||||
}
|
||||
|
||||
Tins::Dot11RTS::Dot11RTS(uint32_t iface_index, const address_type &dst_addr,
|
||||
const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(RTS);
|
||||
}
|
||||
|
||||
Tins::Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
@@ -1799,20 +1739,13 @@ Tins::Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr,
|
||||
subtype(PS);
|
||||
}
|
||||
|
||||
Tins::Dot11PSPoll::Dot11PSPoll(const std::string& iface,
|
||||
Tins::Dot11PSPoll::Dot11PSPoll(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(PS);
|
||||
}
|
||||
|
||||
Tins::Dot11PSPoll::Dot11PSPoll(uint32_t iface_index, const address_type &dst_addr,
|
||||
const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(PS);
|
||||
}
|
||||
|
||||
Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
@@ -1833,20 +1766,13 @@ Tins::Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr,
|
||||
subtype(CF_END);
|
||||
}
|
||||
|
||||
Tins::Dot11CFEnd::Dot11CFEnd(const std::string& iface,
|
||||
Tins::Dot11CFEnd::Dot11CFEnd(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(CF_END);
|
||||
}
|
||||
|
||||
Tins::Dot11CFEnd::Dot11CFEnd(uint32_t iface_index, const address_type &dst_addr,
|
||||
const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(CF_END);
|
||||
}
|
||||
|
||||
Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
@@ -1867,20 +1793,13 @@ Tins::Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr,
|
||||
subtype(CF_END_ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11EndCFAck::Dot11EndCFAck(const std::string& iface,
|
||||
Tins::Dot11EndCFAck::Dot11EndCFAck(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(CF_END_ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11EndCFAck::Dot11EndCFAck(uint32_t iface_index,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(CF_END_ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
@@ -1900,20 +1819,13 @@ Tins::Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child)
|
||||
subtype(ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11Ack::Dot11Ack(const std::string& iface,
|
||||
Tins::Dot11Ack::Dot11Ack(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, PDU* child)
|
||||
: Dot11Control(iface, dst_addr, child)
|
||||
{
|
||||
subtype(ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11Ack::Dot11Ack(uint32_t iface_index,
|
||||
const address_type &dst_addr, PDU* child)
|
||||
: Dot11Control(iface_index, dst_addr, child)
|
||||
{
|
||||
subtype(ACK);
|
||||
}
|
||||
|
||||
Tins::Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
|
||||
|
||||
}
|
||||
@@ -1933,20 +1845,13 @@ Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(
|
||||
init_block_ack();
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const std::string& iface,
|
||||
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
init_block_ack();
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(uint32_t iface_index,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
init_block_ack();
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
|
||||
uint32_t padding = controlta_size();
|
||||
buffer += padding;
|
||||
@@ -2000,7 +1905,7 @@ Tins::Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr,
|
||||
std::memset(_bitmap, 0, sizeof(_bitmap));
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAck::Dot11BlockAck(const std::string& iface,
|
||||
Tins::Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface, dst_addr, target_addr, child)
|
||||
{
|
||||
@@ -2008,14 +1913,6 @@ Tins::Dot11BlockAck::Dot11BlockAck(const std::string& iface,
|
||||
std::memset(_bitmap, 0, sizeof(_bitmap));
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAck::Dot11BlockAck(uint32_t iface_index,
|
||||
const address_type &dst_addr, const address_type &target_addr, PDU* child)
|
||||
: Dot11ControlTA(iface_index, dst_addr, target_addr, child)
|
||||
{
|
||||
subtype(BLOCK_ACK);
|
||||
std::memset(_bitmap, 0, sizeof(_bitmap));
|
||||
}
|
||||
|
||||
Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
|
||||
uint32_t padding = controlta_size();
|
||||
buffer += padding;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
const uint8_t* Tins::EthernetII::BROADCAST = (const uint8_t*)"\xff\xff\xff\xff\xff\xff";
|
||||
const uint32_t Tins::EthernetII::ADDR_SIZE;
|
||||
|
||||
Tins::EthernetII::EthernetII(const std::string& iface,
|
||||
Tins::EthernetII::EthernetII(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: PDU(ETHERTYPE_IP, child)
|
||||
@@ -49,18 +49,6 @@ Tins::EthernetII::EthernetII(const std::string& iface,
|
||||
|
||||
}
|
||||
|
||||
Tins::EthernetII::EthernetII(uint32_t iface_index,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: PDU(ETHERTYPE_IP, child)
|
||||
{
|
||||
memset(&_eth, 0, sizeof(ethhdr));
|
||||
dst_addr(dst_hw_addr);
|
||||
src_addr(src_hw_addr);
|
||||
iface(iface_index);
|
||||
_eth.payload_type = 0;
|
||||
}
|
||||
|
||||
Tins::EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz)
|
||||
: PDU(ETHERTYPE_IP)
|
||||
{
|
||||
@@ -92,14 +80,8 @@ void Tins::EthernetII::src_addr(const address_type &new_src_mac) {
|
||||
std::copy(new_src_mac.begin(), new_src_mac.end(), _eth.src_mac);
|
||||
}
|
||||
|
||||
void Tins::EthernetII::iface(uint32_t new_iface_index) {
|
||||
_iface_index = new_iface_index;
|
||||
}
|
||||
|
||||
void Tins::EthernetII::iface(const std::string& new_iface) throw (std::runtime_error) {
|
||||
if (!Tins::Utils::interface_id(new_iface, this->_iface_index)) {
|
||||
throw std::runtime_error("Invalid interface name!");
|
||||
}
|
||||
void Tins::EthernetII::iface(const NetworkInterface& new_iface) {
|
||||
_iface = new_iface;
|
||||
}
|
||||
|
||||
void Tins::EthernetII::payload_type(uint16_t new_payload_type) {
|
||||
@@ -118,7 +100,7 @@ bool Tins::EthernetII::send(PacketSender* sender) {
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface_index;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
|
||||
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
@@ -164,7 +146,7 @@ Tins::PDU *Tins::EthernetII::recv_response(PacketSender *sender) {
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface_index;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
|
||||
return sender->recv_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#ifndef WIN32
|
||||
#include <net/ethernet.h>
|
||||
#include <netpacket/packet.h>
|
||||
@@ -31,29 +32,20 @@
|
||||
#include "utils.h"
|
||||
|
||||
const uint8_t* Tins::IEEE802_3::BROADCAST = (const uint8_t*)"\xff\xff\xff\xff\xff\xff";
|
||||
const uint32_t Tins::IEEE802_3::ADDR_SIZE;
|
||||
|
||||
Tins::IEEE802_3::IEEE802_3(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : PDU(ETHERTYPE_IP, child) {
|
||||
Tins::IEEE802_3::IEEE802_3(const NetworkInterface& iface,
|
||||
const address_type &dst_hw_addr, const address_type &src_hw_addr,
|
||||
PDU* child)
|
||||
: PDU(ETHERTYPE_IP, child)
|
||||
{
|
||||
memset(&_eth, 0, sizeof(ethhdr));
|
||||
if(dst_hw_addr)
|
||||
this->dst_addr(dst_hw_addr);
|
||||
if(src_hw_addr)
|
||||
this->src_addr(src_hw_addr);
|
||||
this->dst_addr(dst_hw_addr);
|
||||
this->src_addr(src_hw_addr);
|
||||
this->iface(iface);
|
||||
this->_eth.length = 0;
|
||||
|
||||
}
|
||||
|
||||
Tins::IEEE802_3::IEEE802_3(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child) {
|
||||
memset(&_eth, 0, sizeof(ethhdr));
|
||||
if(dst_hw_addr)
|
||||
this->dst_addr(dst_hw_addr);
|
||||
if(src_hw_addr)
|
||||
this->src_addr(src_hw_addr);
|
||||
this->iface(iface_index);
|
||||
this->_eth.length = 0;
|
||||
}
|
||||
|
||||
Tins::IEEE802_3::IEEE802_3(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP) {
|
||||
if(total_sz < sizeof(ethhdr))
|
||||
throw std::runtime_error("Not enough size for an ethernetII header in the buffer.");
|
||||
@@ -67,22 +59,16 @@ Tins::IEEE802_3::IEEE802_3(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHER
|
||||
}
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::dst_addr(const uint8_t* new_dst_mac) {
|
||||
memcpy(_eth.dst_mac, new_dst_mac, sizeof(_eth.dst_mac));
|
||||
void Tins::IEEE802_3::dst_addr(const address_type &new_dst_mac) {
|
||||
std::copy(new_dst_mac.begin(), new_dst_mac.end(), _eth.dst_mac);
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::src_addr(const uint8_t* new_src_mac) {
|
||||
memcpy(_eth.src_mac, new_src_mac, sizeof(_eth.src_mac));
|
||||
void Tins::IEEE802_3::src_addr(const address_type &new_src_mac) {
|
||||
std::copy(new_src_mac.begin(), new_src_mac.end(), _eth.src_mac);
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::iface(uint32_t new_iface_index) {
|
||||
_iface_index = new_iface_index;
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::iface(const std::string& new_iface) throw (std::runtime_error) {
|
||||
if (!Tins::Utils::interface_id(new_iface, this->_iface_index)) {
|
||||
throw std::runtime_error("Invalid interface name!");
|
||||
}
|
||||
void Tins::IEEE802_3::iface(const NetworkInterface &new_iface) {
|
||||
_iface = new_iface;
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::length(uint16_t new_length) {
|
||||
@@ -100,9 +86,9 @@ bool Tins::IEEE802_3::send(PacketSender* sender) {
|
||||
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface_index;
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
addr.sll_halen = address_type::address_size;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, sizeof(_eth.dst_mac));
|
||||
|
||||
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
}
|
||||
@@ -111,7 +97,7 @@ bool Tins::IEEE802_3::matches_response(uint8_t *ptr, uint32_t total_sz) {
|
||||
if(total_sz < sizeof(ethhdr))
|
||||
return false;
|
||||
ethhdr *eth_ptr = (ethhdr*)ptr;
|
||||
if(!memcmp(eth_ptr->dst_mac, _eth.src_mac, ADDR_SIZE)) {
|
||||
if(!memcmp(eth_ptr->dst_mac, _eth.src_mac, sizeof(_eth.src_mac))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -137,9 +123,9 @@ Tins::PDU *Tins::IEEE802_3::recv_response(PacketSender *sender) {
|
||||
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_802_3);
|
||||
addr.sll_halen = ADDR_SIZE;
|
||||
addr.sll_ifindex = _iface_index;
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
|
||||
addr.sll_halen = address_type::address_size;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
memcpy(&(addr.sll_addr), _eth.dst_mac, sizeof(_eth.dst_mac));
|
||||
|
||||
return sender->recv_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
}
|
||||
@@ -156,14 +142,3 @@ Tins::PDU *Tins::IEEE802_3::clone_packet(const uint8_t *ptr, uint32_t total_sz)
|
||||
cloned->inner_pdu(child);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
void Tins::IEEE802_3::copy_fields(const IEEE802_3 *other) {
|
||||
memcpy(&_eth, &other->_eth, sizeof(_eth));
|
||||
_iface_index = other->_iface_index;
|
||||
}
|
||||
|
||||
Tins::PDU *Tins::IEEE802_3::clone_pdu() const {
|
||||
IEEE802_3 *new_pdu = new IEEE802_3(_iface_index);
|
||||
new_pdu->copy_fields(this);
|
||||
return new_pdu;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,16 @@ IPv4Address::IPv4Address(uint32_t ip) : ip_addr(ip) {
|
||||
|
||||
}
|
||||
|
||||
IPv4Address::IPv4Address(const std::string &ip) :
|
||||
ip_addr(Utils::ip_to_int(ip)) {
|
||||
IPv4Address::IPv4Address(const std::string &ip)
|
||||
: ip_addr(Utils::ip_to_int(ip)) {
|
||||
|
||||
}
|
||||
|
||||
IPv4Address::IPv4Address(const char *ip)
|
||||
: ip_addr(Utils::ip_to_int(ip)) {
|
||||
|
||||
}
|
||||
|
||||
IPv4Address &IPv4Address::operator=(uint32_t ip) {
|
||||
ip_addr = ip;
|
||||
return *this;
|
||||
|
||||
@@ -61,17 +61,23 @@ struct InterfaceInfoCollector {
|
||||
/** \endcond */
|
||||
|
||||
namespace Tins {
|
||||
NetworkInterface::NetworkInterface() : iface_id(0) {
|
||||
|
||||
}
|
||||
|
||||
NetworkInterface::NetworkInterface(const std::string &name) {
|
||||
iface_id = if_nametoindex(name.c_str());
|
||||
if(!iface_id)
|
||||
throw std::runtime_error("Invalid interface error");
|
||||
iface_id = resolve_index(name.c_str());
|
||||
}
|
||||
|
||||
NetworkInterface::NetworkInterface(const char *name) {
|
||||
iface_id = resolve_index(name);
|
||||
}
|
||||
|
||||
NetworkInterface::NetworkInterface(IPv4Address ip) : iface_id(0) {
|
||||
typedef std::vector<Utils::RouteEntry> entries_type;
|
||||
|
||||
if(ip == "127.0.0.1")
|
||||
iface_id = if_nametoindex("lo");
|
||||
iface_id = resolve_index("lo");
|
||||
else {
|
||||
entries_type entries;
|
||||
uint32_t ip_int = ip;
|
||||
@@ -103,5 +109,12 @@ NetworkInterface::Info NetworkInterface::addresses() const {
|
||||
throw std::runtime_error("Error looking up interface address");
|
||||
return info;
|
||||
}
|
||||
|
||||
NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) {
|
||||
id_type id = if_nametoindex(name);
|
||||
if(!id)
|
||||
throw std::runtime_error("Invalid interface error");
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,14 +30,9 @@
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
Tins::RadioTap::RadioTap(const std::string &iface, PDU *child) throw (std::runtime_error) : PDU(0xff, child), _options_size(0) {
|
||||
if(!Utils::interface_id(iface, _iface_index))
|
||||
throw std::runtime_error("Invalid interface name!");
|
||||
std::memset(&_radio, 0, sizeof(_radio));
|
||||
init();
|
||||
}
|
||||
|
||||
Tins::RadioTap::RadioTap(uint32_t iface_index, PDU *child) : PDU(0xff, child), _iface_index(iface_index) {
|
||||
Tins::RadioTap::RadioTap(const NetworkInterface &iface, PDU *child)
|
||||
: PDU(0xff, child), _iface(iface), _options_size(0)
|
||||
{
|
||||
std::memset(&_radio, 0, sizeof(_radio));
|
||||
init();
|
||||
}
|
||||
@@ -205,7 +200,7 @@ bool Tins::RadioTap::send(PacketSender* sender) {
|
||||
addr.sll_family = Utils::net_to_host_s(PF_PACKET);
|
||||
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = _iface_index;
|
||||
addr.sll_ifindex = _iface.id();
|
||||
|
||||
Tins::Dot11 *wlan = dynamic_cast<Tins::Dot11*>(inner_pdu());
|
||||
if(wlan) {
|
||||
|
||||
Reference in New Issue
Block a user