public String toString() { StringBuffer buf = new StringBuffer(); buf.append("local host info["); buf.append(getName() != null ? getName() : "no name"); buf.append(", "); buf.append(getInterface() != null ? getInterface().getDisplayName() : "???"); buf.append(":"); buf.append(getAddress() != null ? getAddress().getHostAddress() : "no address"); buf.append("]"); return buf.toString(); }
DNSRecord.Address getDNSAddressRecord(DNSRecord.Address address) { return (DNSConstants.TYPE_AAAA == address.type ? getDNS6AddressRecord() : getDNS4AddressRecord()); }
DNSRecord.Address getDNS6AddressRecord() { if ((getAddress() != null) && (getAddress() instanceof Inet6Address)) { return new DNSRecord.Address(getName(), DNSConstants.TYPE_AAAA, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, getAddress()); } return null; }
if (localHost.getName().equalsIgnoreCase(q.getName())) DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null) DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) DNSRecord answer = localHost.getDNS6AddressRecord(); if (answer != null) DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null) answers.add(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, localHost.getName())); answers.add(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL, info.text)); DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null)
/** * Does the necessary actions, when this as a response. */ boolean handleResponse(JmDNS dns) { DNSRecord.Address dnsAddress = dns.getLocalHost().getDNSAddressRecord(this); if (dnsAddress != null) { if (dnsAddress.sameType(this) && dnsAddress.sameName(this) && (!dnsAddress.sameValue(this))) { logger.finer("handleResponse() Denial detected"); if (dns.getState().isProbing()) { dns.getLocalHost().incrementHostName(); dns.getCache().clear(); for (Iterator i = dns.services.values().iterator(); i.hasNext();) { ServiceInfo info = (ServiceInfo) i.next(); info.revertState(); } } dns.revertState(); return true; } } return false; }
/** * Return the HostName associated with this JmDNS instance. * Note: May not be the same as what started. The host name is subject to * negotiation. */ public String getHostName() { return localHost.getName(); }
boolean shouldIgnorePacket(DatagramPacket packet) { boolean result = false; if (getAddress() != null) { InetAddress from = packet.getAddress(); if (from != null) { if (from.isLinkLocalAddress() && (!getAddress().isLinkLocalAddress())) { // Ignore linklocal packets on regular interfaces, unless this is // also a linklocal interface. This is to avoid duplicates. This is // a terrible hack caused by the lack of an API to get the address // of the interface on which the packet was received. result = true; } if (from.isLoopbackAddress() && (!getAddress().isLoopbackAddress())) { // Ignore loopback packets on a regular interface unless this is // also a loopback interface. result = true; } } } return result; }
private void openMulticastSocket(HostInfo hostInfo) throws IOException { if (group == null) { group = InetAddress.getByName(DNSConstants.MDNS_GROUP); } if (socket != null) { this.closeMulticastSocket(); } socket = new MulticastSocket(DNSConstants.MDNS_PORT); if ((hostInfo != null) && (localHost.getInterface() != null)) { socket.setNetworkInterface(hostInfo.getInterface()); } socket.setTimeToLive(255); socket.joinGroup(group); }
localHost = new HostInfo(address, name);
if (localHost.shouldIgnorePacket(packet))
out.addAnswer(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, ttl, info.priority, info.weight, info.port, localHost.getName()), 0); out.addAnswer(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN, ttl, info.text), 0); DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null)
DNSRecord.Address getDNS4AddressRecord() { if ((getAddress() != null) && ((getAddress() instanceof Inet4Address) || ((getAddress() instanceof Inet6Address) && (((Inet6Address) getAddress()).isIPv4CompatibleAddress())))) { return new DNSRecord.Address(getName(), DNSConstants.TYPE_A, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, getAddress()); } return null; }
/** * Does the necessary actions, when this as a query. */ boolean handleQuery(JmDNS dns, long expirationTime) { DNSRecord.Address dnsAddress = dns.getLocalHost().getDNSAddressRecord(this); if (dnsAddress != null) { if (dnsAddress.sameType(this) && dnsAddress.sameName(this) && (!dnsAddress.sameValue(this))) { logger.finer("handleQuery() Conflicting probe detected. dns state " + dns.getState() + " lex compare " + lexCompare(dnsAddress)); // Tie-breaker test if (dns.getState().isProbing() && lexCompare(dnsAddress) >= 0) { // We lost the tie-break. We have to choose a different name. dns.getLocalHost().incrementHostName(); dns.getCache().clear(); for (Iterator i = dns.services.values().iterator(); i.hasNext();) { ServiceInfo info = (ServiceInfo) i.next(); info.revertState(); } } dns.revertState(); return true; } } return false; }
DNSOutgoing addAnswer(JmDNS dns, DNSIncoming in, InetAddress addr, int port, DNSOutgoing out) throws IOException { ServiceInfo info = (ServiceInfo) dns.services.get(name.toLowerCase()); if (info != null) { if (this.port == info.port != server.equals(dns.getLocalHost().getName())) { return dns.addAnswer(in, addr, port, out, new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, dns.getLocalHost().getName())); } } return out; }
out.addQuestion(new DNSQuestion(localHost.getName(), DNSConstants.TYPE_ANY, DNSConstants.CLASS_IN)); DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null) out.addQuestion(new DNSQuestion(info.getQualifiedName(), DNSConstants.TYPE_ANY, DNSConstants.CLASS_IN)); out.addAuthorativeAnswer(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, localHost.getName()));
info.server = localHost.getName(); info.addr = localHost.getAddress();
|| q.type == DNSConstants.TYPE_A || q.type == DNSConstants.TYPE_AAAA || localHost.getName().equalsIgnoreCase(q.name) || services.containsKey(q.name.toLowerCase())); if (!iAmTheOnlyOne)
DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null) out.addAnswer(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, localHost.getName()), 0); out.addAnswer(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.text), 0);
boolean handleResponse(JmDNS dns) { ServiceInfo info = (ServiceInfo) dns.services.get(name.toLowerCase()); if (info != null && (port != info.port || !server.equalsIgnoreCase(dns.getLocalHost().getName()))) { logger.finer("handleResponse() Denial detected"); if (info.getState().isProbing()) { String oldName = info.getQualifiedName().toLowerCase(); info.setName(dns.incrementName(info.getName())); dns.services.remove(oldName); dns.services.put(info.getQualifiedName().toLowerCase(), info); logger.finer("handleResponse() New unique name chose:" + info.getName()); } info.revertState(); return true; } return false; }
DNSRecord answer = localHost.getDNS4AddressRecord(); if (answer != null) answer = localHost.getDNS6AddressRecord(); if (answer != null) out.addAnswer(new DNSRecord.Service(info.getQualifiedName(), DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, localHost.getName()), 0); out.addAnswer(new DNSRecord.Text(info.getQualifiedName(), DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.text), 0);