選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

dns.h 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _GPXE_DNS_H
  2. #define _GPXE_DNS_H
  3. /** @file
  4. *
  5. * DNS protocol
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/in.h>
  10. /*
  11. * Constants
  12. *
  13. */
  14. #define DNS_TYPE_A 1
  15. #define DNS_TYPE_CNAME 5
  16. #define DNS_TYPE_ANY 255
  17. #define DNS_CLASS_IN 1
  18. #define DNS_CLASS_CS 2
  19. #define DNS_CLASS_CH 3
  20. #define DNS_CLASS_HS 4
  21. #define DNS_FLAG_QUERY ( 0x00 << 15 )
  22. #define DNS_FLAG_RESPONSE ( 0x01 << 15 )
  23. #define DNS_FLAG_QR(flags) ( (flags) & ( 0x01 << 15 ) )
  24. #define DNS_FLAG_OPCODE_QUERY ( 0x00 << 11 )
  25. #define DNS_FLAG_OPCODE_IQUERY ( 0x01 << 11 )
  26. #define DNS_FLAG_OPCODE_STATUS ( 0x02 << 11 )
  27. #define DNS_FLAG_OPCODE(flags) ( (flags) & ( 0x0f << 11 ) )
  28. #define DNS_FLAG_RD ( 0x01 << 8 )
  29. #define DNS_FLAG_RA ( 0x01 << 7 )
  30. #define DNS_FLAG_RCODE_OK ( 0x00 << 0 )
  31. #define DNS_FLAG_RCODE_NX ( 0x03 << 0 )
  32. #define DNS_FLAG_RCODE(flags) ( (flags) & ( 0x0f << 0 ) )
  33. #define DNS_PORT 53
  34. #define DNS_MAX_RETRIES 3
  35. #define DNS_MAX_CNAME_RECURSION 0x30
  36. /*
  37. * DNS protocol structures
  38. *
  39. */
  40. struct dns_header {
  41. uint16_t id;
  42. uint16_t flags;
  43. uint16_t qdcount;
  44. uint16_t ancount;
  45. uint16_t nscount;
  46. uint16_t arcount;
  47. } __attribute__ (( packed ));
  48. struct dns_query_info {
  49. uint16_t qtype;
  50. uint16_t qclass;
  51. } __attribute__ (( packed ));
  52. struct dns_query {
  53. struct dns_header dns;
  54. char payload[ 256 + sizeof ( struct dns_query_info ) ];
  55. } __attribute__ (( packed ));
  56. struct dns_rr_info_common {
  57. uint16_t type;
  58. uint16_t class;
  59. uint32_t ttl;
  60. uint16_t rdlength;
  61. } __attribute__ (( packed ));
  62. struct dns_rr_info_a {
  63. struct dns_rr_info_common common;
  64. struct in_addr in_addr;
  65. } __attribute__ (( packed ));
  66. struct dns_rr_info_cname {
  67. struct dns_rr_info_common common;
  68. char cname[0];
  69. } __attribute__ (( packed ));
  70. union dns_rr_info {
  71. struct dns_rr_info_common common;
  72. struct dns_rr_info_a a;
  73. struct dns_rr_info_cname cname;
  74. };
  75. #endif /* _GPXE_DNS_H */