suricata
util-fix_checksum.c
Go to the documentation of this file.
1
/*
2
* Reference: OpenBSD's pf.c.
3
*
4
* Copyright (c) 2001 Daniel Hartmeier
5
* Copyright (c) 2002 - 2008 Henning Brauer
6
* All rights reserved.
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
10
* are met:
11
*
12
* - Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
14
* - Redistributions in binary form must reproduce the above
15
* copyright notice, this list of conditions and the following
16
* disclaimer in the documentation and/or other materials provided
17
* with the distribution.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*
32
* Effort sponsored in part by the Defense Advanced Research Projects
33
* Agency (DARPA) and Air Force Research Laboratory, Air Force
34
* Materiel Command, USAF, under agreement number F30602-01-2-0537.
35
*/
36
37
#include <stdint.h>
38
39
#include "
util-fix_checksum.h
"
40
41
/**
42
* \brief Fix-up an IP checksum.
43
*
44
* \param sum The current checksum.
45
* \param old Value of old header parameter.
46
* \param new Value of new header parameter.
47
*
48
* \retval New checksum.
49
*/
50
uint16_t
51
FixChecksum
(uint16_t sum, uint16_t old, uint16_t
new
)
52
{
53
uint32_t l;
54
55
l = sum + old -
new
;
56
l = (l >> 16) + (l & 65535);
57
58
return
(uint16_t)(l & 65535);
59
}
util-fix_checksum.h
FixChecksum
uint16_t FixChecksum(uint16_t sum, uint16_t old, uint16_t new)
Fix-up an IP checksum.
Definition:
util-fix_checksum.c:51
src
util-fix_checksum.c
Generated on Wed Nov 20 2024 23:30:38 for suricata by
1.8.18