summaryrefslogtreecommitdiffstats
path: root/src/c-ares/test/dns-dump.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/c-ares/test/dns-dump.cc')
-rw-r--r--src/c-ares/test/dns-dump.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/c-ares/test/dns-dump.cc b/src/c-ares/test/dns-dump.cc
new file mode 100644
index 000000000..023de3697
--- /dev/null
+++ b/src/c-ares/test/dns-dump.cc
@@ -0,0 +1,35 @@
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <vector>
+
+#include "dns-proto.h"
+
+namespace ares {
+
+static void ShowFile(const char* filename) {
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ std::cerr << "Failed to open '" << filename << "'" << std::endl;
+ return;
+ }
+ std::vector<unsigned char> contents;
+ while (true) {
+ unsigned char buffer[1024];
+ int len = read(fd, buffer, sizeof(buffer));
+ if (len <= 0) break;
+ contents.insert(contents.end(), buffer, buffer + len);
+ }
+ std::cout << PacketToString(contents) << std::endl;
+}
+
+} // namespace ares
+
+int main(int argc, char* argv[]) {
+ for (int ii = 1; ii < argc; ++ii) {
+ ares::ShowFile(argv[ii]);
+ }
+}
+