dns_handle_packet_file.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <stddef.h>
  6. #include <string.h>
  7. #include <fcntl.h>
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include "dns.h"
  13. #include "cache.c"
  14. #include "interface.h"
  15. int cfg_proto = 0;
  16. int cfg_no_subnet = 0;
  17. static void fuzz_dns_handle_packet(uint8_t *input, size_t size)
  18. {
  19. struct sockaddr from;
  20. struct interface iface;
  21. struct cache_service *s, *t;
  22. memset(&from, 0, sizeof(from));
  23. memset(&iface, 0, sizeof(iface));
  24. cache_init();
  25. dns_handle_packet(&iface, &from, 1922, input, size);
  26. avl_for_each_element_safe(&services, s, avl, t)
  27. cache_service_free(s);
  28. }
  29. int main(int argc, char *argv[])
  30. {
  31. size_t len = 0;
  32. FILE *fd = NULL;
  33. uint8_t *buf = NULL;
  34. if (argc != 2) {
  35. fprintf(stderr, "Usage: %s <packet.bin>\n", argv[0]);
  36. return -1;
  37. }
  38. fd = fopen(argv[1], "r");
  39. if (!fd) {
  40. perror("unable to open input file\n");
  41. return -1;
  42. }
  43. buf = calloc(1, MDNS_BUF_LEN+1);
  44. if (!buf)
  45. return -1;
  46. len = fread(buf, 1, MDNS_BUF_LEN, fd);
  47. fuzz_dns_handle_packet(buf, len);
  48. fclose(fd);
  49. free(buf);
  50. }