Skip to content
Permalink
Browse files

Allow escape of dot in instance name (#179)

* Allow escape of dot in instance name

Allow dots in service names as per rfc 6763. According to rfc6763 instance names are allowed to contain any characters, including dots. They recommend escaping them if concatenating all the parts internally. See section 4.3

Signed-off-by: mattias <mattias.bergander@gmail.com>
  • Loading branch information...
mattiasbe authored and kaikreuzer committed Apr 11, 2019
1 parent 7d9f730 commit d15acaf8ad5f11fc6a1dfa597e3e36803a332dbd
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/main/java/javax/jmdns/impl/DNSOutgoing.java
@@ -117,15 +117,15 @@ void writeName(String name) {
void writeName(String name, boolean useCompression) {
String aName = name;
while (true) {
int n = aName.indexOf('.');
int n = indexOfSeparator(aName);
if (n < 0) {
n = aName.length();
}
if (n <= 0) {
writeByte(0);
return;
}
String label = aName.substring(0, n);
String label = aName.substring(0, n).replace("\\.", ".");
if (useCompression && USE_DOMAIN_NAME_COMPRESSION) {
Integer offset = _out._names.get(aName);
if (offset != null) {
@@ -146,6 +146,22 @@ void writeName(String name, boolean useCompression) {
}
}

private static int indexOfSeparator(String aName) {
int offset = 0;
int n = 0;

while (true) {
n = aName.indexOf('.', offset);
if (n < 0)
return -1;

if (n == 0 || aName.charAt(n - 1) != '\\')
return n;

offset = n + 1;
}
}

void writeQuestion(DNSQuestion question) {
writeName(question.getName());
writeShort(question.getRecordType().indexValue());

0 comments on commit d15acaf

Please sign in to comment.
You can’t perform that action at this time.