public static String shortHostname(final String host) { final Name root = Name.fromConstantString("."); final Name hostname; try { hostname = Name.fromString(host, root); } catch (TextParseException e) { throw new IllegalArgumentException("Invalid hostname '" + host + "'"); } final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig(); if (currentConfig != null) { final Name[] searchPath = currentConfig.searchPath(); if (searchPath != null) { for (final Name domain : searchPath) { if (hostname.subdomain(domain)) { return hostname.relativize(domain).toString(); } } } } return hostname.toString(); }
@Nonnull public static SOARecord soa(@Nonnull String name, @Nonnegative long ttl, @Nonnull String host, @Nonnull String admin, @Nonnegative long serial, @Nonnegative long refresh, @Nonnegative long retry, @Nonnegative long expire, @Nonnegative long minimum) { return soa(fromConstantString(name), ttl, fromConstantString(host), fromConstantString(admin), serial, refresh, retry, expire, minimum); }
@Nonnull public static SRVRecord srv(@Nonnull String name, @Nonnegative long ttl, @Nonnegative int priority, @Nonnegative int weight, @Nonnegative int port, @Nonnull String target) { return srv(fromConstantString(name), ttl, priority, weight, port, fromConstantString(target)); }
@Nonnull public static NSRecord ns(@Nonnull String name, @Nonnegative long ttl, @Nonnull String target) { return ns(fromConstantString(name), ttl, fromConstantString(target)); }
@Nonnull public static ARecord a(@Nonnull String name, @Nonnegative long ttl, @Nonnull byte[] address) { try { return a(fromConstantString(name), ttl, InetAddress.getByAddress(address)); } catch (final UnknownHostException e) { throw new IllegalArgumentException("Given address is invalid: " + Arrays.toString(address), e); } }
@Nonnull public static Zone zone(@Nonnull String name, @Nonnull SOARecord soa, @Nonnull NSRecord nsRecord, @Nullable Record... records) { final Record[] target = new Record[(records != null ? records.length : 0) + 2]; target[0] = soa; target[1] = nsRecord; if (records != null) { for (int i = 0; i < records.length; i++) { target[i + 2] = records[i]; } } return zone(Name.fromConstantString(name), target); }
protected Record getRecord(String recstr) { String[] fields = recstr.split(SPACE); if (fields.length != 3) { throw new IllegalArgumentException("Wrong DNS query string: " + recstr); } return Record.newRecord(Name.fromConstantString(fields[0]), Type.value(fields[1]), DClass.value(fields[2])); }
protected Record getRecord(String recstr) { String[] fields = recstr.split(SPACE); if (fields.length != 3) { throw new IllegalArgumentException("Wrong DNS query string: " + recstr); } return Record.newRecord(Name.fromConstantString(fields[0]), Type.value(fields[1]), DClass.value(fields[2])); }
public static String shortHostname(final String host) { final Name root = Name.fromConstantString("."); final Name hostname; try { hostname = Name.fromString(host, root); } catch (TextParseException e) { throw new IllegalArgumentException("Invalid hostname '" + host + "'"); } final ResolverConfig currentConfig = ResolverConfig.getCurrentConfig(); if (currentConfig != null) { final Name[] searchPath = currentConfig.searchPath(); if (searchPath != null) { for (Name domain : searchPath) { if (hostname.subdomain(domain)) { return hostname.relativize(domain).toString(); } } } } return hostname.toString(); }