forked from Srar/node-tap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_device_file.cpp
More file actions
31 lines (26 loc) · 811 Bytes
/
create_device_file.cpp
File metadata and controls
31 lines (26 loc) · 811 Bytes
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
#include <nan.h>
#include <string>
#include <cstring>
#include "./util.hpp"
NAN_METHOD(N_CreateDeviceFile)
{
if (info.Length() != 1)
{
Nan::ThrowError("Wrong number of arguments.");
return;
}
if (!info[0]->IsString())
{
Nan::ThrowError("Wrong type of instanceId.");
return;
}
std::string instanceId = *v8::String::Utf8Value(info[0]->ToString());
std::string devicePath = "\\\\.\\Global\\" + instanceId + ".tap";
HANDLE handle = CreateFileW(Utf8Decode(devicePath).c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
if (handle == INVALID_HANDLE_VALUE)
{
Nan::ThrowError("Invalid handle value.");
return;
}
info.GetReturnValue().Set((long)handle);
}