Переглянути джерело

[update] sync code from wiznet official.

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>
liuxianliang 5 роки тому
батько
коміт
469f578bdc

+ 2 - 4
ioLibrary/Ethernet/W5500/w5500.h

@@ -917,15 +917,13 @@ extern "C" {
 /**
  * @brief For Berkeley Socket API
  */
-#ifndef SOCK_STREAM
 #define SOCK_STREAM                  Sn_MR_TCP
-#endif
+
 /**
  * @brief For Berkeley Socket API
  */
-#ifndef SOCK_DGRAM
 #define SOCK_DGRAM                   Sn_MR_UDP
-#endif
+
 
 /* Sn_CR values */
 /**

+ 9 - 4
ioLibrary/Ethernet/wizchip_conf.c

@@ -418,10 +418,10 @@ void wizchip_sw_reset(void)
 
 int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
 {
-#if _WIZCHIP_ < W5200	// add condition for w5100
-    int8_t j;
+   int8_t i;
+#if _WIZCHIP_ < W5200
+   int8_t j;
 #endif
-    int8_t i;
    int8_t tmp = 0;
    wizchip_sw_reset();
    if(txsize)
@@ -521,7 +521,12 @@ void wizchip_clrinterrupt(intr_kind intr)
    setIR( ((((uint16_t)ir) << 8) | (((uint16_t)sir) & 0x00FF)) );
 #else
    setIR(ir);
-   setSIR(sir);
+//M20200227 : For clear
+   //setSIR(sir);
+   for(ir=0; ir<8; ir++){
+       if(sir & (0x01 <<ir) ) setSn_IR(ir, 0xff);
+   }
+
 #endif   
 }
 

+ 1 - 1
ioLibrary/Ethernet/wizchip_conf.h

@@ -232,7 +232,7 @@ extern "C" {
 typedef struct __WIZCHIP
 {
    uint16_t  if_mode;               ///< host interface mode
-   uint8_t   id[6];                 ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
+   uint8_t   id[7];                 ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
    /**
     * The set of critical section callback func.
     */

+ 3 - 8
ioLibrary/Ethernet/wizchip_socket.c

@@ -117,6 +117,7 @@ int8_t wizchip_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
             uint32_t taddr;
             getSIPR((uint8_t*)&taddr);
             if(taddr == 0) return SOCKERR_SOCKINIT;
+	    break;
          }
       case Sn_MR_UDP :
       case Sn_MR_MACRAW :
@@ -306,7 +307,6 @@ int8_t wizchip_disconnect(uint8_t sn)
 	{
 	   if(getSn_IR(sn) & Sn_IR_TIMEOUT)
 	   {
-	      setSn_IR(sn, Sn_IR_TIMEOUT);
 	      wizchip_close(sn);
 	      return SOCKERR_TIMEOUT;
 	   }
@@ -344,7 +344,6 @@ int32_t wizchip_send(uint8_t sn, uint8_t * buf, uint16_t len)
       }
       else if(tmp & Sn_IR_TIMEOUT)
       {
-         setSn_IR(sn, Sn_IR_TIMEOUT);
          wizchip_close(sn);
          return SOCKERR_TIMEOUT;
       }
@@ -425,10 +424,6 @@ int32_t wizchip_recv(uint8_t sn, uint8_t * buf, uint16_t len)
             else
             {
                wizchip_close(sn);
-               if(recvsize != 0)
-               { 
-                   break;
-               } 		    
                return SOCKERR_SOCKSTATUS;
             }
          }
@@ -716,7 +711,7 @@ int32_t wizchip_recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr
    			if(sock_remained_size[sn] > 1514) 
    			{
    			    wizchip_close(sn);
-   			    return SOCKFATAL_PACKLEN;
+   			   return SOCKFATAL_PACKLEN;
    			}
    			sock_pack_info[sn] = PACK_FIRST;
    	   }
@@ -864,7 +859,7 @@ int8_t  wizchip_setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
          		}
             }
          break;
-   #if _WIZCHIP_ > 5200
+   #if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
       case SO_KEEPALIVEAUTO:
          CHECK_SOCKMODE(Sn_MR_TCP);
          setSn_KPALVTR(sn,*(uint8_t*)arg);

+ 1 - 1
ioLibrary/Ethernet/wizchip_socket.h

@@ -390,7 +390,7 @@ typedef enum
    SO_DESTPORT,         ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
 #if _WIZCHIP_ != 5100   
    SO_KEEPALIVESEND,    ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
-   #if _WIZCHIP_ > 5200   
+   #if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
       SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200
    #endif      
 #endif

+ 58 - 21
ioLibrary/Internet/DHCP/wizchip_dhcp.c

@@ -2,10 +2,11 @@
 //
 //! \file wizchip_dhcp.c
 //! \brief DHCP APIs implement file.
-//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
-//! \version 1.1.0
-//! \date 2013/11/18
+//! \details Processing DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
+//! \version 1.1.1
+//! \date 2019/10/08
 //! \par  Revision history
+//!       <2019/10/08> compare DHCP server ip address
 //!       <2013/11/18> 1st Release
 //!       <2012/12/20> V1.1.0
 //!         1. Optimize code
@@ -52,7 +53,7 @@
 #include <wizchip_socket.h>
 #include "DHCP/wizchip_dhcp.h"
 
-/* If you want to display debug & procssing message, Define _DHCP_DEBUG_ in dhcp.h */
+/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */
 
 #ifdef _DHCP_DEBUG_
    #include <stdio.h>
@@ -65,7 +66,7 @@
 #define STATE_DHCP_LEASED        3        ///< ReceiveD ACK and IP leased
 #define STATE_DHCP_REREQUEST     4        ///< send REQUEST for maintaining leased IP
 #define STATE_DHCP_RELEASE       5        ///< No use
-#define STATE_DHCP_STOP          6        ///< Stop procssing DHCP
+#define STATE_DHCP_STOP          6        ///< Stop processing DHCP
 
 #define DHCP_FLAGSBROADCAST      0x8000   ///< The broadcast value of flags in @ref RIP_MSG 
 #define DHCP_FLAGSUNICAST        0x0000   ///< The unicast   value of flags in @ref RIP_MSG
@@ -192,6 +193,7 @@ typedef struct {
 uint8_t DHCP_SOCKET;                      // Socket number for DHCP
 
 uint8_t DHCP_SIP[4];                      // DHCP Server IP address
+uint8_t DHCP_REAL_SIP[4];                 // For extract my DHCP server in a few DHCP server
 
 // Network information from DHCP Server
 uint8_t OLD_allocated_ip[4]   = {0, };    // Previous IP address
@@ -245,7 +247,7 @@ int8_t   check_DHCP_leasedIP(void);
 /* check the timeout in DHCP process */
 uint8_t  check_DHCP_timeout(void);
 
-/* Intialize to timeout process.  */
+/* Initialize to timeout process.  */
 void     reset_DHCP_timeout(void);
 
 /* Parse message as OFFER and ACK and NACK from DHCP server.*/
@@ -259,7 +261,7 @@ void default_ip_assign(void)
    setGAR (DHCP_allocated_gw);
 }
 
-/* The default handler of ip chaged */
+/* The default handler of ip changed */
 void default_ip_update(void)
 {
 	/* WIZchip Software Reset */
@@ -269,7 +271,7 @@ void default_ip_update(void)
    setSHAR(DHCP_CHADDR);
 }
 
-/* The default handler of ip chaged */
+/* The default handler of ip changed */
 void default_ip_conflict(void)
 {
 	// WIZchip Software Reset
@@ -356,8 +358,16 @@ void send_DHCP_DISCOVER(void)
 	uint16_t k = 0;
    
    makeDHCPMSG();
-
-   k = 4;     // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
+   DHCP_SIP[0]=0;
+   DHCP_SIP[1]=0;
+   DHCP_SIP[2]=0;
+   DHCP_SIP[3]=0;
+   DHCP_REAL_SIP[0]=0;
+   DHCP_REAL_SIP[1]=0;
+   DHCP_REAL_SIP[2]=0;
+   DHCP_REAL_SIP[3]=0;
+
+   k = 4;     // because MAGIC_COOKIE already made by makeDHCPMSG()
    
 	// Option Request Param
 	pDHCPMSG->OPT[k++] = dhcpMessageType;
@@ -380,10 +390,13 @@ void send_DHCP_DISCOVER(void)
 	pDHCPMSG->OPT[k++] = 0;          // fill zero length of hostname 
 	for(i = 0 ; HOST_NAME[i] != 0; i++)
    	pDHCPMSG->OPT[k++] = HOST_NAME[i];
-	pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
-	pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
-	pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
-	pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4); 
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4); 
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4); 
+	pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
+	pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
 
 	pDHCPMSG->OPT[k++] = dhcpParamRequest;
 	pDHCPMSG->OPT[k++] = 0x06;	// length of request
@@ -440,7 +453,7 @@ void send_DHCP_REQUEST(void)
    	ip[3] = 255;   	   	   	
    }
    
-   k = 4;      // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
+   k = 4;      // because MAGIC_COOKIE already made by makeDHCPMSG()
 	
 	// Option Request Param.
 	pDHCPMSG->OPT[k++] = dhcpMessageType;
@@ -518,7 +531,7 @@ void send_DHCP_DECLINE(void)
 	
 	makeDHCPMSG();
 
-   k = 4;      // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
+   k = 4;      // because MAGIC_COOKIE already made by makeDHCPMSG()
    
 	*((uint8_t*)(&pDHCPMSG->flags))   = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
 	*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
@@ -578,7 +591,7 @@ int8_t parseDHCPMSG(void)
 
 	uint8_t * p;
 	uint8_t * e;
-	uint8_t type;
+	uint8_t type = 0;
 	uint8_t opt_len;
    
    if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
@@ -594,8 +607,23 @@ int8_t parseDHCPMSG(void)
 		if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
 		     (pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
 		     (pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5])   )
+		{
+#ifdef _DHCP_DEBUG_
+            printf("No My DHCP Message. This message is ignored.\r\n");
+#endif
          return 0;
-      type = 0;
+		}
+        //compare DHCP server ip address
+        if((DHCP_SIP[0]!=0) || (DHCP_SIP[1]!=0) || (DHCP_SIP[2]!=0) || (DHCP_SIP[3]!=0)){
+            if( ((svr_addr[0]!=DHCP_SIP[0])|| (svr_addr[1]!=DHCP_SIP[1])|| (svr_addr[2]!=DHCP_SIP[2])|| (svr_addr[3]!=DHCP_SIP[3])) &&
+                ((svr_addr[0]!=DHCP_REAL_SIP[0])|| (svr_addr[1]!=DHCP_REAL_SIP[1])|| (svr_addr[2]!=DHCP_REAL_SIP[2])|| (svr_addr[3]!=DHCP_REAL_SIP[3]))  )
+            {
+#ifdef _DHCP_DEBUG_
+                printf("Another DHCP sever send a response message. This is ignored.\r\n");
+#endif
+                return 0;
+            }
+        }
 		p = (uint8_t *)(&pDHCPMSG->op);
 		p = p + 240;      // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
 		e = p + (len - 240);
@@ -659,6 +687,10 @@ int8_t parseDHCPMSG(void)
    				DHCP_SIP[1] = *p++;
    				DHCP_SIP[2] = *p++;
    				DHCP_SIP[3] = *p++;
+                DHCP_REAL_SIP[0]=svr_addr[0];
+                DHCP_REAL_SIP[1]=svr_addr[1];
+                DHCP_REAL_SIP[2]=svr_addr[2];
+                DHCP_REAL_SIP[3]=svr_addr[3];
    				break;
    			default :
    				p++;
@@ -901,7 +933,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
    getSHAR(DHCP_CHADDR);
    if((DHCP_CHADDR[0] | DHCP_CHADDR[1]  | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
    {
-      // assing temporary mac address, you should be set SHAR before call this function. 
+      // assigning temporary mac address, you should be set SHAR before call this function. 
       DHCP_CHADDR[0] = 0x00;
       DHCP_CHADDR[1] = 0x08;
       DHCP_CHADDR[2] = 0xdc;      
@@ -914,7 +946,12 @@ void DHCP_init(uint8_t s, uint8_t * buf)
 	DHCP_SOCKET = s; // SOCK_DHCP
 	pDHCPMSG = (RIP_MSG*)buf;
 	DHCP_XID = 0x12345678;
-
+	{
+		DHCP_XID += DHCP_CHADDR[3];
+		DHCP_XID += DHCP_CHADDR[4];
+		DHCP_XID += DHCP_CHADDR[5];
+		DHCP_XID += (DHCP_CHADDR[3] ^ DHCP_CHADDR[4] ^ DHCP_CHADDR[5]);
+	}
 	// WIZchip Netinfo Clear
 	setSIPR(zeroip);
 	setGAR(zeroip);
@@ -924,7 +961,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
 }
 
 
-/* Rset the DHCP timeout count and retry count. */
+/* Reset the DHCP timeout count and retry count. */
 void reset_DHCP_timeout(void)
 {
 	dhcp_tick_1s = 0;

+ 14 - 14
ioLibrary/Internet/DHCP/wizchip_dhcp.h

@@ -3,9 +3,10 @@
 //! \file wizchip_dhcp.h
 //! \brief DHCP APIs Header file.
 //! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
-//! \version 1.1.0
-//! \date 2013/11/18
+//! \version 1.1.1
+//! \date 2019/10/08
 //! \par  Revision history
+//!       <2019/10/08> compare DHCP server ip address
 //!       <2013/11/18> 1st Release
 //!       <2012/12/20> V1.1.0
 //!         1. Move unreferenced DEFINE to dhcp.c
@@ -50,16 +51,15 @@ extern "C" {
 
 /*
  * @brief 
- * @details If you want to display debug & procssing message, Define _DHCP_DEBUG_ 
- * @note    If defined, it dependens on <stdio.h>
+ * @details If you want to display debug & processing message, Define _DHCP_DEBUG_ 
+ * @note    If defined, it depends on <stdio.h>
  */
 //#define _DHCP_DEBUG_
 
 
 /* Retry to processing DHCP */
-#define	MAX_DHCP_RETRY          2        ///< Maxium retry count
-/* WIZnet package change DHCP timeout */
-#define	DHCP_WAIT_TIME          1       ///< Wait Time 1s
+#define	MAX_DHCP_RETRY          2        ///< Maximum retry count
+#define	DHCP_WAIT_TIME          10       ///< Wait Time 10s
 
 
 /* UDP port numbers for DHCP */
@@ -76,18 +76,18 @@ extern "C" {
  */
 enum
 {
-   DHCP_FAILED = 0,  ///< Procssing Fail
-   DHCP_RUNNING,     ///< Procssing DHCP proctocol
+   DHCP_FAILED = 0,  ///< Processing Fail
+   DHCP_RUNNING,     ///< Processing DHCP protocol
    DHCP_IP_ASSIGN,   ///< First Occupy IP from DHPC server      (if cbfunc == null, act as default default_ip_assign)
    DHCP_IP_CHANGED,  ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
    DHCP_IP_LEASED,   ///< Stand by 
-   DHCP_STOPPED      ///< Stop procssing DHCP protocol
+   DHCP_STOPPED      ///< Stop processing DHCP protocol
 };
 
 /*
  * @brief DHCP client initialization (outside of the main loop)
  * @param s   - socket number
- * @param buf - buffer for procssing DHCP message
+ * @param buf - buffer for processing DHCP message
  */
 void DHCP_init(uint8_t s, uint8_t * buf);
 
@@ -101,7 +101,7 @@ void DHCP_time_handler(void);
  * @brief Register call back function 
  * @param ip_assign   - callback func when IP is assigned from DHCP server first
  * @param ip_update   - callback func when IP is changed
- * @prarm ip_conflict - callback func when the assigned IP is conflict with others.
+ * @param ip_conflict - callback func when the assigned IP is conflict with others.
  */
 void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
 
@@ -120,7 +120,7 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
 uint8_t DHCP_run(void);
 
 /*
- * @brief Stop DHCP procssing
+ * @brief Stop DHCP processing
  * @note If you want to restart. call DHCP_init() and DHCP_run()
  */ 
 void    DHCP_stop(void);
@@ -149,7 +149,7 @@ void getDNSfromDHCP(uint8_t* ip);
 
 /*
  * @brief Get the leased time by DHCP sever
- * @retrun unit 1s
+ * @return unit 1s
  */
 uint32_t getDHCPLeasetime(void);
 

+ 25 - 28
ioLibrary/Internet/DNS/wizchip_dns.c

@@ -21,30 +21,30 @@
 //!
 //! 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. 
+//!
+//! 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. 
-//! 
+//! 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 
+//! 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 
+//! 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 
+//! 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.
 //
 //*****************************************************************************
@@ -328,9 +328,9 @@ uint8_t * dns_answer(uint8_t * msg, uint8_t * cp, uint8_t * ip_from_dns)
  * Arguments   : dhdr - is a pointer to the header for DNS message
  *               buf  - is a pointer to the reply message.
  *               len  - is the size of reply message.
- * Returns     : -1 - Domain name lenght is too big 
+ * Returns     : -1 - Domain name lenght is too big
  *                0 - Fail (Timout or parse error)
- *                1 - Success, 
+ *                1 - Success,
  */
 int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
 {
@@ -368,7 +368,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
 	{
 		cp = dns_question(msg, cp);
    #ifdef _DNS_DEUBG_
-      printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
+      printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
    #endif
 		if(!cp) return -1;
 	}
@@ -378,7 +378,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
 	{
 		cp = dns_answer(msg, cp, ip_from_dns);
    #ifdef _DNS_DEUBG_
-      printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
+      printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
    #endif
 		if(!cp) return -1;
 	}
@@ -509,14 +509,14 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
 
 	retry_count = 0;
 	dns_1s_tick = 0;
-   
+
    // Socket open
    wizchip_socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
 
 #ifdef _DNS_DEBUG_
 	printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
 #endif
-   
+
 	len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE);
 	wizchip_sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
 
@@ -562,6 +562,3 @@ void DNS_time_handler(void)
 {
 	dns_1s_tick++;
 }
-
-
-

+ 2 - 2
ioLibrary/Internet/DNS/wizchip_dns.h

@@ -62,13 +62,13 @@ extern "C" {
  */
 //#define _DNS_DEBUG_
 
-#define	MAX_DNS_BUF_SIZE	512		///< maximum size of DNS buffer. */
+#define	MAX_DNS_BUF_SIZE	256		///< maximum size of DNS buffer. */
 /*
  * @brief Maxium length of your queried Domain name 
  * @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1)
  * @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
  */
-#define  MAX_DOMAIN_NAME   512       // for example "www.google.com"
+#define  MAX_DOMAIN_NAME   16       // for example "www.google.com"
 
 #define	MAX_DNS_RETRY     2        ///< Requery Count
 #define	DNS_WAIT_TIME     3        ///< Wait response time. unit 1s.