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

Added enum to identify PDU type. ARP is being sent but not well implemented

This commit is contained in:
Santiago Alessandri
2011-08-15 19:14:31 -03:00
parent 835229f104
commit 6e801011c2
13 changed files with 235 additions and 175 deletions

View File

@@ -1,19 +1,19 @@
/*
* libtins is a net packet wrapper library for crafting and
* libtins is a net packet wrapper library for crafting and
* interpreting sniffed packets.
*
*
* Copyright (C) 2011 Nasel
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -44,7 +44,7 @@ void Tins::UDP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
void Tins::UDP::dport(uint16_t new_dport) {
_udp.dport = new_dport;
}
void Tins::UDP::sport(uint16_t new_sport) {
_udp.sport = new_sport;
}
@@ -55,9 +55,9 @@ uint32_t Tins::UDP::header_size() const {
void Tins::UDP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
assert(total_sz >= sizeof(udphdr));
const IP *ip_packet = dynamic_cast<const IP*>(parent);
const Tins::IP *ip_packet = dynamic_cast<const Tins::IP*>(parent);
if(!_udp.check && ip_packet) {
uint32_t checksum = PDU::pseudoheader_checksum(ip_packet->source_address(), ip_packet->dest_address(), size(), IPPROTO_UDP) +
uint32_t checksum = PDU::pseudoheader_checksum(ip_packet->source_address(), ip_packet->dest_address(), size(), IPPROTO_UDP) +
PDU::do_checksum(buffer + sizeof(udphdr), buffer + total_sz) + PDU::do_checksum((uint8_t*)&_udp, ((uint8_t*)&_udp) + sizeof(udphdr));
while (checksum >> 16)
checksum = (checksum & 0xffff)+(checksum >> 16);