support de l'alumage des interface reseau
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "nodeparams.hpp"
|
||||
#include <iostream>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <unistd.h>
|
||||
#include <node.h>
|
||||
|
||||
const int inet_sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
|
||||
|
||||
namespace ioctlNode {
|
||||
int setflags(const char* iface, short flags) {
|
||||
struct ifreq ifr;
|
||||
|
||||
ifr.ifr_flags = flags;
|
||||
strncpy(ifr.ifr_name, iface, IFNAMSIZ);
|
||||
|
||||
return ioctl(inet_sock_fd, SIOCSIFFLAGS, &ifr);
|
||||
}
|
||||
|
||||
void nodeSetFlags(const nodeparam& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Invalid arguments ip.srtFlags").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
short flags = (short) argToInt(args[1]);
|
||||
std::string path = argToString(args[0]);
|
||||
|
||||
args.GetReturnValue().Set(setflags(path.c_str(), flags));
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "setFlags", nodeSetFlags);
|
||||
}
|
||||
|
||||
NODE_MODULE(ioctl_api, Initialize)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <string>
|
||||
#include <v8.h>
|
||||
|
||||
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
|
||||
#define argToInt(arg) arg.As<v8::Number>()->Value()
|
||||
#define argToString(arg) std::string(*v8::String::Utf8Value(isolate, arg))
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <unistd.h>
|
||||
#include <node.h>
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
|
||||
|
||||
namespace ioctlNode {
|
||||
void nodeSocket(const nodeparam& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
if (args.Length() != 3 || !args[0]->IsUint32() || !args[1]->IsUint32() || !args[2]->IsUint32()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument 1, 2 & 3 must be numbers").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
const int domain = args[0].As<v8::Number>()->Value();
|
||||
const int type = args[1].As<v8::Number>()->Value();
|
||||
const int protocol = args[2].As<v8::Number>()->Value();
|
||||
|
||||
args.GetReturnValue().Set(socket(domain ,type, protocol));
|
||||
}
|
||||
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "socket", nodeSocket);
|
||||
}
|
||||
|
||||
NODE_MODULE(ioctl_api, Initialize)
|
||||
}
|
||||
Reference in New Issue
Block a user