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

RadioTap is working now.

This commit is contained in:
Matias Fontanini
2011-08-21 21:09:19 -03:00
parent 393beda0d7
commit 88146bac89
3 changed files with 85 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ namespace Tins {
ETHERNET_II,
IEEE802_11,
SNAP,
RADIOTAP,
IP,
ARP,
TCP,

View File

@@ -30,7 +30,7 @@ namespace Tins {
/**
* \brief Class that represents the IEEE 802.11 radio tap header.
*/
class RadioTap {
class RadioTap : public PDU {
public:
/**
* Creates an instance of RadioTap.
@@ -44,11 +44,63 @@ namespace Tins {
*/
RadioTap(uint32_t iface_index);
/* Setters */
/**
* \sa PDU::send()
*/
bool send(PacketSender* sender);
/**
* \brief Setter for the version field.
* \param new_version The new version.
*/
void version(uint8_t new_version);
/**
* \brief Setter for the padding field.
* \param new_padding The new padding.
*/
void padding(uint8_t new_padding);
/**
* \brief Setter for the length field.
* \param new_length The new length.
*/
void length(uint8_t new_length);
/**
* \brief Setter for the present field.
* \param new_present The new present.
*/
void present(uint8_t new_present);
/* Getters */
/**
* \brief Getter for the version field.
* \return The version field.
*/
inline uint8_t version() const { return _radio.it_version; }
/**
* \brief Getter for the padding field.
* \return The padding field.
*/
inline uint8_t padding() const { return _radio.it_pad; }
/**
* \brief Getter for the length field.
* \return The length field.
*/
inline uint8_t length() const { return _radio.it_len; }
/**
* \brief Getter for the present field.
* \return The present field.
*/
inline uint8_t present() const { return _radio.it_present; }
/**
* \brief Returns the 802.11 frame's header length.
*
@@ -56,6 +108,12 @@ namespace Tins {
* \sa PDU::header_size()
*/
uint32_t header_size() const;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return PDU::RADIOTAP; }
private:
struct radiotap_hdr {
u_int8_t it_version;

View File

@@ -20,10 +20,13 @@
*/
#include <cstring>
#include <cassert>
#ifndef WIN32
#include <net/ethernet.h>
#include <netpacket/packet.h>
#endif
#include "radiotap.h"
#include "ieee802-11.h"
#include "utils.h"
@@ -37,6 +40,22 @@ Tins::RadioTap::RadioTap(uint32_t iface_index) : PDU(0xff), _iface_index(iface_i
std::memset(&_radio, 0, sizeof(_radio));
}
void Tins::RadioTap::version(uint8_t new_version) {
_radio.it_version = new_version;
}
void Tins::RadioTap::padding(uint8_t new_padding) {
_radio.it_pad = new_padding;
}
void Tins::RadioTap::length(uint8_t new_length) {
_radio.it_len = new_length;
}
void Tins::RadioTap::present(uint8_t new_present) {
_radio.it_present = new_present;
}
uint32_t Tins::RadioTap::header_size() const {
return sizeof(_radio);
}
@@ -50,7 +69,10 @@ bool Tins::RadioTap::send(PacketSender* sender) {
addr.sll_protocol = Utils::net_to_host_s(ETH_P_ALL);
addr.sll_halen = 6;
addr.sll_ifindex = _iface_index;
memcpy(&(addr.sll_addr), _header.dst_addr, 6);
Tins::IEEE802_11 *wlan = dynamic_cast<Tins::IEEE802_11*>(inner_pdu());
if(wlan)
memcpy(&(addr.sll_addr), wlan->dst_addr(), 6);
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
}
@@ -58,6 +80,7 @@ bool Tins::RadioTap::send(PacketSender* sender) {
void Tins::RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
uint32_t sz = header_size();
assert(total_sz >= sz);
_radio.it_len = sz;
if(!_radio.it_len)
_radio.it_len = sz;
memcpy(buffer, &_radio, sizeof(_radio));
}