summaryrefslogtreecommitdiff
path: root/sys/netinet/in.h
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-06-24 23:41:48 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-06-24 23:41:48 +0000
commit75e447d863f7a9d1456dd2cc81e117408f2b55b6 (patch)
treee99fac8cbb04daa0dce30a567c78da2861a6aea8 /sys/netinet/in.h
parent033a42cbd2200a951448b4643610a2f12c7ed64f (diff)
Import in_cksum_phdr() and in_cksum_addword() from NetBSD.
Diffstat (limited to 'sys/netinet/in.h')
-rw-r--r--sys/netinet/in.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 25dcd58b73a..2c91f6673dd 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.h,v 1.50 2001/06/24 23:33:55 angelos Exp $ */
+/* $OpenBSD: in.h,v 1.51 2001/06/24 23:41:47 angelos Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
@@ -494,6 +494,53 @@ struct ip_mreq {
#include <sys/cdefs.h>
+/*
+ * in_cksum_phdr:
+ *
+ * Compute significant parts of the IPv4 checksum pseudo-header
+ * for use in a delayed TCP/UDP checksum calculation.
+ *
+ * Args:
+ *
+ * src Source IP address
+ * dst Destination IP address
+ * lenproto htons(proto-hdr-len + proto-number)
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
+{
+ u_int32_t sum;
+
+ sum = lenproto +
+ (u_int16_t)(src >> 16) +
+ (u_int16_t)(src /*& 0xffff*/) +
+ (u_int16_t)(dst >> 16) +
+ (u_int16_t)(dst /*& 0xffff*/);
+
+ sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
+/*
+ * in_cksum_addword:
+ *
+ * Add the two 16-bit network-order values, carry, and return.
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_addword(u_int16_t a, u_int16_t b)
+{
+ u_int32_t sum = a + b;
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
+}
+
__BEGIN_DECLS
int bindresvport __P((int, struct sockaddr_in *));
struct sockaddr;