home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
internet
/
dnsquery_1
/
h
/
dnsquery
next >
Wrap
Text File
|
1996-02-08
|
10KB
|
236 lines
/*
* DNSQuery.h
*
* A multiply threadable, multitasking DNS resolver
*
* Copyright (C) Stewart Brodie, February 1996.
* Portions are copyright Regents of the University California Berkeley
*
* This code may be freely used in applications designed to work with the
* Acorn TCP/IP stack or FreeNet or compatible stacks for RISC OS, provided
* that a copy of the UCB copyright & disclaimer message is included, and
* also my own disclaimer.
*
* This code is based on the res_ function code from BIND-4.9.3-REL
* but with extensive modifications to make it state driven.
*
* enum dns_status should be treated as an opaque status code except
* for dns_query_complete_success and dns_query_complete_failure
*
* Function veneers described with the functions. The only supported
* address class is C_IN. Lots of the explanations contain VITAL
* information about how to use the API provided, and an explanation
* of the internal workings is provided where necessary.
*
*/
#ifndef dnsquery_h_included
#define dnsquery_h_included
#ifdef __cplusplus
extern "C" {
#endif
/* An abstract handle on the query */
typedef struct dnsquery dnsquery;
/* See comment above about dns_status */
typedef enum {
dns_query_init,
dns_query_next_ns,
dns_query_same_ns,
dns_query_complete_success,
dns_query_complete_failure,
dns_query_v_circuit_init,
dns_query_v_circuit_connect,
dns_query_v_circuit_recv,
dns_query_v_circuit_polling_connect,
dns_query_v_circuit_connect_succeeded,
dns_query_v_circuit_select_for_reading,
dns_query_v_circuit_reading_size,
dns_query_v_circuit_init_main_answer,
dns_query_v_circuit_read_main_answer,
dns_query_v_circuit_junk,
dns_query_dgram_wait_timeout,
dns_query_dgram_blocked_select,
dns_query_dgram_select_result,
dns_query_converged_after_if,
dns_query_running_subquery
} dns_status;
/* dnsquery *dnsquery_new(char *data, int C_??, int T_?? )
*
* Start a new query with class C_?? and type T_?? with the
* data given, which is dependent on T_??. C_ and T_ values
* may be found in netlib:arpa.h.nameser. Do not use this
* API for C_IN/T_A or C_IN/T_PTR unless you wish to bypass
* the search semantics and faking of dotted-quads into hosts
* normally done by gethostbyname, and the automatic data
* creation of gethostbyaddr. The parameter meanings are the
* same as for res_query.
*
* Returns: handle to the query, or NULL if failed to create it
*/
extern dnsquery *dnsquery_new(char *, int , int);
/* dnsquery *dnsquery_gethostbyaddr(char *addr, int size, int addrclass)
*
* Start a multitasking version of gethostbyaddr. Parameters are the
* same as for the standard call. addrclass should be C_IN. size
* must be 4 (ie. can't handle IPv6 lookups yet). Although a char *,
* the addr parameter is a pointer to the 4 byte IP address in network
* order.
*
* Returns: handle to the query, or NULL if failed to create it
*/
extern dnsquery *dnsquery_gethostbyaddr(char *, int ,int);
/* dnsquery *dnsquery_gethostbyname(char *name)
*
* Starts a multitasking version of gethostbyname. Parameter is the
* hostname to lookup. Dotted-quad lookups are trapped (ie. if you
* ask for dnsquery_gethostbyname("152.78.67.42") then you will get an
* artificially created answer bypassing the DNS. This function will
* implement the usual semantics of res_search by searching all the
* domains specified in the resconf file. The multiple lookups which
* may be generated are handled transparently.
*
* Returns: handle to the query, or NULL if failed to create it
*/
extern dnsquery *dnsquery_gethostbyname(char *);
/* dns_status dnsquery_check(dnsquery *query)
*
* Checks on the progress of 'query'. The return value comes from
* the enum given earlier in this file. The only determination
* the client can make from this result is whether the query is
* still in progress, or has finished. dns_query_complete_failure
* represents a failure of some kind (you can't tell what), whereas
* dns_query_complete_success represents a success of some kind.
*
* The purpose of this call is not just to check whether it has
* completed, but to step through the internal state table in order
* to make the resolver work. The code will loop internally whilst
* it isn't waiting for a response from the network, the implication
* of this being that if this function returns and the status is NOT
* one of the two finished states (see above) then it is waiting for
* a timeout or data to arrive.
*
* You can call this function as frequently or infrequently as you
* wish. You may, for example, call SWI Wimp_Poll between calls to
* this function. However, in order to implement the correct timeout
* of failing calls, you must call this function regularly. This
* library does not do anything in the background, and will only
* notice timeouts if you call this function.
*
* >> IMPORTANT NOTE: the definition of 'success' is that none of
* >> the SWI calls to the TCP/IP stack failed. Hence the query
* >> may not have been answered - you need to retrieve the answer
* >> in order to find out whether any answer was obtained.
*/
extern dns_status dnsquery_check(dnsquery *);
/* void dnsquery_dispose(dnsquery *query)
*
* Destroys the internal data structures associated with 'query'.
* 'query' must be a value which was returned by an earlier call
* to one of the dnsquery_ functions, and must not have been
* passed to this function before, unless it was subsequently
* returned by another dnsquery_ function after such a call.
* (Basically, don't free the same thing twice! :-) The current
* SharedCLibrary will cause your application to exit silently
* if you do.
*/
extern void dnsquery_dispose(dnsquery *);
/* struct hostent *dnsquery_getanswer(dnsquery *query)
*
* Returns a pointer to a *static* buffer within the dnsquery
* data area representing the result of a 'query' which was started
* with either dnsquery_gethostbyaddr or dnsquery_gethostbyaddr.
* You must NOT make this call if the query was started with
* dnsquery_new() EVEN IF it was a T_A or T_PTR lookup. However,
* any query which can be validly passed to this function may also
* be passed to dnsquery_getanswerraw described below.
*
* You must only ever make this call after dnsquery_check(query) has
* returned dns_query_complete_success. You must not make this call
* after 'query' has been passed to dnsquery_dispose.
*
* You can make this call more than once in between those two states
* although you should realise that you will suffer a performance hit
* from doing this (the library has to make a lot of calls to malloc
* and free whilst creating the struct hostent).
*
* >> IMPORTANT NOTE: You are returned a pointer to a struct hostent.
* >> This buffer WILL be corrupted by later calls to this function,
* >> AND ALSO by calls to the standard gethostbyname and gethostbyaddr
* >> functions usually associated with DNS resolver libraries.
*/
extern struct hostent *dnsquery_getanswer(dnsquery *);
/* void *dnsquery_getanswerraw(dnsquery *query, int *answersize)
*
* Similar to dnsquery_getanswer, but used when that function cannot
* be called (for reasons given above).
*
* You must only ever make this call after dnsquery_check(query) has
* returned dns_query_complete_success. You must not make this call
* after 'query' has been passed to dnsquery_dispose.
*
* You can make this call more than once in between those two states,
* although there is no performance hit with this function call
*
* This function returns you a pointer to the query result as returned
* by the remote DNS server which responded to the query, and will store
* the size of the result in the given answersize variable. This is a
* result-only parameter. The returned pointer remains valid until
* the 'query' has been passed to dnsquery_dispose. You must parse
* the response yourself (or port the resparse application (not yet
* supplied) to find the answer IF THERE IS ONE). The ancount of the
* query may be zero (indicating no answers have been returned).
*
*/
extern void *dnsquery_getanswerraw(dnsquery *, int *);
/*
* int dnsquery_check_nameservers(struct sockaddr_in **ptr_to_servers)
*
* This function can be used to find out which nameservers are
* being used by the dnsquery library. Internally, the library
* maintains an array of 'struct sockaddr_in' structures, and
* the address of the first element of this array is stored in
* the ptr_to_servers parameter which you supply. The int result
* is a count of the number of nameservers in the array. The
* maximum value that this will be is MAXNS, defined in netlib:h.resolv
* although this information is of no real concern to the client.
*
* If this function returns zero, then the pointer is indeterminate,
* and it may have been modified. A zero return means that there are
* no nameservers, a situation which is either deliberate (because
* you aren't on the Internet or don't have a DNS server), or you
* are relying on the InetDbase:hosts file to satisfy all requests.
*
* >> NOTE: This is a struct sockaddr_in and NOT struct in_addr.
* >> The structures are used internally in calls to sendto() and
* >> connect() and must therefore be treated as read-only (unless
* >> you deliberately wish to alter the nameservers being used, of
* >> course!)
*
* If you want to change the number of nameservers, then you must
* manipulate _res.nscount directly, and ensure that _res.nscount
* does not exceed MAXNS, and ensure that enough of the struct
* sockaddr_in structures have been setup correctly too. See
* resolv.h for details.
*/
extern int dnsquery_check_nameservers(struct sockaddr_in **);
#ifdef __cplusplus
}
#endif
#endif