]> granicus.if.org Git - pdns/commitdiff
dnsreplay: Add `--source-ip` and `--source-port` options
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 9 Mar 2017 14:59:44 +0000 (15:59 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 9 Mar 2017 14:59:44 +0000 (15:59 +0100)
pdns/dnsreplay.cc

index f6b27d26937432b5c0ee77f3d3f30f91123482e3..4e6874ecb4393156dda88aa44c376f9311600f9e 100644 (file)
@@ -709,7 +709,9 @@ try
     ("speedup", po::value<float>()->default_value(1), "replay at this speedup")
     ("timeout-msec", po::value<uint32_t>()->default_value(500), "wait at least this many milliseconds for a reply")
     ("ecs-stamp", "Add original IP address to ECS in replay")
-    ("ecs-mask", po::value<uint16_t>(), "Replace first octet of src IP address with this value in ECS");
+    ("ecs-mask", po::value<uint16_t>(), "Replace first octet of src IP address with this value in ECS")
+    ("source-ip", po::value<string>()->default_value(""), "IP to send the replayed packet from")
+    ("source-port", po::value<uint16_t>()->default_value(0), "Port to send the replayed packet from");
 
   po::options_description alloptions;
   po::options_description hidden("hidden options");
@@ -759,6 +761,10 @@ try
   s_socket= new Socket(AF_INET, SOCK_DGRAM);
 
   s_socket->setNonBlocking();
+
+  if(g_vm.count("source-ip") && !g_vm["source-ip"].as<string>().empty())
+    s_socket->bind(ComboAddress(g_vm["source-ip"].as<string>(), g_vm["source-port"].as<uint16_t>()));
+
   setSocketReceiveBuffer(s_socket->getHandle(), 2000000);
   setSocketSendBuffer(s_socket->getHandle(), 2000000);