Index: /trunk/include/iprt/net.h
===================================================================
--- /trunk/include/iprt/net.h	(revision 10981)
+++ /trunk/include/iprt/net.h	(revision 10982)
@@ -198,6 +198,6 @@
 /** @} */
 
-RTDECL(uint16_t) RTNetIPv4Checksum(PCRTNETIPV4 pIpHdr);
-RTDECL(bool)     RTNetIPv4IsValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax);
+RTDECL(uint16_t) RTNetIPv4HdrChecksum(PCRTNETIPV4 pIpHdr);
+RTDECL(bool)     RTNetIPv4IsHdrValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax);
 RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr);
 RTDECL(uint32_t) RTNetIPv4PseudoChecksumBits(RTNETADDRIPV4 SrcAddr, RTNETADDRIPV4 DstAddr, uint8_t bProtocol, uint16_t cbPkt);
@@ -232,4 +232,5 @@
 
 RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t iSum);
+RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData);
 
 
Index: /trunk/src/VBox/Runtime/common/checksum/ipv4.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/checksum/ipv4.cpp	(revision 10981)
+++ /trunk/src/VBox/Runtime/common/checksum/ipv4.cpp	(revision 10982)
@@ -43,5 +43,5 @@
  *                      Assumes the caller already checked the minimum size requirement.
  */
-RTDECL(uint16_t) RTNetIPv4Checksum(PCRTNETIPV4 pIpHdr)
+RTDECL(uint16_t) RTNetIPv4HdrChecksum(PCRTNETIPV4 pIpHdr)
 {
     uint16_t const *paw = (uint16_t const *)pIpHdr;
@@ -96,5 +96,5 @@
  *                      to be mapped following pIpHdr.
  */
-RTDECL(bool) RTNetIPv4IsValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax)
+RTDECL(bool) RTNetIPv4IsHdrsValid(PCRTNETIPV4 pIpHdr, size_t cbHdrMax, size_t cbPktMax)
 {
     Assert(cbPktMax >= cbHdrMax);
@@ -112,5 +112,5 @@
     if (RT_UNLIKELY(RT_BE2H_U16(pIpHdr->ip_len) > cbPktMax))
         return false;
-    uint16_t u16Sum = RTNetIPv4Checksum(pIpHdr);
+    uint16_t u16Sum = RTNetIPv4HdrChecksum(pIpHdr);
     if (RT_UNLIKELY(RT_BE2H_U16(pIpHdr->ip_sum) != u16Sum))
         return false;
@@ -120,10 +120,10 @@
 
 /**
- * Calculates the checksum of a pseudo header given an IPv4 header.
+ * Calculates the checksum of a pseudo header given an IPv4 header [inlined].
  *
  * @returns 32-bit intermediary checksum value.
  * @param   pIpHdr      The IP header (network endian (big)).
  */
-RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr)
+DECLINLINE(uint32_t) rtNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr)
 {
     uint16_t cbPayload = RT_BE2H_U16(pIpHdr->ip_len) - pIpHdr->ip_hl * 4;
@@ -143,4 +143,16 @@
 
 /**
+ * Calculates the checksum of a pseudo header given an IPv4 header.
+ *
+ * @returns 32-bit intermediary checksum value.
+ * @param   pIpHdr      The IP header (network endian (big)).
+ */
+RTDECL(uint32_t) RTNetIPv4PseudoChecksum(PCRTNETIPV4 pIpHdr)
+{
+    return rtNetIPv4PseudoChecksum(pIpHdr);
+}
+
+
+/**
  * Calculates the checksum of a pseudo header given the individual components.
  *
@@ -168,5 +180,5 @@
 
 /**
- * Adds the checksum of the UDP header to the intermediate checksum value.
+ * Adds the checksum of the UDP header to the intermediate checksum value [inlined].
  *
  * @returns 32-bit intermediary checksum value.
@@ -174,5 +186,5 @@
  * @param   iSum            The 32-bit intermediate checksum value.
  */
-RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t iSum)
+DECLINLINE(uint32_t) rtNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t iSum)
 {
     iSum += pUdpHdr->uh_sport
@@ -185,5 +197,18 @@
 
 /**
- * Adds the checksum of the TCP header to the intermediate checksum value.
+ * Adds the checksum of the UDP header to the intermediate checksum value.
+ *
+ * @returns 32-bit intermediary checksum value.
+ * @param   pUdpHdr         Pointer to the UDP header to checksum, network endian (big).
+ * @param   iSum            The 32-bit intermediate checksum value.
+ */
+RTDECL(uint32_t) RTNetIPv4AddUDPChecksum(PCRTNETUDP pUdpHdr, uint32_t iSum)
+{
+    return rtNetIPv4AddUDPChecksum(pUdpHdr,iSum);
+}
+
+
+/**
+ * Adds the checksum of the TCP header to the intermediate checksum value [inlined].
  *
  * @returns 32-bit intermediary checksum value.
@@ -193,5 +218,5 @@
  * @param   iSum            The 32-bit intermediate checksum value.
  */
-RTDECL(uint32_t) RTNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr, uint32_t iSum)
+DECLINLINE(uint32_t) rtNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr, uint32_t iSum)
 {
     uint16_t const *paw = (uint16_t const *)pTcpHdr;
@@ -231,5 +256,20 @@
 
 /**
- * Adds the checksum of the specified data segment to the intermediate checksum value.
+ * Adds the checksum of the TCP header to the intermediate checksum value.
+ *
+ * @returns 32-bit intermediary checksum value.
+ * @param   pUdpHdr         Pointer to the TCP header to checksum, network endian (big).
+ *                          Assums the caller has already validate it and made sure the
+ *                          entire header is present.
+ * @param   iSum            The 32-bit intermediate checksum value.
+ */
+RTDECL(uint32_t) RTNetIPv4AddTCPChecksum(PCRTNETTCP pTcpHdr, uint32_t iSum)
+{
+    return rtNetIPv4AddTCPChecksum(pTcpHdr, iSum);
+}
+
+
+/**
+ * Adds the checksum of the specified data segment to the intermediate checksum value [inlined].
  *
  * @returns 32-bit intermediary checksum value.
@@ -240,5 +280,5 @@
  *                          or UDP header (data never start at an odd offset).
  */
-RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t iSum, bool *pfOdd)
+DECLINLINE(uint32_t) rtNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t iSum, bool *pfOdd)
 {
     if (*pfOdd)
@@ -263,5 +303,5 @@
     {
         iSum += *pw;
-        pw += 2;
+        pw++;
         cbData -= 2;
     }
@@ -282,12 +322,27 @@
 }
 
-
-/**
- * Finalizes a IPv4 checksum.
+/**
+ * Adds the checksum of the specified data segment to the intermediate checksum value.
+ *
+ * @returns 32-bit intermediary checksum value.
+ * @param   pUdpHdr         Pointer to the UDP header to checksum, network endian (big).
+ * @param   iSum            The 32-bit intermediate checksum value.
+ * @param   pfOdd           This is used to keep track of odd bits, initialize to false
+ *                          when starting to checksum the data (aka text) after a TCP
+ *                          or UDP header (data never start at an odd offset).
+ */
+RTDECL(uint32_t) RTNetIPv4AddDataChecksum(void const *pvData, size_t cbData, uint32_t iSum, bool *pfOdd)
+{
+    return rtNetIPv4AddDataChecksum(pvData, cbData, iSum, pfOdd);
+}
+
+
+/**
+ * Finalizes a IPv4 checksum [inlined].
  *
  * @returns The checksum.
  * @param   iSum            The 32-bit intermediate checksum value.
  */
-RTDECL(uint16_t) RTNetIPv4FinalizeChecksum(uint32_t iSum)
+DECLINLINE(uint16_t) rtNetIPv4FinalizeChecksum(uint32_t iSum)
 {
     /* 16-bit one complement fun */
@@ -298,3 +353,37 @@
 
 
-
+/**
+ * Finalizes a IPv4 checksum.
+ *
+ * @returns The checksum.
+ * @param   iSum            The 32-bit intermediate checksum value.
+ */
+RTDECL(uint16_t) RTNetIPv4FinalizeChecksum(uint32_t iSum)
+{
+    return rtNetIPv4FinalizeChecksum(iSum);
+}
+
+
+
+/**
+ * Calculates the checksum for the UDP header given the IP header,
+ * UDP header and payload.
+ *
+ * @returns The checksum.
+ * @param   pIpHdr          Pointer to the IPv4 header, in network endian (big).
+ * @param   pUdpHdr         Pointer to the UDP header, in network endian (big).
+ * @param   pvData          Pointer to the UDP payload. The size is taken from the
+ *                          UDP header and the caller is supposed to have validated
+ *                          this before calling.
+ */
+RTDECL(uint16_t) RTNetIPv4UDPChecksum(PCRTNETIPV4 pIpHdr, PCRTNETUDP pUdpHdr, void const *pvData)
+{
+    uint32_t iSum = RTNetIPv4PseudoChecksum(pIpHdr);
+    iSum = RTNetIPv4AddUDPChecksum(pUdpHdr, iSum);
+    bool fOdd = false;
+    iSum = RTNetIPv4AddDataChecksum(pvData, RT_BE2H_U16(pUdpHdr->uh_ulen) - sizeof(*pUdpHdr), iSum, &fOdd);
+    iSum = RTNetIPv4FinalizeChecksum(iSum);
+    return iSum;
+}
+
+
