summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-09-29 16:19:27 +0200
committerLennart Poettering <lennart@poettering.net>2008-09-29 16:19:27 +0200
commit3aa298c6e6426c43f9a48e115885b91b29e411fe (patch)
tree1d30b8717a8fe39c9659083a06863c71e9b32629
parentc6c6396ccb8d67c398d5dfa3d309714e737401d3 (diff)
restore h_errno in addition to errno
-rw-r--r--libasyncns/asyncns.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/libasyncns/asyncns.c b/libasyncns/asyncns.c
index b4d7087..d010b66 100644
--- a/libasyncns/asyncns.c
+++ b/libasyncns/asyncns.c
@@ -102,6 +102,7 @@ struct asyncns_query {
asyncns_query_t *done_next, *done_prev;
int ret;
int _errno;
+ int _h_errno;
struct addrinfo *addrinfo;
char *serv, *host;
void *userdata;
@@ -127,6 +128,7 @@ typedef struct addrinfo_response {
struct rheader header;
int ret;
int _errno;
+ int _h_errno;
/* followed by addrinfo_serialization[] */
} addrinfo_response_t;
@@ -152,6 +154,7 @@ typedef struct nameinfo_response {
size_t hostlen, servlen;
int ret;
int _errno;
+ int _h_errno;
} nameinfo_response_t;
typedef struct res_query_request {
@@ -165,6 +168,7 @@ typedef struct res_query_response {
struct rheader header;
int ret;
int _errno;
+ int _h_errno;
} res_response_t;
#ifndef HAVE_STRNDUP
@@ -411,7 +415,7 @@ static void *serialize_addrinfo(void *p, const struct addrinfo *ai, size_t *leng
return (uint8_t*) p + l;
}
-static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo *ai, int _errno) {
+static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo *ai, int _errno, int _h_errno) {
addrinfo_response_t data[BUFSIZE/sizeof(addrinfo_response_t) + 1];
addrinfo_response_t *resp = data;
assert(out_fd >= 0);
@@ -422,6 +426,7 @@ static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo
resp->header.length = sizeof(addrinfo_response_t);
resp->ret = ret;
resp->_errno = _errno;
+ resp->_h_errno = _h_errno;
if (ret == 0 && ai) {
void *p = data + 1;
@@ -442,7 +447,7 @@ static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo
return send(out_fd, resp, resp->header.length, 0);
}
-static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *host, const char *serv, int _errno) {
+static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *host, const char *serv, int _errno, int _h_errno) {
nameinfo_response_t data[BUFSIZE/sizeof(nameinfo_response_t) + 1];
size_t hl, sl;
nameinfo_response_t *resp = data;
@@ -458,6 +463,7 @@ static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *hos
resp->header.length = sizeof(nameinfo_response_t) + hl + sl;
resp->ret = ret;
resp->_errno = _errno;
+ resp->_h_errno = _h_errno;
resp->hostlen = hl;
resp->servlen = sl;
@@ -472,7 +478,7 @@ static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *hos
return send(out_fd, resp, resp->header.length, 0);
}
-static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer, int ret, int _errno) {
+static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer, int ret, int _errno, int _h_errno) {
res_response_t data[BUFSIZE/sizeof(res_response_t) + 1];
res_response_t *resp = data;
@@ -484,6 +490,7 @@ static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer,
resp->header.length = sizeof(res_response_t) + (ret < 0 ? 0 : ret);
resp->ret = ret;
resp->_errno = _errno;
+ resp->_h_errno = _h_errno;
assert(sizeof(data) >= resp->header.length);
@@ -523,7 +530,7 @@ static int handle_request(int out_fd, const rheader_t *req, size_t length) {
&result);
/* send_addrinfo_reply() frees result */
- return send_addrinfo_reply(out_fd, req->id, ret, result, errno);
+ return send_addrinfo_reply(out_fd, req->id, ret, result, errno, h_errno);
}
case REQUEST_NAMEINFO: {
@@ -545,7 +552,7 @@ static int handle_request(int out_fd, const rheader_t *req, size_t length) {
return send_nameinfo_reply(out_fd, req->id, ret,
ret == 0 && ni_req->gethost ? hostbuf : NULL,
ret == 0 && ni_req->getserv ? servbuf : NULL,
- errno);
+ errno, h_errno);
}
case REQUEST_RES_QUERY:
@@ -565,7 +572,7 @@ static int handle_request(int out_fd, const rheader_t *req, size_t length) {
else
ret = res_search(dname, res_req->class, res_req->type, (unsigned char *) answer, BUFSIZE);
- return send_res_reply(out_fd, req->id, (unsigned char *) answer, ret, errno);
+ return send_res_reply(out_fd, req->id, (unsigned char *) answer, ret, errno, h_errno);
}
case REQUEST_TERMINATE:
@@ -987,6 +994,7 @@ static int handle_response(asyncns_t *asyncns, rheader_t *resp, size_t length) {
q->ret = ai_resp->ret;
q->_errno = ai_resp->_errno;
+ q->_h_errno = ai_resp->_h_errno;
l = length - sizeof(addrinfo_response_t);
p = (uint8_t*) resp + sizeof(addrinfo_response_t);
@@ -1019,6 +1027,7 @@ static int handle_response(asyncns_t *asyncns, rheader_t *resp, size_t length) {
q->ret = ni_resp->ret;
q->_errno = ni_resp->_errno;
+ q->_h_errno = ni_resp->_h_errno;
if (ni_resp->hostlen)
if (!(q->host = strndup((const char*) ni_resp + sizeof(nameinfo_response_t), ni_resp->hostlen-1)))
@@ -1040,6 +1049,7 @@ static int handle_response(asyncns_t *asyncns, rheader_t *resp, size_t length) {
q->ret = res_resp->ret;
q->_errno = res_resp->_errno;
+ q->_h_errno = res_resp->_h_errno;
if (res_resp->ret >= 0) {
if (!(q->serv = malloc(res_resp->ret))) {
@@ -1129,6 +1139,7 @@ static asyncns_query_t *alloc_query(asyncns_t *asyncns) {
q->done_next = q->done_prev = NULL;
q->ret = 0;
q->_errno = 0;
+ q->_h_errno = 0;
q->addrinfo = NULL;
q->userdata = NULL;
q->host = q->serv = NULL;
@@ -1213,6 +1224,9 @@ int asyncns_getaddrinfo_done(asyncns_t *asyncns, asyncns_query_t* q, struct addr
if (ret == EAI_SYSTEM)
errno = q->_errno;
+ if (ret != 0)
+ h_errno = q->_h_errno;
+
asyncns_cancel(asyncns, q);
return ret;
@@ -1297,6 +1311,9 @@ int asyncns_getnameinfo_done(asyncns_t *asyncns, asyncns_query_t* q, char *ret_h
if (ret == EAI_SYSTEM)
errno = q->_errno;
+ if (ret != 0)
+ h_errno = q->_h_errno;
+
asyncns_cancel(asyncns, q);
return ret;
@@ -1379,8 +1396,10 @@ int asyncns_res_done(asyncns_t *asyncns, asyncns_query_t* q, unsigned char **ans
ret = q->ret;
- if (ret < 0)
+ if (ret < 0) {
errno = q->_errno;
+ h_errno = q->_h_errno;
+ }
asyncns_cancel(asyncns, q);