00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ares_private.h"
00024 #include "ares_dns.h"
00025
00026 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
00027 ares_callback callback, void *arg)
00028 {
00029 struct query *query;
00030 int i;
00031 time_t now;
00032
00033
00034 if (qlen < HFIXEDSZ
00035 #ifndef LWIP
00036 || qlen >= (1 << 16)
00037 #endif
00038 )
00039 {
00040 callback(arg, ARES_EBADQUERY, NULL, 0);
00041 return;
00042 }
00043
00044
00045 query = malloc(sizeof(struct query));
00046 if (!query)
00047 {
00048 callback(arg, ARES_ENOMEM, NULL, 0);
00049 return;
00050 }
00051 query->tcpbuf = malloc(qlen + 2);
00052 if (!query->tcpbuf)
00053 {
00054 free(query);
00055 callback(arg, ARES_ENOMEM, NULL, 0);
00056 return;
00057 }
00058 query->skip_server = malloc(channel->nservers * sizeof(int));
00059 if (!query->skip_server)
00060 {
00061 free(query->tcpbuf);
00062 free(query);
00063 callback(arg, ARES_ENOMEM, NULL, 0);
00064 return;
00065 }
00066
00067
00068 query->qid = DNS_HEADER_QID(qbuf);
00069 query->timeout = 0;
00070
00071
00072
00073
00074 query->tcpbuf[0] = (qlen >> 8) & 0xff;
00075 query->tcpbuf[1] = qlen & 0xff;
00076 memcpy(query->tcpbuf + 2, qbuf, qlen);
00077 query->tcplen = qlen + 2;
00078
00079
00080 query->qbuf = query->tcpbuf + 2;
00081 query->qlen = qlen;
00082 query->callback = callback;
00083 query->arg = arg;
00084
00085
00086 query->try = 0;
00087 query->server = 0;
00088 for (i = 0; i < channel->nservers; i++)
00089 query->skip_server[i] = 0;
00090 query->using_tcp = (channel->flags & ARES_FLAG_USEVC) || qlen > PACKETSZ;
00091 query->error_status = ARES_ECONNREFUSED;
00092
00093
00094 query->next = channel->queries;
00095 channel->queries = query;
00096
00097
00098 time(&now);
00099 ares__send_query(channel, query, now);
00100 }