dns.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <arpa/inet.h>
  17. #define FLAG_RESPONSE 0x8000
  18. #define FLAG_AUTHORATIVE 0x0400
  19. #define TYPE_A 0x0001
  20. #define TYPE_PTR 0x000C
  21. #define TYPE_TXT 0x0010
  22. #define TYPE_AAAA 0x001c
  23. #define TYPE_SRV 0x0021
  24. #define TYPE_ANY 0x00ff
  25. #define IS_COMPRESSED(x) ((x & 0xc0) == 0xc0)
  26. #define MCAST_ADDR "224.0.0.251"
  27. #define MCAST_ADDR6 "ff02::fb"
  28. #define MCAST_PORT 5353
  29. #define CLASS_FLUSH 0x8000
  30. #define CLASS_UNICAST 0x8000
  31. #define CLASS_IN 0x0001
  32. #define MAX_NAME_LEN 8096
  33. #define MAX_DATA_LEN 8096
  34. #define C_DNS_SD "_services._dns-sd._udp.local"
  35. struct dns_header {
  36. uint16_t id;
  37. uint16_t flags;
  38. uint16_t questions;
  39. uint16_t answers;
  40. uint16_t authority;
  41. uint16_t additional;
  42. } __attribute__((packed));
  43. struct dns_srv_data {
  44. uint16_t priority;
  45. uint16_t weight;
  46. uint16_t port;
  47. } __attribute__((packed));
  48. struct dns_answer {
  49. uint16_t type;
  50. uint16_t class;
  51. uint32_t ttl;
  52. uint16_t rdlength;
  53. } __attribute__((packed));
  54. struct dns_question {
  55. uint16_t type;
  56. uint16_t class;
  57. } __attribute__((packed));
  58. struct interface;
  59. extern int cfg_proto;
  60. extern int cfg_no_subnet;
  61. void dns_send_question(struct interface *iface, struct sockaddr *to,
  62. const char *question, int type, int multicast);
  63. void dns_init_answer(void);
  64. void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
  65. void dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer);
  66. void dns_reply_a(struct interface *iface, struct sockaddr *to, int ttl, const char *hostname);
  67. void dns_reply_a_additional(struct interface *iface, struct sockaddr *to, int ttl);
  68. const char* dns_type_string(uint16_t type);
  69. void dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t port, uint8_t *buf, int len);
  70. #endif