-
Notifications
You must be signed in to change notification settings - Fork 1
/
sock_config.c
84 lines (76 loc) · 2.07 KB
/
sock_config.c
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
/*
* =====================================================================================
*
* Filename: sock_config.c
*
* Description: Configure the shared parts of the attacks
*
* Version: 1.0
* Created: 07/01/2018 12:05:36 PM
* Revision: none
* Compiler: gcc
*
* Author: lc
*
* =====================================================================================
*/
#include "sock_config.h"
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* Opens a socket for TCP
* * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
int get_tcp_sock_fd()
{
int fd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if(fd < 0) {
perror("cannot open socket");
return -1;
}
return fd;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* Opens a socket for UDP
* * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
int get_udp_sock_fd()
{
int fd = socket(AF_INET, SOCK_DGRAM,0);
if(fd < 0) {
perror("cannot open socket");
return -1;
}
return fd;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* Configure the socket
* * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
struct sockaddr_in configure_sock(int port, char *hostname)
{
struct sockaddr_in servaddr;
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(hostname);
servaddr.sin_port = htons(port);
return servaddr;
}
int check_args(char* hostname, char* message, int port, char* source_ip, char* attack_type)
{
if (!*hostname) {
printf ("usage: -p port -h hostname -m message\n");
return -1;
}
if (!*message && !strncmp(attack_type, "udp_spam", 8)) {
printf ("usage: -p port -h hostname -m message\n");
return -1;
}
if (!port) {
printf ("usage: -p port -h hostname -m message\n");
return -1;
}
if (!*source_ip && !strncmp(attack_type, "syn_flood", 9)) {
printf ("usage: -p port -h hostname -s source_ip\n");
return -1;
}
return 0;
}