lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #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 | |
| 10 | namespace ares { |
| 11 | |
| 12 | static 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 | |
| 30 | int main(int argc, char* argv[]) { |
| 31 | for (int ii = 1; ii < argc; ++ii) { |
| 32 | ares::ShowFile(argv[ii]); |
| 33 | } |
| 34 | } |
| 35 | |