-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipk.h
More file actions
159 lines (138 loc) · 3.74 KB
/
ipk.h
File metadata and controls
159 lines (138 loc) · 3.74 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Author: Juraj Budai
// Login: xbudai02
// Date: 26.3.2025
#ifndef __IPK_H__
#define __IPK_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/ip6.h>
#include <ifaddrs.h>
#include <sys/time.h>
#include <pthread.h>
#include <netdb.h>
#include <pcap.h>
#include <semaphore.h>
#define MAX_PORTS 65535
#define PACKET_SIZE 1280
/** Arrays storing TCP/UDP ports to be scanned for IPv4 and IPv6. */
extern int tcp_ports4[MAX_PORTS];
extern int udp_ports4[MAX_PORTS];
extern int tcp_ports6[MAX_PORTS];
extern int udp_ports6[MAX_PORTS];
/** Adresses for filling the packet*/
extern struct sockaddr_in dst_addr;
extern struct sockaddr_in6 dst6_addr;
extern struct sockaddr_in src_addr;
extern struct sockaddr_in6 src6_addr;
/** Semaphores to stop race condition*/
extern sem_t sem4, sem6;
/** Timeout configuration for packet response. */
extern struct timeval timeout;
/** Counters for sent packets and overall packet counts for IPv4 and IPv6. */
extern int packets_sent4;
extern int packets_sent6;
extern int packet_count4;
extern int packet_count6;
struct pseudo_header {
u_int32_t source_address;
u_int32_t dest_address;
u_int8_t placeholder;
u_int8_t protocol;
u_int16_t tcp_length;
};
struct pseudo_header6 {
struct in6_addr source_address;
struct in6_addr dest_address;
uint32_t length;
uint8_t zero[3];
uint8_t next_header;
};
/**
* @brief Sends a TCP SYN packet to a specified IPv4 target.
*
*/
void* send_syn_packet();
/**
* @brief Sends a TCP SYN packet to a specified IPv6 target.
*
*/
void* send_syn_packet_ipv6();
/**
* @brief Sends a UDP packet to a specified IPv4 target.
*
*/
void* send_udp_packet();
/**
* @brief Sends a UDP packet to a specified IPv6 target.
*
*/
void* send_udp_packet_ipv6();
/**
* @brief Computes the checksum for a given buffer.
*
* @param b Pointer to the data buffer.
* @param len Length of the buffer.
* @return Computed checksum value.
*/
unsigned short checksum(void *b, int len);
/**
* @brief Computes the checksum for an IPv6 TCP packet.
*
* @param psh Pointer to the pseudo-header structure.
* @param tcph Pointer to the TCP header structure.
* @param tcp_len Length of the TCP segment.
* @return Computed checksum value.
*/
unsigned short ipv6_checksum(struct pseudo_header6 *psh, struct tcphdr *tcph, int tcp_len);
/**
* @brief Retrieves the local IP address for a given network interface.
*
* @param interface Name of the network interface.
*/
void get_local_ip(const char *interface);
/**
* @brief Parses port numbers from a string argument and stores them in an array.
*
* @param arg Input string containing port numbers (single ports or ranges).
* @param port_array Array to store parsed port numbers.
* @param option Specifies protocol (1 for TCP, 2 for UDP).
*/
void parse_ports(char *arg, int *port_array, int option);
/**
* @brief Prints available network interfaces.
*/
void print_interfaces();
/**
* @brief Receives incoming data from the network for TCP IPv4 packets.
*
* @return NULL.
*/
void *recv_data();
/**
* @brief Receives incoming data from the network for TCP IPv6 packets.
*
* @return NULL.
*/
void *recv_data_ipv6();
/**
* @brief Starts parallel sending and receiving for ipv4
*/
void* send_ipv4();
/**
* @brief Starts parallel sending and receiving for ipv6
*/
void* send_ipv6();
/**
* @brief Prints the help message with usage instructions.
*/
void print_help();
#endif