Core networking libraries including LwIP implementation
Dependencies: DebugLib Socket lwip lwip-sys
Fork of NetworkingCoreLib by
Revision 8:387f573a6813, committed 2012-06-15
- Comitter:
- donatien
- Date:
- Fri Jun 15 14:17:23 2012 +0000
- Parent:
- 7:cdd2b0f68b4f
- Child:
- 9:441d060c8861
- Child:
- 10:14ef6ceb4e75
- Commit message:
- Socket library change, lwip-sys update, IPInterface/LwIPInterface rework
Changed in this revision
--- a/Socket.lib Tue Jun 12 10:08:54 2012 +0000 +++ b/Socket.lib Fri Jun 15 14:17:23 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/Socket/#2b1ac3469583 +http://mbed.org/users/donatien/code/Socket/#bb32ac14d2a9
--- a/lwip-sys.lib Tue Jun 12 10:08:54 2012 +0000 +++ b/lwip-sys.lib Fri Jun 15 14:17:23 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/emilmont/code/lwip-sys/#10a79294ef07 +http://mbed.org/users/emilmont/code/lwip-sys/#6cf5ed7c538a
--- a/main/api/netdb.h Tue Jun 12 10:08:54 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* netdb.h */ -/* -Copyright (C) 2012 ARM Limited. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - -#ifndef NETDB_H_ -#define NETDB_H_ - -#include "lwip/netdb.h" - -//DNS - -inline struct hostent *gethostbyname(const char *name) -{ - return lwip_gethostbyname(name); -} - -inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) -{ - return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); -} - -inline void freeaddrinfo(struct addrinfo *ai) -{ - return lwip_freeaddrinfo(ai); -} - -inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) -{ - return lwip_getaddrinfo(nodename, servname, hints, res); -} - -#endif /* NETDB_H_ */
--- a/main/api/netinet/in.h Tue Jun 12 10:08:54 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* in.h */ -/* -Copyright (C) 2012 ARM Limited. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - -#ifndef IN_H_ -#define IN_H_ - -#include "lwip/inet.h" - -#endif /* IN_H_ */
--- a/main/api/sys/socket.h Tue Jun 12 10:08:54 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* socket.h */ -/* -Copyright (C) 2012 ARM Limited. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - -#ifndef SOCKET_H_ -#define SOCKET_H_ - -#include "lwip/sockets.h" - -//Sockets - -inline int accept(int s, struct sockaddr *addr, socklen_t *addrlen) -{ - return lwip_accept(s, addr, addrlen); -} - -inline int bind(int s, const struct sockaddr *name, socklen_t namelen) -{ - return lwip_bind(s, name, namelen); -} - -inline int shutdown(int s, int how) -{ - return lwip_shutdown(s, how); -} - -inline int getsockname (int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getsockname(s, name, namelen); -} - -inline int getpeername (int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getpeername(s, name, namelen); -} - -inline int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) -{ - return lwip_getsockopt(s, level, optname, optval, optlen); -} - -inline int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) -{ - return lwip_setsockopt(s, level, optname, optval, optlen); -} - -inline int connect(int s, const struct sockaddr *name, socklen_t namelen) -{ - return lwip_connect(s, name, namelen); -} - -inline int listen(int s, int backlog) -{ - return lwip_listen(s, backlog); -} - -inline int recv(int s, void *mem, size_t len, int flags) -{ - return lwip_recv(s, mem, len, flags); -} - -inline int recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) -{ - return lwip_recvfrom(s, mem, len, flags, from, fromlen); -} - -inline int send(int s, const void *dataptr, size_t size, int flags) -{ - return lwip_send(s, dataptr, size, flags); -} - -inline int sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) -{ - return lwip_sendto(s, dataptr, size, flags, to, tolen); -} - -inline int socket(int domain, int type, int protocol) -{ - return lwip_socket(domain, type, protocol); -} - -inline int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, - struct timeval *timeout) -{ - return lwip_select(maxfdp1, readset, writeset, exceptset, timeout); -} - -inline int ioctlsocket(int s, long cmd, void *argp) -{ - return lwip_ioctl(s, cmd, argp); -} - -inline int read(int s, void *mem, size_t len) -{ - return lwip_read(s, mem, len); -} - -inline int write(int s, const void *dataptr, size_t size) -{ - return lwip_write(s, dataptr, size); -} - -inline int close(int s) -{ - return lwip_close(s); -} - -#endif /* SOCKET_H_ */
--- a/main/if/IPInterface.h Tue Jun 12 10:08:54 2012 +0000 +++ b/main/if/IPInterface.h Fri Jun 15 14:17:23 2012 +0000 @@ -32,22 +32,22 @@ class IPInterface { public: - IPInterface(); - virtual ~IPInterface(); + IPInterface(); + virtual ~IPInterface(); - virtual int init() = 0; //Initialize interface; no connection should be performed at this stage - virtual int connect() = 0; //Do connect the interface - virtual int disconnect() = 0; - //It is encouraged that the derived class implement a "setup(...)" function to configure the interface before the connection + //int init(); //Initialize interface; no connection should be performed at this stage + //int connect(); //Do connect the interface + //int disconnect(); + //It is encouraged that the derived class implement a "setup(...)" function to configure the interface before the connection - static IPInterface* getDefaultInterface(); //For use by TCP, UDP sockets library + static IPInterface* getDefaultInterface(); //For use by TCP, UDP sockets library - //WARN: Implementation will have to be more careful in case of multiple interfaces (or implement a routing protocol based on local IP addresses differentiation) - void registerAsDefaultInterface(); //First come, first served - void unregisterAsDefaultInterface(); //Must be called before inst is destroyed to avoid invalid ptr fault + //WARN: Implementation will have to be more careful in case of multiple interfaces (or implement a routing protocol based on local IP addresses differentiation) + void registerAsDefaultInterface(); //First come, first served + void unregisterAsDefaultInterface(); //Must be called before inst is destroyed to avoid invalid ptr fault private: - static IPInterface* s_pDefaultInterface; + static IPInterface* s_pDefaultInterface; }; #endif /* IPINTERFACE_H_ */
--- a/main/if/LwIPInterface.cpp Tue Jun 12 10:08:54 2012 +0000 +++ b/main/if/LwIPInterface.cpp Fri Jun 15 14:17:23 2012 +0000 @@ -36,12 +36,12 @@ m_rdySphre.wait(); } -/*virtual*/ LwIPInterface::~LwIPInterface() +LwIPInterface::~LwIPInterface() { } -/*virtual*/ int LwIPInterface::init() //Init LwIP-specific stuff, create the right bindings, etc +int LwIPInterface::init() //Init LwIP-specific stuff, create the right bindings, etc { //lwip_init(); //All LwIP initialisation functions called on a per-module basis (according to lwipopts.h) tcpip_init(LwIPInterface::tcpipRdyCb, this); //Start TCP/IP processing thread
--- a/main/if/LwIPInterface.h Tue Jun 12 10:08:54 2012 +0000 +++ b/main/if/LwIPInterface.h Fri Jun 15 14:17:23 2012 +0000 @@ -35,16 +35,14 @@ class LwIPInterface : public IPInterface { public: - LwIPInterface(); - virtual ~LwIPInterface(); + LwIPInterface(); + virtual ~LwIPInterface(); - virtual int init(); //Init LwIP-specific stuff, create the right bindings, etc - virtual int connect() = 0; - virtual int disconnect() = 0; + int init(); //Init LwIP-specific stuff, create the right bindings, etc private: - static void tcpipRdyCb(void* ctx); //Result of TCP/IP thread launch - Semaphore m_rdySphre; + static void tcpipRdyCb(void* ctx); //Result of TCP/IP thread launch + Semaphore m_rdySphre; }; #endif /* LWIPINTERFACE_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/socket/netdb.h Fri Jun 15 14:17:23 2012 +0000 @@ -0,0 +1,51 @@ +/* netdb.h */ +/* +Copyright (C) 2012 ARM Limited. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef NETDB_H_ +#define NETDB_H_ + +#include "lwip/netdb.h" + +//DNS + +inline struct hostent *gethostbyname(const char *name) +{ + return lwip_gethostbyname(name); +} + +inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) +{ + return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); +} + +inline void freeaddrinfo(struct addrinfo *ai) +{ + return lwip_freeaddrinfo(ai); +} + +inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) +{ + return lwip_getaddrinfo(nodename, servname, hints, res); +} + +#endif /* NETDB_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/socket/netinet/in.h Fri Jun 15 14:17:23 2012 +0000 @@ -0,0 +1,30 @@ +/* in.h */ +/* +Copyright (C) 2012 ARM Limited. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + + +#ifndef IN_H_ +#define IN_H_ + +#include "lwip/inet.h" + +#endif /* IN_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/socket/sys/socket.h Fri Jun 15 14:17:23 2012 +0000 @@ -0,0 +1,130 @@ +/* socket.h */ +/* +Copyright (C) 2012 ARM Limited. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + + +#ifndef SOCKET_H_ +#define SOCKET_H_ + +#include "lwip/sockets.h" + +//Sockets + +inline int accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + return lwip_accept(s, addr, addrlen); +} + +inline int bind(int s, const struct sockaddr *name, socklen_t namelen) +{ + return lwip_bind(s, name, namelen); +} + +inline int shutdown(int s, int how) +{ + return lwip_shutdown(s, how); +} + +inline int getsockname (int s, struct sockaddr *name, socklen_t *namelen) +{ + return lwip_getsockname(s, name, namelen); +} + +inline int getpeername (int s, struct sockaddr *name, socklen_t *namelen) +{ + return lwip_getpeername(s, name, namelen); +} + +inline int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) +{ + return lwip_getsockopt(s, level, optname, optval, optlen); +} + +inline int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) +{ + return lwip_setsockopt(s, level, optname, optval, optlen); +} + +inline int connect(int s, const struct sockaddr *name, socklen_t namelen) +{ + return lwip_connect(s, name, namelen); +} + +inline int listen(int s, int backlog) +{ + return lwip_listen(s, backlog); +} + +inline int recv(int s, void *mem, size_t len, int flags) +{ + return lwip_recv(s, mem, len, flags); +} + +inline int recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + return lwip_recvfrom(s, mem, len, flags, from, fromlen); +} + +inline int send(int s, const void *dataptr, size_t size, int flags) +{ + return lwip_send(s, dataptr, size, flags); +} + +inline int sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + return lwip_sendto(s, dataptr, size, flags, to, tolen); +} + +inline int socket(int domain, int type, int protocol) +{ + return lwip_socket(domain, type, protocol); +} + +inline int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, + struct timeval *timeout) +{ + return lwip_select(maxfdp1, readset, writeset, exceptset, timeout); +} + +inline int ioctlsocket(int s, long cmd, void *argp) +{ + return lwip_ioctl(s, cmd, argp); +} + +inline int read(int s, void *mem, size_t len) +{ + return lwip_read(s, mem, len); +} + +inline int write(int s, const void *dataptr, size_t size) +{ + return lwip_write(s, dataptr, size); +} + +inline int close(int s) +{ + return lwip_close(s); +} + +#endif /* SOCKET_H_ */