1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 12:44:25 +01:00

Added constants header.

This commit is contained in:
Matias Fontanini
2011-09-12 12:01:17 -03:00
parent 753378cb38
commit abe73f185f
8 changed files with 66 additions and 58 deletions

View File

@@ -25,7 +25,6 @@
#ifndef WIN32
#include <net/ethernet.h>
#include <netpacket/packet.h>
#include <netinet/in.h>
#endif
#include "ethernetII.h"
#include "rawpdu.h"
@@ -34,6 +33,7 @@
#include "utils.h"
const uint8_t* Tins::EthernetII::BROADCAST = (const uint8_t*)"\xff\xff\xff\xff\xff\xff";
//const uint32_t Tins::EthernetII::ADDR_SIZE = 6;
Tins::EthernetII::EthernetII(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) {
memset(&_eth, 0, sizeof(ethhdr));
@@ -92,15 +92,15 @@ uint16_t Tins::EthernetII::payload_type() const {
}
void Tins::EthernetII::dst_addr(const uint8_t* new_dst_mac) {
memcpy(this->_eth.dst_mac, new_dst_mac, 6);
memcpy(_eth.dst_mac, new_dst_mac, sizeof(_eth.dst_mac));
}
void Tins::EthernetII::src_addr(const uint8_t* new_src_mac) {
memcpy(this->_eth.src_mac, new_src_mac, 6);
memcpy(_eth.src_mac, new_src_mac, sizeof(_eth.src_mac));
}
void Tins::EthernetII::iface(uint32_t new_iface_index) {
this->_iface_index = new_iface_index;
_iface_index = new_iface_index;
}
void Tins::EthernetII::iface(const std::string& new_iface) throw (std::runtime_error) {
@@ -120,9 +120,9 @@ 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 = 6;
addr.sll_ifindex = this->_iface_index;
memcpy(&(addr.sll_addr), this->_eth.dst_mac, 6);
addr.sll_halen = ADDR_SIZE;
addr.sll_ifindex = _iface_index;
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
}
@@ -131,7 +131,7 @@ bool Tins::EthernetII::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, 6)) {
if(!memcmp(eth_ptr->dst_mac, _eth.src_mac, ADDR_SIZE)) {
// chequear broadcast en destino original...
return true;
}
@@ -166,20 +166,20 @@ 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 = 6;
addr.sll_ifindex = this->_iface_index;
memcpy(&(addr.sll_addr), this->_eth.dst_mac, 6);
addr.sll_halen = ADDR_SIZE;
addr.sll_ifindex = _iface_index;
memcpy(&(addr.sll_addr), _eth.dst_mac, ADDR_SIZE);
return sender->recv_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
}
Tins::PDU *Tins::EthernetII::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(ethhdr))
if(total_sz < sizeof(_eth))
return 0;
const ethhdr *eth_ptr = (ethhdr*)ptr;
PDU *child = 0, *cloned;
if(total_sz > sizeof(ethhdr)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(ethhdr), total_sz - sizeof(ethhdr))) == 0)
if(total_sz > sizeof(_eth)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(_eth), total_sz - sizeof(_eth))) == 0)
return 0;
}
cloned = new EthernetII(eth_ptr);