aboutsummaryrefslogtreecommitdiff
path: root/analyzer/capture.c
blob: a4a9495efd2173d6fca18e2e4c4ef0664a4fe040 (plain)
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
#include "capture.h"

#include <limits.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 \"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[PATH_MAX], new_path[PATH_MAX + 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);
}