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

Committer:
dan_ackme
Date:
Mon Oct 27 13:42:26 2014 -0700
Revision:
29:b6af04b77a56
Child:
32:b2bdbc018665
refactored library layout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 29:b6af04b77a56 1 /*
dan_ackme 29:b6af04b77a56 2 * Copyright 2014, ACKme Networks
dan_ackme 29:b6af04b77a56 3 * All Rights Reserved.
dan_ackme 29:b6af04b77a56 4 *
dan_ackme 29:b6af04b77a56 5 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
dan_ackme 29:b6af04b77a56 6 * the contents of this file may not be disclosed to third parties, copied
dan_ackme 29:b6af04b77a56 7 * or duplicated in any form, in whole or in part, without the prior
dan_ackme 29:b6af04b77a56 8 * written permission of ACKme Networks.
dan_ackme 29:b6af04b77a56 9 */
dan_ackme 29:b6af04b77a56 10
dan_ackme 29:b6af04b77a56 11
dan_ackme 29:b6af04b77a56 12
dan_ackme 29:b6af04b77a56 13 #include "api/types/Socket/Socket.h"
dan_ackme 29:b6af04b77a56 14 #include "common.h"
dan_ackme 29:b6af04b77a56 15
dan_ackme 29:b6af04b77a56 16
dan_ackme 29:b6af04b77a56 17 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 18 int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
dan_ackme 29:b6af04b77a56 19 {
dan_ackme 29:b6af04b77a56 20 return -1;
dan_ackme 29:b6af04b77a56 21 }
dan_ackme 29:b6af04b77a56 22
dan_ackme 29:b6af04b77a56 23 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 24 struct hostent *gethostbyname(const char *name)
dan_ackme 29:b6af04b77a56 25 {
dan_ackme 29:b6af04b77a56 26 static uint8_t buffer[sizeof(struct hostent) + sizeof(void*)*3 + 1*sizeof(uint32_t)];
dan_ackme 29:b6af04b77a56 27 struct hostent *hostPtr = (struct hostent*)buffer;
dan_ackme 29:b6af04b77a56 28 char **ipPtrList = (char**)&buffer[sizeof(struct hostent)];
dan_ackme 29:b6af04b77a56 29 char **aliasPtrList = (char**)&buffer[sizeof(struct hostent) + sizeof(void*)*2];
dan_ackme 29:b6af04b77a56 30 uint32_t *ipPtr = (uint32_t*)&buffer[sizeof(struct hostent) + sizeof(void*)*3];
dan_ackme 29:b6af04b77a56 31
dan_ackme 29:b6af04b77a56 32
dan_ackme 29:b6af04b77a56 33 hostPtr->h_addr_list = ipPtrList;
dan_ackme 29:b6af04b77a56 34 hostPtr->h_aliases = aliasPtrList;
dan_ackme 29:b6af04b77a56 35 hostPtr->h_addrtype = AF_INET;
dan_ackme 29:b6af04b77a56 36 hostPtr->h_length = sizeof(uint32_t);
dan_ackme 29:b6af04b77a56 37 hostPtr->h_name = (char*)name;
dan_ackme 29:b6af04b77a56 38
dan_ackme 29:b6af04b77a56 39 aliasPtrList[0] = NULL;
dan_ackme 29:b6af04b77a56 40 ipPtrList[0] = (char*)ipPtr;
dan_ackme 29:b6af04b77a56 41 ipPtrList[1] = NULL;
dan_ackme 29:b6af04b77a56 42
dan_ackme 29:b6af04b77a56 43 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 29:b6af04b77a56 44 if(wiconnect->lookup(name, ipPtr) != WICONNECT_SUCCESS)
dan_ackme 29:b6af04b77a56 45 {
dan_ackme 29:b6af04b77a56 46 ipPtrList[0] = NULL;
dan_ackme 29:b6af04b77a56 47 }
dan_ackme 29:b6af04b77a56 48
dan_ackme 29:b6af04b77a56 49 return hostPtr;
dan_ackme 29:b6af04b77a56 50 }
dan_ackme 29:b6af04b77a56 51
dan_ackme 29:b6af04b77a56 52 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 53 u32_t ipaddr_addr(const char *cp)
dan_ackme 29:b6af04b77a56 54 {
dan_ackme 29:b6af04b77a56 55 u32_t ip = 0;
dan_ackme 29:b6af04b77a56 56
dan_ackme 29:b6af04b77a56 57 Wiconnect::strToIp(cp, &ip);
dan_ackme 29:b6af04b77a56 58
dan_ackme 29:b6af04b77a56 59 return ip;
dan_ackme 29:b6af04b77a56 60 }
dan_ackme 29:b6af04b77a56 61
dan_ackme 29:b6af04b77a56 62 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 63 int ipaddr_aton(const char *cp, ip_addr_t *addr)
dan_ackme 29:b6af04b77a56 64 {
dan_ackme 29:b6af04b77a56 65 return Wiconnect::strToIp(cp, &addr->addr) ? 0 : -1;
dan_ackme 29:b6af04b77a56 66 }
dan_ackme 29:b6af04b77a56 67
dan_ackme 29:b6af04b77a56 68 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 69 // returns ptr to static buffer; not reentrant!
dan_ackme 29:b6af04b77a56 70 char *ipaddr_ntoa(const ip_addr_t *addr)
dan_ackme 29:b6af04b77a56 71 {
dan_ackme 29:b6af04b77a56 72 return (char*)Wiconnect::ipToStr(addr->addr);
dan_ackme 29:b6af04b77a56 73 }
dan_ackme 29:b6af04b77a56 74
dan_ackme 29:b6af04b77a56 75 /*************************************************************************************************/
dan_ackme 29:b6af04b77a56 76 char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen)
dan_ackme 29:b6af04b77a56 77 {
dan_ackme 29:b6af04b77a56 78 return (char*)Wiconnect::ipToStr(addr->addr, buf);
dan_ackme 29:b6af04b77a56 79 }