Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
labs
BIRD Internet Routing Daemon
Commits
1a54d44a
Commit
1a54d44a
authored
May 10, 1999
by
Martin Mareš
Browse files
Added packet checksumming code. Watch the comments for an explanation.
parent
a2697f02
Changes
3
Show whitespace changes
Inline
Side-by-side
lib/Modules
View file @
1a54d44a
...
...
@@ -27,3 +27,5 @@ slists.c
slists.h
event.c
event.h
checksum.c
checksum.h
lib/checksum.c
0 → 100644
View file @
1a54d44a
/*
* BIRD Library -- IP One-Complement Checksum
*
* (c) 1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include
<stdarg.h>
#include
"nest/bird.h"
#include
"checksum.h"
static
u16
ipsum_calc
(
void
*
frag
,
unsigned
len
,
va_list
args
)
{
u16
sum
=
0
;
for
(;;)
{
u16
*
x
=
frag
;
ASSERT
(
!
(
len
%
2
));
while
(
len
)
{
u16
z
=
sum
+
*
x
++
;
sum
=
z
+
(
z
<
sum
);
len
-=
2
;
}
frag
=
va_arg
(
args
,
void
*
);
if
(
!
frag
)
break
;
len
=
va_arg
(
args
,
unsigned
);
}
return
sum
;
}
int
ipsum_verify
(
void
*
frag
,
unsigned
len
,
...)
{
va_list
args
;
u16
sum
;
va_start
(
args
,
len
);
sum
=
ipsum_calc
(
frag
,
len
,
args
);
va_end
(
args
);
return
sum
==
0xffff
;
}
u16
ipsum_calculate
(
void
*
frag
,
unsigned
len
,
...)
{
va_list
args
;
u16
sum
;
va_start
(
args
,
len
);
sum
=
ipsum_calc
(
frag
,
len
,
args
);
va_end
(
args
);
return
0xffff
-
sum
;
}
lib/checksum.h
0 → 100644
View file @
1a54d44a
/*
* BIRD Library -- IP One-Complement Checksum
*
* (c) 1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_CHECKSUM_H_
#define _BIRD_CHECKSUM_H_
/*
* Both checksumming functions accept a vararg list of packet
* fragments finished by NULL pointer.
*/
int
ipsum_verify
(
void
*
frag
,
unsigned
len
,
...);
u16
ipsum_calculate
(
void
*
frag
,
unsigned
len
,
...);
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment