4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Definition of non-inline non-template functions
25 //#include "Sniffer.hh"
26 //#include "Sniffer.ih"
32 #include "Socket/PacketSocketHandle.hh"
33 #include "Packets/EthernetPacket.hh"
34 #include "Packets/IpV4Packet.hh"
35 #include "Packets/UDPPacket.hh"
37 //#include "Sniffer.mpp"
39 ///////////////////////////////cc.p////////////////////////////////////////
43 static const unsigned BLOCK_SIZE = 16;
45 template <class Iterator>
46 void hexdump(Iterator i, Iterator const & i_end)
50 for (; i != i_end; ++i, ++offset) {
51 switch (offset % BLOCK_SIZE) {
54 std::cout << " " << ascii << "\n";
58 << std::hex << std::setw(4) << std::setfill('0')
66 std::cout << ' ' << 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 std::cout << " " << ascii << "\n";
78 std::cout << std::dec;
83 // Pull in symbols from the wanted packets ...
84 senf::Packet::create<senf::IpV4Packet>(0,0);
85 senf::Packet::create<senf::UDPPacket>(0,0);
89 int main (int argc, char const * argv[])
92 senf::PacketSocketHandle sock;
93 sock.bind(senf::LLSocketAddress("eth0"));
94 // sock.protocol().promisc("eth0",senf::PacketProtocol::Promiscuous);
96 while (true) { // forever
97 std::string data (sock.read());
98 senf::EthernetPacket::ptr packet (
99 senf::Packet::create<senf::EthernetPacket>(
100 data.begin(), data.end()));
101 packet->dump(std::cout);
102 hexdump(packet->last()->begin(),
103 packet->last()->end());
107 catch (std::exception const & ex) {
108 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
112 ///////////////////////////////cc.e////////////////////////////////////////
114 //#include "Sniffer.mpp"
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"