reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ares_send.c
Go to the documentation of this file.
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 "ares_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
33void 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 {
44 return;
45 }
46
47 if (channel->nservers < 1)
48 {
50 return;
51 }
52
53 /* Allocate space for query and allocated fields. */
54 query = malloc(sizeof(struct query));
55 if (!query)
56 {
58 return;
59 }
60 query->tcpbuf = malloc(qlen + 2);
61 if (!query->tcpbuf)
62 {
63 free(query);
65 return;
66 }
67 query->skip_server = malloc(channel->nservers * sizeof(int));
68 if (!query->skip_server)
69 {
71 free(query);
73 return;
74 }
75
76 /* Compute the query ID. Start with no timeout. */
78 query->timeout = 0;
79
80 /* Form the TCP query buffer by prepending qlen (as two
81 * network-order bytes) to qbuf.
82 */
83 query->tcpbuf[0] = (qlen >> 8) & 0xff;
84 query->tcpbuf[1] = qlen & 0xff;
85 memcpy(query->tcpbuf + 2, qbuf, qlen);
86 query->tcplen = qlen + 2;
87
88 /* Fill in query arguments. */
89 query->qbuf = query->tcpbuf + 2;
90 query->qlen = qlen;
92 query->arg = arg;
93
94 /* Initialize query status. */
95 query->itry = 0;
96 query->server = 0;
97 for (i = 0; i < channel->nservers; i++)
98 query->skip_server[i] = 0;
99 query->using_tcp = (channel->flags & ARES_FLAG_USEVC) || qlen > PACKETSZ;
101
102 /* Chain the query into this channel's query list. */
103 query->next = channel->queries;
104 channel->queries = query;
105
106 /* Perform the first query action. */
107 time(&now);
108 ares__send_query(channel, query, now);
109}
static void callback(void *arg, int status, unsigned char *abuf, int alen)
Definition adig.c:388
#define ARES_ENOMEM
Definition ares.h:98
#define ARES_ECONNREFUSED
Definition ares.h:94
#define ARES_FLAG_USEVC
Definition ares.h:102
#define ARES_EBADQUERY
Definition ares.h:90
void(* ares_callback)(void *arg, int status, unsigned char *abuf, int alen)
Definition ares.h:172
#define ARES_ESERVFAIL
Definition ares.h:84
#define DNS_HEADER_QID(h)
Definition ares_dns.h:30
#define PACKETSZ
void ares__send_query(ares_channel channel, struct query *query, time_t now)
void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen, ares_callback callback, void *arg)
Definition ares_send.c:33
struct query * queries
int using_tcp
const char * qbuf
void * arg
struct query * next
int server
ares_callback callback
int qlen
int * skip_server
unsigned short qid
int tcplen
time_t timeout
char * tcpbuf
int error_status
void list()
Definition userAdmin.cxx:66