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
common.cpp
00001 /* 00002 * Copyright 2014, ACKme Networks 00003 * All Rights Reserved. 00004 * 00005 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; 00006 * the contents of this file may not be disclosed to third parties, copied 00007 * or duplicated in any form, in whole or in part, without the prior 00008 * written permission of ACKme Networks. 00009 */ 00010 00011 00012 #include "Wiconnect.h" 00013 #include "api/types/Socket/Socket.h" 00014 00015 00016 00017 /*************************************************************************************************/ 00018 int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) 00019 { 00020 return -1; 00021 } 00022 00023 /*************************************************************************************************/ 00024 struct hostent *gethostbyname(const char *name) 00025 { 00026 static uint8_t buffer[sizeof(struct hostent) + sizeof(void*)*3 + 1*sizeof(uint32_t)]; 00027 struct hostent *hostPtr = (struct hostent*)buffer; 00028 char **ipPtrList = (char**)&buffer[sizeof(struct hostent)]; 00029 char **aliasPtrList = (char**)&buffer[sizeof(struct hostent) + sizeof(void*)*2]; 00030 uint32_t *ipPtr = (uint32_t*)&buffer[sizeof(struct hostent) + sizeof(void*)*3]; 00031 00032 00033 hostPtr->h_addr_list = ipPtrList; 00034 hostPtr->h_aliases = aliasPtrList; 00035 hostPtr->h_addrtype = AF_INET; 00036 hostPtr->h_length = sizeof(uint32_t); 00037 hostPtr->h_name = (char*)name; 00038 00039 aliasPtrList[0] = NULL; 00040 ipPtrList[0] = (char*)ipPtr; 00041 ipPtrList[1] = NULL; 00042 00043 Wiconnect *wiconnect = Wiconnect::getInstance(); 00044 if(wiconnect->lookup(name, ipPtr) != WICONNECT_SUCCESS) 00045 { 00046 ipPtrList[0] = NULL; 00047 } 00048 00049 return hostPtr; 00050 } 00051 00052 /*************************************************************************************************/ 00053 u32_t ipaddr_addr(const char *cp) 00054 { 00055 u32_t ip = 0; 00056 00057 Wiconnect::strToIp(cp, &ip); 00058 00059 return ip; 00060 } 00061 00062 /*************************************************************************************************/ 00063 int ipaddr_aton(const char *cp, ip_addr_t *addr) 00064 { 00065 return Wiconnect::strToIp(cp, &addr->addr) ? 0 : -1; 00066 } 00067 00068 /*************************************************************************************************/ 00069 // returns ptr to static buffer; not reentrant! 00070 char *ipaddr_ntoa(const ip_addr_t *addr) 00071 { 00072 return (char*)Wiconnect::ipToStr(addr->addr); 00073 } 00074 00075 /*************************************************************************************************/ 00076 char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen) 00077 { 00078 return (char*)Wiconnect::ipToStr(addr->addr, buf); 00079 }
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2