module_udp_dns.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. #include <unistd.h>
  12. #include <string.h>
  13. struct dnshdr {
  14. uint16_t id; /* transaction ID */
  15. uint16_t rd:1; /* recursion desired */
  16. uint16_t tc:1; /* truncation */
  17. uint16_t aa:1; /* authoritative answer */
  18. uint16_t opcode:4; /* opcode 0=std query 1=Inverse query 2=srv status request */
  19. uint16_t qr:1; /* query/response */
  20. uint16_t rcode:4; /* response code */
  21. uint16_t cd :1; /* checking disabled */
  22. uint16_t ad :1; /* authenticated data */
  23. uint16_t z:1; /* reserved set to 0 */
  24. uint16_t ra:1; /* recursion available */
  25. uint16_t qdcount; /* # entries in question section */
  26. uint16_t ancount; /* # RR in answer section */
  27. uint16_t nscount; /* # name server RR in authority section */
  28. uint16_t arcount; /* # RR in additional information section */
  29. };
  30. typedef struct __attribute__((packed)) {
  31. uint16_t name;
  32. uint16_t type;
  33. uint16_t addr_class;
  34. uint32_t ttl;
  35. uint16_t length;
  36. uint32_t addr;
  37. } dnsans;
  38. #define DNS_QR_QUERY 0 /* Msg is a dns query */
  39. #define DNS_QR_ANSWER 1 /* Msg is a dns answer */
  40. #define DNS_OPCODE_STDQUERY 0 /* Msg is a standard query */
  41. #define DNS_OPCODE_INVQUERY 1 /* Msg is a inverse query */
  42. #define DNS_OPCODE_SRVSTATUS 2 /* Msg is a server status query */
  43. #define DNS_RCODE_NOERR 0 /* Response code NO ERROR */
  44. #define DNS_RCODE_FORMATERR 1 /* Response code NO ERROR */
  45. #define DNS_RCODE_SRVFAILURE 2 /* Response code NO ERROR */
  46. #define DNS_RCODE_NXDOMAIN 3 /* Response code NO ERROR */
  47. #define DNS_RCODE_QTYPENOTIMPL 4 /* Response code NO ERROR */
  48. #define DNS_RCODE_QRYREFUSED 5 /* Response code NO ERROR */
  49. void udp_dns_print_packet(FILE *fp, void* packet);
  50. int udp_dns_make_packet(void *buf, ipaddr_n_t src_ip, ipaddr_n_t dst_ip,
  51. uint32_t *validation, int probe_num, void *arg);
  52. int udp_dns_validate_packet(const struct ip *ip_hdr, uint32_t len,
  53. __attribute__((unused))uint32_t *src_ip, uint32_t *validation);
  54. extern const char *udp_unreach_strings[];