NetMaskImplpublic class NetMaskImpl extends PrincipalImpl implements java.security.acl.Group, SerializableThis class is used to represent a subnet mask (a group of hosts matching the same
IP mask). |
Fields Summary |
---|
protected byte[] | subnet | protected int | prefix | String | dbgTag |
Constructors Summary |
---|
public NetMaskImpl()Constructs an empty group.
| public NetMaskImpl(String a, int prefix)Constructs a group using the specified subnet mask.
THIS ALGORITHM IS V4 and V6 compatible.
super(a);
this.prefix = prefix;
subnet = extractSubNet(getAddress().getAddress());
|
Methods Summary |
---|
public boolean | addMember(java.security.Principal p)Adds the specified member to the group.
// we don't need to add members because the ip address is a subnet mask
return true;
| void | debug(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info);
| void | debug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)
Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, exception);
| void | debug(java.lang.String func, java.lang.String info)
debug(dbgTag, func, info);
| void | debug(java.lang.String func, java.lang.Throwable exception)
debug(dbgTag, func, exception);
| public boolean | equals(java.lang.Object p)Compares this group to the specified object. Returns true if the object
passed in matches the group represented.
if (p instanceof PrincipalImpl || p instanceof NetMaskImpl){
PrincipalImpl received = (PrincipalImpl) p;
InetAddress addr = received.getAddress();
if(isDebugOn()) {
debug("equals","Received Address : " + addr);
}
byte[] recAddr = addr.getAddress();
for(int i = 0; i < subnet.length; i++) {
if(isDebugOn()) {
debug("equals","(recAddr[i]) :" + (recAddr[i] & 0xFF));
debug("equals","(recAddr[i] & subnet[i]) :" +
( (int) (recAddr[i] & (int)subnet[i]) &0xFF) +
"subnet[i] :" + (int) (subnet[i] &0xFF));
}
if((recAddr[i] & subnet[i]) != subnet[i]) {
if(isDebugOn()) {
debug("equals","FALSE");
}
return false;
}
}
if(isDebugOn()) {
debug("equals","TRUE");
}
return true;
} else
return false;
| private byte[] | extractSubNet(byte[] b)
int addrLength = b.length;
byte[] subnet = null;
if(isDebugOn()) {
debug("extractSubNet","BINARY ARRAY :");
StringBuffer buff = new StringBuffer();
for(int i =0; i < addrLength; i++) {
buff.append((int)(b[i] &0xFF) +":");
}
debug("extractSubNet", buff.toString());
}
// 8 is a byte size. Common to any InetAddress (V4 or V6).
int fullyCoveredByte = prefix / 8;
if(fullyCoveredByte == addrLength) {
if(isDebugOn()) {
debug("extractSubNet"," The mask is the complete address, strange..." + addrLength);
}
subnet = b;
return subnet;
}
if(fullyCoveredByte > addrLength) {
if(isDebugOn()) {
debug("extractSubNet"," The number of covered byte is longer than the address. BUG");
}
throw new IllegalArgumentException("The number of covered byte is longer than the address.");
}
int partialyCoveredIndex = fullyCoveredByte;
if(isDebugOn()) {
debug("extractSubNet"," Partialy covered index : " + partialyCoveredIndex);
}
byte toDeal = b[partialyCoveredIndex];
if(isDebugOn()) {
debug("extractSubNet"," Partialy covered byte : " + toDeal);
}
// 8 is a byte size. Common to any InetAddress (V4 or V6).
int nbbits = prefix % 8;
int subnetSize = 0;
if(nbbits == 0)
subnetSize = partialyCoveredIndex;
else
subnetSize = partialyCoveredIndex + 1;
if(isDebugOn()) {
debug("extractSubNet"," Remains : " + nbbits);
}
byte mask = 0;
for(int i = 0; i < nbbits; i++) {
mask |= (1 << (7 - i));
}
if(isDebugOn()) {
debug("extractSubNet","Mask value" + (int) (mask & 0xFF));
}
byte maskedValue = (byte) ((int)toDeal & (int)mask);
if(isDebugOn()) {
debug("extractSubNet","Masked byte :" + (int) (maskedValue &0xFF));
}
subnet = new byte[subnetSize];
if(isDebugOn()) {
debug("extractSubNet","Resulting subnet : ");
}
for(int i = 0; i < partialyCoveredIndex; i++) {
subnet[i] = b[i];
if(isDebugOn()) {
debug("extractSubNet",(int) (subnet[i] & 0xFF) +":");
}
}
if(nbbits != 0) {
subnet[partialyCoveredIndex] = maskedValue;
if(isDebugOn()) {
debug("extractSubNet"," Last subnet byte : " + (int) (subnet[partialyCoveredIndex] &0xFF));
}
}
return subnet;
| public int | hashCode()
return super.hashCode();
| boolean | isDebugOn()
return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP);
| public boolean | isMember(java.security.Principal p)Returns true if the passed principal is a member of the group.
if ((p.hashCode() & super.hashCode()) == p.hashCode()) return true;
else return false;
| boolean | isTraceOn()
return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP);
| public java.util.Enumeration | members()Returns an enumeration which contains the subnet mask.
Vector v = new Vector(1);
v.addElement(this);
return v.elements();
| public boolean | removeMember(java.security.Principal p)Removes the specified member from the group. (Not implemented)
return true;
| public java.lang.String | toString()Prints a string representation of this group.
return ("NetMaskImpl :"+ super.getAddress().toString() + "/" + prefix);
| void | trace(java.lang.String clz, java.lang.String func, java.lang.String info)
Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info);
| void | trace(java.lang.String func, java.lang.String info)
trace(dbgTag, func, info);
|
|