Skip to content

Commit

Permalink
chore: Update RawSocket
Browse files Browse the repository at this point in the history
Ref: chkpk/RawSocket@39ea174

Signed-off-by: txtsd <[email protected]>
  • Loading branch information
txtsd committed Sep 6, 2023
1 parent 8c96971 commit 1ccaf2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions RawSocket/CheckSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 1ccaf2f

Please sign in to comment.