Skip to content

Commit

Permalink
add A and AAAA records support
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucidar committed May 4, 2016
1 parent 1e9c12e commit 6533c3d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/mdns-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Server.prototype._respondToQuery = function (query) {
additionals = additionals
.concat(self._recordsFor(answer.data, 'SRV'))
.concat(self._recordsFor(answer.data, 'TXT'))
.concat(self._recordsFor(answer.data, 'A'))
.concat(self._recordsFor(answer.data, 'AAAA'))
})
}

Expand All @@ -83,7 +85,8 @@ Server.prototype._recordsFor = function (name, type) {
if (name) {
return self.registry[type].filter(function (record) {
var _name = ~name.indexOf('.') ? record.name : record.name.split('.')[0]
return dnsEqual(_name, name)
var host = (record.type==='A' || record.type==='AAAA');
return dnsEqual(_name, name) || host; // the A or AAAA name match the host name, not the service name
})
} else {
return self.registry[type]
Expand Down
32 changes: 31 additions & 1 deletion lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ function Service (opts) {
}

Service.prototype._records = function () {
return [rr_ptr(this), rr_srv(this), rr_txt(this)]
var records = [rr_ptr(this), rr_srv(this), rr_txt(this)];
var self = this;
var networks_list = os.networkInterfaces();
Object.keys(networks_list).forEach(function(itr_idx,index,arr){//itr_idx = interface name
networks_list[itr_idx].forEach(function(itr,index2,arr2){ // for each interface (itr)
if (itr.internal === false && itr.family === 'IPv4'){
records.push(rr_a(self,itr.address));
}else if(itr.internal === false && itr.family === 'IPv6'){
records.push(rr_aaaa(self,itr.address));
}
});
});
return records;
}

function rr_ptr (service) {
Expand Down Expand Up @@ -63,3 +75,21 @@ function rr_txt (service) {
data: txt.encode(service.txt)
}
}

function rr_a (service,ip_address) {
return {
name: service.fqdn,
type: 'A',
ttl: 120,
data: ip_address
}
}

function rr_aaaa (service,ip_address) {
return {
name: service.fqdn,
type: 'AAAA',
ttl: 120,
data: ip_address
}
}

0 comments on commit 6533c3d

Please sign in to comment.