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

Updated IP, PDU and PacketSender so as to send forged ip packets successfully

This commit is contained in:
Santiago Alessandri
2011-08-11 09:35:23 -03:00
parent 8dc0a5a832
commit f9445b05b6
7 changed files with 87 additions and 68 deletions

View File

@@ -6,6 +6,8 @@
#include "ip.h"
#include "utils.h"
#include <iostream>
using namespace std;
@@ -15,7 +17,7 @@ Tins::IP::IP(const string &ip_dst, const string &ip_src) : PDU(IPPROTO_IP) {
_ip.daddr = Utils::ip_to_int(ip_dst);
if(ip_src.size())
_ip.saddr = Utils::ip_to_int(ip_src);
}
Tins::IP::IP(uint32_t ip_dst, uint32_t ip_src) : PDU(IPPROTO_IP) {
@@ -28,6 +30,7 @@ void Tins::IP::init_ip_fields() {
memset(&_ip, 0, sizeof(iphdr));
_ip.version = 4;
_ip.ihl = sizeof(iphdr) / sizeof(uint32_t);
_ip.ttl = 128;
}
/* Setters */
@@ -82,8 +85,21 @@ uint32_t Tins::IP::header_size() const {
return sizeof(iphdr);
}
bool Tins::IP::send(PacketSender* sender) {
struct sockaddr_in link_addr;
link_addr.sin_family = AF_INET;
link_addr.sin_port = 0;
link_addr.sin_addr.s_addr = _ip.daddr;
return sender->send_l3(this, (const struct sockaddr*)&link_addr, sizeof(link_addr));
}
void Tins::IP::write_serialization(uint8_t *buffer, uint32_t total_sz) {
uint32_t my_sz = header_size() + trailer_size(), new_flag = inner_pdu()->flag();
uint32_t my_sz = header_size() + trailer_size();
uint32_t new_flag = inner_pdu()? inner_pdu()->flag() : 255;
assert(total_sz >= my_sz);
if(new_flag == IPPROTO_IP)
new_flag = IPPROTO_IPIP;
@@ -91,5 +107,6 @@ void Tins::IP::write_serialization(uint8_t *buffer, uint32_t total_sz) {
_ip.protocol = new_flag;
_ip.tot_len = total_sz;
memcpy(buffer, &_ip, sizeof(iphdr));
/* IP Options here... */
}