npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ioctl

v2.0.2

Published

nodejs ioctl wrapper

Downloads

3,581

Readme

node-ioctl

node ioctl wrapper

Installation

Install with npm:

$ npm install ioctl

API

ioctl(fileDescriptor, request, data)

Parameters

  • fileDescriptor: Integer Target file descriptor, must be open.
  • request: Integer Device specific request code.
  • data: Integer|Buffer Request data.

Returns: Integer Usually zero is returned, some calls use the return value as a output parameter and may return a positive integer.

Throws: Throws on failed ioctl call.

Examples

Read bytes of the next pending datagram using FIONREAD. As it takes a pointer as a parameter, it's straightforward using a Buffer as a parameter.

var dgram = require('dgram');
var ioctl = require('ioctl');

var FIONREAD = 0x541B;

var s = dgram.createSocket('udp4');
s.bind(1234, function(err) {
    if (err) {
        throw err;
    }

    var s1 = dgram.createSocket('udp4');
    var message = new Buffer("Some bytes");
    s1.send(message, 0, message.length, 1234, "localhost", function(err, bytes) {
        var length = new Buffer(4);
        var ret = ioctl(s._handle.fd, FIONREAD, length);
        console.log('Pending bytes: ' + length.readInt32LE(0));
        s1.close();
        s.close();
    });
});

For other cases, involving complex structs, we can use the ref, ref-array and ref-struct modules.

var fs = require('fs');
var ioctl = require('ioctl');
var ref = require('ref');
var ArrayType = require('ref-array');
var StructType = require('ref-struct');

var TTY = '/dev/tty1';
var TCGETA = 0x5405;
var TIOCEXCL = 0x540C;

// #define NCC 8
// struct termio {
// unsigned short c_iflag; /* input mode flags */
// unsigned short c_oflag; /* output mode flags */
// unsigned short c_cflag; /* control mode flags */
// unsigned short c_lflag; /* local mode flags */
// unsigned char c_line; /* line discipline */
// unsigned char c_cc[NCC]; /* control characters */
// };

// define the "snd_hwdep_info" struct type
var termio = StructType({
    c_iflag : ref.types.ushort,
    c_oflag : ref.types.ushort,
    c_cflag : ref.types.ushort,
    c_lflag : ref.types.ushort,
    c_line : ref.types.uchar,
    c_cc : ArrayType(ref.types.uchar, 8)
});

fs.open(TTY, 'r+', function(err, fd) {
    if (err) {
        throw err;
    }

    var info = new termio();
    var ret = ioctl(fd, TCGETA, info.ref());
    console.log('TCGETA ret: ' + ret);
    console.log('c_iflag: ' + info.c_iflag);
    console.log('c_oflag: ' + info.c_oflag);
    console.log('c_cflag: ' + info.c_cflag);
    console.log('c_lflag: ' + info.c_lflag);
    console.log('c_line: ' + info.c_line);
    console.log('c_cc: ' + info.c_cc.buffer.toString());
    ret = ioctl(fd, TIOCEXCL);
    console.log('TIOCEXCL ret: ' + ret);
    fs.close(fd);
});