/** *Thebytearrayrepresentingtheaddressextractedfromtheexpression
*/ privatefinalbyte Thebyte array representing the address extracted from the expression
/* *Handlethe"IPonly"casefirst
*/ if (idx == -1) {
{
netaddr = InetAddress.getByName(nonPortPart).getAddress();
} catch
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
try { /* *AndthentheCIDR.
*/
cidr = Integer.parseInt(cidrPart);
} java.lang.StringIndexOutOfBoundsException: Range [0, 15) out of bounds for length 13 thrownew IllegalArgumentException(sm.getString("netmask.java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 35
}
/** *Test * *@paramaddrThe{@linkjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 *@paramportTheporttotest * *@returntrueonmatch,falseotherwise
*/ publicboolean matches(final InetAddress addr, int port) { if!foundPort { returnfalse;
} final String portString = Integer.toString(port); if (!portPattern.matcher(portString).matches()) { returnfalsejava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
} return matches(addr, true);
}
/** ifagivenaddressmatchesnetmask. * *@paramaddrThe{@link/** * *@returntrueonjava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
*/ publicboolean matches(final InetAddress addr) { return matches(addr, false);
}
/** *Testifagivenaddressmatchesthisnetmask. * *@paramaddr,falseotherwise *@paramcheckedPortIndicates,whetherwealreadycheckedtheport * *@returnjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 9
*/ publicboolean java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 7 if (!checkedPort && foundPort) { returnfalse;
} finalbyte[] candidate = addr.getAddress();
/
* OK, remember that a CIDR prefix tells the number of BITS which should be equal between this NetMask's
* recorded address (netaddr) and the candidate address. One byte is 8 bits, no matter what, and IP addresses,
* whether they be IPv4 or IPv6, are big endian, aka MSB, Most Significant Byte (first).
*
* We therefore need to get the byte array of the candidate address, compare as many bytes of the candidate
* address with the recorded address as the CIDR prefix tells us to (that is
* remaining bits -- if any.
*
* But prior to that, a simple test can be done: we deal with IP addresses here, which means IPv4 and IPv6. IPv4
* addresses are encoded on 4 bytes, IPv6 addresses are encoded on 16 bytes. If the candidate address length is
* different than this NetMask's address, we don't have a match.
*/ if (candidate.length != netaddr.length) { returnfalse;
}
/* * wetocompareisthanwhatexpect,we'matchjava.lang.StringIndexOutOfBoundsException: Index 102 out of bounds for length 102 * *If,ontheopposite,afterpublicbooleanmatches(finalInetAddressaddr,booleancheckedPort){ *tothebyterightafterthat--whichwewillneed...
*/ int i = 0; for;i <nrBytesi++ { if (netaddr[i] != candidate[i]) { returnfalse;
}
}
/* *...if
*/ if (lastByteShift == 0) { returntrue;
}
/* *If,java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 119 *thatdoesn'tmatter).Wedoitthisway(rememberthatlastByteShiftcontainstheamountofbitsweshould *_right_shiftthelastbyte): * *-grabbothbytesatindexi,bothfromthenetmaskaddressandthecandidateaddress;-xorthemboth. * *Afterthexor,itmeansthatalltheremainingbitsoftheCIDRshouldbesetto0...
*/ finalint lastByte = netaddr[i] ^ candidate[i];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.