7 require './access_list.pl';
14 vec($bits, fileno($fh), 1) = 1;
19 my @ports = mbd::find_all_ports();
21 # Open a socket for each port
23 my $udp = getprotobyname("udp");
26 socket($sock, PF_INET, SOCK_DGRAM, $udp);
27 bind($sock, sockaddr_in($p, INADDR_ANY));
31 my $sendsock = Net::RawIP->new({udp => {}});
33 print "Listening on " . scalar @ports . " ports.\n";
37 my $rin = fhbits(@socks);
40 my $nfound = select($rout=$rin, undef, undef, undef);
41 for my $sock (@socks) {
42 next unless (vec($rout, fileno($sock), 1) == 1);
45 my $addr = recv($sock, $data, 8192, 0); # jumbo broadcast! :-P
46 my ($sport, $saddr) = sockaddr_in($addr);
47 my ($dport, $daddr) = sockaddr_in(getsockname($sock));
48 my $size = length($data);
50 # We don't get the packet's destination address, but I guess this should do...
51 # Check against the ACL.
53 for my $rule (@Config::access_list) {
54 next unless (mbd::match_ranges($dport, $rule->{'ports'}));
55 next unless (mbd::match_ranges($size, $rule->{'sizes'}));
57 if ($rule->{'filter'}) {
58 next unless ($rule->{'filter'}($data));
66 print "$dport, $size bytes => filtered\n";
71 for my $net (@Config::networks) {
72 next if (Net::CIDR::cidrlookup(inet_ntoa($saddr), $net));
74 my ($range) = Net::CIDR::cidr2range($net);
78 print inet_ntoa($saddr), ", $dport, $size bytes => $broadcast\n";
82 saddr => inet_ntoa($saddr),