#include "lwip/opt.h"#include "lwip/arch.h"#include "lwip/def.h"#include "lwip/inet.h"#include <ctype.h>Include dependency graph for inet.c:
Go to the source code of this file.
Defines | |
| #define | htons HTONS |
| #define | htonl HTONL |
Functions | |
| u16_t | lwip_chksum (void *dataptr, int len) |
| u16_t | inet_chksum_pseudo (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t proto, u16_t proto_len) |
| u16_t | inet_chksum (void *dataptr, u16_t len) |
| u16_t | inet_chksum_pbuf (struct pbuf *p) |
| u32_t | inet_addr (const char *cp) |
| int | inet_aton (const char *cp, struct in_addr *addr) |
| unsigned int | i2a (char *dest, unsigned int x) |
| char * | inet_ntoa (struct in_addr in) |
|
|
|
|
|
|
|
||||||||||||
|
Definition at line 333 of file inet.c. References len. Referenced by inet_ntoa().
|
|
|
Definition at line 221 of file inet.c. References INADDR_NONE, inet_aton(), in_addr::s_addr, and u32_t. Referenced by dns_client(), and fake_hostent().
00222 {
00223 struct in_addr val;
00224
00225 if (inet_aton(cp, &val)) {
00226 return (val.s_addr);
00227 }
00228 return (INADDR_NONE);
00229 }
|
Here is the call graph for this function:
|
||||||||||||
|
Definition at line 240 of file inet.c. References htonl, in_addr::s_addr, and u32_t. Referenced by dns_client(), inet_addr(), and sock_udpclient().
00241 {
00242 u32_t val;
00243 int base, n;
00244 char c;
00245 // u_int parts[4];
00246 // u_int *pp = parts;
00247 u32_t parts[4];
00248 u32_t* pp = parts;
00249
00250 c = *cp;
00251 for (;;) {
00252 /*
00253 * Collect number up to ``.''.
00254 * Values are specified as for C:
00255 * 0x=hex, 0=octal, isdigit=decimal.
00256 */
00257 if (!isdigit(c))
00258 return (0);
00259 val = 0; base = 10;
00260 if (c == '0') {
00261 c = *++cp;
00262 if (c == 'x' || c == 'X')
00263 base = 16, c = *++cp;
00264 else
00265 base = 8;
00266 }
00267 for (;;) {
00268 if (isascii(c) && isdigit(c)) {
00269 val = (val * base) + (c - '0');
00270 c = *++cp;
00271 } else if (base == 16 && isascii(c) && isxdigit(c)) {
00272 val = (val << 4) |
00273 (c + 10 - (islower(c) ? 'a' : 'A'));
00274 c = *++cp;
00275 } else
00276 break;
00277 }
00278 if (c == '.') {
00279 /*
00280 * Internet format:
00281 * a.b.c.d
00282 * a.b.c (with c treated as 16 bits)
00283 * a.b (with b treated as 24 bits)
00284 */
00285 if (pp >= parts + 3)
00286 return (0);
00287 *pp++ = val;
00288 c = *++cp;
00289 } else
00290 break;
00291 }
00292 /*
00293 * Check for trailing characters.
00294 */
00295 if (c != '\0' && (!isascii(c) || !isspace(c)))
00296 return (0);
00297 /*
00298 * Concoct the address according to
00299 * the number of parts specified.
00300 */
00301 n = pp - parts + 1;
00302 switch (n) {
00303
00304 case 0:
00305 return (0); /* initial nondigit */
00306
00307 case 1: /* a -- 32 bits */
00308 break;
00309
00310 case 2: /* a.b -- 8.24 bits */
00311 if (val > 0xffffff)
00312 return (0);
00313 val |= parts[0] << 24;
00314 break;
00315
00316 case 3: /* a.b.c -- 8.8.16 bits */
00317 if (val > 0xffff)
00318 return (0);
00319 val |= (parts[0] << 24) | (parts[1] << 16);
00320 break;
00321
00322 case 4: /* a.b.c.d -- 8.8.8.8 bits */
00323 if (val > 0xff)
00324 return (0);
00325 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
00326 break;
00327 }
00328 if (addr)
00329 addr->s_addr = htonl(val);
00330 return (1);
00331 }
|
|
||||||||||||
|
Definition at line 141 of file inet.c.
00142 {
00143 u32_t acc;
00144
00145 acc = lwip_chksum(dataptr, len);
00146 while(acc >> 16) {
00147 acc = (acc & 0xffff) + (acc >> 16);
00148 }
00149 return ~(acc & 0xffff);
00150 }
|
|
|
Definition at line 153 of file inet.c.
00154 {
00155 u32_t acc;
00156 struct pbuf *q;
00157 u8_t swapped;
00158
00159 acc = 0;
00160 swapped = 0;
00161 for(q = p; q != NULL; q = q->next) {
00162 acc += lwip_chksum(q->payload, q->len);
00163 while(acc >> 16) {
00164 acc = (acc & 0xffffUL) + (acc >> 16);
00165 }
00166 if(q->len % 2 != 0) {
00167 swapped = 1 - swapped;
00168 acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
00169 }
00170 }
00171
00172 if(swapped) {
00173 acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
00174 }
00175 return ~(acc & 0xffffUL);
00176 }
|
|
||||||||||||||||||||||||
|
Definition at line 92 of file inet.c.
00095 {
00096 u32_t acc;
00097 struct pbuf *q;
00098 u8_t swapped;
00099
00100 acc = 0;
00101 swapped = 0;
00102 /* iterate through all pbuf in chain */
00103 for(q = p; q != NULL; q = q->next) {
00104 DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n", (void *) q, (void *)q->next));
00105 acc += lwip_chksum(q->payload, q->len);
00106 /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%lx \n", acc));*/
00107 while(acc >> 16) {
00108 acc = (acc & 0xffffUL) + (acc >> 16);
00109 }
00110 if(q->len % 2 != 0) {
00111 swapped = 1 - swapped;
00112 acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
00113 }
00114 /*DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%lx \n", acc));*/
00115 }
00116
00117 if(swapped) {
00118 acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
00119 }
00120 acc += (src->addr & 0xffffUL);
00121 acc += ((src->addr >> 16) & 0xffffUL);
00122 acc += (dest->addr & 0xffffUL);
00123 acc += ((dest->addr >> 16) & 0xffffUL);
00124 acc += (u32_t)htons((u16_t)proto);
00125 acc += (u32_t)htons(proto_len);
00126
00127 while(acc >> 16) {
00128 acc = (acc & 0xffffUL) + (acc >> 16);
00129 }
00130 DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%lx\n", acc));
00131 return ~(acc & 0xffffUL);
00132 }
|
|
|
Definition at line 342 of file inet.c. Referenced by dns_client_callback(), and main().
00342 {
00343 static char buf[20];
00344 unsigned int len;
00345 unsigned char *ip=(unsigned char*)∈
00346 len=i2a(buf,ip[0]); buf[len]='.'; ++len;
00347 len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len;
00348 len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len;
00349 len+=i2a(buf+ len,ip[3]); buf[len]=0;
00350 return buf;
00351 }
|
Here is the call graph for this function:
|
||||||||||||
|
Definition at line 59 of file inet.c. References DEBUGF, htons, INET_DEBUG, len, u16_t, u32_t, and u8_t. Referenced by inet_chksum(), inet_chksum_pbuf(), and inet_chksum_pseudo().
00060 {
00061 u32_t acc;
00062
00063 DEBUGF(INET_DEBUG, ("lwip_chksum(%p, %d)\n", dataptr, len));
00064 for(acc = 0; len > 1; len -= 2) {
00065 /* acc = acc + *((u16_t *)dataptr)++;*/
00066 acc += *(u16_t *)dataptr;
00067 dataptr = (void *)((u16_t *)dataptr + 1);
00068 }
00069
00070 /* add up any odd byte */
00071 if(len == 1) {
00072 acc += htons((u16_t)((*(u8_t *)dataptr) & 0xff) << 8);
00073 DEBUGF(INET_DEBUG, ("inet: chksum: odd byte %d\n", *(u8_t *)dataptr));
00074 } else {
00075 DEBUGF(INET_DEBUG, ("inet: chksum: no odd byte\n"));
00076 }
00077 acc = (acc >> 16) + (acc & 0xffffUL);
00078
00079 if((acc & 0xffff0000) != 0) {
00080 acc = (acc >> 16) + (acc & 0xffffUL);
00081 }
00082
00083 return (u16_t)acc;
00084 }
|
1.3.4