Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix] Changed require('util') to require('util') for compatibility wi…

…th node v0.8
  • Loading branch information...
commit 867d3d08dabe4d34466ecd7f2041a7bbfa8d71d2 1 parent 48a7c11
@blakmatrix blakmatrix authored
View
70 examples/http_trace
@@ -2,7 +2,7 @@
/*global process require exports setInterval console */
-var sys = require("sys"),
+var util = require('util'),
node_http = require('http'),
node_url = require('url'),
pcap = require("pcap"), pcap_session,
@@ -101,7 +101,7 @@ function format_obj(obj) {
return keys.map(function (key) {
if (typeof obj[key] === 'object') {
- return " " + ANSI(key, "white") + sys.inspect(obj[key]);
+ return " " + ANSI(key, "white") + util.inspect(obj[key]);
} else {
return " " + ANSI(key, "white") + ": " + ANSI(obj[key], "grey");
}
@@ -110,38 +110,38 @@ function format_obj(obj) {
function usage_die(message) {
if (message) {
- sys.error("");
- sys.error(message);
+ util.error("");
+ util.error(message);
}
- sys.error("");
- sys.error("usage: http_trace [options]");
- sys.error("");
- sys.error("Capture options:");
- sys.error(" -i <interface> interface name for capture (def: first with an addr)");
- sys.error(" -f <pcap_filter> packet filter in pcap-filter(7) syntax (def: all TCP packets)");
- sys.error(" -b <buffer> size in MB to buffer between libpcap and app (def: 10)");
- sys.error("");
- sys.error("HTTP filtering:");
- sys.error(" Filters are OR-ed together and may be specified more than once.");
- sys.error(" --method <regex> filter on method");
- sys.error(" --host <regex> filter on Host request header");
- sys.error(" --url <regex> filter on URL");
- sys.error(" --user-agent <regex> filter on User-Agent request header");
- sys.error("");
- sys.error("HTTP output:");
- sys.error(" --headers print headers of request and response (def: off)");
- sys.error(" --bodies print request and response bodies, if any (def: off)");
-// sys.error(" --group group all output for req/res (def: progressive)");
- sys.error(" --tcp-verbose display TCP events (def: off)");
- sys.error(" --no-color disable ANSI colors (def: pretty colors on)");
- sys.error("");
- sys.error("Examples:");
- sys.error(' http_trace -f "tcp port 80"');
- sys.error(' listen for TCP port 80 on the default device');
- sys.error(' http_trace -i eth1 --method POST');
- sys.error(' listen on eth1 for all traffic that has an HTTP POST');
- sys.error(' http_trace --host ranney --headers');
- sys.error(' matches ranney in Host header and prints req/res headers');
+ util.error("");
+ util.error("usage: http_trace [options]");
+ util.error("");
+ util.error("Capture options:");
+ util.error(" -i <interface> interface name for capture (def: first with an addr)");
+ util.error(" -f <pcap_filter> packet filter in pcap-filter(7) syntax (def: all TCP packets)");
+ util.error(" -b <buffer> size in MB to buffer between libpcap and app (def: 10)");
+ util.error("");
+ util.error("HTTP filtering:");
+ util.error(" Filters are OR-ed together and may be specified more than once.");
+ util.error(" --method <regex> filter on method");
+ util.error(" --host <regex> filter on Host request header");
+ util.error(" --url <regex> filter on URL");
+ util.error(" --user-agent <regex> filter on User-Agent request header");
+ util.error("");
+ util.error("HTTP output:");
+ util.error(" --headers print headers of request and response (def: off)");
+ util.error(" --bodies print request and response bodies, if any (def: off)");
+// util.error(" --group group all output for req/res (def: progressive)");
+ util.error(" --tcp-verbose display TCP events (def: off)");
+ util.error(" --no-color disable ANSI colors (def: pretty colors on)");
+ util.error("");
+ util.error("Examples:");
+ util.error(' http_trace -f "tcp port 80"');
+ util.error(' listen for TCP port 80 on the default device');
+ util.error(' http_trace -i eth1 --method POST');
+ util.error(' listen on eth1 for all traffic that has an HTTP POST');
+ util.error(' http_trace --host ranney --headers');
+ util.error(' matches ranney in Host header and prints req/res headers');
process.exit(1);
}
@@ -261,7 +261,7 @@ function start_drop_watcher() {
setInterval(function () {
var stats = pcap_session.stats();
if (stats.ps_drop > 0) {
- console.log(ANSI("pcap dropped packets, need larger buffer or less work to do: " + sys.inspect(stats), "bold"));
+ console.log(ANSI("pcap dropped packets, need larger buffer or less work to do: " + util.inspect(stats), "bold"));
}
}, 2000);
}
@@ -423,7 +423,7 @@ function setup_listeners() {
console.log(line_start + " WebSocket message " + format_size(message.length));
try {
obj = JSON.parse(message);
- console.log("JSON: " + ANSI(sys.inspect(obj), "green"));
+ console.log("JSON: " + ANSI(util.inspect(obj), "green"));
} catch (err) {
console.log(ANSI(message, "green"));
}
View
26 examples/simple_capture
@@ -2,41 +2,41 @@
/*global process require exports */
-var sys = require("sys"),
+var util = require('util'),
pcap = require("pcap"), pcap_session;
if (process.argv.length > 4) {
- sys.error("usage: simple_capture interface filter");
- sys.error("Examples: ");
- sys.error(' simple_capture "" "tcp port 80"');
- sys.error(' simple_capture eth1 ""');
- sys.error(' simple_capture lo0 "ip proto \\tcp and tcp port 80"');
+ util.error("usage: simple_capture interface filter");
+ util.error("Examples: ");
+ util.error(' simple_capture "" "tcp port 80"');
+ util.error(' simple_capture eth1 ""');
+ util.error(' simple_capture lo0 "ip proto \\tcp and tcp port 80"');
process.exit(1);
}
pcap_session = pcap.createSession(process.argv[2], process.argv[3]);
// libpcap's internal version numnber
-sys.puts(pcap.lib_version);
+util.puts(pcap.lib_version);
// Print all devices, currently listening device prefixed with an asterisk
pcap_session.findalldevs().forEach(function (dev) {
if (pcap_session.device_name === dev.name) {
- sys.print("* ");
+ util.print("* ");
}
- sys.print(dev.name + " ");
+ util.print(dev.name + " ");
if (dev.addresses.length > 0) {
dev.addresses.forEach(function (address) {
- sys.print(address.addr + "/" + address.netmask);
+ util.print(address.addr + "/" + address.netmask);
});
- sys.print("\n");
+ util.print("\n");
} else {
- sys.print("no address\n");
+ util.print("no address\n");
}
});
// Listen for packets, decode them, and feed the simple printer. No tricks.
pcap_session.on('packet', function (raw_packet) {
var packet = pcap.decode.packet(raw_packet);
- sys.puts(pcap.print.packet(packet));
+ util.puts(pcap.print.packet(packet));
});
View
24 examples/speed_server
@@ -2,7 +2,7 @@
/*global process require exports setInterval __dirname */
-var sys = require("sys"),
+var util = require('util'),
Buffer = require("buffer").Buffer,
pcap = require("pcap"), pcap_session,
count = 0,
@@ -17,11 +17,11 @@ var sys = require("sys"),
bulk_data;
if (process.argv.length !== 4) {
- sys.error("usage speed_server interface filter");
- sys.error("Examples: ");
- sys.error(' speed_server "" "tcp port 80"');
- sys.error(' speed_server eth1 ""');
- sys.error(' speed_server lo0 "ip proto \\tcp and tcp port 80"');
+ util.error("usage speed_server interface filter");
+ util.error("Examples: ");
+ util.error(' speed_server "" "tcp port 80"');
+ util.error(' speed_server eth1 ""');
+ util.error(' speed_server lo0 "ip proto \\tcp and tcp port 80"');
process.exit(1);
}
@@ -36,23 +36,23 @@ pcap_session = pcap.createSession(process.argv[2], process.argv[3]);
console.log("All devices:");
pcap_session.findalldevs().forEach(function (dev) {
if (pcap_session.device_name === dev.name) {
- sys.print("* ");
+ util.print("* ");
}
- sys.print(dev.name + " ");
+ util.print(dev.name + " ");
if (dev.addresses.length > 0) {
dev.addresses.forEach(function (address) {
- sys.print(address.addr + "/" + address.netmask);
+ util.print(address.addr + "/" + address.netmask);
});
- sys.print("\n");
+ util.print("\n");
} else {
- sys.print("no address\n");
+ util.print("no address\n");
}
});
setInterval(function () {
var stats = pcap_session.stats();
if (stats.ps_drop > 0) {
- console.log("pcap dropped packets: " + sys.inspect(stats));
+ console.log("pcap dropped packets: " + util.inspect(stats));
}
}, 5000);
View
18 examples/tcp_metrics
@@ -2,29 +2,29 @@
/*global process require exports setInterval */
-var sys = require("sys"),
+var util = require('util'),
pcap = require("pcap"), pcap_session,
dns_cache = pcap.dns_cache,
tcp_tracker = new pcap.TCP_tracker();
if (process.argv.length > 4) {
- sys.error("usage: tcp_metrics interface filter");
- sys.error("Examples: ");
- sys.error(' tcp_metrics "" "tcp port 80"');
- sys.error(' tcp_metrics eth1 ""');
- sys.error(' tcp_metrics lo0 "ip proto \\tcp and tcp port 80"');
+ util.error("usage: tcp_metrics interface filter");
+ util.error("Examples: ");
+ util.error(' tcp_metrics "" "tcp port 80"');
+ util.error(' tcp_metrics eth1 ""');
+ util.error(' tcp_metrics lo0 "ip proto \\tcp and tcp port 80"');
process.exit(1);
}
pcap_session = pcap.createSession(process.argv[2], process.argv[3]);
-sys.puts("Listening on " + pcap_session.device_name);
+util.puts("Listening on " + pcap_session.device_name);
// Check for pcap dropped packets on an interval
setInterval(function () {
var stats = pcap_session.stats();
if (stats.ps_drop > 0) {
- sys.puts("pcap dropped packets: " + sys.inspect(stats));
+ util.puts("pcap dropped packets: " + util.inspect(stats));
}
}, 2000);
@@ -34,7 +34,7 @@ tcp_tracker.on('start', function (session) {
tcp_tracker.on('end', function (session) {
console.log("End of TCP session between " + session.src_name + " and " + session.dst_name);
- console.log("Set stats for session: " + sys.inspect(tcp_tracker.session_stats(session)));
+ console.log("Set stats for session: " + util.inspect(tcp_tracker.session_stats(session)));
});
// listen for packets, decode them, and feed TCP to the tracker
View
2  pcap.js
@@ -12,7 +12,7 @@ if (process.versions && process.versions.node && process.versions.node.split('.'
util = require("util");
IOWatcher = process.binding('io_watcher').IOWatcher;
} else {
- util = require("sys");
+ util = require('util');
IOWatcher = process.IOWatcher;
}
Please sign in to comment.
Something went wrong with that request. Please try again.