nbdkit_peer_name3
Get client address and information for nbdkit
Usage
#include <nbdkit-plugin.h>int nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen);int64_t nbdkit_peer_pid (void);int64_t nbdkit_peer_uid (void);int64_t nbdkit_peer_gid (void);char *nbdkit_peer_security_context (void);
Overview
nbdkit_peer_name
Return the peer (client) address, if available. The "addr" and "addrlen" parameters behave like getpeername(2). In particular you must initialize "addrlen" with the size of the buffer pointed to by "addr", and if "addr" is not large enough then the address will be truncated.
In some cases this is not available or the address returned will be meaningless (eg. if there is a proxy between the client and nbdkit). This call uses thread-local magic so no parameter is required to specify the current connection.
nbdkit_peer_pid
(nbdkit ≥ 1.24, Linux only)
Return the peer process ID. This is only available when the client connected over a Unix domain socket.
nbdkit_peer_uid
(nbdkit ≥ 1.24)
Return the peer user ID. This is only available when the client connected over a Unix domain socket.
nbdkit_peer_gid
(nbdkit ≥ 1.24)
Return the peer group ID. This is only available when the client connected over a Unix domain socket.
nbdkit_peer_security_context
(nbdkit ≥ 1.36, not Windows)
Return the peer security context (usually the SELinux label, IPSEC label or NetLabel). See the description of "SO_PEERSEC" in unix(7) and ip(7).
Return value
All functions except "nbdkit_peer_security_context" return 0 on success. If there is an error they call nbdkit_error(3) and return -1.
"nbdkit_peer_security_context" returns a security context as a string on success. The caller must free this string. On error (which can include missing label or unsupported protocol), nbdkit_error(3) is called and this call returns "NULL".
Language bindings
In nbdkit-ocaml-plugin(3):
NBDKit.peer_name : unit -> Unix.sockaddrNBDKit.peer_pid : unit -> int64NBDKit.peer_uid : unit -> int64NBDKit.peer_gid : unit -> int64NBDKit.peer_security_context : unit -> string
import nbdkitpid = nbdkit.peer_pid()uid = nbdkit.peer_uid()gid = nbdkit.peer_gid()security_context = nbdkit.peer_security_context()
In nbdkit-rust-plugin(3):
use nbdkit::*;pub fn peername<T: SockaddrLike>() ->std::result::Result<T, Box<dyn error::Error>>