#include "icmp/icmppacketfactory.h"
+#include <stdlib.h>
+
#include <logfunc.hpp>
+#include <boost/scoped_array.hpp>
#include "boost_assert_handler.h"
#include "icmp/icmpchecksum.h"
#include "icmp/icmpdata.h"
// IcmpPacketFactory
//-----------------------------------------------------------------------------
+bool dump_broken_packets = true;
+
/**
* @brief Creates an ICMP packet from the input stream @c std::istream.
*
return icmp_packet;
}
- IcmpPacket::ReadReturnCode return_code = icmp_packet->read( is );
+ IcmpPacket::ReadReturnCode return_code;
+ is.seekg(0, is.end);
+ int length = is.tellg();
+ is.seekg(0, is.beg);
+ boost::scoped_array<char> all_data( new char[length] );
+ if (dump_broken_packets)
+ {
+ // read all data into a string
+ is.read(all_data.get(), length);
+
+ GlobalLogger.debug() << "Copied " << length
+ << " chars before reading" << endl;
+
+ // create a copy to read from again
+ std::stringbuf strbuf(all_data.get(), std::ios::in);
+ istream is_2(&strbuf);
+ return_code = icmp_packet->read( is_2 );
+ }
+ else
+ return_code = icmp_packet->read( is );
+
if ( return_code != IcmpPacket::ReadReturnCode_OK )
{
GlobalLogger.warning() << "ICMP packet creation failed: "
icmp_packet.reset(); // --> (!icmp_packet) is true
}
+ if (dump_broken_packets && !icmp_packet)
+ {
+ char secure_filename[] = "/datastore/pingcheck.broken/icmp_XXXXXX";
+ int fd = mkstemp(secure_filename);
+ if (fd == -1)
+ GlobalLogger.warning() << "Failed to create temp file!" << endl;
+ else
+ {
+ write(fd, all_data.get(), length);
+ close(fd);
+ GlobalLogger.debug() << "Dumped a copy of the data into "
+ << secure_filename << endl;
+ }
+ }
+
return icmp_packet;
}