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

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

?? dns.c

?? 開放源碼實時操作系統(tǒng)源碼.
?? C
?? 第 1 頁 / 共 2 頁
字號:
//=============================================================================
//
//      dns.c
//
//      DNS client code
//
//=============================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//=============================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):   andrew.lunn
// Contributors:andrew.lunn, jskov
// Date:        2001-09-18
// Description: Provides DNS lookup as per RFC 1034/1035.
// 
// Note:        Does only support A and PTR lookups. Maybe add for other
//              types as well?
//
//              parse_answer() only returns the first found record.
//
//              Add tracing and assertions.
//
//####DESCRIPTIONEND####
//
//=============================================================================

#include <pkgconf/system.h>
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
# include <cyg/kernel/kapi.h>
#endif
#include <cyg/hal/drv_api.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/cyg_trac.h>         /* Tracing support */

#include <netdb.h>

#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include <ctype.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <cyg/ns/dns/dns_priv.h>

static short id = 0;              /* ID of the last query */
static int s = -1;                /* Socket to the DNS server */
static cyg_drv_mutex_t dns_mutex; /* Mutex to stop multiple queries as once */
static cyg_ucount32 ptdindex;     /* Index for the per thread data */
static char * domainname=NULL;    /* Domain name used for queries */

/* Allocate space for string of length len. Return NULL on failure. */
static inline char*
alloc_string(int len)
{
    return malloc(len);
}

static inline void
free_string(char* s)
{
    free(s);
}

/* Deallocate the memory taken to hold a hent structure */
static void
free_hent(struct hostent * hent)
{
    if (hent->h_name) {
        free_string(hent->h_name);
    }

    if (hent->h_addr_list) {
        int i = 0;
        while (hent->h_addr_list[i]) {
            free(hent->h_addr_list[i]);
            i++;
        }
        free(hent->h_addr_list);
    }
    free(hent);
}

/* Allocate hent structure with room for one in_addr. Returns NULL on
   failure. */
static struct hostent*
alloc_hent(void)
{
    struct hostent *hent;

    hent = malloc(sizeof(struct hostent));
    if (hent) {
        memset(hent, 0, sizeof(struct hostent));
        hent->h_addr_list = malloc(sizeof(char *)*2);
        if (!hent->h_addr_list) {
            free_hent(hent);
            return NULL;
        }
        hent->h_addr_list[0] = malloc(sizeof(struct in_addr));
        if (!hent->h_addr_list[0]) {
            free_hent(hent);
            return NULL;
        }
        hent->h_addr_list[1] = NULL;
    }

    return hent;
}

/* Thread destructor used to free stuff stored in per-thread data slot. */
static void
thread_destructor(CYG_ADDRWORD data)
{
    struct hostent *hent;
    hent = (struct hostent *)cyg_thread_get_data(ptdindex);
    if (hent)
        free_hent(hent);
    return;
    data=data;
}

/* Store the hent away in the per-thread data. */
static void
store_hent(struct hostent *hent)
{
    // Prevent memory leaks by setting a destructor to be
    // called on thread exit to free per-thread data.
    cyg_thread_add_destructor( &thread_destructor, 0 );
    cyg_thread_set_data(ptdindex, (CYG_ADDRWORD)hent);
}

/* If there is an answer to an old query, free the memory it uses. */
static void
free_stored_hent(void)
{
    struct hostent *hent;
    hent = (struct hostent *)cyg_thread_get_data(ptdindex);
    if (hent) {
        free_hent(hent);
        cyg_thread_set_data(ptdindex, (CYG_ADDRWORD)NULL);
        cyg_thread_rem_destructor( &thread_destructor, 0 );
    }
}

/* Send the query to the server and read the response back. Return -1
   if it fails, otherwise put the response back in msg and return the
   length of the response. */
static int 
send_recv(unsigned char * msg, int len, int msglen)
{
    struct dns_header *dns_hdr;
    struct timeval timeout;
    int finished = false;
    int backoff = 1;
    fd_set readfds;
    int written;
    int ret;

    CYG_REPORT_FUNCNAMETYPE( "send_recv", "returning %d" );
    CYG_REPORT_FUNCARG3( "msg=%08x, len=%d, msglen", msg, len, msglen );

    CYG_CHECK_DATA_PTR( msg, "msg is not a valid pointer!" );

    dns_hdr = (struct dns_header *) msg;

    do { 
        written = write(s, msg, len);
        if (written < 0) {
            ret = -1;
            break;
        }

        FD_ZERO(&readfds);
        FD_SET(s, &readfds);
    
        timeout.tv_sec = backoff;
        timeout.tv_usec = 0;
        backoff = backoff << 1;

        ret = select(s+1, &readfds, NULL, NULL, &timeout);
        if (ret < 0) {
            ret = -1;
            break;
        }
        /* Timeout */
        if (ret == 0) {
            if (backoff > 16) {
                h_errno = TRY_AGAIN;
                ret = -1;
                break;
            }
        }
        if (ret == 1) {
            ret = read(s, msg, msglen);
            if (ret < 0) {
                ret = -1;
                break;
            }
      
            /* Reply to an old query. Ignore it */
            if (ntohs(dns_hdr->id) != (id-1)) {
                continue;
            }
            finished = true;
        }
    } while (!finished);

    CYG_REPORT_RETVAL( ret );

    return ret;
}

/* Include the DNS client implementation code */
#include <cyg/ns/dns/dns_impl.inl>

/* (re)Start the DNS client. This opens a socket to the DNS server
   who's address is passed in. This address can be either an IPv4 or
   IPv6 address. This function can be called multiple times.  If we
   are being called a second time we have to be careful to allow any
   ongoing lookups to finish before we close the socket and connect to
   a different DNS server. The danger here is that we may have to wait
   for up to 32 seconds if the DNS server is down.
   Each invocation will close any previous connection and make a new
   connection to the new server. Note the address of the server must
   be in numeric form since its not possible to do a DNS lookup! */

int cyg_dns_res_start(char * dns_server) {

    static int init =0;
    struct addrinfo * res;
    int err;

    CYG_REPORT_FUNCNAMETYPE( "cyg_dns_res_start", "returning %d" );
    CYG_REPORT_FUNCARG1( "dns_server=%s", dns_server );

    CYG_CHECK_DATA_PTR( dns_server, "dns_server is not a valid pointer!" );

    if (init) {
      cyg_drv_mutex_lock(&dns_mutex);
      cyg_thread_free_data_index(ptdindex);
      if (s >= 0) {
        close(s);
      }
    } else {
      init = 1;
      cyg_drv_mutex_init(&dns_mutex);
      cyg_drv_mutex_lock(&dns_mutex);
    }
    
    err = getaddrinfo(dns_server,"domain", NULL, &res);
    if (err != 0) {
        cyg_drv_mutex_unlock(&dns_mutex);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }
  
    s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (s == -1) {
        cyg_drv_mutex_unlock(&dns_mutex);
        freeaddrinfo(res);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }

    if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
        s = -1;
        cyg_drv_mutex_unlock(&dns_mutex);
        freeaddrinfo(res);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }
    ptdindex = cyg_thread_new_data_index();  
  
    cyg_drv_mutex_unlock(&dns_mutex);
    freeaddrinfo(res);
    CYG_REPORT_RETVAL( 0 );
    return 0;
}

/* This is the old interface to start the resolver. It is only IPv4
   capable and so is now deprecated in favor of cyg_dns_res_start().
   Initialise the resolver. Open a socket and bind it to the
   address of the server.  return -1 if something goes wrong,
   otherwise 0. If we are being called a second time we have to be
   careful to allow any ongoing lookups to finish before we close the
   socket and connect to a different DNS server. The danger here is
   that we may have to wait for up to 32 seconds if the DNS server is
   down.  */
int  
cyg_dns_res_init(struct in_addr *dns_server)
{
  char name[20];
  unsigned char *bytes = (unsigned char *)dns_server;
  int ret;

  CYG_REPORT_FUNCNAMETYPE( "cyg_dns_res_init", "returning %d" );
  CYG_REPORT_FUNCARG1( "dns_server=%08x", dns_server );

  diag_sprintf(name, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
  
  ret = cyg_dns_res_start(name);
  
  CYG_REPORT_RETVAL( ret );
  return ret;
}

/* add_answer checks to see if we already have this answer and if not,
   adds it to the answers. */
static int 
add_answer(char *rdata, short rr_type, int family, 
           struct sockaddr addrs[], int num, int used) {
    int i;
    int found = 0;
    
    for (i = 0; i < used ; i++) {
        if ((addrs[i].sa_family == family) &&
            !memcmp(addrs[i].sa_data, rdata, addrs[i].sa_len)) {
            found = 1;
            break;
        }
    }
    if (!found) {
        memset(&addrs[used],0,sizeof(addrs[used]));
        addrs[used].sa_family = family;
        
        switch(family) {
        case AF_INET: {
            struct sockaddr_in * addr = (struct sockaddr_in *) &addrs[used];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品日韩一区| 亚洲欧美日韩在线| 亚洲激情六月丁香| 韩国一区二区在线观看| 精品污污网站免费看| 国产精品久久久久久久裸模| 青草国产精品久久久久久| 99国产精品久久| 欧美国产97人人爽人人喊| 天堂午夜影视日韩欧美一区二区| caoporm超碰国产精品| 国产女人18水真多18精品一级做| 日韩高清不卡在线| 欧美日韩中文字幕一区二区| 国产精品久久久久久久岛一牛影视 | 国产日韩三级在线| 久久99精品久久久久婷婷| 欧美巨大另类极品videosbest| 首页综合国产亚洲丝袜| 欧洲在线/亚洲| 一区二区三区日本| 日本国产一区二区| 亚洲欧美另类久久久精品2019| 不卡电影免费在线播放一区| 国产日韩成人精品| 成人精品视频一区| 中文一区一区三区高中清不卡| 国产成人午夜精品影院观看视频| 精品国产乱码久久久久久老虎| 精品一二三四区| 久久综合色天天久久综合图片| 久久爱www久久做| 久久品道一品道久久精品| 国产毛片精品国产一区二区三区| 精品久久国产97色综合| 国产一区二三区好的| 久久精品亚洲精品国产欧美| 国产成人精品三级| 国产精品乱码一区二区三区软件| 成人av资源站| 一区二区不卡在线播放| 67194成人在线观看| 久久精品国内一区二区三区| 久久久久久亚洲综合影院红桃| 国产成人av一区二区三区在线观看| 国产人成一区二区三区影院| 国产不卡视频一区二区三区| 亚洲欧洲精品一区二区三区 | 日韩视频永久免费| 国产一区二区精品久久99| 中文成人综合网| 色婷婷激情综合| 免费视频最近日韩| 国产精品素人视频| 欧美日韩一区二区在线观看视频| 日本午夜精品一区二区三区电影| 久久久久国产精品麻豆| 一本大道久久a久久精品综合| 亚洲成精国产精品女| 久久久亚洲午夜电影| 色素色在线综合| 韩国理伦片一区二区三区在线播放| 中文字幕第一区二区| 欧美三级欧美一级| 国产成人三级在线观看| 亚洲成人免费影院| 国产夜色精品一区二区av| 欧美日韩免费一区二区三区| 国产制服丝袜一区| 亚洲在线观看免费| 国产亚洲欧美日韩在线一区| 色噜噜狠狠一区二区三区果冻| 青青草精品视频| 一区二区三区四区五区视频在线观看| 91精品国产高清一区二区三区| 99re这里只有精品首页| 久久国产精品99久久久久久老狼| 亚洲色图.com| 久久久www免费人成精品| 欧美在线视频不卡| www.日本不卡| 国产一区二区三区在线观看精品 | 亚洲一区二区三区小说| 国产三级精品在线| 日韩欧美一二三| 色乱码一区二区三区88| 国产精一品亚洲二区在线视频| 亚洲国产美女搞黄色| 中国色在线观看另类| 欧美大尺度电影在线| 欧美日本在线观看| 在线视频中文字幕一区二区| 成人av网站在线观看免费| 黄色日韩三级电影| 免费观看在线综合色| 亚洲第一主播视频| 亚洲一二三四在线| 亚洲色图视频免费播放| 国产精品天干天干在观线| 久久免费精品国产久精品久久久久 | 久久久精品2019中文字幕之3| 在线综合+亚洲+欧美中文字幕| 91欧美激情一区二区三区成人| 国产精品一级黄| 国产精品中文字幕日韩精品| 蜜臀a∨国产成人精品| 日韩二区三区在线观看| 亚洲大型综合色站| 午夜久久久影院| 午夜亚洲国产au精品一区二区| 一区二区日韩av| 亚洲制服丝袜av| 亚洲成人精品一区| 亚洲超丰满肉感bbw| 午夜精品一区二区三区电影天堂| 亚洲欧洲精品天堂一级 | 麻豆国产欧美一区二区三区| 人人爽香蕉精品| 久久精品国产秦先生| 免费精品视频在线| 国产精品自拍毛片| av中文字幕亚洲| 91视频com| 欧美日韩一区二区三区免费看| 欧美日韩国产影片| 欧美大片日本大片免费观看| 26uuu国产一区二区三区| 欧美激情中文不卡| 亚洲免费av观看| 日韩av中文字幕一区二区| 美女尤物国产一区| 岛国一区二区三区| 欧美日韩在线亚洲一区蜜芽| 欧美一区二区三区在| 久久精品一区八戒影视| 最新国产成人在线观看| 天堂蜜桃一区二区三区| 国产精品一二一区| 色婷婷av一区二区三区gif| 91精品在线一区二区| 欧美国产综合一区二区| 一区二区三区中文字幕| 麻豆成人久久精品二区三区小说| 国产精品123| 欧美最猛黑人xxxxx猛交| 欧美成人vps| 伊人性伊人情综合网| 奇米影视在线99精品| 成人18精品视频| 欧美一区二区网站| 欧美国产激情一区二区三区蜜月| 亚洲资源中文字幕| 国产成人午夜99999| 在线免费观看视频一区| 精品国产成人系列| 亚洲精品国产品国语在线app| 日本午夜精品视频在线观看| 成人一区二区三区| 5858s免费视频成人| 日韩理论电影院| 黄网站免费久久| 欧美日韩一区二区三区四区| 国产精品视频一二三| 日韩电影免费在线| 色综合久久久久综合体| 精品第一国产综合精品aⅴ| 亚洲另类在线制服丝袜| 国产成人午夜高潮毛片| 日韩欧美综合在线| 亚洲最大的成人av| 国产91精品精华液一区二区三区 | 国产精品无码永久免费888| 首页综合国产亚洲丝袜| 一本色道久久综合狠狠躁的推荐| 亚洲精品一区二区三区四区高清 | 久久美女高清视频| 日韩av不卡在线观看| 在线视频国内自拍亚洲视频| 国产亚洲成av人在线观看导航| 日韩**一区毛片| 欧美自拍偷拍午夜视频| 亚洲啪啪综合av一区二区三区| 国产精品综合视频| 日韩美女视频在线| 蜜臀av一区二区在线免费观看| 欧美艳星brazzers| 亚洲在线一区二区三区| 色系网站成人免费| 亚洲色图欧美激情| 色婷婷综合久久久久中文一区二区 | 美女高潮久久久| 91精品国产综合久久精品| 亚洲成人免费观看| 欧美日韩一二三| 丝袜国产日韩另类美女| 欧美精品色综合| 蜜桃视频第一区免费观看| 欧美一区二区成人6969| 蜜桃传媒麻豆第一区在线观看| 在线观看91av|