4 /* Here for now until needed in other places in lwIP */
6 #define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
7 #define isascii(c) in_range(c, 0x20, 0x7f)
8 #define isdigit(c) in_range(c, '0', '9')
9 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
10 #define islower(c) in_range(c, 'a', 'z')
11 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
16 * Ascii internet address interpretation routine.
17 * The value returned is in network order.
22 u32_t
inet_addr(const char *cp
)
26 if (inet_aton(cp
, &val
)) {
33 * Check whether "cp" is a valid ascii representation
34 * of an Internet address and convert to a binary address.
35 * Returns 1 if the address is valid, 0 if not.
36 * This replaces inet_addr, the return value from which
37 * cannot distinguish between failure and a local broadcast address.
42 inet_aton(const char *cp
, struct in_addr
*addr
)
53 * Collect number up to ``.''.
54 * Values are specified as for C:
55 * 0x=hex, 0=octal, isdigit=decimal.
62 if (c
== 'x' || c
== 'X')
69 val
= (val
* base
) + (s16_t
)(c
- '0');
71 } else if (base
== 16 && isxdigit(c
)) {
73 (s16_t
)(c
+ 10 - (islower(c
) ? 'a' : 'A'));
82 * a.b.c (with c treated as 16 bits)
83 * a.b (with b treated as 24 bits)
93 * Check for trailing characters.
95 if (c
!= '\0' && (!isascii(c
) || !isspace(c
)))
98 * Concoct the address according to
99 * the number of parts specified.
105 return (0); /* initial nondigit */
107 case 1: /* a -- 32 bits */
110 case 2: /* a.b -- 8.24 bits */
113 val
|= parts
[0] << 24;
116 case 3: /* a.b.c -- 8.8.16 bits */
119 val
|= (parts
[0] << 24) | (parts
[1] << 16);
122 case 4: /* a.b.c.d -- 8.8.8.8 bits */
125 val
|= (parts
[0] << 24) | (parts
[1] << 16) | (parts
[2] << 8);
129 addr
->s_addr
= htonl(val
);
133 /* Convert numeric IP address into decimal dotted ASCII representation.
134 * returns ptr to static buffer; not reentrant!
136 char *inet_ntoa(struct in_addr addr
)
139 u32_t s_addr
= addr
.s_addr
;
148 ap
= (u8_t
*)&s_addr
;
149 for(n
= 0; n
< 4; n
++) {
152 rem
= *ap
% (u8_t
)10;
154 inv
[i
++] = '0' + rem
;
167 #error BYTE_ORDER is not defined
169 #if BYTE_ORDER == LITTLE_ENDIAN
174 return ((n
& 0xff) << 8) | ((n
& 0xff00) >> 8);
186 return ((n
& 0xff) << 24) |
187 ((n
& 0xff00) << 8) |
188 ((n
& 0xff0000) >> 8) |
189 ((n
& 0xff000000) >> 24);
198 #endif /* BYTE_ORDER == LITTLE_ENDIAN */