{"library":"pcap-parser","title":"PCAP File Parser for Node.js","description":"pcap-parser is a Node.js module designed to parse `.pcap` packet capture files. Originally published in 2012, its current and last stable version is 0.2.1. This library focuses on the raw parsing of pcap file headers and individual packet data, emitting events for global header, packet header, packet data, and complete packets. It strictly supports only version 2.4 of the `libpcap` file format in both big-endian and little-endian formats. Due to its age, it primarily caters to older Node.js environments (engine requirement `>=0.6.0`) and does not support the newer `pcapng` format or provide high-level protocol decoding. Its release cadence is non-existent, as it has not been updated in over a decade. While functional for its specific, limited purpose, developers should be aware of its lack of maintenance and consider modern alternatives for broader compatibility or advanced features.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install pcap-parser"],"cli":null},"imports":["const pcapp = require('pcap-parser');\nconst parser = new pcapp.Parser('/path/to/file.pcap');","const pcapp = require('pcap-parser');\nconst fs = require('fs');\nconst readableStream = fs.createReadStream('/path/to/file.pcap');\nconst parser = new pcapp.Parser(readableStream);","const pcapp = require('pcap-parser');\nconst parser = new pcapp.Parser('/path/to/file.pcap');\nparser.on('packet', function(packet) {\n  // packet.header and packet.data (Buffer)\n});"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const pcapp = require('pcap-parser');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create a dummy pcap file for demonstration if it doesn't exist\nconst dummyPcapPath = path.join(__dirname, 'dummy.pcap');\nif (!fs.existsSync(dummyPcapPath)) {\n  // This is a minimal valid pcap global header followed by an empty packet header\n  // Magic number (0xa1b2c3d4), major=2, minor=4, GMT=0, accuracy=0, snaplen=65535, linktype=1 (Ethernet)\n  const dummyPcapData = Buffer.from([\n    0xd4, 0xc3, 0xb2, 0xa1, // magic_number (little-endian)\n    0x02, 0x00, 0x04, 0x00, // version_major, version_minor\n    0x00, 0x00, 0x00, 0x00, // thiszone\n    0x00, 0x00, 0x00, 0x00, // sigfigs\n    0xff, 0xff, 0x00, 0x00, // snaplen (65535)\n    0x01, 0x00, 0x00, 0x00, // network (LINKTYPE_ETHERNET)\n    // Empty packet data\n    0x00, 0x00, 0x00, 0x00, // ts_sec\n    0x00, 0x00, 0x00, 0x00, // ts_usec\n    0x00, 0x00, 0x00, 0x00, // incl_len\n    0x00, 0x00, 0x00, 0x00  // orig_len\n  ]);\n  fs.writeFileSync(dummyPcapPath, dummyPcapData);\n  console.log(`Created dummy pcap file at ${dummyPcapPath}`);\n}\n\nconst parser = new pcapp.Parser(dummyPcapPath);\nlet packetCount = 0;\n\nparser.on('globalHeader', function(header) {\n  console.log('Global Header:', header);\n});\n\nparser.on('packet', function(packet) {\n  packetCount++;\n  console.log(`Packet ${packetCount}:`, {\n    header: packet.header,\n    dataLength: packet.data.length\n  });\n  // You can process packet.data (a Buffer) here\n});\n\nparser.on('end', function() {\n  console.log(`Finished parsing. Total packets: ${packetCount}`);\n  // Clean up dummy file\n  fs.unlinkSync(dummyPcapPath);\n  console.log(`Removed dummy pcap file: ${dummyPcapPath}`);\n});\n\nparser.on('error', function(err) {\n  console.error('Parser error:', err);\n});\n\nparser.parse(); // Initiate parsing","lang":"javascript","description":"This quickstart demonstrates how to instantiate the PCAP parser with a file path, listen for `globalHeader`, `packet`, and `end` events, and then initiate the parsing process. It includes a small self-contained dummy pcap file creation for immediate execution.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}