Stroika Library
3.0d16
Help-Home
Loading...
Searching...
No Matches
IP.cpp
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#include "Stroika/Foundation/StroikaPreComp.h"
5
6
#include "Stroika/Foundation/IO/Network/HTTP/Headers.h"
7
8
#include "IP.h"
9
10
using namespace
Stroika::Foundation
;
11
using namespace
Stroika::Foundation::Characters
;
12
using namespace
Stroika::Foundation::IO::Network
;
13
using namespace
Stroika::Foundation::IO::Network::InternetProtocol;
14
15
/*
16
********************************************************************************
17
***************** IO::Network::InternetProtocol::ip_checksum *******************
18
********************************************************************************
19
*/
20
uint16_t InternetProtocol::IP::ip_checksum (
const
void
* packetStart,
const
void
* packetEnd)
21
{
22
const
uint16_t* buffer =
reinterpret_cast<
const
uint16_t*
>
(packetStart);
23
ptrdiff_t size =
reinterpret_cast<
const
uint8_t*
>
(packetEnd) -
reinterpret_cast<
const
uint8_t*
>
(packetStart);
24
unsigned
long
cksum = 0;
25
26
// Sum all the words together, adding the final byte if size is odd
27
while
(size > 1) {
28
cksum += *buffer++;
29
size -=
sizeof
(uint16_t);
30
}
31
if
(size) {
32
cksum += *
reinterpret_cast<
const
uint8_t*
>
(buffer);
33
}
34
35
// Do a little shuffling
36
cksum = (cksum >> 16) + (cksum & 0xffff);
37
cksum += (cksum >> 16);
38
39
// Return the bitwise complement of the resulting mishmash
40
return
(uint16_t)(~cksum);
41
}
Stroika::Foundation::Characters
Definition
Character.h:31
Stroika::Foundation::IO::Network
Definition
Cryptography/SSL/SocketStream.inl:5
Stroika::Foundation
Definition
BloomFilter.h:22
Library
Sources
Stroika
Foundation
IO
Network
InternetProtocol
IP.cpp
Generated by
1.9.8