本文整理匯總了Java中org.xbill.DNS.Name.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Name.toString方法的具體用法?Java Name.toString怎麽用?Java Name.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xbill.DNS.Name
的用法示例。
在下文中一共展示了Name.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handle_dns_packet
import org.xbill.DNS.Name; //導入方法依賴的package包/類
public static ByteBuffer handle_dns_packet(Packet packet) {
if (DOMAINS_IP_MAPS == null) {
Log.d(TAG, "DOMAINS_IP_MAPS IS NULL HOST FILE ERROR");
return null;
}
try {
ByteBuffer packet_buffer=packet.backingBuffer;
packet_buffer.mark();
byte[] tmp_bytes = new byte[packet_buffer.remaining()];
packet_buffer.get(tmp_bytes);
packet_buffer.reset();
Message message = new Message(tmp_bytes);
Name query_domain = message.getQuestion().getName();
String query_string = query_domain.toString();
Log.d(TAG, "query: " + query_domain);
if (!DOMAINS_IP_MAPS.containsKey(query_string)) {
query_string="."+query_string;
int j=0;
while (true){
int i=query_string.indexOf(".",j);
if (i==-1){
return null;
}
String str=query_string.substring(i);
if("".equals(str)){
return null;
}
if(DOMAINS_IP_MAPS.containsKey(str)){
query_string=str;
break;
}
j=i+1;
}
}
InetAddress address = Address.getByAddress(DOMAINS_IP_MAPS.get(query_string));
ARecord a_record = new ARecord(query_domain, 1, 86400, address);
message.addRecord(a_record, 1);
message.getHeader().setFlag(Flags.QR);
packet_buffer.limit(packet_buffer.capacity());
packet_buffer.put(message.toWire());
packet_buffer.limit(packet_buffer.position());
packet_buffer.reset();
packet.swapSourceAndDestination();
packet.updateUDPBuffer(packet_buffer, packet_buffer.remaining());
packet_buffer.position(packet_buffer.limit());
Log.d(TAG, "hit: " + query_domain.toString() + " " + address.getHostName());
return packet_buffer;
} catch (Exception e) {
Log.d(TAG, "dns hook error", e);
return null;
}
}
示例2: name2string
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private static String name2string(Name name) {
String s = name.toString();
if (s.charAt(s.length() - 1) == '.')
s = s.substring(0, s.length() - 1);
return s;
}