1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
57
58
86
87
92
93
94
95
96
97
98
99
104
105
111
112
113
114
115
122
123
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
160
163
164
165
174
185
200
201
204
207
211
212
213
216
219
229
239
248
251
252
255
256
257
258
259
260
261
262
263
264
265
266
267
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
305
311
314
315
316
317
318
319
320
321
/* ... */
/* ... */
#include "lwip/opt.h"
#if LWIP_IPV4
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
const ip_addr_t ip_addr_any = IPADDR4_INIT(IPADDR_ANY);
const ip_addr_t ip_addr_broadcast = IPADDR4_INIT(IPADDR_BROADCAST);
/* ... */
u8_t
ip4_addr_isbroadcast_u32(u32_t addr, const struct netif *netif)
{
ip4_addr_t ipaddr;
ip4_addr_set_u32(&ipaddr, addr);
if ((~addr == IPADDR_ANY) ||
(addr == IPADDR_ANY)) {
return 1;
}if ((~addr == IPADDR_ANY) || (addr == IPADDR_ANY)) { ... } else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) {
/* ... */
return 0;
}else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) { ... } else if (addr == ip4_addr_get_u32(netif_ip4_addr(netif))) {
return 0;
}else if (addr == ip4_addr_get_u32(netif_ip4_addr(netif))) { ... } else if (ip4_addr_netcmp(&ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif))
&& ((addr & ~ip4_addr_get_u32(netif_ip4_netmask(netif))) ==
(IPADDR_BROADCAST & ~ip4_addr_get_u32(netif_ip4_netmask(netif))))) {
return 1;
}else if (ip4_addr_netcmp(&ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif)) /* ...and host identifier bits are all ones? =>... */ && ((addr & ~ip4_addr_get_u32(netif_ip4_netmask(netif))) == (IPADDR_BROADCAST & ~ip4_addr_get_u32(netif_ip4_netmask(netif))))) { ... } else {
return 0;
}else { ... }
}{ ... }
/* ... */
u8_t
ip4_addr_netmask_valid(u32_t netmask)
{
u32_t mask;
u32_t nm_hostorder = lwip_htonl(netmask);
for (mask = 1UL << 31 ; mask != 0; mask >>= 1) {
if ((nm_hostorder & mask) == 0) {
break;
}if ((nm_hostorder & mask) == 0) { ... }
}for (mask = 1UL << 31 ; mask != 0; mask >>= 1) { ... }
for (; mask != 0; mask >>= 1) {
if ((nm_hostorder & mask) != 0) {
return 0;
}if ((nm_hostorder & mask) != 0) { ... }
}for (; mask != 0; mask >>= 1) { ... }
return 1;
}{ ... }
/* ... */
u32_t
ipaddr_addr(const char *cp)
{
ip4_addr_t val;
if (ip4addr_aton(cp, &val)) {
return ip4_addr_get_u32(&val);
}if (ip4addr_aton(cp, &val)) { ... }
return (IPADDR_NONE);
}{ ... }
/* ... */
int
ip4addr_aton(const char *cp, ip4_addr_t *addr)
{
u32_t val;
u8_t base;
char c;
u32_t parts[4];
u32_t *pp = parts;
c = *cp;
for (;;) {
/* ... */
if (!lwip_isdigit(c)) {
return 0;
}if (!lwip_isdigit(c)) { ... }
val = 0;
base = 10;
if (c == '0') {
c = *++cp;
if (c == 'x' || c == 'X') {
base = 16;
c = *++cp;
}if (c == 'x' || c == 'X') { ... } else {
base = 8;
}else { ... }
}if (c == '0') { ... }
for (;;) {
if (lwip_isdigit(c)) {
val = (val * base) + (u32_t)(c - '0');
c = *++cp;
}if (lwip_isdigit(c)) { ... } else if (base == 16 && lwip_isxdigit(c)) {
val = (val << 4) | (u32_t)(c + 10 - (lwip_islower(c) ? 'a' : 'A'));
c = *++cp;
}else if (base == 16 && lwip_isxdigit(c)) { ... } else {
break;
}else { ... }
}for (;;) { ... }
if (c == '.') {
/* ... */
if (pp >= parts + 3) {
return 0;
}if (pp >= parts + 3) { ... }
*pp++ = val;
c = *++cp;
}if (c == '.') { ... } else {
break;
}else { ... }
}for (;;) { ... }
/* ... */
if (c != '\0' && !lwip_isspace(c)) {
return 0;
}if (c != '\0' && !lwip_isspace(c)) { ... }
/* ... */
switch (pp - parts + 1) {
case 0:
return 0;
case 0:
case 1:
break;
case 1:
case 2:
if (val > 0xffffffUL) {
return 0;
}if (val > 0xffffffUL) { ... }
if (parts[0] > 0xff) {
return 0;
}if (parts[0] > 0xff) { ... }
val |= parts[0] << 24;
break;
case 2:
case 3:
if (val > 0xffff) {
return 0;
}if (val > 0xffff) { ... }
if ((parts[0] > 0xff) || (parts[1] > 0xff)) {
return 0;
}if ((parts[0] > 0xff) || (parts[1] > 0xff)) { ... }
val |= (parts[0] << 24) | (parts[1] << 16);
break;
case 3:
case 4:
if (val > 0xff) {
return 0;
}if (val > 0xff) { ... }
if ((parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) {
return 0;
}if ((parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) { ... }
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
break;case 4:
default:
LWIP_ASSERT("unhandled", 0);
break;default
}switch (pp - parts + 1) { ... }
if (addr) {
ip4_addr_set_u32(addr, lwip_htonl(val));
}if (addr) { ... }
return 1;
}{ ... }
/* ... */
char *
ip4addr_ntoa(const ip4_addr_t *addr)
{
static char str[IP4ADDR_STRLEN_MAX];
return ip4addr_ntoa_r(addr, str, IP4ADDR_STRLEN_MAX);
}{ ... }
/* ... */
char *
ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen)
{
u32_t s_addr;
char inv[3];
char *rp;
u8_t *ap;
u8_t rem;
u8_t n;
u8_t i;
int len = 0;
s_addr = ip4_addr_get_u32(addr);
rp = buf;
ap = (u8_t *)&s_addr;
for (n = 0; n < 4; n++) {
i = 0;
do {
rem = *ap % (u8_t)10;
*ap /= (u8_t)10;
inv[i++] = (char)('0' + rem);
...} while (*ap);
while (i--) {
if (len++ >= buflen) {
return NULL;
}if (len++ >= buflen) { ... }
*rp++ = inv[i];
}while (i--) { ... }
if (len++ >= buflen) {
return NULL;
}if (len++ >= buflen) { ... }
*rp++ = '.';
ap++;
}for (n = 0; n < 4; n++) { ... }
*--rp = 0;
return buf;
}{ ... }
/* ... */#endif