forked from samyk/pwnat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.h
101 lines (85 loc) · 2.24 KB
/
packet.h
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
#ifndef PACKET_T_H
#define PACKET_T_H
// Includes
#ifndef WIN32
#include <sys/unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <limits.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <errno.h>
//#include <net/ethernet.h>
#include <syslog.h>
#include <pwd.h>
#include <grp.h>
#endif /* !WIN32 */
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <signal.h>
#include <stdint.h>
#ifdef WIN32
#include <winsock2.h>
typedef int socklen_t;
typedef uint32_t in_addr_t;
#define ETH_ALEN 6 /* Octets in one ethernet addr */
struct ether_header
{
u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
u_int16_t ether_type; /* packet type ID field */
};
#endif /* WIN32 */
// Constants
#define false 0
#define true 1
#define bool char
/* packet size (physical header size + ip header + tcp header + 0 data bytes) */
#ifndef IP_MAX_SIZE
#define IP_MAX_SIZE 65535
#endif
#ifndef IPHDR_SIZE
#define IPHDR_SIZE sizeof(struct ip_packet_t)
#endif
#ifndef ICMPHDR_SIZE
#define ICMPHDR_SIZE sizeof(struct icmp_packet_t)
#endif
/* ip_packet_t: This is basically my own definition of the IP packet, which
of course complies with the official definition ;) See any good book on IP
(or even the RFC) for info on the contents of this packet.
*/
struct ip_packet_t {
uint8_t vers_ihl,
tos;
uint16_t pkt_len,
id,
flags_frag_offset;
uint8_t ttl,
proto; // 1 for ICMP
uint16_t checksum;
uint32_t src_ip,
dst_ip;
};
/* icmp_packet_t: This is the definition of a standard ICMP header. */
struct icmp_packet_t {
uint8_t type,
code;
uint16_t checksum,
identifier,
seq;
};
// Prototypes
int send_icmp(int icmp_sock, struct sockaddr_in *rsrc, struct sockaddr_in *dest_addr, struct sockaddr_in *src_addr, int server);
uint16_t calc_icmp_checksum(uint16_t *data, int bytes);
int create_icmp_socket();
int create_listen_socket();
void socket_broadcast(int sd);
void socket_iphdrincl(int sd);
#endif