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

dns.h 2.0KB

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