2 .\" Copyright (c) 2013 The FreeBSD Foundation
3 .\" Copyright (c) 2013-2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
4 .\" All rights reserved.
6 .\" This documentation was written by Pawel Jakub Dawidek under sponsorship
7 .\" the FreeBSD Foundation.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 .Nm nvlist_set_error ,
60 .Nd "library for name/value pairs"
66 .Fn nvlist_create "int flags"
68 .Fn nvlist_destroy "nvlist_t *nvl"
70 .Fn nvlist_error "const nvlist_t *nvl"
72 .Fn nvlist_set_error "nvlist_t *nvl" "int error"
74 .Fn nvlist_empty "const nvlist_t *nvl"
76 .Fn nvlist_flags "const nvlist_t *nvl"
78 .Fn nvlist_in_array "const nvlist_t *nvl"
81 .Fn nvlist_clone "const nvlist_t *nvl"
84 .Fn nvlist_dump "const nvlist_t *nvl" "int fd"
86 .Fn nvlist_fdump "const nvlist_t *nvl" "FILE *fp"
89 .Fn nvlist_size "const nvlist_t *nvl"
91 .Fn nvlist_pack "const nvlist_t *nvl" "size_t *sizep"
93 .Fn nvlist_unpack "const void *buf" "size_t size" "int flags"
96 .Fn nvlist_send "int sock" "const nvlist_t *nvl"
98 .Fn nvlist_recv "int sock" "int flags"
100 .Fn nvlist_xfer "int sock" "nvlist_t *nvl" "int flags"
103 .Fn nvlist_next "const nvlist_t *nvl" "int *typep" "void **cookiep"
106 .Fn nvlist_exists "const nvlist_t *nvl" "const char *name"
108 .Fn nvlist_exists_type "const nvlist_t *nvl" "const char *name" "int type"
110 .Fn nvlist_exists_null "const nvlist_t *nvl" "const char *name"
112 .Fn nvlist_exists_bool "const nvlist_t *nvl" "const char *name"
114 .Fn nvlist_exists_number "const nvlist_t *nvl" "const char *name"
116 .Fn nvlist_exists_string "const nvlist_t *nvl" "const char *name"
118 .Fn nvlist_exists_nvlist "const nvlist_t *nvl" "const char *name"
120 .Fn nvlist_exists_descriptor "const nvlist_t *nvl" "const char *name"
122 .Fn nvlist_exists_binary "const nvlist_t *nvl" "const char *name"
124 .Fn nvlist_exists_bool_array "const nvlist_t *nvl" "const char *name"
126 .Fn nvlist_exists_number_array "const nvlist_t *nvl" "const char *name"
128 .Fn nvlist_exists_string_array "const nvlist_t *nvl" "const char *name"
130 .Fn nvlist_exists_nvlist_array "const nvlist_t *nvl" "const char *name"
132 .Fn nvlist_exists_descriptor_array "const nvlist_t *nvl" "const char *name"
135 .Fn nvlist_add_null "nvlist_t *nvl" "const char *name"
137 .Fn nvlist_add_bool "nvlist_t *nvl" "const char *name" "bool value"
139 .Fn nvlist_add_number "nvlist_t *nvl" "const char *name" "uint64_t value"
141 .Fn nvlist_add_string "nvlist_t *nvl" "const char *name" "const char *value"
143 .Fn nvlist_add_stringf "nvlist_t *nvl" "const char *name" "const char *valuefmt" "..."
145 .Fn nvlist_add_stringv "nvlist_t *nvl" "const char *name" "const char *valuefmt" "va_list valueap"
147 .Fn nvlist_add_nvlist "nvlist_t *nvl" "const char *name" "const nvlist_t *value"
149 .Fn nvlist_add_descriptor "nvlist_t *nvl" "const char *name" "int value"
151 .Fn nvlist_add_binary "nvlist_t *nvl" "const char *name" "const void *value" "size_t size"
153 .Fn nvlist_add_bool_array "nvlist_t *nvl" "const char *name" "const bool *value" "size_t nitems"
156 .Fn nvlist_add_number_array "nvlist_t *nvl" "const char *name" "const uint64_t *value" "size_t nitems"
159 .Fn nvlist_add_string_array "nvlist_t *nvl" "const char *name" "const char * const * value" "size_t nitems"
162 .Fn nvlist_add_nvlist_array "nvlist_t *nvl" "const char *name" "const nvlist_t * const * value" "size_t nitems"
165 .Fn nvlist_add_descriptor_array "nvlist_t *nvl" "const char *name" "const int *value" "size_t nitems"
168 .Fn nvlist_move_string "nvlist_t *nvl" "const char *name" "char *value"
170 .Fn nvlist_move_nvlist "nvlist_t *nvl" "const char *name" "nvlist_t *value"
172 .Fn nvlist_move_descriptor "nvlist_t *nvl" "const char *name" "int value"
174 .Fn nvlist_move_binary "nvlist_t *nvl" "const char *name" "void *value" "size_t size"
176 .Fn nvlist_move_bool_array "nvlist_t *nvl" "const char *name" "bool *value" "size_t nitems"
179 .Fn nvlist_move_number_array "nvlist_t *nvl" "const char *name" "uint64_t *value" "size_t nitems"
182 .Fn nvlist_move_string_array "nvlist_t *nvl" "const char *name" "char **value" "size_t nitems"
185 .Fn nvlist_move_nvlist_array "nvlist_t *nvl" "const char *name" "nvlist_t **value" "size_t nitems"
188 .Fn nvlist_move_descriptor_array "nvlist_t *nvl" "const char *name" "int *value" "size_t nitems"
191 .Fn nvlist_get_bool "const nvlist_t *nvl" "const char *name"
193 .Fn nvlist_get_number "const nvlist_t *nvl" "const char *name"
195 .Fn nvlist_get_string "const nvlist_t *nvl" "const char *name"
196 .Ft "const nvlist_t *"
197 .Fn nvlist_get_nvlist "const nvlist_t *nvl" "const char *name"
199 .Fn nvlist_get_descriptor "const nvlist_t *nvl" "const char *name"
201 .Fn nvlist_get_binary "const nvlist_t *nvl" "const char *name" "size_t *sizep"
203 .Fn nvlist_get_bool_array "const nvlist_t *nvl" "const char *name" "size_t *nitems"
204 .Ft "const uint64_t *"
205 .Fn nvlist_get_number_array "const nvlist_t *nvl" "const char *name" "size_t *nitems"
206 .Ft "const char * const *"
207 .Fn nvlist_get_string_array "const nvlist_t *nvl" "const char *name" "size_t *nitems"
208 .Ft "const nvlist_t * const *"
209 .Fn nvlist_get_nvlist_array "const nvlist_t *nvl" "const char *name" "size_t *nitems"
211 .Fn nvlist_get_descriptor_array "const nvlist_t *nvl" "const char *name" "size_t *nitems"
212 .Ft "const nvlist_t *"
213 .Fn nvlist_get_parent "const nvlist_t *nvl" "void **cookiep"
214 .Ft "const nvlist_t *"
215 .Fn nvlist_get_array_next "const nvlist_t *nvl"
216 .Ft "const nvlist_t *"
217 .Fn nvlist_get_pararr "const nvlist_t *nvl" "void **cookiep"
220 .Fn nvlist_take_bool "nvlist_t *nvl" "const char *name"
222 .Fn nvlist_take_number "nvlist_t *nvl" "const char *name"
224 .Fn nvlist_take_string "nvlist_t *nvl" "const char *name"
226 .Fn nvlist_take_nvlist "nvlist_t *nvl" "const char *name"
228 .Fn nvlist_take_descriptor "nvlist_t *nvl" "const char *name"
230 .Fn nvlist_take_binary "nvlist_t *nvl" "const char *name" "size_t *sizep"
232 .Fn nvlist_take_bool_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
234 .Fn nvlist_take_number_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
236 .Fn nvlist_take_string_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
238 .Fn nvlist_take_nvlist_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
240 .Fn nvlist_take_descriptor_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
243 .Fn nvlist_append_bool_array "nvlist_t *nvl" "const char *name" "const bool value"
245 .Fn nvlist_append_number_array "nvlist_t *nvl" "const char *name" "const uint64_t value"
247 .Fn nvlist_append_string_array "nvlist_t *nvl" "const char *name" "const char * const value"
249 .Fn nvlist_append_nvlist_array "nvlist_t *nvl" "const char *name" "const nvlist_t * const value"
251 .Fn nvlist_append_descriptor_array "nvlist_t *nvl" "const char *name" "int value"
254 .Fn nvlist_free "nvlist_t *nvl" "const char *name"
256 .Fn nvlist_free_type "nvlist_t *nvl" "const char *name" "int type"
259 .Fn nvlist_free_null "nvlist_t *nvl" "const char *name"
261 .Fn nvlist_free_bool "nvlist_t *nvl" "const char *name"
263 .Fn nvlist_free_number "nvlist_t *nvl" "const char *name"
265 .Fn nvlist_free_string "nvlist_t *nvl" "const char *name"
267 .Fn nvlist_free_nvlist "nvlist_t *nvl" "const char *name"
269 .Fn nvlist_free_descriptor "nvlist_t *nvl" "const char *name"
271 .Fn nvlist_free_binary "nvlist_t *nvl" "const char *name"
273 .Fn nvlist_free_bool_array "nvlist_t *nvl" "const char *name"
275 .Fn nvlist_free_number_array "nvlist_t *nvl" "const char *name"
277 .Fn nvlist_free_string_array "nvlist_t *nvl" "const char *name"
279 .Fn nvlist_free_nvlist_array "nvlist_t *nvl" "const char *name"
281 .Fn nvlist_free_descriptor_array "nvlist_t *nvl" "const char *name"
285 library allows to easily manage name value pairs as well as send and receive
287 A group (list) of name value pairs is called an
289 The API supports the following data types:
290 .Bl -ohang -offset indent
291 .It Sy null ( NV_TYPE_NULL )
292 There is no data associated with the name.
293 .It Sy bool ( NV_TYPE_BOOL )
294 The value can be either
298 .It Sy number ( NV_TYPE_NUMBER )
299 The value is a number stored as
301 .It Sy string ( NV_TYPE_STRING )
302 The value is a C string.
303 .It Sy nvlist ( NV_TYPE_NVLIST )
304 The value is a nested nvlist.
305 .It Sy descriptor ( NV_TYPE_DESCRIPTOR )
306 The value is a file descriptor.
307 Note that file descriptors can be sent only over
310 .It Sy binary ( NV_TYPE_BINARY )
311 The value is a binary buffer.
312 .It Sy bool array ( NV_TYPE_BOOL_ARRAY )
313 The value is an array of boolean values.
314 .It Sy number array ( NV_TYPE_NUMBER_ARRAY )
315 The value is an array of numbers, each stored as
317 .It Sy string array ( NV_TYPE_STRING_ARRAY )
318 The value is an array of C strings.
319 .It Sy nvlist array ( NV_TYPE_NVLIST_ARRAY )
320 The value is an array of nvlists.
321 When an nvlist is added to an array, it becomes part of the primary nvlist.
322 Traversing these arrays can be done using the
323 .Fn nvlist_get_array_next
325 .Fn nvlist_get_pararr
327 .It Sy descriptor array ( NV_TYPE_DESCRIPTOR_ARRAY )
328 The value is an array of files descriptors.
333 function allocates memory and initializes an nvlist.
335 The following flag can be provided:
337 .Bl -tag -width "NV_FLAG_IGNORE_CASE" -compact -offset indent
338 .It Dv NV_FLAG_IGNORE_CASE
339 Perform case-insensitive lookups of provided names.
340 .It Dv NV_FLAG_NO_UNIQUE
341 Names in the nvlist do not have to be unique.
346 function destroys the given nvlist.
347 Function does nothing if
350 Function never modifies the
356 function returns any error value that the nvlist accumulated.
357 If the given nvlist is
361 error will be returned.
365 function sets an nvlist to be in the error state.
368 will return the given error value.
369 This function cannot be used to clear the error state from an nvlist.
370 This function does nothing if the nvlist is already in the error state.
376 if the given nvlist is empty and
379 The nvlist must not be in error state.
383 function returns flags used to create the nvlist with the
393 is part of an array that is a member of another nvlist.
397 functions clones the given nvlist.
398 The clone shares no resources with its origin.
399 This also means that all file descriptors that are part of the nvlist will be
402 system call before placing them in the clone.
406 dumps nvlist content for debugging purposes to the given file descriptor
411 dumps nvlist content for debugging purposes to the given file stream
416 function returns the size of the given nvlist after converting it to binary
423 function converts the given nvlist to a binary buffer.
424 The function allocates memory for the buffer, which should be freed with the
431 the size of the buffer will be stored there.
434 in case of an error (allocation failure).
435 If the nvlist contains any file descriptors
438 The nvlist must not be in error state.
442 function converts the given buffer to the nvlist.
445 argument defines what type of the top level nvlist is expected to be.
446 Flags are set up using the
449 If the nvlist flags do not match the flags passed to
451 the nvlist will not be returned.
452 Every nested nvlist list should be checked using
461 function sends the given nvlist over the socket given by the
464 Note that nvlist that contains file descriptors can only be send over
470 function receives nvlist over the socket given by the
475 argument defines what type of the top level nvlist is expected to be.
476 Flags are set up using the
479 If the nvlist flags do not match the flags passed to
481 the nvlist will not be returned.
482 Every nested nvlist list should be checked using
488 function sends the given nvlist over the socket given by the
490 argument and receives nvlist over the same socket.
493 argument defines what type of the top level nvlist is expected to be.
494 Flags are set up using the
497 If the nvlist flags do not match the flags passed to
499 the nvlist will not be returned.
500 Every nested nvlist list should be checked using
503 The given nvlist is always destroyed.
507 function iterates over the given nvlist returning names and types of subsequent
511 argument allows the function to figure out which element should be returned
517 for the first call and should not be changed later.
520 means there are no more elements on the nvlist.
523 argument can be NULL.
524 Elements may not be removed from the nvlist while traversing it.
525 The nvlist must not be in error state.
532 In this case first element is returned or
535 This behavior simplifies removing the first element from the list.
541 if element of the given name exists (besides of its type) or
544 The nvlist must not be in error state.
547 .Fn nvlist_exists_type
550 if element of the given name and the given type exists or
553 The nvlist must not be in error state.
556 .Fn nvlist_exists_null ,
557 .Fn nvlist_exists_bool ,
558 .Fn nvlist_exists_number ,
559 .Fn nvlist_exists_string ,
560 .Fn nvlist_exists_nvlist ,
561 .Fn nvlist_exists_descriptor ,
562 .Fn nvlist_exists_binary ,
563 .Fn nvlist_exists_bool_array ,
564 .Fn nvlist_exists_number_array ,
565 .Fn nvlist_exists_string_array ,
566 .Fn nvlist_exists_nvlist_array ,
567 .Fn nvlist_exists_descriptor_array
570 if element of the given name and the given type determined by the function name
574 The nvlist must not be in error state.
577 .Fn nvlist_add_null ,
578 .Fn nvlist_add_bool ,
579 .Fn nvlist_add_number ,
580 .Fn nvlist_add_string ,
581 .Fn nvlist_add_stringf ,
582 .Fn nvlist_add_stringv ,
583 .Fn nvlist_add_nvlist ,
584 .Fn nvlist_add_descriptor ,
585 .Fn nvlist_add_binary ,
586 .Fn nvlist_add_bool_array ,
587 .Fn nvlist_add_number_array ,
588 .Fn nvlist_add_string_array ,
589 .Fn nvlist_add_nvlist_array ,
590 .Fn nvlist_add_descriptor_array
591 functions add element to the given nvlist.
592 When adding string or binary buffer the functions will allocate memory
593 and copy the data over.
594 When adding nvlist, the nvlist will be cloned and clone will be added.
595 When adding descriptor, the descriptor will be duplicated using the
597 system call and the new descriptor will be added.
598 The array functions will fail if there are any
600 elements in the array, or if the array pointer is
602 If an error occurs while adding new element, internal error is set which can be
608 .Fn nvlist_move_string ,
609 .Fn nvlist_move_nvlist ,
610 .Fn nvlist_move_descriptor ,
611 .Fn nvlist_move_binary ,
612 .Fn nvlist_move_bool_array ,
613 .Fn nvlist_move_number_array ,
614 .Fn nvlist_move_string_array ,
615 .Fn nvlist_move_nvlist_array ,
616 .Fn nvlist_move_descriptor_array
617 functions add new element to the given nvlist, but unlike
618 .Fn nvlist_add_<type>
619 functions they will consume the given resource.
620 In the case of strings, descriptors, or nvlists every elements must be
621 unique, or it could cause a double free.
622 The array functions will fail if there are any
624 elements, or if the array pointer is
626 If an error occurs while adding new element, the resource is destroyed and
627 internal error is set which can be examined using the
632 .Fn nvlist_get_bool ,
633 .Fn nvlist_get_number ,
634 .Fn nvlist_get_string ,
635 .Fn nvlist_get_nvlist ,
636 .Fn nvlist_get_descriptor ,
637 .Fn nvlist_get_binary ,
638 .Fn nvlist_get_bool_array ,
639 .Fn nvlist_get_number_array ,
640 .Fn nvlist_get_string_array ,
641 .Fn nvlist_get_nvlist_array ,
642 .Fn nvlist_get_descriptor_array
643 functions return the value that corresponds to the given key name.
644 In the case of strings, nvlists, descriptors, binary, or arrays, the returned
645 resource should not be modified - they still belong to the nvlist.
646 If an element of the given name does not exist, the program will be aborted.
647 To avoid this, the caller should check for the existence of the name before
648 trying to obtain the value, or use the
650 extension, which can provide a default value in the case of a missing element.
651 The nvlist must not be in error state.
654 .Fn nvlist_get_parent
655 function returns the parent nvlist of the nested nvlist.
658 .Fn nvlist_get_array_next
659 function returns the next element from the array or
661 if the nvlist is not in array or it is the last element.
663 .Fn nvlist_get_array_next
664 only works if you added the nvlist array using the
665 .Fn nvlist_move_nvlist_array
667 .Fn nvlist_add_nvlist_array
671 .Fn nvlist_get_pararr
672 function returns the next element in the array, or if not available
673 the parent of the nested nvlist.
676 .Fn nvlist_take_bool ,
677 .Fn nvlist_take_number ,
678 .Fn nvlist_take_string ,
679 .Fn nvlist_take_nvlist ,
680 .Fn nvlist_take_descriptor ,
681 .Fn nvlist_take_binary ,
682 .Fn nvlist_take_bool_array ,
683 .Fn nvlist_take_number_array ,
684 .Fn nvlist_take_string_array ,
685 .Fn nvlist_take_nvlist_array ,
686 .Fn nvlist_take_descriptor_array
687 functions return value associated with the given name and remove the element
689 In case of string and binary values, the caller is responsible for free returned
693 In case of nvlist, the caller is responsible for destroying returned nvlist
697 In case of descriptor, the caller is responsible for closing returned descriptor
701 If an element of the given name does not exist, the program will be aborted.
702 To avoid that the caller should check for the existence of the given name
703 before trying to obtain the value, or use the
705 extension, which can provide a default value in the case of a missing element.
706 In the case of an array of strings or binary values, the caller is responsible
707 for freeing every element of the array using the
710 In the case of an array of nvlists, the caller is responsible for destroying
711 every element of array using the
714 In the case of descriptors, the caller is responsible for closing every
715 element of array using the
718 In every case involving an array, the caller must also free the pointer to
722 The nvlist must not be in error state.
725 .Fn nvlist_append_bool_array ,
726 .Fn nvlist_append_number_array ,
727 .Fn nvlist_append_string_array ,
728 .Fn nvlist_append_nvlist_array ,
729 .Fn nvlist_append_descriptor_array
730 functions append an element to the existing array using the same semantics
731 as the add functions (i.e. the element will be copied when applicable).
732 If the array for a given key does not exist, then it will be created
734 .Fn nvlist_add_<type>_array
736 The internal error is set on append failure.
740 function removes element of the given name from the nvlist (besides of its type)
741 and frees all resources associated with it.
742 If element of the given name does not exist, the program will be aborted.
743 The nvlist must not be in error state.
747 function removes element of the given name and the given type from the nvlist
748 and frees all resources associated with it.
749 If element of the given name and the given type does not exist, the program
751 The nvlist must not be in error state.
754 .Fn nvlist_free_null ,
755 .Fn nvlist_free_bool ,
756 .Fn nvlist_free_number ,
757 .Fn nvlist_free_string ,
758 .Fn nvlist_free_nvlist ,
759 .Fn nvlist_free_descriptor ,
760 .Fn nvlist_free_binary ,
761 .Fn nvlist_free_bool_array ,
762 .Fn nvlist_free_number_array ,
763 .Fn nvlist_free_string_array ,
764 .Fn nvlist_free_nvlist_array ,
765 .Fn nvlist_free_descriptor_array
766 functions remove element of the given name and the given type determined by the
767 function name from the nvlist and free all resources associated with it.
768 If element of the given name and the given type does not exist, the program
770 The nvlist must not be in error state.
776 functions handle the byte-order conversions, so the binary buffer can be
777 packed/unpacked by the hosts with the different endianness.
779 The following example demonstrates how to prepare an nvlist and send it over
786 fd = open("/tmp/foo", O_RDONLY);
788 err(1, "open(\\"/tmp/foo\\") failed");
790 nvl = nvlist_create(0);
792 * There is no need to check if nvlist_create() succeeded,
793 * as the nvlist_add_<type>() functions can cope.
794 * If it failed, nvlist_send() will fail.
796 nvlist_add_string(nvl, "filename", "/tmp/foo");
797 nvlist_add_number(nvl, "flags", O_RDONLY);
799 * We just want to send the descriptor, so we can give it
800 * for the nvlist to consume (that's why we use nvlist_move
803 nvlist_move_descriptor(nvl, "fd", fd);
804 if (nvlist_send(sock, nvl) < 0) {
806 err(1, "nvlist_send() failed");
811 Receiving nvlist and getting data:
818 nvl = nvlist_recv(sock, 0);
820 err(1, "nvlist_recv() failed");
822 /* For command we take pointer to nvlist's buffer. */
823 command = nvlist_get_string(nvl, "command");
825 * For filename we remove it from the nvlist and take
826 * ownership of the buffer.
828 filename = nvlist_take_string(nvl, "filename");
829 /* The same for the descriptor. */
830 fd = nvlist_take_descriptor(nvl, "fd");
832 printf("command=%s filename=%s fd=%d\n", command, filename, fd);
837 /* command was freed by nvlist_destroy() */
840 Iterating over nvlist:
847 nvl = nvlist_recv(sock, 0);
849 err(1, "nvlist_recv() failed");
852 while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
856 printf("%ju", (uintmax_t)nvlist_get_number(nvl, name));
859 printf("%s", nvlist_get_string(nvl, name));
869 Iterating over every nested nvlist:
876 nvl = nvlist_recv(sock, 0);
878 err(1, "nvlist_recv() failed");
882 while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
883 if (type == NV_TYPE_NVLIST) {
884 nvl = nvlist_get_nvlist(nvl, name);
888 } while ((nvl = nvlist_get_parent(nvl, &cookie)) != NULL);
891 Iterating over every nested nvlist and every nvlist element:
894 const nvlist_t * const *array;
899 nvl = nvlist_recv(sock, 0);
901 err(1, "nvlist_recv() failed");
905 while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
906 if (type == NV_TYPE_NVLIST) {
907 nvl = nvlist_get_nvlist(nvl, name);
909 } else if (type == NV_TYPE_NVLIST_ARRAY) {
910 nvl = nvlist_get_nvlist_array(nvl, name, NULL)[0];
914 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
920 const nvlist_t * const *array;
925 nvl = nvlist_recv(sock, 0);
927 err(1, "nvlist_recv() failed");
934 while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
935 if (type == NV_TYPE_NVLIST) {
936 nvl = nvlist_get_nvlist(nvl,
939 } else if (type == NV_TYPE_NVLIST_ARRAY) {
940 nvl = nvlist_get_nvlist_array(nvl, name,
946 } while ((tmp = nvlist_get_array_next(nvl)) != NULL);
947 } while ((tmp = nvlist_get_parent(nvl, &cookie)) != NULL);
966 library was implemented by
967 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
968 under sponsorship from the FreeBSD Foundation.