riot_sys

Function coap_opt_get_next

Source
pub unsafe extern "C" fn coap_opt_get_next(
    pkt: *const coap_pkt_t,
    opt: *mut coap_optpos_t,
    value: *mut *mut u8,
    init_opt: bool,
) -> ssize_t
Expand description

@brief Iterate over a packet’s options

To start iteration from the first option, set @p init_opt to true. To start iteration from a specific option, set @p init_opt to false, set @p opt->offset to the offset of the desired option from pkt->hdr, and @p opt->opt_num as required. See below for how @p opt->opt_num is modified.

With each invocation, this function returns the length of the option value and sets @p value to point to the start of the value. The value for @p opt->opt_num is increased by the delta in the option number value over the preceding option in the packet. So, @p opt->opt_num is accurate if iteration started with the first option. Otherwise, it is useful for identification of repeated options. Finally, @p opt->offset is set to the offset for any following option, to prepare for the next iteration.

The end of the options is indicated by a -ENOENT return value. In this case @p value and @p opt are unchanged from their input values.

@param[in] pkt packet to read from @param[in,out] opt option attributes; read on input if @p init_opt is false @param[out] value start of the option value @param[in] init_opt true to retrieve first option; false to retrieve option at opt->offset

@return length of option value @return -ENOENT if option not found