@@ -121,7 +121,8 @@ uint8_t* pDNSMSG; // DNS message buffer
121
121
uint8_t DNS_SOCKET ; // SOCKET number for DNS
122
122
uint16_t DNS_MSGID ; // DNS message ID
123
123
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 ;
125
126
126
127
/* converts uint16_t from network buffer to a host byte order integer. */
127
128
uint16_t get16 (uint8_t * s )
@@ -341,7 +342,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
341
342
uint8_t * cp ;
342
343
343
344
msg = pbuf ;
344
- memset (pdhdr , 0 , sizeof (pdhdr ));
345
+ memset (pdhdr , 0 , sizeof (* pdhdr ));
345
346
346
347
pdhdr -> id = get16 (& msg [0 ]);
347
348
tmp = get16 (& msg [2 ]);
@@ -453,7 +454,7 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
453
454
if (len == 0 ) break ;
454
455
455
456
/* Copy component up to (but not including) dot */
456
- strncpy (( char * ) cp , dname , len );
457
+ memcpy ( cp , dname , len );
457
458
cp += len ;
458
459
if (cp1 == NULL )
459
460
{
@@ -483,9 +484,10 @@ int8_t check_DNS_timeout(void)
483
484
{
484
485
static uint8_t retry_count ;
485
486
486
- if (dns_1s_tick >= DNS_WAIT_TIME )
487
+ uint32_t tick = HAL_GetTick ();
488
+ if (tick - hal_sys_tick >= DNS_WAIT_TIME * 1000 )
487
489
{
488
- dns_1s_tick = 0 ;
490
+ hal_sys_tick = tick ;
489
491
if (retry_count >= MAX_DNS_RETRY ) {
490
492
retry_count = 0 ;
491
493
return -1 ; // timeout occurred
@@ -515,6 +517,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
515
517
uint8_t ip [4 ];
516
518
uint16_t len , port ;
517
519
int8_t ret_check_timeout ;
520
+
521
+ hal_sys_tick = HAL_GetTick ();
518
522
519
523
// Socket open
520
524
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)
560
564
// 0 > : failed / 1 - success
561
565
return ret ;
562
566
}
563
-
564
-
565
- /* DNS TIMER HANDLER */
566
- void DNS_time_handler (void )
567
- {
568
- dns_1s_tick ++ ;
569
- }
570
-
571
-
572
-
0 commit comments