diff options
Diffstat (limited to 'src/inc/dns_analyse.h')
| -rw-r--r-- | src/inc/dns_analyse.h | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/src/inc/dns_analyse.h b/src/inc/dns_analyse.h new file mode 100644 index 0000000..9f6e639 --- /dev/null +++ b/src/inc/dns_analyse.h @@ -0,0 +1,242 @@ +#ifndef DNS_ANALYSE_H
+#define DNS_ANALYSE_H
+
+#ifndef u_char
+#define u_char unsigned char
+#endif
+#ifndef u_int16_t
+#define u_int16_t unsigned short
+#endif
+#ifndef u_int32_t
+#define u_int32_t unsigned int //adjust by lqy 20070521 long to int
+#endif
+
+#include <MESA/stream.h>
+
+#define RUNTIME_DNSMODULE "[DNS MODULE:]"
+
+#define DNS_PORT 53
+#define PROTID_DNS 6
+
+#define DNS_MAX_UDP_MESSAGE 512
+#define DNS_MAX_LABEL 63
+#define DNS_MAX_NAME 255
+#define MAX_IP_NUM 128
+#define MAX_CNAME_NUM 32
+#define MAX_NS_NUM 32
+#define MAX_MB_NUM 32
+#define MAX_MX_NUM 32
+#define MAX_SOA_NUM 32
+#define IPV6_LEN 16
+
+#define MAX_FLAG_LEN 30
+
+typedef struct{
+ u_char type; //0-query, 1-response
+ void *apme;
+} dns_info_t;
+
+typedef struct{
+ u_int16_t qtype;
+ u_int16_t qclass;
+ u_char qname[DNS_MAX_NAME + 1];
+} dns_question_t;
+
+typedef struct
+{
+ u_char type; //0-query, 1-response
+ dns_question_t question; //query structure
+ int ipv4_num; //number of ipv4s in response
+ int ipv6_num; //number of ipv6s in response
+ int cname_num; //number of cnames in response
+ int ns_num; //number of ns in response
+ int mb_num; //number of mbs in response
+ int mx_num; //number of mxs in response
+ int soa_num; //number of soa(start of authority) in response
+ unsigned int ipv4[MAX_IP_NUM]; //list of ips in response for ipv4 (network order)
+ unsigned char ipv6[MAX_IP_NUM][IPV6_LEN]; //list of ips in response for ipv6 (network order)
+ u_char cname[MAX_CNAME_NUM][DNS_MAX_NAME]; //list of cnames in response
+ u_char ns[MAX_NS_NUM][DNS_MAX_NAME]; //list of name server(ns)s in response
+ u_char mb[MAX_MB_NUM][DNS_MAX_NAME]; //list of mail box(nmb)s in response
+ u_char mx[MAX_MX_NUM][DNS_MAX_NAME]; //list of mail exchange(mx)s in response
+ u_char soa_manme[MAX_SOA_NUM][DNS_MAX_NAME]; //list of soa master name(mname)s in response
+ u_char soa_rname[MAX_SOA_NUM][DNS_MAX_NAME]; //list of soa responsible name(rname:ranme is a emalil addr)s in response
+} dns_response_t;
+
+typedef struct {
+ u_int16_t id;
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ u_char rd:1;
+ u_char tc:1;
+ u_char aa:1;
+ u_char opcode:4;
+ u_char qr:1;
+ u_char rcode:4;
+ u_char z:3;
+ u_char ra:1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ u_char qr:1;
+ u_char opcode:4;
+ u_char aa:1;
+ u_char tc:1;
+ u_char rd:1;
+ u_char ra:1;
+ u_char z:3;
+ u_char rcode:4;
+#endif
+
+ u_int16_t qdcount;
+ u_int16_t ancount;
+ u_int16_t nscount;
+ u_int16_t arcount;
+} dnshdr_t;
+
+#define DNSHDR_OPCODE_QUERY 0
+#define DNSHDR_OPCODE_IQUERY 1
+#define DNSHDR_OPCODE_STATUS 2
+
+#define DNSHDR_RCODE_NOERR 0
+#define DNSHDR_RCODE_FMTERR 1
+#define DNSHDR_RCODE_SRVFAIL 2
+#define DNSHDR_RCODE_NAMEERR 3
+#define DNSHDR_RCODE_NOTIMPL 4
+#define DNSHDR_RCODE_REFUSE 5
+
+#define DNS_HINFO_MAX_CPU 40
+#define DNS_HINFO_MAX_OS 40
+
+typedef struct {
+ u_char name[DNS_MAX_NAME + 1];
+ u_int16_t type;
+ u_int16_t rr_class;
+ u_int32_t ttl;
+ u_int16_t rdlength;
+ union {
+ u_char cname[DNS_MAX_NAME + 1];
+ struct {
+ u_char cpu[DNS_HINFO_MAX_CPU + 1];
+ u_char os[DNS_HINFO_MAX_OS + 1];
+ } hinfo;
+ u_char mb[DNS_MAX_NAME + 1];
+ u_char md[DNS_MAX_NAME + 1];
+ u_char mf[DNS_MAX_NAME + 1];
+ u_char mg[DNS_MAX_NAME + 1];
+ struct {
+ u_char rmailbx[DNS_MAX_NAME + 1];
+ u_char emailbx[DNS_MAX_NAME + 1];
+ } minfo;
+ u_char mr[DNS_MAX_NAME + 1];
+ struct {
+ u_int16_t preference;
+ u_char exchange[DNS_MAX_NAME + 1];
+ } mx;
+ u_char ns[DNS_MAX_NAME + 1];
+ u_char ptr[DNS_MAX_NAME + 1];
+ struct {
+ u_char mname[DNS_MAX_NAME + 1];
+ u_char rname[DNS_MAX_NAME + 1];
+ u_int32_t serial;
+ u_int32_t refresh;
+ u_int32_t retry;
+ u_int32_t expire;
+ u_int32_t minimum;
+ } soa;
+ u_int32_t a;
+ u_char aaaa[16];
+ struct {
+ u_char * txt;
+ u_int32_t size;
+ } txt;
+ struct {
+ u_char * null;
+ u_int32_t size;
+ } null;
+ struct {
+ u_int32_t addr;
+ u_char protocol;
+ u_char * bitmap;
+ u_int32_t size;
+ } wks;
+ } rdata;
+} dns_rr_t;
+
+#define DNS_TYPE_A 1
+#define DNS_TYPE_NS 2
+#define DNS_TYPE_MD 3
+#define DNS_TYPE_MF 4
+#define DNS_TYPE_CNAME 5
+#define DNS_TYPE_SOA 6
+#define DNS_TYPE_MB 7
+#define DNS_TYPE_MG 8
+#define DNS_TYPE_MR 9
+#define DNS_TYPE_NULL 10
+#define DNS_TYPE_WKS 11
+#define DNS_TYPE_PTR 12
+#define DNS_TYPE_HINFO 13
+#define DNS_TYPE_MINFO 14
+#define DNS_TYPE_MX 15
+#define DNS_TYPE_TXT 16
+#define DNS_TYPE_AAAA 28 //dns_ipv6
+
+#define DNS_QTYPE_AXFR 252
+#define DNS_QTYPE_MAILB 253
+#define DNS_QTYPE_MAILA 254
+#define DNS_QTYPE_ANY 255
+
+#define DNS_CLASS_IN 1
+#define DNS_CLASS_CS 2
+#define DNS_CLASS_CH 3
+#define DNS_CLASS_HS 4
+#define DNS_QCLASS_ANY 255
+
+#define NS_INT16SZ 2
+#define NS_INT32SZ 4
+
+#define NS_GET16(s, cp) do { \
+ register u_char *t_cp = (u_char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+} while (0)
+
+#define NS_GET32(l, cp) do { \
+ register u_char *t_cp = (u_char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+} while (0)
+
+#define NS_PUT16(s, cp) do { \
+ register u_int16_t t_s = (u_int16_t)(s); \
+ register u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = t_s >> 8; \
+ *t_cp = t_s; \
+ (cp) += NS_INT16SZ; \
+} while (0)
+
+#define NS_PUT32(l, cp) do { \
+ register u_int32_t t_l = (u_int32_t)(l); \
+ register u_char *t_cp = (u_char *)(cp); \
+ *t_cp++ = t_l >> 24; \
+ *t_cp++ = t_l >> 16; \
+ *t_cp++ = t_l >> 8; \
+ *t_cp = t_l; \
+ (cp) += NS_INT32SZ; \
+} while (0)
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
|
