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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? dns.c

?? 基于STM32F107的UDP服務(wù)器程序
?? 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/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
/** 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

#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
/** 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. */
  PACK_STRUCT_FIELD(u16_t type);
  PACK_STRUCT_FIELD(u16_t class);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif
#define SIZEOF_DNS_QUERY 4

#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
/** 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. */
  PACK_STRUCT_FIELD(u16_t type);
  PACK_STRUCT_FIELD(u16_t class);
  PACK_STRUCT_FIELD(u32_t ttl);
  PACK_STRUCT_FIELD(u16_t len);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif
#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];
  struct ip_addr ipaddr;
  /* pointer to callback on DNS query done */
  dns_found_callback found;
  void *arg;
};

#if DNS_LOCAL_HOSTLIST
/** struct used for local host-list */
struct local_hostlist_entry {
  /** static hostname */
  const char *name;
  /** static host address in network byteorder */
  u32_t addr;
  struct local_hostlist_entry *next;
};

#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, 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);
    }
  }
#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, 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();

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人免费黄色大片| 91猫先生在线| 国产精品99久久不卡二区| 亚洲裸体xxx| 久久综合九色综合久久久精品综合| 99久久精品久久久久久清纯| 日本成人超碰在线观看| 中文字幕色av一区二区三区| www国产亚洲精品久久麻豆| 欧美午夜理伦三级在线观看| 成人深夜视频在线观看| 久久99精品一区二区三区三区| 亚洲男女一区二区三区| 国产欧美日韩亚州综合| 日韩欧美一级片| 欧美日韩一级大片网址| 91视频在线看| 成人av在线资源网站| 国产在线精品免费| 久久精品国产在热久久| 亚洲午夜久久久久| 亚洲精品成人天堂一二三| 中文字幕乱码日本亚洲一区二区 | 国产精品99久久久久久久女警| 青青草国产成人99久久| 亚洲制服丝袜av| 亚洲精品日产精品乱码不卡| 日本一区二区久久| 国产免费久久精品| 久久精品一区二区三区av| 精品久久人人做人人爰| 日韩亚洲欧美高清| 欧美一区欧美二区| 91精品久久久久久久91蜜桃| 欧美人牲a欧美精品| 欧美精品乱人伦久久久久久| 日本黄色一区二区| 在线亚洲人成电影网站色www| 亚洲精品一区二区精华| 日韩视频一区二区三区| 欧美大片顶级少妇| 精品国产乱码久久久久久闺蜜 | 国产大片一区二区| 国产麻豆视频精品| 成人午夜电影小说| 成人免费视频一区| 91丝袜美腿高跟国产极品老师 | 亚洲国产精品久久艾草纯爱| 一区二区三区中文免费| 亚洲午夜在线观看视频在线| 亚洲高清视频的网址| 日本不卡一二三区黄网| 久久国产精品色婷婷| 国产成人亚洲综合a∨婷婷| 成人中文字幕电影| 日本韩国精品一区二区在线观看| 欧美综合在线视频| 欧美一区二区三区视频| 久久中文字幕电影| 国产精品另类一区| 亚洲国产毛片aaaaa无费看 | 国产宾馆实践打屁股91| www.成人网.com| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 成人欧美一区二区三区1314| 亚洲高清免费观看| 国产一区欧美日韩| 色婷婷综合久久久中文一区二区| 欧美群妇大交群中文字幕| 精品欧美黑人一区二区三区| 国产欧美精品一区二区三区四区 | 九九热在线视频观看这里只有精品| 国产精品一区二区你懂的| 91亚洲精品乱码久久久久久蜜桃| 欧美疯狂做受xxxx富婆| 国产亚洲一区二区在线观看| 亚洲黄色片在线观看| 久久99久久99精品免视看婷婷| 成人免费福利片| 51久久夜色精品国产麻豆| 国产三级一区二区| 亚洲va欧美va人人爽午夜| 国产成人av网站| 欧美日韩不卡一区二区| 国产精品视频看| 日韩精品一二三区| av电影天堂一区二区在线 | 亚洲欧美日本韩国| 美女视频一区在线观看| 91视频国产资源| 久久久久久久久久久99999| 亚洲在线视频免费观看| 国产精品亚洲专一区二区三区 | 免费一级欧美片在线观看| av在线不卡电影| 26uuu国产一区二区三区| 亚洲一区二区四区蜜桃| 成人一区二区三区视频 | 日韩一区在线看| 狠狠网亚洲精品| 精品视频一区三区九区| 欧美国产国产综合| 久久精品国产在热久久| 欧美日韩在线亚洲一区蜜芽| 国产精品久久久久aaaa| 国产又黄又大久久| 欧美一区二区三区小说| 夜夜爽夜夜爽精品视频| eeuss国产一区二区三区| 久久青草国产手机看片福利盒子 | 欧美午夜一区二区三区| 中文字幕在线观看一区二区| 国产精品一级黄| 精品国产电影一区二区| 日韩av网站在线观看| 欧美写真视频网站| 亚洲综合免费观看高清完整版| 99视频国产精品| 国产女主播视频一区二区| 国产一区二区视频在线| 日韩欧美激情一区| 日本aⅴ精品一区二区三区| 欧美日韩国产综合视频在线观看| 亚洲精品精品亚洲| 一本一道久久a久久精品| 中文字幕在线观看不卡| 北岛玲一区二区三区四区| 欧美极品少妇xxxxⅹ高跟鞋| 国产成a人亚洲精| 久久精品男人天堂av| 夫妻av一区二区| 中文字幕国产一区二区| 成人深夜在线观看| 亚洲天堂免费看| 91视频免费看| 亚洲一区在线免费观看| 欧美图片一区二区三区| 亚洲成a人在线观看| 欧美日韩国产另类不卡| 免费视频最近日韩| 久久综合久久久久88| 国产成人av影院| 亚洲三级免费电影| 欧美亚洲另类激情小说| 午夜伊人狠狠久久| 日韩精品一区二区三区视频播放 | 天堂va蜜桃一区二区三区| 欧美日韩高清一区二区| 美女在线视频一区| 久久久久久电影| 成人美女视频在线观看| 亚洲女女做受ⅹxx高潮| 欧美无砖砖区免费| 蜜桃精品视频在线| 久久视频一区二区| 成人av资源在线| 亚洲成人综合视频| 欧美成人综合网站| 国产91精品精华液一区二区三区| 国产精品美女一区二区三区| 在线国产电影不卡| 麻豆精品在线看| 亚洲国产精品传媒在线观看| 色综合天天视频在线观看| 婷婷夜色潮精品综合在线| 欧美色图片你懂的| 亚洲高清不卡在线观看| 久久综合九色综合久久久精品综合 | 久久嫩草精品久久久久| 成人自拍视频在线观看| 亚洲一区二区三区四区在线免费观看| 欧美一区二区三区婷婷月色| 国产精品资源在线观看| 亚洲一区自拍偷拍| 久久久99精品免费观看| 欧美无乱码久久久免费午夜一区 | 精品一区二区免费在线观看| 国产精品国产精品国产专区不蜜| 欧美日本韩国一区二区三区视频 | 不卡一区二区中文字幕| 日韩国产欧美三级| 日韩一区中文字幕| 精品国产在天天线2019| 在线精品视频免费播放| 国产在线精品不卡| 香蕉加勒比综合久久| 国产嫩草影院久久久久| 欧美一区二区三区四区在线观看 | 免费av网站大全久久| 日韩美女啊v在线免费观看| 91精品国产综合久久精品app| 国产精品一区二区91| 视频在线观看国产精品| 成人免费在线观看入口| 精品欧美一区二区久久| 欧美日韩一区二区三区免费看 | 日韩av二区在线播放| 亚洲欧美一区二区三区久本道91| 久久日韩粉嫩一区二区三区| 欧美日韩免费一区二区三区 |