Skip to content
This repository
Browse code

Packet.address for remote address fixes #16

  • Loading branch information...
commit 1dcdd3513c69cab6f12fc538da0844cf6c76d533 1 parent 03de61f
Timothy J Fontaine authored January 09, 2013
1  lib/packet.js
@@ -46,6 +46,7 @@ var Packet = module.exports = function(socket) {
46 46
   this.additional = [];
47 47
   this.edns_options = [];
48 48
   this.payload = undefined;
  49
+  this.address = undefined;
49 50
 
50 51
   this._socket = socket;
51 52
 };
9  lib/server.js
@@ -53,12 +53,14 @@ Server.prototype.address = function() {
53 53
   return this._socket.address();
54 54
 };
55 55
 
56  
-Server.prototype.handleMessage = function(msg, remote) {
  56
+Server.prototype.handleMessage = function(msg, remote, address) {
57 57
   var request, response = new Packet(remote);
58 58
 
59 59
   try {
60 60
     request = Packet.parse(msg, remote);
61 61
 
  62
+    request.address = address;
  63
+
62 64
     response.header.id = request.header.id;
63 65
     response.header.qr = 1;
64 66
     response.question = request.question;
@@ -75,7 +77,7 @@ var UDPServer = function(opts) {
75 77
   this._socket = dgram.createSocket(opts.dgram_type || 'udp4');
76 78
 
77 79
   this._socket.on('message', function(msg, remote) {
78  
-    self.handleMessage(msg, new UDPSocket(self._socket, remote));
  80
+    self.handleMessage(msg, new UDPSocket(self._socket, remote), remote);
79 81
   });
80 82
 
81 83
   Server.call(this, opts);
@@ -91,8 +93,9 @@ var TCPServer = function(opts) {
91 93
 
92 94
   this._socket = net.createServer(function(client) {
93 95
     var tcp = new TCPSocket(client);
  96
+    var address = client.address();
94 97
     tcp.on('message', function(msg, remote) {
95  
-      self.handleMessage(msg, tcp);
  98
+      self.handleMessage(msg, tcp, address);
96 99
     });
97 100
     tcp.catchMessages();
98 101
   });

0 notes on commit 1dcdd35

Please sign in to comment.
Something went wrong with that request. Please try again.