{"id":16951342,"url":"https://github.com/santigimeno/node-ioctl","last_synced_at":"2025-09-27T12:31:35.982Z","repository":{"id":16398406,"uuid":"19149252","full_name":"santigimeno/node-ioctl","owner":"santigimeno","description":"node ioctl wrapper","archived":false,"fork":false,"pushed_at":"2021-08-16T15:48:21.000Z","size":25,"stargazers_count":31,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T22:21:38.811Z","etag":null,"topics":["ioctl","node-ioctl"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/santigimeno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-25T14:38:40.000Z","updated_at":"2024-01-26T15:25:38.000Z","dependencies_parsed_at":"2022-09-15T18:10:56.095Z","dependency_job_id":null,"html_url":"https://github.com/santigimeno/node-ioctl","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-ioctl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-ioctl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-ioctl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-ioctl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santigimeno","download_url":"https://codeload.github.com/santigimeno/node-ioctl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234437685,"owners_count":18832524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ioctl","node-ioctl"],"created_at":"2024-10-13T21:59:52.978Z","updated_at":"2025-09-27T12:31:35.687Z","avatar_url":"https://github.com/santigimeno.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-ioctl\n==========\n\nnode ioctl wrapper\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install ioctl\n```\n\nAPI\n--------\n\n### ioctl(fileDescriptor, request, data)\n**Parameters**\n- **fileDescriptor**: `Integer` Target file descriptor, must be open.\n- **request**: `Integer` Device specific request code.\n- **data**: `Integer|Buffer` Request data.\n\n**Returns**: `Integer` Usually zero is returned, some calls use the return value as a output parameter\nand may return a positive integer.\n\n**Throws**: Throws on failed `ioctl` call.\n\nExamples\n--------\n\nRead bytes of the next pending datagram using FIONREAD.\nAs it takes a pointer as a parameter, it's straightforward using a Buffer as a parameter.\n\n```\nvar dgram = require('dgram');\nvar ioctl = require('ioctl');\n\nvar FIONREAD = 0x541B;\n\nvar s = dgram.createSocket('udp4');\ns.bind(1234, function(err) {\n    if (err) {\n        throw err;\n    }\n\n    var s1 = dgram.createSocket('udp4');\n    var message = new Buffer(\"Some bytes\");\n    s1.send(message, 0, message.length, 1234, \"localhost\", function(err, bytes) {\n        var length = new Buffer(4);\n        var ret = ioctl(s._handle.fd, FIONREAD, length);\n        console.log('Pending bytes: ' + length.readInt32LE(0));\n        s1.close();\n        s.close();\n    });\n});\n```\n\nFor other cases, involving complex structs, we can use the `ref`, `ref-array` and `ref-struct` modules.\n\n```\nvar fs = require('fs');\nvar ioctl = require('ioctl');\nvar ref = require('ref');\nvar ArrayType = require('ref-array');\nvar StructType = require('ref-struct');\n\nvar TTY = '/dev/tty1';\nvar TCGETA = 0x5405;\nvar TIOCEXCL = 0x540C;\n\n// #define NCC 8\n// struct termio {\n// unsigned short c_iflag; /* input mode flags */\n// unsigned short c_oflag; /* output mode flags */\n// unsigned short c_cflag; /* control mode flags */\n// unsigned short c_lflag; /* local mode flags */\n// unsigned char c_line; /* line discipline */\n// unsigned char c_cc[NCC]; /* control characters */\n// };\n\n// define the \"snd_hwdep_info\" struct type\nvar termio = StructType({\n    c_iflag : ref.types.ushort,\n    c_oflag : ref.types.ushort,\n    c_cflag : ref.types.ushort,\n    c_lflag : ref.types.ushort,\n    c_line : ref.types.uchar,\n    c_cc : ArrayType(ref.types.uchar, 8)\n});\n\nfs.open(TTY, 'r+', function(err, fd) {\n    if (err) {\n        throw err;\n    }\n\n    var info = new termio();\n    var ret = ioctl(fd, TCGETA, info.ref());\n    console.log('TCGETA ret: ' + ret);\n    console.log('c_iflag: ' + info.c_iflag);\n    console.log('c_oflag: ' + info.c_oflag);\n    console.log('c_cflag: ' + info.c_cflag);\n    console.log('c_lflag: ' + info.c_lflag);\n    console.log('c_line: ' + info.c_line);\n    console.log('c_cc: ' + info.c_cc.buffer.toString());\n    ret = ioctl(fd, TIOCEXCL);\n    console.log('TIOCEXCL ret: ' + ret);\n    fs.close(fd);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigimeno%2Fnode-ioctl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsantigimeno%2Fnode-ioctl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigimeno%2Fnode-ioctl/lists"}