From 0d737de882bbdaaa726552f9dae19aa402eb7ce6 Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Fri, 24 Aug 2018 20:32:14 +0800 Subject: [PATCH 1/3] [net][at] Modify AT Socket log information, fix at_freeaddrinfo() implement --- components/net/at/at_socket/at_socket.c | 80 +++++++++++++------------ components/net/at/at_socket/at_socket.h | 2 +- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 3580df957b..a95c7aec53 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -36,10 +36,9 @@ #ifdef DBG_SECTION_NAME #undef DBG_SECTION_NAME -#define DBG_SECTION_NAME "[AT_SOC] " +#define DBG_SECTION_NAME "AT_SOC" #endif - #define HTONS_PORT(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8)) #define NIPQUAD(addr) \ ((unsigned char *)&addr)[0], \ @@ -89,7 +88,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) at_recv_pkt_t pkt; pkt = (at_recv_pkt_t) rt_calloc(1, sizeof(struct at_recv_pkt)); - if (!pkt) + if (pkt == RT_NULL) { LOG_E("No memory for receive packet table!"); return 0; @@ -340,7 +339,7 @@ int at_socket(int domain, int type, int protocol) /* allocate and initialize a new AT socket */ sock = alloc_socket(); - if(!sock) + if(sock == RT_NULL) { LOG_E("Allocate a new AT socket failed!"); return RT_NULL; @@ -381,14 +380,16 @@ int at_closesocket(int socket) struct at_socket *sock; enum at_socket_state last_state; - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return -1; } - if ((sock = at_get_socket(socket)) == RT_NULL) + sock = at_get_socket(socket); + if (sock == RT_NULL) + { return -1; + } last_state = sock->state; @@ -410,14 +411,16 @@ int at_shutdown(int socket, int how) { struct at_socket *sock; - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return -1; } - if ((sock = at_get_socket(socket)) == RT_NULL) + sock = at_get_socket(socket); + if (sock == RT_NULL) + { return -1; + } if (sock->state == AT_SOCKET_CONNECT) { @@ -434,7 +437,9 @@ int at_bind(int socket, const struct sockaddr *name, socklen_t namelen) { if (at_get_socket(socket) == RT_NULL) + { return -1; + } return 0; } @@ -470,7 +475,8 @@ static void at_recv_notice_cb(int socket, at_socket_evt_t event, const char *buf RT_ASSERT(bfsz); RT_ASSERT(event == AT_SOCKET_EVT_RECV); - if ((sock = at_get_socket(socket)) == RT_NULL) + sock = at_get_socket(socket); + if (sock == RT_NULL) return ; /* put receive buffer to receiver packet list */ @@ -506,14 +512,13 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen) char ipstr[16] = { 0 }; int result = 0; - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return -1; } sock = at_get_socket(socket); - if (!sock) + if (sock == RT_NULL) { result = -1; goto __exit; @@ -560,21 +565,19 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f int result = 0; size_t recv_len = 0; - if (!mem || len == 0) + if (mem == RT_NULL || len == 0) { LOG_E("AT recvfrom input data or length error!"); - result = -1; - goto __exit; + return -1; } - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return -1; } sock = at_get_socket(socket); - if (!sock) + if (sock == RT_NULL) { result = -1; goto __exit; @@ -686,14 +689,13 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct struct at_socket *sock; int len, result = 0; - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); result = -1; goto __exit; } - if (!data || size == 0) + if (data == RT_NULL || size == 0) { LOG_E("AT sendto input data or size error!"); result = -1; @@ -701,7 +703,7 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct } sock = at_get_socket(socket); - if (!sock) + if (sock == RT_NULL) { result = -1; goto __exit; @@ -780,14 +782,14 @@ int at_getsockopt(int socket, int level, int optname, void *optval, socklen_t *o struct at_socket *sock; int32_t timeout; - if (!optval || !optlen) + if (optval == RT_NULL || optlen == RT_NULL) { LOG_E("AT getsocketopt input option value or option length error!"); return -1; } sock = at_get_socket(socket); - if (!sock) + if (sock == RT_NULL) { return -1; } @@ -827,14 +829,14 @@ int at_setsockopt(int socket, int level, int optname, const void *optval, sockle { struct at_socket *sock; - if (!optval) + if (optval == RT_NULL) { LOG_E("AT setsockopt input option value error!"); return -1; } sock = at_get_socket(socket); - if (!sock) + if (sock == RT_NULL) { return -1; } @@ -923,15 +925,14 @@ struct hostent *at_gethostbyname(const char *name) static char s_hostname[DNS_MAX_NAME_LENGTH + 1]; size_t idx = 0; - if (!name) + if (name == RT_NULL) { LOG_E("AT gethostbyname input name error!"); return RT_NULL; } - if (!at_dev_ops) + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return RT_NULL; } @@ -983,12 +984,13 @@ int at_getaddrinfo(const char *nodename, const char *servname, { return EAI_FAIL; } - if (!at_dev_ops) + *res = RT_NULL; + + if (at_dev_ops == RT_NULL) { - LOG_E("Please register AT device socket options first!"); return EAI_FAIL; } - *res = RT_NULL; + if ((nodename == RT_NULL) && (servname == RT_NULL)) { return EAI_NONAME; @@ -1085,10 +1087,10 @@ int at_getaddrinfo(const char *nodename, const char *servname, struct sockaddr_in *sa4 = (struct sockaddr_in *) sa; /* set up sockaddr */ sa4->sin_addr.s_addr = addr.u_addr.ip4.addr; - sa4->sin_family = AF_AT; + sa4->sin_family = AF_INET; sa4->sin_len = sizeof(struct sockaddr_in); sa4->sin_port = htons((u16_t )port_nr); - ai->ai_family = AF_AT; + ai->ai_family = AF_INET; /* set up addrinfo */ if (hints != RT_NULL) @@ -1114,9 +1116,13 @@ int at_getaddrinfo(const char *nodename, const char *servname, void at_freeaddrinfo(struct addrinfo *ai) { - if (ai != RT_NULL) + struct addrinfo *next; + + while (ai != NULL) { + next = ai->ai_next; rt_free(ai); + ai = next; } } diff --git a/components/net/at/at_socket/at_socket.h b/components/net/at/at_socket/at_socket.h index 612078522d..8e90609082 100644 --- a/components/net/at/at_socket/at_socket.h +++ b/components/net/at/at_socket/at_socket.h @@ -144,7 +144,7 @@ void at_scoket_device_register(const struct at_device_ops *ops); #ifndef RT_USING_SAL #define socket(domain, type, protocol) at_socket(domain, type, protocol) -#define closescoket(socket) at_closesocket(socket) +#define closesocket(socket) at_closesocket(socket) #define shutdown(socket, how) at_shutdown(socket, how) #define bind(socket, name, namelen) at_bind(socket, name, namelen) #define connect(socket, name, namelen) at_connect(socket, name, namelen) From 192b17751868b4aa9a95ad34bb90dcd54071e5df Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Fri, 24 Aug 2018 20:39:10 +0800 Subject: [PATCH 2/3] [at][sal] Add query and unregistered protocol family functions --- components/net/sal_socket/SConscript | 3 + components/net/sal_socket/impl/af_inet.h | 40 ++++++ components/net/sal_socket/impl/af_inet_at.c | 2 + components/net/sal_socket/impl/af_inet_lwip.c | 2 + components/net/sal_socket/include/sal.h | 13 +- components/net/sal_socket/socket/net_netdb.c | 1 + components/net/sal_socket/src/sal_socket.c | 130 ++++++++++++++---- 7 files changed, 159 insertions(+), 32 deletions(-) create mode 100644 components/net/sal_socket/impl/af_inet.h diff --git a/components/net/sal_socket/SConscript b/components/net/sal_socket/SConscript index 76becca09f..3dcb5c3fe4 100644 --- a/components/net/sal_socket/SConscript +++ b/components/net/sal_socket/SConscript @@ -16,6 +16,9 @@ if GetDepend('SAL_USING_LWIP'): if GetDepend('SAL_USING_AT'): src += Glob('impl/af_inet_at.c') + +if GetDepend('SAL_USING_LWIP') or GetDepend('SAL_USING_AT'): + CPPPATH += [cwd + '/impl'] if GetDepend('SAL_USING_POSIX'): src += Glob('dfs_net/*.c') diff --git a/components/net/sal_socket/impl/af_inet.h b/components/net/sal_socket/impl/af_inet.h new file mode 100644 index 0000000000..10a77d5871 --- /dev/null +++ b/components/net/sal_socket/impl/af_inet.h @@ -0,0 +1,40 @@ +/* + * File : af_inet.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2018-08-25 ChenYong First version + */ + +#ifndef __AF_INET_H__ +#define __AF_INET_H__ + +#include + +#ifdef SAL_USING_LWIP +/* lwIP protocol family register */ +int lwip_inet_init(void); +#endif + +#ifdef SAL_USING_AT +/* AT protocol family register */ +int at_inet_init(void); +#endif + +#endif /* __AF_INET_H__ */ diff --git a/components/net/sal_socket/impl/af_inet_at.c b/components/net/sal_socket/impl/af_inet_at.c index 8ddb236e84..3337af4194 100644 --- a/components/net/sal_socket/impl/af_inet_at.c +++ b/components/net/sal_socket/impl/af_inet_at.c @@ -26,6 +26,7 @@ #include #include +#include #ifdef SAL_USING_POSIX #include @@ -107,6 +108,7 @@ static int at_create(struct sal_socket *socket, int type, int protocol) } static const struct proto_family at_inet_family_ops = { + "at", AF_AT, AF_INET, at_create, diff --git a/components/net/sal_socket/impl/af_inet_lwip.c b/components/net/sal_socket/impl/af_inet_lwip.c index deb9239bf4..c45e39e39e 100644 --- a/components/net/sal_socket/impl/af_inet_lwip.c +++ b/components/net/sal_socket/impl/af_inet_lwip.c @@ -34,6 +34,7 @@ #endif #include +#include #if LWIP_VERSION < 0x2000000 #define SELWAIT_T int @@ -284,6 +285,7 @@ static int inet_create(struct sal_socket *socket, int type, int protocol) } static const struct proto_family lwip_inet_family_ops = { + "lwip", AF_INET, AF_INET, inet_create, diff --git a/components/net/sal_socket/include/sal.h b/components/net/sal_socket/include/sal.h index 8a9dd61b67..e1a6dbedba 100644 --- a/components/net/sal_socket/include/sal.h +++ b/components/net/sal_socket/include/sal.h @@ -82,8 +82,9 @@ struct sal_socket struct proto_family { - int family; /* primary protocol families type*/ - int sec_family; /* secondary protocol families type*/ + char name[RT_NAME_MAX]; + int family; /* primary protocol families type */ + int sec_family; /* secondary protocol families type */ int (*create)(struct sal_socket *sal_socket, int type, int protocol); /* register socket options */ struct hostent* (*gethostbyname) (const char *name); @@ -92,10 +93,14 @@ struct proto_family int (*getaddrinfo) (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); }; -/* SAL socket initialization */ +/* SAL(Socket Abstraction Layer) initialize */ int sal_init(void); -int sal_proto_family_register(const struct proto_family *pf); struct sal_socket *sal_get_socket(int sock); +/* protocol family register and unregister operate */ +int sal_proto_family_register(const struct proto_family *pf); +int sal_proto_family_unregister(const struct proto_family *pf); +struct proto_family *sal_proto_family_find(const char *name); + #endif /* SAL_H__ */ diff --git a/components/net/sal_socket/socket/net_netdb.c b/components/net/sal_socket/socket/net_netdb.c index 5acab36403..1f10afe337 100644 --- a/components/net/sal_socket/socket/net_netdb.c +++ b/components/net/sal_socket/socket/net_netdb.c @@ -38,6 +38,7 @@ int gethostbyname_r(const char *name, struct hostent *ret, char *buf, { return sal_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); } +RTM_EXPORT(gethostbyname_r); void freeaddrinfo(struct addrinfo *ai) { diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index 71aaa2c658..920ce720c2 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -50,7 +50,7 @@ static struct rt_mutex sal_core_lock; static rt_bool_t init_ok = RT_FALSE; /** - * SAL (Socket Abstraction Layer) initialization. + * SAL (Socket Abstraction Layer) initialize. * * @return result * >= 0: initialize success @@ -64,7 +64,7 @@ int sal_init(void) } /* clean sal socket table */ - memset(&socket_table, 0, sizeof(socket_table)); + rt_memset(&socket_table, 0, sizeof(socket_table)); /* create sal socket lock */ rt_mutex_init(&sal_core_lock, "sal_lock", RT_IPC_FLAG_FIFO); @@ -76,12 +76,12 @@ int sal_init(void) INIT_COMPONENT_EXPORT(sal_init); /** - * this function will register the current protocol family to the global array of protocol families. + * This function will register protocol family to the global array of protocol families. * - * @param pf protocol families structure + * @param pf protocol family object * - * @return 0 : protocol families structure index - * -1 : the global array of available protocol families is full + * @return >=0 : protocol family object index + * -1 : the global array of available protocol families is full */ int sal_proto_family_register(const struct proto_family *pf) { @@ -91,6 +91,18 @@ int sal_proto_family_register(const struct proto_family *pf) /* disable interrupt */ level = rt_hw_interrupt_disable(); + /* check protocol family is already registered */ + for(idx = 0; idx < SAL_PROTO_FAMILIES_NUM; idx++) + { + if(rt_strcmp(proto_families[idx].name, pf->name) == 0) + { + /* enable interrupt */ + rt_hw_interrupt_enable(level); + LOG_E("%s protocol family is already registered!", pf->name); + return -1; + } + } + /* find an empty protocol family entry */ for(idx = 0; idx < SAL_PROTO_FAMILIES_NUM && proto_families[idx].create; idx++); @@ -99,10 +111,10 @@ int sal_proto_family_register(const struct proto_family *pf) { /* enable interrupt */ rt_hw_interrupt_enable(level); - return -1; } + rt_strncpy(proto_families[idx].name, pf->name, rt_strlen(pf->name)); proto_families[idx].family = pf->family; proto_families[idx].sec_family = pf->sec_family; proto_families[idx].create = pf->create; @@ -119,11 +131,62 @@ int sal_proto_family_register(const struct proto_family *pf) } /** - * this function will get socket structure by sal socket descriptor + * This function removes a previously registered protocol family object. + * + * @param pf protocol family object + * + * @return >=0 : unregister protocol family index + * -1 : unregister failed + */ +int sal_proto_family_unregister(const struct proto_family *pf) +{ + int idx = 0; + + RT_ASSERT(pf != RT_NULL); + + for(idx = 0; idx < SAL_PROTO_FAMILIES_NUM; idx++) + { + if(rt_strcmp(proto_families[idx].name, pf->name) == 0) + { + rt_memset(&proto_families[idx], 0x00, sizeof(struct proto_family)); + + return idx; + } + } + + return -1; +} + +/** + * This function will get protocol family by name. + * + * @param name protocol family name + * + * @return protocol family object + */ +struct proto_family *sal_proto_family_find(const char *name) +{ + int idx = 0; + + RT_ASSERT(name != RT_NULL); + + for (idx = 0; idx < SAL_PROTO_FAMILIES_NUM; idx++) + { + if (rt_strcmp(proto_families[idx].name, name) == 0) + { + return &proto_families[idx]; + } + } + + return RT_NULL; +} + +/** + * This function will get sal socket object by sal socket descriptor. * * @param socket sal socket index * - * @return socket structure of the current sal socket index + * @return sal socket object of the current sal socket index */ struct sal_socket *sal_get_socket(int socket) { @@ -145,7 +208,7 @@ struct sal_socket *sal_get_socket(int socket) } /** - * this function will lock sal socket. + * This function will lock sal socket. * * @note please don't invoke it on ISR. */ @@ -161,7 +224,7 @@ static void sal_lock(void) } /** - * this function will lock sal socket. + * This function will lock sal socket. * * @note please don't invoke it on ISR. */ @@ -171,7 +234,7 @@ static void sal_unlock(void) } /** - * this function will get protocol family structure by family type + * This function will get protocol family structure by family type * * @param family protocol family * @@ -201,17 +264,17 @@ static struct proto_family *get_proto_family(int family) } /** - * this function will initialize socket structure and set socket options + * This function will initialize sal socket object and set socket options * * @param family protocol family * @param type socket type * @param protocol transfer Protocol - * @param res socket structure address + * @param res sal socket object address * * @return 0 : socket initialize success * -1 : input the wrong family * -2 : input the wrong socket type - * -3 : get protocol family structure failed + * -3 : get protocol family object failed * -4 : set socket options failed */ static int socket_init(int family, int type, int protocol, struct sal_socket **res) @@ -234,7 +297,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r sock->type = type; sock->protocol = protocol; - /* get socket protocol family structure */ + /* get socket protocol family object */ if ((pf = get_proto_family(family)) == RT_NULL) { return -3; @@ -301,11 +364,6 @@ __result: } -/** - * this function will return a empty sal socket structure address - * - * @return sal socket structure address - */ static int socket_new(void) { struct sal_socket *sock; @@ -415,7 +473,7 @@ int sal_shutdown(int socket, int how) if (sock->ops->shutdown((int) sock->user_data, how) == 0) { - memset(sock, 0x00, sizeof(struct sal_socket)); + rt_memset(sock, 0x00, sizeof(struct sal_socket)); return 0; } @@ -622,7 +680,7 @@ int sal_closesocket(int socket) if (sock->ops->closesocket((int) sock->user_data) == 0) { - memset(sock, 0x00, sizeof(struct sal_socket)); + rt_memset(sock, 0x00, sizeof(struct sal_socket)); return 0; } @@ -669,12 +727,18 @@ int sal_poll(struct dfs_fd *file, struct rt_pollreq *req) struct hostent *sal_gethostbyname(const char *name) { int i; + struct hostent *hst; for (i = 0; i < SAL_PROTO_FAMILIES_NUM; ++i) { if (proto_families[i].gethostbyname) { - return proto_families[i].gethostbyname(name); + hst = proto_families[i].gethostbyname(name); + if (hst != RT_NULL) + { + return hst; + } + continue; } } @@ -684,13 +748,18 @@ struct hostent *sal_gethostbyname(const char *name) int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) { - int i; + int i, res; for (i = 0; i < SAL_PROTO_FAMILIES_NUM; ++i) { if (proto_families[i].gethostbyname_r) { - return proto_families[i].gethostbyname_r(name, ret, buf, buflen, result, h_errnop); + res = proto_families[i].gethostbyname_r(name, ret, buf, buflen, result, h_errnop); + if (res == 0) + { + return res; + } + continue; } } @@ -716,13 +785,18 @@ int sal_getaddrinfo(const char *nodename, const struct addrinfo *hints, struct addrinfo **res) { - int i; + int i, ret; for (i = 0; i < SAL_PROTO_FAMILIES_NUM; ++i) { if (proto_families[i].getaddrinfo) { - return proto_families[i].getaddrinfo(nodename, servname, hints, res); + ret = proto_families[i].getaddrinfo(nodename, servname, hints, res); + if (ret == 0) + { + return ret; + } + continue; } } From fc73538153ff2e1b775b0357b0f8df6010a70493 Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Sat, 25 Aug 2018 21:04:11 +0800 Subject: [PATCH 3/3] [net][sal/at] Add components C++ support --- components/net/at/at_socket/at_socket.h | 8 ++++++++ components/net/at/include/at.h | 7 +++++++ components/net/sal_socket/impl/af_inet.h | 8 ++++++++ components/net/sal_socket/include/dfs_net/dfs_net.h | 4 ++-- components/net/sal_socket/include/sal.h | 8 ++++++++ components/net/sal_socket/include/sal_ipaddr.h | 4 ++++ components/net/sal_socket/include/sal_netdb.h | 8 ++++++++ components/net/sal_socket/include/sal_socket.h | 8 ++++++++ components/net/sal_socket/include/sal_type.h | 8 ++++++++ components/net/sal_socket/src/sal_socket.c | 3 --- 10 files changed, 61 insertions(+), 5 deletions(-) diff --git a/components/net/at/at_socket/at_socket.h b/components/net/at/at_socket/at_socket.h index 8e90609082..7d9ce91f39 100644 --- a/components/net/at/at_socket/at_socket.h +++ b/components/net/at/at_socket/at_socket.h @@ -32,6 +32,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef AT_SOCKET_RECV_BFSZ #define AT_SOCKET_RECV_BFSZ 512 #endif @@ -160,4 +164,8 @@ void at_scoket_device_register(const struct at_device_ops *ops); #endif /* RT_USING_SAL */ +#ifdef __cplusplus +} +#endif + #endif /* AT_SOCKET_H__ */ diff --git a/components/net/at/include/at.h b/components/net/at/include/at.h index d0040f86cf..1ef0388a65 100644 --- a/components/net/at/include/at.h +++ b/components/net/at/include/at.h @@ -27,6 +27,9 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #define AT_SW_VERSION "0.3.0" #define DBG_ENABLE @@ -251,4 +254,8 @@ void at_port_reset(void); void at_port_factory_reset(void); #endif +#ifdef __cplusplus +} +#endif + #endif /* __AT_H__ */ diff --git a/components/net/sal_socket/impl/af_inet.h b/components/net/sal_socket/impl/af_inet.h index 10a77d5871..8d6be25eaa 100644 --- a/components/net/sal_socket/impl/af_inet.h +++ b/components/net/sal_socket/impl/af_inet.h @@ -27,6 +27,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef SAL_USING_LWIP /* lwIP protocol family register */ int lwip_inet_init(void); @@ -37,4 +41,8 @@ int lwip_inet_init(void); int at_inet_init(void); #endif +#ifdef __cplusplus +} +#endif + #endif /* __AF_INET_H__ */ diff --git a/components/net/sal_socket/include/dfs_net/dfs_net.h b/components/net/sal_socket/include/dfs_net/dfs_net.h index 2a21fe3858..242d3c5334 100644 --- a/components/net/sal_socket/include/dfs_net/dfs_net.h +++ b/components/net/sal_socket/include/dfs_net/dfs_net.h @@ -26,12 +26,12 @@ #ifndef DFS_NET_H__ #define DFS_NET_H__ +#include + #ifdef __cplusplus extern "C" { #endif -#include - const struct dfs_file_ops* dfs_net_get_fops(void); int dfs_net_getsocket(int fd); diff --git a/components/net/sal_socket/include/sal.h b/components/net/sal_socket/include/sal.h index e1a6dbedba..62ffaa303e 100644 --- a/components/net/sal_socket/include/sal.h +++ b/components/net/sal_socket/include/sal.h @@ -28,6 +28,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) typedef uint32_t socklen_t; #endif @@ -103,4 +107,8 @@ int sal_proto_family_register(const struct proto_family *pf); int sal_proto_family_unregister(const struct proto_family *pf); struct proto_family *sal_proto_family_find(const char *name); +#ifdef __cplusplus +} +#endif + #endif /* SAL_H__ */ diff --git a/components/net/sal_socket/include/sal_ipaddr.h b/components/net/sal_socket/include/sal_ipaddr.h index 814d1d16e9..c40fc18374 100644 --- a/components/net/sal_socket/include/sal_ipaddr.h +++ b/components/net/sal_socket/include/sal_ipaddr.h @@ -26,6 +26,10 @@ #include "sal_type.h" +#ifdef __cplusplus +extern "C" { +#endif + /** IPv4 only: set the IP address given as an u32_t */ #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32)) /** IPv4 only: get the IP address as an u32_t */ diff --git a/components/net/sal_socket/include/sal_netdb.h b/components/net/sal_socket/include/sal_netdb.h index 12f7abe6b7..0a31f26fae 100644 --- a/components/net/sal_socket/include/sal_netdb.h +++ b/components/net/sal_socket/include/sal_netdb.h @@ -26,6 +26,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define EAI_NONAME 200 #define EAI_SERVICE 201 #define EAI_FAIL 202 @@ -88,4 +92,8 @@ int sal_getaddrinfo(const char *nodename, const struct addrinfo *hints, struct addrinfo **res); +#ifdef __cplusplus +} +#endif + #endif /* SAL_NETDB_H__ */ diff --git a/components/net/sal_socket/include/sal_socket.h b/components/net/sal_socket/include/sal_socket.h index 872fd5ca95..477112392c 100644 --- a/components/net/sal_socket/include/sal_socket.h +++ b/components/net/sal_socket/include/sal_socket.h @@ -27,6 +27,10 @@ #include "sal_ipaddr.h" +#ifdef __cplusplus +extern "C" { +#endif + #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) typedef uint32_t socklen_t; #endif @@ -175,4 +179,8 @@ int sal_socket(int domain, int type, int protocol); int sal_closesocket(int socket); int sal_ioctlsocket(int socket, long cmd, void *arg); +#ifdef __cplusplus +} +#endif + #endif /* SAL_SOCKET_H__ */ diff --git a/components/net/sal_socket/include/sal_type.h b/components/net/sal_socket/include/sal_type.h index 0446d5f4e1..907b3d02b4 100644 --- a/components/net/sal_socket/include/sal_type.h +++ b/components/net/sal_socket/include/sal_type.h @@ -28,6 +28,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + typedef int8_t err_t; typedef uint8_t u8_t; typedef int8_t s8_t; @@ -37,4 +41,8 @@ typedef uint32_t u32_t; typedef int32_t s32_t; typedef uintptr_t mem_ptr_t; +#ifdef __cplusplus +} +#endif + #endif /* SAL_TYPE_H__ */ diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index 920ce720c2..7b6683a69c 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -738,7 +738,6 @@ struct hostent *sal_gethostbyname(const char *name) { return hst; } - continue; } } @@ -759,7 +758,6 @@ int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf, { return res; } - continue; } } @@ -796,7 +794,6 @@ int sal_getaddrinfo(const char *nodename, { return ret; } - continue; } }