-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: make isIPv4
and isIPv6
more efficient
#5478
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1087,6 +1087,27 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) { | |
args.GetReturnValue().Set(rc); | ||
} | ||
|
||
static void IsIPv4(const FunctionCallbackInfo<Value>& args) { | ||
node::Utf8Value ip(args.GetIsolate(), args[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a check that args[0] is a string here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe include a test passing |
||
char address_buffer[sizeof(struct in_addr)]; | ||
|
||
if (uv_inet_pton(AF_INET, *ip, &address_buffer) == 0) { | ||
args.GetReturnValue().Set(true); | ||
} else { | ||
args.GetReturnValue().Set(false); | ||
} | ||
} | ||
|
||
static void IsIPv6(const FunctionCallbackInfo<Value>& args) { | ||
node::Utf8Value ip(args.GetIsolate(), args[0]); | ||
char address_buffer[sizeof(struct in6_addr)]; | ||
|
||
if (uv_inet_pton(AF_INET6, *ip, &address_buffer) == 0) { | ||
args.GetReturnValue().Set(true); | ||
} else { | ||
args.GetReturnValue().Set(false); | ||
} | ||
} | ||
|
||
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
|
@@ -1327,6 +1348,8 @@ static void Initialize(Local<Object> target, | |
env->SetMethod(target, "getaddrinfo", GetAddrInfo); | ||
env->SetMethod(target, "getnameinfo", GetNameInfo); | ||
env->SetMethod(target, "isIP", IsIP); | ||
env->SetMethod(target, "isIPv4", IsIPv4); | ||
env->SetMethod(target, "isIPv6", IsIPv6); | ||
|
||
env->SetMethod(target, "strerror", StrError); | ||
env->SetMethod(target, "getServers", GetServers); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you don't just assign it as
exports.isIPv4 = cares.isIPv4;
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason, but I've just added check for symbol in js, so wrapper is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about now?