本文整理了Java中org.xbill.DNS.Address.addressLength()
方法的一些代码示例,展示了Address.addressLength()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.addressLength()
方法的具体详情如下:
包路径:org.xbill.DNS.Address
类名称:Address
方法名:addressLength
暂无
代码示例来源:origin: org.littleshoot/dnsjava
private static int
checkMaskLength(String field, int family, int val) {
int max = Address.addressLength(family) * 8;
if (val < 0 || val > max)
throw new IllegalArgumentException("\"" + field + "\" " + val +
" must be in the range " +
"[0.." + max + "]");
return val;
}
代码示例来源:origin: tiandawu/IotXmpp
private static int
checkMaskLength(String field, int family, int val) {
int max = Address.addressLength(family) * 8;
if (val < 0 || val > max)
throw new IllegalArgumentException("\"" + field + "\" " + val +
" must be in the range " +
"[0.." + max + "]");
return val;
}
代码示例来源:origin: dnsjava/dnsjava
private static int
checkMaskLength(String field, int family, int val) {
int max = Address.addressLength(family) * 8;
if (val < 0 || val > max)
throw new IllegalArgumentException("\"" + field + "\" " + val +
" must be in the range " +
"[0.." + max + "]");
return val;
}
代码示例来源:origin: org.littleshoot/dnsjava
/**
* Truncates an address to the specified number of bits. For example,
* truncating the address 10.1.2.3 to 8 bits would yield 10.0.0.0.
* @param address The source address
* @param maskLength The number of bits to truncate the address to.
*/
public static InetAddress
truncate(InetAddress address, int maskLength)
{
int family = familyOf(address);
int maxMaskLength = addressLength(family) * 8;
if (maskLength < 0 || maskLength > maxMaskLength)
throw new IllegalArgumentException("invalid mask length");
if (maskLength == maxMaskLength)
return address;
byte [] bytes = address.getAddress();
for (int i = maskLength / 8 + 1; i < bytes.length; i++)
bytes[i] = 0;
int maskBits = maskLength % 8;
int bitmask = 0;
for (int i = 0; i < maskBits; i++)
bitmask |= (1 << (7 - i));
bytes[maskLength / 8] &= bitmask;
try {
return InetAddress.getByAddress(bytes);
} catch (UnknownHostException e) {
throw new IllegalArgumentException("invalid address");
}
}
代码示例来源:origin: tiandawu/IotXmpp
/**
* Truncates an address to the specified number of bits. For example,
* truncating the address 10.1.2.3 to 8 bits would yield 10.0.0.0.
* @param address The source address
* @param maskLength The number of bits to truncate the address to.
*/
public static InetAddress
truncate(InetAddress address, int maskLength)
{
int family = familyOf(address);
int maxMaskLength = addressLength(family) * 8;
if (maskLength < 0 || maskLength > maxMaskLength)
throw new IllegalArgumentException("invalid mask length");
if (maskLength == maxMaskLength)
return address;
byte [] bytes = address.getAddress();
for (int i = maskLength / 8 + 1; i < bytes.length; i++)
bytes[i] = 0;
int maskBits = maskLength % 8;
int bitmask = 0;
for (int i = 0; i < maskBits; i++)
bitmask |= (1 << (7 - i));
bytes[maskLength / 8] &= bitmask;
try {
return InetAddress.getByAddress(bytes);
} catch (UnknownHostException e) {
throw new IllegalArgumentException("invalid address");
}
}
代码示例来源:origin: dnsjava/dnsjava
/**
* Truncates an address to the specified number of bits. For example,
* truncating the address 10.1.2.3 to 8 bits would yield 10.0.0.0.
* @param address The source address
* @param maskLength The number of bits to truncate the address to.
*/
public static InetAddress
truncate(InetAddress address, int maskLength)
{
int family = familyOf(address);
int maxMaskLength = addressLength(family) * 8;
if (maskLength < 0 || maskLength > maxMaskLength)
throw new IllegalArgumentException("invalid mask length");
if (maskLength == maxMaskLength)
return address;
byte [] bytes = address.getAddress();
for (int i = maskLength / 8 + 1; i < bytes.length; i++)
bytes[i] = 0;
int maskBits = maskLength % 8;
int bitmask = 0;
for (int i = 0; i < maskBits; i++)
bitmask |= (1 << (7 - i));
bytes[maskLength / 8] &= bitmask;
try {
return InetAddress.getByAddress(bytes);
} catch (UnknownHostException e) {
throw new IllegalArgumentException("invalid address");
}
}
代码示例来源:origin: tiandawu/IotXmpp
throw new WireParseException("unknown address family");
sourceNetmask = in.readU8();
if (sourceNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid source netmask");
scopeNetmask = in.readU8();
if (scopeNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid scope netmask");
byte [] fulladdr = new byte[Address.addressLength(family)];
System.arraycopy(addr, 0, fulladdr, 0, addr.length);
代码示例来源:origin: dnsjava/dnsjava
throw new WireParseException("unknown address family");
sourceNetmask = in.readU8();
if (sourceNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid source netmask");
scopeNetmask = in.readU8();
if (scopeNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid scope netmask");
byte [] fulladdr = new byte[Address.addressLength(family)];
System.arraycopy(addr, 0, fulladdr, 0, addr.length);
代码示例来源:origin: org.littleshoot/dnsjava
throw new WireParseException("unknown address family");
sourceNetmask = in.readU8();
if (sourceNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid source netmask");
scopeNetmask = in.readU8();
if (scopeNetmask > Address.addressLength(family) * 8)
throw new WireParseException("invalid scope netmask");
byte [] fulladdr = new byte[Address.addressLength(family)];
System.arraycopy(addr, 0, fulladdr, 0, addr.length);
代码示例来源:origin: org.littleshoot/dnsjava
void
rrFromWire(DNSInput in) throws IOException {
elements = new ArrayList(1);
while (in.remaining() != 0) {
int family = in.readU16();
int prefix = in.readU8();
int length = in.readU8();
boolean negative = (length & 0x80) != 0;
length &= ~0x80;
byte [] data = in.readByteArray(length);
Element element;
if (!validatePrefixLength(family, prefix)) {
throw new WireParseException("invalid prefix length");
}
if (family == Address.IPv4 || family == Address.IPv6) {
data = parseAddress(data,
Address.addressLength(family));
InetAddress addr = InetAddress.getByAddress(data);
element = new Element(negative, addr, prefix);
} else {
element = new Element(family, negative, data, prefix);
}
elements.add(element);
}
}
代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi
void
rrFromWire(DNSInput in) throws IOException {
elements = new ArrayList(1);
while (in.remaining() != 0) {
int family = in.readU16();
int prefix = in.readU8();
int length = in.readU8();
boolean negative = (length & 0x80) != 0;
length &= ~0x80;
byte [] data = in.readByteArray(length);
Element element;
if (!validatePrefixLength(family, prefix)) {
throw new WireParseException("invalid prefix length");
}
if (family == Address.IPv4 || family == Address.IPv6) {
data = parseAddress(data,
Address.addressLength(family));
InetAddress addr = InetAddress.getByAddress(data);
element = new Element(negative, addr, prefix);
} else {
element = new Element(family, negative, data, prefix);
}
elements.add(element);
}
}
代码示例来源:origin: tiandawu/IotXmpp
void
rrFromWire(DNSInput in) throws IOException {
elements = new ArrayList(1);
while (in.remaining() != 0) {
int family = in.readU16();
int prefix = in.readU8();
int length = in.readU8();
boolean negative = (length & 0x80) != 0;
length &= ~0x80;
byte [] data = in.readByteArray(length);
Element element;
if (!validatePrefixLength(family, prefix)) {
throw new WireParseException("invalid prefix length");
}
if (family == Address.IPv4 || family == Address.IPv6) {
data = parseAddress(data,
Address.addressLength(family));
InetAddress addr = InetAddress.getByAddress(data);
element = new Element(negative, addr, prefix);
} else {
element = new Element(family, negative, data, prefix);
}
elements.add(element);
}
}
代码示例来源:origin: dnsjava/dnsjava
void
rrFromWire(DNSInput in) throws IOException {
elements = new ArrayList(1);
while (in.remaining() != 0) {
int family = in.readU16();
int prefix = in.readU8();
int length = in.readU8();
boolean negative = (length & 0x80) != 0;
length &= ~0x80;
byte [] data = in.readByteArray(length);
Element element;
if (!validatePrefixLength(family, prefix)) {
throw new WireParseException("invalid prefix length");
}
if (family == Address.IPv4 || family == Address.IPv6) {
data = parseAddress(data,
Address.addressLength(family));
InetAddress addr = InetAddress.getByAddress(data);
element = new Element(negative, addr, prefix);
} else {
element = new Element(family, negative, data, prefix);
}
elements.add(element);
}
}
内容来源于网络,如有侵权,请联系作者删除!