mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
r9097@Kushana: nickm | 2006-10-05 14:51:57 -0400
Make eventdns.c formatting a little closer to evdns.c in libevent; add some bulletproofing to APPEND16 macro; clean some messages. svn:r8600
This commit is contained in:
parent
64b5fd3194
commit
4767d533f7
@ -418,7 +418,7 @@ static int search_try_next(struct request *const req);
|
||||
static int search_request_new(int type, const char *const name, int flags, evdns_callback_type user_callback, void *user_arg);
|
||||
static void evdns_requests_pump_waiting_queue(void);
|
||||
static u16 transaction_id_pick(void);
|
||||
static struct request *request_new(int type, const char *name, int flags, evdns_callback_type, void *ptr);
|
||||
static struct request *request_new(int type, const char *name, int flags, evdns_callback_type callback, void *ptr);
|
||||
static void request_submit(struct request *req);
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
@ -785,7 +785,6 @@ reply_handle(struct request *const req,
|
||||
// we regard these errors as marking a bad nameserver
|
||||
if (req->reissue_count < global_max_reissues) {
|
||||
char msg[64];
|
||||
|
||||
snprintf(msg, sizeof(msg), "Bad response %d (%s)",
|
||||
error, evdns_err_to_string(error));
|
||||
nameserver_failed(req->ns, msg);
|
||||
@ -924,9 +923,9 @@ reply_parse(u8 *packet, int length) {
|
||||
|
||||
// now we have the answer section which looks like
|
||||
// <label:name><u16:type><u16:class><u32:ttl><u16:len><data...>
|
||||
|
||||
for (i = 0; i < answers; ++i) {
|
||||
u16 type, class;
|
||||
//int pre = j;
|
||||
|
||||
// XXX I'd be more comfortable if we actually checked the name
|
||||
// here. -NM
|
||||
@ -947,6 +946,7 @@ reply_parse(u8 *packet, int length) {
|
||||
addrcount = datalength >> 2; // each IP address is 4 bytes
|
||||
addrtocopy = MIN(MAX_ADDRS - reply.data.a.addrcount, (unsigned)addrcount);
|
||||
ttl_r = MIN(ttl_r, ttl);
|
||||
|
||||
// we only bother with the first four addresses.
|
||||
if (j + 4*addrtocopy > length) return -1;
|
||||
memcpy(&reply.data.a.addresses[reply.data.a.addrcount],
|
||||
@ -1189,7 +1189,14 @@ evdns_request_data_build(const char *const name, const int name_len, const u16 t
|
||||
u8 *labels;
|
||||
int labels_len;
|
||||
|
||||
#define APPEND16(x) do { _t = htons(x); memcpy(buf + j, &_t, 2); j += 2; } while(0);
|
||||
#define APPEND16(x) do { \
|
||||
if (j + 2 > buf_len) \
|
||||
return (-1); \
|
||||
_t = htons(x); \
|
||||
memcpy(buf + j, &_t, 2); \
|
||||
j += 2; \
|
||||
} while (0)
|
||||
|
||||
APPEND16(trans_id);
|
||||
APPEND16(0x0100); // standard query, recusion needed
|
||||
APPEND16(1); // one question
|
||||
@ -1337,6 +1344,7 @@ nameserver_send_probe(struct nameserver *const ns) {
|
||||
// in the hope that it is up now.
|
||||
|
||||
log(EVDNS_LOG_DEBUG, "Sending probe to %s", debug_ntoa(ns->address));
|
||||
|
||||
req = request_new(TYPE_A, "www.google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_callback, ns);
|
||||
if (!req) return;
|
||||
// we force this into the inflight queue no matter what
|
||||
@ -1563,9 +1571,12 @@ request_new(int type, const char *name, int flags, evdns_callback_type callback,
|
||||
|
||||
// request data lives just after the header
|
||||
req->request = ((u8 *) req) + sizeof(struct request);
|
||||
req->request_appended = 1; // denotes that the request data shouldn't be free()ed
|
||||
rlen = evdns_request_data_build(name, name_len, trans_id, type, CLASS_INET, req->request, request_max_len);
|
||||
if (rlen < 0) goto err1;
|
||||
// denotes that the request data shouldn't be free()ed
|
||||
req->request_appended = 1;
|
||||
rlen = evdns_request_data_build(name, name_len, trans_id,
|
||||
type, CLASS_INET, req->request, request_max_len);
|
||||
if (rlen < 0)
|
||||
goto err1;
|
||||
req->request_len = rlen;
|
||||
req->trans_id = trans_id;
|
||||
req->tx_count = 0;
|
||||
@ -1596,11 +1607,14 @@ request_submit(struct request *const req) {
|
||||
}
|
||||
|
||||
// exported function
|
||||
int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr) {
|
||||
int evdns_resolve_ipv4(const char *name, int flags,
|
||||
evdns_callback_type callback, void *ptr) {
|
||||
log(EVDNS_LOG_DEBUG, "Resolve requested for %s", name);
|
||||
if (flags & DNS_QUERY_NO_SEARCH) {
|
||||
struct request *const req = request_new(TYPE_A, name, flags, callback, ptr);
|
||||
if (!req) return 1;
|
||||
struct request *const req =
|
||||
request_new(TYPE_A, name, flags, callback, ptr);
|
||||
if (req == NULL)
|
||||
return 1;
|
||||
request_submit(req);
|
||||
return 0;
|
||||
} else {
|
||||
@ -1975,7 +1989,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) {
|
||||
char *start;
|
||||
int err = 0;
|
||||
|
||||
log(EVDNS_LOG_DEBUG,"Parsing resolve.conf file %s", filename);
|
||||
log(EVDNS_LOG_DEBUG, "Parsing resolv.conf file %s", filename);
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
@ -2071,9 +2085,7 @@ load_nameservers_with_getnetworkparams(void) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!(fn =
|
||||
(GetNetworkParams_fn_t)
|
||||
GetProcAddress(handle, "GetNetworkParams"))) {
|
||||
if (!(fn = (GetNetworkParams_fn_t) GetProcAddress(handle, "GetNetworkParams"))) {
|
||||
log(EVDNS_LOG_WARN, "Could not get address of function.");
|
||||
//same as above
|
||||
status = -1;
|
||||
@ -2158,7 +2170,6 @@ config_nameserver_from_reg_key(HKEY key, const char *subkey) {
|
||||
}
|
||||
|
||||
#define SERVICES_KEY "System\\CurrentControlSet\\Services\\"
|
||||
|
||||
#define WIN_NS_9X_KEY SERVICES_KEY "VxD\\MSTCP"
|
||||
#define WIN_NS_NT_KEY SERVICES_KEY "Tcpip\\Parameters"
|
||||
|
||||
@ -2170,8 +2181,7 @@ load_nameservers_from_registry(void) {
|
||||
if (!found && config_nameserver_from_reg_key(k,name) == 0) { \
|
||||
log(EVDNS_LOG_DEBUG,"Found nameservers in %s/%s",#k,name); \
|
||||
found = 1; \
|
||||
} else { \
|
||||
if (!found) \
|
||||
} else if (!found) { \
|
||||
log(EVDNS_LOG_DEBUG,"Didn't find nameservers in %s/%s", \
|
||||
#k,#name); \
|
||||
}
|
||||
@ -2184,16 +2194,13 @@ load_nameservers_from_registry(void) {
|
||||
log(EVDNS_LOG_DEBUG,"Couldn't open nt key, %d",(int)GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = RegOpenKeyEx(nt_key, "Interfaces", 0,
|
||||
KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS,
|
||||
&interfaces_key);
|
||||
|
||||
if (r != ERROR_SUCCESS) {
|
||||
log(EVDNS_LOG_DEBUG,"Couldn't open interfaces key, %d",(int)GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
TRY(nt_key, "NameServer");
|
||||
TRY(nt_key, "DhcpNameServer");
|
||||
TRY(interfaces_key, "NameServer");
|
||||
@ -2206,7 +2213,6 @@ load_nameservers_from_registry(void) {
|
||||
KEY_READ, &win_key) != ERROR_SUCCESS) {
|
||||
log(EVDNS_LOG_DEBUG, "Couldn't open registry key, %d", (int)GetLastError());
|
||||
return -1;
|
||||
|
||||
}
|
||||
TRY(win_key, "NameServer");
|
||||
RegCloseKey(win_key);
|
||||
@ -2222,9 +2228,8 @@ load_nameservers_from_registry(void) {
|
||||
|
||||
int
|
||||
evdns_config_windows_nameservers(void) {
|
||||
if (load_nameservers_with_getnetworkparams() == 0) {
|
||||
if (load_nameservers_with_getnetworkparams() == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return load_nameservers_from_registry();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user