@@ -121,7 +121,8 @@ uint8_t* pDNSMSG; // DNS message buffer
121121uint8_t DNS_SOCKET ; // SOCKET number for DNS
122122uint16_t DNS_MSGID ; // DNS message ID
123123
124- uint32_t dns_1s_tick ; // SecTick counter for DNS process timeout
124+ extern uint32_t HAL_GetTick (void );
125+ uint32_t hal_sys_tick ;
125126
126127/* converts uint16_t from network buffer to a host byte order integer. */
127128uint16_t get16 (uint8_t * s )
@@ -341,7 +342,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
341342 uint8_t * cp ;
342343
343344 msg = pbuf ;
344- memset (pdhdr , 0 , sizeof (pdhdr ));
345+ memset (pdhdr , 0 , sizeof (* pdhdr ));
345346
346347 pdhdr -> id = get16 (& msg [0 ]);
347348 tmp = get16 (& msg [2 ]);
@@ -453,7 +454,7 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
453454 if (len == 0 ) break ;
454455
455456 /* Copy component up to (but not including) dot */
456- strncpy (( char * ) cp , dname , len );
457+ memcpy ( cp , dname , len );
457458 cp += len ;
458459 if (cp1 == NULL )
459460 {
@@ -483,9 +484,10 @@ int8_t check_DNS_timeout(void)
483484{
484485 static uint8_t retry_count ;
485486
486- if (dns_1s_tick >= DNS_WAIT_TIME )
487+ uint32_t tick = HAL_GetTick ();
488+ if (tick - hal_sys_tick >= DNS_WAIT_TIME * 1000 )
487489 {
488- dns_1s_tick = 0 ;
490+ hal_sys_tick = tick ;
489491 if (retry_count >= MAX_DNS_RETRY ) {
490492 retry_count = 0 ;
491493 return -1 ; // timeout occurred
@@ -515,6 +517,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
515517 uint8_t ip [4 ];
516518 uint16_t len , port ;
517519 int8_t ret_check_timeout ;
520+
521+ hal_sys_tick = HAL_GetTick ();
518522
519523 // Socket open
520524 socket (DNS_SOCKET , Sn_MR_UDP , 0 , 0 );
@@ -560,13 +564,3 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
560564 // 0 > : failed / 1 - success
561565 return ret ;
562566}
563-
564-
565- /* DNS TIMER HANDLER */
566- void DNS_time_handler (void )
567- {
568- dns_1s_tick ++ ;
569- }
570-
571-
572-
0 commit comments