📄 dns_client.h
字号:
/* ############################################################################ (c) Copyright Virata Limited 2001 ## Virata Limited Confidential and Proprietary## The following software source code ("Software") is strictly confidential and# is proprietary to Virata Limited ("Virata"). It may only be read, used,# copied, adapted, modified or otherwise dealt with by you if you have# entered into a confidentiality agreement with Virata and then subject to the# terms of that confidentiality agreement and any other applicable agreement# between you and Virata. If you are in any doubt as to whether you are # entitled to access, read, use, copy, adapt, modify or otherwise deal with# the Software or whether you are entitled to disclose the Software to any# other person you should contact Virata. If you have not entered into a# confidentiality agreement with Virata granting access to this Software you# should forthwith return all media, copies and printed listings containing# the Software to Virata. ## Virata reserves the right to take legal action against you should you breach# the above provisions.## If you are unsure, or to report violations, please contact # support@virata.com# ##########################################################################*//* * file: dns_client.h * * description: this file contains defines and structures used by the * dns_client code. in particular this file contains the * structures used for internal representation of the DNS * messages and defines used for parsing. the file also * contains the structure to maintain the needed configuration * data. * *//* * List of New Routines: * SOCKEQUAL() * long2sock() * data2sock() * sock2long() * reverse_sockaddr_int() * reverse_sockaddr_arpa() * */#ifndef _DNS_CLIENT_H#define _DNS_CLIENT_H #include <atypes.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include <timelib.h>#include "dns_resolv.h"#undef DEBUG#define DNSC_MSG(x...) printf("%C " x)#ifdef DEBUG#define DNS_DEBUG #define DNS_VERBOSE#define DEBUG_LEVEL (0x01 | 0x02)#define DNSC_TRACE(x...) \ do { \ if (DEBUG_LEVEL & 0x01) \ { \ kprintf("<%C>: " x); \ } \ } while (0)#define DNSC_DEBUG(x...) \ do { \ if (DEBUG_LEVEL & 0x02) \ { \ kprintf("[%C]: " __FUNCTION__ ": " x); \ } \ } while (0)#define ASSERT(x) assert(x)#else#define DNSC_TRACE(x...)#define DNSC_DEBUG(x...)#define ASSERT(x)#endif#ifdef ATIC_SUPPORT_IPV6#define DNS_HAVE_IP6STACK#endif#ifndef IN#define IN#endif#ifndef OUT#define OUT#endif#ifdef DNS_DEBUG#define dprintf(args...) kprintf(args)#else#define dprintf(args...) ((void) 0)#endif#define LABELMAX 63 /* max label size, see RFC 1034 */ #define DNSMAX 512 /* max size of DNS message */#define CMPMASK (U8 )0xC0 /* compression test mask */ #define CMPSTRIP (U16 )0x3FFF /* zero the first two bits of the short */#define CMPBITSET(byte) (((byte) & CMPMASK) == CMPMASK)#define MIN(x,y) (x) < (y) ? (x) : (y)/* * typedef for the DNS message header. a DNS message is defined for both queries * and responses. it has a fixed 12 byte header followed by 4 variable length * fields. (RR are resource records) */typedef struct { U16 id; /* identification */ U16 flags; /* flags, see below */ U16 nquest; /* number questions */ U16 nansrr; /* number of answer RRs */ U16 nauthrr; /* number of authority RRs, also called NS RRs */ U16 naddrr; /* number of additional RRs */} DnsHdr; /* * defines used for the flags field of the DNS message, see RFC 1035. * * flag format: * * -------------------------------------------------- * | QR | opcode | AA | TC | RD | RA | zero | rcode | * -------------------------------------------------- * 1 4 1 1 1 1 3 4 * * QR - 0 = query . * 1 = response. * * opcode - 0 = a standard query. * 1 = an inverse query. * 2 = server status request. * * AA - 1 = is an authoritative answer. * * TC - 1 = message truncated, the reply would exceed 512 bytes so only the * first 512 bytes were returned. * * RD - 1 = recursion desired (recursive query). * * RA - 1 = recursion available. * * zero - must be 0. (see RFC 1035 section 4.1.1 and RFC 2065 section 6 and 6.1) * * rcode - 0 = no error. * 3 = name error, authoritative name server says the domain does not exist. * other errors described in section 4.1.1 of RFC 1035. */#define RSV_STDQUERY 0x0100 /* standard query with recursion desired, (requested) */#define RSV_INVQUERY 0x0900 /* inverse query with recursion desired, (requested) */ #define DNS_QR 0x8000 /* query or response */#define DNS_OPCODE 0x7800 /* dns header op code */#define DNS_STDQUERY 0x0000 /* standard query, 0 */#define DNS_INVQUERY 0x0800 /* inverse query, 1 */#define DNS_STATUS 0x0100 /* server status request */#define DNS_AUTHANS 0x0400 /* authoritive answer */#define DNS_TRUNC 0x0200 /* truncated answer */#define DNS_RECURDD 0x0100 /* recursion desired */#define DNS_RECURAV 0x0080 /* recursion available */#define DNS_RCODE 0x000F /* rcode */#define DNS_NOERROR 0x0000 /* rcode = 0 no error */#define DNS_NAMEERR 0x0003 /* name server says domain does not exist */#define DNS_FMTERR 0x0001 /* format error - name server unable to interpret query */#define DNS_SVRFAILERR 0x0002 /* server failure - problem with the name server */#define DNS_NOTIMPERR 0x0004 /* not implemented - server doesn't support query type */#define DNS_REFUSEERR 0x0005 /* refused - name server refuses to perform query *//* * structures and defines used to represent DNS messages. a DNS message is * defined in RFC 1035. the messages contain a 12 byte header, questions and * resource records. (resource records are abreviated in the comments and code * in several places as RR.) *//* DNS question */typedef struct question_t { struct question_t *q_next; /* pointer to the next question if there is one */ BOOL q_used; /* indicator as to whether this one's free */ char q_name[NAMEMAX+1]; /* query name, (domain name or IP address) */ U16 q_type; /* query type, (for us either A or PTR) */ U16 q_class; /* query class, will normally 1 for IP address */} DnsQuestion;/* query types */#define QT_A 1 /* IP address */#define QT_NS 2 /* name server */#define QT_CNAME 5 /* canonical name */#define QT_SOA 6 /* start of zone of authority */#define QT_PTR 12 /* pointer record */#define QT_HINFO 13 /* host info */#define QT_MX 15 /* mail exchange record */#define QT_AAAA 28 /* IP6 address, RFC 1886 */#define QT_SRV 33 /* SRV RFC 2782 */#define QT_NAPTR 35 /* NAPTR RFC 2915 */#define QT_A6 38 /* A6, RFC 2874 *//* query class */#define QC_IN 1 /* the internet *//* DNS resource record */typedef struct RR_t { struct RR_t *r_next; /* pointer to the next RR if there is one */ BOOL r_used; /* indicator as to whether this one's free */ char r_dname[NAMEMAX+1]; /* domain name */ U16 r_type; /* type */ U16 r_class; /* class */ U32 r_ttl; /* time to live */ U16 r_datalen; /* resource data length */ U8 *r_data; /* resource data */} DnsRRec;/* parsed or created DNS message */typedef struct { DnsHdr m_dnshdr; /* the DNS message header */ DnsQuestion *m_questions; /* list of DNS questions */ DnsRRec *m_answers; /* list of answer RRs */ DnsRRec *m_authoritys; /* list of authority RRs, (NS RRs) */ DnsRRec *m_additionals; /* list of additional RRs */} DnsMsg;/* general use defines */#define INADDR_ARPA "in-addr.arpa."#define IP6_ARPA "ip6.arpa."#define IP6_INT "ip6.int."#define DOT '.'#define SDOT "."#define COLON ":"/* SOA rdata structure, used with negative caching, see RFC 1035 section 3.3.13 and * RFC 2181 and RFC 2308. */typedef struct { BOOL s_used; /* in use indicator */ char s_mname[NAMEMAX+1]; /* domain name of NS that was primary source for zone */ char s_rname[NAMEMAX+1]; /* domain specifies mailbox of responsible person */ U32 s_serial; /* version number of original copy of zone */ U32 s_refresh; /* time interval before zone should be refreshed */ U32 s_retry; /* time interval before failed refresh should be retried */ U32 s_expire; /* time interval before zone is no longer authoritative */ U32 s_minimum; /* TTL field to be exported with RR from this zone */} SOArec; /* the following structures are used internally only. */typedef struct { char *dname; /* the domain name */ int dparts; /* number of parts to the name */} Dcmp;typedef enum { ptr_t, addr_t, aaaa_t} query_t;typedef struct { query_t qtype; /* query type, PTR, ADDRESS, etc */ char *hostname; /* domain name for ADDRESS queries */ U32 ipaddr; /* IP address for PTR queries */ BOOL cache_flag; /* cache use flag (IPv4 only) */ int qcnt; /* query count */ ATMOS_MESSAGE *amsg; /* the message to use */ struct dns_hostent *hptr; /* structure for results (IPv4 only) */ struct hostent *hent; /* structure for results (IPv6) */} Qinfo_t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -