You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

andns_lib.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************
  2. * AUTHOR: Federico Tomassini *
  3. * Copyright (C) Federico Tomassini *
  4. * Contact effetom@gmail.com *
  5. ***********************************************
  6. ******* BEGIN 3/2006 ********
  7. *************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, *
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  17. * GNU General Public License for more details. *
  18. * *
  19. ************************************************************************/
  20. #ifndef ANDNS_LIB_H
  21. #define ANDNS_LIB_H
  22. #include <string.h>
  23. #include <stdint.h>
  24. #include <sys/types.h>
  25. #define ANDNS_MAX_QUESTION_LEN 263 /* TODO */
  26. #define ANDNS_MAX_ANSWER_LEN 516
  27. #define ANDNS_MAX_ANSWERS_NUM 256
  28. #define ANDNS_MAX_PK_LEN ANDNS_MAX_QUESTION_LEN+\
  29. ANDNS_MAX_ANSWERS_NUM*ANDNS_MAX_ANSWER_LEN
  30. #define ANDNS_MAX_DATA_LEN 512
  31. #define ANDNS_MAX_QST_LEN 512
  32. #define ANNDS_DNS_MAZ_QST_LEN 255
  33. #define ANDNS_MAX_ANSW_IP_LEN 20
  34. #define ANDNS_MAX_ANSW_H_LEN 516
  35. #define ANDNS_HASH_H 16
  36. #define ANDNS_COMPR_LEVEL Z_BEST_COMPRESSION
  37. #define ANDNS_COMPR_THRESHOLD 1000
  38. struct andns_pkt_data
  39. {
  40. uint8_t m;
  41. uint8_t wg;
  42. uint8_t prio;
  43. uint16_t rdlength;
  44. uint16_t service;
  45. char *rdata;
  46. struct andns_pkt_data *next;
  47. };
  48. typedef struct andns_pkt_data andns_pkt_data;
  49. #define ANDNS_PKT_DATA_SZ sizeof(andns_pkt_data)
  50. #define APD_ALIGN(apd) (apd)->rdata=(char*)xmalloc((apd)->rdlength+1); \
  51. memset((apd)->rdata,0,(apd)->rdlength+1)
  52. #define APD_MAIN_IP 1<<0
  53. #define APD_IP 1<<1
  54. #define APD_TCP 1<<2
  55. #define APD_UDP 1<<3
  56. typedef struct andns_pkt
  57. {
  58. uint16_t id;
  59. uint8_t r;
  60. uint8_t qr;
  61. uint8_t p;
  62. uint8_t z;
  63. uint8_t qtype;
  64. uint16_t ancount;
  65. uint8_t ipv;
  66. uint8_t nk;
  67. uint8_t rcode;
  68. uint16_t service;
  69. uint16_t qstlength;
  70. char *qstdata;
  71. andns_pkt_data *pkt_answ;
  72. } andns_pkt;
  73. #define ANDNS_PKT_SZ sizeof(andns_pkt)
  74. #define AP_ALIGN(ap) (ap)->qstdata=(char*)xmalloc((ap)->qstlength)
  75. #define ANDNS_HDR_SZ 4
  76. #define ANDNS_HDR_Z 4
  77. #define ANDNS_MAX_SZ ANDNS_HDR_SZ+ANDNS_MAX_QST_LEN+ANDNS_MAX_QST_LEN+4
  78. #define ANDNS_SET_RCODE(s,c) *((s)+3)=(((*((s)+3))&0xf0)|c)
  79. #define ANDNS_SET_QR(s) (*((s)+2))|=0x80
  80. #define ANDNS_SET_ANCOUNT(s,n) *(s+2)|=((n)>>1);*(s+3)|=((n)<<7);
  81. #define ANDNS_SET_Z(s) *(s+3)|=0x20;
  82. #define ANDNS_UNSET_Z(s) *(s+3)&=0xdf;
  83. /* ANDNS PROTO-TYPE */
  84. #define ANDNS_PROTO_TCP 0
  85. #define ANDNS_PROTO_UDP 1
  86. /* ANDNS QUERY-TYPE */
  87. #define AT_A 0 /* h->ip */
  88. #define AT_PTR 1 /* ip->h */
  89. #define AT_G 2 /* global */
  90. /* RCODES: The rcodes are portable between ANDNS and DNS */
  91. #define ANDNS_RCODE_NOERR 0 /* No error */
  92. #define ANDNS_RCODE_EINTRPRT 1 /* Intepret error */
  93. #define ANDNS_RCODE_ESRVFAIL 2 /* Server failure */
  94. #define ANDNS_RCODE_ENSDMN 3 /* No such domain */
  95. #define ANDNS_RCODE_ENIMPL 4 /* Not implemented */
  96. #define ANDNS_RCODE_ERFSD 5 /* Refused */
  97. /* REALMS TO SEARCH */
  98. #define NTK_REALM 1
  99. #define INET_REALM 2
  100. /* IP VERSION */
  101. #define ANDNS_IPV4 0
  102. #define ANDNS_IPV6 1
  103. int andns_compress(char *src,int srclen);
  104. char* andns_uncompress(char *src,int srclen,int *dstlen) ;
  105. int a_hdr_u(char *buf,andns_pkt *ap);
  106. int a_qst_u(char *buf,andns_pkt *ap,int limitlen);
  107. int a_answ_u(char *buf,andns_pkt *ap,int limitlen);
  108. int a_answs_u(char *buf,andns_pkt *ap,int limitlen);
  109. int a_u(char *buf,int pktlen,andns_pkt **app);
  110. int a_hdr_p(andns_pkt *ap,char *buf);
  111. int a_qst_p(andns_pkt *ap,char *buf,int limitlen);
  112. int a_answ_p(andns_pkt *ap,andns_pkt_data *apd,char *buf,int limitlen);
  113. int a_answs_p(andns_pkt *ap,char *buf, int limitlen);
  114. int a_p(andns_pkt *ap, char *buf);
  115. andns_pkt* create_andns_pkt(void);
  116. andns_pkt_data* create_andns_pkt_data(void);
  117. andns_pkt_data* andns_add_answ(andns_pkt *ap);
  118. void destroy_andns_pkt_data(andns_pkt_data *apd);
  119. void andns_del_answ(andns_pkt *ap);
  120. void destroy_andns_pkt_datas(andns_pkt *ap);
  121. void destroy_andns_pkt(andns_pkt *ap);
  122. #endif /* ANDNS_LIB_H */