1
/* Copyright (C) 2011 Open Information Security Foundation
3
* You can copy, redistribute or modify this Program under the terms of
4
* the GNU General Public License version 2 as published by the Free
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* version 2 along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
* \author Eric Leblond <eric@regit.org>
23
* Util functions for checskum.
26
#include "suricata-common.h"
28
int ReCalculateChecksum(Packet *p)
34
p->tcph->th_sum = TCPCalculateChecksum((uint16_t *)&(p->ip4h->ip_src),
35
(uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)));
36
} else if (PKT_IS_UDP(p)) {
38
p->udph->uh_sum = UDPV4CalculateChecksum((uint16_t *)&(p->ip4h->ip_src),
39
(uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN));
43
p->ip4h->ip_csum = IPV4CalculateChecksum((uint16_t *)p->ip4h,
44
IPV4_GET_RAW_HLEN(p->ip4h));
45
} else if (PKT_IS_IPV6(p)) {
46
/* just TCP for IPV6 */
49
p->tcph->th_sum = TCPV6CalculateChecksum((uint16_t *)&(p->ip6h->ip6_src),
50
(uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)));
51
} else if (PKT_IS_UDP(p)) {
53
p->udph->uh_sum = UDPV6CalculateChecksum((uint16_t *)&(p->ip6h->ip6_src),
54
(uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN));