sub lnetsearch() {
    my($ip, $data_file) = @_;
    my(@ip_packed) = split(/\./, $ip);
    while (@ip_packed < 4) {
	@ip_packed = (@ip_packed, '0');
    }
    my($ip1_packed) = ($ip_packed[$[] << 24) +
		    ($ip_packed[$[+1] << 16) +
		    ($ip_packed[$[+2] << 8) +
		    $ip_packed[$[+3];

    my(%nets);
    unless (open(DATA, $data_file)) {
        die("couldn't open file '$data_file': $!\n");
    } else {
	my($line, $result, $found, $ip_net);
	while ($line = <DATA>) {
	    unless ($line =~ /^\s*[#\r\n]/) {
	        my($net, $tmp2, $tmp3, $mask, $value) = ($line =~
		    /^\s*(\d{0,3}(\.\d{0,3}){0,3})(\s*\/\s*(\d+))?\s*:?\s*(.*)?\s*$/);
	        my(@ip_packed) = split(/\./, $net);
		while (@ip_packed < 4) {
		    @ip_packed = (@ip_packed, '0');
	        }
	        my($ip2_packed) = ($ip_packed[$[] << 24) +
				    ($ip_packed[$[+1] << 16) +
				    ($ip_packed[$[+2] << 8) +
				    $ip_packed[$[+3];
		chomp($value);
		$mask = 32 unless ($mask);
		my $packed_mask = (0xffffffff << (32-$mask)) & 0xffffffff;
		my $ip_net1 = $ip1_packed & $packed_mask;
		my $ip_net2 = $ip2_packed & $packed_mask;
		
		if ($ip_net1 eq $ip_net2) {
    		    $result = ($value ? $value : 'found');
		    $found = 1;
		}
	    }
	}
	close(DATA);
	return($result) if ($found);
    }
    return('');
}
