From 849dfb17c70ff6872355c0ffb7fc21177c536033 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 5 Nov 2017 10:27:46 +0100 Subject: [PATCH] The macros in ip6_addr.c are duplicated from ip4_addr.c, so move them to lwIPs portability layer ...didn't see that in the first place... --- src/core/ipv4/ip4_addr.c | 20 +++++--------------- src/core/ipv6/ip6_addr.c | 7 ------- src/include/lwip/arch.h | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/core/ipv4/ip4_addr.c b/src/core/ipv4/ip4_addr.c index e60e2cf1..33204d11 100644 --- a/src/core/ipv4/ip4_addr.c +++ b/src/core/ipv4/ip4_addr.c @@ -112,16 +112,6 @@ ip4_addr_netmask_valid(u32_t netmask) return 1; } -/* Here for now until needed in other places in lwIP */ -#ifndef isprint -#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) -#define isprint(c) in_range(c, 0x20, 0x7f) -#define isdigit(c) in_range(c, '0', '9') -#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) -#define islower(c) in_range(c, 'a', 'z') -#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') -#endif - /** * Ascii internet address interpretation routine. * The value returned is in network order. @@ -167,7 +157,7 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr) * Values are specified as for C: * 0x=hex, 0=octal, 1-9=decimal. */ - if (!isdigit(c)) { + if (!lwip_isdigit(c)) { return 0; } val = 0; @@ -182,11 +172,11 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr) } } for (;;) { - if (isdigit(c)) { + if (lwip_isdigit(c)) { val = (val * base) + (u32_t)(c - '0'); c = *++cp; - } else if (base == 16 && isxdigit(c)) { - val = (val << 4) | (u32_t)(c + 10 - (islower(c) ? 'a' : 'A')); + } else if (base == 16 && lwip_isxdigit(c)) { + val = (val << 4) | (u32_t)(c + 10 - (lwip_islower(c) ? 'a' : 'A')); c = *++cp; } else { break; @@ -211,7 +201,7 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr) /* * Check for trailing characters. */ - if (c != '\0' && !isspace(c)) { + if (c != '\0' && !lwip_isspace(c)) { return 0; } /* diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index dbd6fe82..3846b2f5 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -50,13 +50,6 @@ /* used by IP6_ADDR_ANY(6) in ip6_addr.h */ const ip_addr_t ip6_addr_any = IPADDR6_INIT(0ul, 0ul, 0ul, 0ul); -#define lwip_in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) -#define lwip_isprint(c) lwip_in_range(c, 0x20, 0x7f) -#define lwip_isdigit(c) lwip_in_range(c, '0', '9') -#define lwip_isxdigit(c) (lwip_isdigit(c) || lwip_in_range(c, 'a', 'f') || lwip_in_range(c, 'A', 'F')) -#define lwip_islower(c) lwip_in_range(c, 'a', 'z') -#define lwip_isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') - #define lwip_xchar(i) ((char)((i) < 10 ? '0' + (i) : 'A' + (i) - 10)) /** diff --git a/src/include/lwip/arch.h b/src/include/lwip/arch.h index dafd500c..3738863c 100644 --- a/src/include/lwip/arch.h +++ b/src/include/lwip/arch.h @@ -203,6 +203,29 @@ typedef int ssize_t; #define SSIZE_MAX INT_MAX #endif /* SSIZE_MAX */ +/** Define this to 1 in arch/cc.h of your port if your compiler does not provide + * the cytype.h header. If ctype.h is available, a few few character functions + * are mapped to the appropriate functions (lwip_islower, lwip_isdigit...), if + * not, a private implementation is provided. + */ +#ifndef LWIP_NO_CTYPE_H +#define LWIP_NO_CTYPE_H 0 +#endif + +#if LWIP_NO_CTYPE_H +#define lwip_in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) +#define lwip_isdigit(c) lwip_in_range(c, '0', '9') +#define lwip_isxdigit(c) (lwip_isdigit(c) || lwip_in_range(c, 'a', 'f') || lwip_in_range(c, 'A', 'F')) +#define lwip_islower(c) lwip_in_range(c, 'a', 'z') +#define lwip_isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') +#else +#include +#define lwip_isdigit(c) isdigit(c) +#define lwip_isxdigit(c) isxdigit(c) +#define lwip_islower(c) islower(c) +#define lwip_isspace(c) isspace(c) +#endif + /** C++ const_cast(val) equivalent to remove constness from a value (GCC -Wcast-qual) */ #ifndef LWIP_CONST_CAST #define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))