Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
Revision 40:4b4306f3d829, committed 2015-02-23
- Comitter:
- dan_ackme
- Date:
- Mon Feb 23 22:21:50 2015 -0800
- Parent:
- 39:a963f69cb2de
- Child:
- 41:66beaca0fd1a
- Commit message:
- minor bug fixes
Changed in this revision
--- a/Gpio.cpp Mon Feb 23 20:30:18 2015 -0800 +++ b/Gpio.cpp Mon Feb 23 22:21:50 2015 -0800 @@ -36,9 +36,10 @@ /*************************************************************************************************/ -Gpio::Gpio(Pin pin) : DigitalOut(pin) -{ -} +Gpio::Gpio(Pin pin, bool isOutput) : DigitalOut(pin) +{ +} + /*************************************************************************************************/ void Gpio::write(bool value)
--- a/NetworkInterface.cpp Mon Feb 23 20:30:18 2015 -0800 +++ b/NetworkInterface.cpp Mon Feb 23 22:21:50 2015 -0800 @@ -354,14 +354,14 @@ //----------------------------------------------------------------------------------------------- -/*************************************************************************************************/ -bool NetworkInterface::strToIp(const char *str, uint32_t *intPtr) -{ - if (!intPtr) - { - return false; - } - uint32_t ip = 0; +/*************************************************************************************************/ +bool NetworkInterface::strToIp(const char *str, uint32_t *intPtr) +{ + if (!intPtr) + { + return false; + } + uint32_t ip = 0; int i; const char *tok; @@ -371,17 +371,24 @@ char buf[4]; tok = strchr(str, '.'); + + const int len = (int)(tok - str); if(tok == NULL) { - if(i < 3) + if(i < 3 || strlen(str) > 3) { return false; } strcpy(buf, str); } + else if(len > 3) + { + return false; + } else { - strncpy(buf, str, tok - str); + strncpy(buf, str, len); + buf[len] = 0; ++tok; } @@ -399,11 +406,11 @@ if(i != 4) { return false; - } - - *intPtr = ip; - - return true; + } + + *intPtr = ip; + + return true; } /*************************************************************************************************/
--- a/SocketInterface.cpp Mon Feb 23 20:30:18 2015 -0800 +++ b/SocketInterface.cpp Mon Feb 23 22:21:50 2015 -0800 @@ -248,6 +248,38 @@ return result; } + +/*************************************************************************************************/ +WiconnectResult SocketInterface::httpAcceptWebSocket(WiconnectSocket &socket, uint32_t timeoutMs) +{ + TimeoutTimer timer; + + do + { + uint8_t handle; + uint16_t local, remote; + uint32_t ipAddress; + WiconnectResult result; + + if(WICONNECT_SUCCEEDED(result, pollForClient(SOCKET_TYPE_WS, &handle, &local, &remote, &ipAddress))) + { + char ipBuffer[17]; + if(WICONNECT_FAILED(result, socket.init(handle, SOCKET_TYPE_WS, Wiconnect::ipToStr(ipAddress, ipBuffer), remote, local))) + { + return result; + } + websocketConnectedList |= (1 << handle); + return WICONNECT_SUCCESS; + } + else if(!(result == WICONNECT_PROCESSING || result == WICONNECT_NOT_FOUND)) + { + return result; + } + + } while(timeoutMs == WICONNECT_WAIT_FOREVER || !timer.timedOut(timeoutMs)); + + return WICONNECT_TIMEOUT; +} /*************************************************************************************************/ WiconnectResult SocketInterface::closeAllSockets()
--- a/TcpServer.cpp Mon Feb 23 20:30:18 2015 -0800 +++ b/TcpServer.cpp Mon Feb 23 22:21:50 2015 -0800 @@ -136,7 +136,7 @@ uint32_t ipAddress; WiconnectResult result; - if(WICONNECT_SUCCEEDED(result, pollForServerClient(&handle, &local, &remote, &ipAddress))) + if(WICONNECT_SUCCEEDED(result, pollForClient(SOCKET_TYPE_TCP, &handle, &local, &remote, &ipAddress))) { char ipBuffer[17]; if(WICONNECT_FAILED(result, socket.init(handle, SOCKET_TYPE_TCP, Wiconnect::ipToStr(ipAddress, ipBuffer), remote, local))) @@ -171,7 +171,7 @@ } /*************************************************************************************************/ -WiconnectResult SocketInterface::pollForServerClient(uint8_t *handlePtr, uint16_t *localPort, uint16_t *remotePort, uint32_t *ipAddress) +WiconnectResult SocketInterface::pollForClient(SocketType type, uint8_t *handlePtr, uint16_t *localPort, uint16_t *remotePort, uint32_t *ipAddress) { WiconnectResult result; @@ -202,7 +202,7 @@ } } - if(strcmp(toks[1], "TCPS") != 0) + if(!((type == SOCKET_TYPE_TCP && strcmp(toks[1], "TCPS") == 0) || (type == SOCKET_TYPE_WS && strcmp(toks[1], "WEBS") == 0))) { continue; } @@ -220,7 +220,11 @@ { continue; } - else if(serverConnectedClientList & handleMask) + else if(type == SOCKET_TYPE_TCP && (serverConnectedClientList & handleMask)) + { + continue; + } + else if(type == SOCKET_TYPE_WS && (websocketConnectedList & handleMask)) { continue; } @@ -240,7 +244,14 @@ { if(!(connectedClients & mask)) { - serverConnectedClientList &= ~mask; + if(type == SOCKET_TYPE_TCP) + { + serverConnectedClientList &= ~mask; + } + else + { + websocketConnectedList &= ~mask; + } } } }
--- a/WiconnectSocket.cpp Mon Feb 23 20:30:18 2015 -0800 +++ b/WiconnectSocket.cpp Mon Feb 23 22:21:50 2015 -0800 @@ -97,7 +97,12 @@ /*************************************************************************************************/ WiconnectResult WiconnectSocket::init(uint8_t handle_, SocketType type_, const char *host_, uint16_t remotePort_, uint16_t localPort_) -{ +{ + do + { + result = close(); + } while(result == WICONNECT_PROCESSING); + handle = handle_; type = type_; remotePort = remotePort_;
--- a/api/types/Socket/internal/Endpoint.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * 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. - */ -#include "api/types/Socket/Socket.h" -#include "api/types/Socket/Endpoint.h" -#include <cstring> -#include <cstdio> - - - -/*************************************************************************************************/ -Endpoint::Endpoint() -{ - reset_address(); -} - -/*************************************************************************************************/ -Endpoint::~Endpoint() {} - -/*************************************************************************************************/ -void Endpoint::reset_address(void) -{ - std::memset(&_remoteHost, 0, sizeof(struct sockaddr_in)); - _ipAddress[0] = '\0'; -} - -/*************************************************************************************************/ -int Endpoint::set_address(const char* host, const int port) -{ - reset_address(); - - // IP Address - char address[5]; - char *p_address = address; - - // Dot-decimal notation - int result = std::sscanf(host, "%3u.%3u.%3u.%3u", - (unsigned int*)&address[0], (unsigned int*)&address[1], - (unsigned int*)&address[2], (unsigned int*)&address[3]); - - if (result != 4) - { - // Resolve address with DNS - struct hostent *host_address = gethostbyname(host); - if (host_address == NULL) - return -1; //Could not resolve address - p_address = (char*)host_address->h_addr_list[0]; - } - std::memcpy((char*)&_remoteHost.sin_addr.s_addr, p_address, 4); - - // Address family - _remoteHost.sin_family = AF_INET; - - // Set port - _remoteHost.sin_port = htons(port); - - return 0; -} - -/*************************************************************************************************/ -char* Endpoint::get_address() -{ - if ((_ipAddress[0] == '\0') && (_remoteHost.sin_addr.s_addr != 0)) - inet_ntoa_r(_remoteHost.sin_addr, _ipAddress, sizeof(_ipAddress)); - return _ipAddress; -} - -/*************************************************************************************************/ -int Endpoint::get_port() -{ - return ntohs(_remoteHost.sin_port); -}
--- a/api/types/Socket/internal/Socket.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "Wiconnect.h" -#include "api/types/Socket/Socket.h" - - - - - -/*************************************************************************************************/ -Socket::Socket() : _blocking(true), _timeout(1500) -{ -} - -/*************************************************************************************************/ -Socket::Socket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) : - _blocking(true), _timeout(1500), socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer) -{ - -} - -/*************************************************************************************************/ -Socket::~Socket() -{ - close(true); -} - -/*************************************************************************************************/ -void Socket::set_blocking(bool blocking, unsigned int timeout) -{ - _blocking = blocking; - _timeout = timeout; -} - -/*************************************************************************************************/ -int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) -{ - return -1; -} - -/*************************************************************************************************/ -int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) -{ - return -1; -} - -/*************************************************************************************************/ -int Socket::close(bool shutdown) -{ - return (socket.close() == WICONNECT_SUCCESS) ? 0 : -1; -} - -
--- a/api/types/Socket/internal/TCPSocketConnection.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "Wiconnect.h" -#include "api/types/Socket/TCPSocketConnection.h" - - - -/*************************************************************************************************/ -TCPSocketConnection::TCPSocketConnection(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) -: Socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer) -{ -} - -/*************************************************************************************************/ -int TCPSocketConnection::connect(const char* host, const int port) -{ - return (Wiconnect::getInstance()->tcpConnect(socket, host, (uint16_t)port) == WICONNECT_SUCCESS) ? 0 : -1; -} - -/*************************************************************************************************/ -bool TCPSocketConnection::is_connected(void) -{ - return socket.isConnected(); -} - -/*************************************************************************************************/ -// currently there's no way to timeout writing data to WiConnect, so we just have to try and send it all. -// NOTE: this WILL be fixed in the next version -int TCPSocketConnection::send(char* data, int length) -{ - return send_all(data, length); -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes written -int TCPSocketConnection::send_all(char* data, int length) -{ - return (socket.write(data, length, true) == WICONNECT_SUCCESS) ? length : -1; -} - -/*************************************************************************************************/ -int TCPSocketConnection::receive(char* data, int length) -{ - uint16_t bytesRead; - - if (!_blocking) - { - if(socket.getRxBufferSize() == 0 || socket.getRxBufferBytesPending() == 0) - { - TimeoutTimer timer; - - for(;;) - { - bool hasData; - - if(socket.poll(&hasData) != WICONNECT_SUCCESS) - { - return -1; - } - else if(hasData) - { - break; - } - else if(timer.timedOut(_timeout)) - { - return -1; - } - } - } - } - - if(length == 1 && socket.getRxBufferSize() > 0) - { - return (socket.getc((uint8_t*)data) == WICONNECT_SUCCESS) ? 1 : -1; - } - else - { - for(;;) - { - if(socket.read(data, length, &bytesRead) != WICONNECT_SUCCESS) - { - return -1; - } - else if(bytesRead > 0) - { - return bytesRead; - } - } - } -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes received -int TCPSocketConnection::receive_all(char* data, int length) -{ - char *ptr = data; - int totReadSize = length; - - while(length > 0) - { - int bytesRead = receive(ptr, length); - if(bytesRead == -1) - { - return -1; - } - ptr += bytesRead; - length -= bytesRead; - } - - return totReadSize; -} - -
--- a/api/types/Socket/internal/TCPSocketServer.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "Wiconnect.h" -#include "api/types/Socket/TCPSocketServer.h" - - - -/*************************************************************************************************/ -TCPSocketServer::TCPSocketServer() -{ -} - - -/*************************************************************************************************/ -int TCPSocketServer::bind(int port) -{ - return -1; -} - -/*************************************************************************************************/ -int TCPSocketServer::listen(int max) -{ - return -1; -} - -/*************************************************************************************************/ -int TCPSocketServer::accept(TCPSocketConnection& connection) -{ - return -1; -}
--- a/api/types/Socket/internal/UDPSocket.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "Wiconnect.h" -#include "api/types/Socket/UDPSocket.h" - - - -/*************************************************************************************************/ -UDPSocket::UDPSocket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) -: Socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer), localPort(SOCKET_ANY_PORT) -{ -} - -/*************************************************************************************************/ -int UDPSocket::init(void) -{ - return 0; -} - -/*************************************************************************************************/ -// Server initialization -int UDPSocket::bind(int port) -{ - localPort = port; - return 0; -} - -/*************************************************************************************************/ -int UDPSocket::join_multicast_group(const char* address) -{ - return -1; -} - -/*************************************************************************************************/ -int UDPSocket::set_broadcasting(bool broadcast) -{ - return 0; -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes written -int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) -{ - if(!socket.isConnected()) - { - if(Wiconnect::getInstance()->udpConnect(socket, remote.get_address(), remote.get_port(), localPort) != WICONNECT_SUCCESS) - { - return -1; - } - } - return (socket.write(packet, length, true) == WICONNECT_SUCCESS) ? length : -1; -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes received -int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) -{ - uint16_t bytesRead; - - if(!socket.isConnected()) - { - if(Wiconnect::getInstance()->udpConnect(socket, remote._ipAddress, remote.get_port(), localPort) != WICONNECT_SUCCESS) - { - return -1; - } - } - - if (!_blocking) - { - if(socket.getRxBufferSize() == 0 || socket.getRxBufferBytesPending() == 0) - { - TimeoutTimer timer; - - for(;;) - { - bool hasData; - - if(socket.poll(&hasData) != WICONNECT_SUCCESS) - { - return -1; - } - else if(hasData) - { - break; - } - else if(timer.timedOut(_timeout)) - { - return -1; - } - } - } - } - - if(length == 1 && socket.getRxBufferSize() > 0) - { - return (socket.getc((uint8_t*)buffer) == WICONNECT_SUCCESS) ? 1 : -1; - } - else - { - for(;;) - { - if(socket.read(buffer, length, &bytesRead) != WICONNECT_SUCCESS) - { - return -1; - } - else if(bytesRead > 0) - { - return bytesRead; - } - } - } - -}
--- a/api/types/Socket/internal/common.cpp Mon Feb 23 20:30:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright 2014, ACKme Networks - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; - * the contents of this file may not be disclosed to third parties, copied - * or duplicated in any form, in whole or in part, without the prior - * written permission of ACKme Networks. - */ - - -#include "Wiconnect.h" -#include "api/types/Socket/Socket.h" - - - -/*************************************************************************************************/ -int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) -{ - return -1; -} - -/*************************************************************************************************/ -struct hostent *gethostbyname(const char *name) -{ - static uint8_t buffer[sizeof(struct hostent) + sizeof(void*)*3 + 1*sizeof(uint32_t)]; - struct hostent *hostPtr = (struct hostent*)buffer; - char **ipPtrList = (char**)&buffer[sizeof(struct hostent)]; - char **aliasPtrList = (char**)&buffer[sizeof(struct hostent) + sizeof(void*)*2]; - uint32_t *ipPtr = (uint32_t*)&buffer[sizeof(struct hostent) + sizeof(void*)*3]; - - - hostPtr->h_addr_list = ipPtrList; - hostPtr->h_aliases = aliasPtrList; - hostPtr->h_addrtype = AF_INET; - hostPtr->h_length = sizeof(uint32_t); - hostPtr->h_name = (char*)name; - - aliasPtrList[0] = NULL; - ipPtrList[0] = (char*)ipPtr; - ipPtrList[1] = NULL; - - Wiconnect *wiconnect = Wiconnect::getInstance(); - if(wiconnect->lookup(name, ipPtr) != WICONNECT_SUCCESS) - { - ipPtrList[0] = NULL; - } - - return hostPtr; -} - -/*************************************************************************************************/ -u32_t ipaddr_addr(const char *cp) -{ - u32_t ip = 0; - - Wiconnect::strToIp(cp, &ip); - - return ip; -} - -/*************************************************************************************************/ -int ipaddr_aton(const char *cp, ip_addr_t *addr) -{ - return Wiconnect::strToIp(cp, &addr->addr) ? 0 : -1; -} - -/*************************************************************************************************/ -// returns ptr to static buffer; not reentrant! -char *ipaddr_ntoa(const ip_addr_t *addr) -{ - return (char*)Wiconnect::ipToStr(addr->addr); -} - -/*************************************************************************************************/ -char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen) -{ - return (char*)Wiconnect::ipToStr(addr->addr, buf); -}