This commit is contained in:
Administrator
2025-04-24 10:16:38 +08:00
parent 6de65562be
commit 7267aec1fd
108 changed files with 7621 additions and 1890 deletions
@@ -63,13 +63,43 @@ public class Inet6AddressGroup implements Comparable<Inet6AddressGroup>{
public int getPrefixLength() {
return prefixLength;
}
private byte[] cachedRawAddress;
public byte[] getRawAddress() {
if(cachedRawAddress==null) {
return (cachedRawAddress=address.getAddress());
}else {
return cachedRawAddress;
}
}
private byte[] cachedAndm;
private byte[] getAndm(byte[]mask) {
if(cachedAndm==null) {
return (cachedAndm=and0(mask ,getRawAddress()));
}else {
return cachedAndm;
}
}
public boolean checkMatch(Inet6Address ia) {
byte[]mask=maskTransf[prefixLength];
byte[]andj=and0(mask,ia.getAddress());
byte[]andm=and0(mask ,address.getAddress());
return Arrays.equals(andj,andm);
byte[]andm=getAndm(mask);
return andeq0(mask,ia.getAddress(),andm);
}
private byte[] and0(byte[] bs, byte[] address2) {
public boolean checkMatch(byte[] ia) {
byte[]mask=maskTransf[prefixLength];
byte[]andm=getAndm(mask);
return andeq0(mask,ia,andm);
}
private static boolean andeq0(byte[] bs, byte[] address2, byte[] andm) {
for (int i = 0; i < bs.length; i++) {
if(andm[i]!=(byte) (bs[i]&address2[i])) {
return false;
}
}
return true;
}
private static byte[] and0(byte[] bs, byte[] address2) {
byte[]rez=new byte[bs.length];
for (int i = 0; i < rez.length; i++) {
rez[i]=(byte) (bs[i]&address2[i]);
@@ -90,4 +120,5 @@ public class Inet6AddressGroup implements Comparable<Inet6AddressGroup>{
address=(Inet6Address) Inet6Address.getByAddress(b);
prefixLength=in.read();
}
}