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

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

?? dns.c

?? 開放源碼實(shí)時(shí)操作系統(tǒng)源碼.
?? C
?? 第 1 頁 / 共 2 頁
字號(hào):
//=============================================================================
//
//      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];

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩亚州综合| 欧美精品一区二区久久久| 成人福利视频网站| 国产一区二区调教| 日本不卡的三区四区五区| 欧美精品国产精品| 91精品国产综合久久久久久久 | 极品少妇xxxx精品少妇| 国产.精品.日韩.另类.中文.在线.播放 | 中文字幕乱码亚洲精品一区| 久久影院视频免费| 欧美激情一区二区在线| 国产精品久久久久7777按摩| 亚洲免费在线电影| 午夜精品一区二区三区免费视频 | 色悠久久久久综合欧美99| 色综合久久天天综合网| 欧美日韩一区二区三区不卡 | 美洲天堂一区二卡三卡四卡视频| 久久久影视传媒| 午夜精品一区二区三区电影天堂 | 26uuu国产在线精品一区二区| 色综合一个色综合亚洲| 一本色道亚洲精品aⅴ| 不卡免费追剧大全电视剧网站| 久久成人羞羞网站| 国产在线精品一区二区| 国产久卡久卡久卡久卡视频精品| 美女视频黄a大片欧美| 国产成人精品亚洲日本在线桃色| 波多野结衣精品在线| 宅男在线国产精品| 国产日韩欧美精品电影三级在线 | 国内成人免费视频| 欧美亚洲日本一区| 国产欧美精品一区| 中文字幕一区二区在线播放| 国产精品女同互慰在线看| 亚洲综合色视频| 久久超碰97中文字幕| 国产成人av电影在线观看| 在线视频一区二区三区| 精品久久久久久久一区二区蜜臀| 国产精品美女一区二区| 亚洲色图色小说| 久久国产成人午夜av影院| 国产综合色产在线精品| 在线免费一区三区| 久久久电影一区二区三区| 最新成人av在线| 国产精华液一区二区三区| 91免费视频网址| 久久免费看少妇高潮| 成人美女视频在线观看| 美女一区二区久久| 不卡一区二区中文字幕| 欧美一二三四在线| 亚洲欧美激情插| 国产乱码精品一区二区三区av| 91高清视频在线| 亚洲精品在线免费观看视频| 亚洲狠狠爱一区二区三区| 成人黄色一级视频| 欧美大度的电影原声| 亚洲国产精品麻豆| 99麻豆久久久国产精品免费| 精品国产电影一区二区| 亚洲成人tv网| 99久久精品国产导航| 国产亚洲制服色| 蜜桃视频在线观看一区二区| 91丨九色丨蝌蚪丨老版| 欧美日韩在线直播| 国产精品久久久久久久久免费桃花 | 国产剧情一区在线| 欧美精品粉嫩高潮一区二区| 亚洲免费观看在线观看| 国产白丝精品91爽爽久久 | 视频在线观看国产精品| 色婷婷久久久亚洲一区二区三区| 国产欧美日韩在线看| 麻豆精品一区二区三区| 欧美放荡的少妇| 亚洲国产成人tv| 日本高清成人免费播放| 亚洲男人天堂av| 91影院在线观看| 国产精品美女久久久久久久久| 九九九久久久精品| 日韩欧美中文字幕精品| 日韩1区2区日韩1区2区| 欧美精品在线观看一区二区| 精品91自产拍在线观看一区| av电影天堂一区二区在线| 国产精品国产馆在线真实露脸| 不卡在线观看av| 亚洲人亚洲人成电影网站色| 欧美视频一区二区| 看电视剧不卡顿的网站| 日本一区二区三区在线观看| 91丨porny丨蝌蚪视频| 一区二区日韩av| 日韩一级片网站| eeuss鲁一区二区三区| 亚洲成av人影院| 精品国产亚洲一区二区三区在线观看| 国产福利一区二区三区视频在线 | 日韩理论片网站| 久久精品国内一区二区三区| 欧美日韩中文一区| 国产高清亚洲一区| 性做久久久久久久免费看| 中文字幕一区二区三区乱码在线| 亚洲综合色区另类av| 久久99热狠狠色一区二区| 中文字幕av一区 二区| 不卡视频免费播放| 亚洲精品成人天堂一二三| 欧美亚洲综合色| 免费精品视频在线| 亚洲精品一区在线观看| 丁香啪啪综合成人亚洲小说| 亚洲色图制服诱惑| 欧美日韩免费观看一区三区| 蜜臀av一级做a爰片久久| 久久综合国产精品| 成人午夜又粗又硬又大| 亚洲欧美色图小说| 欧美日韩一区在线观看| 久久99国内精品| 中文字幕一区二区视频| 欧美日韩aaa| 国产伦精一区二区三区| 亚洲精品日产精品乱码不卡| 在线成人av影院| 韩国精品主播一区二区在线观看 | 美女精品自拍一二三四| 国产精品五月天| 欧美午夜精品一区二区蜜桃| 蜜桃av噜噜一区| 成人欧美一区二区三区黑人麻豆| 欧美精品自拍偷拍| 高清国产一区二区| 五月天欧美精品| 国产视频视频一区| 欧美日高清视频| 高清shemale亚洲人妖| 亚洲国产精品一区二区久久 | 一区在线播放视频| 91精品国产欧美一区二区成人| 粉嫩av一区二区三区| 亚洲高清视频的网址| 国产日韩欧美亚洲| 欧美美女一区二区三区| 国产成人免费视频一区| 婷婷丁香久久五月婷婷| 中文字幕乱码久久午夜不卡| 欧美精品一卡两卡| av不卡一区二区三区| 麻豆久久久久久| 亚洲国产精品一区二区www在线| 国产欧美1区2区3区| 欧美群妇大交群的观看方式| 成人免费黄色大片| 黄一区二区三区| 午夜精品在线视频一区| 亚洲欧美一区二区三区国产精品| 亚洲精品一区二区三区影院 | 国产精品成人网| 精品久久久久久久久久久院品网| 欧美亚洲另类激情小说| 成人永久免费视频| 韩日欧美一区二区三区| 婷婷丁香激情综合| 一级日本不卡的影视| 中文字幕av一区二区三区高 | 一区二区三区在线播放| 国产欧美日韩综合| 久久青草欧美一区二区三区| 欧美一区二区三区视频| 欧美日韩免费观看一区三区| 色天天综合色天天久久| 东方aⅴ免费观看久久av| 国产一区二区不卡| 精品亚洲成a人| 久久国产综合精品| 热久久免费视频| 丝袜诱惑制服诱惑色一区在线观看| 日韩伦理av电影| 成人欧美一区二区三区| 国产精品乱码一区二三区小蝌蚪| 精品国免费一区二区三区| 亚洲高清一区二区三区| 欧美放荡的少妇| 一区二区三区.www| 97se亚洲国产综合自在线不卡| 欧美va亚洲va| 国产综合色产在线精品| 欧美乱熟臀69xxxxxx| 亚洲国产一区二区三区|