/[resiprocate]/main/contrib/ares/ares_send.c
ViewVC logotype

Contents of /main/contrib/ares/ares_send.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5295 - (show annotations) (download)
Mon Aug 22 00:30:05 2005 UTC (14 years, 3 months ago) by jason
File MIME type: text/plain
File size: 2924 byte(s)
merged 5270:HEAD from b-directory-reorg
1 /* Copyright 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
14 */
15
16
17 #include <sys/types.h>
18
19 #ifndef WIN32
20 #include <netinet/in.h>
21 #ifndef __CYGWIN__
22 # include <arpa/nameser.h>
23 #endif
24 #endif
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include "ares.h"
30 #include "ares_dns.h"
31 #include "ares_private.h"
32
33 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
34 ares_callback callback, void *arg)
35 {
36 struct query *query;
37 int i;
38 time_t now;
39
40 /* Verify that the query is at least long enough to hold the header. */
41 if (qlen < HFIXEDSZ || qlen >= (1 << 16))
42 {
43 callback(arg, ARES_EBADQUERY, NULL, 0);
44 return;
45 }
46
47 /* Allocate space for query and allocated fields. */
48 query = malloc(sizeof(struct query));
49 if (!query)
50 {
51 callback(arg, ARES_ENOMEM, NULL, 0);
52 return;
53 }
54 query->tcpbuf = malloc(qlen + 2);
55 if (!query->tcpbuf)
56 {
57 free(query);
58 callback(arg, ARES_ENOMEM, NULL, 0);
59 return;
60 }
61 if (channel->nservers)
62 {
63 query->skip_server = malloc(channel->nservers * sizeof(int));
64 }
65 else
66 {
67 query->skip_server = 0;
68 }
69
70 if (!query->skip_server)
71 {
72 free(query->tcpbuf);
73 free(query);
74 callback(arg, ARES_ENOMEM, NULL, 0);
75 return;
76 }
77
78 /* Compute the query ID. Start with no timeout. */
79 query->qid = DNS_HEADER_QID(qbuf);
80 query->timeout = 0;
81
82 /* Form the TCP query buffer by prepending qlen (as two
83 * network-order bytes) to qbuf.
84 */
85 query->tcpbuf[0] = (qlen >> 8) & 0xff;
86 query->tcpbuf[1] = qlen & 0xff;
87 memcpy(query->tcpbuf + 2, qbuf, qlen);
88 query->tcplen = qlen + 2;
89
90 /* Fill in query arguments. */
91 query->qbuf = query->tcpbuf + 2;
92 query->qlen = qlen;
93 query->callback = callback;
94 query->arg = arg;
95
96 /* Initialize query status. */
97 query->try = 0;
98 query->server = 0;
99 for (i = 0; i < channel->nservers; i++)
100 query->skip_server[i] = 0;
101 query->using_tcp = (channel->flags & ARES_FLAG_USEVC) || qlen > PACKETSZ;
102 query->error_status = ARES_ECONNREFUSED;
103
104 /* Chain the query into this channel's query list. */
105 query->next = channel->queries;
106 channel->queries = query;
107
108 /* Perform the first query action. */
109 time(&now);
110 ares__send_query(channel, query, now);
111 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27