summaryrefslogtreecommitdiffstats
path: root/lib/libatm/ip_checksum.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-09-15 08:23:17 +0000
committerphk <phk@FreeBSD.org>1998-09-15 08:23:17 +0000
commitc3dd1fa899d435ea4bf79897f646a93cb80c94ac (patch)
tree98dfbc96e3c6aa7ff1f322855f6484c4e609819d /lib/libatm/ip_checksum.c
parent9ed6892f4808d56de443849229e151f8f7ad43b0 (diff)
downloadFreeBSD-src-c3dd1fa899d435ea4bf79897f646a93cb80c94ac.zip
FreeBSD-src-c3dd1fa899d435ea4bf79897f646a93cb80c94ac.tar.gz
Add new files for HARP3
Host ATM Research Platform (HARP), Network Computing Services, Inc. This software was developed with the support of the Defense Advanced Research Projects Agency (DARPA).
Diffstat (limited to 'lib/libatm/ip_checksum.c')
-rw-r--r--lib/libatm/ip_checksum.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/libatm/ip_checksum.c b/lib/libatm/ip_checksum.c
new file mode 100644
index 0000000..478f6ca
--- /dev/null
+++ b/lib/libatm/ip_checksum.c
@@ -0,0 +1,102 @@
+/*
+ *
+ * ===================================
+ * HARP | Host ATM Research Platform
+ * ===================================
+ *
+ *
+ * This Host ATM Research Platform ("HARP") file (the "Software") is
+ * made available by Network Computing Services, Inc. ("NetworkCS")
+ * "AS IS". NetworkCS does not provide maintenance, improvements or
+ * support of any kind.
+ *
+ * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
+ * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
+ * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
+ * In no event shall NetworkCS be responsible for any damages, including
+ * but not limited to consequential damages, arising from or relating to
+ * any use of the Software or related support.
+ *
+ * Copyright 1994-1998 Network Computing Services, Inc.
+ *
+ * Copies of this Software may be made, however, the above copyright
+ * notice must be reproduced on all copies.
+ *
+ * @(#) $Id: ip_checksum.c,v 1.4 1998/08/11 18:11:48 johnc Exp $
+ *
+ */
+
+
+/*
+ * User Space Library Functions
+ * ----------------------------
+ *
+ * IP checksum computation
+ *
+ */
+
+
+#ifndef lint
+static char *RCSid = "@(#) $Id: ip_checksum.c,v 1.4 1998/08/11 18:11:48 johnc Exp $";
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netatm/port.h>
+#include <netatm/atm.h>
+#include <netatm/atm_if.h>
+#include <netatm/atm_sap.h>
+#include <netatm/atm_sys.h>
+#include <netatm/atm_ioctl.h>
+
+#include "libatm.h"
+
+
+/*
+ * Compute an IP checksum
+ *
+ * This code was taken from RFC 1071.
+ *
+ * "The following "C" code algorithm computes the checksum with an inner
+ * loop that sums 16 bits at a time in a 32-bit accumulator."
+ *
+ * Arguments:
+ * addr pointer to the buffer whose checksum is to be computed
+ * count number of bytes to include in the checksum
+ *
+ * Returns:
+ * the computed checksum
+ *
+ */
+short
+ip_checksum(addr, count)
+ char *addr;
+ int count;
+{
+ /* Compute Internet Checksum for "count" bytes
+ * beginning at location "addr".
+ */
+ register long sum = 0;
+
+ while( count > 1 ) {
+ /* This is the inner loop */
+ sum += ntohs(* (unsigned short *) addr);
+ addr += sizeof(unsigned short);
+ count -= sizeof(unsigned short);
+ }
+
+ /* Add left-over byte, if any */
+ if( count > 0 )
+ sum += * (unsigned char *) addr;
+
+ /* Fold 32-bit sum to 16 bits */
+ while (sum>>16)
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ return((short)~sum);
+}
OpenPOWER on IntegriCloud