Packets/80211Bundle: Fix byteorder issues for radiotap parser
g0dil [Fri, 20 Aug 2010 10:31:07 +0000 (10:31 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1695 270642c3-0616-0410-b53a-bc976706d245

SConfigure
senf/Packets/80211Bundle/SConscript
senf/Packets/80211Bundle/radiotap.c
site_scons/site_tools/CustomTests.py

index 40382e8..249f9b7 100644 (file)
@@ -69,37 +69,6 @@ def CheckValgrindWildcards(context):
     context.Result( ret[0] )
     return ret[0]
 
-@env.ConfTest()
-def CheckExpression(context, name, expression, header="", language="C"):
-    import SCons.Conftest
-
-    lang, suffix, msg = SCons.Conftest._lang2suffix(language)
-    if msg:
-        context.Message("Cannot check for header file %s: \n" % header_name)
-        context.Result(msg)
-        return False
-
-    text = ("#include <assert.h>\n"
-            "%s\n"
-            "int main() {\n"
-            "%s;\n"
-            "return 0;\n"
-            "}\n") % (header, expression)
-
-    context.Message("Checking for valid %s expression %s... " % (lang, expression))
-    ret = context.TryLink(text, suffix)
-    context.Result(ret)
-    if ret:
-        import re
-        key = name.upper()
-        key = re.sub('[^A-Z0-9_]', '_', key)
-        context.sconf.Define("HAVE_%s" % key,
-                             1,
-                             "Define to 1 if the expression `%s' is valid on your system"
-                             % expression)
-
-    return ret
-
 ###########################################################################
 
 conf = env.Configure(clean=False, help=False, config_h="#/senf/autoconf.hh")
@@ -116,10 +85,11 @@ res = conf.CheckTempBufferStrategy()
 
 # Standard library stuff
 res = conf.CheckFunc("timerfd_create")
-res = conf.CheckExpression("le16toh", "le16toh(0)",
-                           "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
-res = conf.CheckExpression("le32toh", "le32toh(0)",
-                           "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
+res = conf.CheckSymbolWithExpression(
+    "le16toh", "le16toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
+res = conf.CheckSymbolWithExpression(
+    "le32toh", "le32toh(0)", "#include <senf/Packets/80211Bundle/radiotap/platform.h>")
+res = conf.CheckByteorder()
 res = conf.CheckSTLCopyN(); \
     conf.env.Fail(condition=not res, message="No 'copy_n' implementation found")
 
index 6ea2d44..5f7c5d9 100644 (file)
@@ -7,5 +7,4 @@ import SENFSCons
 
 SConscript(env.Glob("*/SConscript"))
 
-SENFSCons.AutoPacketBundle(env, '80211Bundle',
-                           subdirs=['radiotap'], exclude=['radiotap/radiotap.c'])
+SENFSCons.AutoPacketBundle(env, '80211Bundle')
index f176a55..fa6c67d 100644 (file)
 
 # include <senf/autoconf.hh>
 #
-# ifndef HAVE_LE16TOH
-#     define le16toh(x) (x)
-# endif
-#
-# ifndef HAVE_LE32TOH
-#     define le32toh(x) (x)
+# ifdef BYTEORDER_LITTLE_ENDIAN
+#     ifndef HAVE_LE16TOH
+#         define le16toh(x) (x)
+#     endif
+#     ifndef HAVE_LE32TOH
+#         define le32toh(x) (x)
+#     endif
+# else
+#     if !defined(HAVE_LE16TOH) || !defined(HAVE_LE32TOH)
+#         include <byteswap.h>
+#     endif
+#     ifndef HAVE_LE16TOH
+#         define le16toh(x) bswap_16(x)
+#     endif
+#     ifndef HAVE_LE32TOH
+#         define le32toh(x) bswap_32(x)
+#     endif
 # endif
 #
 # include "radiotap/radiotap.c"
index 218a7bc..e482f80 100644 (file)
@@ -1,5 +1,5 @@
-import SCons.Environment
-import SCons.Util, SCons.Script
+import SCons.Environment, SCons.Util, SCons.Script, SCons.Conftest
+import re
 
 # Fix for SCons 0.97 compatibility
 import SCons.SConf
@@ -111,7 +111,51 @@ def Fail(context, message, condition=True):
 
 DefaultTest = ConfTest()
 
-# Hmm .. no default tests for now ...
+@DefaultTest
+def CheckSymbolWithExpression(context, symbol, expression, header="", language="C"):
+    lang, suffix, msg = SCons.Conftest._lang2suffix(language)
+    if msg:
+        context.Message("Cannot check for %s: " % symbol)
+        context.Result(msg)
+        return False
+
+    text = ("#include <assert.h>\n"
+            "%s\n"
+            "int main() {\n"
+            "%s;\n"
+            "return 0;\n"
+            "}\n") % (header, expression)
+
+    context.Message("Checking for %s... " % symbol)
+    ret = context.TryLink(text, suffix)
+    context.Result(ret)
+    if ret:
+        key = symbol.upper()
+        key = re.sub('[^A-Z0-9_]', '_', key)
+        context.sconf.Define("HAVE_%s" % key, 1,
+                             "Define to 1 if you have `%s'" % symbol)
+
+    return ret
+
+@DefaultTest
+def CheckByteorder(context):
+    context.Message("Checking byteorder... ")
+    ret = context.TryRun('#include <stdio.h>\n'
+                         'union byteorder_test { int i; char b; };\n'
+                         'int main() {\n'
+                         '    union byteorder_test t; t.i=1;\n'
+                         '    printf(t.b ? "little\\n" : "big\\n");\n'
+                         '    return 0;\n'
+                         '}\n',
+                         ".c")[-1].strip()
+    if not ret:
+        context.Result("failed")
+        return False
+    else:
+        context.Result(ret+"-endian")
+        context.sconf.Define("BYTEORDER_%s_ENDIAN" % ret.upper(), 1,
+                             "Define BYTEORDER_LITTLE_ENDIAN or BYTEORDER_BIG_ENDIAN")
+        return ret
 
 def generate(env):
     env.Append( CUSTOM_TESTS = DefaultTest.tests )