-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdns_flood_detector.h
79 lines (67 loc) · 2.62 KB
/
dns_flood_detector.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
/******************************************************************************
Program: dns_flood_detector.h
Author: Dennis Opacki <[email protected]>
Date: Tue Mar 18 16:46:53 EST 2003
Purpose: Monitor DNS servers for abusive usage levels
and alarm to syslog
Copyright (C) 2003 Dennis Opacki
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*******************************************************************************/
// definitions
#ifndef ETHER_HDRLEN
#define ETHER_HDRLEN 14
#endif
#define NS_MAXDNAME 1025
#define MAXSYSLOG 192
#define MAXMESSAGE 1200
#define MAXDATALET 64
#define MAXHEAD 300
#define MAX_TIME_LEN 20
#define DEFAULT_PORT 2000
#define DEFAULT_IP "226.1.1.2"
#define HOST_NAME_MAX 254
// evil Solaris hack
#ifdef __sun__
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#endif
// prototypes
void handle_IP(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* packet);
int calculate_averages();
int saddr_stats(int sock, struct sockaddr_in addr, char *hostname);
int scour_bucket(int i);
int find_bucket(struct in_addr *ip_src);
int daemonize(void);
int malloc_fail(char * var, int size);
int microsleep(unsigned int usec);
// data structures
struct my_dns {
u_int16_t dns_id; /* query identification number */
u_int8_t dns_flags1; /* first byte of flags */
u_int8_t dns_flags2; /* second byte of flags */
u_int16_t dns_qdcount; /* number of question entries */
u_int16_t dns_ancount; /* number of answer entries */
u_int16_t dns_nscount; /* number of authority entries */
u_int16_t dns_arcount; /* number of resource entries */
};
struct bucket {
struct in_addr ip_addr;
unsigned int tcp_count;
unsigned int udp_count;
unsigned int qps;
int qstats[256];
time_t first_packet;
time_t last_packet;
time_t alarm_set;
};