AM243x MCU+ SDK  09.00.00
cb_inet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Texas Instruments Incorporated
3  * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4  *
5  * All rights reserved not granted herein.
6  * Limited License.
7  *
8  * Texas Instruments Incorporated grants a world-wide, royalty-free,
9  * non-exclusive license under copyrights and patents it now or hereafter
10  * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11  * this software subject to the terms herein. With respect to the foregoing patent
12  * license, such license is granted solely to the extent that any such patent is necessary
13  * to Utilize the software alone. The patent license shall not apply to any combinations which
14  * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15  * No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce this license (including the
18  * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19  * in the documentation and/or other materials provided with the distribution
20  *
21  * Redistribution and use in binary form, without modification, are permitted provided that the following
22  * conditions are met:
23  *
24  * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25  * software provided in binary form.
26  * * any redistribution and use are licensed by TI for use only with TI Devices.
27  * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28  *
29  * If software source code is provided to you, modification and redistribution of the source code are permitted
30  * provided that the following conditions are met:
31  *
32  * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33  * TI for use only with TI Devices.
34  * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35  * works, are licensed by TI for use only with TI Devices.
36  *
37  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38  * promote products derived from this software without specific prior written permission.
39  *
40  * DISCLAIMER.
41  *
42  * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49 */
59 #ifndef CB_INET_H_
60 #define CB_INET_H_
61 
62 #ifdef CB_INET_NON_POSIX_H
63 /* non-posix platforms need to support necessary POSIX compatible
64  * functions and types which are defined as CB_* macros below.
65  * And provide them in a header file defined as CB_SOCKET_NON_POSIX_H */
66 #include CB_INET_NON_POSIX_H
67 #else
68 #include <sys/ioctl.h>
69 #include <sys/socket.h>
70 #include <sys/types.h>
71 #include <netinet/in.h>
72 #include <netdb.h>
73 
74 #define CB_ADDRINFO_T struct addrinfo
75 #define CB_GETADDRINFO getaddrinfo
76 #define CB_FREEADDRINFO freeaddrinfo
77 
78 #define CB_ADDRINFO_AI_FAMILY(x) ((x)->ai_family)
79 #define CB_ADDRINFO_AI_SOCKTYPE(x) ((x)->ai_socktype)
80 #define CB_ADDRINFO_AI_ADDR(x) ((x)->ai_addr)
81 #define CB_ADDRINFO_AI_ADDRLEN(x) ((x)->ai_addrlen)
82 #define CB_ADDRINFO_SA_FAMILY(x) ((x)->ai_addr->sa_family)
83 
84 #define CB_SOCKADDR_SA_FAMILY(x) ((x)->sa_family)
85 
86 #define CB_SOCKADDR_IN_ADDR(x)(((CB_SOCKADDR_IN_T *)(x))->sin_addr.s_addr)
87 #define CB_SOCKADDR_IN6_ADDR(x)(((CB_SOCKADDR_IN6_T *)(x))->sin6_addr)
88 
89 #define CB_SOCK_BIND bind
90 #define CB_GETSOCKNAME getsockname
91 #define CB_GETNAMEINFO getnameinfo
92 
96 #define CB_ADDRINFO_FOREACH_ITER(list, node) \
97  (node) = (list); (node); (node) = (node)->ai_next
98 
99 #endif // CB_INET_NON_POSIX_H
100 
110 typedef struct cb_inetaddr {
111  int family;
112  union {
115  } addr;
116  unsigned short port;
117 } cb_inetaddr_t;
118 
123 typedef struct cb_inetaddr_map {
126  uint64_t ts;
128 
142 CB_ADDRINFO_T * cb_name_to_addrinfo(int family, int socktype, const char *name, int port, bool numeric_only);
143 
154  size_t ip_size, int *port);
155 
164 int cb_addrinfo_to_ipaddr(const CB_ADDRINFO_T *ai, char *ip, size_t ip_size, int *port);
165 
166 
173 
174 #endif
175 
cb_addrinfo_to_ipaddr
int cb_addrinfo_to_ipaddr(const CB_ADDRINFO_T *ai, char *ip, size_t ip_size, int *port)
Translate socket information to IP address.
CB_ADDRINFO_T
#define CB_ADDRINFO_T
Definition: cb_inet.h:74
cb_inetaddr_map_t::ss
CB_SOCKADDR_STORAGE_T ss
Definition: cb_inet.h:124
cb_inetaddr_map_t::ts
uint64_t ts
Definition: cb_inet.h:126
cb_inetaddr_t
Network address encapsulation structure for IPv4 or IPv6 address This structure is used to encapsulat...
Definition: cb_inet.h:110
cb_is_multicast_addr
bool cb_is_multicast_addr(CB_SOCKADDR_T *addr)
Checks if the proveded socket address is a multicast address.
cb_sockaddr_to_ipaddr
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.
addr
uint64_t addr
Definition: csl_udmap_tr.h:3
cb_inetaddr_t::family
int family
Definition: cb_inet.h:111
cb_inetaddr_t::port
unsigned short port
Definition: cb_inet.h:116
cb_name_to_addrinfo
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.
cb_inetaddr_map_t
Network address to socket address mapping This structure is used to store mapping between network add...
Definition: cb_inet.h:123
CB_SOCKADDR_STORAGE_T
#define CB_SOCKADDR_STORAGE_T
Definition: cb_ethernet.h:89
cb_inetaddr_t::ip_inaddr
CB_IN_ADDR_T ip_inaddr
Definition: cb_inet.h:113
CB_SOCKLEN_T
#define CB_SOCKLEN_T
Definition: cb_ethernet.h:84
cb_inetaddr_map_t::addr
cb_inetaddr_t addr
Definition: cb_inet.h:125
CB_IN_ADDR_T
#define CB_IN_ADDR_T
Definition: cb_lld_ethernet.h:84
CB_IN6_ADDR_T
#define CB_IN6_ADDR_T
Definition: cb_ethernet.h:91
cb_inetaddr_t::ip6_inaddr
CB_IN6_ADDR_T ip6_inaddr
Definition: cb_inet.h:114
CB_SOCKADDR_T
#define CB_SOCKADDR_T
Definition: cb_ethernet.h:85