aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--analyzer/capture.c28
-rw-r--r--analyzer/capture.h8
-rw-r--r--main.c9
4 files changed, 43 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 00fcb55..a85df64 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,13 @@ global: compile
local: compile
mv branal ${HOME}/.local/bin
-compile: utils
+compile: utils capture
gcc *.o main.c -o branal
rm *.o
utils:
gcc -c analyzer/utils/fs.c
+ gcc -c analyzer/utils/time.c
+
+capture:
+ gcc -c analyzer/capture.c
diff --git a/analyzer/capture.c b/analyzer/capture.c
new file mode 100644
index 0000000..0a75e09
--- /dev/null
+++ b/analyzer/capture.c
@@ -0,0 +1,28 @@
+#include "capture.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "headers/interface.h"
+#include "headers/server.h"
+#include "utils/fs.h"
+#include "utils/time.h"
+
+void capture_to_file(char *path) {
+ char command[128];
+ sprintf(command, "tshark -i %s -f \"src host %s\" -w %s", INTERFACE, SERVER_IP, path);
+ system(command);
+}
+
+void capturing_mode(char *path) {
+ if (path != NULL) {
+ capture_to_file(path);
+ return;
+ }
+
+ char capture_dir[256], new_path[256], date_time[128];
+ get_capture_dir(capture_dir);
+ get_date_time_string(date_time);
+ sprintf(new_path, "%s/capture-%s.pcap", capture_dir, date_time);
+ capture_to_file(new_path);
+}
diff --git a/analyzer/capture.h b/analyzer/capture.h
new file mode 100644
index 0000000..648e5ad
--- /dev/null
+++ b/analyzer/capture.h
@@ -0,0 +1,8 @@
+// capture.h
+// functions for capturing packets using tshark
+
+// starts capturing mode
+// params:
+// - path - file path to capture the .pcap file to,
+// if NULL, saves it to default capture directory as capture-<date>_<time>.pcap
+extern void capturing_mode(char *path);
diff --git a/main.c b/main.c
index aa43e57..456b590 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
+#include "analyzer/capture.h"
#include "analyzer/utils/fs.h"
// prints help
@@ -21,12 +22,6 @@ void start_live_analyzer() {
printf("Not implemented\n");
}
-// starts the only capturing packets mode
-void start_capturing_packets() {
- // TODO: implement
- printf("Not implemented\n");
-}
-
// analyzes the specified file
// params:
// - file_path - path to the .pcap file to be analyzed
@@ -48,7 +43,7 @@ int main(int argc, char *argv[]) {
start_live_analyzer();
}
else if (strcmp("c", argv[1]) == 0 || strcmp("capture", argv[1]) == 0) {
- start_capturing_packets();
+ capturing_mode(argc >= 3 ? argv[2] : NULL);
}
else if (strcmp("h", argv[1]) == 0 || strcmp("help", argv[1]) == 0) {
print_help();