Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

ares_send.c

Go to the documentation of this file.
00001 /* Copyright 1998 by the Massachusetts Institute of Technology.
00002  *
00003  * Permission to use, copy, modify, and distribute this
00004  * software and its documentation for any purpose and without
00005  * fee is hereby granted, provided that the above copyright
00006  * notice appear in all copies and that both that copyright
00007  * notice and this permission notice appear in supporting
00008  * documentation, and that the name of M.I.T. not be used in
00009  * advertising or publicity pertaining to distribution of the
00010  * software without specific, written prior permission.
00011  * M.I.T. makes no representations about the suitability of
00012  * this software for any purpose.  It is provided "as is"
00013  * without express or implied warranty.
00014  *
00015  * CHANGELOG: this file has been modified by Sergio Perez Alcañiz <serpeal@disca.upv.es> 
00016  *            Departamento de Informática de Sistemas y Computadores          
00017  *            Universidad Politécnica de Valencia                             
00018  *            Valencia (Spain)    
00019  *            Date: April 2003                                          
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   /* 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 }

Generated on Wed Jan 14 12:58:56 2004 for RTL-lwIP-0.4 by doxygen 1.3.4