X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Examples%2FMCSniffer%2FMCSniffer.cc;h=fd288d2edf7ac3fcac7a5f4875c8bde56fd8a420;hb=9cd0c7d8fc22ecf342c5d2a45980c245b827a67f;hp=8976c3d64580e97f4bb0b042145104bab8730184;hpb=fb08e3defcfb7cd8851ede0fab6cad424d168485;p=senf.git diff --git a/Examples/MCSniffer/MCSniffer.cc b/Examples/MCSniffer/MCSniffer.cc index 8976c3d..fd288d2 100644 --- a/Examples/MCSniffer/MCSniffer.cc +++ b/Examples/MCSniffer/MCSniffer.cc @@ -32,54 +32,13 @@ #include "Scheduler/Scheduler.hh" #include "Packets/DefaultBundle/EthernetPacket.hh" #include "Utils/membind.hh" +#include "Utils/hexdump.hh" //#include "MCSniffer.mpp" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -namespace { - - static const unsigned BLOCK_SIZE = 16; - - template - void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream) - { - unsigned offset (0); - std::string ascii; - for (; i != i_end; ++i, ++offset) { - switch (offset % BLOCK_SIZE) { - case 0: - if (!ascii.empty()) { - stream << " " << ascii << "\n"; - ascii = ""; - } - stream << " " - << std::hex << std::setw(4) << std::setfill('0') - << offset << ' '; - break; - case BLOCK_SIZE/2: - stream << " "; - ascii += ' '; - break; - } - stream << ' ' << std::hex << std::setw(2) << std::setfill('0') - << unsigned(*i); - ascii += (*i >= ' ' && *i < 126) ? *i : '.'; - } - if (!ascii.empty()) { - for (; (offset % BLOCK_SIZE) != 0; ++offset) { - if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2) - stream << " "; - stream << " "; - } - stream << " " << ascii << "\n"; - } - stream << std::dec; - } -} - - class MCSniffer { senf::UDPv4ClientSocketHandle sock; @@ -103,7 +62,7 @@ private: senf::EthernetPacket packet ( senf::EthernetPacket::create(data)); packet.dump(stream); - hexdump(packet.last().data().begin(), + senf::hexdump(packet.last().data().begin(), packet.last().data().end(), stream); stream << "\n\n";