亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
午夜久久久久久电影| 欧美日韩免费视频| 91高清视频在线| 2023国产精品自拍| 亚洲午夜在线视频| 国产成人精品1024| 欧美精品少妇一区二区三区 | 日韩成人免费看| 成人精品小蝌蚪| 精品少妇一区二区三区日产乱码| 亚洲精品网站在线观看| 精品一区二区精品| 欧美一区二区三区视频免费播放 | 国产白丝网站精品污在线入口| 在线免费观看日本一区| 久久久久久久久久美女| 日韩二区在线观看| 欧美日免费三级在线| 最新中文字幕一区二区三区| 精品亚洲国内自在自线福利| 欧美一区二区三区在线电影| 夜夜精品视频一区二区| av在线不卡网| 国产精品丝袜一区| 国产成人精品综合在线观看| 精品美女被调教视频大全网站| 奇米综合一区二区三区精品视频 | 亚洲视频狠狠干| 成人av高清在线| 国产精品私房写真福利视频| 国产精品一区三区| 欧美国产日韩一二三区| 成人免费视频caoporn| 精品国产欧美一区二区| 日本成人在线一区| 91精品国产全国免费观看 | 17c精品麻豆一区二区免费| 国产成人在线影院| 国产性做久久久久久| 国产精品一区免费在线观看| 欧美激情中文不卡| 欧美变态口味重另类| 久久国产福利国产秒拍| 日本aⅴ免费视频一区二区三区| 欧美情侣在线播放| 免费在线一区观看| 日韩欧美的一区二区| 久久99在线观看| 国产丝袜欧美中文另类| 不卡一卡二卡三乱码免费网站| 一色屋精品亚洲香蕉网站| 99久久久精品| 午夜在线成人av| 精品国产欧美一区二区| 懂色av一区二区在线播放| 日韩毛片精品高清免费| 欧美精品一卡二卡| 国产一区二区三区免费看| 国产精品美女一区二区三区| 色偷偷久久人人79超碰人人澡| 亚洲福中文字幕伊人影院| 日韩精品中文字幕一区| 成人18精品视频| 视频一区视频二区中文| 久久蜜桃av一区二区天堂 | 极品瑜伽女神91| 国产精品欧美一区二区三区| 91国偷自产一区二区开放时间| 美女一区二区久久| 亚洲少妇屁股交4| 日韩一级免费观看| 91蝌蚪porny| 国产一区二区三区久久久| 亚洲欧美偷拍卡通变态| 亚洲精品一区二区三区在线观看| av在线一区二区| 精品一区免费av| 亚洲美女免费在线| 久久精品一二三| 在线综合视频播放| 在线欧美日韩精品| 国产成人一级电影| 麻豆精品视频在线| 一区二区三区中文在线观看| 国产亚洲人成网站| 欧美一区在线视频| 欧美亚洲国产bt| jvid福利写真一区二区三区| 喷白浆一区二区| 亚洲成人av免费| 一区二区三区四区不卡视频| 国产午夜精品在线观看| 日韩视频免费观看高清完整版在线观看 | va亚洲va日韩不卡在线观看| 免费欧美高清视频| 亚洲狠狠爱一区二区三区| 中文字幕精品一区| 精品久久久久久久久久久院品网 | 国产99精品在线观看| 蜜臀av一区二区| 视频精品一区二区| 亚洲综合丝袜美腿| 亚洲三级电影网站| 国产精品久久久久久久久免费相片 | 免费xxxx性欧美18vr| 一二三四社区欧美黄| 国产精品丝袜黑色高跟| 久久精子c满五个校花| 日韩一区二区电影| 欧美一区二区三区思思人| 欧美久久久久久久久中文字幕| 91麻豆成人久久精品二区三区| av激情综合网| 99久久99久久免费精品蜜臀| 国产99久久久精品| www.激情成人| 99热这里都是精品| 91成人网在线| 欧美日本视频在线| 91精品国产日韩91久久久久久| 欧美一区二区三区四区高清| 日韩一区二区在线观看视频播放| 51精品国自产在线| 欧美一区二区三区播放老司机| 欧美日韩免费观看一区三区| 欧美日本不卡视频| 精品欧美一区二区久久| 精品国产伦理网| 欧美韩国日本不卡| 亚洲精品一二三| 亚洲成人在线观看视频| 午夜精品久久久久久久久久| 日韩高清不卡一区二区三区| 国产做a爰片久久毛片| 国产精品亚洲人在线观看| www.日韩大片| 欧美日韩免费观看一区二区三区| 欧美美女一区二区在线观看| 日韩你懂的在线观看| 久久综合九色综合97婷婷| 国产蜜臀av在线一区二区三区| 中文字幕综合网| 日韩电影一区二区三区| 激情av综合网| 色视频一区二区| 日韩欧美一级二级三级久久久| 2019国产精品| 一区二区三区小说| 蜜桃视频在线观看一区| 风间由美性色一区二区三区| 欧洲另类一二三四区| 欧美成人艳星乳罩| 亚洲欧美激情插| 久久精品国产秦先生| 99re在线精品| 精品国产a毛片| 一个色妞综合视频在线观看| 久久精品国产精品亚洲红杏| 99久久久精品| 国产亚洲一区二区三区四区| 一区二区三区视频在线看| 久久草av在线| 欧美日韩一区二区在线观看| 久久久久久久精| 视频一区欧美精品| 在线视频一区二区三| 久久久久99精品一区| 亚洲国产精品久久不卡毛片| 国产不卡高清在线观看视频| 4438成人网| 一区二区日韩av| 不卡视频在线看| 日本一区二区视频在线| 久久精品国产色蜜蜜麻豆| 欧美日韩你懂的| 久久色在线观看| 水蜜桃久久夜色精品一区的特点 | 欧美丰满一区二区免费视频| 国产蜜臀av在线一区二区三区| 日韩av二区在线播放| 色视频欧美一区二区三区| 国产精品久久久久国产精品日日| 精品一区二区三区日韩| 欧美日韩另类国产亚洲欧美一级| 中文字幕在线观看一区二区| 国产综合色在线视频区| 日韩精品综合一本久道在线视频| 偷拍日韩校园综合在线| 欧美性淫爽ww久久久久无| 亚洲日本在线a| 91丨porny丨国产入口| 国产欧美一区二区在线| 国产一区999| 久久久高清一区二区三区| 久久电影网站中文字幕 | 国产欧美日韩在线观看| 美腿丝袜亚洲一区| 日韩欧美一二区| 国产一区二区三区四| 久久久噜噜噜久久人人看|