io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
Data Structures | Macros | Functions | Variables
dns.c File Reference

DNS APIs Implement file. More...

#include <string.h>
#include <stdlib.h>
#include "socket.h"
#include "dns.h"

Go to the source code of this file.

Data Structures

struct  dhdr
 

Macros

#define INITRTT   2000L /* Initial smoothed response time */
 
#define MAXCNAME   (MAX_DOMAIN_NAME + (MAX_DOMAIN_NAME>>1)) /* Maximum amount of cname recursion */
 
#define TYPE_A   1 /* Host address */
 
#define TYPE_NS   2 /* Name server */
 
#define TYPE_MD   3 /* Mail destination (obsolete) */
 
#define TYPE_MF   4 /* Mail forwarder (obsolete) */
 
#define TYPE_CNAME   5 /* Canonical name */
 
#define TYPE_SOA   6 /* Start of Authority */
 
#define TYPE_MB   7 /* Mailbox name (experimental) */
 
#define TYPE_MG   8 /* Mail group member (experimental) */
 
#define TYPE_MR   9 /* Mail rename name (experimental) */
 
#define TYPE_NULL   10 /* Null (experimental) */
 
#define TYPE_WKS   11 /* Well-known sockets */
 
#define TYPE_PTR   12 /* Pointer record */
 
#define TYPE_HINFO   13 /* Host information */
 
#define TYPE_MINFO   14 /* Mailbox information (experimental)*/
 
#define TYPE_MX   15 /* Mail exchanger */
 
#define TYPE_TXT   16 /* Text strings */
 
#define TYPE_AAAA   28
 
#define TYPE_ANY   255 /* Matches any type */
 
#define CLASS_IN   1 /* The ARPA Internet */
 
#define AGAIN   8 /* Average RTT gain = 1/8 */
 
#define LAGAIN   3 /* Log2(AGAIN) */
 
#define DGAIN   4 /* Mean deviation gain = 1/4 */
 
#define LDGAIN   2 /* log2(DGAIN) */
 
#define QUERY   0
 
#define RESPONSE   1
 
#define IQUERY   1
 
#define NO_ERROR   0
 
#define FORMAT_ERROR   1
 
#define SERVER_FAIL   2
 
#define NAME_ERROR   3
 
#define NOT_IMPL   4
 
#define REFUSED   5
 

Functions

uint16_t get16 (uint8_t *s)
 
uint8_t * put16 (uint8_t *s, uint16_t i)
 
int parse_name (uint8_t *msg, uint8_t *compressed, char *buf, int16_t len)
 
uint8_t * dns_question (uint8_t *msg, uint8_t *cp)
 
uint8_t * dns_answer (uint8_t *msg, uint8_t *cp, uint8_t *ip_from_dns)
 
int8_t parseDNSMSG (struct dhdr *pdhdr, uint8_t *pbuf, uint8_t *ip_from_dns)
 
int16_t dns_makequery (uint16_t op, char *name, uint8_t *buf, uint16_t len, uint8_t type)
 
int8_t check_DNS_timeout (void)
 
void DNS_init (uint8_t *buf)
 
int8_t DNS_run (uint8_t s, uint8_t *dns_ip, uint8_t *name, uint8_t *ip_from_dns, uint8_t mode)
 
void DNS_time_handler (void)
 

Variables

uint8_t * pDNSMSG
 
uint8_t DNS_SOCKET
 
uint16_t DNS_MSGID
 
uint32_t dns_1s_tick
 
uint8_t IP_TYPE
 

Detailed Description

DNS APIs Implement file.

Send DNS query & Receive DNS reponse.
It depends on stdlib.h & string.h in ansi-c library

Version
1.1.0
Date
2013/11/18
Revision history
<2013/10/21> 1st Release <2013/12/20> V1.1.0 1. Remove secondary DNS server in DNS_run If 1st DNS_run failed, call DNS_run with 2nd DNS again 2. DNS_timerHandler -> DNS_time_handler 3. Remove the unused define 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c <2013/12/20> V1.1.0
Author
Eric Jung & MidnightCow

Copyright (c) 2013, WIZnet Co., LTD. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file dns.c.

Macro Definition Documentation

◆ INITRTT

#define INITRTT   2000L /* Initial smoothed response time */

Definition at line 62 of file dns.c.

◆ MAXCNAME

#define MAXCNAME   (MAX_DOMAIN_NAME + (MAX_DOMAIN_NAME>>1)) /* Maximum amount of cname recursion */

Definition at line 63 of file dns.c.

◆ TYPE_A

#define TYPE_A   1 /* Host address */

Definition at line 65 of file dns.c.

◆ TYPE_NS

#define TYPE_NS   2 /* Name server */

Definition at line 66 of file dns.c.

◆ TYPE_MD

#define TYPE_MD   3 /* Mail destination (obsolete) */

Definition at line 67 of file dns.c.

◆ TYPE_MF

#define TYPE_MF   4 /* Mail forwarder (obsolete) */

Definition at line 68 of file dns.c.

◆ TYPE_CNAME

#define TYPE_CNAME   5 /* Canonical name */

Definition at line 69 of file dns.c.

◆ TYPE_SOA

#define TYPE_SOA   6 /* Start of Authority */

Definition at line 70 of file dns.c.

◆ TYPE_MB

#define TYPE_MB   7 /* Mailbox name (experimental) */

Definition at line 71 of file dns.c.

◆ TYPE_MG

#define TYPE_MG   8 /* Mail group member (experimental) */

Definition at line 72 of file dns.c.

◆ TYPE_MR

#define TYPE_MR   9 /* Mail rename name (experimental) */

Definition at line 73 of file dns.c.

◆ TYPE_NULL

#define TYPE_NULL   10 /* Null (experimental) */

Definition at line 74 of file dns.c.

◆ TYPE_WKS

#define TYPE_WKS   11 /* Well-known sockets */

Definition at line 75 of file dns.c.

◆ TYPE_PTR

#define TYPE_PTR   12 /* Pointer record */

Definition at line 76 of file dns.c.

◆ TYPE_HINFO

#define TYPE_HINFO   13 /* Host information */

Definition at line 77 of file dns.c.

◆ TYPE_MINFO

#define TYPE_MINFO   14 /* Mailbox information (experimental)*/

Definition at line 78 of file dns.c.

◆ TYPE_MX

#define TYPE_MX   15 /* Mail exchanger */

Definition at line 79 of file dns.c.

◆ TYPE_TXT

#define TYPE_TXT   16 /* Text strings */

Definition at line 80 of file dns.c.

◆ TYPE_AAAA

#define TYPE_AAAA   28

Definition at line 81 of file dns.c.

◆ TYPE_ANY

#define TYPE_ANY   255 /* Matches any type */

Definition at line 82 of file dns.c.

◆ CLASS_IN

#define CLASS_IN   1 /* The ARPA Internet */

Definition at line 84 of file dns.c.

◆ AGAIN

#define AGAIN   8 /* Average RTT gain = 1/8 */

Definition at line 87 of file dns.c.

◆ LAGAIN

#define LAGAIN   3 /* Log2(AGAIN) */

Definition at line 88 of file dns.c.

◆ DGAIN

#define DGAIN   4 /* Mean deviation gain = 1/4 */

Definition at line 89 of file dns.c.

◆ LDGAIN

#define LDGAIN   2 /* log2(DGAIN) */

Definition at line 90 of file dns.c.

◆ QUERY

#define QUERY   0

Definition at line 97 of file dns.c.

◆ RESPONSE

#define RESPONSE   1

Definition at line 98 of file dns.c.

◆ IQUERY

#define IQUERY   1

Definition at line 100 of file dns.c.

◆ NO_ERROR

#define NO_ERROR   0

Definition at line 106 of file dns.c.

◆ FORMAT_ERROR

#define FORMAT_ERROR   1

Definition at line 107 of file dns.c.

◆ SERVER_FAIL

#define SERVER_FAIL   2

Definition at line 108 of file dns.c.

◆ NAME_ERROR

#define NAME_ERROR   3

Definition at line 109 of file dns.c.

◆ NOT_IMPL

#define NOT_IMPL   4

Definition at line 110 of file dns.c.

◆ REFUSED

#define REFUSED   5

Definition at line 111 of file dns.c.

Function Documentation

◆ get16()

uint16_t get16 ( uint8_t *  s)

Definition at line 127 of file dns.c.

Referenced by dns_answer(), and parseDNSMSG().

◆ put16()

uint8_t* put16 ( uint8_t *  s,
uint16_t  i 
)

Definition at line 136 of file dns.c.

Referenced by dns_makequery().

◆ parse_name()

int parse_name ( uint8_t *  msg,
uint8_t *  compressed,
char *  buf,
int16_t  len 
)

Definition at line 154 of file dns.c.

Referenced by dns_answer(), and dns_question().

◆ dns_question()

uint8_t* dns_question ( uint8_t *  msg,
uint8_t *  cp 
)

Definition at line 215 of file dns.c.

References MAXCNAME, and parse_name().

Referenced by parseDNSMSG().

◆ dns_answer()

uint8_t* dns_answer ( uint8_t *  msg,
uint8_t *  cp,
uint8_t *  ip_from_dns 
)

◆ parseDNSMSG()

int8_t parseDNSMSG ( struct dhdr pdhdr,
uint8_t *  pbuf,
uint8_t *  ip_from_dns 
)

◆ dns_makequery()

int16_t dns_makequery ( uint16_t  op,
char *  name,
uint8_t *  buf,
uint16_t  len,
uint8_t  type 
)

Definition at line 433 of file dns.c.

References DNS_MSGID, IP_TYPE, MAXCNAME, and put16().

◆ check_DNS_timeout()

int8_t check_DNS_timeout ( void  )

Definition at line 498 of file dns.c.

References dns_1s_tick, and DNS_WAIT_TIME.

◆ DNS_init()

void DNS_init ( uint8_t *  buf)

Definition at line 518 of file dns.c.

References DNS_MSG_ID, DNS_MSGID, and pDNSMSG.

◆ DNS_run()

int8_t DNS_run ( uint8_t  s,
uint8_t *  dns_ip,
uint8_t *  name,
uint8_t *  ip_from_dns,
uint8_t  mode 
)

Definition at line 526 of file dns.c.

◆ DNS_time_handler()

void DNS_time_handler ( void  )

Definition at line 594 of file dns.c.

References dns_1s_tick.

Variable Documentation

◆ pDNSMSG

uint8_t* pDNSMSG

Definition at line 119 of file dns.c.

Referenced by DNS_init().

◆ DNS_SOCKET

uint8_t DNS_SOCKET

Definition at line 120 of file dns.c.

◆ DNS_MSGID

uint16_t DNS_MSGID

Definition at line 121 of file dns.c.

Referenced by DNS_init(), and dns_makequery().

◆ dns_1s_tick

uint32_t dns_1s_tick

Definition at line 123 of file dns.c.

Referenced by check_DNS_timeout(), and DNS_time_handler().

◆ IP_TYPE

uint8_t IP_TYPE

Referenced by dns_makequery().