/[suikacvs]/messaging/manakai/lib/Message/Util/HostPermit.pm
Suika

Diff of /messaging/manakai/lib/Message/Util/HostPermit.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Wed Sep 17 02:34:32 2003 UTC revision 1.2 by wakaba, Sat Sep 27 07:59:11 2003 UTC
# Line 69  sub check ($$;$) { Line 69  sub check ($$;$) {
69        }        }
70      }      }
71    }    }
72    return 1;    return 0;
73  }  }
74    
75  sub match_host ($$$) {  sub match_host ($$$) {
# Line 97  sub match_ipv4 ($$$) { Line 97  sub match_ipv4 ($$$) {
97      $addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/;      $addr =~ /([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/;
98      $addr = pack 'C4', $1, $2, $3, $4;      $addr = pack 'C4', $1, $2, $3, $4;
99    }    }
100      my $mask = pack 'C4', 255, 255, 255, 255;
101    if (length ($pattern) != 4) {    if (length ($pattern) != 4) {
102      $pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?!;      $pattern =~ m!([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(?:/([0-9]+))?!;
103      $pattern = pack 'C4', $1, $2, $3, $4;      $pattern = pack 'C4', $1, $2, $3, $4;
104      my $m = $5; $m %= 33;      my $m = $5; $m = 32 if $m > 32;
105      my $mask = pack 'C4', (($m > 24) ? (2**($m-24)-1, 255, 255, 255) :      if (defined $m) {
106                             ($m > 16) ? (0, 2**($m-16)-1, 255, 255) :        $mask = pack 'C4', (($m > 24) ? (255, 255, 255, (2**($m-24)-1) << (32-$m)) :
107                             ($m >  8) ? (0, 0, 2**($m-8)-1, 255) :                            ($m > 16) ? (255, 255, (2**($m-16)-1) << (24-$m), 0) :
108                                         (0, 0, 0, 2**$m));                            ($m >  8) ? (255, (2**($m-8)-1) << (16-$m), 0, 0) :
109      $pattern |= $mask;                                        ((2**$m-1) << (8-$m), 0, 0, 0));
110        }
111        $pattern &= $mask;
112        #printf '[%vd] %vd (%s) %vd (%vd) %d', $mask, $pattern, $_[1], ($addr & $mask), $addr, (($addr & $mask) eq $pattern);
113    }    }
114    return (($addr & $pattern) eq $addr) ? 1 : 0;    return (($addr & $mask) eq $pattern) ? 1 : 0;
115  }  }
116    
117  ## TODO: IPv6 support  ## TODO: IPv6 support

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24