Skip to content

Conversation

@mkg20001
Copy link

@mkg20001 mkg20001 commented Jun 2, 2018

By default an IPv6-only socket is created which makes it impossible to use this server with IPv4 hosts.
I've added a bit of code that checks the IP version via regex and creates the appropriate socket for it

address = '0.0.0.0';
}

let fam = ''
Copy link

@zbjornson zbjornson Aug 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node.js's "net" module (since v0.3.0) has this ability built in, no need for the regexes:

const net = require("net");
const ipversion = net.isIP(address);
if (ipversion === 0) throw new TypeError("address is neither valid v4 or v6");
const fam = ipversion === 4 ? "udp4" : "upd6";

https://nodejs.org/api/net.html#net_net_isip_input


edit This library already uses that actually:

IPv4: function(v) {
return net.isIPv4(v);
},
IPv6: function(v) {
return net.isIPv6(v);
},


edit 2 #26 and #29 make an equivalent fix using the net module.


var src = {
family: 'udp6',
family: fam,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think this will match the socket's type, but you could also make this rinfo.family === "IPv6" ? 'udp6' : "udp4".)

@eqyiel eqyiel mentioned this pull request Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants