ndn-lite
Data Structures | Typedefs | Functions
Forwarder helper

Some helper functions used by the forwarder. More...

Collaboration diagram for Forwarder helper:

Data Structures

struct  interest_options
 Interest options which the forwarder cares. More...
 

Typedefs

typedef struct interest_options interest_options_t
 Interest options which the forwarder cares. More...
 

Functions

size_t tlv_get_tlvar (uint8_t *buf, size_t buflen, uint32_t *var)
 Get the first variable of type or length from a TLV encoded form. More...
 
uint8_t * tlv_get_type_length (uint8_t *buf, size_t buflen, uint32_t *type, uint32_t *length)
 Get type and length from a TLV encoded form. More...
 
int tlv_check_type_length (uint8_t *buf, size_t buflen, uint32_t type)
 Check the type and length of a TLV block. More...
 
int tlv_interest_get_header (uint8_t *interest, size_t buflen, interest_options_t *options, uint8_t **name, size_t *name_len)
 Get the name and options of an Interest packet. More...
 
int tlv_data_get_name (uint8_t *data, size_t buflen, uint8_t **name, size_t *name_len)
 Get the name of a Data packet. More...
 
uint8_t * tlv_interest_get_hoplimit_ptr (uint8_t *interest, size_t buflen)
 Get the pointer to hop limit field of a Interest packet. More...
 
uint64_t tlv_get_uint (uint8_t *buf, size_t buflen)
 Decode an unsigned integer value. More...
 

Detailed Description

Some helper functions used by the forwarder.

Typedef Documentation

◆ interest_options_t

Interest options which the forwarder cares.

Currently only used in the forwarder.

Function Documentation

◆ tlv_check_type_length()

int tlv_check_type_length ( uint8_t *  buf,
size_t  buflen,
uint32_t  type 
)

Check the type and length of a TLV block.

Parameters
[in]buf[Optional] The buffer containing the TLV block.
[in]buflenThe length of buf.
[in]typeThe required type.
Return values
NDN_SUCCESSThe check succeeds.
NDN_INVALID_POINTERThe buf is NULL.
NDN_OVERSIZE_VAREither type of length in buf is truncated or malicious.
NDN_WRONG_TLV_TYPEThe type of buf is different from type.
NDN_WRONG_TLV_LENGTHThe length of buf is different from length.
Note
This function will kindly check buf != NULL.

◆ tlv_data_get_name()

int tlv_data_get_name ( uint8_t *  data,
size_t  buflen,
uint8_t **  name,
size_t *  name_len 
)

Get the name of a Data packet.

Parameters
[in]dataThe Data packet.
[in]buflenThe length of data.
[out]nameA pointer to the name in data.
[out]name_lenThe length of name.
Return values
NDN_SUCCESSThe operation succeeds.
NDN_OVERSIZE_VAREither type of length in buf is truncated or malicious.
NDN_WRONG_TLV_TYPEThe type of buf is not TLV_Data.
NDN_WRONG_TLV_LENGTHThe length of buf is different from length.
NDN_UNSUPPORTED_FORMATThe first element of interest is not TLV_Name.

◆ tlv_get_tlvar()

size_t tlv_get_tlvar ( uint8_t *  buf,
size_t  buflen,
uint32_t *  var 
)

Get the first variable of type or length from a TLV encoded form.

Parameters
[in]bufThe buffer containing the TLV encoded form.
[in]buflenThe length of buf.
[out]varThe decoded value.
Returns
If the function succeeds, return the size var takes. If the function fails, return 0.

◆ tlv_get_type_length()

uint8_t* tlv_get_type_length ( uint8_t *  buf,
size_t  buflen,
uint32_t *  type,
uint32_t *  length 
)

Get type and length from a TLV encoded form.

Parameters
[in]bufThe buffer containing the TLV encoded form.
[in]buflenThe length of buf.
[out]typeThe decoded type.
[out]lengthThe decoded length.
Returns
If the function succeeds, return a pointer to its content. If the function fails, return NULL.

◆ tlv_get_uint()

uint64_t tlv_get_uint ( uint8_t *  buf,
size_t  buflen 
)

Decode an unsigned integer value.

Parameters
[in]bufBuffer pointing to the value, not including T and L.
[in]buflenThe length of buf.
Returns
The value.

◆ tlv_interest_get_header()

int tlv_interest_get_header ( uint8_t *  interest,
size_t  buflen,
interest_options_t options,
uint8_t **  name,
size_t *  name_len 
)

Get the name and options of an Interest packet.

Parameters
[in]interestThe Interest packet.
[in]buflenThe length of interest.
[out]options[Optional] Options of interest.
[out]nameA pointer to the name in interest.
[out]name_lenThe length of name.
Return values
NDN_SUCCESSThe operation succeeds.
NDN_OVERSIZE_VAREither type of length in buf is truncated or malicious.
NDN_WRONG_TLV_TYPEThe type of buf is not TLV_Interest.
NDN_WRONG_TLV_LENGTHThe length of buf is different from length.
NDN_UNSUPPORTED_FORMATThe first element of interest is not TLV_Name.

◆ tlv_interest_get_hoplimit_ptr()

uint8_t* tlv_interest_get_hoplimit_ptr ( uint8_t *  interest,
size_t  buflen 
)

Get the pointer to hop limit field of a Interest packet.

Parameters
[in]interestThe Interest packet.
[in]buflenThe length of interest.
Returns
If the function succeeds, return a pointer to the hop limit. If interest doesn't contain a hop limit field, return NULL.
Precondition
tlv_interest_get_header should succeed for interest.