Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add A & AAAA record support #12

Merged
merged 4 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add A and AAAA records support
  • Loading branch information
jlucidar committed May 4, 2016
commit 6533c3d33e4bbf31e16fc06a782226f80f7aac8c
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
}
}