blob: 023de36973c12d8916ed4ccabf55cdaa5a6b0cc9 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <sys/types.h>
2#include <fcntl.h>
3#include <unistd.h>
4
5#include <iostream>
6#include <vector>
7
8#include "dns-proto.h"
9
10namespace ares {
11
12static void ShowFile(const char* filename) {
13 int fd = open(filename, O_RDONLY);
14 if (fd < 0) {
15 std::cerr << "Failed to open '" << filename << "'" << std::endl;
16 return;
17 }
18 std::vector<unsigned char> contents;
19 while (true) {
20 unsigned char buffer[1024];
21 int len = read(fd, buffer, sizeof(buffer));
22 if (len <= 0) break;
23 contents.insert(contents.end(), buffer, buffer + len);
24 }
25 std::cout << PacketToString(contents) << std::endl;
26}
27
28} // namespace ares
29
30int main(int argc, char* argv[]) {
31 for (int ii = 1; ii < argc; ++ii) {
32 ares::ShowFile(argv[ii]);
33 }
34}
35