#include "ares_private.h"
#include "ares_dns.h"
Include dependency graph for ares_send.c:
Go to the source code of this file.
Functions | |
void | ares_send (ares_channel channel, const unsigned char *qbuf, int qlen, ares_callback callback, void *arg) |
|
Definition at line 26 of file ares_send.c. References ares__send_query(), ares_callback, ares_channel, ARES_EBADQUERY, ARES_ECONNREFUSED, ARES_ENOMEM, ARES_FLAG_USEVC, callback(), DNS_HEADER_QID, ares_channeldata::flags, free, HFIXEDSZ, malloc, ares_channeldata::nservers, NULL, PACKETSZ, ares_channeldata::queries, and time. Referenced by ares_query().
00028 { 00029 struct query *query; 00030 int i; 00031 time_t now; 00032 00033 /* Verify that the query is at least long enough to hold the header. */ 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 /* Allocate space for query and allocated fields. */ 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 /* Compute the query ID. Start with no timeout. */ 00068 query->qid = DNS_HEADER_QID(qbuf); 00069 query->timeout = 0; 00070 00071 /* Form the TCP query buffer by prepending qlen (as two 00072 * network-order bytes) to qbuf. 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 /* Fill in query arguments. */ 00080 query->qbuf = query->tcpbuf + 2; 00081 query->qlen = qlen; 00082 query->callback = callback; 00083 query->arg = arg; 00084 00085 /* Initialize query status. */ 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 /* Chain the query into this channel's query list. */ 00094 query->next = channel->queries; 00095 channel->queries = query; 00096 00097 /* Perform the first query action. */ 00098 time(&now); 00099 ares__send_query(channel, query, now); 00100 } |
Here is the call graph for this function: