sub detect_hashtype (@) {
my @data = @_;
- # XXX - Currently we only support sets with single addresses and/or networks.
- # Improve the detection if neccessary at a later time.
+ # Currently we only support sets with single addresses, networks and
+ # ports. Improve the detection if neccessary at a later time.
#
- # Default to a hashtype of hash:ip for only single addresses.
- my $hashtype = "hash:ip";
-
- # Use perl grep to check if a "/" could be found in the data.
- # In this case the list contains at least one network and we have to use the
- # hash:net as hashtype.
- if(grep(/\//, @data)) {
- # The set contains a network, switching hashtype.
- $hashtype = "hash:net";
- }
+ # Check if the data contains a comma, which is used by the
+ # multip element sets.
+ return "Not supported" if(grep(/\,/, @data));
+
+ # Check if the data contains a slash, which assumes it contains
+ # at least one network.
+ return "hash:net" if(grep(/\//, @data));
+
+ # Check if the data contains dots, which assumes it contains
+ # IP addresses.
+ return "hash:ip" if(grep(/\./, @data));
+
+ # Check if the first data element is nummeric, in this case
+ # decide it contains only ports.
+ return "bitmap:port" if( $data[0] =~ /\d+/);
- return $hashtype;
+ # If we got here, no rule matched and we could not determine
+ # a type for the given data.
+ return "Not detected";
}
#