#include "Packets/DefaultBundle/EthernetPacket.hh"
#include "Packets/MPEGDVBBundle/DatagramSection.hh"
#include "Utils/membind.hh"
+#include "Utils/hexdump.hh"
#include "Socket/Protocols/DVB/DVBDemuxHandles.hh"
#include "Packets/ParseInt.hh"
#include "Packets/Packet.hh"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-namespace {
-
- static const unsigned BLOCK_SIZE = 16;
-
- template <class Iterator>
- 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 MySniffer
{
senf::DVBDemuxSectionHandle handle;
senf::DatagramSection section (senf::DatagramSection::create(data));
section.dump(std::cout);
senf::PacketData & datagramData (section.last().data());
- hexdump(datagramData.begin(), datagramData.end(), std::cout);
+ senf::hexdump(datagramData.begin(), datagramData.end(), std::cout);
}
};
#include "Packets/MPEGDVBBundle/TransportPacket.hh"
#include "Packets/MPEGDVBBundle/SNDUPacket.hh"
#include "Utils/membind.hh"
+#include "Utils/hexdump.hh"
#include "Socket/Protocols/DVB/DVBDemuxHandles.hh"
#include "Packets/ParseInt.hh"
#include "Packets/Packet.hh"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-template <class Iterator>
-void ULEdec::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;
-}
-
ULEdec::ULEdec()
{
iterator payload_start = payloadData.begin();
iterator payload_end = payloadData.end();
- hexdump(payload_start, payload_end, std::cout);
+ senf::hexdump(payload_start, payload_end, std::cout);
// Synchronize continuity counter
this->priv_tscc = ts_packet->continuity_counter();
- if (ts_packet->pusi() == 0) {
+ switch (ts_packet->pusi()) {
+ case 0: {
switch (this->receiver_state) {
case Idle:
return;
case Reassembly:
- readContSNDUPacket( payload_start, payload_end );
+ payload_start = readContSNDUPacket( payload_start, payload_end );
+ if (isSDNUPacketComplete()) {
+ handleSNDUPacket();
+ this->receiver_state = Idle;
+ switch (std::distance( payload_start, payload_end ))
+ case 0:
+ case 1:
+ return;
+ default:
+ if ( (*payload_start++ | *payload_start++) != ULE_END_INDICATOR )
+ std::cerr << "delimiting error\n";
+ } else {
+ BOOST_ASSERT( std::distance( payload_start, payload_end ) == 0 );
+ }
}
- } else {
+ break;
+ }
+ case 1: {
// a PUSI value of 1 indicates the presence of a Payload Pointer.
unsigned char payload_pointer = *payload_start++;
if (payload_pointer > 181) {
case Idle:
payload_start += payload_pointer;
readNewSNDUPacket( payload_start, payload_end );
- this->snduPacket.dump(std::cout);
break;
case Reassembly:
// Reassembly Payload Pointer Checking
- unsigned char sdnu_bytes_left = std::distance(
- this->snduPacketData_iter, this->snduPacket.data().end() );
- if (sdnu_bytes_left != payload_pointer) {
+ unsigned char sndu_bytes_left = snduPacketBytesLeft();
+ if (sndu_bytes_left != payload_pointer) {
// delimiting error
std::cerr << "delimiting error\n";
payload_start += payload_pointer;
} else {
readContSNDUPacket( payload_start, payload_end );
- BOOST_ASSERT( this->snduPacketData_iter == this->snduPacket.data().end() );
+ BOOST_ASSERT( isSDNUPacketComplete() );
}
readNewSNDUPacket( payload_start, payload_end );
- }
+ }
}
+ } // end pusi-switch
}
ULEdec::iterator ULEdec::readRawSNDUPacketData(iterator i_start, iterator i_end)
{
unsigned char how_much = std::min(
- std::distance( this->snduPacketData_iter, this->snduPacket.data().end() ),
- std::distance( i_start, i_end ) );
+ snduPacketBytesLeft(), std::distance( i_start, i_end ) );
copy_n(i_start, how_much, this->snduPacketData_iter);
i_start += how_much;
this->snduPacketData_iter += how_much;
}
+void ULEdec::handleSNDUPacket()
+{
+ this->snduPacket.dump(std::cout);
+}
+
+
+inline bool ULEdec::isSDNUPacketComplete()
+{
+ return this->snduPacketData_iter == this->snduPacket.data().end();
+}
+
+inline ULEdec::iterator::difference_type ULEdec::snduPacketBytesLeft()
+{
+ return std::distance( this->snduPacketData_iter, this->snduPacket.data().end() );
+}
+
+
int main(int argc, char const * argv[])
{
try {
bool priv_sndu_type_1;
iterator snduPacketData_iter;
- static const unsigned BLOCK_SIZE = 16;
-
- template <class Iterator>
- void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream);
-
void handleEvent(senf::FileHandle, senf::Scheduler::EventId event);
-
void handleTSPacket(senf::TransportPacket tsPacket);
+ void handleSNDUPacket();
iterator readNewSNDUPacket(iterator i_start, iterator i_end);
iterator readContSNDUPacket(iterator i_start, iterator i_end);
iterator readRawSNDUPacketData(iterator i_start, iterator i_end);
+ inline bool isSDNUPacketComplete();
+ inline iterator::difference_type snduPacketBytesLeft();
+
};
\f
#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 <class Iterator>
- 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;
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";
#include "Socket/Protocols/Raw/PacketSocketHandle.hh"
#include "Scheduler/Scheduler.hh"
#include "Utils/membind.hh"
+#include "Utils/hexdump.hh"
#include "Packets/DefaultBundle/EthernetPacket.hh"
//#include "Sniffer.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-namespace {
-
- static const unsigned BLOCK_SIZE = 16;
-
- template <class Iterator>
- void hexdump(Iterator i, Iterator const & i_end)
- {
- unsigned offset (0);
- std::string ascii;
- for (; i != i_end; ++i, ++offset) {
- switch (offset % BLOCK_SIZE) {
- case 0:
- if (!ascii.empty()) {
- std::cout << " " << ascii << "\n";
- ascii = "";
- }
- std::cout << " "
- << std::hex << std::setw(4) << std::setfill('0')
- << offset << ' ';
- break;
- case BLOCK_SIZE/2:
- std::cout << " ";
- ascii += ' ';
- break;
- }
- std::cout << ' ' << 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)
- std::cout << " ";
- std::cout << " ";
- }
- std::cout << " " << ascii << "\n";
- }
- std::cout << std::dec;
- }
-
-}
-
int loop_main (int argc, char const * argv[])
{
try {
senf::EthernetPacket::noinit));
sock.read(packet.data(),0);
packet.dump(std::cout);
- hexdump(packet.last().data().begin(),
- packet.last().data().end());
+ senf::hexdump(
+ packet.last().data().begin(),
+ packet.last().data().end(),
+ std::cout);
std::cout << "\n\n";
}
}
senf::EthernetPacket::create(senf::EthernetPacket::noinit));
sock.read(packet.data(),0);
packet.dump(std::cout);
- hexdump(packet.last().data().begin(),
- packet.last().data().end());
+ senf::hexdump(
+ packet.last().data().begin(),
+ packet.last().data().end(),
+ std::cout);
std::cout << "\n\n";
}
};
<dt>\ref TypeIdValue</dt><dd>class wrapping a typeid in a way that it can be used like any other
value type, e.g. as the key in a map.</dd>
+
+ <dt>\ref hexdump<dt>
+ <dd>a simple but usefull function to write binary data in in hexadecimal format.</dd>
</dl>
*/
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief hexdump non-inline template implementation */
+
+//#include "hexdump.ih"
+
+// Custom includes
+#include <iomanip>
+
+//#include "hexdump.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+template <class Iterator>
+prefix_ void senf::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream, unsigned block_size=16)
+{
+ unsigned offset (0);
+ std::string ascii;
+ for (; i != i_end; ++i, ++offset) {
+ switch ((offset % block_size)==0) {
+ case true:
+ if (!ascii.empty()) {
+ stream << " " << ascii << "\n";
+ ascii = "";
+ }
+ stream << " "
+ << std::hex << std::setw(4) << std::setfill('0')
+ << offset << ' ';
+ break;
+ case false:
+ 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;
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "hexdump.mpp"
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
+// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief public header for hexdump */
+
+#ifndef HH_hexdump_
+#define HH_hexdump_ 1
+
+// Custom includes
+#include <iostream>
+
+//#include "hexdump.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ /** \brief write the contents from Iterator i to i_end to the output stream in hexadecimal format.
+ */
+ template <class Iterator>
+ void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream, unsigned block_size=16);
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+//#include "hexdump.cci"
+#include "hexdump.ct"
+//#include "hexdump.cti"
+//#include "hexdump.mpp"
+#endif
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End: