update code
This commit is contained in:
153
dns.h
153
dns.h
@@ -1,23 +1,22 @@
|
||||
#ifndef _DNS_HEAD_H
|
||||
#define _DNS_HEAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <linux/filter.h>
|
||||
#include <netdb.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum dns_section {
|
||||
DNS_S_QD = 0x01,
|
||||
DNS_S_AN = 0x02,
|
||||
DNS_S_NS = 0x04,
|
||||
DNS_S_AR = 0x08,
|
||||
DNS_S_ALL = 0x0f
|
||||
} dns_section_t;
|
||||
#define QR_MASK 0x8000
|
||||
#define OPCODE_MASK 0x7800
|
||||
#define AA_MASK 0x0400
|
||||
#define TC_MASK 0x0200
|
||||
#define RD_MASK 0x0100
|
||||
#define RA_MASK 0x8000
|
||||
#define RCODE_MASK 0x000F
|
||||
|
||||
typedef enum dns_class {
|
||||
DNS_C_IN = 1,
|
||||
DNS_C_ANY = 255
|
||||
} dns_class_t;
|
||||
typedef enum dns_section { DNS_S_QD = 0x01, DNS_S_AN = 0x02, DNS_S_NS = 0x04, DNS_S_AR = 0x08, DNS_S_ALL = 0x0f } dns_section_t;
|
||||
|
||||
typedef enum dns_class { DNS_C_IN = 1, DNS_C_ANY = 255 } dns_class_t;
|
||||
|
||||
typedef enum dns_type {
|
||||
DNS_T_A = 1,
|
||||
@@ -58,36 +57,22 @@ typedef enum dns_rtcode {
|
||||
DNS_RC_NOTZONE = 10,
|
||||
/* EDNS(0) extended RCODEs */
|
||||
DNS_RC_BADVERS = 16,
|
||||
} dns_rtcode_t ; /* dns_rcode */
|
||||
|
||||
struct idns_head
|
||||
{
|
||||
unsigned short id;
|
||||
unsigned char opcode;
|
||||
unsigned char rcode;
|
||||
unsigned short qdcount;
|
||||
unsigned short ancount;
|
||||
unsigned short nscount;
|
||||
unsigned short arcount;
|
||||
} __attribute__ ((packed));
|
||||
} dns_rtcode_t; /* dns_rcode */
|
||||
|
||||
struct dns_head {
|
||||
unsigned short id; // identification number
|
||||
unsigned char rd : 1; // recursion desired
|
||||
unsigned char tc : 1; // truncated message
|
||||
unsigned char aa : 1; // authoritive answer
|
||||
unsigned char opcode : 4; // purpose of message
|
||||
unsigned char query : 1; // query/response flag
|
||||
unsigned char rcode : 4; // response code
|
||||
unsigned char cd : 1; // checking disabled
|
||||
unsigned char ad : 1; // authenticated data
|
||||
unsigned char z : 1; // its z! reserved
|
||||
unsigned char ra : 1; // recursion available
|
||||
unsigned short qdcount; // number of question entries
|
||||
unsigned short ancount; // number of answer entries
|
||||
unsigned short nscount; // number of authority entries
|
||||
unsigned short nrcount; // number of resource entries
|
||||
} __attribute__ ((packed));
|
||||
unsigned short id; // identification number
|
||||
unsigned short qr; /* Query/Response Flag */
|
||||
unsigned short opcode; /* Operation Code */
|
||||
unsigned short aa; /* Authoritative Answer Flag */
|
||||
unsigned short tc; /* Truncation Flag */
|
||||
unsigned short rd; /* Recursion Desired */
|
||||
unsigned short ra; /* Recursion Available */
|
||||
unsigned short rcode; /* Response Code */
|
||||
unsigned short qdcount; // number of question entries
|
||||
unsigned short ancount; // number of answer entries
|
||||
unsigned short nscount; // number of authority entries
|
||||
unsigned short nrcount; // number of addititional resource entries
|
||||
} __attribute__((packed));
|
||||
|
||||
struct dns_qds {
|
||||
unsigned short type;
|
||||
@@ -104,75 +89,73 @@ struct dns_rrs {
|
||||
|
||||
typedef uint32_t TTL;
|
||||
|
||||
typedef struct dns_question_t /* RFC-1035 */
|
||||
typedef struct dns_question_t /* RFC-1035 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
} dns_question_t;
|
||||
|
||||
typedef struct dns_generic_t /* RFC-1035 */
|
||||
typedef struct dns_generic_t /* RFC-1035 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
} dns_generic_t;
|
||||
|
||||
typedef struct dns_a_t /* RFC-1035 */
|
||||
typedef struct dns_a_t /* RFC-1035 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
in_addr_t address;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
in_addr_t address;
|
||||
} dns_a_t;
|
||||
|
||||
typedef struct dns_aaaa_t /* RFC-1886 */
|
||||
typedef struct dns_aaaa_t /* RFC-1886 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
struct in6_addr address;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
struct in6_addr address;
|
||||
} dns_aaaa_t;
|
||||
|
||||
typedef struct dns_cname_t /* RFC-1035 */
|
||||
typedef struct dns_cname_t /* RFC-1035 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
const char *cname;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
const char *cname;
|
||||
} dns_cname_t;
|
||||
|
||||
typedef struct dns_ptr_t /* RFC-1035 */
|
||||
typedef struct dns_ptr_t /* RFC-1035 */
|
||||
{
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
const char *ptr;
|
||||
const char *name;
|
||||
dns_type_t type;
|
||||
dns_class_t class;
|
||||
TTL ttl;
|
||||
const char *ptr;
|
||||
} dns_ptr_t;
|
||||
|
||||
|
||||
typedef union dns_answer_t
|
||||
{
|
||||
dns_generic_t generic;
|
||||
dns_a_t a;
|
||||
dns_cname_t cname;
|
||||
dns_ptr_t ptr;
|
||||
dns_aaaa_t aaaa;
|
||||
typedef union dns_answer_t {
|
||||
dns_generic_t generic;
|
||||
dns_a_t a;
|
||||
dns_cname_t cname;
|
||||
dns_ptr_t ptr;
|
||||
dns_aaaa_t aaaa;
|
||||
} dns_answer_t;
|
||||
|
||||
struct dns_packet {
|
||||
struct dns_head head;
|
||||
dns_question_t *questions;
|
||||
dns_answer_t *answers;
|
||||
dns_answer_t *nameservers;
|
||||
dns_answer_t *additional;
|
||||
dns_answer_t *answers;
|
||||
dns_answer_t *nameservers;
|
||||
dns_answer_t *additional;
|
||||
};
|
||||
|
||||
int dns_decode(struct dns_packet *packet, char *data, int size);
|
||||
int dns_decode(struct dns_packet *packet, unsigned char *data, int size);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user