1084 lines
40 KiB
C
1084 lines
40 KiB
C
/*
|
|
******************************************************************************
|
|
* HEADER FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_util.h,v $ $Revision: 1.24.10.6 $
|
|
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike_util.h,v $
|
|
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:26 $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
#ifndef IPIKE_UTIL_H
|
|
#define IPIKE_UTIL_H
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
|
|
#include "ipike_config.h"
|
|
#include "ipike.h"
|
|
#include "ipike_isakmp.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
typedef struct Ipike_string_int_map_struct
|
|
{
|
|
const char* key;
|
|
int value;
|
|
}
|
|
Ipike_string_int_map;
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_are_cookies_equal
|
|
*===========================================================================
|
|
* Description: Compares the cookies for equality.
|
|
* Parameters: cookie1 - a IPIKE_ISAKMP_COOKIE_SIZE byte cookie.
|
|
* cookie2 - a IPIKE_ISAKMP_COOKIE_SIZE byte cookie.
|
|
* Returns: IP_TRUE if the cookies are equal. IP_TRUE if cookie 2 is the
|
|
* zero cookie. IP_FALSE otherwise.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_are_cookies_equal(const Ip_u8 cookie1[IPIKE_ISAKMP_COOKIE_SIZE],
|
|
const Ip_u8 cookie2[IPIKE_ISAKMP_COOKIE_SIZE]);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_are_values_equal
|
|
*===========================================================================
|
|
* Description: Compares the values for equality.
|
|
* Parameters: val1 - a binary value.
|
|
* val2 - a binary value.
|
|
* Returns: IP_TRUE if the sizes are equal and each octet are equal.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_are_values_equal(const Ipike_value* val1, const Ipike_value* val2);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_set_value
|
|
*===========================================================================
|
|
* Description: Copies a binary value. The dest buffer will not be freed if
|
|
* the buffer pointer is not IP_NULL.
|
|
* Parameters: destination - pointer to the destnation value.
|
|
* source - pointer to the source value..
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_set_value(Ipike_value* destination, const Ipike_value* source);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_cpy_value
|
|
*===========================================================================
|
|
* Description: Copies a binary value. The dest buffer will be freed if the
|
|
* buffer pointer is not IP_NULL.
|
|
* Parameters: destination - pointer to the destination value.
|
|
* source - pointer to the source value.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_cpy_value(Ipike_value *destination, const Ipike_value *source);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_swap_value
|
|
*===========================================================================
|
|
* Description: Swaps the content inside v1 and v2.
|
|
* Parameters: v1 - value
|
|
* v2 - value
|
|
* Returns: -
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_swap_value(Ipike_value *v1, Ipike_value *v2);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_set_data
|
|
*===========================================================================
|
|
* Description: Copies a binary value. The dest buffer will not be freed if
|
|
* the buffer pointer is not IP_NULL.
|
|
* Parameters: destination - pointer to the destnation value.
|
|
* data - pointer to the data value buffer.
|
|
* len - length of data buffer.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
#ifdef IPCOM_USE_DMALLOC
|
|
IP_GLOBAL Ipike_error
|
|
ipike_set_data_debug(Ipike_value *destination, const void *data, Ip_size_t len, const char *file, const char *function, Ip_u32 line);
|
|
#define ipike_set_data(dest,data,len) ipike_set_data_debug(dest,data,len, __FILE__, __FUNCTION__, __LINE__)
|
|
#else
|
|
IP_GLOBAL Ipike_error
|
|
ipike_set_data(Ipike_value *destination, const void *data, Ip_size_t len);
|
|
#endif
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_cpy_data
|
|
*===========================================================================
|
|
* Description: Copies a binary value. The dest buffer will be freed if the
|
|
* buffer pointer is not IP_NULL.
|
|
* Parameters: destination - pointer to the destnation value.
|
|
* data - pointer to the data value buffer.
|
|
* len - length of data buffer.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
#ifdef IPCOM_USE_DMALLOC
|
|
IP_GLOBAL Ipike_error
|
|
ipike_cpy_data_debug(Ipike_value *destination, const void *data, Ip_size_t len, const char *file, const char *function, Ip_u32 line);
|
|
#define ipike_cpy_data(dest,data,len) ipike_cpy_data_debug(dest,data,len, __FILE__, __FUNCTION__, __LINE__)
|
|
#else
|
|
IP_GLOBAL Ipike_error
|
|
ipike_cpy_data(Ipike_value *destination, const void *data, Ip_size_t len);
|
|
#endif
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_append_value
|
|
*===========================================================================
|
|
* Description: Appends a binary value from the source to the destination
|
|
* buffer.
|
|
* Parameters: destination - pointer to the destnation value.
|
|
* source - pointer to the source value..
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_append_value(Ipike_value* destination, const Ipike_value* source);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_append_value
|
|
*===========================================================================
|
|
* Description: Appends a binary value from the source to the destination
|
|
* buffer.
|
|
* Parameters: destination - pointer to the destnation value.
|
|
* data - pointer to the data value buffer.
|
|
* len - length of data buffer.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_append_data(Ipike_value* destination, const void* data, Ip_size_t len);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_is_zero_cookie
|
|
*===========================================================================
|
|
* Description: Tests if all octets in the cookie is zero.
|
|
* Parameters: cookie - a IPIKE_ISAKMP_COOKIE_SIZE byte cookie.
|
|
* Returns: IP_TRUE if all octets in the cookie is zero.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_is_zero_cookie(const Ip_u8 cookie[IPIKE_ISAKMP_COOKIE_SIZE]);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_cookie_to_string
|
|
*===========================================================================
|
|
* Description: Returns a string representation of a cookie.
|
|
* Parameters: cookie - a IPIKE_ISAKMP_COOKIE_SIZE byte cookie.
|
|
* Returns: A string representation of the passed cookie.
|
|
*
|
|
*/
|
|
IP_GLOBAL const char*
|
|
ipike_cookie_to_string(const Ip_u8 cookie[IPIKE_ISAKMP_COOKIE_SIZE]);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_memory_to_string
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the specified memory area.
|
|
* Parameters: ptr - pointer to a memory area.
|
|
* size - the number of bytes that should be returned as a string.
|
|
* alignment - number of bytes before a space is inserted.
|
|
* Returns: A string representation of the specified memory area. Must
|
|
* be freed with ipcom_free.
|
|
*
|
|
*/
|
|
IP_GLOBAL char*
|
|
ipike_memory_to_string(const Ip_u8* ptr, Ip_size_t size, Ip_u8 alignment);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_print_memory
|
|
*===========================================================================
|
|
* Description: Prints the content of the specified memory to the system
|
|
* log.
|
|
* Parameters: priority - the priority level to use when logging this message.
|
|
* prefix - text string to write before the memory content.
|
|
* data - pointer to the memory are to log.
|
|
* len - the length of the memory content.
|
|
* Returns: IPIKE_SUCCESSS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_print_memory(Ip_u32 priority, const char* prefix, const Ip_u8* data, Ip_size_t len);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_add
|
|
*===========================================================================
|
|
* Description: Adds an element to a IP_NULL terminated array of pointers to
|
|
* elem_type. The memory for elem must have been allocated with
|
|
* ipcom_malloc, ipcom_calloc or ipcom_realloc.
|
|
* Parameters: array - a pointer to the array. A new array is created if
|
|
* *array is IP_NULL.
|
|
* elem - the element to add. Note! Adding the element to the
|
|
* array also transfers the ownership of the memory pointed to
|
|
* by elem to the array. The elem memory will be freed when
|
|
* ipike_array_free is called or if this function failes.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
* IPIKE_TRIED_TO_ADD_NULL
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_add(void*** array, void* elem);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_remove
|
|
*===========================================================================
|
|
* Description: Remove an element from an IP_NULL terminated array of
|
|
* pointers to elem_type. The memory for elem must have been
|
|
* allocated with ipcom_malloc, ipcom_calloc or ipcom_realloc.
|
|
* Parameters: array - a pointer to the array. A new array is created if
|
|
* *array is IP_NULL.
|
|
* elem - the element to add. Note! Adding the element to the
|
|
* array also transfers the ownership of the memory pointed to
|
|
* by elem to the array. The elem memory will be freed with the
|
|
* function free_func.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_array_remove(void*** array, void* elem, void(*free_func)(void*));
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_size
|
|
*===========================================================================
|
|
* Description: Returns the number of elements in the array.
|
|
* Parameters: array - the array to return the length for.
|
|
* Returns: The array length.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_u32
|
|
ipike_array_size(void** array);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_free
|
|
*===========================================================================
|
|
* Description: Frees all memory allocated by the array, including the memory
|
|
* allocated by the elements.
|
|
* Parameters: array - the array to free.
|
|
* free_func - A function that will be called to free each element.
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_array_free(void** array, void(*free_func)(void*));
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_free_elements
|
|
*===========================================================================
|
|
* Description: Frees all array elements only, leave array pointer as it is
|
|
* Parameters: array - the array to free.
|
|
* free_func - A function that will be called to free each element.
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_array_free_elements(void*** array, void(*free_func)(void*));
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_add_u8
|
|
*===========================================================================
|
|
* Description: Add an u8 number to array of numbers
|
|
* Parameters: n - the number to add
|
|
* array - the array to add to.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_add_u8(Ip_u8 n, Ip_u8*** array);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_add_u32
|
|
*===========================================================================
|
|
* Description: Add an u32 number to array of numbers
|
|
* Parameters: n - the number to add
|
|
* array - the array to add to.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_add_u32(Ip_u32 n, Ip_u32*** array);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_add_u64
|
|
*===========================================================================
|
|
* Description: Add an u64 number to array of numbers
|
|
* Parameters: n - the number to add
|
|
* array - the array to add to.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_add_u64(Ip_u64 n, Ip_u64*** array);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_copy_u32
|
|
*===========================================================================
|
|
* Description: Copy array of u32 numbers
|
|
* Parameters: array_dst - the destination array
|
|
* array_src - the source array
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_copy_u32(Ip_u32*** array_dst, Ip_u32** array_src);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_array_copy_u64
|
|
*===========================================================================
|
|
* Description: Copy array of u64 numbers
|
|
* Parameters: array_dst - the destination array
|
|
* array_src - the source array
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_OUT_OF_MEMORY
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_array_copy_u64(Ip_u64*** array_dst, Ip_u64** array_src);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_map_int
|
|
*===========================================================================
|
|
* Description: Sets the 'value' variable to the integer corresponding to
|
|
* the 'key' string in the map.
|
|
* Parameters: map - An array of string to int mappings, the array must be
|
|
* terminated with a Ipike_string_int_map element where the
|
|
* the key is set to IP_NULL.
|
|
* key - A key in the map, must not be IP_NULL.
|
|
* value - Will contain the value if the call was successful.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_VALUE_NOT_FOUND
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_map_int(const Ipike_string_int_map map[], const char* key, int* value);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_map_string
|
|
*===========================================================================
|
|
* Description: Sets the 'value' variable to the string corresponding to
|
|
* the key integer in the map.
|
|
* Parameters: map - An array of string to int mappings, the array must be
|
|
* terminated with a Ipike_string_int_map element where the
|
|
* the key is set to IP_NULL.
|
|
* key - A integer.
|
|
* value - Will contain the string if the call was successful,
|
|
* must not be IP_NULL.
|
|
* Returns: IPIKE_SUCCESS
|
|
* IPIKE_VALUE_NOT_FOUND
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_map_string(const Ipike_string_int_map map[], int key, const char** value);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_strvec
|
|
*===========================================================================
|
|
* Description: Creates tokens of the input string and returns them as a
|
|
* IP_NULL terminated string. s="DES,IDEA", token="," ->
|
|
* { "DES", "IDEA", IP_NULL }
|
|
* Parameters: s - A string that should be tokentized.
|
|
* delimiter - A string containing all character that
|
|
* Returns: A IP_NULL terminated array of tokens or IP_NULL if out of memory.
|
|
* The caller must release the array returned using
|
|
* ipike_array_free.
|
|
*/
|
|
IP_GLOBAL char**
|
|
ipike_strvec(const char* s, const char* delimiter);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_addr_to_str
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the address in static
|
|
* buffer that must NOT be freed.
|
|
* Parameters: addr - The address to return a string for.
|
|
* Returns: A string representation.
|
|
*/
|
|
IP_GLOBAL const char*
|
|
ipike_addr_to_str(const union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_addr_to_str_buf
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the address
|
|
* Parameters: addr - The address to return a string for.
|
|
* buf - Pointer to buffer that will receive string
|
|
* size - Size of buffer
|
|
* Returns: A string representation.
|
|
*/
|
|
IP_GLOBAL const char*
|
|
ipike_addr_to_str_buf(
|
|
const union Ip_sockaddr_union* addr,
|
|
char* buf,
|
|
Ip_size_t size);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_subnet_to_str
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the subnet in static
|
|
* buffer that must NOT be freed.
|
|
* Parameters: addr - The address to return a string for.
|
|
* mask - The subnet mask.
|
|
* Returns: A string representation.
|
|
*/
|
|
IP_GLOBAL const char*
|
|
ipike_addr_subnet_to_str(
|
|
const union Ip_sockaddr_union* addr,
|
|
const union Ip_sockaddr_union* mask);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_subnet_to_str_buf
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the subnet.
|
|
* Parameters: addr - The address to return a string for.
|
|
* mask - The subnet mask.
|
|
* buf - Pointer to buffer that will receive string
|
|
* size - Size of buffer
|
|
* Returns: A string representation.
|
|
*/
|
|
IP_GLOBAL const char*
|
|
ipike_addr_subnet_to_str_buf(
|
|
const union Ip_sockaddr_union* addr,
|
|
const union Ip_sockaddr_union* mask,
|
|
char* buf,
|
|
Ip_size_t size);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_subnet_to_str_buf
|
|
*===========================================================================
|
|
* Description: Returns a string representation of the range of address.
|
|
* Parameters: low - The lower address limit
|
|
* high - The higher address limit.
|
|
* buf - Pointer to buffer that will receive string
|
|
* size - Size of buffer
|
|
* Returns: A string representation.
|
|
*/
|
|
IP_GLOBAL const char *
|
|
ipike_addr_range_to_str_buf(
|
|
const union Ip_sockaddr_union* low,
|
|
const union Ip_sockaddr_union* high,
|
|
char* buf,
|
|
Ip_size_t size);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_addr_compare
|
|
*===========================================================================
|
|
* Description: Compares two IP addresses.
|
|
* Parameters: addr1 - The lower address limit
|
|
* addr2 - The higher address limit.
|
|
* Returns: 1 if addr1 is higher than addr2
|
|
* -1 if addr1 is lower than addr2
|
|
* 0 if addresses are equal
|
|
*/
|
|
IP_GLOBAL int
|
|
ipike_addr_compare(
|
|
const union Ip_sockaddr_union* addr1,
|
|
const union Ip_sockaddr_union* addr2);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_match_socket
|
|
*===========================================================================
|
|
* Description: Returns if the socket is bound to the specific address.
|
|
* Parameters: bind_addr - The address the socket should be tested for.
|
|
* sock - Socket to test.
|
|
*
|
|
* Returns: IP_TRUE if the socket is bound to the specified address.
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_match_socket(union Ip_sockaddr_union *bind_addr, int sock);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_are_addr_equal
|
|
*===========================================================================
|
|
* Description: Compares 2 socket addresses for equality.
|
|
* Parameters: a1 -
|
|
* a2 -
|
|
* Returns: IP_TRUE if the addresses are equal.
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_are_equal(
|
|
const union Ip_sockaddr_union* a1,
|
|
const union Ip_sockaddr_union* a2);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_are_addr_and_port_equal
|
|
*===========================================================================
|
|
* Description: Compares 2 socket addresses with ports for equality.
|
|
* Parameters: a1 -
|
|
* a2 -
|
|
* Returns: IP_TRUE if the addresses are equal.
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_are_equal_port(
|
|
const union Ip_sockaddr_union* a1,
|
|
const union Ip_sockaddr_union* a2);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_get_addr_ptr
|
|
*===========================================================================
|
|
* Description: Returns the address where the family address is stored.
|
|
* Parameters: addr - socket address
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void *
|
|
ipike_addr_get_ptr(union Ip_sockaddr_union* addr);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_get_addr_len
|
|
*===========================================================================
|
|
* Description: Returns the length of address buffer where the family address
|
|
* is stored.
|
|
* Parameters: addr - socket address
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ip_u8
|
|
ipike_addr_get_len(const union Ip_sockaddr_union *addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_is_zero_addr
|
|
*===========================================================================
|
|
* Description: Returns IP_TRUE if zero address, i.e. 0.0.0.0.
|
|
* Parameters: addr - socket address
|
|
* Returns: IP_TRUE or IP_FALSE
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_is_zero(union Ip_sockaddr_union *addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_set_address
|
|
*===========================================================================
|
|
* Description: Set ip address for address structure
|
|
* Parameters: ip - ip address as ipv4 or ipv6 string representation
|
|
* addr - address structure that will be filled with the ip
|
|
* address.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_set(union Ip_sockaddr_union* addr, const char* ip);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_set_address_from_data
|
|
*===========================================================================
|
|
* Description: Set ip address for address structure
|
|
* Parameters: data - data buffer with ip4 or ip6 address
|
|
* len - length of data buffer
|
|
* addr - address structure that will be filled with the ip
|
|
* address.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_set_from_data(Ip_u8* data, Ip_size_t len, union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_append_address_from_data
|
|
*===========================================================================
|
|
* Description: Set ip address for address structure and append to list
|
|
* Parameters: data - data buffer with ip4 or ip6 address
|
|
* len - length of data buffer
|
|
* list - list of address structures that will be filled with the ip
|
|
* address.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_append_from_data(Ip_u8* data, Ip_size_t len, union Ip_sockaddr_union*** list);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_set_port
|
|
*===========================================================================
|
|
* Description: Set ip port for address structure
|
|
* Parameters: addr - address structure that will be filled with the ip
|
|
* address.
|
|
* port - port number to set.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_addr_set_port(union Ip_sockaddr_union* addr, Ip_u16 port);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_addr_get_port
|
|
*===========================================================================
|
|
* Description: Return ip port for address structure
|
|
* Parameters: addr - address structure that have the ip port.
|
|
* Returns: ip port if successful and 0 if fails.
|
|
*/
|
|
IP_GLOBAL Ip_u16
|
|
ipike_addr_get_port(const union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_copy_address
|
|
*===========================================================================
|
|
* Description: Copy source address to destination address structure.
|
|
* Parameters: addr1 - destination address.
|
|
* addr2 - source address.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_copy(
|
|
union Ip_sockaddr_union* addr1,
|
|
const union Ip_sockaddr_union* addr2);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_has_valid_address
|
|
*===========================================================================
|
|
* Description: Return IP_TRUE if the specified address is valid.
|
|
* Parameters: addr - ip address.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_is_valid(const union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_address_network_match
|
|
*===========================================================================
|
|
* Description: Return TRUE if ip address match the network and netmask.
|
|
* Parameters: address - an ip address.
|
|
* network - an ip network
|
|
* netmask - an ip netmask
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_match_network(
|
|
union Ip_sockaddr_union* address,
|
|
union Ip_sockaddr_union* network,
|
|
union Ip_sockaddr_union* netmask);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_address_network_match
|
|
*===========================================================================
|
|
* Description: Return TRUE if addr is within the range between
|
|
* low and high.
|
|
* Parameters: addr - IP address.
|
|
* low - Lower IP address
|
|
* high - Higher IP address
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_match_range(
|
|
const union Ip_sockaddr_union* addr,
|
|
const union Ip_sockaddr_union* low,
|
|
const union Ip_sockaddr_union* high);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_address_range_to_mask
|
|
*===========================================================================
|
|
* Description: Convert address range to address with mask. addr should
|
|
* contain address start and mask should contain addr end.
|
|
* Parameters:
|
|
*
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_range_to_mask(
|
|
union Ip_sockaddr_union* addr,
|
|
union Ip_sockaddr_union* mask);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_address_mask_to_range
|
|
*===========================================================================
|
|
* Description: Convert address mask to address with ange. addr will
|
|
* get address start and mask will get addr end.
|
|
* Parameters:
|
|
*
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_mask_to_range(
|
|
union Ip_sockaddr_union* addr,
|
|
union Ip_sockaddr_union* mask);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_apply_network_mask
|
|
*===========================================================================
|
|
* Description: Apply network mask to address.
|
|
* Parameters: addr - the network address
|
|
* mask - the network mask
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_apply_network_mask(
|
|
union Ip_sockaddr_union* addr,
|
|
union Ip_sockaddr_union* mask);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_load_subnet
|
|
*===========================================================================
|
|
* Description: Load address and mask structure with the given network.
|
|
* Parameters: network - the given network
|
|
* addr - the returned address
|
|
* mask - the returned netmask
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_load_subnet(
|
|
const char* network,
|
|
union Ip_sockaddr_union* addr,
|
|
union Ip_sockaddr_union* mask);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_create_mask ( Thank you IPNET !)
|
|
*===========================================================================
|
|
* Description: Creates a network mask with the 'netbits' leftmost bits set.
|
|
* Parameters: [in] mask - Pointer to a buffer where the mask should be stored.
|
|
* [in] netbits - The number of set bits.
|
|
* [in] inverse - create inverse of netmask if true
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_addr_create_mask(
|
|
void *mask,
|
|
int netbits,
|
|
Ip_bool inverse);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_addr_increment_v6
|
|
*===========================================================================
|
|
* Description: Given an v6 address and mask increments it
|
|
* Parameters: [in] address - v6 address
|
|
* [in] prefixlen - v6 prefix
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_addr_increment_v6(
|
|
union Ip_sockaddr_union *address,
|
|
int prefixlen);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_to_lower_string
|
|
*===========================================================================
|
|
* Description: Convert string to lower.
|
|
* Parameters:
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_to_lower_string(char* str);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_hex2bin
|
|
*===========================================================================
|
|
* Description: Convert hexadecmial to binary value. The binary value will be
|
|
* allocated and returned.
|
|
* Parameters: value - the null terminated hexadicaml value.
|
|
* len - will contain length of binary data on successful return
|
|
* Returns: The binary value or null if failure.
|
|
*/
|
|
IP_GLOBAL Ip_u8*
|
|
ipike_hex2bin(const char* value, Ip_size_t* len);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_bin2hex
|
|
*===========================================================================
|
|
* Description: Convert binary to hexadecmial value. The value buffer will be
|
|
* null terminated and must be big enough.
|
|
* Parameters: buf - buffer with the binary value.
|
|
* len - length of binary buffer
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_bin2hex(unsigned char* buf, Ip_size_t len, char* value);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_write_file
|
|
*===========================================================================
|
|
* Description: Write buffer content to file.
|
|
* Parameters: filename - File to write to.
|
|
* buf - Buffer with data to be written.
|
|
* buf_len - Length of data buffer.
|
|
* Returns: IPIKE_SUCCESS, IPIKE_FAILED
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_write_file(const char* filename, Ip_u8* buf, Ip_size_t buf_len);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_read_file
|
|
*===========================================================================
|
|
* Description: Read file content and to buffer.
|
|
* Parameters: filename - File to write to.
|
|
* buf - Poniter to buffer that will be allocated with data
|
|
* content from file.
|
|
* buf_len - Length of data buffer.
|
|
* Returns: IPIKE_SUCCESS, IPIKE_FAILED
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_read_file(const char* filename, Ip_u8** buf, Ip_size_t* buf_len);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_tmo2_cancel
|
|
*===========================================================================
|
|
* Description: Same as ipcom_tmo2_cancel, but with more error handling.
|
|
* Parameters: tmo - The same Ipcom_tmo timeout handle that was given
|
|
* upon requesting the timeout.
|
|
* Returns:
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_tmo2_cancel(Ipcom_tmo2 *tmo);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_get_if_addr
|
|
*===========================================================================
|
|
* Description: Get primary ip address from interface.
|
|
* Parameters: name - Interface name, set to IP_NULL to get first available
|
|
* interface.
|
|
* Returns: IP_TRUE if successful (else IP_FALSE)
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_get_if_addr(const char* name, union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_add_delete_address
|
|
*===========================================================================
|
|
* Description: Add/Delete ip address from interface.
|
|
* Parameters: add - Set to IP_TRUE for add address (IP_FALSE for delete)
|
|
* ifname - Interface name, set to IP_NULL to get first available
|
|
* interface.
|
|
* addr - The ip address to set
|
|
* netmask - The ip netmask to set
|
|
* Returns: IPIKE_SUCCESS, IPIKE_FAILED
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_add_delete_address(
|
|
Ip_bool add,
|
|
const char *ifname,
|
|
union Ip_sockaddr_union *addr,
|
|
union Ip_sockaddr_union *netmask);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_validate_str
|
|
*===========================================================================
|
|
* Description: Checks if a string contains IP_NULL,{,} chrs
|
|
* Parameters: input - string to be verified
|
|
* ctx - prefix to error message
|
|
* Returns: IPIKE_SUCCESS, IPIKE_FAILED
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_validate_str(const char *input, char *ctx);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_is_any_addr
|
|
*===========================================================================
|
|
* Description: Returns true if address is an any address (:: or 0.0.0.0)
|
|
* Parameters: addr - IP address
|
|
* Returns: IP_TRUE or IP_FALSE
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_is_any(union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_is_host_mask
|
|
*===========================================================================
|
|
* Description: Returns true if the mask is an host mask (all ones).
|
|
* Parameters: addr - IP address
|
|
* Returns: IP_TRUE or IP_FALSE
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipike_addr_is_host_mask(union Ip_sockaddr_union* addr);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_util_str_is_hex
|
|
*===========================================================================
|
|
* Description: Returns true if the string can be interpreted as hexdecimal
|
|
* value, i.e. the string begins with '0x' and is only contain
|
|
* valid hexadecimal characters.
|
|
* Parameters: str - String to be examined
|
|
* Returns: IP or IP_FALSE
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_util_str_is_hex(const char *str);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_util_str_hex2bin
|
|
*===========================================================================
|
|
* Description: Converts a hexadecimal string to a binary value.
|
|
*
|
|
* Parameters: str - Hexadecimal string ('0x' prefix)
|
|
* len - length of the binary data
|
|
* Returns: Pointer to the binary value or IP_NULL
|
|
*/
|
|
IP_GLOBAL Ip_u8*
|
|
ipike_util_str_hex2bin(const char *str, Ip_size_t *len);
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_time_diff_sec
|
|
*===========================================================================
|
|
* Description: Returns the time difference t1 - t2 seconds (rounded up or down).
|
|
* Parameters: t1 - Time 1
|
|
* t1 - Time 2
|
|
* Returns: The time difference t1 - t2 in seconds
|
|
*/
|
|
IP_GLOBAL long
|
|
ipike_time_diff_sec(
|
|
const struct Ip_timeval * t1,
|
|
const struct Ip_timeval * t2);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_time
|
|
*===========================================================================
|
|
* Description: Returns current time in seconds based on the monotonic clock
|
|
* Parameters:
|
|
* Returns: Current time
|
|
*/
|
|
IP_GLOBAL long
|
|
ipike_time(void);
|
|
|
|
#endif
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|