org.xbill.DNS.Address类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(251)

本文整理了Java中org.xbill.DNS.Address类的一些代码示例,展示了Address类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address类的具体详情如下:
包路径:org.xbill.DNS.Address
类名称:Address

Address介绍

暂无

代码示例

代码示例来源:origin: dnsjava/dnsjava

/**
 * Determines the IP address of a host
 * @param name The hostname to look up
 * @return The first matching IP address
 * @exception UnknownHostException The hostname does not have any addresses
 */
public static InetAddress
getByName(String name) throws UnknownHostException {
  try {
    return getByAddress(name);
  } catch (UnknownHostException e) {
    Record [] records = lookupHostName(name, false);
    return addrFromRecord(name, records[0]);
  }
}

代码示例来源:origin: internetarchive/heritrix3

if (address == null) {
  address = Address.getByName(host);

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

/**
 * Determines if a string contains a valid IP address.
 * @param s The string
 * @return Whether the string contains a valid IP address
 */
public static boolean
isDottedQuad(String s) {
  byte [] address = Address.toByteArray(s, IPv4);
  return (address != null);
}

代码示例来源:origin: dnsjava/dnsjava

/**
 * Convert a string containing an IP address to an array of 4 or 16 bytes.
 * @param s The address, in text format.
 * @param family The address family.
 * @return The address
 */
public static byte []
toByteArray(String s, int family) {
  if (family == IPv4)
    return parseV4(s);
  else if (family == IPv6)
    return parseV6(s);
  else
    throw new IllegalArgumentException("unknown address family");
}

代码示例来源:origin: OpenNMS/opennms

protected void initializeDefaults() throws UnknownHostException {
  if (m_ports.size() == 0) {
    m_ports.add(Integer.valueOf(53));
  }
  if (m_addresses.size() == 0) {
    m_addresses.add(Address.getByAddress("0.0.0.0"));
  }
}

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

/**
 * Creates an APL element corresponding to an IPv4 or IPv6 prefix.
 * @param negative Indicates if this prefix is a negation.
 * @param address The IPv4 or IPv6 address.
 * @param prefixLength The length of this prefix, in bits.
 * @throws IllegalArgumentException The prefix length is invalid.
 */
public
Element(boolean negative, InetAddress address, int prefixLength) {
  this(Address.familyOf(address), negative, address,
     prefixLength);
}

代码示例来源: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: dnsjava/dnsjava

/**
 * Construct a Client Subnet option.  Note that the number of significant bits
 * in the address must not be greater than the supplied source netmask.  There
 * may also be issues related to Java's handling of mapped addresses
 * @param sourceNetmask The length of the netmask pertaining to the query.
 * In replies, it mirrors the same value as in the requests.
 * @param scopeNetmask The length of the netmask pertaining to the reply.
 * In requests, it MUST be set to 0.  In responses, this may or may not match
 * the source netmask.
 * @param address The address of the client.
 */
public 
ClientSubnetOption(int sourceNetmask, int scopeNetmask, InetAddress address) {
  super(EDNSOption.Code.CLIENT_SUBNET);

  this.family = Address.familyOf(address);
  this.sourceNetmask = checkMaskLength("source netmask", this.family,
             sourceNetmask);
  this.scopeNetmask = checkMaskLength("scope netmask", this.family,
             scopeNetmask);
  this.address = Address.truncate(address, sourceNetmask);

  if (!address.equals(this.address))
    throw new IllegalArgumentException("source netmask is not " +
              "valid for address");
}

代码示例来源: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);
InetAddress tmp = Address.truncate(address, sourceNetmask);
if (!tmp.equals(address))
  throw new WireParseException("invalid padding");

代码示例来源: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: dnsjava/dnsjava

/**
 * Convert a string containing an IPv4 address to an array of 4 integers.
 * @param s The address, in text format.
 * @return The address
 */
public static int []
toArray(String s) {
  return toArray(s, IPv4);
}

代码示例来源:origin: dnsjava/dnsjava

/**
 * Gets the next token from a tokenizer and converts it to an IP Address.
 * @param family The address family.
 * @return The next token in the stream, as an InetAddress
 * @throws TextParseException The input was invalid or not a valid address.
 * @throws IOException An I/O error occurred.
 * @see Address
 */
public InetAddress
getAddress(int family) throws IOException {
  String next = _getIdentifier("an address");
  try {
    return Address.getByAddress(next, family);
  }
  catch (UnknownHostException e) {
    throw exception(e.getMessage());
  }
}

代码示例来源:origin: dnsjava/dnsjava

/**
 * Creates an APL element corresponding to an IPv4 or IPv6 prefix.
 * @param negative Indicates if this prefix is a negation.
 * @param address The IPv4 or IPv6 address.
 * @param prefixLength The length of this prefix, in bits.
 * @throws IllegalArgumentException The prefix length is invalid.
 */
public
Element(boolean negative, InetAddress address, int prefixLength) {
  this(Address.familyOf(address), negative, address,
     prefixLength);
}

代码示例来源:origin: org.littleshoot/dnsjava

/**
 * Convert a string containing an IP address to an array of 4 or 16 bytes.
 * @param s The address, in text format.
 * @param family The address family.
 * @return The address
 */
public static byte []
toByteArray(String s, int family) {
  if (family == IPv4)
    return parseV4(s);
  else if (family == IPv6)
    return parseV6(s);
  else
    throw new IllegalArgumentException("unknown address family");
}

代码示例来源: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

/**
 * Construct a Client Subnet option.  Note that the number of significant bits in
 * the address must not be greater than the supplied source netmask.
 * XXX something about Java's mapped addresses
 * @param sourceNetmask The length of the netmask pertaining to the query.
 * In replies, it mirrors the same value as in the requests.
 * @param scopeNetmask The length of the netmask pertaining to the reply.
 * In requests, it MUST be set to 0.  In responses, this may or may not match
 * the source netmask.
 * @param address The address of the client.
 */
public 
ClientSubnetOption(int sourceNetmask, int scopeNetmask, InetAddress address) {
  super(Code.CLIENT_SUBNET);

  this.family = Address.familyOf(address);
  this.sourceNetmask = checkMaskLength("source netmask", this.family,
             sourceNetmask);
  this.scopeNetmask = checkMaskLength("scope netmask", this.family,
             scopeNetmask);
  this.address = Address.truncate(address, sourceNetmask);

  if (!address.equals(this.address))
    throw new IllegalArgumentException("source netmask is not " +
              "valid for 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);
InetAddress tmp = Address.truncate(address, sourceNetmask);
if (!tmp.equals(address))
  throw new WireParseException("invalid padding");

代码示例来源: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

/**
 * Convert a string containing an IPv4 address to an array of 4 integers.
 * @param s The address, in text format.
 * @return The address
 */
public static int []
toArray(String s) {
  return toArray(s, IPv4);
}

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

/**
 * Determines the IP address of a host
 * @param name The hostname to look up
 * @return The first matching IP address
 * @exception UnknownHostException The hostname does not have any addresses
 */
public static InetAddress
getByName(String name) throws UnknownHostException {
  try {
    return getByAddress(name);
  } catch (UnknownHostException e) {
    Record [] records = lookupHostName(name);
    return addrFromRecord(name, records[0]);
  }
}

相关文章