= nng_options(5)
//
// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
// This document is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

== NAME

nng_options - socket, dialer, listener, and pipe options

== SYNOPSIS

[source, c]
----
#include <nng/nng.h>

#define NNG_OPT_RECVBUF       "recv-buffer"
#define NNG_OPT_SENDBUF       "send-buffer"
#define NNG_OPT_RECVTIMEO     "recv-timeout"
#define NNG_OPT_SENDTIMEO     "send-timeout"
#define NNG_OPT_LOCADDR       "local-address"
#define NNG_OPT_URL           "url"
#define NNG_OPT_MAXTTL        "ttl-max"
#define NNG_OPT_RECVMAXSZ     "recv-size-max"
#define NNG_OPT_RECONNMINT    "reconnect-time-min"
#define NNG_OPT_RECONNMAXT    "reconnect-time-max"
#define NNG_OPT_PEER_GID      "ipc:peer-gid"
#define NNG_OPT_PEER_PID      "ipc:peer-pid"
#define NNG_OPT_PEER_UID      "ipc:peer-uid"
#define NNG_OPT_PEER_ZONEID   "ipc:peer-zoneid"
----

== DESCRIPTION

This page documents the various standard options that can be set or
retrieved on objects.

Dialers (xref:nng_dialer.5.adoc[`nng_dialer`] objects) use the functions
xref:nng_dialer_get.3.adoc[`nng_dialer_get()`] and
xref:nng_dialer_set.3.adoc[`nng_dialer_set()`] to set and retrieve option
values.

Listeners (xref:nng_listener.5.adoc[`nng_listener`] objects) use the functions
xref:nng_listener_get.3.adoc[`nng_listener_get()`]
and xref:nng_listener_set.3.adoc[`nng_listener_set()`] to set and
retrieve option values.

Pipes (xref:nng_pipe.5.adoc[`nng_pipe`] objects) can only retrieve option values using
the xref:nng_pipe_get.3.adoc[`nng_pipe_get()`] function.

Other object types may have additional methods to access these options.

In addition to the options listed here, transports and protocols will generally
have some of their own options, which will be documented with the transport
or protocol.

=== Generic Options

In the following list of options, the name of the option is supplied,
along with the data type of the underlying value.

Some options are only meaningful or supported in certain contexts; for
example there is no single meaningful address for a socket, since sockets
can have multiple dialers and endpoints associated with them.
An attempt has been made to include details about such restrictions in the
description of the option.

[[NNG_OPT_LOCADDR]]
((`NNG_OPT_LOCADDR`))::
(xref:nng_sockaddr.5.adoc[`nng_sockaddr`])
This read-only option may be used dialers and
represents the local address used for communication.
NOTE: Not all transports support this option, and some transports may support it on
listeners but not dialers.
+
When used on a TCP dialer, this option is used to configure the source IP
address that will be used when initiating outgoing connections.
The specific port number will be ignored, however, and the system will
choose a random ephemeral port instead.

[[NNG_OPT_RECONNMINT]]
((`NNG_OPT_RECONNMINT`))::
(((reconnect time, minimum)))
(xref:nng_duration.5.adoc[`nng_duration`])
This is the minimum amount of time (milliseconds) to wait before attempting
to establish a connection after a previous attempt has failed.
This can be set on a socket, but it can also be overridden on an individual
dialer.
The option is irrelevant for listeners.

[[NNG_OPT_RECONNMAXT]]
((`NNG_OPT_RECONNMAXT`))::
(((`NNG_OPT_RECONNMAXT`)))
(((reconnect time, maximum)))
(xref:nng_duration.5.adoc[`nng_duration`])
This is the maximum amount of time
(milliseconds) to wait before attempting to establish a connection after
a previous attempt has failed.
If this is non-zero, then the time between successive connection attempts
will start at the value of `NNG_OPT_RECONNMINT`,
and grow exponentially, until it reaches this value.
If this value is zero, then no exponential
back-off between connection attempts is done, and each attempt will wait
the time specified by `NNG_OPT_RECONNMINT`.
This can be set on a socket, but it can also be overridden on an individual
dialer.
The option is irrelevant for listeners.

[[NNG_OPT_RECVBUF]]
((`NNG_OPT_RECVBUF`))::
(((buffer, receive)))
(((receive, buffer)))
(`int`)
This is the depth of the socket's receive buffer as a number of messages.
Messages received by a transport may be buffered until the application
has accepted them for delivery.
This value must be an integer between 0 and 8192, inclusive.
NOTE: Not all protocols support buffering received messages.
For example xref:nng_req.7.adoc[_req_] can only deal with a single reply at a time.

[[NNG_OPT_RECVMAXSZ]]
((`NNG_OPT_RECVMAXSZ`))::
(((receive, maximum size)))
(`size_t`)
This is the maximum message size that the will be accepted from a remote peer.
If a peer attempts to send a message larger than this, then the message
will be discarded.
If the value of this is zero, then no limit on message sizes is enforced.
This option exists to prevent certain kinds of denial-of-service attacks,
where a malicious agent can claim to want to send an extraordinarily
large message, without sending any data.
This option can be set for the socket, but may be overridden for on a
per-dialer or per-listener basis.
+
IMPORTANT: Applications on hostile networks should set this to a non-zero
value to prevent denial-of-service attacks.
+
IMPORTANT: This option should be set before any listeners or dialers are added.
Ideally this option should be set on specific dialers or listeners; setting it
on the socket globally is deprecated behavior, and might not work in a future release,
or might only work for endpoints that have not yet been created.
(Maximum receive sizes might be negotiated during connection establishment for
future transports, which means that the option needs to be set before any connections
are established.)
+
NOTE: Some transports may have further message size restrictions.


[[NNG_OPT_MAXTTL]]
((`NNG_OPT_MAXTTL`))::
(`int`)
(((time-to-live)))
This is the maximum number of times a message may traverse across
a xref:nng_device.3.adoc[`nng_device()`] forwarders.
The intention here is to prevent ((forwarding loops)) in device chains.
When this is supported, it can have a value between 1 and 255, inclusive.
+
NOTE: Not all protocols support this option.
Those that do generally have a default value of 8.
+
TIP: Each node along a forwarding path may have its own value for the
maximum time-to-live, and performs its own checks before forwarding a message.
Therefore it is helpful if all nodes in the topology use the same value for
this option.

[[NNG_OPT_URL]]
((`NNG_OPT_URL`))::
(((URI)))
(((URL)))
(string)
This read-only option is used to obtain the URL with which a listener
or dialer was configured.
Accordingly it can only be used with dialers, listeners, and pipes.
+
NOTE: Some transports will canonify URLs before returning them to the
application.

[[NNG_OPT_PEER_GID]]
((`NNG_OPT_PEER_GID`))::
(`uint64_t`)
This read-only option provides a connected peer's primary group id, when known.
This is the effective group id of the peer when either the underlying
`listen()` or `connect()` calls were made, and is not forgeable.
This option is generally only available on POSIX systems, only on certain transports.

[[NNG_OPT_PEER_PID]]
((`NNG_OPT_PEER_PID`))::
(`uint64_t`)
This read-only option provides the process id of the connected peer, when known.
This option is only available on certain platforms and transports.
+
NOTE: Applications should not assume that the process ID does not change,
as it may be possible for a process to pass a file descriptor between processes.
However, it is not possible for a nefarious application to forge the identity
of a well-behaved one using this method.

[[NNG_OPT_PEER_UID]]
((`NNG_OPT_PEER_UID`))::
(`uint64_t`)
This read-only option provides a connected peer's user id.
This is the effective user id of the peer when either the underlying
`listen()` or `connect()` calls were made, and cannot be forged.
This option is generally only available on POSIX systems, on certain transports.

[[NNG_OPT_PEER_ZONEID]]
((`NNG_OPT_PEER_ZONEID`))::
(`uint64_t`)
This read-only option provides a connected peer's the zone id.
Zones (and this option) are only supported on Solaris and illumos systems, on select transports.

== SEE ALSO

[.text-left]
xref:nng_dialer_get.3.adoc[nng_dialer_get(3)],
xref:nng_dialer_set.3.adoc[nng_dialer_set(3)],
xref:nng_listener_get.3.adoc[nng_listener_get(3)],
xref:nng_listener_set.3.adoc[nng_listener_set(3)],
xref:nng_pipe_get.3.adoc[nng_pipe_get(3)],
xref:nng_socket_get.3.adoc[nng_socket_get(3)],
xref:nng_socket_set.3.adoc[nng_socket_set(3)],
xref:nng_tcp_options.5.adoc[nng_tcp_options(5)],
xref:nng_tls_options.5.adoc[nng_tls_options(5)],
xref:nng.7.adoc[nng(7)]
