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

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

?? dns.c

?? NXPl788上lwip的無操作系統移植,基于Embest開發板
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**
 * @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/memp.h"
#include "lwip/dns.h"

#include <string.h>

/** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS(ipaddr)        (ip4_addr_set_u32(ipaddr, ipaddr_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
/** DNS message header */
struct dns_hdr {
  PACK_STRUCT_FIELD(u16_t id);
  PACK_STRUCT_FIELD(u8_t flags1);
  PACK_STRUCT_FIELD(u8_t flags2);
  PACK_STRUCT_FIELD(u16_t numquestions);
  PACK_STRUCT_FIELD(u16_t numanswers);
  PACK_STRUCT_FIELD(u16_t numauthrr);
  PACK_STRUCT_FIELD(u16_t numextrarr);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif
#define SIZEOF_DNS_HDR 12

/** DNS query message structure.
    No packing needed: only used locally on the stack. */
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 cls;
};
#define SIZEOF_DNS_QUERY 4

/** DNS answer message structure.
    No packing needed: only used locally on the stack. */
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 cls;
  u32_t ttl;
  u16_t len;
};
#define SIZEOF_DNS_ANSWER 10

/** 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];
  ip_addr_t ipaddr;
  /* pointer to callback on DNS query done */
  dns_found_callback found;
  void *arg;
};

#if DNS_LOCAL_HOSTLIST

#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
/** Local host-list. For hostnames in this list, no
 *  external name resolution is performed */
static struct local_hostlist_entry *local_hostlist_dynamic;
#else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */

/** Defining this allows the local_hostlist_static to be placed in a different
 * linker section (e.g. FLASH) */
#ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE
#define DNS_LOCAL_HOSTLIST_STORAGE_PRE static
#endif /* DNS_LOCAL_HOSTLIST_STORAGE_PRE */
/** Defining this allows the local_hostlist_static to be placed in a different
 * linker section (e.g. FLASH) */
#ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST
#define DNS_LOCAL_HOSTLIST_STORAGE_POST
#endif /* DNS_LOCAL_HOSTLIST_STORAGE_POST */
DNS_LOCAL_HOSTLIST_STORAGE_PRE struct local_hostlist_entry local_hostlist_static[]
  DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;

#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */

static void dns_init_local();
#endif /* DNS_LOCAL_HOSTLIST */


/* forward declarations */
static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *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 ip_addr_t              dns_servers[DNS_MAX_SERVERS];
/** Contiguous buffer for processing responses */
static u8_t                   dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
static u8_t*                  dns_payload;

/**
 * Initialize the resolver: set up the UDP pcb and configure the default server
 * (DNS_SERVER_ADDRESS).
 */
void
dns_init()
{
  ip_addr_t dnsserver;

  dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
  
  /* initialize default DNS server address */
  DNS_SERVER_ADDRESS(&dnsserver);

  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);
    }
  }
#if DNS_LOCAL_HOSTLIST
  dns_init_local();
#endif
}

/**
 * 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, ip_addr_t *dnsserver)
{
  if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
      (dnsserver != NULL) && !ip_addr_isany(dnsserver)) {
    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.
 */
ip_addr_t
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();
  }
}

#if DNS_LOCAL_HOSTLIST
static void
dns_init_local()
{
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT)
  int i;
  struct local_hostlist_entry *entry;
  /* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
  struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
  size_t namelen;
  for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) {
    struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
    LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
    namelen = strlen(init_entry->name);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜臀va亚洲va欧美va天堂| 亚洲mv在线观看| 91老师国产黑色丝袜在线| 日韩在线一二三区| 国产精品免费观看视频| 91精品国产综合久久香蕉麻豆| 国产高清精品在线| 日本麻豆一区二区三区视频| 国产精品久久久久aaaa| 日韩免费看的电影| 欧美三级日韩三级国产三级| 成人免费毛片嘿嘿连载视频| 日本中文字幕不卡| 亚洲va在线va天堂| 亚洲欧洲精品天堂一级| 精品久久久久久久久久久院品网| 欧美在线视频日韩| 92精品国产成人观看免费 | 一区二区三区在线视频免费观看| 久久综合给合久久狠狠狠97色69| 欧美三区在线观看| 色婷婷精品久久二区二区蜜臂av | 色婷婷国产精品| 国产成人精品影视| 精品亚洲成av人在线观看| 婷婷久久综合九色综合绿巨人 | 国产丝袜在线精品| 日韩视频免费观看高清完整版在线观看| 日本道色综合久久| 99精品视频一区| 99久久久国产精品| 成人国产精品免费网站| 国产精品1区2区| 韩国av一区二区三区| 日韩**一区毛片| 久久国产精品免费| 久久精品国产77777蜜臀| 日本成人超碰在线观看| 日韩精品一二三四| 天天色天天爱天天射综合| 亚洲电影你懂得| 日韩电影免费一区| 麻豆一区二区99久久久久| 免费观看在线综合| 精品在线播放免费| 国产在线精品一区二区三区不卡| 久久成人久久爱| 国产一区不卡在线| 粉嫩一区二区三区性色av| 大尺度一区二区| 91免费版在线| 欧美色中文字幕| 日韩三级.com| 国产视频一区在线观看| 国产精品欧美经典| 亚洲你懂的在线视频| 亚洲一区二区不卡免费| 日韩在线一二三区| 久久国产福利国产秒拍| 国产成人在线看| 色综合久久久久久久久| 欧美日韩一级视频| 精品理论电影在线观看| 国产三级一区二区| 日韩av午夜在线观看| 蜜桃视频在线观看一区二区| 国产一区二区毛片| 色综合久久综合网| 91精品国产丝袜白色高跟鞋| 久久婷婷国产综合精品青草| 国产精品国产三级国产有无不卡| 一区二区三区在线免费视频| 日本 国产 欧美色综合| 国产宾馆实践打屁股91| 欧洲国内综合视频| 欧美精品一区视频| 日韩码欧中文字| 蜜乳av一区二区三区| 国产成人自拍高清视频在线免费播放| 91蝌蚪porny成人天涯| 日韩一级高清毛片| 国产精品国产三级国产aⅴ入口| 亚洲高清一区二区三区| 国产一区二区精品久久99| 色老汉一区二区三区| 精品少妇一区二区三区日产乱码 | 亚洲欧美电影院| 免费日本视频一区| 懂色av噜噜一区二区三区av| 欧美日韩午夜在线| 中文字幕成人av| 偷拍与自拍一区| 99视频在线观看一区三区| 91精品国产综合久久小美女| 亚洲欧洲三级电影| 狠狠色丁香九九婷婷综合五月| 色婷婷狠狠综合| 国产欧美一区二区精品性| 日韩精品高清不卡| 91网站视频在线观看| 精品成a人在线观看| 亚洲一级不卡视频| 99热99精品| 久久精品一区二区三区四区| 午夜成人在线视频| 在线观看日韩高清av| 中文字幕的久久| 国产精品一区二区免费不卡| 国产午夜亚洲精品不卡| 日韩福利电影在线| 欧美日韩精品是欧美日韩精品| 国产精品国产三级国产有无不卡| 国产一区亚洲一区| 日韩免费高清视频| 无吗不卡中文字幕| 欧美日韩国产一级片| 亚洲免费毛片网站| av不卡一区二区三区| 中文一区在线播放| 国产黑丝在线一区二区三区| 欧美大黄免费观看| 蜜臀va亚洲va欧美va天堂| 欧美精品丝袜中出| 亚洲国产综合人成综合网站| 色美美综合视频| 亚洲精品欧美综合四区| 成人精品免费视频| 国产网站一区二区| 国产精品主播直播| 精品国产91亚洲一区二区三区婷婷| 午夜电影一区二区| 欧美一区午夜视频在线观看| 天天色综合天天| 7777女厕盗摄久久久| 日韩一区精品视频| 欧美一区二区三区在| 日韩**一区毛片| 欧美精品一区二区久久婷婷| 另类小说综合欧美亚洲| 欧美大片在线观看一区二区| 精品一区二区在线免费观看| 精品动漫一区二区三区在线观看| 免费三级欧美电影| 久久久无码精品亚洲日韩按摩| 国产黑丝在线一区二区三区| 国产精品午夜春色av| 91丝袜呻吟高潮美腿白嫩在线观看| 中文字幕综合网| 欧美日韩综合一区| 久久精品国产一区二区三| 久久青草国产手机看片福利盒子| 国产高清精品在线| 亚洲激情男女视频| 欧美夫妻性生活| 国产福利精品一区二区| 日本一区二区免费在线观看视频| 成人黄色国产精品网站大全在线免费观看| 国产精品每日更新在线播放网址| 99久久精品国产一区二区三区| 亚洲男帅同性gay1069| 欧美伦理电影网| 国产一区二区久久| 一区av在线播放| 欧美激情一区二区三区蜜桃视频| 色视频成人在线观看免| 青娱乐精品在线视频| 国产亚洲一区二区三区四区 | 不卡的电影网站| 亚洲国产视频在线| 亚洲精品一区二区三区福利| 不卡av电影在线播放| 午夜久久福利影院| 国产日韩v精品一区二区| 色哟哟在线观看一区二区三区| 水蜜桃久久夜色精品一区的特点| 久久先锋影音av| 欧美午夜在线一二页| 国产剧情av麻豆香蕉精品| 亚洲精品国产品国语在线app| 3d成人h动漫网站入口| 成人黄色电影在线| 日韩高清不卡在线| 亚洲丝袜制服诱惑| 精品女同一区二区| 在线观看亚洲精品| 国产老妇另类xxxxx| 亚洲午夜精品网| 国产精品女同互慰在线看| 欧美精品第一页| av中文字幕一区| 久久草av在线| 亚洲国产日韩精品| 国产精品欧美一区喷水| 欧美tk—视频vk| 欧美日韩国产一级片| 色哟哟在线观看一区二区三区| 国产精品一区二区在线观看不卡 | 欧美一区二区三区在线观看视频 | 91福利在线导航| 国产高清久久久久|