forked from node-pcap/node_pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcap_session.h
58 lines (48 loc) · 1.95 KB
/
pcap_session.h
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
#ifndef PCAP_SESSION_H
#define PCAP_SESSION_H
#if defined(__GNUC__) && __GNUC__ >= 8
#define DISABLE_WCAST_FUNCTION_TYPE _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wcast-function-type\"")
#define DISABLE_WCAST_FUNCTION_TYPE_END _Pragma("GCC diagnostic pop")
#else
#define DISABLE_WCAST_FUNCTION_TYPE
#define DISABLE_WCAST_FUNCTION_TYPE_END
#endif
DISABLE_WCAST_FUNCTION_TYPE
#include <nan.h>
DISABLE_WCAST_FUNCTION_TYPE_END
#include <uv.h>
#include <pcap/pcap.h>
class PcapSession : public Nan::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
private:
PcapSession();
~PcapSession();
static void New(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void Open(bool live, const Nan::FunctionCallbackInfo<v8::Value>& info);
static void OpenLive(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void OpenOffline(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void Dispatch(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void StartPolling(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void Close(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void Stats(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void Inject(const Nan::FunctionCallbackInfo<v8::Value>& info);
static void PacketReady(u_char *callback_p, const struct pcap_pkthdr* pkthdr, const u_char* packet);
static void FinalizeClose(PcapSession *session);
static void poll_handler(uv_poll_t* handle, int status, int events);
Nan::Callback packet_ready_cb;
static Nan::Persistent<v8::Function> constructor;
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;
uv_poll_t poll_handle;
Nan::AsyncResource* poll_resource = NULL;
bool poll_init = false;
};
#endif