Skip to content

Commit 4902862

Browse files
committed
Fix conversion of IPv4/IPv6 bindata to strings
The documentation mentions taking care of bindata (buffers in node), such as IPv4 and IPV6 addresses, and converting them to easy-to-use javascript strings where possible. This was apparently not happening for at least `just_address_answers`, due to a small bug in the `getdns_dict_to_ip_string()` function. The tests were written to match the buffer output, so this documentation mismatch/bug was not detected. This fixes getdnsapi#16 and should align the documentation and the code.
1 parent caf72d0 commit 4902862

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Bindatas are converted to strings when possible:
133133
- printable bindata
134134
- wire format dname
135135

136-
All other bindata objects are converted into Node.js buffers (represented below as <node buffer>)
136+
All other bindata objects are converted into Node.js buffers (represented below as `<node buffer>`)
137137

138138
Also see the output of the examples:
139139

src/GNUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ char* getdns_dict_to_ip_string(getdns_dict* dict) {
355355
if (r != GETDNS_RETURN_GOOD) {
356356
return NULL;
357357
}
358-
if (data->size == 5 &&
358+
if (data->size == 4 &&
359359
(strcmp("IPv4", (char*) data->data) == 0 ||
360360
strcmp("IPv6", (char*) data->data) == 0)) {
361361
r = getdns_dict_get_bindata(dict, "address_data", &data);

test/test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ it:false,
3333
"use strict";
3434

3535
// Requires.
36+
const net = require("net");
3637
const expect = require("expect.js");
3738
const getdns = require("../");
3839
const async = require("async");
@@ -83,9 +84,9 @@ describe("getdns test", () => {
8384
expect(result).to.be.ok();
8485
expect(result.just_address_answers).to.be.an(Array);
8586
expect(result.just_address_answers).to.not.be.empty();
86-
result.just_address_answers.map((r) => {
87-
expect(r.address_type).to.be.an("string");
88-
expect(r.address_data).to.be.an(Buffer);
87+
result.just_address_answers.map((address) => {
88+
expect(address).to.be.an("string");
89+
expect(net.isIP(address)).to.be.ok();
8990
});
9091
finish(ctx, done);
9192
});

0 commit comments

Comments
 (0)