dgram: added setMulticastInterface() · nodejs/node@b24ee68 · GitHub
Skip to content

Commit b24ee68

Browse files
lostnetjasnell
authored andcommitted
dgram: added setMulticastInterface()
Add wrapper for uv's uv_udp_set_multicast_interface which provides the sender side mechanism to explicitly select an interface. The equivalent receiver side mechanism is the optional 2nd argument of addMembership(). PR-URL: #7855 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 606da2b commit b24ee68

7 files changed

Lines changed: 530 additions & 1 deletion

File tree

doc/api/dgram.md

Lines changed: 81 additions & 0 deletions

lib/dgram.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,21 @@ Socket.prototype.setMulticastLoopback = function(arg) {
562562
};
563563

564564

565+
Socket.prototype.setMulticastInterface = function(interfaceAddress) {
566+
this._healthCheck();
567+
568+
if (typeof interfaceAddress !== 'string') {
569+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
570+
'interfaceAddress',
571+
'string');
572+
}
573+
574+
const err = this._handle.setMulticastInterface(interfaceAddress);
575+
if (err) {
576+
throw errnoException(err, 'setMulticastInterface');
577+
}
578+
};
579+
565580
Socket.prototype.addMembership = function(multicastAddress,
566581
interfaceAddress) {
567582
this._healthCheck();

src/udp_wrap.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void UDPWrap::Initialize(Local<Object> target,
130130
GetSockOrPeerName<UDPWrap, uv_udp_getsockname>);
131131
env->SetProtoMethod(t, "addMembership", AddMembership);
132132
env->SetProtoMethod(t, "dropMembership", DropMembership);
133+
env->SetProtoMethod(t, "setMulticastInterface", SetMulticastInterface);
133134
env->SetProtoMethod(t, "setMulticastTTL", SetMulticastTTL);
134135
env->SetProtoMethod(t, "setMulticastLoopback", SetMulticastLoopback);
135136
env->SetProtoMethod(t, "setBroadcast", SetBroadcast);
@@ -238,6 +239,22 @@ X(SetMulticastLoopback, uv_udp_set_multicast_loop)
238239

239240
#undef X
240241

242+
void UDPWrap::SetMulticastInterface(const FunctionCallbackInfo<Value>& args) {
243+
UDPWrap* wrap;
244+
ASSIGN_OR_RETURN_UNWRAP(&wrap,
245+
args.Holder(),
246+
args.GetReturnValue().Set(UV_EBADF));
247+
248+
CHECK_EQ(args.Length(), 1);
249+
CHECK(args[0]->IsString());
250+
251+
Utf8Value iface(args.GetIsolate(), args[0]);
252+
253+
const char* iface_cstr = *iface;
254+
255+
int err = uv_udp_set_multicast_interface(&wrap->handle_, iface_cstr);
256+
args.GetReturnValue().Set(err);
257+
}
241258

242259
void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
243260
uv_membership membership) {

src/udp_wrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class UDPWrap: public HandleWrap {
5050
static void RecvStop(const v8::FunctionCallbackInfo<v8::Value>& args);
5151
static void AddMembership(const v8::FunctionCallbackInfo<v8::Value>& args);
5252
static void DropMembership(const v8::FunctionCallbackInfo<v8::Value>& args);
53+
static void SetMulticastInterface(
54+
const v8::FunctionCallbackInfo<v8::Value>& args);
5355
static void SetMulticastTTL(const v8::FunctionCallbackInfo<v8::Value>& args);
5456
static void SetMulticastLoopback(
5557
const v8::FunctionCallbackInfo<v8::Value>& args);

test/internet/test-dgram-multicast-multi-process.js

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)