📄 dns_client_query.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_query.h * * description: this file contains defines and typedefs that * support the QueryState structure that is used to represent * DNS query requests in the dns client code. * *//* * List of New Routines: * dns_stdaaa_query() */#ifndef _DNS_QUERY_H#define _DNS_QUERY_H #include <sys/time.h>#include "atypes.h"#include "dns_client.h"struct query_state;typedef struct query_state QueryState;/* set up function pointers for use in the query state structure. */typedef int (*DnsConst)(QueryState *); /* message construction */typedef void (*DnsResp)(QueryState *); /* message response handling */typedef void (*DnsQuery)(QueryState *); /* handle results from internal query *//* name server structure */typedef struct { char ns_name[NAMEMAX+1]; /* name server's name, if we have it */ struct sockaddr_storage ns_addr; /* server's address */ int ns_error; /* this server returned an error or bad response */ int ns_recursion; /* will server do recursive lookups */ int ns_try; /* number of times we've tried this server */} NS_t;typedef enum { a_type, /* A, address type, looking for an IPv4 address */ a6_type, /* A6, address type, looking for IPv6 address/prefix */ aaaa_type, /* AAAA, address type, looking for an IPv6 address */ ac_type, /* starting with a CNAME, A, address type looking for IP address */ ptr_type, /* PTR, pointer type, looking for a host name */ ptr6_type, /* PTR, pointer type, looking for a host name */ naptr_type, /* NAPTR type */ srv_type /* SRV type */} Qtype;typedef enum { wf_addr, /* waiting for an A type, that is an IP address */ wf_aaaa, /* waiting for an AAAA type, that is an IPv6 address */ wf_a6, /* waiting for an A6 type, that is an IPv6 address */ wf_nsaddr, /* waiting for a name server's IP address */ wf_nsaddr6, /* waiting for a name server's IP address */ wf_caddr, /* waiting for a CNAME address */ wf_cqaddr, /* waiting for a CNAME query */ wf_ptr, /* waiting for a PTR type which is a host name */ wf_ptr6, /* waiting for a PTR type for an IPv6 address */ wf_naptr, /* waiting for NAPTR RRs */ wf_srv /* waiting for SRV RRs */} Qstate; /* * query_state structure * * this structure represents an individual DNS query. it maintains state * information concerning the query and the constructed DNS request message. * the request message is maintained to simplify resends. the queries are * identified by the qid or reply. note also that the buffer for * the constructed DNS message, dns_query, should remain as the first element * of the structure. */struct query_state { U8 dns_query[BUFLEN]; /* the DNS request message */ int dq_size; /* number of bytes in the DNS request message */ DnsMsg dnsreply; /* the parsed DNS reply */ BOOL used; /* free flag */ BOOL use_cache; /* flag to indicating use of the cache */ ATMOS_MESSAGE *nxquery; /* next query in the chain */ ATMOS_MESSAGE *reply; /* reply message from user */ struct sockaddr_storage svripaddr; /* IP address of responding server */ char domain[NAMEMAX+1]; /* the domain name the request was for */ char cname[NAMEMAX+1]; /* canonical domain name, if CNAME */ struct timeval deadline; /* timeout for current query */ DnsDomain dm; /* our domain information from config */ NS_t ns_addrs[MAXNS]; /* list of NS addresses */ int addr_index; /* Index of the name server to which the query was sent. This will be used in case the server sents back a refused response */ int num_ns; /* number of NS in the list */ int next_srch; /* next search to use */ int ntrys; /* number of attempts made for this query */ U16 nquerys; /* number of querys done for this domain */ U16 qid; /* DNS query ID */ Qtype qtype; /* the query type */ Qstate qstate; /* the query state, what we're waiting for */ DnsConst dns_construct; /* routine to construct DNS message */ DnsResp dns_response; /* routine to handle the DNS response */ DnsQuery dns_qreply; /* routine to handle internal query reply */}; /* QueryState */extern int construct_std_dnsquery(QueryState *, U16);/* dns_std6_query -- * Construct a standard DNS query for AAAA or A6 record. * * PARAMETERS * qs - query state * * RETURNS * 0 for success, or * -1 to indicate an error. */static inline intdns_std6_query(QueryState *qs){ return construct_std_dnsquery(qs, qs->qtype == aaaa_type ? QT_AAAA : QT_A6);}/* * dns_std_query() * construct a standard DNS query for an IP address */static inline intdns_std_query(QueryState *qs){ return construct_std_dnsquery(qs, QT_A);}/* * dns_ptr_query() * this routine constructs a PTR query, that is a query for a host name * using an IP address. */static inline intdns_ptr_query(QueryState *qs){ return construct_std_dnsquery(qs, QT_PTR);}static inline intdns_NAPTR_query(QueryState *qs){ return construct_std_dnsquery(qs, QT_NAPTR);} static inline intdns_SRV_query(QueryState *qs){ return construct_std_dnsquery(qs, QT_SRV);}/* * ns_list_complete() * * this routine will just loop through the name server list and see if we've * tried all of them. we can tell this by looking at the ns_try member, if any * are zero we haven't tried all the servers in the list. * * return: TRUE if we've tried all the servers in the list, * FALSE if not. */static inline BOOLns_list_complete(NS_t *list, int cnt){ int i; for ( i = 0; i < cnt; i++ ) { if ( list[i].ns_try == 0 ) return FALSE; } return TRUE;} /* end ns_list_complete() */#ifdef DNS_DEBUG/* * print_responding_server() * * this routine will print the address of the server that we received the * last message from. */static inline voidprint_responding_server(QueryState *query){ char ipstring[INET6_ADDRSTRLEN]; ip_string(&query->svripaddr, ipstring, sizeof(ipstring)); dprintf("reply from NS: %s\n", ipstring);} /* end print_responding_server() */#endifextern void dns_response_std_query(QueryState *);extern void dns_response_std6_query(QueryState *);extern void dns_response_ptr_query(QueryState *);extern void dns_response_ptr6_query(QueryState *);extern void cname_reply(QueryState *);extern void ns_reply(QueryState *);extern int dns_query(QueryState *query);extern int post_query(QueryState *, int);extern void dns_response_timeout(QueryState *);extern void dns_start_next_search(QueryState *);extern void dns_start_next_search6(QueryState *);extern void dns_start_next_search_common(QueryState *);extern int get_ns_list(const char *, NS_t *, DnsDomain *);extern int fmt_ptr_answer(QueryState *, DnsMsg *);extern int fmt_ip_answer(QueryState *, DnsMsg *);extern int fmt_cname_answer(QueryState *, DnsMsg *);extern int fmt_cache_answer(QueryState *, DnsMsg *);extern void print_dns_error(int);extern void copy_domain(DnsDomain *to, DnsDomain *from);extern void dns_XX_query(ATMOS_MESSAGE *, DnsDomain *);extern void dns_response_XX_query(QueryState *query);extern void fmt_XX_answer(QueryState *query, DnsRRec *answers);#ifdef DNS_DEBUGextern void dns_print_query(QueryState *qs);#endif /* DNS_DEBUG */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -