Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Packet.address for remote address fixes #16

  • Loading branch information...
commit 1dcdd3513c69cab6f12fc538da0844cf6c76d533 1 parent 03de61f
@tjfontaine authored
Showing with 7 additions and 3 deletions.
  1. +1 −0  lib/packet.js
  2. +6 −3 lib/server.js
View
1  lib/packet.js
@@ -46,6 +46,7 @@ var Packet = module.exports = function(socket) {
this.additional = [];
this.edns_options = [];
this.payload = undefined;
+ this.address = undefined;
this._socket = socket;
};
View
9 lib/server.js
@@ -53,12 +53,14 @@ Server.prototype.address = function() {
return this._socket.address();
};
-Server.prototype.handleMessage = function(msg, remote) {
+Server.prototype.handleMessage = function(msg, remote, address) {
var request, response = new Packet(remote);
try {
request = Packet.parse(msg, remote);
+ request.address = address;
+
response.header.id = request.header.id;
response.header.qr = 1;
response.question = request.question;
@@ -75,7 +77,7 @@ var UDPServer = function(opts) {
this._socket = dgram.createSocket(opts.dgram_type || 'udp4');
this._socket.on('message', function(msg, remote) {
- self.handleMessage(msg, new UDPSocket(self._socket, remote));
+ self.handleMessage(msg, new UDPSocket(self._socket, remote), remote);
});
Server.call(this, opts);
@@ -91,8 +93,9 @@ var TCPServer = function(opts) {
this._socket = net.createServer(function(client) {
var tcp = new TCPSocket(client);
+ var address = client.address();
tcp.on('message', function(msg, remote) {
- self.handleMessage(msg, tcp);
+ self.handleMessage(msg, tcp, address);
});
tcp.catchMessages();
});
Please sign in to comment.
Something went wrong with that request. Please try again.