Files | |
file | cb_inet.h |
Bindings to POSIX network IP layer functions. | |
Data Structures | |
struct | cb_inetaddr_t |
Network address encapsulation structure for IPv4 or IPv6 address This structure is used to encapsulation of address type such that the implementation does not need to have separate containers for IPv4 and IPv6 address. It now supports either AF_INET or AF_INET6 network addresses. This structure may not hold both address type at a given time. Dual-stack implementation must assume that IPv4 can be effective in parallel with IPv6 address, thus it is expected that the the implementation uses two instances of this structure/. More... | |
struct | cb_inetaddr_map_t |
Network address to socket address mapping This structure is used to store mapping between network address and socket address. More... | |
Functions | |
CB_ADDRINFO_T * | cb_name_to_addrinfo (int family, int socktype, const char *name, int port, bool numeric_only) |
Converts a name or ip address and port into CB_ADDRINFO_T. More... | |
int | cb_sockaddr_to_ipaddr (CB_SOCKADDR_T *sa, CB_SOCKLEN_T salen, char *ip, size_t ip_size, int *port) |
Translates socket address structure to IP address. More... | |
int | cb_addrinfo_to_ipaddr (const CB_ADDRINFO_T *ai, char *ip, size_t ip_size, int *port) |
Translate socket information to IP address. More... | |
bool | cb_is_multicast_addr (CB_SOCKADDR_T *addr) |
Checks if the proveded socket address is a multicast address. More... | |
Macros | |
#define | CB_ADDRINFO_T struct addrinfo |
#define | CB_GETADDRINFO getaddrinfo |
#define | CB_FREEADDRINFO freeaddrinfo |
#define | CB_ADDRINFO_AI_FAMILY(x) ((x)->ai_family) |
#define | CB_ADDRINFO_AI_SOCKTYPE(x) ((x)->ai_socktype) |
#define | CB_ADDRINFO_AI_ADDR(x) ((x)->ai_addr) |
#define | CB_ADDRINFO_AI_ADDRLEN(x) ((x)->ai_addrlen) |
#define | CB_ADDRINFO_SA_FAMILY(x) ((x)->ai_addr->sa_family) |
#define | CB_SOCKADDR_SA_FAMILY(x) ((x)->sa_family) |
#define | CB_SOCKADDR_IN_ADDR(x) (((CB_SOCKADDR_IN_T *)(x))->sin_addr.s_addr) |
#define | CB_SOCKADDR_IN6_ADDR(x) (((CB_SOCKADDR_IN6_T *)(x))->sin6_addr) |
#define | CB_SOCK_BIND bind |
#define | CB_GETSOCKNAME getsockname |
#define | CB_GETNAMEINFO getnameinfo |
#define | CB_ADDRINFO_FOREACH_ITER(list, node) (node) = (list); (node); (node) = (node)->ai_next |
Traverse CB_ADDRINFO_T. More... | |
#define CB_ADDRINFO_T struct addrinfo |
#define CB_GETADDRINFO getaddrinfo |
#define CB_FREEADDRINFO freeaddrinfo |
#define CB_ADDRINFO_AI_FAMILY | ( | x | ) | ((x)->ai_family) |
#define CB_ADDRINFO_AI_SOCKTYPE | ( | x | ) | ((x)->ai_socktype) |
#define CB_ADDRINFO_AI_ADDR | ( | x | ) | ((x)->ai_addr) |
#define CB_ADDRINFO_AI_ADDRLEN | ( | x | ) | ((x)->ai_addrlen) |
#define CB_ADDRINFO_SA_FAMILY | ( | x | ) | ((x)->ai_addr->sa_family) |
#define CB_SOCKADDR_SA_FAMILY | ( | x | ) | ((x)->sa_family) |
#define CB_SOCKADDR_IN_ADDR | ( | x | ) | (((CB_SOCKADDR_IN_T *)(x))->sin_addr.s_addr) |
#define CB_SOCKADDR_IN6_ADDR | ( | x | ) | (((CB_SOCKADDR_IN6_T *)(x))->sin6_addr) |
#define CB_SOCK_BIND bind |
#define CB_GETSOCKNAME getsockname |
#define CB_GETNAMEINFO getnameinfo |
#define CB_ADDRINFO_FOREACH_ITER | ( | list, | |
node | |||
) | (node) = (list); (node); (node) = (node)->ai_next |
Traverse CB_ADDRINFO_T.
CB_ADDRINFO_T* cb_name_to_addrinfo | ( | int | family, |
int | socktype, | ||
const char * | name, | ||
int | port, | ||
bool | numeric_only | ||
) |
Converts a name or ip address and port into CB_ADDRINFO_T.
family | address protocol family type |
socktype | preferred socket type |
name | name of the service |
port | port number of the service |
numeric_only | filter result to include numeric hosts only |
Pasing CB_AF_INET6 ensures that the list of CB_ADDRINFO_T returned are IPv6 address. Otherwise passing CB_AF_UNSPEC leads to unspecified results, caller need to confirm the results.
Note that this function allocates CB_ADDRINFO_T, the caller needs to perform CB_FREEADDRIINFO afterwards.
int cb_sockaddr_to_ipaddr | ( | CB_SOCKADDR_T * | sa, |
CB_SOCKLEN_T | salen, | ||
char * | ip, | ||
size_t | ip_size, | ||
int * | port | ||
) |
Translates socket address structure to IP address.
sa | socket address structure |
salen | socket address structure length |
ip | buffer for the resulting IP address |
ip_size | size of the buffer |
port | resulting port number |
int cb_addrinfo_to_ipaddr | ( | const CB_ADDRINFO_T * | ai, |
char * | ip, | ||
size_t | ip_size, | ||
int * | port | ||
) |
Translate socket information to IP address.
ai | a ponter to an address information |
ip | buffer for the resulting IP address |
ip_size | size of the buffer |
port | resulting port number |
bool cb_is_multicast_addr | ( | CB_SOCKADDR_T * | addr | ) |
Checks if the proveded socket address is a multicast address.
addr | socket address container |