removed nodefiles and added raise interface functionnality
This commit is contained in:
+32
-2
@@ -6,10 +6,11 @@
|
||||
#include <linux/sockios.h>
|
||||
#include <unistd.h>
|
||||
#include <node.h>
|
||||
#include <errno.h>
|
||||
|
||||
const int inet_sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
|
||||
|
||||
namespace ioctlNode {
|
||||
namespace ipNode {
|
||||
int setflags(const char* iface, short flags) {
|
||||
struct ifreq ifr;
|
||||
|
||||
@@ -19,6 +20,34 @@ namespace ioctlNode {
|
||||
return ioctl(inet_sock_fd, SIOCSIFFLAGS, &ifr);
|
||||
}
|
||||
|
||||
int getIfreq(struct ifreq *ifr ) {
|
||||
return ioctl(inet_sock_fd, SIOCGIFFLAGS, ifr);
|
||||
}
|
||||
|
||||
void nodeGetFlags(const nodeparam& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Invalid arguments ip.getflags").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
std::string iface = argToString(args[0]);
|
||||
|
||||
struct ifreq ifr;
|
||||
strncpy(ifr.ifr_name, iface.c_str(), IFNAMSIZ);
|
||||
int err = getIfreq(&ifr);
|
||||
|
||||
if(err != 0) {
|
||||
char errstr[36];
|
||||
sprintf(errstr, "Error while getting flags %d", errno);
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, errstr).ToLocalChecked()));
|
||||
}
|
||||
args.GetReturnValue().Set(ifr.ifr_flags);
|
||||
}
|
||||
|
||||
void nodeSetFlags(const nodeparam& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
@@ -36,8 +65,9 @@ namespace ioctlNode {
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "setFlags", nodeSetFlags);
|
||||
NODE_SET_METHOD(exports, "getFlags", nodeGetFlags);
|
||||
}
|
||||
|
||||
NODE_MODULE(ioctl_api, Initialize)
|
||||
NODE_MODULE(ip_api, Initialize)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user