X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Examples%2FMainpage.dox;h=9557a7126afdeb0d8c96c542b633c418a5a47083;hb=ac86c2bb40746fbedf70a19af3307e5da642b04a;hp=2bd029c62405d0bf4ecce609cbeaa3398d8d2288;hpb=9a988902090d28007578e93bffd809f6bd913155;p=senf.git diff --git a/Examples/Mainpage.dox b/Examples/Mainpage.dox index 2bd029c..9557a71 100644 --- a/Examples/Mainpage.dox +++ b/Examples/Mainpage.dox @@ -1,169 +1,17 @@ /** \mainpage Examples - \anchor Examples_Main - \ref sniffer -*/ - -/** \page sniffer Sniffer: A simple example application - - \dontinclude Sniffer.cc - - The Sniffer application is a simple command line network sniffer like \c tcpdump or \c - tethereal. The application uses a packet socket to read Ethernet packets from the \c eth0 - interface and dumps the parsed packets out to the standard output. - - To try out the example application, check out the library, go to the \c Sniffer - directory and execute - -
- # scons -u - # ./sniffer loop - < Hit Ctrl-C when you've seen enough > - # ./sniffer scheduler - < Hit Ctrl-C when you've seen enough > -- - 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 - - \skip // Custom includes - \until membind - - (The additional includes found in the source but not shown here are part of a short-time fix - which will be removed as soon as possible). The example application now contains a helper - routine to produce a packet hexdump. We will skip this routine here. The example includes two - implementations, one using blocking calls and a while loop, the other using the senf::Scheduler - for asynchronous event notification. They are implemented in \c loop_main() and \c - scheduler_main(). They will be documented below. For now, we skip these implementations and go - straight to the \c main() function - - \skip int main( - \until return 1; - \until } - - This routine simply interprets the first command line argument and dispatches to the required - implementation. - - Now lets go back and study each implementation in detail. - - \dontinclude Sniffer.cc - - \section example_loop A Blocking Implementation - - This implementation is found in the \c loop_main function. - - \skip loop_main - \until try - - We catch all exceptions in a \c try block. This is good for a deliverable binary. When debugging - 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 \c eth0 interface. 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 will now read packets from the socket forever, that is until the user hits Ctrl-C - - \skip while - \until read - - The next step is, to parse the data read from the socket as an Ethernet packet - - \until ; - - 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. - - The next step is to write out the packet to the standard output + \htmlonly +