mirror of
https://github.com/h3xduck/TripleCross.git
synced 2025-12-31 05:33:06 +08:00
Added module which arbitrarily increases the size of the packet we received. Needs some tweaking to allow for modification of the header and payload fields yet, but the space allocation is already there. Also, multiple improvements overall
This commit is contained in:
31
src/include/packet/protocol/ip_helper.h
Normal file
31
src/include/packet/protocol/ip_helper.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __IP_HELPER_H__
|
||||
#define __IP_HELPER_H__
|
||||
|
||||
#include <linux/ip.h>
|
||||
|
||||
/**
|
||||
* IP checksum calculation.
|
||||
* Following RFC 1071.
|
||||
* In essence 1's complement of 16-bit groups.
|
||||
* Taken from my own library https://github.com/h3xduck/RawTCP_Lib/blob/master/src/packet.c
|
||||
*/
|
||||
static __always_inline unsigned short checksum(unsigned short *addr, int nbytes){
|
||||
long sum = 0;
|
||||
unsigned short checksum;
|
||||
while(nbytes>1){
|
||||
sum += (unsigned short) *addr++;
|
||||
nbytes -= 2;
|
||||
}
|
||||
if(nbytes>0){
|
||||
sum +=htons((unsigned char)*addr);
|
||||
}
|
||||
|
||||
while (sum>>16){
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
}
|
||||
|
||||
checksum = ~sum;
|
||||
return checksum;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user