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

Marked PDU::clone_packet as deprecated.

This commit is contained in:
Matias Fontanini
2013-03-24 16:08:09 -03:00
parent d7dd1e131f
commit 8be0c4c23c
16 changed files with 90 additions and 67 deletions

View File

@@ -119,17 +119,7 @@ bool ARP::matches_response(uint8_t *ptr, uint32_t total_sz) {
}
PDU *ARP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(arphdr))
return 0;
PDU *child = 0, *cloned;
if(total_sz > sizeof(arphdr)) {
child = PDU::clone_inner_pdu(ptr + sizeof(arphdr), total_sz - sizeof(arphdr));
if(!child)
return 0;
}
cloned = new ARP(ptr, std::min(total_sz, (uint32_t)sizeof(_arp)));
cloned->inner_pdu(child);
return cloned;
return new ARP(ptr, total_sz);
}
EthernetII ARP::make_arp_request(const NetworkInterface& iface,

View File

@@ -172,15 +172,6 @@ PDU *EthernetII::recv_response(PacketSender &sender) {
#endif // WIN32
PDU *EthernetII::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(_eth))
return 0;
PDU *child = 0, *cloned;
if(total_sz > sizeof(_eth)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(_eth), total_sz - sizeof(_eth))) == 0)
return 0;
}
cloned = new EthernetII(ptr, std::min(total_sz, (uint32_t)sizeof(_eth)));
cloned->inner_pdu(child);
return cloned;
return new EthernetII(ptr, total_sz);
}
}

View File

@@ -169,14 +169,5 @@ bool Tins::ICMP::matches_response(uint8_t *ptr, uint32_t total_sz) {
}
Tins::PDU *Tins::ICMP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(icmphdr))
return 0;
PDU *child = 0, *cloned;
if(total_sz > sizeof(icmphdr)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(icmphdr), total_sz - sizeof(icmphdr))) == 0)
return 0;
}
cloned = new ICMP(ptr, std::min(total_sz, (uint32_t)sizeof(_icmp)));
cloned->inner_pdu(child);
return cloned;
return new ICMP(ptr, total_sz);
}

View File

@@ -161,15 +161,6 @@ PDU *IEEE802_3::recv_response(PacketSender &sender) {
#endif // WIN32
PDU *IEEE802_3::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(_eth))
return 0;
PDU *child = 0, *cloned;
if(total_sz > sizeof(_eth)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(_eth), total_sz - sizeof(_eth))) == 0)
return 0;
}
cloned = new IEEE802_3(ptr, std::min(total_sz, (uint32_t)sizeof(_eth)));
cloned->inner_pdu(child);
return cloned;
return new IEEE802_3(ptr, total_sz);
}
}

View File

@@ -29,6 +29,10 @@
#include "internals.h"
#include "ip.h"
#include "ethernetII.h"
#include "ieee802_3.h"
#include "radiotap.h"
#include "dot11.h"
#include "ipv6.h"
#include "arp.h"
#include "eapol.h"
@@ -81,6 +85,49 @@ Tins::PDU *pdu_from_flag(Constants::Ethernet::e flag, const uint8_t *buffer,
};
}
Tins::PDU *pdu_from_flag(PDU::PDUType type, const uint8_t *buffer, uint32_t size)
{
switch(type) {
case Tins::PDU::ETHERNET_II:
return new Tins::EthernetII(buffer, size);
case Tins::PDU::IP:
return new Tins::IP(buffer, size);
case Tins::PDU::IPv6:
return new Tins::IPv6(buffer, size);
case Tins::PDU::ARP:
return new Tins::ARP(buffer, size);
case Tins::PDU::IEEE802_3:
return new Tins::IEEE802_3(buffer, size);
case Tins::PDU::RADIOTAP:
return new Tins::RadioTap(buffer, size);
case Tins::PDU::DOT11:
case Tins::PDU::DOT11_ACK:
case Tins::PDU::DOT11_ASSOC_REQ:
case Tins::PDU::DOT11_ASSOC_RESP:
case Tins::PDU::DOT11_AUTH:
case Tins::PDU::DOT11_BEACON:
case Tins::PDU::DOT11_BLOCK_ACK:
case Tins::PDU::DOT11_BLOCK_ACK_REQ:
case Tins::PDU::DOT11_CF_END:
case Tins::PDU::DOT11_DATA:
case Tins::PDU::DOT11_CONTROL:
case Tins::PDU::DOT11_DEAUTH:
case Tins::PDU::DOT11_DIASSOC:
case Tins::PDU::DOT11_END_CF_ACK:
case Tins::PDU::DOT11_MANAGEMENT:
case Tins::PDU::DOT11_PROBE_REQ:
case Tins::PDU::DOT11_PROBE_RESP:
case Tins::PDU::DOT11_PS_POLL:
case Tins::PDU::DOT11_REASSOC_REQ:
case Tins::PDU::DOT11_REASSOC_RESP:
case Tins::PDU::DOT11_RTS:
case Tins::PDU::DOT11_QOS_DATA:
return Tins::Dot11::from_bytes(buffer, size);
default:
return 0;
};
}
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) {
switch (flag) {
case PDU::IP:

View File

@@ -436,19 +436,6 @@ bool IP::matches_response(uint8_t *ptr, uint32_t total_sz) {
}
PDU *IP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(iphdr))
return 0;
const iphdr *ip_ptr = (iphdr*)ptr;
uint32_t sz = ip_ptr->ihl * sizeof(uint32_t);
if(total_sz < sz)
return 0;
PDU *child = 0, *cloned;
if(total_sz > sz) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(_ip), total_sz - sizeof(_ip))) == 0)
return 0;
}
cloned = new IP(ptr, std::min(total_sz, (uint32_t)(Endian::be_to_host(ip_ptr->tot_len) * sizeof(uint32_t))));
cloned->inner_pdu(child);
return cloned;
return new IP(ptr, total_sz);
}
}

View File

@@ -65,6 +65,7 @@
#include "dot11.h"
#include "radiotap.h"
#include "ieee802_3.h"
#include "internals.h"
namespace Tins {
@@ -307,7 +308,8 @@ PDU *PacketSender::recv_match_loop(int sock, PDU &pdu, struct sockaddr* link_add
#endif
size = recvfrom(sock, (char*)buffer, 2048, 0, link_addr, &length);
if(pdu.matches_response(buffer, size)) {
return pdu.clone_packet(buffer, size);
return Internals::pdu_from_flag(pdu.pdu_type(), buffer, size);
//return pdu.clone_packet(buffer, size);
}
}
struct timeval this_time, diff;

View File

@@ -113,4 +113,8 @@ PDU *PDU::clone_inner_pdu(const uint8_t *ptr, uint32_t total_sz) {
child = new RawPDU(ptr, total_sz);
return child;
}
PDU *PDU::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
return 0;
}
}