-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibAnonLuaHelpers.h
More file actions
45 lines (35 loc) · 1.66 KB
/
libAnonLuaHelpers.h
File metadata and controls
45 lines (35 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* libAnonLuaHelpers.h
*
* Created on: Sep 19, 2019
* Author: mislav
*/
#ifndef LIBANONLUAHELPERS_H_
#define LIBANONLUAHELPERS_H_
#include "stdio.h"
#include "stdlib.h"
#include "stdint.h"
#include "string.h"
#include "arpa/inet.h"
#include "stdarg.h"
//Network to host and host to network byte order change for 128-bit fields
void ntoh_128(uint32_t *address);
void hton_128(uint32_t *address);
/*
* Returns the offset, in bytes, from the beginning of the IPv6 header to the beginning of the provided next header.
* The next header can be either an IPv6 extension header or the next protocol payload.
* Returns: Next header offset or -1 in case of failure to find the desired header
*/
uint32_t ipv6_next_header_offset(const char* packet, int protocol_number);
//Helper function to calculate the internet checksum. This algorithm is used for TCP, UDP, ICMP, ICMPv6 and IPv4 checksums
//Calculating the checksum is different for different cases so separate functions will handle that. Here we'll only have the central logic
uint16_t calculate_internet_checksum(const char *data, int length);
//Returns an ipv4 or ipv6 address in human readable form
int humanForm(const char* address, size_t length, char* result);
//Checks if an IPv4 address is in the provided subnet. Returns 1 if true, -1 if false
int ipv4_in_subnet(const char* address, const char* cidr_subnet);
//Checks if an IPv6 address is in the provided subnet. Returns 1 if true, -1 if false
int ipv6_in_subnet(const char* address, const char* cidr_subnet);
//Closes count files using fclose, tests if the pointers are null to avoid segfaults
int closeFiles(int count, ...);
#endif /* LIBANONLUAHELPERS_H_ */