Watt-32 tcp/ip  2.2 dev-rel.10
Functions | Variables
pcdns.c File Reference

Go to the source code of this file.

Functions

 int (W32_CALL *_resolve_hook)(void) = NULL
 
static void query_init (struct DNS_query *q, BOOL is_ip6)
 Initialise the query header and clear the alternate addr-list.
 
static void store_alt_address (const void *data, int idx, BOOL is_ip6)
 Remember alternate address in dom_a?list[].
 
static int pack_domain (BYTE *dst, const char *src)
 Pack a regular text string into a packed domain name, suitable for the name server. More...
 
static int send_query (sock_type *sock, struct DNS_query *q, const char *name, DWORD towho, WORD qtype)
 Put together a domain lookup packet and send it. More...
 
static __inline int count_paths (const char *path_str)
 
static __inline const char * get_path (const char *path_str, int which_one)
 
static void extract_cname (const struct DNS_query *q, const char *src, char *dest, size_t max)
 Extract the CNAME from a resource record.
 
static int unpack_domain (const struct DNS_query *q, const BYTE *src, size_t src_size, BYTE *dst, size_t dst_size)
 Unpack a received compressed domain name. More...
 
static int read_response (const struct DNS_query *q, int len, WORD qtype, void *addr)
 Extract the IPv4/v6 address from a response message (A or AAAA record). More...
 
static __inline BOOL legal_ident (WORD id, const WORD *cache, int num)
 
static int lookup_domain (struct DNS_query *q, const char *mname, BOOL add_dom, DWORD nameserver, BOOL *timedout, BOOL is_aaaa, void *addr)
 DOMAIN based name lookup. More...
 
static const char * next_domain (const char *domain, int count)
 Given domain and count = 0,1,2,..., return next larger domain or NULL when no more are available.
 
static const char * server_error (enum DNS_serv_resp err)
 Return text for server-side errors.
 
static const char * client_error (enum DNS_client_code err)
 Return text for client-side errors.
 
const char *W32_CALL dom_strerror (int err)
 Return text for error code (dom_errno).
 
char *W32_CALL dom_remove_dot (char *name)
 
DWORD W32_CALL resolve (const char *name)
 Convert host name to an address. More...
 
int W32_CALL resolve_ip6 (const char *name, void *addr)
 

Variables

BOOL called_from_resolve = FALSE
 Hacks to make gethostbyname() and resolve() cooperate.
 
BOOL called_from_ghbn = FALSE
 
char defaultdomain [MAX_HOSTLEN+1] = "your.domain.com"
 The 2 next variables are loaded from WATTCP.CFG file.
 
char * def_domain = defaultdomain
 
BOOL _resolve_exit
 
BOOL _resolve_timeout
 
BOOL from_windns
 
DWORD dom_ttl
 
int dom_errno
 
char dom_cname [MAX_HOSTLEN+1]
 
DWORD def_nameservers [MAX_NAMESERVERS]
 
WORD last_nameserver = 0
 
WORD dns_timeout = 0
 
BOOL dns_recurse = TRUE
 
BOOL dns_do_ipv6 = TRUE
 
BOOL dns_do_idna = FALSE
 
WORD dns_windns = 0
 
static const char * loc_domain
 
static DWORD res_timeout
 
DWORD dom_a4list [MAX_ADDRESSES+1]
 
ip6_address dom_a6list [MAX_ADDRESSES+1]
 

Detailed Description

Domain Name Server protocol.

This portion of the code needs some major work. I ported it (read STOLE IT) from NCSA and lost about half the code somewhere in the process.

Version
0.6
Date
Mar 19, 2004 - Added ACE encoding/decoding of international domain names. Ref. RFC-3490.
Version
0.5
Date
Aug 20, 2003 - Added storing of CNAME record (used as alias in gethostbyname, gethostbyaddr)
Version
0.4
Date
Aug 04, 2002 - Rewritten for IPv6 support (DTYPE_AAAA)
Version
0.3
Date
Jun 16, 1997 - calling usr_yield (i.e. system_yield) while resolving
Version
0.2
Date
Apr 24, 1991 - use substring portions of domain
Version
0.1
Date
Mar 18, 1991 - improved the trailing domain list
Version
0.0
Date
Feb 19, 1991 - pirated by Erick Engelke
Version
-1.0 - NCSA code

Definition in file pcdns.c.

Function Documentation

static int lookup_domain ( struct DNS_query q,
const char *  mname,
BOOL  add_dom,
DWORD  nameserver,
BOOL *  timedout,
BOOL  is_aaaa,
void addr 
)
static

DOMAIN based name lookup.

Query a domain name server to get an IP number Returns the machine number of the machine record for future reference. Events generated will have this number tagged with them. Returns various negative numbers on error conditions.

if add_dom is nonzero, add default domain.

Definition at line 490 of file pcdns.c.

References _watt_cbroke, chk_timeout(), dom_strerror(), IDNA_convert_from_ACE(), IDNA_convert_to_ACE(), Random(), read_response(), send_query(), sock_close(), sock_dataready(), sock_fastread(), and tcp_tick().

static int pack_domain ( BYTE *  dst,
const char *  src 
)
static

Pack a regular text string into a packed domain name, suitable for the name server.

Returns length or -1 if a labellength is > 63.

Definition at line 148 of file pcdns.c.

static int read_response ( const struct DNS_query q,
int  len,
WORD  qtype,
void addr 
)
static

Extract the IPv4/v6 address from a response message (A or AAAA record).

Returns 0 on fail and sets appropriate status code in `dom_errno'. Returns 1 if okay and if the ip is available, Read upto len bytes from reply.

Note: Our query is echoed in the answer, but 'q' below is not same as we sent in send_query().

Definition at line 368 of file pcdns.c.

References extract_cname(), store_alt_address(), and unpack_domain().

DWORD W32_CALL resolve ( const char *  name)

Convert host name to an address.

Returns 0 if name is unresolvable right now. Return value is host-order.

Definition at line 775 of file pcdns.c.

References aton(), called_from_resolve, dom_strerror(), isaddr(), lookup_domain(), my_ip_addr, next_domain(), query_init(), rip(), and set_timeout().

static int send_query ( sock_type sock,
struct DNS_query q,
const char *  name,
DWORD  towho,
WORD  qtype 
)
static

Put together a domain lookup packet and send it.

Uses port DOM_DST_PORT (53).

Definition at line 197 of file pcdns.c.

References pack_domain(), sock_write(), and udp_open().

static int unpack_domain ( const struct DNS_query q,
const BYTE *  src,
size_t  src_size,
BYTE *  dst,
size_t  dst_size 
)
static

Unpack a received compressed domain name.

Handles pointers to continuation domain names.

  • address of query response ('q') is used as the base for the offset of any pointer which is present.
  • returns the number of bytes at 'src' which should be skipped over. Includes the 0-terminator in its length count.
  • returns -1 if the response is munged.

Definition at line 314 of file pcdns.c.