1 #include <boost/asio.hpp> 2 #include <boost/program_options.hpp> 5 #include <net/ethernet.h> 6 #include <netinet/ip.h> 7 #include <netinet/udp.h> 11 namespace po = boost::program_options;
25 if(errocode != boost::asio::error::operation_aborted && errocode)
27 std::cout <<
"Unexpected timer error : " << errocode.message();
30 char errbuf[PCAP_ERRBUF_SIZE];
36 std::cout <<
"pcap_open() failed: " << errbuf << std::endl;
41 struct pcap_pkthdr*
header;
42 const u_char* pkt_data;
60 boost::system::error_code ec;
61 const u_char* startOfData = pkt_data +
sizeof(
struct ether_header) +
62 sizeof(struct ip) + sizeof(struct udphdr);
63 size_t dataLength = header->len - (
sizeof(
struct ether_header) + sizeof(struct ip) +
64 sizeof(struct udphdr));
65 if(*startOfData !=
'I' && *(startOfData + 1) !=
'X')
67 std::cout <<
"Can't send this packet, its not STDBin packet" << std::endl;
74 std::cout <<
"Problem when sending data on UDP " << ec.message() << std::endl;
78 timer.expires_from_now(boost::posix_time::milliseconds(
period_ms));
82 int main(
int argc,
char* argv[])
84 po::options_description desc(
"Allowed options");
87 (
"help",
"produce help message")
88 (
"period", po::value<long>()->default_value(10),
"Publication period in ms.")
89 (
"repeat",
"Will repeat the file infinitely")
90 (
"ip", po::value<std::string>()->
default_value(std::string(
"127.0.0.1")),
"Interface on which UDP Frames will be sent")
91 (
"port", po::value<uint16_t>()->
default_value(8200),
"Port on which UDP Frames will be sent")
92 (
"file", po::value<std::string>(),
"File to replay")
97 po::store(po::parse_command_line(argc, argv, desc), vm);
102 std::cout << desc <<
"\n";
106 if(vm.count(
"file") == 0)
108 std::cout << desc <<
"\nFile parameter is REQUIRED\n";
111 pcapFile = vm[
"file"].as<std::string>();
115 endPoint = ip::udp::endpoint(ip::address::from_string(vm[
"ip"].as<std::string>()),
116 vm[
"port"].as<uint16_t>());
118 socket_base::reuse_address option(
true);
121 timer.expires_from_now(boost::posix_time::milliseconds(
period_ms));
void processNextDataInPcapFile(const boost::system::error_code &errocode)
int main(int argc, char *argv[])
std_msgs::Header * header(M &m)
ip::udp::endpoint endPoint
ip::udp::socket UDPSocket(service)
deadline_timer timer(service)