標題:
W5500實現(xiàn)DNS域名解析STM32源碼
[打印本頁]
作者:
563093271
時間:
2017-5-24 11:32
標題:
W5500實現(xiàn)DNS域名解析STM32源碼
W5500 dns 域名解析
0.png
(65 KB, 下載次數(shù): 98)
下載附件
2017-5-24 15:10 上傳
單片機源程序如下:
/**
******************************************************************************
* @file main.c
* $Author: 飛鴻踏雪 $
* $Revision: 17 $
* $Date:: 2014-10-25 11:16:48 +0800 #$
* @brief 主函數(shù).
******************************************************************************
* @attention
*
*<h3><center>© Copyright 2009-2012, EmbedNet</center>
*<center>All Rights Reserved</center></h3>
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "delay.h"
#include "spi.h"
#include "socket.h" // Just include one header for WIZCHIP
#include "Internet/DNS/dns.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define _MAIN_DEBUG_
#define SOCK_DNS 0
#define DATA_BUF_SIZE 2048
/* Private macro -------------------------------------------------------------*/
uint8_t gDATABUF[DATA_BUF_SIZE];
// Default Network Configuration
wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd},
.ip = {192, 168, 1, 123},
.sn = {255,255,255,0},
.gw = {192, 168, 1, 1},
.dns = {8,8,8,8},
.dhcp = NETINFO_STATIC };
uint8_t DNS_2nd[4] = {192, 168, 1, 1}; // Secondary DNS server IP
uint8_t Domain_name[] = "www點embed-net點com"; // for Example domain name
uint8_t Domain_IP[4] = {0}; // Translated IP address by DNS
volatile uint32_t msTicks; /* counts 100ms timeTicks */
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void platform_init(void); // initialize the dependent host peripheral
void network_init(void);
/*****************************************************************************
* @brief SysTickIntHandler
* Interrupt Service Routine for system tick counter
*****************************************************************************/
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
// SHOULD BE Added DNS Timer Handler your 1s tick timer
if((msTicks % 1000) == 0){
DNS_time_handler();
}
}
/**
* @brief 串口打印輸出
* @param None
* @retval None
*/
int main(void)
{
int8_t ret;
uint8_t tmp;
uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
//Host dependent peripheral initialized
platform_init();
// First of all, Should register SPI callback functions implemented by user for accessing WIZCHIP
/* Critical section callback */
reg_wizchip_cris_cbfunc(SPI_CrisEnter, SPI_CrisExit); //注冊臨界區(qū)函數(shù)
/* Chip selection call back */
#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_
reg_wizchip_cs_cbfunc(SPI_CS_Select, SPI_CS_Deselect);//注冊SPI片選信號函數(shù)
#elif _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_
reg_wizchip_cs_cbfunc(SPI_CS_Select, SPI_CS_Deselect); // CS must be tried with LOW.
#else
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
#error "Unknown _WIZCHIP_IO_MODE_"
#else
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
#endif
#endif
/* SPI Read & Write callback function */
reg_wizchip_spi_cbfunc(SPI_ReadByte, SPI_WriteByte); //注冊讀寫函數(shù)
/* WIZCHIP SOCKET Buffer initialize */
if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1){
printf("WIZCHIP Initialized fail.\r\n");
while(1);
}
/* PHY link status check */
do{
if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1){
printf("Unknown PHY Link stauts.\r\n");
}
}while(tmp == PHY_LINK_OFF);
/* Network initialization */
network_init(); // Static netinfo setting
/************************************************/
/* WIZnet W5500 Code Examples : */
/* Implemented using ioLibrary_BSD Socket APIs */
/************************************************/
/* >> DNS Client */
/************************************************/
#ifdef _MAIN_DEBUG_
printf("\r\n=== DNS Client Example ===============\r\n");
printf("> DNS 1st : %d.%d.%d.%d\r\n", gWIZNETINFO.dns[0], gWIZNETINFO.dns[1], gWIZNETINFO.dns[2], gWIZNETINFO.dns[3]);
printf("> DNS 2nd : %d.%d.%d.%d\r\n", DNS_2nd[0], DNS_2nd[1], DNS_2nd[2], DNS_2nd[3]);
printf("======================================\r\n");
printf("> Example Domain Name : %s\r\n", Domain_name);
#endif
/* DNS client initialization */
DNS_init(SOCK_DNS, gDATABUF);
/* DNS procssing */
if ((ret = DNS_run(gWIZNETINFO.dns, Domain_name, Domain_IP)) > 0) // try to 1st DNS
{
#ifdef _MAIN_DEBUG_
printf("> 1st DNS Reponsed\r\n");
#endif
}
else if ((ret != -1) && ((ret = DNS_run(DNS_2nd, Domain_name, Domain_IP))>0)) // retry to 2nd DNS
{
#ifdef _MAIN_DEBUG_
printf("> 2nd DNS Reponsed\r\n");
#endif
}
else if(ret == -1)
{
#ifdef _MAIN_DEBUG_
printf("> MAX_DOMAIN_NAME is too small. Should be redefined it.\r\n");
#endif
}
else
{
#ifdef _MAIN_DEBUG_
printf("> DNS Failed\r\n");
#endif
}
if(ret > 0)
{
#ifdef _MAIN_DEBUG_
printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],Domain_IP[1],Domain_IP[2],Domain_IP[3]);
#endif
//
// TO DO
//
}
/* Main Loop */
while(1)
{
}
} // end of main()
/**
* @brief Loopback Test Example Code using ioLibrary_BSD
* @retval None
*/
void platform_init(void)
{
SystemInit();//系統(tǒng)時鐘初始化
USART_Configuration();//串口1初始化
printf("\x0c");printf("\x0c");//超級終端清屏
printf("\033[1;40;32m");//設(shè)置超級終端背景為黑色,字符為綠色
printf("\r\n*******************************************************************************");
printf("\r\n************************ Copyright 2009-2014, EmbedNet ************************");
printf("\r\n*************************** www點embed-net點com **************************");
printf("\r\n***************************** All Rights Reserved *****************************");
printf("\r\n*******************************************************************************");
printf("\r\n");
//Config SPI
SPI_Configuration();
//滴答定時器初始化
SysTick_Config(72000000 / 1000);//1ms
}
/******************************************************************************
* @brief Network Init
* Intialize the network information to be used in WIZCHIP
*****************************************************************************/
void network_init(void)
{
#ifdef _MAIN_DEBUG_
uint8_t tmpstr[6] = {0,};
wiz_NetInfo netinfo;
#endif
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
stm32_w5500_dns (1).zip
(779.32 KB, 下載次數(shù): 114)
2017-5-24 11:31 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
chifen
時間:
2017-7-23 13:23
謝謝
作者:
csgtli
時間:
2017-11-13 16:02
已下載,非常感謝
作者:
某小韓
時間:
2018-4-6 23:07
不錯,非常感謝
作者:
幽夢軒
時間:
2018-8-14 12:16
學習一下
作者:
jh3zr
時間:
2018-8-14 12:49
學習學習
作者:
djk0125
時間:
2018-10-1 01:59
謝謝啦!正好用到
作者:
Absio
時間:
2019-4-10 07:04
感謝感謝
作者:
jemery1030
時間:
2019-8-26 13:51
感謝分享
作者:
jianfeii
時間:
2019-9-24 19:08
這個實現(xiàn)dns解析,應該需要路由支持解吧,不然自己怎么獲取/.?
作者:
de34r
時間:
2019-9-25 08:18
感謝分享
作者:
星星之火可以燎
時間:
2019-11-12 16:57
支持樓主
作者:
jianfeii
時間:
2020-4-30 16:27
建議用原廠新版的代碼,優(yōu)化了很多
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1