Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/ndns.js');
44 changes: 22 additions & 22 deletions lib/ndns.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var sys = require('sys');
var util = require('util');

var debug;
var debugLevel = parseInt(process.env.NODE_DEBUG, 16);
if(debugLevel & 0x4) {
debug = function (x) { sys.error('NDNS: ' + x); };
debug = function (x) { util.error('NDNS: ' + x); };
} else {
debug = function () { };
}
Expand All @@ -30,14 +30,14 @@ var ns_in6addrsz = 16; // IPv6 T_AAAA
var ns_cmprsflgs = 0xc0;// Flag bits indicating name compression.
var ns_defaultport = 53;// For both UDP and TCP.

function enum (obj) {
function _enum (obj) {
for (key in obj) {
global[key] = obj[key];
}
return obj;
}

var ns_sect = enum({
var ns_sect = _enum({
'ns_s_qd': 0, // Query: Question.
'ns_s_zn': 0, // Update: Zone.
'ns_s_an': 1, // Query: Answer.
Expand All @@ -48,7 +48,7 @@ var ns_sect = enum({
'ns_s_max': 4,
});

var ns_flag = enum({
var ns_flag = _enum({
'ns_f_qr': 0, // Question/Response.
'ns_f_opcode': 1, // Operation code.
'ns_f_aa': 2, // Authorative Answer.
Expand All @@ -63,7 +63,7 @@ var ns_flag = enum({
});

// Currently defined opcodes.
var ns_opcode = enum({
var ns_opcode = _enum({
'ns_o_query': 0, // Standard query.
'ns_o_iquery': 1, // Inverse query (deprecated/unsupported).
'ns_o_status': 2, // Name server status query (unsupported).
Expand All @@ -73,7 +73,7 @@ var ns_opcode = enum({
});

// Currently defined response codes
var ns_rcode = enum({
var ns_rcode = _enum({
'ns_r_noerror': 0, // No error occured.
'ns_r_formerr': 1, // Format error.
'ns_r_servfail': 2, // Server failure.
Expand All @@ -96,13 +96,13 @@ var ns_rcode = enum({
});

// BIND_UPDATE
var ns_update_operation = enum({
var ns_update_operation = _enum({
'ns_oup_delete': 0,
'ns_oup_add': 1,
'ns_oup_max': 2,
});

var NS_TSIG = enum({
var NS_TSIG = _enum({
'NS_TSIG_FUDGE': 300,
'NS_TSIG_TCP_COUNT': 100,
'NS_TSIG_ALG_HMAC_MD5': "HMAC-MD5.SIG-ALG.REG.INT",
Expand All @@ -113,7 +113,7 @@ var NS_TSIG = enum({
});

// Currently defined type values for resources and queries.
var ns_type = enum({
var ns_type = _enum({
'ns_t_invalid': 0, // Cookie.
'ns_t_a': 1, // Host address.
'ns_t_ns': 2, // Authoritative server.
Expand Down Expand Up @@ -182,7 +182,7 @@ var ns_type = enum({
exports.ns_type = ns_type;

// Values for class field
var ns_class = enum({
var ns_class = _enum({
'ns_c_invalid': 0, // Cookie.
'ns_c_in': 1, // Internet.
'ns_c_2': 2, // unallocated/unsupported.
Expand All @@ -196,14 +196,14 @@ var ns_class = enum({
exports.ns_class = ns_class;

// DNSSEC constants.
var ns_key_types = enum({
var ns_key_types = _enum({
'ns_kt_rsa': 1, // key type RSA/MD5
'ns_kt_dh': 2, // Diffie Hellman
'ns_kt_dsa': 3, // Digital Signature Standard (MANDATORY)
'ns_kt_private': 4 // Private key type starts with OID
});

var ns_cert_type = enum({
var ns_cert_type = _enum({
'cert_t_pkix': 1, // PKIX (X.509v3)
'cert_t_spki': 2, // SPKI
'cert_t_pgp': 3, // PGP
Expand Down Expand Up @@ -1176,7 +1176,7 @@ function DNSParser(buf, start, end) {
return;
}

if (!(buf instanceof Buffer)) {
if (!(Buffer.isBuffer(buf))) {
throw new Error("Argument should be a buffer");
}
if (start > buf.length) {
Expand Down Expand Up @@ -1367,8 +1367,8 @@ DNSParser.prototype.parseA = function () {
throw new Error();
this.parseStart += 4;
return [this.buf[this.parseStart-4],
this.buf[this.parseStart-3],
this.buf[this.parseStart-2],
this.buf[this.parseStart-1],
this.buf[this.parseStart-1]].join('.');
};

Expand Down Expand Up @@ -1959,7 +1959,7 @@ function Message (socket, rinfo) {
this.q = new MessageObject();
this.rr = new MessageObject();
}
sys.inherits(Message, events.EventEmitter);
util.inherits(Message, events.EventEmitter);
exports.Message = Message;

Message.prototype.addRR = function (name, ttl, className, typeName) {
Expand Down Expand Up @@ -2005,14 +2005,14 @@ Message.prototype.addQuestion = function (name, typeName, className) {
function IncomingMessage (socket, rinfo) {
Message.call(this, socket, rinfo);
};
sys.inherits(IncomingMessage, Message);
util.inherits(IncomingMessage, Message);
exports.IncomingMessage = IncomingMessage;

function OutgoingMessage (socket, rinfo) {
Message.call(this, socket, rinfo);
this.maxSend = 512;
}
sys.inherits(OutgoingMessage, Message);
util.inherits(OutgoingMessage, Message);
exports.OutgoingMessage = OutgoingMessage;

OutgoingMessage.prototype._Buffer = new Buffer(ns_maxmsg);
Expand Down Expand Up @@ -2045,7 +2045,7 @@ OutgoingMessage.prototype.send = function (message) {
function ServerResponse (req) {
OutgoingMessage.call(this, req.socket, req.rinfo);
}
sys.inherits(ServerResponse, OutgoingMessage);
util.inherits(ServerResponse, OutgoingMessage);
exports.ServerResponse = ServerResponse;

function ClientRequest(client, socket, port, host) {
Expand All @@ -2057,7 +2057,7 @@ function ClientRequest(client, socket, port, host) {
this.port = port;
this.host = host;
}
sys.inherits(ClientRequest, OutgoingMessage);
util.inherits(ClientRequest, OutgoingMessage);
exports.ClientRequest = ClientRequest;

ClientRequest.prototype.send = function (message) {
Expand Down Expand Up @@ -2091,7 +2091,7 @@ function Server(type, requestListener) {

this.on("message", messageListener);
};
sys.inherits(Server, dgram.Socket);
util.inherits(Server, dgram.Socket);
exports.Server = Server;

Server.prototype._Parser = parsers.alloc();
Expand Down Expand Up @@ -2141,7 +2141,7 @@ function Client(type, responseListener) {
this.on("message", clientMessageListener);
this.bind();
}
sys.inherits(Client, dgram.Socket);
util.inherits(Client, dgram.Socket);
exports.Client = Client;

Client.prototype.request = function (port, host) {
Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "ndns",
"description": "dns library for node.js",
"version": "0.1.2",
"homepage": "http://github.com/stefounet/ndns",
"repository": {
"type": "git",
"url": "http://github.com/stefounet/ndns.git"
},
"author": "tomas",
"directories": {
"lib": "lib"
},
"engines": {
"node": "*"
}
}