ReactOS 0.4.16-dev-477-g6ada597
inet_chksum.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
Include dependency graph for inet_chksum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SWAP_BYTES_IN_WORD(w)   (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
 
#define FOLD_U32T(u)   ((u32_t)(((u) >> 16) + ((u) & 0x0000ffffUL)))
 
#define LWIP_CHKSUM_COPY_ALGORITHM   0
 

Functions

u16_t inet_chksum (const void *dataptr, u16_t len)
 
u16_t inet_chksum_pbuf (struct pbuf *p)
 
u16_t ip_chksum_pseudo (struct pbuf *p, u8_t proto, u16_t proto_len, const ip_addr_t *src, const ip_addr_t *dest)
 
u16_t ip_chksum_pseudo_partial (struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest)
 

Detailed Description

IP checksum calculation functions

Definition in file inet_chksum.h.

Macro Definition Documentation

◆ FOLD_U32T

#define FOLD_U32T (   u)    ((u32_t)(((u) >> 16) + ((u) & 0x0000ffffUL)))

Split an u32_t in two u16_ts and add them up

Definition at line 52 of file inet_chksum.h.

◆ LWIP_CHKSUM_COPY_ALGORITHM

#define LWIP_CHKSUM_COPY_ALGORITHM   0

Definition at line 67 of file inet_chksum.h.

◆ SWAP_BYTES_IN_WORD

#define SWAP_BYTES_IN_WORD (   w)    (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)

Swap the bytes in an u16_t: much like lwip_htons() for little-endian

Definition at line 47 of file inet_chksum.h.

Function Documentation

◆ inet_chksum()

u16_t inet_chksum ( const void dataptr,
u16_t  len 
)

Definition at line 555 of file inet_chksum.c.

556{
557 return (u16_t)~(unsigned int)LWIP_CHKSUM(dataptr, len);
558}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLenum GLsizei len
Definition: glext.h:6722
uint16_t u16_t
Definition: arch.h:127
#define LWIP_CHKSUM
Definition: inet_chksum.c:57
int const JOCTET * dataptr
Definition: jpeglib.h:1031

Referenced by create_ip4_input_fragment(), tcp_create_segment_wnd(), and test_udp_create_test_packet().

◆ 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 568 of file inet_chksum.c.

569{
570 u32_t acc;
571 struct pbuf *q;
572 int swapped = 0;
573
574 acc = 0;
575 for (q = p; q != NULL; q = q->next) {
576 acc += LWIP_CHKSUM(q->payload, q->len);
577 acc = FOLD_U32T(acc);
578 if (q->len % 2 != 0) {
579 swapped = !swapped;
580 acc = SWAP_BYTES_IN_WORD(acc);
581 }
582 }
583
584 if (swapped) {
585 acc = SWAP_BYTES_IN_WORD(acc);
586 }
587 return (u16_t)~(acc & 0xffffUL);
588}
#define NULL
Definition: types.h:112
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
uint32_t u32_t
Definition: arch.h:129
#define SWAP_BYTES_IN_WORD(w)
Definition: inet_chksum.h:47
#define FOLD_U32T(u)
Definition: inet_chksum.h:52
struct define * next
Definition: compiler.c:65
Definition: pbuf.h:186

◆ ip_chksum_pseudo()

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

Definition at line 379 of file inet_chksum.c.

381{
382#if LWIP_IPV6
383 if (IP_IS_V6(dest)) {
384 return ip6_chksum_pseudo(p, proto, proto_len, ip_2_ip6(src), ip_2_ip6(dest));
385 }
386#endif /* LWIP_IPV6 */
387#if LWIP_IPV4 && LWIP_IPV6
388 else
389#endif /* LWIP_IPV4 && LWIP_IPV6 */
390#if LWIP_IPV4
391 {
392 return inet_chksum_pseudo(p, proto, proto_len, ip_2_ip4(src), ip_2_ip4(dest));
393 }
394#endif /* LWIP_IPV4 */
395}
GLenum src
Definition: glext.h:6340
#define ip_2_ip6(ipaddr)
Definition: ip_addr.h:356
#define IP_IS_V6(ipaddr)
Definition: ip_addr.h:350
static char * dest
Definition: rtl.c:135

Referenced by START_TEST(), and tcp_create_segment_wnd().

◆ ip_chksum_pseudo_partial()

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

Definition at line 526 of file inet_chksum.c.

528{
529#if LWIP_IPV6
530 if (IP_IS_V6(dest)) {
531 return ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip6(src), ip_2_ip6(dest));
532 }
533#endif /* LWIP_IPV6 */
534#if LWIP_IPV4 && LWIP_IPV6
535 else
536#endif /* LWIP_IPV4 && LWIP_IPV6 */
537#if LWIP_IPV4
538 {
539 return inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip4(src), ip_2_ip4(dest));
540 }
541#endif /* LWIP_IPV4 */
542}