-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneti.h
More file actions
202 lines (164 loc) · 5.35 KB
/
neti.h
File metadata and controls
202 lines (164 loc) · 5.35 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* name: neti.h
* author: Jean Philippe GUILLEMIN <jpgu@users.sourceforge.net>
* Copyright (C) 2002 by Jean Philippe GUILLEMIN <jp.guillemin@free.fr>
* license: This software is under GPL version 2 of license
* date: 04 17 2003
* rev: 0.8
*/
#define __BYTE_ORDER __LITTLE_ENDIAN
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sysexits.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>
struct pseudohdr /* this struct is used to calculate the TCP & UDP checsum */
{
u_int32_t saddr;
u_int32_t daddr;
unsigned char zero;
unsigned char protocol;
u_int16_t lenght;
};
/*
0 7 8 15 16 23 24 31
+--------+--------+--------+--------+
| source address |
+--------+--------+--------+--------+
| destination address |
+--------+--------+--------+--------+
| zero |protocol| UDP/TCP length |
+--------+--------+--------+--------+
*/
struct optionhdr
{
u_int32_t data_size;
u_int32_t inet_src_ip;
u_int32_t inet_dst_ip;
char src_ip[32];
char dst_ip[32];
u_int16_t proto;
u_int16_t lenght;
u_int32_t inet_dst_port;
u_int32_t inet_src_port;
u_int32_t src_port;
u_int32_t dst_port;
u_int32_t syn;
u_int32_t ack;
u_int32_t psh;
u_int32_t rst;
u_int32_t fin;
u_int32_t urg;
u_int16_t ttl;
u_int32_t window;
u_int16_t offset;
u_int16_t icmp_type;
u_int16_t icmp_code;
u_int32_t icmp_echo_id;
u_int32_t icmp_echo_sequence;
unsigned char iptos;
char icmp_redirect_gateway[32];
char interface[32];
int tcp_opt_size;
};
struct filter {
u_int16_t filter_on_icmp;
u_int16_t filter_on_udp;
u_int16_t filter_on_tcp;
u_int16_t filter_on_target_addr;
};
struct icmp_timestamp {
unsigned long originate;
unsigned long receive;
unsigned long transmit;
};
#define DOUBLE 32
#define TCPHDR_SIZE sizeof (struct tcphdr)
#define UDPHDR_SIZE sizeof (struct udphdr)
#define PSEUDOHDR_SIZE sizeof (struct pseudohdr)
#define IPHDR_SIZE sizeof (struct ip)
#define ICMPHDR_SIZE sizeof (struct icmphdr)
#define IFREQ_SIZE sizeof(struct ifreq)
#define HOSTENT_SIZE sizeof(struct hostent)
#define ICMP_TIMESTAMP_SIZE sizeof(struct icmp_timestamp);
#define MF 0x2000 /* More IP fragment flag */
/**********************/
/* GLOBALS */
/**********************/
char *payload, *data;
char last_address[32];
char last_name[1024];
struct optionhdr *myhdr;
struct filter *waitfor;
int so_udp, so_tcp, so_icmp, *so_send, so_raw; /* sockets identifiers */
u_int16_t be_promiscuous, flood, keep_sniffing, no_lookup, use_this_if, use_this_address, be_blind, do_reverse_lookup;
u_int32_t time_to_wait_for_packet;
/**********************/
/* PROTOTYPES */
/**********************/
/* main program */
int main(int argc, char *argv[]);
/* print() prototype
param1 : rlookup = [0,1] tell print() to perform a reverse lookup (1) or no (0)
*/
void print(u_int16_t rlookup);
/* to quit clean */
void close_sockets(void);
/* function that create the UDP header and data field
the result is a pointer (*udp_packet) to the begining of UDP header
*/
int write_udp(char *udp_packet, int size, u_int32_t ip_saddr, u_int32_t ip_daddr);
/* function that create the TCP header and data field
the result is a pointer (*tcp_packet) to the begining of TCP header
*/
int write_tcp(char *tcp_packet, int size, u_int32_t ip_saddr, u_int32_t ip_daddr);
/* function that create the ICMP header and data field
the result is a pointer (*icmp_packet) to the begining of ICMP header
*/
int write_icmp(char *icmp_packet, int size);
/* calculate all checksums */
u_int16_t sum(u_int16_t *buf, int nbytes);
/* get the IP address of a given interface */
int getif_ip_by_name(char *ip, u_int32_t *inet_ip, char *ifname);
/* Get IP address of the output interface from the routing table
(Derived from R.Stevens) */
int getout_ip(struct sockaddr_in *if_addr, struct sockaddr_in *dest);
/* Gets the name of output interface from a given address */
int getif_name_by_ip(char *ifname, u_int32_t *inet_ip);
/* sniff incoming packets */
int sniff(int udp_sniff_sock, int tcp_sniff_sock, int icmp_sniff_sock, int keep,
u_int32_t timeout, u_int16_t rlookup);
/* resolve given hostname into IP address and reverse :) */
int lookup(u_int32_t *inet_ip, char *ip, char *name);
int reverse_lookup(char *name, char *ip);
/* sets and unsets listening interface in promiscuous mode */
int set_promisc(int sock);
int unset_promisc(int sock);
/* find the max socket id for select() */
int max(int a, int b, int c);
/* try to find parameters in given config file using the func parse_from_config() */
int take_args_from_file(char *cfile);
/* scan the config file to find given parameter and return the associated value in uint & char */
int parse_from_config(u_int32_t *uint_value, char *char_value, char *filename,
char *param );
/* multi use debug function */
int debug();
/* catch_sig() prototype */
void catch_sig(int);