@@ -386,6 +386,84 @@ added: v0.6.9
386386Sets or clears the ` SO_BROADCAST ` socket option. When set to ` true ` , UDP
387387packets may be sent to a local interface's broadcast address.
388388
389+ ### socket.setMulticastInterface(multicastInterface)
390+ <!-- YAML
391+ added: REPLACEME
392+ -->
393+
394+ * ` multicastInterface ` {String}
395+
396+ * Note: All references to scope in this section are refering to
397+ [ IPv6 Zone Indices] [ ] , which are defined by [ RFC 4007] [ ] . In string form, an IP
398+ with a scope index is written as ` 'IP%scope' ` where scope is an interface name or
399+ interface number.*
400+
401+ Sets the default outgoing multicast interface of the socket to a chosen
402+ interface or back to system interface selection. The ` multicastInterface ` must
403+ be a valid string representation of an IP from the socket's family.
404+
405+ For IPv4 sockets, this should be the IP configured for the desired physical
406+ interface. All packets sent to multicast on the socket will be sent on the
407+ interface determined by the most recent successful use of this call.
408+
409+ For IPv6 sockets, ` multicastInterface ` should include a scope to indicate the
410+ interface as in the examples that follow. In IPv6, individual ` send ` calls can
411+ also use explicit scope in addresses, so only packets sent to a multicast
412+ address without specifying an explicit scope are affected by the most recent
413+ successful use of this call.
414+
415+ #### Examples: IPv6 Outgoing Multicast Interface
416+
417+ On most systems, where scope format uses the interface name:
418+
419+ ``` js
420+ const socket = dgram .createSocket (' udp6' );
421+
422+ socket .bind (1234 , () => {
423+ socket .setMulticastInterface (' ::%eth1' );
424+ });
425+ ```
426+
427+ On Windows, where scope format uses an interface number:
428+
429+ ``` js
430+ const socket = dgram .createSocket (' udp6' );
431+
432+ socket .bind (1234 , () => {
433+ socket .setMulticastInterface (' ::%2' );
434+ });
435+ ```
436+
437+ #### Example: IPv4 Outgoing Multicast Interface
438+ All systems use an IP of the host on the desired physical interface:
439+ ``` js
440+ const socket = dgram .createSocket (' udp4' );
441+
442+ socket .bind (1234 , () => {
443+ socket .setMulticastInterface (' 10.0.0.2' );
444+ });
445+ ```
446+
447+ #### Call Results
448+
449+ A call on a socket that is not ready to send or no longer open may throw a * Not
450+ running* [ ` Error ` ] [ ] .
451+
452+ If ` multicastInterface ` can not be parsed into an IP then an * EINVAL*
453+ [ ` System Error ` ] [ ] is thrown.
454+
455+ On IPv4, if ` multicastInterface ` is a valid address but does not match any
456+ interface, or if the address does not match the family then
457+ a [ ` System Error ` ] [ ] such as ` EADDRNOTAVAIL ` or ` EPROTONOSUP ` is thrown.
458+
459+ On IPv6, most errors with specifying or omiting scope will result in the socket
460+ continuing to use (or returning to) the system's default interface selection.
461+
462+ A socket's address family's ANY address (IPv4 ` '0.0.0.0' ` or IPv6 ` '::' ` ) can be
463+ used to return control of the sockets default outgoing interface to the system
464+ for future multicast packets.
465+
466+
389467### socket.setMulticastLoopback(flag)
390468<!-- YAML
391469added: v0.3.8
@@ -553,4 +631,7 @@ and `udp6` sockets). The bound address and port can be retrieved using
553631[ `socket.address().address` ] : #dgram_socket_address
554632[ `socket.address().port` ] : #dgram_socket_address
555633[ `socket.bind()` ] : #dgram_socket_bind_port_address_callback
634+ [ `System Error` ] : errors.html#errors_class_system_error
556635[ byte length ] : buffer.html#buffer_class_method_buffer_bytelength_string_encoding
636+ [ IPv6 Zone Indices ] : https://en.wikipedia.org/wiki/IPv6_address#Link-local_addresses_and_zone_indices
637+ [ RFC 4007 ] : https://tools.ietf.org/html/rfc4007
0 commit comments