ns_parse.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef NS_PARSE_H_
  2. #define NS_PARSE_H_
  3. #ifndef NS_INT16SZ
  4. #define NS_INT16SZ (sizeof(uint16_t))
  5. #endif // NS_INT16SZ
  6. #ifndef NS_INT32SZ
  7. #define NS_INT32SZ (sizeof(uint32_t))
  8. #endif // NS_INT32SZ
  9. #ifndef NS_MAXDNAME
  10. #define NS_MAXDNAME 1025
  11. #endif
  12. #define ns_msg_id_vlmcsd(handle) ((handle)._id + 0)
  13. #define ns_msg_base_vlmcsd(handle) ((handle)._msg + 0)
  14. #define ns_msg_end_vlmcsd(handle) ((handle)._eom + 0)
  15. #define ns_msg_size_vlmcsd(handle) ((handle)._eom - (handle)._msg)
  16. #define ns_msg_count_vlmcsd(handle, section) ((handle)._counts[section] + 0)
  17. #define ns_rr_name_vlmcsd(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
  18. #define ns_rr_type_vlmcsd(rr) ((ns_type)((rr).type + 0))
  19. #define ns_rr_class_vlmcsd(rr) ((ns_class)((rr).rr_class + 0))
  20. #define ns_rr_ttl_vlmcsd(rr) ((rr).ttl + 0)
  21. #define ns_rr_rdlen_vlmcsd(rr) ((rr).rdlength + 0)
  22. #define ns_rr_rdata_vlmcsd(rr) ((rr).rdata + 0)
  23. #define ns_msg_id_vlmcsd(handle) ((handle)._id + 0)
  24. #define ns_msg_base_vlmcsd(handle) ((handle)._msg + 0)
  25. #define ns_msg_end_vlmcsd(handle) ((handle)._eom + 0)
  26. #define ns_msg_size_vlmcsd(handle) ((handle)._eom - (handle)._msg)
  27. #define ns_msg_count_vlmcsd(handle, section) ((handle)._counts[section] + 0)
  28. typedef enum __ns_sect_vlmcsd {
  29. ns_s_qd_vlmcsd = 0, /*%< Query: Question. */
  30. ns_s_zn_vlmcsd = 0, /*%< Update: Zone. */
  31. ns_s_an_vlmcsd = 1, /*%< Query: Answer. */
  32. ns_s_pr_vlmcsd = 1, /*%< Update: Prerequisites. */
  33. ns_s_ns_vlmcsd = 2, /*%< Query: Name servers. */
  34. ns_s_ud_vlmcsd = 2, /*%< Update: Update. */
  35. ns_s_ar_vlmcsd = 3, /*%< Query|Update: Additional records. */
  36. ns_s_max_vlmcsd = 4
  37. } ns_sect_vlmcsd;
  38. typedef struct __ns_msg_vlmcsd {
  39. const uint8_t *_msg, *_eom;
  40. uint16_t _id, _flags, _counts[ns_s_max_vlmcsd];
  41. const uint8_t *_sections[ns_s_max_vlmcsd];
  42. ns_sect_vlmcsd _sect;
  43. int _rrnum;
  44. const uint8_t *_msg_ptr;
  45. } ns_msg_vlmcsd;
  46. typedef struct __ns_rr_vlmcsd {
  47. char name[NS_MAXDNAME];
  48. uint16_t type;
  49. uint16_t rr_class;
  50. uint32_t ttl;
  51. uint16_t rdlength;
  52. const uint8_t * rdata;
  53. } ns_rr_vlmcsd;
  54. int ns_initparse_vlmcsd(const uint8_t *msg, int msglen, ns_msg_vlmcsd *handle);
  55. int ns_parserr_vlmcsd(ns_msg_vlmcsd *handle, ns_sect_vlmcsd section, int rrnum, ns_rr_vlmcsd *rr);
  56. #endif /* NS_PARSE_H_ */