std C/C++ patch #11
David Scott Page
page at cs.utexas.edu
Mon Apr 29 19:02:54 EDT 2002
Hi,
I don't really expect you'll apply this patch directly, but I wanted
to bring these details to your attention.
click_ip.h
- Per C99 (and presumably earlier, related standards), bitfields are
of type (un)signed int or _Bool, or implementation defined. Picky
KCC complains about the uint8_t (I'd agree, since I don't think
uint8_t increases comprehension, and might even be a bit
misleading), but I think if I turn off the strict option for the C
compiler, it will stop complaining.
- Since it is a .h file, I moved the closing __cplusplus test to the
end, necessitating the other changes.
I doubt you'll really want to do all this, but one thing you might
want to consider is renaming lib/in_cksum.c to a C++ extension. I
think it is the only C file including click_ip.h, and thus, the only
one requiring any C code in click_ip.h (causing the problem with the
inline click_update_in_cksum and comment).
clp.h
- Sun has interpreted the C standard to preclude the fancy 64-bit
integer types in an ILP32 environment. Technically, I think long
long int is also not part of the standard, but KCC has a special
flag to allow it (such a popular extension).
--
Scott Page
-------------------------------- 8< -------------------------------------
diff -Naur click-20020427/include/click/click_ip.h click-20020427a/include/click/click_ip.h
--- click-20020427/include/click/click_ip.h Tue Apr 9 06:03:58 2002
+++ click-20020427a/include/click/click_ip.h Sun Apr 28 03:17:01 2002
@@ -13,8 +13,6 @@
# include <netinet/in.h>
uint16_t click_in_cksum(const unsigned char *addr, int len);
#endif
-CLICK_CXX_UNPROTECT
-#include <click/cxxunprotect.h>
/*
* click_ip.h -- our own definitions of IP headers
@@ -23,11 +21,21 @@
struct click_ip {
#if CLICK_BYTE_ORDER == CLICK_LITTLE_ENDIAN
+#if __STDC__
+ unsigned ip_hl : 4; /* 0 header length */
+ unsigned ip_v : 4; /* version == 4 */
+#else
uint8_t ip_hl : 4; /* 0 header length */
uint8_t ip_v : 4; /* version == 4 */
+#endif /* __STDC__ */
#elif CLICK_BYTE_ORDER == CLICK_BIG_ENDIAN
+#if __STDC__
+ unsigned ip_v : 4; /* 0 version == 4 */
+ unsigned ip_hl : 4; /* header length */
+#else
uint8_t ip_v : 4; /* 0 version == 4 */
uint8_t ip_hl : 4; /* header length */
+#endif /* __STDC__ */
#else
# error "unknown byte order"
#endif
@@ -113,14 +121,20 @@
#define IP_ISFRAG(iph) (((iph)->ip_off & htons(IP_MF | IP_OFFMASK)) != 0)
#define IP_FIRSTFRAG(iph) (((iph)->ip_off & htons(IP_OFFMASK)) == 0)
+#if __cplusplus
static inline void
+#else
+static void
+#endif
click_update_in_cksum(uint16_t *csum, uint16_t old_hw, uint16_t new_hw)
{
- // incrementally update IP checksum according to RFC1624:
- // new_sum = ~(~old_sum + ~old_halfword + new_halfword)
+ /* incrementally update IP checksum according to RFC1624:
+ new_sum = ~(~old_sum + ~old_halfword + new_halfword) */
uint32_t sum = (~*csum & 0xFFFF) + (~old_hw & 0xFFFF) + new_hw;
sum = (sum & 0xFFFF) + (sum >> 16);
*csum = ~(sum + (sum >> 16));
}
+CLICK_CXX_UNPROTECT
+#include <click/cxxunprotect.h>
#endif
diff -Naur click-20020427/include/click/clp.h click-20020427a/include/click/clp.h
--- click-20020427/include/click/clp.h Thu Oct 4 18:50:50 2001
+++ click-20020427a/include/click/clp.h Sun Apr 28 02:55:18 2002
@@ -91,8 +91,13 @@
char *s;
void *pv;
#ifdef HAVE_INT64_TYPES
+#if __STDC__
+ long long int i64;
+ unsigned long long int u64;
+#else
int64_t i64;
uint64_t u64;
+#endif
#endif
char cs[Clp_ValSize];
unsigned char ucs[Clp_ValSize];
More information about the click
mailing list