|
|
|
@ -32,8 +32,8 @@ |
|
|
|
|
*/ |
|
|
|
|
#include "utils.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str) |
|
|
|
|
uint8_t ICACHE_FLASH_ATTR
|
|
|
|
|
UTILS_IsIPV4(int8_t *str) |
|
|
|
|
{ |
|
|
|
|
uint8_t segs = 0; /* Segment count. */ |
|
|
|
|
uint8_t chcnt = 0; /* Character count within segment. */ |
|
|
|
@ -83,23 +83,22 @@ uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str) |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP(const int8_t* str, void *ip) |
|
|
|
|
|
|
|
|
|
uint8_t ICACHE_FLASH_ATTR |
|
|
|
|
UTILS_StrToIP(const int8_t* str, void *ip) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
/* The count of the number of bytes processed. */ |
|
|
|
|
int i; |
|
|
|
|
/* A pointer to the next digit to process. */ |
|
|
|
|
const char * start; |
|
|
|
|
|
|
|
|
|
start = str; |
|
|
|
|
for (i = 0; i < 4; i++) { |
|
|
|
|
/* The digit being processed. */ |
|
|
|
|
char c; |
|
|
|
|
/* The value of this byte. */ |
|
|
|
|
int n = 0; |
|
|
|
|
while (1) { |
|
|
|
|
c = * start; |
|
|
|
|
start++; |
|
|
|
|
c = *(const char *)str; |
|
|
|
|
(const char *)str++; |
|
|
|
|
if (c >= '0' && c <= '9') { |
|
|
|
|
n *= 10; |
|
|
|
|
n += c - '0'; |
|
|
|
@ -120,19 +119,20 @@ uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP(const int8_t* str, void *ip) |
|
|
|
|
((uint8_t*)ip)[i] = n; |
|
|
|
|
} |
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
uint32_t ICACHE_FLASH_ATTR UTILS_Atoh(const int8_t *s) |
|
|
|
|
|
|
|
|
|
uint32_t ICACHE_FLASH_ATTR
|
|
|
|
|
UTILS_Atoh(const int8_t *s) |
|
|
|
|
{ |
|
|
|
|
uint32_t value = 0, digit; |
|
|
|
|
int8_t c; |
|
|
|
|
|
|
|
|
|
while((c = *s++)){ |
|
|
|
|
if('0' <= c && c <= '9') |
|
|
|
|
while ((c = *s++)){ |
|
|
|
|
if ('0' <= c && c <= '9') |
|
|
|
|
digit = c - '0'; |
|
|
|
|
else if('A' <= c && c <= 'F') |
|
|
|
|
else if ('A' <= c && c <= 'F') |
|
|
|
|
digit = c - 'A' + 10; |
|
|
|
|
else if('a' <= c && c<= 'f') |
|
|
|
|
else if ('a' <= c && c <= 'f') |
|
|
|
|
digit = c - 'a' + 10; |
|
|
|
|
else break; |
|
|
|
|
|
|
|
|
|