通过Uip WebClient 实现中应用DNS解析
Uip WebClient 实现
作者:Changing发表时间:07-27 00:42分类:电子相关2 Comments
前一篇:Uip + Stm32移植问题总结
后一篇:Uip WebServer 实现
#define UIP_CONF_LOGGING 0 //logging off//typedef int uip_tcp_appstate_t; //出错可注释
typedef int uip_udp_appstate_t; //出错可注释/*#include "smtp.h"*/
/*#include "hello-world.h"*/
/*#include "telnetd.h"*/
/*#include "webserver.h"*/
/*#include "dhcpc.h"*/
/*#include "resolv.h"*/
#include "webclient.h" //包含WebClient 文件#include "app_call.h" //加入一个Uip的数据接口文件
#include "stm32f10x.h"
#include "stdio.h"
#include "string.h"#include "uip.h"
#include "uip_arp.h"
#include "tapdev.h"
#include "timer.h"
#include "ENC28J60.h"
#include "SPI.h"#define PRINTF_ON 1#define BUF ((struct uip_eth_hdr *)&uip_buf[0])#ifndef NULL
#define NULL (void *)0
#endif /* NULL */static unsigned char mymac[6] = {0x04,0x02,0x35,0x00,0x00,0x01};void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);int main(void)
{int i;uip_ipaddr_t ipaddr;struct timer periodic_timer, arp_timer;RCC_Configuration();GPIO_Configuration();USART_Configuration();SPInet_Init();timer_set(&periodic_timer, CLOCK_SECOND / 2);timer_set(&arp_timer, CLOCK_SECOND * 10);SysTick_Config(72000); //以太网控制器驱动初始化tapdev_init(mymac);//Uip 协议栈初始化uip_init();
uip_ipaddr(ipaddr, 192, 168, 1, 15); //配置Ipuip_sethostaddr(ipaddr);uip_ipaddr(ipaddr, 192, 168, 1, 1); //配置网关uip_setdraddr(ipaddr);uip_ipaddr(ipaddr, 255, 255, 255, 0); //配置子网掩码uip_setnetmask(ipaddr);webclient_init();resolv_init();uip_ipaddr(ipaddr, 8,8,8,8); //DNS server ,Google DNS Serverresolv_conf(ipaddr);resolv_query("www.ichanging.org");while(1){uip_len = tapdev_read(); //从网卡读取数据if(uip_len > 0) { //如果数据存在则按协议处理if(BUF->type == htons(UIP_ETHTYPE_IP)) { //如果收到的是IP数据,调用uip_input()处理uip_arp_ipin(); uip_input();/* If the above function invocation resulted in data thatshould be sent out on the network, the global variable uip_len is set to a value > 0. */if(uip_len > 0) {uip_arp_out();tapdev_send();}}else if(BUF->type == htons(UIP_ETHTYPE_ARP)){ //如果收到的是ARP数据,调用uip_arp_arpin处理uip_arp_arpin();/* If the above function invocation resulted in data thatshould be sent out on the network, the global variable uip_len is set to a value > 0. */if(uip_len > 0) {tapdev_send();}}}else if(timer_expired(&periodic_timer)){ //查看0.5s是否到了,调用uip_periodic处理TCP超时程序timer_reset(&periodic_timer);for(i = 0; i < UIP_CONNS; i++) {uip_periodic(i);/* If the above function invocation resulted in data thatshould be sent out on the network, the global variable uip_len is set to a value > 0. */if(uip_len > 0) {uip_arp_out();tapdev_send();}}for(i = 0; i < UIP_UDP_CONNS; i++) {uip_udp_periodic(i); //处理udp超时程序/* If the above function invocation resulted in data thatshould be sent out on the network, the global variable uip_len is set to a value > 0. */if(uip_len > 0) {uip_arp_out();tapdev_send();}}/* Call the ARP timer function every 10 seconds. */ //10s到了就处理ARPif(timer_expired(&arp_timer)) {timer_reset(&arp_timer);uip_arp_timer();}}}}/*******************************WebClient Set***************************************/void resolv_found(char *name, u16_t *ipaddr) //DNS 找到对应服务器IP
{//u16_t *ipaddr2;if(ipaddr == NULL) {printf("Host '%s' not found.\n", name);} else {printf("Found name '%s' = %d.%d.%d.%d\n", name,htons(ipaddr[0]) >> 8,htons(ipaddr[0]) & 0xff,htons(ipaddr[1]) >> 8,htons(ipaddr[1]) & 0xff);if(webclient_get("www.ichanging.org", 80, "/index.php")) {printf("the connection was initiated");}else{printf("the host name could not be found in the cache or TCP connection could not be created.");}}
}void webclient_closed(void)
{//printf("Webclient: connection closed\n");
}
void webclient_aborted(void)
{//printf("Webclient: connection aborted\n");
}
void webclient_timedout(void)
{//printf("Webclient: connection timed out\n");
}
void webclient_connected(void)
{//printf("Webclient: connected, waiting for data...\n");
}
void webclient_datahandler(char *data, u16_t len)
{//printf("Webclient: got %d bytes of data.\n", len);
}/*******************************Stm32 Set***************************************/void GPIO_Configuration(void)
{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA , &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA , &GPIO_InitStructure); }void RCC_Configuration(void)
{/* 定义枚举类型变量 HSEStartUpStatus */ErrorStatus HSEStartUpStatus;/* 复位系统时钟设置*/RCC_DeInit();/* 开启HSE*/RCC_HSEConfig(RCC_HSE_ON);/* 等待HSE起振并稳定*/HSEStartUpStatus = RCC_WaitForHSEStartUp();/* 判断HSE起是否振成功,是则进入if()内部 */if(HSEStartUpStatus == SUCCESS){/* 选择HCLK(AHB)时钟源为SYSCLK 1分频 */RCC_HCLKConfig(RCC_SYSCLK_Div1); /* 选择PCLK2时钟源为 HCLK(AHB) 1分频 */RCC_PCLK2Config(RCC_HCLK_Div1); /* 选择PCLK1时钟源为 HCLK(AHB) 2分频 */RCC_PCLK1Config(RCC_HCLK_Div2);/* 设置FLASH延时周期数为2 */FLASH_SetLatency(FLASH_Latency_2);/* 使能FLASH预取缓存 */FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);/* 选择锁相环(PLL)时钟源为HSE 1分频,倍频数为9,则PLL输出频率为 8MHz * 9 = 72MHz */RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);/* 使能PLL */ RCC_PLLCmd(ENABLE);/* 等待PLL输出稳定 */while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);/* 选择SYSCLK时钟源为PLL */RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);/* 等待PLL成为SYSCLK时钟源 */while(RCC_GetSYSCLKSource() != 0x08);} /* 打开APB2总线上的GPIOA时钟*/RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1, ENABLE);}void USART_Configuration(void)
{USART_InitTypeDef USART_InitStructure;USART_ClockInitTypeDef USART_ClockInitStructure;USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;USART_ClockInit(USART1 , &USART_ClockInitStructure);USART_InitStructure.USART_BaudRate = 9600;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;USART_Init(USART1,&USART_InitStructure);USART_Cmd(USART1,ENABLE);
}#if PRINTF_ONint fputc(int ch,FILE *f)
{USART_SendData(USART1,(u8) ch);while(USART_GetFlagStatus(USART1,USART_FLAG_TC) == RESET);return ch;
}#endif
通过Uip WebClient 实现中应用DNS解析相关推荐
- 为何解析浏览器地址参数会为null_request 包中出现 DNS 解析超时的探究
事情的起因是这样的,公司使用自建 dns 服务器,但是有一个致命缺陷,不支持 ipv6 格式的地址解析,而 node 的 DNS 解析默认是同时请求 v4 和 v6 的地址的,这样会导致偶尔在解析 v ...
- 如何在 Windows 10 中刷新 DNS 解析缓存
DNS(域名系统)解析缓存是一个由 Windows 维护的临时数据库,其中包含不最近访问和尝试访问网站和其他Internet域的所有记录. 互联网依靠域名系统(DNS)来维护所有公共网站及其相应 IP ...
- DNS(域名系统)介绍,深入解析DNS解析失败发生的原因及解决方法
域名系统(英文:Domain Name System,缩写:DNS)是互联网的一项服务.它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便地访问互联网.DNS使用TCP和UDP端口53. ...
- pfSense book之DNS解析
pfSense中的DNS解析利用unbound,这是一个验证.递归.缓存DNS解析器,支持DNSSEC和各种选项.当前版本的pfSense默认启用DNS解析. 默认情况下,DNS解析程序不使用在&qu ...
- Linux之高速缓存DNS解析
一.DNS的背景 (1)DNS(Domain Name System,域名系统),万维网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的I ...
- 通过负载均衡器+域名实现容灾切换-(8)基于DNS解析的GSLB在BS架构中应用实践(转)(2)...
================================================================================================= 摘自 ...
- android 自定义dns解析器,Android中DNS解析
当服务端IP变化,大量用户还是访问的以前的IP,连接不上服务器. 我们的客户端软件如何通过域名正确访问服务器?这里面主要涉及到DNS缓存的问题. 什么是DNS? DNS 是域名系统 (Domain N ...
- python socket 域名_Python网络编程中的套接字名和DNS解析。
距离上一次TCP的文章,这一次要讲的是套接字名和DNS,并且还会涉及到网络数据的发送接受和网络错误的发生和处理. 下面说套接字名,在创建和部署每个套接字对象时总共需要做5个主要的决定,主机名和IP地址 ...
- DNS解析过程中不得不知道的那些事
DNS解析过程中不得不知道的那些事 0x01 定义 0x02 域名结构 0x03 DNS查询方式 1.从查询方式分类 2.从查询内容: 0x04 常见的DNS资源记录 1.A/AAAA记录 2.CNA ...
最新文章
- json最大长度限制_GET请求中URL的最大长度限制总结,读完之后,大部分程序员收藏了...
- linux wget 下载文件 报错 To connect to xxxx, use ‘--no-check-certificate’ 解决方法
- Android笔记之FragmentTabHost实现选项卡
- 3.5 mysql备份与恢复
- F-Principle:初探深度学习在计算数学的应用
- 【20181102T2】飞越行星带【智商题+最小瓶颈路】
- 安装完MySQL数据库,在服务列表里找不到MySQL的解决办法
- 正则判断windows文件路径是否正确
- 【转载】Apache如何设置访问一个目录需要密码
- 团队博客-第三周:需求改进系统设计(科利尔拉弗队)
- imx226_IMX226CQJ-海思网络摄像芯片
- .NetCore对接各大财务软件凭证API——金蝶系列(2)
- 三态门有一个信号控制端en_什么是三态门? 三态逻辑与非门电路以及三态门电路...
- python 3维正态分布图_三维正态分布图
- 聊聊新股市盈率的那些事
- glib linux,[转载]linux下glib.h的介绍
- jntoo.php,admin/website.php · 曹琪/shufadasai-englishi - Gitee.com
- cc2530自组网的网络结构是什么?在哪里可以修改
- 8.25 欢乐emmm赛
- 如何对网站排名进行优化?带你深入理解SEO