4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the
19 // Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // Definition of non-inline non-template functions
24 //#include "MCSniffer.hh"
25 //#include "MCSniffer.ih"
31 #include "Socket/Protocols/INet/UDPSocketHandle.hh"
32 #include "Scheduler/Scheduler.hh"
33 #include "Packets/DefaultBundle/EthernetPacket.hh"
34 #include "Utils/membind.hh"
37 //#include "MCSniffer.mpp"
39 ///////////////////////////////cc.p////////////////////////////////////////
43 static const unsigned BLOCK_SIZE = 16;
45 template <class Iterator>
46 void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream)
50 for (; i != i_end; ++i, ++offset) {
51 switch (offset % BLOCK_SIZE) {
54 stream << " " << ascii << "\n";
58 << std::hex << std::setw(4) << std::setfill('0')
66 stream << ' ' << std::hex << std::setw(2) << std::setfill('0')
68 ascii += (*i >= ' ' && *i < 126) ? *i : '.';
71 for (; (offset % BLOCK_SIZE) != 0; ++offset) {
72 if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2)
76 stream << " " << ascii << "\n";
85 senf::UDPv4ClientSocketHandle sock;
89 MCSniffer(senf::INet4SocketAddress addr, std::ostream& s)
92 sock.protocol().bind(addr);
93 sock.protocol().mcLoop(true);
94 sock.protocol().mcAddMembership(addr);
95 senf::Scheduler::instance().add(
96 sock, senf::membind(&MCSniffer::dumpPacket, this));
100 void dumpPacket(senf::FileHandle /* ignored */, senf::Scheduler::EventId event)
102 std::string data (sock.read());
103 senf::EthernetPacket packet (
104 senf::EthernetPacket::create(data));
106 hexdump(packet.last().data().begin(),
107 packet.last().data().end(),
114 int main(int argc, char const * argv[])
117 std::ofstream f1 ("233.132.152.1.txt");
118 std::ofstream f2 ("233.132.152.2.txt");
121 senf::INet4SocketAddress("233.132.152.1:22344"), f1);
123 senf::INet4SocketAddress("233.132.152.2:22344"), f2);
125 senf::Scheduler::instance().process();
127 catch (std::exception const & ex) {
128 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
134 ///////////////////////////////cc.e////////////////////////////////////////
136 //#include "MCSniffer.mpp"
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u"
146 // comment-column: 40