NV(9)
π NV(9): library for name/value pairs π
okay so bestie, this is the manual page for libnv, and itβs genuinely giving main character energy. Weβre talking name/value pairs, sending them over sockets, the whole vibe. π
πΈ NAME πΈ
nvlist_create, nvlist_destroy, nvlist_error, nvlist_set_error, nvlist_empty, nvlist_flags, nvlist_exists, nvlist_free, nvlist_clone, nvlist_dump, nvlist_fdump, nvlist_size, nvlist_pack, nvlist_unpack, nvlist_send, nvlist_recv, nvlist_xfer, nvlist_in_array, nvlist_next, nvlist_add, nvlist_move, nvlist_get, nvlist_take, nvlist_append β library for name/value pairs
π LIBRARY π
library βlibnvβ
β¨ SYNOPSIS β¨
No cap, hereβs the whole lineup:
#include <sys/nv.h>
nvlist_t *
nvlist_create(int flags);
void
nvlist_destroy(nvlist_t *nvl);
int
nvlist_error(const nvlist_t *nvl);
void
nvlist_set_error(nvlist_t *nvl, int error);
bool
nvlist_empty(const nvlist_t *nvl);
int
nvlist_flags(const nvlist_t *nvl);
bool
nvlist_in_array(const nvlist_t *nvl);
nvlist_t *
nvlist_clone(const nvlist_t *nvl);
void
nvlist_dump(const nvlist_t *nvl, int fd);
void
nvlist_fdump(const nvlist_t *nvl, FILE *fp);
size_t
nvlist_size(const nvlist_t *nvl);
void *
nvlist_pack(const nvlist_t *nvl, size_t *sizep);
nvlist_t *
nvlist_unpack(const void *buf, size_t size, int flags);
int
nvlist_send(int sock, const nvlist_t *nvl);
nvlist_t *
nvlist_recv(int sock, int flags);
nvlist_t *
nvlist_xfer(int sock, nvlist_t *nvl, int flags);
const char *
nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
bool
nvlist_exists(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
bool
nvlist_exists_null(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_bool(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_number(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_string(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_binary(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_bool_array(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_number_array(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_string_array(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_nvlist_array(const nvlist_t *nvl, const char *name);
bool
nvlist_exists_descriptor_array(const nvlist_t *nvl, const char *name);
void
nvlist_add_null(nvlist_t *nvl, const char *name);
void
nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
void
nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
void
nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
void
nvlist_add_stringf(nvlist_t *nvl, const char *name,
const char *valuefmt, ...);
void
nvlist_add_stringv(nvlist_t *nvl, const char *name,
const char *valuefmt, va_list valueap);
void
nvlist_add_nvlist(nvlist_t *nvl, const char *name,
const nvlist_t *value);
void
nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
void
nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
size_t size);
void
nvlist_add_bool_array(nvlist_t *nvl, const char *name,
const bool *value, size_t nitems);
void
nvlist_add_number_array(nvlist_t *nvl, const char *name,
const uint64_t *value, size_t nitems);
void
nvlist_add_string_array(nvlist_t *nvl, const char *name,
const char * const * value, size_t nitems);
void
nvlist_add_nvlist_array(nvlist_t *nvl, const char *name,
const nvlist_t * const * value, size_t nitems);
void
nvlist_add_descriptor_array(nvlist_t *nvl, const char *name,
const int *value, size_t nitems);
void
nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
void
nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
void
nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
void
nvlist_move_binary(nvlist_t *nvl, const char *name, void *value,
size_t size);
void
nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value,
size_t nitems);
void
nvlist_move_number_array(nvlist_t *nvl, const char *name,
uint64_t *value, size_t nitems);
void
nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value,
size_t nitems);
void
nvlist_move_nvlist_array(nvlist_t *nvl, const char *name,
nvlist_t **value, size_t nitems);
void
nvlist_move_descriptor_array(nvlist_t *nvl, const char *name,
int *value, size_t nitems);
bool
nvlist_get_bool(const nvlist_t *nvl, const char *name);
uint64_t
nvlist_get_number(const nvlist_t *nvl, const char *name);
const char *
nvlist_get_string(const nvlist_t *nvl, const char *name);
const nvlist_t *
nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
int
nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
const void *
nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
const bool *
nvlist_get_bool_array(const nvlist_t *nvl, const char *name,
size_t *nitems);
const uint64_t *
nvlist_get_number_array(const nvlist_t *nvl, const char *name,
size_t *nitems);
const char * const *
nvlist_get_string_array(const nvlist_t *nvl, const char *name,
size_t *nitems);
const nvlist_t * const *
nvlist_get_nvlist_array(const nvlist_t *nvl, const char *name,
size_t *nitems);
const int *
nvlist_get_descriptor_array(const nvlist_t *nvl, const char *name,
size_t *nitems);
const nvlist_t *
nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
const nvlist_t *
nvlist_get_array_next(const nvlist_t *nvl);
const nvlist_t *
nvlist_get_pararr(const nvlist_t *nvl, void **cookiep);
bool
nvlist_take_bool(nvlist_t *nvl, const char *name);
uint64_t
nvlist_take_number(nvlist_t *nvl, const char *name);
char *
nvlist_take_string(nvlist_t *nvl, const char *name);
nvlist_t *
nvlist_take_nvlist(nvlist_t *nvl, const char *name);
int
nvlist_take_descriptor(nvlist_t *nvl, const char *name);
void *
nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
bool *
nvlist_take_bool_array(nvlist_t *nvl, const char *name, size_t *nitems);
uint64_t **
nvlist_take_number_array(nvlist_t *nvl, const char *name,
size_t *nitems);
char **
nvlist_take_string_array(nvlist_t *nvl, const char *name,
size_t *nitems);
nvlist_t **
nvlist_take_nvlist_array(nvlist_t *nvl, const char *name,
size_t *nitems);
int *
nvlist_take_descriptor_array(nvlist_t *nvl, const char *name,
size_t *nitems);
void
nvlist_append_bool_array(nvlist_t *nvl, const char *name,
const bool value);
void
nvlist_append_number_array(nvlist_t *nvl, const char *name,
const uint64_t value);
void
nvlist_append_string_array(nvlist_t *nvl, const char *name,
const char * const value);
void
nvlist_append_nvlist_array(nvlist_t *nvl, const char *name,
const nvlist_t * const value);
void
nvlist_append_descriptor_array(nvlist_t *nvl, const char *name,
int value);
void
nvlist_free(nvlist_t *nvl, const char *name);
void
nvlist_free_type(nvlist_t *nvl, const char *name, int type);
void
nvlist_free_null(nvlist_t *nvl, const char *name);
void
nvlist_free_bool(nvlist_t *nvl, const char *name);
void
nvlist_free_number(nvlist_t *nvl, const char *name);
void
nvlist_free_string(nvlist_t *nvl, const char *name);
void
nvlist_free_nvlist(nvlist_t *nvl, const char *name);
void
nvlist_free_descriptor(nvlist_t *nvl, const char *name);
void
nvlist_free_binary(nvlist_t *nvl, const char *name);
void
nvlist_free_bool_array(nvlist_t *nvl, const char *name);
void
nvlist_free_number_array(nvlist_t *nvl, const char *name);
void
nvlist_free_string_array(nvlist_t *nvl, const char *name);
void
nvlist_free_nvlist_array(nvlist_t *nvl, const char *name);
void
nvlist_free_descriptor_array(nvlist_t *nvl, const char *name);
π DESCRIPTION π
okay so the libnv library lets you create and manage name value pairs as well as send and receive them over sockets. A group (list) of name value pairs is called an nvlist. The API supports these data types for values:
null(NV_TYPE_NULL) β there is no data associated with the name. literally no payload, just vibes.bool(NV_TYPE_BOOL) β the value can be eithertrueorfalse.number(NV_TYPE_NUMBER) β the value is a number stored asuint64_t.string(NV_TYPE_STRING) β the value is a C string.nvlist(NV_TYPE_NVLIST) β the value is a nestednvlist.descriptor(NV_TYPE_DESCRIPTOR) β the value is a file descriptor. note that file descriptors can be sent only overunix(4)domain sockets.binary(NV_TYPE_BINARY) β the value is a binary buffer.bool array(NV_TYPE_BOOL_ARRAY) β the value is an array of boolean values.number array(NV_TYPE_NUMBER_ARRAY) β the value is an array of numbers, each stored asuint64_t.string array(NV_TYPE_STRING_ARRAY) β the value is an array of C strings.nvlist array(NV_TYPE_NVLIST_ARRAY) β the value is an array of nvlists. when an nvlist is added to an array, it becomes part of the primary nvlist. traversing these arrays can be done using thenvlist_get_array_next()andnvlist_get_pararr()functions.descriptor array(NV_TYPE_DESCRIPTOR_ARRAY) β the value is an array of file descriptors.
The nvlist_create() function allocates memory and initializes an nvlist.
The following flags can be provided:
NV_FLAG_IGNORE_CASEβ perform case-insensitive lookups of provided names.NV_FLAG_NO_UNIQUEβ names in thenvlistdo not have to be unique.
The nvlist_destroy() function destroys the given nvlist. This function does nothing if nvl is NULL. This function never modifies errno β periodt.
The nvlist_error() function returns the first error set on nvl. If nvl is not in the error state, this function returns zero. If nvl is NULL, ENOMEM is returned.
The nvlist_set_error() function sets the error value for nvl. Subsequent calls to nvlist_error() will return error. This function cannot be used to clear the error state from an nvlist. This function does nothing if the nvlist is already in the error state.
Okay so nvlist_empty() is your vibe check: it returns true if nvl is empty and false otherwise. Tiny catch, bestie β nvl must not be in the error state. π
nvlist_flags() returns the flags used to create nvl with nvlist_create(), nvlist_recv(), nvlist_unpack(), or nvlist_xfer(). Now you know where it came from, periodt. β¨
nvlist_in_array() returns true if nvl is part of an array that is a member of another nvlist. Cute nested situation, honestly.
nvlist_clone() clones nvl. The clone shares no resources with its origin. This also means that all file descriptors that are part of the nvlist will be duplicated with the dup(2) system call before placing them in the clone. No sharing, no drama. π¦
nvlist_dump() dumps nvlist content for debugging purposes to the file descriptor fd.
nvlist_fdump() dumps nvlist content for debugging purposes to the file stream fp.
nvlist_size() returns the size of the binary buffer that would be generated by the nvlist_pack() function. It's giving "how big is this gonna be" energy. π
nvlist_pack() converts the given nvlist to a binary buffer. The function allocates memory for the buffer, which should be freed with the free(3) function. If the sizep argument is not NULL, the size of the buffer is stored there. This function returns NULL in case of an error (allocation failure). If the nvlist contains any file descriptors, NULL will be returned. The nvlist must not be in the error state. No cap. π₯
nvlist_unpack() converts a binary buffer to a new nvlist. The flags argument has the same meaning as the flags argument passed to nvlist_create(). If flags do not match the flags used to create the initial nvlist before it was packed, this function will fail. The flags of nested nvlists are not validated by this function. The caller is responsible for validating the flags on any nested nvlists using nvlist_flags(). This function returns the new nvlist on success or NULL in case of an error.
nvlist_send() sends nvl over the socket sock. Note that nvlists that contain file descriptors can only be sent over unix(4) domain sockets. That's the rule, bestie. π«Ά
nvlist_recv() receives an nvlist over the socket sock. As with nvlist_unpack(), the flags argument is used to construct the new nvlist and must match the flags used to construct the original nvlist written to sock by the peer. The flags of nested nvlists are not validated by this function. The caller is responsible for validating the flags on any nested nvlists using nvlist_flags(). This function returns the new nvlist on success or NULL in case of an error.
nvlist_xfer() sends nvl over the socket sock argument and then receives a new nvlist over the same socket. The flags argument applies to the new nvlist similar to nvlist_recv(). The nvlist nvl is always destroyed. This function returns the new nvlist on success or NULL in case of an error. Sending and receiving, one socket, main character energy. π
nvlist_next() iterates over nvl, returning the names and types of subsequent elements. The cookiep argument determines which element is returned. If *cookiep is NULL, the values for the first element in the list are returned. Otherwise, *cookiep should contain the result of a prior call to nvlist_next(), in which case values for the next element from nvl are returned. This function returns NULL when there are no more elements on nvl. The typep argument can be NULL. Elements may not be removed from nvl (the nvlist) while traversing it. nvl must not be in the error state. Additional actions can be performed on an element identified by a cookie via the cnv(9) API.
nvlist_exists() returns true if an element named name exists in nvl (regardless of type) or false otherwise. The nvlist must not be in the error state. π
nvlist_exists_type() returns true if an element named name of type type exists or false otherwise. The nvlist must not be in the error state.
The nvlist_exists_null(), nvlist_exists_bool(), nvlist_exists_number(), nvlist_exists_string(), nvlist_exists_nvlist(), nvlist_exists_descriptor(), nvlist_exists_binary(), nvlist_exists_bool_array(), nvlist_exists_number_array(), nvlist_exists_string_array(), nvlist_exists_nvlist_array(), nvlist_exists_descriptor_array() functions return true if element named name with the type determined by the function name exists or false otherwise. The nvlist must not be in the error state. Yes, that's a whole lineup, and they all ate. π
The nvlist_add_null(), nvlist_add_bool(), nvlist_add_number(), nvlist_add_string(), nvlist_add_stringf(), nvlist_add_stringv(), nvlist_add_nvlist(), nvlist_add_descriptor(), nvlist_add_binary(), nvlist_add_bool_array(), nvlist_add_number_array(), nvlist_add_string_array(), nvlist_add_nvlist_array(), nvlist_add_descriptor_array() functions add an element to nvl. When adding a string or binary buffer, these functions allocate memory and copy the data. When adding an nvlist, the value nvlist is cloned and the clone is added to nvl. When adding a file descriptor, the descriptor is duplicated via the dup(2) system call and the new file descriptor is added. The array functions fail if there are any NULL elements in the array, or if the array pointer is NULL. If an error occurs while adding a new element, an internal error is set which can be examined using the nvlist_error() function. Copy responsibly, bestie. π
The nvlist_move_string(), nvlist_move_nvlist(), nvlist_move_descriptor(), nvlist_move_binary(), nvlist_move_bool_array(), nvlist_move_number_array(), nvlist_move_string_array(), nvlist_move_nvlist_array(), nvlist_move_descriptor_array() functions add an element to nvl, but unlike the nvlist_add_<type>() functions they consume the given resource.
π¨ For string, file descriptor, binary buffer, or nvlist values, no value should be moved into an nvlist multiple times; doing so will cause that value to be freed multiple times. That's the dangerous part, fr fr.
Note that strings or binary buffers must be allocated with malloc(3), and the pointers will be released via free(3) when nvl is destroyed. The array functions fail if there are any NULL elements, or if the array pointer is NULL. If an error occurs while adding a new element, the resource is destroyed and an internal error is set which can be examined using the nvlist_error() function.
The nvlist_get_bool(), nvlist_get_number(), nvlist_get_string(), nvlist_get_nvlist(), nvlist_get_descriptor(), nvlist_get_binary(), nvlist_get_bool_array(), nvlist_get_number_array(), nvlist_get_string_array(), nvlist_get_nvlist_array(), nvlist_get_descriptor_array() functions return the value of the first element in nvl named name. For string, nvlist, file descriptor, binary buffer, or array values, the returned resource must not be modified β it still belongs to nvl. Hands off, bestie. π
If an element named name does not exist, the program aborts. To avoid this, the caller should check for the existence of the element before trying to obtain the value, or use the dnv(9) extension which provides a default value in the case of a missing element. Please check first, I am begging. π
The nvlist must not be in the error state.
nvlist_get_parent() returns the parent nvlist of nvl.
nvlist_get_array_next() returns the next element after nvl from an array of nvlists. If nvl is not in an array of nvlists or it is the last element, this function returns NULL. An nvlist is only in an nvlist array if it was added to an nvlist array using nvlist_add_nvlist_array(), nvlist_append_nvlist_array(), or nvlist_move_nvlist_array(). Array rules, iykyk. πΈ
nvlist_get_pararr() returns the next element after nvl() from an array of nvlists. If nvl() is the last element in an array of nvlists, the parent nvlist of nvl is returned. If nvl() is not in an array of nvlists, NULL is returned.
The nvlist_take_bool(), nvlist_take_number(), nvlist_take_string(), nvlist_take_nvlist(), nvlist_take_descriptor(), nvlist_take_binary(), nvlist_take_bool_array(), nvlist_take_number_array(), nvlist_take_string_array(), nvlist_take_nvlist_array(), nvlist_take_descriptor_array() functions return the value of the element named name and remove the element from nvl. For string and binary buffer values, the caller is responsible for freeing the returned value using the free(3) function. For nvlist values, the caller is responsible for destroying the returned nvlist using the nvlist_destroy() function. For file descriptor values, the caller is responsible for closing the returned descriptor using the close(2) system call. For array values, the caller is responsible for destroying every element of the array based on the element type. In addition, the caller must also free the pointer to the array using the free(3) function. Take it, but take care of it. π
If an element named name does not exist, the program aborts. To avoid this, the caller should check for the existence of the element before trying to obtain the value, or use the dnv(9) extension which provides a default value in the case of a missing element.
The nvlist must not be in the error state.
The nvlist_append_bool_array(), nvlist_append_number_array(), nvlist_append_string_array(), nvlist_append_nvlist_array(), nvlist_append_descriptor_array() functions append an element to an existing array using the same semantics as the add functions (that is, the element will be copied when applicable). If the array named name does not exist, then it will be created as if using the nvlist_add_<type>_array() function. If an error occurs while appending a new element, an internal error is set on nvl. Append era, honestly. β¨
nvlist_free() removes the first element named name from nvl (regardless of type) and frees all resources associated with it. If no element named name exists, the program aborts. The nvlist must not be in the error state.
nvlist_free_type() removes the first element named name of type type from nvl and frees all resources associated with it. If no element named name of type type exists, the program aborts. The nvlist must not be in the error state.
The nvlist_free_null(), nvlist_free_bool(), nvlist_free_number(), nvlist_free_string(), nvlist_free_nvlist(), nvlist_free_descriptor(), nvlist_free_binary(), nvlist_free_bool_array(), nvlist_free_number_array(), nvlist_free_string_array(), nvlist_free_nvlist_array(), nvlist_free_descriptor_array() functions remove the first element named name with the type determined by the function name from nvl and free all resources associated with it. If no element named name with the appropriate type exists, the program aborts. The nvlist must not be in the error state. Cleanup slay. π§
π Notes β¨
nvlist_pack() and nvlist_unpack() handle byte-order conversions, so binary buffers can be packed and unpacked on hosts with different endianness. Endianness who? We don't know her. π
nvlist_recv(), nvlist_send(), and nvlist_xfer() can transfer nvlists between hosts with different endianness. Cross-host communication, iconic behavior. β
π₯οΈ Kernel Considerations
So you wanna use the nv, cnv, and dnv APIs inside the kernel? Respect, bestie, but there are a few plot twists you need to know about first:
- File descriptor and file descriptor array value types? Not supported in kernel land. Sorry babe. π«
nvlist_recv(),nvlist_send(), andnvlist_xfer()are also not supported. Those are userspace-only vibes, iykyk.- Every single memory allocation uses the
M_NVLISTmemory type withmalloc(9)andfree(9). That's the drama of it: any allocated buffer you move into an nvlist must have been allocated withM_NVLIST, and any buffer that comes back to you from functions likenvlist_pack()must be freed withM_NVLIST. Get this wrong and the kernel will be like π.
β¨ EXAMPLES β¨
Okay bestie, this is the fun part β here's how you actually do the thing. π
The first example shows how to prepare an nvlist and send it over a unix(4) domain socket:
nvlist_t *nvl;
int fd;
fd = open("/tmp/foo", O_RDONLY);
if (fd < 0)
err(1, "open(\"/tmp/foo\") failed");
nvl = nvlist_create(0);
/*
* There is no need to check if nvlist_create() succeeded
* as the nvlist_add_<type>() functions can cope.
* If it failed, nvlist_send() will fail.
*/
nvlist_add_string(nvl, "filename", "/tmp/foo");
nvlist_add_number(nvl, "flags", O_RDONLY);
/*
* We just want to send the descriptor, so we can give it
* for the nvlist to consume (that is why we use nvlist_move
* not nvlist_add).
*/
nvlist_move_descriptor(nvl, "fd", fd);
if (nvlist_send(sock, nvl) < 0) {
nvlist_destroy(nvl);
err(1, "nvlist_send() failed");
}
nvlist_destroy(nvl);
Receiving an nvlist and retrieving element values β the receiving end of the group chat:
nvlist_t *nvl;
const char *command;
char *filename;
int fd;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
/* For command we accept a pointer to the nvlist's internal buffer. */
command = nvlist_get_string(nvl, "command");
/*
* For filename we remove it from the nvlist and take
* ownership of the buffer.
*/
filename = nvlist_take_string(nvl, "filename");
/* The same for the file descriptor. */
fd = nvlist_take_descriptor(nvl, "fd");
printf("command=%s filename=%s fd=%d0, command, filename, fd);
/* command is freed by nvlist_destroy() */
nvlist_destroy(nvl);
free(filename);
close(fd);
Iterating over an nvlist β literally just vibing through the elements one by one:
nvlist_t *nvl;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
cookie = NULL;
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
printf("%s=", name);
switch (type) {
case NV_TYPE_NUMBER:
printf("%ju", (uintmax_t)nvlist_get_number(nvl, name));
break;
case NV_TYPE_STRING:
printf("%s", nvlist_get_string(nvl, name));
break;
default:
printf("N/A");
break;
}
printf("\n");
}
Iterating over every nested nvlist β going full main character and descending into the depths π:
nvlist_t *nvl;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == NULL)
err(1, "nvlist_recv() failed");
cookie = NULL;
do {
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
}
}
} while ((nvl = nvlist_get_parent(nvl, &cookie)) != NULL);
Iterating over every nested nvlist and every nvlist element β max effort, no notes:
nvlist_t *nvl;
const nvlist_t * const *array;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == null)
err(1, "nvlist_recv() failed");
cookie = NULL;
do {
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
} else if (type == NV_TYPE_NVLIST_ARRAY) {
nvl = nvlist_get_nvlist_array(nvl, name, NULL)[0];
cookie = NULL;
}
}
} while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
Or alternatively β same energy, slightly different choreography π :
nvlist_t *nvl, *tmp;
const nvlist_t * const *array;
const char *name;
void *cookie;
int type;
nvl = nvlist_recv(sock, 0);
if (nvl == null)
err(1, "nvlist_recv() failed");
cooke = NULL;
tmp = nvl;
do {
do {
nvl = tmp;
while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
if (type == NV_TYPE_NVLIST) {
nvl = nvlist_get_nvlist(nvl, name);
cookie = NULL;
} else if (type == NV_TYPE_NVLIST_ARRAY) {
nvl = nvlist_get_nvlist_array(nvl, name,
NULL)[0];
cookie = NULL;
}
}
cookie = NULL;
} while ((tmp = nvlist_get_array_next(nvl)) != NULL);
} while ((tmp = nvlist_get_parent(nvl, &cookie)) != NULL);
π SEE ALSO
Go read these next, bestie β they're the supporting cast and they ate:
close(2), dup(2), open(2), err(3), free(3), printf(3), unix(4)
π¦ HISTORY
The libnv library appeared in FreeBSD 11.0. Periodt. β¨
π AUTHORS
The libnv library was implemented by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation. Giving credit where credit is due, as one should π«Ά
And that's a wrap on this whole manpage, bestie! π This page lives in Debian, dated January 3, 2025 β so if you're reading it, that's the version tea you're sipping. Go forth and nvlist responsibly πβπ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2013 The FreeBSD Foundation
- Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms