summaryrefslogtreecommitdiff
path: root/lib/dns.js
blob: dd3770e0fe486fb9ecafaa2cdf02987176e85505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
process.binding('dns');

exports.resolve = function (domain, type_, callback_) {
  var type, callback;
  if (typeof(type_) == 'string') {
    type = type_;
    callback = callback_;
  } else {
    type = 'A';
    callback = arguments[1];
  }

  var resolveFunc = resolveMap[type];

  if (typeof(resolveFunc) == 'function') {
    resolveFunc(domain, callback);
  } else {
    throw new Error('Unknown type "' + type + '"');
  }
}

exports.resolve4    = process.dns.resolve4;
exports.resolve6    = process.dns.resolve6;
exports.resolveMx   = process.dns.resolveMx;
exports.resolveTxt  = process.dns.resolveTxt;
exports.resolveSrv  = process.dns.resolveSrv;
exports.reverse     = process.dns.reverse;

// ERROR CODES

// timeout, SERVFAIL or similar.
exports.TEMPFAIL = process.dns.TEMPFAIL;

// got garbled reply.
exports.PROTOCOL = process.dns.PROTOCOL;

// domain does not exists.
exports.NXDOMAIN = process.dns.NXDOMAIN;

// domain exists but no data of reqd type.
exports.NODATA = process.dns.NODATA;

// out of memory while processing.
exports.NOMEM = process.dns.NOMEM;

// the query is malformed.
exports.BADQUERY = process.dns.BADQUERY;

var resolveMap = {
  'A': exports.resolve4,
  'AAAA': exports.resolve6,
  'MX': exports.resolveMx,
  'TXT': exports.resolveTxt,
  'SRV': exports.resolveSrv,
  'PTR': exports.reverse,
};