Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #24 from jmoyers/master

UDP payload support
  • Loading branch information...
commit 23fc6a4932fa15b3e0bf04c68ce08662b1fdd3e0 2 parents f0c04a5 + 2852a81
@mranney authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 pcap.js
View
21 pcap.js
@@ -697,11 +697,22 @@ decode.udp = function (raw_packet, offset) {
var ret = {};
// http://en.wikipedia.org/wiki/User_Datagram_Protocol
- ret.sport = unpack.uint16(raw_packet, offset); // 0, 1
- ret.dport = unpack.uint16(raw_packet, offset + 2); // 2, 3
- ret.length = unpack.uint16(raw_packet, offset + 4); // 4, 5
- ret.checksum = unpack.uint16(raw_packet, offset + 6); // 6, 7
-
+ ret.sport = unpack.uint16(raw_packet, offset); // 0, 1
+ ret.dport = unpack.uint16(raw_packet, offset + 2); // 2, 3
+ ret.length = unpack.uint16(raw_packet, offset + 4); // 4, 5
+ ret.checksum = unpack.uint16(raw_packet, offset + 6); // 6, 7
+
+ ret.data_offset = offset + 8;
+ ret.data_end = ret.length + ret.data_offset - 8;
+ ret.data_bytes = ret.data_end - ret.data_offset;
+
+ // Follow tcp pattern and don't make a copy of the data payload
+ // Therefore its only valid for this pass throught the capture loop
+ if (ret.data_bytes > 0) {
+ ret.data = raw_packet.slice(ret.data_offset, ret.data_end);
+ ret.data.length = ret.data_bytes;
+ }
+
if (ret.sport === 53 || ret.dport === 53) {
ret.dns = decode.dns(raw_packet, offset + 8);
}
Please sign in to comment.
Something went wrong with that request. Please try again.