Update Examples/Sniffer documentation
g0dil [Thu, 4 Nov 2010 20:46:01 +0000 (20:46 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1743 270642c3-0616-0410-b53a-bc976706d245

.project.el
Examples/Sniffer/Mainpage.dox
site_scons/SENFSCons.py
tools/senf.dict

index 307ad27..409eadb 100644 (file)
@@ -8,7 +8,7 @@
              (not (looking-at ".*}")))
         [0] '+)))
 
- (defconst senf-c-style
+(defconst senf-c-style
   '((c-basic-offset              . 4)
     (c-backslash-column          . 98)
     (c-cleanup-list              . (empty-defun-braces
 
 (c-add-style "senf" senf-c-style)
 
-(set (make-local-variable 'ccide-file-vars)
-     '((fill-column  . 100)
-       (comment-column . 40)
-       (c-file-style . "senf")
-       (indent-tabs-mode . nil)
-       (ispell-local-dictionary . "american")
-       (compile-command . "scons -u test")))
-
-(set (make-local-variable 'ccide-default-copyright)
-     (concat "//\n"
-             "// This program is free software; you can redistribute it and/or modify\n"
-             "// it under the terms of the GNU General Public License as published by\n"
-             "// the Free Software Foundation; either version 2 of the License, or\n"
-             "// (at your option) any later version.\n"
-             "//\n"
-             "// This program is distributed in the hope that it will be useful,\n"
-             "// but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-             "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-             "// GNU General Public License for more details.\n"
-             "//\n"
-             "// You should have received a copy of the GNU General Public License\n"
-             "// along with this program; if not, write to the\n"
-             "// Free Software Foundation, Inc.,\n"
-             "// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"))
-
-(set (make-local-variable 'ccide-project-name) "SENF")
-
-(let ((local-conf (ccide-project-search-upwards "project-local.el")))
-  (if local-conf
-      (load-file local-conf)))
-
 (defun flyspell-cc-progmode-verify ()
   "Replacement for standard flyspell-generic-progmode-verify which
 checks for C/C++ preproc directives. Additionally, anything after ^L
@@ -82,13 +51,7 @@ is ignored (Those are the file local variables and local words)."
   "Torn on `flyspell-mode` for comments and strings in C/C++ mode."
   (interactive)
   (setq flyspell-generic-check-word-p 'flyspell-cc-progmode-verify)
-  (flyspell-mode 1))
-
-;; Better set this here than in the file variables since the setting
-;; is only valid if project.el is loaded ...
-(set (make-local-variable 'ispell-personal-dictionary)
-     (expand-file-name "tools/senf.dict" ccide-project-root))
-(flyspell-cc-mode)
+  (flyspell-mode t))
 
 (defun senf-new-file-hook ()
   (when (string-match "\\.test\\.cc$" (buffer-file-name))
@@ -99,10 +62,51 @@ is ignored (Those are the file local variables and local words)."
       (delete-region (point) (progn (end-of-line) (point)))
       (insert "#include <senf/Utils/auto_unit_test.hh>"))))
 
-(add-hook 'ccide-new-file-hooks 'senf-new-file-hook nil t)
+(defun senf-ccide-init ()
+  (interactive)
+  (set (make-local-variable 'ccide-file-vars)
+       '((fill-column  . 100)
+         (comment-column . 40)
+         (c-file-style . "senf")
+         (indent-tabs-mode . nil)
+         (ispell-local-dictionary . "american")
+         (compile-command . "scons -u test")))
+
+  (set (make-local-variable 'ccide-default-copyright)
+       (concat "//\n"
+               "// This program is free software; you can redistribute it and/or modify\n"
+               "// it under the terms of the GNU General Public License as published by\n"
+               "// the Free Software Foundation; either version 2 of the License, or\n"
+               "// (at your option) any later version.\n"
+               "//\n"
+               "// This program is distributed in the hope that it will be useful,\n"
+               "// but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+               "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+               "// GNU General Public License for more details.\n"
+               "//\n"
+               "// You should have received a copy of the GNU General Public License\n"
+               "// along with this program; if not, write to the\n"
+               "// Free Software Foundation, Inc.,\n"
+               "// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"))
+
+  (set (make-local-variable 'ccide-project-name) "SENF")
+
+  (let ((local-conf (ccide-project-search-upwards "project-local.el")))
+    (if local-conf
+        (load-file local-conf)))
+
+  ;; Better set this here than in the file variables since the setting
+  ;; is only valid if project.el is loaded ...
+  (set (make-local-variable 'ispell-personal-dictionary)
+       (expand-file-name "tools/senf.dict" ccide-project-root))
+  (flyspell-cc-mode)
+
+  (add-hook 'ccide-new-file-hooks 'senf-new-file-hook nil t)
+
+  (setq indent-tabs-mode nil) ;; needed since whitespace-mode caches this value ...
+  (whitespace-mode 1))
 
-(setq indent-tabs-mode nil) ;; needed since whitespace-mode caches this value ...
-(whitespace-mode 1)
+(senf-ccide-init)
 
 \f
 ;; Local Variables:
index 3f88daf..349087d 100644 (file)
@@ -39,8 +39,8 @@
     < Hit Ctrl-C when you've seen enough >
     </pre>
 
-    We will now look at the code which is found in \c Sniffer.cc in the \c %Sniffer directory. The
-    code starts out by including the necessary headers
+    We will now look at the code which is found in \c Sniffer.cc in the <tt>Examples/%Sniffer</tt>
+    directory. The code starts out by including the necessary headers
 
     \skip // Custom includes
     \until #include <senf/Scheduler/Scheduler.hh>
     the application, it might be better to let the exception \c abort the execution so you can get a
     backtrace of the exception origin in the debugger.
 
-    We now create a packet socket and bind it to the interface given as second command line argument.
-    A packet socket is a linux specific type of socket which returns ethernet packets directly from
-    the network wire. By uncommenting the last line, you may switch the interface into promiscuous mode.
+    We create a packet socket and bind it to the interface given as second command line argument.  A
+    packet socket is a linux specific type of socket which returns ethernet packets directly from
+    the network wire. By uncommenting the last line, you may switch the interface into promiscuous
+    mode.
 
     \until //
 
 
     \until sock.read
 
-    \doc the following section is obsolete!
+    There are several ways to read and parse a packet with different tradeoffs between efficiency
+    and simplicity. The Version we use here is already quite efficient.
 
-    Lets digest this line step by step: We declare a variable named \c packet as a smart pointer to
-    an \c EthernetPacket instance. \c ptr is a typedef member of all Packet classes for the
-    corresponding smart pointer type. We then initialize this pointer with a call to the static \c
-    create member of the \c Packet class. This member takes the type of Packet to parse as a
-    template argument. We pass \c EthernetPacket here. The function takes an iterator range as an
-    argument, and we pass it the complete packet just read by giving the range \c begin() to \c
-    end() of our just read \c data string.
+    We begin by pre-declaring an uninitialized senf::EthernetPacket instance. By uninitialized we
+    mean, that the instance is not parseable and has a length of 0 bytes. This differs from a
+    default-constructed packet instance which may have initial content and \e is parseable.
+
+    We then tell the socket to read as much data as is available into the packet. The second arg to
+    read specifies the maximum number of bytes to read or 0 to read as much as possible. We pass
+    <tt>packet.data()</tt> to <tt>socket.read</tt> which is an STL compatible container holding the
+    data bytes of our previously created senf::EthernetPacket instance (which is currently empty).
 
     The next step is to write out the packet to the standard output
 
 
     The \c prettyName function from the \c Utils library is used, to get a nice, printable
     representation of the \e dynamic type of the exception instance. It is an interface to the g++
-    demangler. This is necessary since the \c name member of the C++ \c type_info instance is a
+    de-mangler. This is necessary since the \c name member of the C++ \c type_info instance is a
     mangled name in \c g++.
 
     That's it for the simple blocking implementation.
 
     \section example_scheduler Using the Scheduler
 
-    However, we have another one which uses the Scheduler. We do this as it will be most of the
-    time: We define a class which manages reading the packets and dumping them out.
+    However, we have another one which uses the Scheduler.
 
     \until }
 
     The class constructor binds the socket defined as a data member to the correct interface. To
     tell the scheduler to call us back whenever data is available on the socket, we add a
-    senf::scheduler::FdEvent isntance to out class.
+    senf::scheduler::FdEvent instance to out class.
 
     The senf::scheduler::FdEvent constructor takes several arguments:
     \li a string describing the event.
     \li the callback to call whenever the event occurs.  The callback is specified as a <a
         href="http://www.boost.org/doc/libs/release/doc/html/function.html">Boost.Function</a>
         object. We use the \c senf::membind helper from the Utils library to build such a
-        function object. This helper takes an arbitrary class member and binds it to a specific 
+        function object. This helper takes an arbitrary class member and binds it to a specific
         instance.
     \li the handle or file descriptor to monitor.
     \li and the events to watch for.
 
     The public \c run() member is called to run the sniffer.  Here we just forward the call to the
     scheduler. Calling the Schedulers \c process() method will start the event loop. This call does
-    not return (ok, it does return in special cases if \c senf::scheduler::terminate() is called
+    not return (ok, that's a lie. It does return when \c senf::scheduler::terminate() is called
     which does not apply here).
 
     \until {
     implementation. However, the scheduler guarantees, that a read on the socket will not block if
     the socket is triggered to be readable (even if the socket is not set to non-blocking mode).
 
-    We now only need to provide the \c scheduler_main() function to run this code
+    What's left is the \c scheduler_main() function to utilize this code
 
     \until 0;
     \until }
 
-    This function is straight forward. The exception handling is the same as in \c loop_main(). The
-    code then just creates a \c Sniffer instance and calls it's \c run() member.
+    This function is straight forward. The exception handling is the same as in \c loop_main().
 
     \see \ref senf_components \n
          \ref senf_build \n
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
 // compile-command: "scons -u doc"
-// mode: flyspell
 // mode: auto-fill
 // End:
index e64e844..e132151 100644 (file)
@@ -150,7 +150,6 @@ def AutoRules(env, exclude=[], subdirs=[], doc_extra_sources = []):
     sources, tests, includes = SENFSCons.Glob(env, exclude=((exclude)), subdirs=((subdirs)) )
     subscripts               = sorted(env.Glob("*/SConscript", strings=True))
     doxyfile                 = env.Glob("Doxyfile")
-    objects                  = []
 
     if sources               : env.Append(ALLOBJECTS = env.Object(sources))
     if tests                 : env.BoostUnitTest('test', tests)
@@ -166,10 +165,10 @@ def AutoPacketBundle(env, name, exclude=[], subdirs=[], doc_extra_sources=[]):
     subscripts               = sorted(env.Glob("*/SConscript", strings=True))
     doxyfile                 = env.Glob("Doxyfile")
 
-    objects = env.Object(sources)
-    cobject = env.CombinedObject('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
-    sobundle = env.SharedLibrary('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', sources, NAME=((name)),
-                                 LIBS=[], SHLIBPREFIX='')
+    objects  = env.Object         (sources)
+    cobject  = env.CombinedObject ('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', objects, NAME=((name)))
+    sobundle = env.SharedLibrary  ('${LOCALLIBDIR}/${NAME}${OBJADDSUFFIX}', sources, NAME=((name)),
+                                   LIBS=[], SHLIBPREFIX='')
 
     env.Default(cobject)
     env.Default(sobundle)
index db608dc..e2373b4 100644 (file)
@@ -101,6 +101,7 @@ cref
 CRON
 ct
 cti
+Ctrl
 CXXFLAGS
 daemonization
 datagram
@@ -137,6 +138,7 @@ DSMCCSection
 dt
 DTCP
 DTCPHelloPacket
+dumpPacket
 dumpPacketInfo
 DVB
 ElementParser
@@ -194,6 +196,7 @@ failbit
 fbipList
 FBIPList
 fbips
+FdEvent
 FFFF
 FileBody
 filebody
@@ -240,6 +243,7 @@ HardwareWLANInterface
 headport
 Helvetica
 hexadecimal
+hexdump
 hh
 hideinitializer
 Hmm
@@ -454,6 +458,7 @@ PacketTypeMixin
 PacketTypeNotRegistered
 param
 parameterIndex
+parseable
 ParseArray
 parsecollection
 ParseCommandInfo
@@ -490,6 +495,7 @@ POSIX
 powerIndexValue
 ppi
 pre
+prettyName
 prev
 PriorityJoin
 protocolbundle
@@ -641,9 +647,11 @@ SyslogTarget
 SystemException
 TapSocketHandle
 TargetInterface
+tcpdump
 td
 telnet
 templated
+tethereal
 thorsten
 ThresholdQueueing
 ThrottleBarrier