1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-30 05:24:26 +01:00

Created UDP PDU. Done some documentation on TCP.

This commit is contained in:
Matias F
2011-08-12 20:22:45 -03:00
parent d59cec94b6
commit 35c1a6e65d
5 changed files with 65 additions and 4 deletions

View File

@@ -126,8 +126,6 @@ void Tins::IP::set_option(uint8_t copied,
option.type.number = number;
uint8_t* buffer(0);
if (data_size) {
/* data must be a valid pointer */
assert(data);
buffer = new uint8_t[data_size];
memcpy(buffer, data, data_size);
}

View File

@@ -37,6 +37,7 @@ Tins::TCP::TCP(uint16_t dport, uint16_t sport) : PDU(IPPROTO_TCP), _payload(0),
_tcp.sport = Utils::net_to_host_s(sport);
_tcp.doff = sizeof(tcphdr) / sizeof(uint32_t);
_tcp.window = Utils::net_to_host_s(DEFAULT_WINDOW);
_tcp.check = 0;
}
Tins::TCP::~TCP() {
@@ -153,7 +154,8 @@ void Tins::TCP::write_serialization(uint8_t *buffer, uint32_t total_sz) {
}
memcpy(buffer, _payload, _payload_size);
_tcp.check = Utils::net_to_host_s(do_checksum(tcp_start + sizeof(tcphdr), buffer));
if(!_tcp.check)
_tcp.check = Utils::net_to_host_s(do_checksum(tcp_start + sizeof(tcphdr), buffer));
memcpy(tcp_start, &_tcp, sizeof(tcphdr));
}

14
src/udp.cpp Normal file
View File

@@ -0,0 +1,14 @@
#ifndef WIN32
#include <netinet/in.h>
#endif
#include "udp.h"
Tins::UDP::UDP(uint16_t sport, uint16_t dport) : PDU(IPPROTO_UDP), _payload(0) {
_udp.sport = sport;
_udp.dport = dport;
}
void Tins::UDP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
_payload = new_payload;
_udp.len = sizeof(udphdr) + new_payload_size;
}