summaryrefslogtreecommitdiff
path: root/src/udp_wrap.cc
diff options
context:
space:
mode:
authorLucas Pardue <lucas.pardue@bbc.co.uk>2017-10-02 13:20:52 +0100
committerAnna Henningsen <anna@addaleax.net>2019-10-17 03:12:53 +0200
commit1784b7fafac2755f870db3de9eb45a754b7a6477 (patch)
tree670a84f1ba0c508578efa5254d1960d8bfe36cce /src/udp_wrap.cc
parent273d38b1980fe308583c430eaeb837b8e6b3d204 (diff)
downloadnode-new-1784b7fafac2755f870db3de9eb45a754b7a6477.tar.gz
dgram: add source-specific multicast support
This adds RFC 4607 support for IPv4 and IPv6. Co-Authored-By: Nicolas Thumann <46975855+n-thumann@users.noreply.github.com> Co-Authored-By: Rich Trott <rtrott@gmail.com> PR-URL: https://github.com/nodejs/node/pull/15735 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/udp_wrap.cc')
-rw-r--r--src/udp_wrap.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 64c4c8b304..4a66ce0a1f 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -128,6 +128,10 @@ void UDPWrap::Initialize(Local<Object> target,
GetSockOrPeerName<UDPWrap, uv_udp_getsockname>);
env->SetProtoMethod(t, "addMembership", AddMembership);
env->SetProtoMethod(t, "dropMembership", DropMembership);
+ env->SetProtoMethod(t, "addSourceSpecificMembership",
+ AddSourceSpecificMembership);
+ env->SetProtoMethod(t, "dropSourceSpecificMembership",
+ DropSourceSpecificMembership);
env->SetProtoMethod(t, "setMulticastInterface", SetMulticastInterface);
env->SetProtoMethod(t, "setMulticastTTL", SetMulticastTTL);
env->SetProtoMethod(t, "setMulticastLoopback", SetMulticastLoopback);
@@ -397,6 +401,44 @@ void UDPWrap::DropMembership(const FunctionCallbackInfo<Value>& args) {
SetMembership(args, UV_LEAVE_GROUP);
}
+void UDPWrap::SetSourceMembership(const FunctionCallbackInfo<Value>& args,
+ uv_membership membership) {
+ UDPWrap* wrap;
+ ASSIGN_OR_RETURN_UNWRAP(&wrap,
+ args.Holder(),
+ args.GetReturnValue().Set(UV_EBADF));
+
+ CHECK_EQ(args.Length(), 3);
+
+ node::Utf8Value source_address(args.GetIsolate(), args[0]);
+ node::Utf8Value group_address(args.GetIsolate(), args[1]);
+ node::Utf8Value iface(args.GetIsolate(), args[2]);
+
+ if (*iface == nullptr) return;
+ const char* iface_cstr = *iface;
+ if (args[2]->IsUndefined() || args[2]->IsNull()) {
+ iface_cstr = nullptr;
+ }
+
+ int err = uv_udp_set_source_membership(&wrap->handle_,
+ *group_address,
+ iface_cstr,
+ *source_address,
+ membership);
+ args.GetReturnValue().Set(err);
+}
+
+void UDPWrap::AddSourceSpecificMembership(
+ const FunctionCallbackInfo<Value>& args) {
+ SetSourceMembership(args, UV_JOIN_GROUP);
+}
+
+
+void UDPWrap::DropSourceSpecificMembership(
+ const FunctionCallbackInfo<Value>& args) {
+ SetSourceMembership(args, UV_LEAVE_GROUP);
+}
+
void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
Environment* env = Environment::GetCurrent(args);