Skip to content

Commit

Permalink
Merge pull request #11 from txtsd/submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
txtsd authored Sep 6, 2023
2 parents 8c96971 + ba60517 commit 7011a16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions RawSocket/CheckSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ static uint32_t CalSum(const uint8_t* buf, int len) {
p += 2;
}
if (len == 1)
sum += *p << 8; //
//sum += *p; //
sum += *p << 8;
return sum;
}

Expand All @@ -40,6 +39,15 @@ uint16_t cksumIp(iphdr* pIpHead){
return htons((uint16_t)~ckSum);
}

uint16_t cksumUdp(iphdr* pIpHead, udphdr* pUdpHead){
pUdpHead->check = 0;
uint32_t ckSum = CalPseudoHeadSum(pIpHead, 0x11);
ckSum += CalSum((uint8_t*)pUdpHead, ntohs(pUdpHead->len));
ckSum = (ckSum >> 16) + (ckSum & 0xffff);
ckSum += ckSum >> 16;
return htons((uint16_t)~ckSum);
}

uint16_t cksumTcp(iphdr* pIpHead, tcphdr* pTcpHead){
pTcpHead->check = 0;
uint32_t ckSum = CalPseudoHeadSum(pIpHead, 0x06);
Expand Down
2 changes: 2 additions & 0 deletions RawSocket/include/RawSocket/CheckSum.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ extern "C" {

#include <stdint.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>

uint16_t cksumIp(iphdr* pIpHead);
uint16_t cksumUdp(iphdr* pIpHead, udphdr* pUdpHead);
uint16_t cksumTcp(iphdr* pIpHead, tcphdr* pTcpHead);

#ifdef __cplusplus
Expand Down

0 comments on commit 7011a16

Please sign in to comment.