dns.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License version 2.1
  6. * as published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _DNS_H__
  14. #define _DNS_H__
  15. #include <stdint.h>
  16. #define FLAG_RESPONSE 0x8000
  17. #define FLAG_AUTHORATIVE 0x0400
  18. #define TYPE_A 0x0001
  19. #define TYPE_PTR 0x000C
  20. #define TYPE_TXT 0x0010
  21. #define TYPE_AAAA 0x001c
  22. #define TYPE_SRV 0x0021
  23. #define TYPE_ANY 0x00ff
  24. #define IS_COMPRESSED(x) ((x & 0xc0) == 0xc0)
  25. #define MCAST_ADDR "224.0.0.251"
  26. #define MCAST_PORT 5353
  27. #define CLASS_FLUSH 0x8000
  28. #define CLASS_IN 0x0001
  29. #define MAX_NAME_LEN 8096
  30. #define MAX_DATA_LEN 8096
  31. #define C_DNS_SD "_services._dns-sd._udp.local"
  32. struct dns_header {
  33. uint16_t id;
  34. uint16_t flags;
  35. uint16_t questions;
  36. uint16_t answers;
  37. uint16_t authority;
  38. uint16_t additional;
  39. };
  40. struct dns_srv_data {
  41. uint16_t priority;
  42. uint16_t weight;
  43. uint16_t port;
  44. } __attribute__((packed, aligned(2)));
  45. struct dns_answer {
  46. uint16_t type;
  47. uint16_t class;
  48. uint32_t ttl;
  49. uint16_t rdlength;
  50. } __attribute__((packed, aligned(2)));
  51. struct dns_question {
  52. uint16_t type;
  53. uint16_t class;
  54. } __attribute__((packed, aligned(2)));
  55. struct interface;
  56. void dns_send_question(struct interface *iface, const char *question, int type);
  57. void dns_init_answer(void);
  58. void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength);
  59. void dns_send_answer(struct interface *iface, const char *answer);
  60. const char* dns_type_string(uint16_t type);
  61. void dns_handle_packet(struct interface *iface, uint8_t *buf, int len);
  62. #endif