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)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#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)
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
syscall.node
|
||||
ioctl.node
|
||||
mount.node
|
||||
file.node
|
||||
node_modules
|
||||
package-lock.json
|
||||
package-lock.json
|
||||
*.node
|
||||
@@ -32,4 +32,12 @@ function setFlags(interface, flags) {
|
||||
return ip.setFlags(interface, flags)
|
||||
}
|
||||
|
||||
module.exports = { setFlags, flags }
|
||||
/**
|
||||
* @param { string } interface
|
||||
* @returns { number }
|
||||
*/
|
||||
function getFlags(interface) {
|
||||
return ip.getFlags(interface);
|
||||
}
|
||||
|
||||
module.exports = { setFlags, getFlags, flags }
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
//@ts-check
|
||||
const ip = require('../../core/ip')
|
||||
const fs = require('fs')
|
||||
const { exit } = require('process')
|
||||
|
||||
function usage() {
|
||||
console.log('invalid syntax')
|
||||
console.log('ifup [interface name]')
|
||||
}
|
||||
|
||||
if ( process.argv.length !== 4 ){
|
||||
usage()
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if ( !fs.existsSync('/sys/class/net/' + process.argv[3]) ) {
|
||||
console.log("Interface not found")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
||||
let flagsStr = ''
|
||||
let flags = ip.getFlags(process.argv[3])
|
||||
|
||||
if(flags & ip.flags.IFF_ALLMULTI) {
|
||||
flagsStr += 'IFF_ALLMULTI\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_AUTOMEDIA) {
|
||||
flagsStr += 'IFF_AUTOMEDIA\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_BROADCAST) {
|
||||
flagsStr += 'IFF_BROADCAST\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_DEBUG) {
|
||||
flagsStr += 'IFF_DEBUG\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_DYNAMIC) {
|
||||
flagsStr += 'IFF_DYNAMIC\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_LOOPBACK) {
|
||||
flagsStr += 'IFF_LOOPBACK\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_MASTER) {
|
||||
flagsStr += 'IFF_MASTER\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_MULTICAST) {
|
||||
flagsStr += 'IFF_MULTICAST\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_NOARP) {
|
||||
flagsStr += 'IFF_NOARP\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_NOTRAILERS) {
|
||||
flagsStr += 'IFF_NOTRAILERS\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_POINTOPOINT) {
|
||||
flagsStr += 'IFF_POINTOPOINT\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_PORTSEL) {
|
||||
flagsStr += 'IFF_PORTSEL\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_PROMISC) {
|
||||
flagsStr += 'IFF_PROMISC\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_RUNNING) {
|
||||
flagsStr += 'IFF_RUNNING\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_SLAVE) {
|
||||
flagsStr += 'IFF_SLAVE\n'
|
||||
}
|
||||
if(flags & ip.flags.IFF_UP) {
|
||||
flagsStr += 'IFF_SLAVE\n'
|
||||
}
|
||||
console.log(flagsStr)
|
||||
@@ -0,0 +1,25 @@
|
||||
//@ts-check
|
||||
const ip = require('../../core/ip')
|
||||
const fs = require('fs')
|
||||
const { exit } = require('process')
|
||||
|
||||
function usage() {
|
||||
console.log('invalid syntax')
|
||||
console.log('ifup [interface name]')
|
||||
}
|
||||
|
||||
if ( process.argv.length !== 4 ){
|
||||
usage()
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if ( !fs.existsSync('/sys/class/net/' + process.argv[3]) ) {
|
||||
console.log("Interface not found")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
let flags = ip.getFlags(process.argv[3])
|
||||
|
||||
flags |= ip.flags.IFF_UP
|
||||
|
||||
ip.setFlags(process.argv[3], flags)
|
||||
Reference in New Issue
Block a user