Socket
Socket
Sign inDemoInstall

pcap

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pcap - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

decode/ieee802.11/radiotap_fields.json

187

decode/ieee802.11/radio_packet.js

@@ -0,42 +1,23 @@

/* jshint evil: true */
var RadioFrame = require("./radio_frame");
var radiotap_fields = require('./radiotap_fields');
function PresentFieldFlags() {
this.tsft = undefined;
this.flags = undefined;
this.rate = undefined;
this.channel = undefined;
this.fhss = undefined;
this.signalStrength = undefined;
this.signalNoise = undefined;
this.lockQuality = undefined;
this.txAttenuation = undefined;
this.dbTxAttenuation = undefined;
this.dbmTxPower = undefined;
this.antenna = undefined;
this.dbAntennaSignal = undefined;
this.dbAntennaNoise = undefined;
this.rxFlags = undefined;
const associations = {
u8: 'data.readUInt8(',
u16: 'data.readUInt16LE(',
u32: 'data.readUInt32LE(',
u64: Buffer.prototype.readBigUInt64LE ? 'data.readBigUInt64LE(' : 'readBigUInt64LE(data, ',
s8: 'data.readInt8(',
s16: 'data.readInt16LE(',
s32: 'data.readInt32LE(',
};
function readBigUInt64LE(buffer, offset = 0) {
const lo = buffer.readUInt32LE(offset);
const hi = buffer.readUInt32LE(offset + 4);
return BigInt(lo) + (BigInt(hi) << BigInt(32));
}
//flags should be a UInt32LE
PresentFieldFlags.prototype.decode = function decode (flags) {
var r = flags;
this.tsft = Boolean(r & 0x0001) ;
this.flags = Boolean((r >> 1) & 0x0001);
this.rate = Boolean((r >> 2) & 0x0001);
this.channel = Boolean((r >> 3) & 0x0001);
this.fhss = Boolean((r >> 4) & 0x0001);
this.signalStrength = Boolean((r >> 5) & 0x0001);
this.signalNoise = Boolean((r >> 6) & 0x0001);
this.lockQuality = Boolean((r >> 7) & 0x0001);
this.txAttenuation = Boolean((r >> 8) & 0x0001);
this.dbTxAttenuation = Boolean((r >> 9) & 0x0001);
this.dbmTxPower = Boolean((r >> 10) & 0x0001);
this.antenna = Boolean((r >> 11) & 0x0001);
this.dbAntennaSignal = Boolean((r >> 12) & 0x0001);
this.dbAntennaNoise = Boolean((r >> 13) & 0x0001);
this.rxFlags = Boolean((r >> 14) & 0x0001);
return this;
};
/** Radiotap header (http://www.radiotap.org) **/
function RadioPacket(emitter) {

@@ -47,68 +28,110 @@ this.emitter = emitter;

this.headerLength = undefined;
this.signalStrength = undefined;
this.frequency = undefined;
this.antenna = undefined;
this.ieee802_11Frame = undefined;
this.presentFields = undefined;
this.signalNoise = undefined;
this.fields = undefined;
this._decoderCache = {};
}
RadioPacket.prototype.decode = function (raw_packet, offset) {
RadioPacket.prototype.decode = function (raw_packet, offset, options) {
var original_offset = offset;
this.headerRevision = raw_packet[offset++];
if (this.headerRevision !== 0)
console.warning(`Unknown radiotap version: ${this.headerRevision}`);
this.headerPad = raw_packet[offset++];
this.headerLength = raw_packet.readUInt16LE(offset); offset += 2;
this.presentFields = raw_packet.readUInt32LE(offset); offset += 4;
// We need to use a bigint if the extension bit is set
if (this.presentFields >> 31) {
this.presentFields = BigInt(this.presentFields);
for (var s = BigInt(32); this.presentFields >> (s-BigInt(1)); s += BigInt(32)) {
this.presentFields ^= BigInt(1) << (s-BigInt(1));
const v = raw_packet.readUInt32LE(offset); offset += 4;
this.presentFields |= BigInt(v) << s;
}
}
//Present Flags
this.presentFields = new PresentFieldFlags().decode(
raw_packet.readUInt32LE(offset));
offset += 4;
if (!Object.hasOwnProperty.call(this._decoderCache, this.presentFields))
this._decoderCache[this.presentFields] = this.buildDecoder(this.presentFields);
this.fields = this._decoderCache[this.presentFields](raw_packet, offset, original_offset + this.headerLength);
//alias presentFields as it will be used a lot
var p = this.presentFields;
offset = original_offset + this.headerLength;
//MAC timestamp
if(p.tsft) { offset += 8; }
if (options && options.decodeLower === false) {
this.ieee802_11Frame = raw_packet.slice(offset);
} else {
this.ieee802_11Frame = new RadioFrame(this.emitter).decode(raw_packet, offset);
}
//Flags
if(p.flags) { offset += 1; }
if(this.emitter) { this.emitter.emit("radio-packet", this); }
return this;
};
if(p.rate) { offset += 1; }
// Creates a (data, offset, end_offset) function that parses
// radiotap field data and returns the `fields` object.
// Both this function and the returned function may throw
// Important: Bits 31, 63, etc. must NOT be set
RadioPacket.prototype.buildDecoder = function (fields) {
var code = 'var result = {};\n';
if(p.channel) {
//Frequency
this.frequency = raw_packet.readUInt16LE(offset, true);
//channel flags are the 2 bytes after channel freq
offset += 4;
// Generate field extraction code
fields = BigInt(fields);
var offset = 0;
var has_tlv = false;
for (let i = 0; fields; (i++, fields >>= BigInt(1))) {
if (!(fields & BigInt(1))) continue;
if ((i % 32) === 29 || (i % 32) === 30)
throw new Error('Radiotap Namespace / Vendor Namespace not implemented yet');
if (i === 28) {
has_tlv = true;
break;
}
if (!Object.hasOwnProperty.call(radiotap_fields, i))
throw new Error(`Unknown field bit ${i}`);
const { id, structure, align } = radiotap_fields[i];
// consume alignment
offset += (((-offset) % align) + align) % align;
// prepare structure
let things = structure.map(([kind, name]) => [kind, id + '.' + name]);
if (structure.length === 1)
things[0][1] = id || structure[0][1];
else
code += `result.${id} = {};\n`; // extensions with many fields are grouped
// parse the things
things.forEach(([kind, name]) => {
if (typeof kind === 'number') {
code += `result.${name} = data.slice(offset + ${offset}, offset + ${offset + kind});\n`;
offset += kind;
return;
}
// FIXME: parse flags too
const fname = associations[kind].toString();
code += `result.${name} = ${fname}offset + ${offset});\n`;
offset += Number(kind.substring(1))/8;
});
}
if(p.fhss) { offset += 2; }
// Check length
var pre_check = '';
pre_check += `if (end_offset - offset < ${offset})\n`;
pre_check += ` throw Error('Radiotap header length too short');\n`;
if(p.signalStrength) { //in dbi
this.signalStrength = raw_packet.readInt8(offset++);
// Extract TLV or check for extra data
if (has_tlv) {
if (fields >> BigInt(1))
throw Error('If bit 28 (TLV) is set, no higher bits can be set');
// FIXME: parse better?
code += `result.tlv = Buffer.slice(data, offset+${offset}, end_offset);\n`;
} else {
// FIXME: make this a warning
pre_check += `if (end_offset - offset > ${offset})\n`;
pre_check += ` throw Error('Radiotap header length too high, extra data?');\n`;
}
if(p.signalNoise) { //in dbi
this.signalNoise = raw_packet.readInt8(offset++);
}
if(p.lockQuality) { offset += 2; }
if(p.txAttenuation) { offset++; }
if(p.dbTxAttenuation) { offset += 2; }
if(p.dbmTxPower) { offset++; }
if(p.antenna) {
this.antenna = raw_packet[offset++];
}
if(p.dbAntennaSignal) { offset++; }
if(p.dbAntennaNoise) { offset++; }
if(p.rxFlags) { offset += 2; }
offset = original_offset + this.headerLength;
this.ieee802_11Frame = new RadioFrame(this.emitter).decode(raw_packet, offset);
if(this.emitter) { this.emitter.emit("radio-packet", this); }
return this;
code = pre_check + code + 'return result;';
return new Function('readBigUInt64LE', 'data', 'offset', 'end_offset', code)
.bind(this, readBigUInt64LE);
};
module.exports = RadioPacket;

@@ -10,4 +10,4 @@ // convert binary capture data into objects with friendly names

function decode(packet, emitter) {
return new PcapPacket(emitter).decode(packet);
function decode(packet, emitter, options) {
return new PcapPacket(emitter).decode(packet, options);
}

@@ -14,0 +14,0 @@

@@ -29,23 +29,23 @@ var EthernetPacket = require("./ethernet_packet");

PcapPacket.prototype.decode = function (packet_with_header) {
PcapPacket.prototype.decode = function (packet_with_header, options) {
this.link_type = packet_with_header.link_type;
this.pcap_header = new PcapHeader(packet_with_header.header);
var buf = packet_with_header.buf.slice(0, this.pcap_header.len);
var buf = packet_with_header.buf.slice(0, this.pcap_header.caplen);
switch (this.link_type) {
case "LINKTYPE_ETHERNET":
this.payload = new EthernetPacket(this.emitter).decode(buf, 0);
this.payload = new EthernetPacket(this.emitter).decode(buf, 0, options);
break;
case "LINKTYPE_NULL":
this.payload = new NullPacket(this.emitter).decode(buf, 0);
this.payload = new NullPacket(this.emitter).decode(buf, 0, options);
break;
case "LINKTYPE_RAW":
this.payload = new Ipv4(this.emitter).decode(buf, 0);
this.payload = new Ipv4(this.emitter).decode(buf, 0, options);
break;
case "LINKTYPE_IEEE802_11_RADIO":
this.payload = new RadioPacket(this.emitter).decode(buf, 0);
this.payload = new RadioPacket(this.emitter).decode(buf, 0, options);
break;
case "LINKTYPE_LINUX_SLL":
this.payload = new SLLPacket(this.emitter).decode(buf, 0);
this.payload = new SLLPacket(this.emitter).decode(buf, 0, options);
break;

@@ -52,0 +52,0 @@ default:

@@ -16,3 +16,3 @@

TCPFlags.prototype.decode = function (first_byte, second_byte) {
this.nonce = Boolean(first_byte & 16);
this.nonce = Boolean(first_byte & 1);
this.cwr = Boolean(second_byte & 128);

@@ -19,0 +19,0 @@ this.ece = Boolean(second_byte & 64);

{
"name": "pcap",
"version": "2.1.0",
"version": "3.0.0",
"description": "raw packet capture, decoding, and analysis",
"author": "Matt Ranney <mjr@ranney.com>",
"license": "MIT",
"maintainers": [

@@ -10,2 +11,3 @@ "Ujjwal Thaakar <ujjwalthaakar@gmail.com>"

"main": "./pcap",
"types": "pcap.d.ts",
"repository": {

@@ -16,17 +18,17 @@ "type": "git",

"engines": {
"node": ">=0.10"
"node": ">=10.0.0"
},
"dependencies": {
"nan": "^2.0.9",
"socketwatcher": "git+https://github.com/bytzdev/node-socketwatcher.git"
"@types/node": "^10.0.0",
"nan": "^2.14.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.0",
"grunt-coveralls": "^1.0.0",
"grunt-mocha-istanbul": "^2.3.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"grunt-contrib-jshint": "^2.1.0",
"grunt-coveralls": "^2.0.0",
"grunt-mocha-istanbul": "^5.0.2",
"grunt-mocha-test": "^0.12.7",
"istanbul": "^0.3.5",
"mocha": "^2.1.0",
"istanbul": "^0.4.5",
"mocha": "^7.0.1",
"mocha-sinon": "^1.1.4",

@@ -33,0 +35,0 @@ "should": "^5.0.0",

var util = require("util");
var events = require("events");
var binding = require("./build/Release/pcap_binding");
var SocketWatcher = require("socketwatcher").SocketWatcher;
var decode = require("./decode").decode;

@@ -15,3 +14,8 @@ var tcp_tracker = require("./tcp_tracker");

function PcapSession(is_live, device_name, filter, buffer_size, outfile, is_monitor) {
// This may be overriden by the user
exports.warningHandler = function warningHandler(x) {
console.warn('warning: %s - this may not actually work', x);
};
function PcapSession(is_live, device_name, filter, buffer_size, snap_length, outfile, is_monitor, buffer_timeout) {
this.is_live = is_live;

@@ -21,11 +25,11 @@ this.device_name = device_name;

this.buffer_size = buffer_size;
this.snap_length = snap_length;
this.outfile = outfile || "";
this.is_monitor = Boolean(is_monitor);
this.buffer_timeout = buffer_timeout;
this.link_type = null;
this.fd = null;
this.opened = null;
this.buf = null;
this.header = null;
this.read_watcher = null;
this.empty_reads = 0;

@@ -42,27 +46,30 @@ this.packets_read = null;

var self = this;
if (typeof this.snap_length === "number" && !isNaN(this.snap_length)) {
this.snap_length = Math.round(this.snap_length);
} else {
this.snap_length = 65535; // Default snap length is 65535
}
// called for each packet read by pcap
function packet_ready() {
self.on_packet_ready();
if (typeof this.buffer_timeout === "number" && !isNaN(this.buffer_timeout)) {
this.buffer_timeout = Math.round(this.buffer_timeout);
} else {
this.buffer_timeout = 1000; // Default buffer timeout is 1s
}
const packet_ready = this.on_packet_ready.bind(this);
if (this.is_live) {
this.device_name = this.device_name || binding.default_device();
this.link_type = this.session.open_live(this.device_name, this.filter, this.buffer_size, this.outfile, packet_ready, this.is_monitor);
this.link_type = this.session.open_live(this.device_name, this.filter, this.buffer_size, this.snap_length, this.outfile, packet_ready, this.is_monitor, this.buffer_timeout, exports.warningHandler);
} else {
this.link_type = this.session.open_offline(this.device_name, this.filter, this.buffer_size, this.outfile, packet_ready, this.is_monitor);
this.link_type = this.session.open_offline(this.device_name, this.filter, this.buffer_size, this.snap_length, this.outfile, packet_ready, this.is_monitor, this.buffer_timeout, exports.warningHandler);
}
this.fd = this.session.fileno();
this.opened = true;
this.buf = new Buffer(this.buffer_size || 65535);
this.header = new Buffer(16);
this.buf = Buffer.alloc(this.snap_length);
this.header = Buffer.alloc(16);
if (is_live) {
this.readWatcher = new SocketWatcher();
// readWatcher gets a callback when pcap has data to read. multiple packets may be readable.
this.readWatcher.callback = function pcap_read_callback() {
var packets_read = self.session.dispatch(self.buf, self.header);
// callback when pcap has data to read. multiple packets may be readable.
this.session.read_callback = () => {
var packets_read = this.session.dispatch(this.buf, this.header);
if (packets_read < 1) {

@@ -72,11 +79,11 @@ this.empty_reads += 1;

};
this.readWatcher.set(this.fd, true, false);
this.readWatcher.start();
this.session.start_polling();
process.nextTick(this.session.read_callback); // kickstart to prevent races
} else {
timers.setImmediate(function() {
timers.setImmediate(() => {
var packets = 0;
do {
packets = self.session.dispatch(self.buf, self.header);
packets = this.session.dispatch(this.buf, this.header);
} while ( packets > 0 );
self.emit("complete");
this.emit("complete");
});

@@ -108,7 +115,6 @@ }

this.opened = false;
this.removeAllListeners();
this.session.close();
if (this.is_live) {
this.readWatcher.stop();
}
// TODO - remove listeners so program will exit I guess?
};

@@ -127,8 +133,10 @@

exports.createSession = function (device, filter, buffer_size, monitor) {
return new PcapSession(true, device, filter, buffer_size, null, monitor);
exports.createSession = function (device, options) {
options = options || {};
return new PcapSession(true, device, options.filter, options.buffer_size, options.snap_length, null, options.monitor, options.buffer_timeout);
};
exports.createOfflineSession = function (path, filter) {
return new PcapSession(false, path, filter, 0, null, null);
exports.createOfflineSession = function (path, options) {
options = options || {};
return new PcapSession(false, path, options.filter, 0, null, null);
};

@@ -1,4 +0,8 @@

##Disclaimer
node_pcap is currently being heavily refactored much of the documentation is out of date. If you installed node_pcap from npm go to [v2.0.1](https://github.com/mranney/node_pcap/commit/6e4d56671c54e0cf690f72b92554a538244bd1b6). Thanks for your patience and contributions as we work on the next major version of node_pcap.
**Disclaimer:**
There's been some API changes between v2 and v3; the `createSession` and `createOfflineSession` arguments
now accept an `options` object. Also, if you're capturing on monitor wifi interfaces, the Radiotap
header now has different fields.
---
node_pcap

@@ -64,5 +68,2 @@ =========

To use this library in your own program, `pcap.js` and `pcap_binding.node` must be in `NODE_PATH`. `npm`
takes care of this automatically.
### Starting a capture session

@@ -74,3 +75,3 @@

var pcap = require('pcap'),
pcap_session = pcap.createSession(interface, filter);
pcap_session = pcap.createSession(interface, options);
```

@@ -81,5 +82,42 @@

`filter` is a pcap filter expression, see `pcap-filter(7)` for more information. An empty string will capture
all packets visible on the interface.
The `options` object accepts the following properties:
- `filter` (string) is a pcap filter expression, see `pcap-filter(7)` for more information. (default: no filter,
all packets visible on the interface will be captured)
- `buffer_size` (number) specifies size of the ringbuffer where packets are stored until delivered to your code, in bytes (default: 10MB)
> Packets that arrive for a capture are stored in a buffer, so that they do not have to be read by the application as soon as they arrive. On some platforms, the buffer's size can be set; a size that's too small could mean that, if too many packets are being captured and the snapshot length doesn't limit the amount of data that's buffered, packets could be dropped if the buffer fills up before the application can read packets from it, while a size that's too large could use more non-pageable operating system memory than is necessary to prevent packets from being dropped.
- `buffer_timeout` (number) specifies the packet buffer timeout in milliseconds (default: 1000)
> If, when capturing, packets are delivered as soon as they arrive, the application capturing the packets will be woken up for each packet as it arrives, and might have to make one or more calls to the operating system to fetch each packet.
>
> If, instead, packets are not delivered as soon as they arrive, but are delivered after a short delay (called a "packet buffer timeout"), more than one packet can be accumulated before the packets are delivered, so that a single wakeup would be done for multiple packets, and each set of calls made to the operating system would supply multiple packets, rather than a single packet. This reduces the per-packet CPU overhead if packets are arriving at a high rate, increasing the number of packets per second that can be captured.
>
> The packet buffer timeout is required so that an application won't wait for the operating system's capture buffer to fill up before packets are delivered; if packets are arriving slowly, that wait could take an arbitrarily long period of time.
>
> Not all platforms support a packet buffer timeout; on platforms that don't, the packet buffer timeout is ignored. A zero value for the timeout, on platforms that support a packet buffer timeout, will cause a read to wait forever to allow enough packets to arrive, with no timeout. A negative value is invalid; the result of setting the timeout to a negative value is unpredictable.
>
> **NOTE:** the packet buffer timeout cannot be used to cause calls that read packets to return within a limited period of time, because, on some platforms, the packet buffer timeout isn't supported, and, on other platforms, the timer doesn't start until at least one packet arrives. This means that the packet buffer timeout should **NOT** be used, for example, in an interactive application to allow the packet capture loop to 'poll' for user input periodically, as there's no guarantee that a call reading packets will return after the timeout expires even if no packets have arrived.
If set to zero or negative, then instead immediate mode is enabled:
> In immediate mode, packets are always delivered as soon as they arrive, with no buffering.
- `monitor` (boolean) specifies if monitor mode is enabled (default: false)
> On IEEE 802.11 wireless LANs, even if an adapter is in promiscuous mode, it will supply to the host only frames for the network with which it's associated. It might also supply only data frames, not management or control frames, and might not provide the 802.11 header or radio information pseudo-header for those frames.
>
> In "monitor mode", sometimes also called "rfmon mode" (for "Radio Frequency MONitor"), the adapter will supply all frames that it receives, with 802.11 headers, and might supply a pseudo-header with radio information about the frame as well.
>
> Note that in monitor mode the adapter might disassociate from the network with which it's associated, so that you will not be able to use any wireless networks with that adapter. This could prevent accessing files on a network server, or resolving host names or network addresses, if you are capturing in monitor mode and are not connected to another network with another adapter.
- `snap_length` (number) specifies the snapshot length in bytes (default: 65535)
> If, when capturing, you capture the entire contents of the packet, that requires more CPU time to copy the packet to your application, more disk and possibly network bandwidth to write the packet data to a file, and more disk space to save the packet. If you don't need the entire contents of the packet - for example, if you are only interested in the TCP headers of packets - you can set the "snapshot length" for the capture to an appropriate value. If the snapshot length is set to snaplen, and snaplen is less than the size of a packet that is captured, only the first snaplen bytes of that packet will be captured and provided as packet data.
>
> A snapshot length of 65535 should be sufficient, on most if not all networks, to capture all the data available from the packet.
Note that `node_pcap` always opens the interface in promiscuous mode, which generally requires running as root.

@@ -90,7 +128,7 @@ Unless you are recklessly roaming about as root already, you'll probably want to start your node program like this:

### Listening for packets
`pcap_session` is an `EventEmitter` that emits a `packet` event. The only argument to the callback will be a
`Buffer` object with the raw bytes returned by `libpcap`.
`PacketWithHeader` object containing the raw bytes returned by `libpcap`:
Listening for packets:
```javascript

@@ -102,5 +140,9 @@ pcap_session.on('packet', function (raw_packet) {

This `raw_packet` contains `buf` and `header` (`Buffer`s) and `link_type`.
To convert `raw_packet` into a JavaScript object that is easy to work with, decode it:
var packet = pcap.decode.packet(raw_packet);
```javascript
var packet = pcap.decode.packet(raw_packet);
```

@@ -114,4 +156,6 @@ The protocol stack is exposed as a nested set of objects. For example, the TCP destination port is part of TCP

This structure is easy to explore with `sys.inspect`.
This structure is easy to explore with `util.inspect`.
However, if you decide to parse `raw_packet.buf` yourself, make sure to truncate it to the first `caplen` bytes first.
### TCP Analysis

@@ -144,2 +188,25 @@

### Other operations
To know the format of the link-layer headers, use `pcap_session.link_type` or `raw_packet.link_type`.
The property is a `LINKTYPE_<...>` string, see [this list](https://www.tcpdump.org/linktypes.html).
To get current capture statistics, use `pcap_session.stats()`. This returns an object with the following properties:
- `ps_recv`: number of packets received
- `ps_ifdrop`: number of packets dropped by the network interface or its driver
- `ps_drop`: number of packets dropped because there was no room in the operating system's buffer when they arrived, because packets weren't being read fast enough
For more info, see [`pcap_stats`](https://www.tcpdump.org/manpages/pcap_stats.3pcap.html).
If you no longer need to receive packets, you can use `pcap_session.close()`.
To read packets from a file instead of from a live interface, use `createOfflineSession` instead:
```javascript
pcap.createOfflineSession('/path/to/capture.pcap', options);
```
Where `options` only accepts the `filter` property.
## Some Common Problems

@@ -190,2 +257,13 @@

### Handling warnings
libpcap may sometimes emit warnings (for instance, when an interface has no address). By default these
are printed to the console, but you can override the warning handler with your own function:
```js
pcap.warningHandler = function (text) {
// ...
}
```
## Examples

@@ -196,26 +274,1 @@

[http_trace](https://github.com/mranney/http_trace) (Node 4 only)
## LICENSE - "MIT License"
Copyright (c) 2010 Matthew Ranney, http://ranney.com/
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
var RadioPacket = require("../../../decode/ieee802.11/radio_packet");
describe("RadioPacket", function(){
var instance, probeExample1, probeExample2;
var instance, probeExample1, probeExample2, probeExample3;
beforeEach(function () {

@@ -18,2 +18,8 @@

"FFFFFFFF" , "hex"); // checksum, note this one is not valid
probeExample3 = new Buffer("000018006f0000008e64643a0000000010029409a000af00" + //Example of a radio tap header
"40000000ffffffffffffe4ce8f16da48ffffffffffff804b" + // Probe request
"0000010402040b16" + // i802.11 tags [ssid]
"FFFFFFFF" , "hex"); // checksum, note this one is not valid
instance = new RadioPacket();

@@ -32,5 +38,5 @@ });

it("sets #signalStrength to be the signal strength in dbi", function(){
it("sets #antenna_signal to be the signal strength in dbi", function(){
instance.decode(probeExample2, 0);
instance.should.have.property("signalStrength", -40);
instance.fields.should.have.property("antenna_signal", -40);
});

@@ -40,5 +46,18 @@

instance.decode(probeExample1, 0);
instance.should.have.property("signalStrength", -45);
instance.fields.should.have.property("antenna_signal", -45);
});
it("handles 64-bit fields", function() {
instance.decode(probeExample3, 0);
instance.fields.should.eql({
tsft: BigInt(979657870),
flags: 0x10,
rate: 2,
channel: { frequency: 2452, flags: 160 },
antenna_signal: -81,
antenna_noise: 0
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc