{
try {
senf::PacketSocketHandle sock;
- sock.bind(senf::LLSocketAddress("eth1"));
+ sock.bind(senf::LLSocketAddress(argv[2]));
// sock.protocol().promisc("eth0",senf::PacketProtocol::Promiscuous);
while (true) { // forever
int scheduler_main(int argc, char const * argv[])
{
try {
- Sniffer sniffer ("eth1");
+ Sniffer sniffer (argv[2]);
sniffer.run();
}
catch (std::exception const & ex) {
int main(int argc, char const * argv[])
{
- if (argc >= 2)
+ if (argc >= 3)
if (std::string(argv[1]) == "loop")
return loop_main(argc,argv);
else if (std::string(argv[1]) == "scheduler")
return scheduler_main(argc,argv);
- std::cerr << "Usage: sniffer { loop | scheduler }" << std::endl;
+ std::cerr << "Usage: sniffer { loop | scheduler } [interface]" << std::endl;
return 1;
}
prefix_ void senf::IpV4PacketType::dump(packet p, std::ostream & os)
{
- struct in_addr in;
- in.s_addr = htonl(p->source());
- char buffer[128];
- std::string src (inet_ntop(AF_INET,&in,buffer,128));
- in.s_addr = htonl(p->destination());
- std::string dst (inet_ntop(AF_INET,&in,buffer,128));
os << "Internet protocol Version 4:\n"
<< " version : " << p->version() << "\n"
<< " IHL : " << p->ihl() << "\n"
<< " TTL : " << unsigned(p->ttl()) << "\n"
<< " protocol : " << unsigned(p->protocol()) << "\n"
<< " CRC : " << std::hex << p->crc() << std::dec << "\n"
- << " source : " << src << "\n"
- << " destination : " << dst << "\n";
+ << " source : " << p->source() << "\n"
+ << " destination : " << p->destination() << "\n";
}
///////////////////////////////cc.e////////////////////////////////////////
#define HH_IpV4Packet_ 1
// Custom includes
+#include "Socket/Protocols/INet/INet4Address.hh"
#include "Packets/Packets.hh"
//#include "IpV4Packet.mpp"
namespace senf {
+ /** \brief Parse in IpV4 address
+
+ \see INet4Address
+ */
+ struct Parse_INet4Address : public PacketParserBase
+ {
+ Parse_INet4Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ typedef INet4Address value_type;
+ static const size_type fixed_bytes = 4u;
+
+ value_type value() const { return value_type::from_data(i()); }
+ void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
+ operator value_type() { return value(); }
+ byte & operator[](size_type index) { return *boost::next(i(),index); }
+ Parse_INet4Address const & operator= (value_type const & other)
+ { value(other); return *this; }
+ };
+
/** \brief Parse an IpV4 packet
Parser implementing the IpV4 header. The fields implemented are:
typedef Parse_Flag < 2 > Parse_MF;
typedef Parse_UIntField < 3, 16 > Parse_Frag;
typedef Parse_UInt32 Parse_32bit;
+ typedef Parse_INet4Address Parse_Addr;
# ifndef DOXYGEN
((Field )( ttl, Parse_8bit ))
((Field )( protocol, Parse_8bit ))
((Field )( crc, Parse_16bit ))
- ((Field )( source, Parse_32bit ))
- ((Field )( destination, Parse_32bit )) );
+ ((Field )( source, Parse_Addr ))
+ ((Field )( destination, Parse_Addr )) );
# else
Parse_8bit ttl() const;
Parse_8bit protocol() const;
Parse_16bit crc() const;
- Parse_32bit source() const;
- Parse_32bit destination() const;
+ Parse_Addr source() const;
+ Parse_Addr destination() const;
# endif
BOOST_CHECK_EQUAL( p->ttl(), 0x09u );
BOOST_CHECK_EQUAL( p->protocol(), 0x0Au );
BOOST_CHECK_EQUAL( p->crc(), 0x0B0Cu );
- BOOST_CHECK_EQUAL( p->source(), 0x11121314u );
- BOOST_CHECK_EQUAL( p->destination(), 0x15161718u );
+ BOOST_CHECK_EQUAL( p->source().value(), senf::INet4Address(0x11121314u) );
+ BOOST_CHECK_EQUAL( p->destination().value(), senf::INet4Address(0x15161718u) );
}
///////////////////////////////cc.e////////////////////////////////////////
BOOST_CHECK_EQUAL( p->version(), 6u );
BOOST_CHECK_EQUAL( p->length(), 20u );
BOOST_CHECK_EQUAL( p->nextHeader(), 44u );
- BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->source().i()),
- senf::INet6Address::from_string("2001::1") );
- BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->destination().i()),
- senf::INet6Address::from_string("2001::2") );
+ BOOST_CHECK_EQUAL( p->source().value(), senf::INet6Address::from_string("2001::1") );
+ BOOST_CHECK_EQUAL( p->destination().value(), senf::INet6Address::from_string("2001::2") );
BOOST_CHECK( p.next().is<senf::IpV6Extension_Fragment>() );
senf::IpV6Extension_Fragment f (p.next().as<senf::IpV6Extension_Fragment>());
//#include "IpV6Packet.ih"
// Custom includes
+#include <boost/io/ios_state.hpp>
#include "EthernetPacket.hh"
#include "Socket/Protocols/INet/INetAddressing.hh"
prefix_ void senf::IpV6PacketType::dump(packet p, std::ostream & os)
{
+ boost::io::ios_all_saver ias(os);
os << "Internet protocol Version 6:\n"
<< " version : " << unsigned(p->version()) << "\n"
<< " traffic class : " << std::hex << unsigned(p->trafficClass()) << "\n"
<< " length : " << std::dec << unsigned(p->length()) << "\n"
<< " next header : " << unsigned(p->nextHeader()) << "\n"
<< " hop limit : " << unsigned(p->hopLimit()) << "\n"
- << " source : " << INet6Address::from_data(p->source().i()) << "\n"
- << " destination : " << INet6Address::from_data(p->destination().i()) << "\n";
+ << " source : " << p->source() << "\n"
+ << " destination : " << p->destination() << "\n";
}
///////////////////////////////cc.e////////////////////////////////////////
#define HH_IpV6Packet_ 1
// Custom includes
+#include "Socket/Protocols/INet/INet6Address.hh"
#include "Packets/Packets.hh"
#include "IpV4Packet.hh"
namespace senf {
- /** \brief Parse an IpV6 packet
+ /** \brief Parse an IpV6 address
+
+ \see INet6Address
+ */
+ struct Parse_INet6Address : public PacketParserBase
+ {
+ Parse_INet6Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+ ///////////////////////////////////////////////////////////////////////////
- Parser implementing the IpV6 header. The fields implemented are:
+ typedef INet6Address value_type;
+ static const size_type fixed_bytes = 16u;
+
+ value_type value() const { return value_type::from_data(i()); }
+ void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
+ operator value_type() { return value(); }
+ byte & operator[](size_type index) { return *boost::next(i(),index); }
+ Parse_INet6Address const & operator= (value_type const & other)
+ { value(other); return *this; }
+ };
+
+ /** \brief Parse an IpV6 packet
\see IpV6PacketType \n
<a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
typedef Parse_UIntField < 12, 32 > Parse_FlowLabel;
typedef Parse_UInt8 Parse_8bit;
typedef Parse_UInt16 Parse_16bit;
-
- typedef Parse_Array < 16, Parse_8bit > Parse_Addr;
+ typedef Parse_INet6Address Parse_Addr;
# ifndef DOXYGEN
BOOST_CHECK_EQUAL( p->length(), 0x0102u );
BOOST_CHECK_EQUAL( p->nextHeader(), 0x03u );
BOOST_CHECK_EQUAL( p->hopLimit(), 0x04u );
- BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->source().i()),
+ BOOST_CHECK_EQUAL( p->source().value(),
senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f") );
- BOOST_CHECK_EQUAL( senf::INet6Address::from_data(p->destination().i()),
+ BOOST_CHECK_EQUAL( p->destination().value(),
senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f") );
BOOST_CHECK( p.next() );