ReactOS 0.4.15-dev-8096-ga0eec98
inet_chksum.c File Reference
#include "lwip/opt.h"
#include "lwip/inet_chksum.h"
#include "lwip/def.h"
#include <stddef.h>
#include <string.h>
Include dependency graph for inet_chksum.c:

Go to the source code of this file.

Macros

#define LWIP_CHKSUM   lwip_standard_chksum
 
#define LWIP_CHKSUM_ALGORITHM   2
 

Functions

static u16_t lwip_standard_chksum (void *dataptr, int len)
 
u16_t inet_chksum_pseudo (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len)
 
u16_t inet_chksum_pseudo_partial (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len, u16_t chksum_len)
 
u16_t inet_chksum (void *dataptr, u16_t len)
 
u16_t inet_chksum_pbuf (struct pbuf *p)
 

Detailed Description

Incluse internet checksum functions.

Definition in file inet_chksum.c.

Macro Definition Documentation

◆ LWIP_CHKSUM

#define LWIP_CHKSUM   lwip_standard_chksum

Definition at line 59 of file inet_chksum.c.

◆ LWIP_CHKSUM_ALGORITHM

#define LWIP_CHKSUM_ALGORITHM   2

Definition at line 61 of file inet_chksum.c.

Function Documentation

◆ inet_chksum()

u16_t inet_chksum ( void dataptr,
u16_t  len 
)

Definition at line 396 of file inet_chksum.c.

397{
398 return ~LWIP_CHKSUM(dataptr, len);
399}
GLenum GLsizei len
Definition: glext.h:6722
int const JOCTET * dataptr
Definition: jpeglib.h:1031

Referenced by ip_input(), and tcp_create_segment_wnd().

◆ inet_chksum_pbuf()

u16_t inet_chksum_pbuf ( struct pbuf p)

Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used).

Parameters
ppbuf chain over that the checksum should be calculated
Returns
checksum (as u16_t) to be saved directly in the protocol header

Definition at line 409 of file inet_chksum.c.

410{
411 u32_t acc;
412 struct pbuf *q;
413 u8_t swapped;
414
415 acc = 0;
416 swapped = 0;
417 for(q = p; q != NULL; q = q->next) {
418 acc += LWIP_CHKSUM(q->payload, q->len);
419 acc = FOLD_U32T(acc);
420 if (q->len % 2 != 0) {
421 swapped = 1 - swapped;
422 acc = SWAP_BYTES_IN_WORD(acc);
423 }
424 }
425
426 if (swapped) {
427 acc = SWAP_BYTES_IN_WORD(acc);
428 }
429 return (u16_t)~(acc & 0xffffUL);
430}
#define NULL
Definition: types.h:112
unsigned long u32_t
Definition: cc.h:25
unsigned char u8_t
Definition: cc.h:23
unsigned short u16_t
Definition: cc.h:24
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define LWIP_CHKSUM
Definition: inet_chksum.c:59
#define SWAP_BYTES_IN_WORD(w)
Definition: inet_chksum.h:47
#define FOLD_U32T(u)
Definition: inet_chksum.h:53
struct define * next
Definition: compiler.c:65
Definition: pbuf.h:79

◆ inet_chksum_pseudo()

u16_t inet_chksum_pseudo ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  proto,
u16_t  proto_len 
)

Definition at line 272 of file inet_chksum.c.

275{
276 u32_t acc;
277 u32_t addr;
278 struct pbuf *q;
279 u8_t swapped;
280
281 acc = 0;
282 swapped = 0;
283 /* iterate through all pbuf in chain */
284 for(q = p; q != NULL; q = q->next) {
285 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n",
286 (void *)q, (void *)q->next));
287 acc += LWIP_CHKSUM(q->payload, q->len);
288 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
289 /* just executing this next line is probably faster that the if statement needed
290 to check whether we really need to execute it, and does no harm */
291 acc = FOLD_U32T(acc);
292 if (q->len % 2 != 0) {
293 swapped = 1 - swapped;
294 acc = SWAP_BYTES_IN_WORD(acc);
295 }
296 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
297 }
298
299 if (swapped) {
300 acc = SWAP_BYTES_IN_WORD(acc);
301 }
303 acc += (addr & 0xffffUL);
304 acc += ((addr >> 16) & 0xffffUL);
306 acc += (addr & 0xffffUL);
307 acc += ((addr >> 16) & 0xffffUL);
308 acc += (u32_t)htons((u16_t)proto);
309 acc += (u32_t)htons(proto_len);
310
311 /* Fold 32-bit sum to 16 bits
312 calling this twice is propably faster than if statements... */
313 acc = FOLD_U32T(acc);
314 acc = FOLD_U32T(acc);
315 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
316 return (u16_t)~(acc & 0xffffUL);
317}
#define X32_F
Definition: cc.h:41
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
GLenum src
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
#define INET_DEBUG
Definition: lwipopts.h:130
#define ip4_addr_get_u32(src_ipaddr)
Definition: ip_addr.h:181
#define htons(x)
Definition: module.h:215
static char * dest
Definition: rtl.c:135

Referenced by tcp_create_segment_wnd().

◆ inet_chksum_pseudo_partial()

u16_t inet_chksum_pseudo_partial ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len 
)

Definition at line 332 of file inet_chksum.c.

335{
336 u32_t acc;
337 u32_t addr;
338 struct pbuf *q;
339 u8_t swapped;
340 u16_t chklen;
341
342 acc = 0;
343 swapped = 0;
344 /* iterate through all pbuf in chain */
345 for(q = p; (q != NULL) && (chksum_len > 0); q = q->next) {
346 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n",
347 (void *)q, (void *)q->next));
348 chklen = q->len;
349 if (chklen > chksum_len) {
350 chklen = chksum_len;
351 }
352 acc += LWIP_CHKSUM(q->payload, chklen);
353 chksum_len -= chklen;
354 LWIP_ASSERT("delete me", chksum_len < 0x7fff);
355 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
356 /* fold the upper bit down */
357 acc = FOLD_U32T(acc);
358 if (q->len % 2 != 0) {
359 swapped = 1 - swapped;
360 acc = SWAP_BYTES_IN_WORD(acc);
361 }
362 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
363 }
364
365 if (swapped) {
366 acc = SWAP_BYTES_IN_WORD(acc);
367 }
369 acc += (addr & 0xffffUL);
370 acc += ((addr >> 16) & 0xffffUL);
372 acc += (addr & 0xffffUL);
373 acc += ((addr >> 16) & 0xffffUL);
374 acc += (u32_t)htons((u16_t)proto);
375 acc += (u32_t)htons(proto_len);
376
377 /* Fold 32-bit sum to 16 bits
378 calling this twice is propably faster than if statements... */
379 acc = FOLD_U32T(acc);
380 acc = FOLD_U32T(acc);
381 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
382 return (u16_t)~(acc & 0xffffUL);
383}
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66

◆ lwip_standard_chksum()

static u16_t lwip_standard_chksum ( void dataptr,
int  len 
)
static

Definition at line 135 of file inet_chksum.c.

136{
137 u8_t *pb = (u8_t *)dataptr;
138 u16_t *ps, t = 0;
139 u32_t sum = 0;
140 int odd = ((mem_ptr_t)pb & 1);
141
142 /* Get aligned to u16_t */
143 if (odd && len > 0) {
144 ((u8_t *)&t)[1] = *pb++;
145 len--;
146 }
147
148 /* Add the bulk of the data */
149 ps = (u16_t *)(void *)pb;
150 while (len > 1) {
151 sum += *ps++;
152 len -= 2;
153 }
154
155 /* Consume left-over byte, if any */
156 if (len > 0) {
157 ((u8_t *)&t)[0] = *(u8_t *)ps;
158 }
159
160 /* Add end bytes */
161 sum += t;
162
163 /* Fold 32-bit sum to 16 bits
164 calling this twice is propably faster than if statements... */
165 sum = FOLD_U32T(sum);
166 sum = FOLD_U32T(sum);
167
168 /* Swap if alignment was odd */
169 if (odd) {
171 }
172
173 return (u16_t)sum;
174}
ULONG_PTR mem_ptr_t
Definition: cc.h:33
GLdouble GLdouble t
Definition: gl.h:2047
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
Definition: unary.h:11