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

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

?? dns.c

?? FreeRTOS - V5.1.1 Last Update: Nov 20 2008 http://sourceforge.net/projects/freertos/
?? 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一区二区三区免费野_久草精品视频
www.日韩在线| 一色桃子久久精品亚洲| 国产亚洲精品超碰| 一区二区三区四区av| 久久精品国产一区二区三区免费看| 国产精品亚洲第一| 337p亚洲精品色噜噜狠狠| 中文字幕亚洲一区二区av在线 | a亚洲天堂av| 精品国偷自产国产一区| 亚洲v日本v欧美v久久精品| 成人免费视频播放| 国产欧美一区二区精品性| 蜜桃久久av一区| 91精品欧美久久久久久动漫 | 国内精品国产成人国产三级粉色 | 成人免费小视频| 国产精品一区二区黑丝| 日韩欧美一区二区免费| 日本亚洲欧美天堂免费| 欧美日产国产精品| 一区二区三区四区亚洲| 91麻豆国产精品久久| 国产精品第一页第二页第三页| 国产成人精品三级| 日本一区二区综合亚洲| 国产乱码精品一区二区三区av| 欧美一区二区在线播放| 蜜臀av一区二区在线观看| 欧美丰满高潮xxxx喷水动漫| 亚洲.国产.中文慕字在线| 欧美日韩在线一区二区| 亚洲午夜电影网| 56国语精品自产拍在线观看| 日韩av一二三| 精品国产亚洲在线| 大胆亚洲人体视频| 国产精品国产三级国产专播品爱网 | 在线观看国产91| 亚洲精品成a人| 欧美日韩国产成人在线免费| 日本一区中文字幕| 欧美成人综合网站| 国产福利精品一区二区| 亚洲品质自拍视频| 在线观看一区二区视频| 日日夜夜精品视频免费| 精品电影一区二区| 成人毛片老司机大片| 日韩美女视频一区二区| 欧美影院一区二区三区| 七七婷婷婷婷精品国产| 久久这里只有精品视频网| 成人综合婷婷国产精品久久蜜臀 | 国产专区欧美精品| 欧美国产日产图区| 色欧美日韩亚洲| 免费成人在线观看视频| 国产精品女人毛片| 欧美裸体一区二区三区| 九色porny丨国产精品| 亚洲三级免费观看| 欧美一区二区福利视频| 高清国产一区二区三区| 亚洲国产精品一区二区尤物区| 欧美tk丨vk视频| 色婷婷精品大视频在线蜜桃视频| 日韩精品五月天| 中文字幕中文字幕在线一区| 欧美日韩电影一区| 成人av午夜电影| 麻豆91精品视频| 樱桃视频在线观看一区| 国产亚洲欧美一级| 91精品国产色综合久久久蜜香臀| 成人亚洲一区二区一| 亚洲第一福利一区| 亚洲欧美综合色| 久久久美女毛片| 538prom精品视频线放| av在线一区二区| 国产综合成人久久大片91| 亚洲高清在线精品| 日韩美女视频一区二区 | 亚洲综合精品久久| 欧美成人午夜电影| 欧美视频中文一区二区三区在线观看| 国产一区二区三区精品视频| 五月婷婷激情综合网| 国产精品第四页| 欧美成人乱码一区二区三区| 欧美日韩免费一区二区三区视频| a亚洲天堂av| 丰满少妇在线播放bd日韩电影| 日本在线不卡视频| 日韩一区精品视频| 亚洲另类在线一区| 成人欧美一区二区三区在线播放| 国产亚洲欧美日韩日本| 精品成人在线观看| 日韩欧美精品在线视频| 欧美精品久久99久久在免费线| 色老汉av一区二区三区| av成人动漫在线观看| 国产精品白丝jk白祙喷水网站| 久久99久久99| 激情深爱一区二区| 久久精品国产亚洲一区二区三区| 日本大胆欧美人术艺术动态| 日韩在线观看一区二区| 麻豆视频一区二区| 青青草原综合久久大伊人精品| 婷婷综合另类小说色区| 亚洲成人精品一区二区| 亚洲国产一区二区a毛片| 亚洲国产精品一区二区久久 | 亚洲美女屁股眼交3| 亚洲日本va午夜在线电影| 最新国产精品久久精品| 亚洲人成网站精品片在线观看 | 国产精品久久久一区麻豆最新章节| 久久久久久97三级| 久久精品免费在线观看| 国产欧美一区二区精品性色| 中文幕一区二区三区久久蜜桃| 国产精品视频在线看| 亚洲免费观看高清| 天堂成人国产精品一区| 久久精品二区亚洲w码| 国产高清久久久久| 92国产精品观看| 欧美日韩国产a| 欧美精品一区男女天堂| 国产精品你懂的在线| 亚洲精品成a人| 久久精品99久久久| 不卡的av中国片| 欧美专区在线观看一区| 91精品婷婷国产综合久久| 久久中文娱乐网| 一区二区三区中文免费| 日本aⅴ精品一区二区三区| 国产精品一二一区| 色婷婷亚洲婷婷| 日韩女优视频免费观看| 自拍偷在线精品自拍偷无码专区 | 欧美成人r级一区二区三区| 国产日韩三级在线| 亚洲成人先锋电影| 国产老妇另类xxxxx| 91久久精品网| 国产视频一区在线播放| 亚洲成av人片| 国产成人高清视频| 在线观看91视频| 日本一区二区三区dvd视频在线| 亚洲精品福利视频网站| 韩国欧美国产一区| 欧美性大战久久久久久久蜜臀 | 色婷婷av一区二区三区gif | 国产福利一区二区三区| 欧美亚洲国产bt| 中文字幕精品在线不卡| 麻豆国产91在线播放| 日本韩国欧美在线| 国产女人aaa级久久久级| 免费观看久久久4p| 91福利视频久久久久| 久久久www成人免费无遮挡大片| 亚洲电影你懂得| 成人黄色在线视频| 久久久久久97三级| 男女男精品视频| 欧美精品在线观看播放| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 日韩vs国产vs欧美| 91行情网站电视在线观看高清版| 久久你懂得1024| 国产综合色视频| 精品国产三级电影在线观看| 婷婷综合五月天| 欧美日韩久久一区| 亚洲欧美一区二区三区国产精品| 国产成人综合自拍| 久久亚洲一区二区三区四区| 午夜视频在线观看一区二区三区| fc2成人免费人成在线观看播放| 国产午夜精品一区二区三区四区| 麻豆国产精品777777在线| 日韩一区二区在线观看视频| 午夜国产不卡在线观看视频| 欧美日韩精品免费| 亚洲国产精品久久艾草纯爱| 91国在线观看| 亚洲国产视频直播| 欧美日韩国产美| 午夜av区久久| 欧美一区二区免费观在线| 蜜臀精品久久久久久蜜臀| 精品久久久久久无|