Implementation of the NetworkSocketAPI for LWIP
Dependencies: lwip-eth lwip-sys lwip
Dependents: HelloLWIPInterface HelloLWIPInterfaceNonBlocking LWIPInterfaceTests SimpleHTTPExample ... more
Diff: LWIPInterface.cpp
- Revision:
- 16:1efb0d91c223
- Parent:
- 15:0d8d1dafe064
- Child:
- 17:7db2f5d503d4
--- a/LWIPInterface.cpp Wed Apr 06 00:20:35 2016 +0000 +++ b/LWIPInterface.cpp Wed Apr 06 10:45:34 2016 +0000 @@ -154,7 +154,19 @@ int LWIPInterface::socket_bind(void *handle, int port) { - return NSAPI_ERROR_UNSUPPORTED; + int fd = (int)handle-1; + struct sockaddr_in sa; + memset(&sa, 0, sizeof sa); + + sa.sin_family = AF_INET; + sa.sin_port = htons(port); + sa.sin_addr.s_addr = INADDR_ANY; + + if (lwip_bind(fd, (const struct sockaddr *)&sa, sizeof sa) < 0) { + return NSAPI_ERROR_DEVICE_ERROR; + } + + return 0; } int LWIPInterface::socket_listen(void *handle, int backlog)