~ubuntu-branches/ubuntu/utopic/suricata/utopic

« back to all changes in this revision

Viewing changes to src/util-checksum.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2011-11-17 23:20:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20111117232051-wlo0g2fyinx0zi25
Tags: 1.1-1
* Imported Upstream version 1.1
* Add instructions on getting new rules using oinkmaster
* Add Recommends on oinkmaster
* Move snort-rules-default to Recommends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2011 Open Information Security Foundation
 
2
 *
 
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
 
5
 * Software Foundation.
 
6
 *
 
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.
 
11
 *
 
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
 
15
 * 02110-1301, USA.
 
16
 */
 
17
 
 
18
/**
 
19
 * \file
 
20
 *
 
21
 * \author Eric Leblond <eric@regit.org>
 
22
 *
 
23
 * Util functions for checskum.
 
24
 */
 
25
 
 
26
#include "suricata-common.h"
 
27
 
 
28
int ReCalculateChecksum(Packet *p)
 
29
{
 
30
    if (PKT_IS_IPV4(p)) {
 
31
        if (PKT_IS_TCP(p)) {
 
32
            /* TCP */
 
33
            p->tcph->th_sum = 0;
 
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)) {
 
37
            p->udph->uh_sum = 0;
 
38
            p->udph->uh_sum = UDPV4CalculateChecksum((uint16_t *)&(p->ip4h->ip_src),
 
39
                    (uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN));
 
40
        }
 
41
        /* IPV4 */
 
42
        p->ip4h->ip_csum = 0;
 
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 */
 
47
        if (PKT_IS_TCP(p)) {
 
48
            p->tcph->th_sum = 0;
 
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)) {
 
52
            p->udph->uh_sum = 0;
 
53
            p->udph->uh_sum = UDPV6CalculateChecksum((uint16_t *)&(p->ip6h->ip6_src),
 
54
                    (uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN));
 
55
        }
 
56
    }
 
57
 
 
58
    return 0;
 
59
}