标题:
W5500实现DNS域名解析STM32源码
[打印本页]
作者:
563093271
时间:
2017-5-24 11:32
标题:
W5500实现DNS域名解析STM32源码
W5500 dns 域名解析
0.png
(65 KB, 下载次数: 98)
下载附件
2017-5-24 15:10 上传
单片机源程序如下:
/**
******************************************************************************
* @file main.c
* $Author: 飞鸿踏雪 $
* $Revision: 17 $
* $Date:: 2014-10-25 11:16:48 +0800 #$
* @brief 主函数.
******************************************************************************
* @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); //注册临界区函数
/* Chip selection call back */
#if _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_
reg_wizchip_cs_cbfunc(SPI_CS_Select, SPI_CS_Deselect);//注册SPI片选信号函数
#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); //注册读写函数
/* 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();//系统时钟初始化
USART_Configuration();//串口1初始化
printf("\x0c");printf("\x0c");//超级终端清屏
printf("\033[1;40;32m");//设置超级终端背景为黑色,字符为绿色
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, 下载次数: 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
这个实现dns解析,应该需要路由支持解吧,不然自己怎么获取/.?
作者:
de34r
时间:
2019-9-25 08:18
感谢分享
作者:
星星之火可以燎
时间:
2019-11-12 16:57
支持楼主
作者:
jianfeii
时间:
2020-4-30 16:27
建议用原厂新版的代码,优化了很多
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1