/* Copyright 2006-2007 Niels Provos
* Copyright 2007-2012 Nick Mathewson and Niels Provos
*
* 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.
*/
/* Based on software by Adam Langly. Adam's original message:
*
* Async DNS Library
* Adam Langley <agl@imperialviolet.org>
* http://www.imperialviolet.org/eventdns.html
* Public Domain code
*
* This software is Public Domain. To view a copy of the public domain dedication,
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
*
* I ask and expect, but do not require, that all derivative works contain an
* attribution similar to:
* Parts developed by Adam Langley <agl@imperialviolet.org>
*
* You may wish to replace the word "Parts" with something else depending on
* the amount of original code.
*
* (Derivative works does not include programs which link against, run or include
* the source verbatim in their source distributions)
*
* Version: 0.1b
*/
#include "event2/event-config.h"
#include "evconfig-private.h"
#include <sys/types.h>
#ifndef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 3
#endif
#include <string.h>
#include <fcntl.h>
#ifdef EVENT__HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef EVENT__HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef EVENT__HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <limits.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#ifndef _WIN32_IE
#define _WIN32_IE 0x400
#endif
#include <shlobj.h>
#endif
#include "event2/dns.h"
#include "event2/dns_struct.h"
#include "event2/dns_compat.h"
#include "event2/util.h"
#include "event2/event.h"
#include "event2/event_struct.h"
#include "event2/thread.h"
#include "defer-internal.h"
#include "log-internal.h"
#include "mm-internal.h"
#include "strlcpy-internal.h"
#include "ipv6-internal.h"
#include "util-internal.h"
#include "evthread-internal.h"
#ifdef _WIN32
#include <ctype.h>
#include <winsock2.h>
#include <windows.h>
#include <iphlpapi.h>
#include <io.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#ifdef EVENT__HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
#define EVDNS_LOG_DEBUG EVENT_LOG_DEBUG
#define EVDNS_LOG_WARN EVENT_LOG_WARN
#define EVDNS_LOG_MSG EVENT_LOG_MSG
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
#include <stdio.h>
#undef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ASSERT_VALID_REQUEST(req) \
EVUTIL_ASSERT((req)->handle && (req)->handle->current_req == (req))
#define u64 ev_uint64_t
#define u32 ev_uint32_t
#define u16 ev_uint16_t
#define u8 ev_uint8_t
/* maximum number of addresses from a single packet */
/* that we bother recording */
#define MAX_V4_ADDRS 32
#define MAX_V6_ADDRS 32
#define TYPE_A EVDNS_TYPE_A
#define TYPE_CNAME 5
#define TYPE_PTR EVDNS_TYPE_PTR
#define TYPE_SOA EVDNS_TYPE_SOA
#define TYPE_AAAA EVDNS_TYPE_AAAA
#define CLASS_INET EVDNS_CLASS_INET
/* Persistent handle. We keep this separate from 'struct request' since we
* need some object to last for as long as an evdns_request is outstanding so
* that it can be canceled, whereas a search request can lead to multiple
* 'struct request' instances being created over its lifetime. */
struct evdns_request {
struct request *current_req;
struct evdns_base *base;
int pending_cb; /* Waiting for its callback to be invoked; not
* owned by event base any more. */
/* elements used by the searching code */
int search_index;
struct search_state *search_state;
char *search_origname; /* needs to be free()ed */
int search_flags;
};
struct request {
u8 *request; /* the dns packet data */
u8 request_type; /* TYPE_PTR or TYPE_A or TYPE_AAAA */
unsigned int request_len;
int reissue_count;
int tx_count; /* the number of times that this packet has been sent */
void *user_pointer; /* the pointer given to us for this request */
evdns_callback_type user_callback;
struct nameserver *ns; /* the server which we last sent it */
/* these objects are kept in a circular list */
/* XXX We could turn this into a CIRCLEQ. */
struct request *next, *prev;
struct event timeout_event;
u16 trans_id; /* the transaction id */
unsigned request_appended :1; /* true if the request pointer is data which follows this struct */
unsigned transmit_me :1; /* needs to be transmitted */
/* XXXX This is a horrible hack. */
char **put_cname_in_ptr; /* store the cname here if we get one. */
struct evdns_base *base;
struct evdns_request *handle;
};
struct reply {
unsigned int type;
unsigned int have_answer : 1;
union {
struct {
u32 addrcount;
u32 addresses[MAX_V4_ADDRS];
} a;
struct {
u32 addrcount;
struct in6_addr addresses[MAX_V6_ADDRS];
} aaaa;
struct {
char name[HOST_NAME_MAX];
} ptr;
} data;
};
struct nameserver {
evutil_socket_t socket; /* a connected UDP socket */
struct sockaddr_storage address;
ev_socklen_t addrlen;
int failed_times; /* number of times which we have given this server a chance */
int timedout; /* number of times in a row a request has timed out */
struct event event;
/* these objects are kept in a circular list */
struct nameserver *next, *prev;
struct event timeout_event; /* used to keep the timeout for */
/* when we next probe this server. */
/* Valid if state == 0 */
/* Outstanding probe request for this nameserver, if any */
struct evdns_request *probe_request;
char state; /* zero if we think that this server is down */
char choked; /* true if we have an EAGAIN from this server's socket */
char write_waiting; /* true if we are waiting for EV_WRITE events */
struct evdns_base *base;
/* Number of currently inflight requests: used
* to track when we should add/del the event. */
int requests_inflight;
};
/* Represents a local port where we're listening for DNS requests. Right now, */
/* only UDP is supported. */
struct evdns_server_port {
evutil_socket_t socket; /* socket we use to read queries and write replies. */
int refcnt; /* reference count. */
char choked; /* Are we currently blocked from writing? */
char closing; /* Are we trying to close this port, pending writes? */
evdns_request_callback_fn_type user_callback; /* Fn to handle requests */
void *user_data; /* Opaque pointer passed to user_callback */
struct event event; /* Read/write event */
/* circular list of replies that we want to write. */
struct server_request *pending_replies;
struct event_base *eve
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
可调试(vs2012编译)libevent 2.1.8 (259个子文件)
evdns.c 127KB
http.c 121KB
event.c 100KB
buffer.c 80KB
evutil.c 69KB
bufferevent_openssl.c 39KB
bufferevent_ratelim.c 30KB
evrpc.c 29KB
evmap.c 28KB
bufferevent.c 25KB
listener.c 21KB
bufferevent_sock.c 18KB
bufferevent_async.c 18KB
bufferevent_filter.c 18KB
evutil_time.c 17KB
epoll.c 14KB
kqueue.c 14KB
event_tagging.c 14KB
evthread.c 13KB
arc4random.c 13KB
signal.c 12KB
evport.c 12KB
win32select.c 10KB
bufferevent_pair.c 10KB
select.c 9KB
buffer_iocp.c 8KB
evthread_win32.c 8KB
poll.c 8KB
devpoll.c 8KB
event_iocp.c 8KB
log.c 6KB
evutil_rand.c 5KB
evthread_pthread.c 5KB
strlcpy.c 3KB
epoll_sub.c 2KB
main.cpp 3KB
libcrypto-1_1.dll 1.98MB
libcrypto-1_1.dll 1.98MB
libssl-1_1.dll 363KB
libssl-1_1.dll 363KB
Jvklibevent.exe 809KB
Jvklibevent.vcxproj.filters 10KB
obj_mac.h 187KB
ssl.h 121KB
evp.h 73KB
ec.h 69KB
event.h 61KB
tls1.h 48KB
x509.h 47KB
asn1.h 45KB
objects.h 44KB
http.h 42KB
epolltable-internal.h 40KB
engine.h 39KB
buffer.h 38KB
x509v3.h 37KB
bio.h 37KB
bufferevent.h 34KB
asn1t.h 31KB
ht-internal.h 29KB
util.h 28KB
x509_vfy.h 27KB
ts.h 27KB
rsa.h 27KB
dns.h 26KB
cms.h 26KB
bn.h 24KB
tree.h 22KB
rpc.h 21KB
pem.h 20KB
bufferevent-internal.h 18KB
ocsp.h 18KB
ct.h 18KB
crypto.h 17KB
event-internal.h 17KB
queue.h 16KB
pkcs7.h 16KB
ui.h 16KB
util-internal.h 16KB
evthread-internal.h 14KB
dh.h 14KB
pkcs12.h 13KB
ssl3.h 13KB
evbuffer-internal.h 13KB
dns_compat.h 12KB
dsa.h 11KB
event-config.h 11KB
dso.h 11KB
err.h 10KB
modes.h 10KB
thread.h 10KB
e_os2.h 9KB
conf.h 8KB
lhash.h 8KB
iocp-internal.h 8KB
event_compat.h 7KB
des.h 7KB
listener.h 7KB
minheap-internal.h 7KB
safestack.h 6KB
共 259 条
- 1
- 2
- 3
资源评论
- shx08162017-09-27测试可以编译通过,感谢分享
- maplewsh2020-10-27挺好用,就是积分贵
- ln_08072019-01-18不错,可以用,但是有个地方有问题,我修改了,谢谢
- code-player2017-10-16非常好的学习代码
- cheidtf2019-01-14东西还不错 以后还接着用。
dingzhaoyan
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功