This repository was archived by the owner on Apr 7, 2024. It is now read-only.
forked from frankie-zeng/node_npcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpcap_session.h
More file actions
70 lines (55 loc) · 1.81 KB
/
Copy pathnpcap_session.h
File metadata and controls
70 lines (55 loc) · 1.81 KB
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
#ifndef NPCAP_SESSION_H
#define NPCAP_SESSION_H
#define NAPI_VERSION 6
#include <napi.h>
#include <pcap/pcap.h>
#include "stdio.h"
#if 0
class PcapWorker : public Napi::AsyncWorker {
public:
PcapWorker(Napi::Function& callback)
: Napi::AsyncWorker(callback) {}
~PcapWorker() {}
// This code will be executed on the worker thread
void Execute() override {
// Need to simulate cpu heavy task
// std::this_thread::sleep_for(std::chrono::seconds(1));
printf("excute\r\n");
}
// void OnOK() override {
// Napi::HandleScope scope(Env());
// Callback().Call({Env().Null()});
// }
private:
};
#endif
class PcapSession : public Napi::ObjectWrap<PcapSession>{
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
PcapSession(const Napi::CallbackInfo& info);
private:
static Napi::FunctionReference constructor;
Napi::Value PcapSession::New(const Napi::CallbackInfo& info);
Napi::Value PcapSession::Open(bool,const Napi::CallbackInfo& info);
Napi::Value PcapSession::OpenLive(const Napi::CallbackInfo& info);
Napi::Value PcapSession::OpenOffline(const Napi::CallbackInfo& info);
Napi::Value PcapSession::LoadBuffer(const Napi::CallbackInfo& info);
Napi::Value PcapSession::Close(const Napi::CallbackInfo& info);
Napi::Value PcapSession::Stats(const Napi::CallbackInfo& info);
Napi::Value PcapSession::Inject(const Napi::CallbackInfo& info);
static DWORD WINAPI PacketThread(LPVOID lpParam);
pcap_t * session;
Napi::ThreadSafeFunction tsFn;
HANDLE rThread;
struct bpf_program fp;
bpf_u_int32 mask;
bpf_u_int32 net;
pcap_t *pcap_handle;
pcap_dumper_t *pcap_dump_handle;
char *buffer_data;
size_t buffer_length;
size_t snap_length;
char *header_data;
bool opened=false;
};
#endif