@@ -336,6 +336,84 @@ added: v0.6.9
336
336
Sets or clears the ` SO_BROADCAST ` socket option. When set to ` true ` , UDP
337
337
packets may be sent to a local interface's broadcast address.
338
338
339
+ ### socket.setMulticastInterface(multicastInterface)
340
+ <!-- YAML
341
+ added: REPLACEME
342
+ -->
343
+
344
+ * ` multicastInterface ` {String}
345
+
346
+ * Note: All references to scope in this section are refering to
347
+ [ IPv6 Zone Indices] [ ] , which are defined by [ RFC 4007] [ ] . In string form, an IP
348
+ with a scope index is written as ` 'IP%scope' ` where scope is an interface name or
349
+ interface number.*
350
+
351
+ Sets the default outgoing multicast interface of the socket to a chosen
352
+ interface or back to system interface selection. The ` multicastInterface ` must
353
+ be a valid string representation of an IP from the socket's family.
354
+
355
+ For IPv4 sockets, this should be the IP configured for the desired physical
356
+ interface. All packets sent to multicast on the socket will be sent on the
357
+ interface determined by the most recent successful use of this call.
358
+
359
+ For IPv6 sockets, ` multicastInterface ` should include a scope to indicate the
360
+ interface as in the examples that follow. In IPv6, individual ` send ` calls can
361
+ also use explicit scope in addresses, so only packets sent to a multicast
362
+ address without specifying an explicit scope are affected by the most recent
363
+ successful use of this call.
364
+
365
+ #### Examples: IPv6 Outgoing Multicast Interface
366
+
367
+ On most systems, where scope format uses the interface name:
368
+
369
+ ``` js
370
+ const socket = dgram .createSocket (' udp6' );
371
+
372
+ socket .bind (1234 , () => {
373
+ socket .setMulticastInterface (' ::%eth1' );
374
+ });
375
+ ```
376
+
377
+ On Windows, where scope format uses an interface number:
378
+
379
+ ``` js
380
+ const socket = dgram .createSocket (' udp6' );
381
+
382
+ socket .bind (1234 , () => {
383
+ socket .setMulticastInterface (' ::%2' );
384
+ });
385
+ ```
386
+
387
+ #### Example: IPv4 Outgoing Multicast Interface
388
+ All systems use an IP of the host on the desired physical interface:
389
+ ``` js
390
+ const socket = dgram .createSocket (' udp4' );
391
+
392
+ socket .bind (1234 , () => {
393
+ socket .setMulticastInterface (' 10.0.0.2' );
394
+ });
395
+ ```
396
+
397
+ #### Call Results
398
+
399
+ A call on a socket that is not ready to send or no longer open may throw a * Not
400
+ running* [ ` Error ` ] [ ] .
401
+
402
+ If ` multicastInterface ` can not be parsed into an IP then an * EINVAL*
403
+ [ ` System Error ` ] [ ] is thrown.
404
+
405
+ On IPv4, if ` multicastInterface ` is a valid address but does not match any
406
+ interface, or if the address does not match the family then
407
+ a [ ` System Error ` ] [ ] such as ` EADDRNOTAVAIL ` or ` EPROTONOSUP ` is thrown.
408
+
409
+ On IPv6, most errors with specifying or omiting scope will result in the socket
410
+ continuing to use (or returning to) the system's default interface selection.
411
+
412
+ A socket's address family's ANY address (IPv4 ` '0.0.0.0' ` or IPv6 ` '::' ` ) can be
413
+ used to return control of the sockets default outgoing interface to the system
414
+ for future multicast packets.
415
+
416
+
339
417
### socket.setMulticastLoopback(flag)
340
418
<!-- YAML
341
419
added: v0.3.8
@@ -490,4 +568,7 @@ and `udp6` sockets). The bound address and port can be retrieved using
490
568
[ `socket.address().address` ] : #dgram_socket_address
491
569
[ `socket.address().port` ] : #dgram_socket_address
492
570
[ `socket.bind()` ] : #dgram_socket_bind_port_address_callback
571
+ [ `System Error` ] : errors.html#errors_class_system_error
493
572
[ byte length ] : buffer.html#buffer_class_method_buffer_bytelength_string_encoding
573
+ [ IPv6 Zone Indices ] : https://en.wikipedia.org/wiki/IPv6_address#Link-local_addresses_and_zone_indices
574
+ [ RFC 4007 ] : https://tools.ietf.org/html/rfc4007
0 commit comments