亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dns.c

?? 在luminary平臺下移植lwip到freertos,集成開發環境KEIL
?? C
?? 第 1 頁 / 共 2 頁
字號:
/**
 * @file
 * DNS - host name to IP address resolver.
 *
 */

/**

 * This file implements a DNS host name to IP address resolver.

 * Port to lwIP from uIP
 * by Jim Pettinato April 2007

 * uIP version Copyright (c) 2002-2003, Adam Dunkels.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 * DNS.C
 *
 * The lwIP DNS resolver functions are used to lookup a host name and
 * map it to a numerical IP address. It maintains a list of resolved
 * hostnames that can be queried with the dns_lookup() function.
 * New hostnames can be resolved using the dns_query() function.
 *
 * The lwIP version of the resolver also adds a non-blocking version of
 * gethostbyname() that will work with a raw API application. This function
 * checks for an IP address string first and converts it if it is valid.
 * gethostbyname() then does a dns_lookup() to see if the name is 
 * already in the table. If so, the IP is returned. If not, a query is 
 * issued and the function returns with a ERR_INPROGRESS status. The app
 * using the dns client must then go into a waiting state.
 *
 * Once a hostname has been resolved (or found to be non-existent),
 * the resolver code calls a specified callback function (which 
 * must be implemented by the module that uses the resolver).
 */

/*-----------------------------------------------------------------------------
 * RFC 1035 - Domain names - implementation and specification
 * RFC 2181 - Clarifications to the DNS Specification
 *----------------------------------------------------------------------------*/

/** @todo: define good default values (rfc compliance) */
/** @todo: improve answer parsing, more checkings... */
/** @todo: check RFC1035 - 7.3. Processing responses */

/*-----------------------------------------------------------------------------
 * Includes
 *----------------------------------------------------------------------------*/

#include "lwip/opt.h"

#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */

#include "lwip/udp.h"
#include "lwip/mem.h"
#include "lwip/dns.h"

#include <string.h>

/** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS        inet_addr("208.67.222.222") /* resolver1.opendns.com */
#endif

/** DNS server port address */
#ifndef DNS_SERVER_PORT
#define DNS_SERVER_PORT           53
#endif

/** DNS maximum number of retries when asking for a name, before "timeout". */
#ifndef DNS_MAX_RETRIES
#define DNS_MAX_RETRIES           4
#endif

/** DNS resource record max. TTL (one week as default) */
#ifndef DNS_MAX_TTL
#define DNS_MAX_TTL               604800
#endif

/* DNS protocol flags */
#define DNS_FLAG1_RESPONSE        0x80
#define DNS_FLAG1_OPCODE_STATUS   0x10
#define DNS_FLAG1_OPCODE_INVERSE  0x08
#define DNS_FLAG1_OPCODE_STANDARD 0x00
#define DNS_FLAG1_AUTHORATIVE     0x04
#define DNS_FLAG1_TRUNC           0x02
#define DNS_FLAG1_RD              0x01
#define DNS_FLAG2_RA              0x80
#define DNS_FLAG2_ERR_MASK        0x0f
#define DNS_FLAG2_ERR_NONE        0x00
#define DNS_FLAG2_ERR_NAME        0x03

/* DNS protocol states */
#define DNS_STATE_UNUSED          0
#define DNS_STATE_NEW             1
#define DNS_STATE_ASKING          2
#define DNS_STATE_DONE            3

#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
#if (defined(__MWERKS__)  || defined(__CWCC__))
	#pragma options align= packed
#endif
/** DNS message header */
struct dns_hdr {
  u16_t id;
  u8_t flags1;
  u8_t flags2;
  u16_t numquestions;
  u16_t numanswers;
  u16_t numauthrr;
  u16_t numextrarr;
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif

#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
#if (defined(__MWERKS__)  || defined(__CWCC__))
	#pragma options align= packed
#endif
/** DNS query message structure */
struct dns_query {
  /* DNS query record starts with either a domain name or a pointer
     to a name already present somewhere in the packet. */
  u16_t type;
  u16_t class;
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif

#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
#if (defined(__MWERKS__)  || defined(__CWCC__))
	#pragma options align= packed
#endif
/** DNS answer message structure */
struct dns_answer {
  /* DNS answer record starts with either a domain name or a pointer
     to a name already present somewhere in the packet. */
  u16_t type;
  u16_t class;
  u32_t ttl;
  u16_t len;
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif

/** DNS table entry */
struct dns_table_entry {
  u8_t  state;
  u8_t  numdns;
  u8_t  tmr;
  u8_t  retries;
  u8_t  seqno;
  u8_t  err;
  u32_t ttl;
  char name[DNS_MAX_NAME_LENGTH];
  struct ip_addr ipaddr;
  /* pointer to callback on DNS query done */
  dns_found_callback found;
  void *arg;
};


/* forward declarations */
static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
static void dns_check_entries(void);

/*-----------------------------------------------------------------------------
 * Globales
 *----------------------------------------------------------------------------*/

/* DNS variables */
static struct udp_pcb        *dns_pcb;
static u8_t                   dns_seqno;
static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
static struct ip_addr         dns_servers[DNS_MAX_SERVERS];

#if (DNS_USES_STATIC_BUF == 1)
static u8_t                   dns_payload[DNS_MSG_SIZE];
#endif /* (DNS_USES_STATIC_BUF == 1) */

/**
 * Initialize the resolver: set up the UDP pcb and configure the default server
 * (DNS_SERVER_ADDRESS).
 */
void
dns_init()
{
  struct ip_addr dnsserver;
  
  /* initialize default DNS server address */
  dnsserver.addr = DNS_SERVER_ADDRESS;

  LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n"));

  /* if dns client not yet initialized... */
  if (dns_pcb == NULL) {
    dns_pcb = udp_new();

    if (dns_pcb != NULL) {
      /* initialize DNS table not needed (initialized to zero since it is a
       * global variable) */
      LWIP_ASSERT("For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
        DNS_STATE_UNUSED == 0);

      /* initialize DNS client */
      udp_bind(dns_pcb, IP_ADDR_ANY, 0);
      udp_recv(dns_pcb, dns_recv, NULL);

      /* initialize default DNS primary server */
      dns_setserver(0, &dnsserver);
    }
  }
}

/**
 * Initialize one of the DNS servers.
 *
 * @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
 * @param dnsserver IP address of the DNS server to set
 */
void
dns_setserver(u8_t numdns, struct ip_addr *dnsserver)
{
  if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
      (dnsserver != NULL) && (dnsserver->addr !=0 )) {
    dns_servers[numdns] = (*dnsserver);
  }
}

/**
 * Obtain one of the currently configured DNS server.
 *
 * @param numdns the index of the DNS server
 * @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
 *         server has not been configured.
 */
struct ip_addr
dns_getserver(u8_t numdns)
{
  if (numdns < DNS_MAX_SERVERS) {
    return dns_servers[numdns];
  } else {
    return *IP_ADDR_ANY;
  }
}

/**
 * The DNS resolver client timer - handle retries and timeouts and should
 * be called every DNS_TMR_INTERVAL milliseconds (every second by default).
 */
void
dns_tmr(void)
{
  if (dns_pcb != NULL) {
    LWIP_DEBUGF(DNS_DEBUG, ("dns_tmr: dns_check_entries\n"));
    dns_check_entries();
  }
}

/**
 * Look up a hostname in the array of known hostnames.
 *
 * @note This function only looks in the internal array of known
 * hostnames, it does not send out a query for the hostname if none
 * was found. The function dns_enqueue() can be used to send a query
 * for a hostname.
 *
 * @param name the hostname to look up
 * @return the hostname's IP address, as u32_t (instead of struct ip_addr to
 *         better check for failure: != 0) or 0 if the hostname was not found
 *         in the cached dns_table.
 */
static u32_t
dns_lookup(const char *name)
{
  u8_t i;

  /* Walk through name list, return entry if found. If not, return NULL. */
  for (i = 0; i < DNS_TABLE_SIZE; ++i) {
    if ((dns_table[i].state == DNS_STATE_DONE) &&
        (strcmp(name, dns_table[i].name) == 0)) {
      LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
      ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
      LWIP_DEBUGF(DNS_DEBUG, ("\n"));
      return dns_table[i].ipaddr.addr;
    }
  }

  return 0;
}

#if DNS_DOES_NAME_CHECK
/**
 * Compare the "dotted" name "query" with the encoded name "response"
 * to make sure an answer from the DNS server matches the current dns_table
 * entry (otherwise, answers might arrive late for hostname not on the list
 * any more).
 *
 * @param query hostname (not encoded) from the dns_table
 * @param response encoded hostname in the DNS response
 * @return 0: names equal; 1: names differ
 */
static u8_t
dns_compare_name(unsigned char *query, unsigned char *response)
{
  unsigned char n;

  do {
    n = *response++;
    /** @see RFC 1035 - 4.1.4. Message compression */
    if ((n & 0xc0) == 0xc0) {
      /* Compressed name */
      break;
    } else {
      /* Not compressed name */
      while (n > 0) {
        if ((*query) != (*response)) {
          return 1;
        }
        ++response;
        ++query;
        --n;
      };
      ++query;
    }
  } while (*response != 0);

  return 0;
}
#endif /* DNS_DOES_NAME_CHECK */

/**
 * Walk through a compact encoded DNS name and return the end of the name.
 *
 * @param query encoded DNS name in the DNS server response
 * @return end of the name
 */
static unsigned char *
dns_parse_name(unsigned char *query)
{
  unsigned char n;

  do {
    n = *query++;
    /** @see RFC 1035 - 4.1.4. Message compression */
    if ((n & 0xc0) == 0xc0) {
      /* Compressed name */
      break;
    } else {
      /* Not compressed name */
      while (n > 0) {
        ++query;
        --n;
      };
    }
  } while (*query != 0);

  return query + 1;
}

/**
 * Send a DNS query packet.
 *
 * @param numdns index of the DNS server in the dns_servers table
 * @param name hostname to query
 * @param id index of the hostname in dns_table, used as transaction ID in the
 *        DNS query packet
 * @return ERR_OK if packet is sent; an err_t indicating the problem otherwise
 */
static err_t
dns_send(u8_t numdns, const char* name, u8_t id)
{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美亚洲免费在线一区| 久久先锋资源网| 久久精品一区四区| 一区二区三区不卡在线观看 | 国产成人精品一区二区三区网站观看| 不卡av在线免费观看| 日韩视频永久免费| 亚洲成人午夜影院| 99久久国产综合精品色伊| 日韩精品资源二区在线| 亚洲一区精品在线| 91蜜桃网址入口| 国产欧美日韩不卡| 久久精品国产一区二区| 欧美日韩综合在线| 亚洲综合视频在线| 在线中文字幕一区| 国产精品久久久久一区| 国产一区不卡视频| 精品国产乱码久久久久久久 | 亚洲欧美日韩在线| 国产成人av电影在线播放| 欧美mv日韩mv| 韩国在线一区二区| 日韩欧美中文字幕公布| 五月天亚洲婷婷| 欧美浪妇xxxx高跟鞋交| 偷拍一区二区三区四区| 欧美日韩黄色一区二区| 性欧美疯狂xxxxbbbb| 欧美三级视频在线播放| 亚洲成人高清在线| 欧美一区二区在线不卡| 青青草原综合久久大伊人精品优势 | 麻豆久久久久久| 国产69精品久久777的优势| 久久久久99精品国产片| 国产精品一区二区在线观看网站| 精品av综合导航| 国产乱理伦片在线观看夜一区| 精品欧美久久久| 粉嫩久久99精品久久久久久夜| 国产精品乱人伦中文| 91一区二区三区在线观看| 亚洲男人的天堂在线aⅴ视频| 色域天天综合网| 五月激情丁香一区二区三区| 91精品黄色片免费大全| 精品在线观看视频| 欧美国产综合一区二区| 91丨porny丨在线| 午夜精品久久久久影视| 欧美精品一区二区三区视频 | 欧美日韩一级黄| 蜜臀av一级做a爰片久久| 久久久亚洲精品石原莉奈| 成人激情免费网站| 亚洲成人1区2区| 久久久www成人免费毛片麻豆| 不卡电影一区二区三区| 午夜精品视频一区| 久久久不卡网国产精品一区| 99久久免费精品高清特色大片| 亚洲一区二区在线免费观看视频 | 精品系列免费在线观看| 国产精品欧美久久久久无广告 | 91在线国产福利| 欧美96一区二区免费视频| 26uuu国产一区二区三区| 色综合天天天天做夜夜夜夜做| 午夜久久久久久| 国产欧美综合在线| 欧美情侣在线播放| 成人av在线一区二区| 亚洲成人资源在线| 国产精品美女久久久久久久久久久| 精品视频一区二区三区免费| 国产伦理精品不卡| 一区二区三区自拍| 国产日产欧美一区| 91麻豆精品国产91久久久资源速度| 福利电影一区二区| 麻豆国产一区二区| 一区二区在线电影| 国产精品―色哟哟| 亚洲精品一区二区三区影院| 日本道色综合久久| 不卡一区中文字幕| 国产毛片精品视频| 日本欧美久久久久免费播放网| 樱花影视一区二区| 国产欧美日韩三区| 26uuu亚洲综合色| 这里只有精品电影| 欧美午夜精品免费| 99在线热播精品免费| 国产老妇另类xxxxx| 麻豆久久一区二区| 视频在线在亚洲| 水野朝阳av一区二区三区| 亚洲视频中文字幕| 国产精品国产三级国产有无不卡 | 亚洲精品日产精品乱码不卡| 国产欧美日韩激情| 2024国产精品| 日韩一区二区影院| 91精品国产品国语在线不卡| 欧美中文字幕亚洲一区二区va在线 | 欧美日韩国产欧美日美国产精品| 91在线视频免费观看| 99久久婷婷国产综合精品| 福利91精品一区二区三区| 国产成人免费av在线| 丰满放荡岳乱妇91ww| 成人污污视频在线观看| 成人午夜精品在线| 成人综合日日夜夜| 波多野洁衣一区| 一本色道久久综合狠狠躁的推荐| 91视频国产观看| 欧洲精品视频在线观看| 日本乱人伦一区| 欧美日韩激情一区二区三区| 欧美精品视频www在线观看| 7777精品伊人久久久大香线蕉经典版下载 | 国产精品国产三级国产普通话三级 | 亚洲国产欧美一区二区三区丁香婷| 一区二区三区精密机械公司| 亚洲国产视频a| 日本成人在线网站| 经典三级一区二区| 不卡电影一区二区三区| 在线区一区二视频| 日韩一级二级三级| 欧美经典一区二区| 亚洲人成人一区二区在线观看| 亚洲国产一区二区视频| 捆绑调教美女网站视频一区| 国产一区二区三区免费播放| 高清不卡一区二区| 色婷婷亚洲精品| 欧美成人艳星乳罩| 18欧美亚洲精品| 男人的天堂亚洲一区| 国产**成人网毛片九色 | 国产亚洲欧美色| 亚洲女人小视频在线观看| 亚洲bt欧美bt精品| 国产成人在线视频播放| 91麻豆国产自产在线观看| 7777精品久久久大香线蕉| 久久久亚洲国产美女国产盗摄| 亚洲图片你懂的| 国模大尺度一区二区三区| eeuss鲁片一区二区三区 | 国产精品美女久久久久久2018| 一区二区三区在线影院| 久久福利视频一区二区| 色综合久久久久久久久久久| 日韩欧美国产午夜精品| 亚洲欧美一区二区三区极速播放 | 偷拍与自拍一区| 99久久婷婷国产| 精品久久久久久最新网址| 亚洲已满18点击进入久久| 成人网在线免费视频| 日韩欧美国产午夜精品| 亚洲色图欧美偷拍| 精品在线观看视频| 777奇米成人网| 亚洲一级二级在线| www.日韩精品| 久久久无码精品亚洲日韩按摩| 丝瓜av网站精品一区二区| 91免费观看视频在线| 久久久久青草大香线综合精品| 日韩国产在线观看一区| 91美女在线视频| 国产精品乱子久久久久| 国产精品自拍网站| 精品播放一区二区| 久久国产综合精品| 欧美喷水一区二区| 亚洲小说欧美激情另类| av毛片久久久久**hd| 亚洲国产精品精华液ab| 精品一区二区日韩| 日韩欧美视频在线| 九色综合狠狠综合久久| 日韩精品一区二区三区在线观看| 五月激情丁香一区二区三区| 欧美综合在线视频| 亚洲电影视频在线| 欧美老女人在线| 日韩影院在线观看| 制服丝袜av成人在线看| 人人精品人人爱| 日韩欧美电影一区| 久久66热偷产精品| 精品少妇一区二区三区免费观看|