summaryrefslogtreecommitdiff
path: root/lib/checksum.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/checksum.c')
-rw-r--r--lib/checksum.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/checksum.c b/lib/checksum.c
index 94cf71e8..2ffc1770 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -1,11 +1,15 @@
/*
* BIRD Library -- IP One-Complement Checksum
*
- * (c) 1999 Martin Mares <mj@ucw.cz>
+ * (c) 1999--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
+/**
+ * DOC: Miscellaneous functions.
+ */
+
#include <stdarg.h>
#include "nest/bird.h"
@@ -83,6 +87,20 @@ ipsum_calc(void *frag, unsigned len, va_list args)
return sum;
}
+/**
+ * ipsum_verify - verify an IP checksum
+ * @frag: first packet fragment
+ * @len: length in bytes
+ *
+ * This function verifies whether a given fragmented packet
+ * has correct one's complement checksum as used by the IP
+ * protocol.
+ *
+ * It uses all the clever tricks described in RFC 1071 to speed
+ * up checksum calculation as much as possible.
+ *
+ * Result: 1 if the checksum is correct, 0 else.
+ */
int
ipsum_verify(void *frag, unsigned len, ...)
{
@@ -95,6 +113,17 @@ ipsum_verify(void *frag, unsigned len, ...)
return sum == 0xffff;
}
+/**
+ * ipsum_calculate - compute an IP checksum
+ * @frag: first packet fragment
+ * @len: length in bytes
+ *
+ * This function caculates a one's complement checksum of a given fragmented
+ * packet.
+ *
+ * It uses all the clever tricks described in RFC 1071 to speed
+ * up checksum calculation as much as possible.
+ */
u16
ipsum_calculate(void *frag, unsigned len, ...)
{