Conversation
patrick-ogrady
approved these changes
Aug 13, 2018
zbjornson
reviewed
Aug 15, 2018
| address = '0.0.0.0'; | ||
| } | ||
|
|
||
| let fam = '' |
There was a problem hiding this comment.
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:
Lines 57 to 62 in 2b1adaa
edit 2 #26 and #29 make an equivalent fix using the net module.
|
|
||
| var src = { | ||
| family: 'udp6', | ||
| family: fam, |
There was a problem hiding this comment.
(I think this will match the socket's type, but you could also make this rinfo.family === "IPv6" ? 'udp6' : "udp4".)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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