New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ip-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-stream - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

test/test-fragment.js

2

package.json

@@ -11,3 +11,3 @@ {

],
"version": "0.1.0",
"version": "0.2.0",
"author": "Ben Kelly <ben@wanderview.com>",

@@ -14,0 +14,0 @@ "license": "BSD",

@@ -52,2 +52,4 @@ // Copyright (c) 2013, Benjamin J. Kelly ("Author")

self._fragments = {};
return self;

@@ -71,8 +73,14 @@ }

try {
var iph = new IpHeader(msg.data, msg.offset);
msg.ip = new IpHeader(msg.data, msg.offset);
msg.offset += msg.ip.length;
// TODO: handle fragmentation
if (msg.ip.flags.mf || msg.ip.offset) {
msg = this._handleFragment(msg);
if (!msg) {
callback();
return;
}
}
msg.ip = iph;
msg.offset += iph.length;
output(msg);

@@ -86,1 +94,49 @@

}
IpStream.prototype._handleFragment = function(msg) {
var key = msg.ip.src + '-' + msg.ip.dst + '-' + msg.ip.id;
// TODO: cleanup stale fragments to avoid memory leaks
var list = this._fragments[key];
if (!list) {
list = this._fragments[key] = [];
}
list.push(msg);
list.sort(function(a, b) {
return a.ip.offset - b.ip.offset;
});
// If the last packet still expects more fragments, can't reassemble yet.
if (list[list.length - 1].ip.flags.mf) {
return null;
}
// Ok, last packet is here, do we have the rest? If there is a gap in
// the sequence of bytes, then we can't reassemble yet.
var totalLength = 0;
var bufferList = [];
var expectedOffset = 0;
for (var i = 0, n = list.length; i < n; ++i) {
var packet = list[i];
if (packet.ip.offset !== expectedOffset) {
return null;
}
totalLength += packet.ip.dataLength;
bufferList.push(packet.data.slice(~~packet.offset));
expectedOffset += (packet.ip.dataLength / 8);
}
msg.data = Buffer.concat(bufferList, totalLength);
msg.ip.dataLength = msg.data.length;
msg.ip.totalLength = msg.ip.length + msg.ip.dataLength;
msg.ip.flags.mf = false;
msg.ip.offset = 0;
delete this._fragments[key];
return msg;
};
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