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

Added ethernet packet(not tested). Updated PacketSender interface(not implemented). Added crc32 in Utils

This commit is contained in:
Santiago Alessandri
2011-08-12 23:53:09 -03:00
parent 398ba31111
commit 019998d8ad
6 changed files with 280 additions and 24 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
@@ -69,3 +69,20 @@ uint32_t Tins::Utils::resolve_ip(const string &to_resolve) {
return 0;
return ((struct in_addr**)data->h_addr_list)[0]->s_addr;
}
uint32_t Tins::Utils::crc32(uint8_t* data, uint32_t data_size) {
uint32_t i, crc = 0;
static uint32_t crc_table[] = {
0x4DBDF21C, 0x500AE278, 0x76D3D2D4, 0x6B64C2B0,
0x3B61B38C, 0x26D6A3E8, 0x000F9344, 0x1DB88320,
0xA005713C, 0xBDB26158, 0x9B6B51F4, 0x86DC4190,
0xD6D930AC, 0xCB6E20C8, 0xEDB71064, 0xF0000000
};
for (i = 0; i < data_size; ++i) {
crc = (crc >> 4) ^ crc_table[(crc ^ data[i]) & 0x0F];
crc = (crc >> 4) ^ crc_table[(crc ^ (data[i] >> 4)) & 0x0F];
}
return crc;
}