return sprintf("%.2f %s", $bytes, $unit);
}
+# Function to collect and generate a hash for translating protocol numbers into
+# their names.
+sub generateProtoTransHash () {
+ # File which contains the protocol definitions.
+ my $protocols_file = "/etc/protocols";
+
+ my %protocols = ();
+
+ # Open protocols file.
+ open(FILE, "$protocols_file") or die "Could not open $protocols_file. $!\n";
+
+ # Loop through the file.
+ while (my $line = <FILE>) {
+ # Skip comments.
+ next if ($line =~ /^\#/);
+
+ # Skip blank lines.
+ next if ($line =~ /^\s*$/);
+
+ # Remove any newlines.
+ chomp($line);
+
+ # Split line content.
+ my ($protocol_lc, $number, $protocol_uc, $comment) = split(' ', $line);
+
+ # Add proto details to the hash of protocols.
+ $protocols{$number} = $protocol_uc;
+ }
+
+ # Close file handle.
+ close(FILE);
+
+ # Return the hash.
+ return %protocols;
+}
+
# Cloud Stuff
sub running_in_cloud() {
END
;
+# Generate hash to translate protocol numbers into protocol names.
+my %protocols = &General::generateProtoTransHash();
$lines = 0;
foreach $_ (@log)
# Get the country code.
my $ccode = &Location::Functions::lookup_country_code($srcaddr);
+ # Lookup if the grabbed protocol is part of the protocols hash.
+ if (exists ($protocols{$proto})) {
+ # Translate protocol number into protocol name.
+ $proto = $protocols{$proto};
+ }
+
my $servi = uc(getservbyport($srcport, lc($proto)));
if ($servi ne '' && $srcport < 1024) {
$srcport = "$srcport($servi)";