Tools to work with “struct sockaddr”
Overview
Definition of test API for working with struct sockaddr. More…
// enums enum tapi_address_type; // global functions uint16_t tapi_get_random_port(void); te_errno tapi_allocate_port(struct rcf_rpc_server* pco, uint16_t* p_port); te_errno tapi_allocate_port_range(struct rcf_rpc_server* pco, uint16_t* p_port, int num); te_errno tapi_allocate_port_htons(rcf_rpc_server* pco, uint16_t* p_port); uint16_t tapi_get_port(rcf_rpc_server* rpcs); static uint16_t tapi_get_port_htons(rcf_rpc_server* rpcs); static te_errno tapi_sockaddr_clone(rcf_rpc_server* pco, const struct sockaddr* src, struct sockaddr_storage* dst); static void tapi_sockaddr_clone_exact(const struct sockaddr* src, struct sockaddr_storage* dst); struct sockaddr* tapi_sockaddr_clone_typed(const struct sockaddr* addr, tapi_address_type type); te_errno tapi_allocate_set_port(rcf_rpc_server* rpcs, const struct sockaddr* addr); static int tapi_sockaddr_cmp(const struct sockaddr* addr1, const struct sockaddr* addr2); te_errno tapi_sockaddr_clone2(const struct sockaddr* src, struct sockaddr** dst); // macros #define TAPI_ADDRESS_TYPE #define TEST_GET_TYPED_ADDR(_base_addr, _type_arg, _res_addr)
Detailed Documentation
Definition of test API for working with struct sockaddr.
Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.
Global Functions
uint16_t tapi_get_random_port(void)
Get a random port number from a range where conflicts with other applications are unlikely.
You should check for yourself whether retrieved port is free on your host.
Returns:
Port number in host byte order.
te_errno tapi_allocate_port(struct rcf_rpc_server* pco, uint16_t* p_port)
Retrieve unused in system port in host order.
Parameters:
pco |
RPC server to check that port is free |
p_port |
Location for allocated port |
Returns:
Status code.
See also:
te_errno tapi_allocate_port_range(struct rcf_rpc_server* pco, uint16_t* p_port, int num)
Retrieve range of ports unused in system, in host order.
Parameters:
pco |
RPC server to check that port is free |
p_port |
Location for allocated ports, pointer to array, should have enough place for |
num |
Number of ports requests, i.e. length of range. |
Returns:
Status code.
te_errno tapi_allocate_port_htons(rcf_rpc_server* pco, uint16_t* p_port)
Retrieve unused in system port in network order.
Parameters:
pco |
RPC server to check that port is free |
p_port |
Location for allocated port |
Returns:
Status code.
See also:
uint16_t tapi_get_port(rcf_rpc_server* rpcs)
Retrieve unused in system port in host order. It calls tapi_allocate_port() to get a port, but unlike that function it jumps to cleanup on failure.
Parameters:
rpcs |
RPC server to check that port is free. |
Returns:
Port number.
See also:
tapi_get_port_htons, tapi_allocate_port
static uint16_t tapi_get_port_htons(rcf_rpc_server* rpcs)
Retrieve unused in system port in network order.
It jumps to cleanup on failure.
Parameters:
rpcs |
RPC server to check that port is free. |
Returns:
Port number.
See also:
tapi_get_port, tapi_allocate_port_htons
static te_errno tapi_sockaddr_clone(rcf_rpc_server* pco, const struct sockaddr* src, struct sockaddr_storage* dst)
Generate new sockaddr basing on existing one (copy data and allocate new port).
Parameters:
pco |
RPC server to check that port is free |
src |
existing sockaddr |
dst |
location for new sockaddr |
Returns:
Status code.
static void tapi_sockaddr_clone_exact(const struct sockaddr* src, struct sockaddr_storage* dst)
Obtain an exact copy of a given socket address.
Parameters:
src |
existing sockaddr |
dst |
location for a clone |
Returns:
Status code.
struct sockaddr* tapi_sockaddr_clone_typed(const struct sockaddr* addr, tapi_address_type type)
Get address of the specified type based on addr
. New address instance is allocated from the heap.
Parameters:
addr |
Base address - port is copied from it. |
type |
Required address type. |
Returns:
Pointer to the address of the specified type.
te_errno tapi_allocate_set_port(rcf_rpc_server* rpcs, const struct sockaddr* addr)
Allocate a free port and set it to addr
.
Parameters:
rpcs |
RPC server handle. |
addr |
Address to set the new port. |
Returns:
Status code.
static int tapi_sockaddr_cmp(const struct sockaddr* addr1, const struct sockaddr* addr2)
Compair the content of two ‘struct sockaddr’ structures.
Parameters:
addr1 |
The first address |
addr2 |
The second address |
0 |
equal |
-1 |
not equal |
-2 |
comparison of addresses of unsupported family |
Returns:
The comparison result:
te_errno tapi_sockaddr_clone2(const struct sockaddr* src, struct sockaddr** dst)
Allocate memory of sockaddr_storage size and copy src
data to there. dst
should be released with free(3)
when it is no longer needed.
Parameters:
src |
Existing sockaddr. |
dst |
Copy of sockaddr. |
Returns:
Status code.
Macros
#define TAPI_ADDRESS_TYPE
Address types list, can be passed to macro TEST_GET_ENUM_PARAM.
#define TEST_GET_TYPED_ADDR(_base_addr, _type_arg, _res_addr)
Get address type and allocate required address.
Parameters:
_base_addr |
Pointer to the base address. |
_type_arg |
Variable to get address type. |
_res_addr |
Ponter to save the requested address. |