summaryrefslogtreecommitdiff
path: root/Echolot/Tools.pm
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-02-16 10:07:27 +0000
committerPeter Palfrader <peter@palfrader.org>2003-02-16 10:07:27 +0000
commitf1f08852ceddea6f66627b8473f9b0177ddd8fef (patch)
tree70c079112017bf8bb97b2de505d3685383934473 /Echolot/Tools.pm
parent18c647bc293990fd8471d7d6fdb902315359dcfd (diff)
Append random garbage to pings so they have different lengths
Diffstat (limited to 'Echolot/Tools.pm')
-rw-r--r--Echolot/Tools.pm31
1 files changed, 30 insertions, 1 deletions
diff --git a/Echolot/Tools.pm b/Echolot/Tools.pm
index 86adb91..2094d5c 100644
--- a/Echolot/Tools.pm
+++ b/Echolot/Tools.pm
@@ -1,7 +1,7 @@
package Echolot::Tools;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: Tools.pm,v 1.15 2003/02/15 11:43:41 weasel Exp $
+# $Id: Tools.pm,v 1.16 2003/02/16 10:07:27 weasel Exp $
#
=pod
@@ -308,6 +308,35 @@ sub crypt_symmetrically($$) {
return $result;
};
+sub make_garbage() {
+
+ my $file = Echolot::Config::get()->{'dev_urandom'};
+ open(FH, $file) or
+ Echolot::Log::warn("Cannot open $file: $!."),
+ return "";
+ my $random = '';
+ my $want = rand(int(Echolot::Config::get()->{'random_garbage'} / 2));
+ my $i = 0;
+ while ($want > 0) {
+ my $buf;
+ $want -= read(FH, $buf, $want);
+ $random .= $buf;
+ ($i++ > 15 && $want > 0) and
+ Echolot::Log::warn("Could not get enough garbage (still missing $want."),
+ last;
+ };
+ close (FH) or
+ Echolot::Log::warn("Cannot close $file: $!.");
+
+ $random = unpack("H*", $random);
+ $random = join "\n", grep { $_ ne '' } (split /(.{64})/, $random);
+ $random = "----- BEGIN GARBAGE' -----\n".
+ $random."\n".
+ "----- BEGIN GARBAGE' -----\n";
+
+ return $random;
+};
+
1;
# vim: set ts=4 shiftwidth=4: