Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/dns/dns.c File Reference


Detailed Description

Author:
Version:
1.0
Date:
10.10.2002
Bug:
Warning:
Todo:
OpenTCP DNS client implementation. API functions, data structures and constants may be found in inet/dns/dns.h

Definition in file dns.c.

Go to the source code of this file.

Functions

void dns_init (void)
 Initialize resources needed for the DNS client.

void dns_retransmit (void)
 Retransmits requests towards the DNS server.

void dns_run (void)
 DNS client main loop.

INT32 dns_eventlistener (INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen)
 DNS client event listener.

UINT8 get_host_by_name (UINT8 *host_name_ptr, void(*listener)(UINT8, UINT32))
 Invokes DNS resolver.


Variables

UINT8 dns_state
UINT8 dns_socket
UINT8 dns_timer
UINT8 dns_retries
UINT32 dns_tmp_ip
UINT8 * dns_hostptr


Function Documentation

void dns_init void   
 

Author:
Date:
10.10.2002
Invoke this function at startup to properly initialize DNS resources.

Definition at line 108 of file dns.c.

References dns_eventlistener(), dns_socket, dns_state, dns_timer, DNS_UDP_PORT, get_timer(), udp_getsocket(), udp_open(), UDP_OPT_CHECK_CS, and UDP_OPT_SEND_CS.

void dns_retransmit void   
 

Author:
Date:
10.10.2002
This is internal function and IS NOT INTENDED to be invoked by the user application. It simply checks if retransmissions should be done (when retransmissions not used yet) and if yes, sends one. Otherwise timeout error is sent to the event listener.

Definition at line 142 of file dns.c.

References DNS_ERROR_TIMEOUT, DNS_EVENT_ERROR, dns_hostptr, DNS_RESEND_PERIOD, dns_retries, dns_state, dns_timer, get_host_by_name(), init_timer(), and TIMERTIC.

Referenced by dns_eventlistener(), and dns_run().

void dns_run void   
 

Author:
Date:
10.10.2002
Simple main loop that checks whether DNS requests should be sent or not (based on timer timeout). If yes, and DNS is in appropriate state, dns_retransmit() function is invoked.

Definition at line 168 of file dns.c.

References check_timer(), dns_retransmit(), dns_state, and dns_timer.

INT32 dns_eventlistener INT8    cbhandle,
UINT8    event,
UINT32    ipaddr,
UINT16    port,
UINT16    buffindex,
UINT16    datalen
 

Author:
Date:
10.10.2002
Parameters:
cbhandle  handle of the socket this packet is intended for.
event  event that is notified. For UDP, only UDP_EVENT_DATA.
ipaddr  IP address of remote host who sent the UDP datagram
port  port number of remote host who sent the UDP datagram
buffindex  buffer index in RTL8019AS
Returns:
  • - 1 - error in processing
  • 0 - DNS reply successfully processed
Note:
  • Event listeners are NOT to be invoked directly. They are callback functions invoked by the TCP/IP stack to notify events.
This, of course, is where responses from DNS server are processed and checked whether they contain the IP address we requested or if they contain authorative name server to which we should proceed.

If we received the IP address we requested, DNS_EVENT_SUCCESS is reported to application DNS event listener. Otherwise DNS_EVENT_ERROR is reported.

Definition at line 205 of file dns.c.

References DNS_ERROR_GENERAL, DNS_EVENT_ERROR, DNS_EVENT_SUCCESS, dns_hostptr, dns_retransmit(), dns_socket, dns_state, dns_tmp_ip, RECEIVE_NETWORK_B, and UDP_EVENT_DATA.

Referenced by dns_init().

UINT8 get_host_by_name UINT8 *    host_name_ptr,
void(*    listener)(UINT8, UINT32)
 

Author:
Date:
10.10.2002
Parameters:
host_name_ptr  Pointer to null-terminated host name to be resolved
listener  Pointer to DNS listener function that listens to events from DNS client. This function takes two parameters: first one can take a value of DNS_EVENT_SUCCESS or DNS_EVENT_ERROR and thus determine the meaning of the second parameter. If first parameter is DNS_EVENT_SUCCESS, second parameter represents requested IP address. In case of DNS_EVENT_ERROR, second parameter can be one of the: DNS_ERROR_FORMAT, DNS_ERROR_SERVER_FAILURE, DNS_ERROR_NAME_ERROR, DNS_ERROR_NOT_IMPLEMENTED, DNS_ERROR_REFUSED, DNS_ERROR_TIMEOUT, DNS_ERROR_GENERAL
Returns:
  • DNS_ERROR_BUSY - Signals that DNS is currently processing another request so it is not possible to process a new one
  • DNS_ERROR_OVERFLOW - Network transmit buffer too small to hold DNS request
  • DNS_ERROR_LABEL - Label in host name longer than 63 bytes. Error
  • DNS_ERROR_NAME - Host name longer than 264 bytes. Error
Invoke this function to start name-resolving process. Note that currently DNS client can process only one request at a time and will not allow multiple requests.

Definition at line 445 of file dns.c.

References DNS_ERROR_BUSY, dns_hostptr, DNS_NUM_RETRIES, DNS_RESEND_PERIOD, dns_retries, DNS_SERVER_IP, dns_socket, dns_state, dns_timer, dns_tmp_ip, DNS_UDP_PORT, init_timer(), NETWORK_TX_BUFFER_SIZE, RESET_SYSTEM, TIMERTIC, UDP_APP_OFFSET, and udp_send().

Referenced by dns_retransmit().


Variable Documentation

UINT8 dns_state
 

Current DNS state. Used to prevent multiple requests, issue retransmissions,... See DNS_STATE_* for possible values.

Definition at line 88 of file dns.c.

Referenced by dns_eventlistener(), dns_init(), dns_retransmit(), dns_run(), and get_host_by_name().

UINT8 dns_socket
 

UDP socket used by the DNS resolver

Definition at line 89 of file dns.c.

Referenced by dns_eventlistener(), dns_init(), and get_host_by_name().

UINT8 dns_timer
 

DNS timer handle used for retransmissions

Definition at line 90 of file dns.c.

Referenced by dns_init(), dns_retransmit(), dns_run(), and get_host_by_name().

UINT8 dns_retries
 

DNS retry counter used for detecting timeouts

Definition at line 91 of file dns.c.

Referenced by dns_retransmit(), and get_host_by_name().

UINT32 dns_tmp_ip
 

Used in many ways: as an IP address holder, for issuing requests to authorative name servers,..

Definition at line 93 of file dns.c.

Referenced by dns_eventlistener(), and get_host_by_name().

UINT8* dns_hostptr
 

Pointer to hostname that is beeing resolved. Needed for retransmissions.

Definition at line 95 of file dns.c.

Referenced by dns_eventlistener(), dns_retransmit(), and get_host_by_name().


Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by doxygen1.2.18