+++ /dev/null
-/*\r
- * Copyright (c) 1985, 1993\r
- * The Regents of the University of California. All rights reserved.\r
- *\r
- * Portions copyright (c) 1999, 2000\r
- * Intel Corporation.\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- *\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * 3. All advertising materials mentioning features or use of this software\r
- * must display the following acknowledgement:\r
- *\r
- * This product includes software developed by the University of\r
- * California, Berkeley, Intel Corporation, and its contributors.\r
- *\r
- * 4. Neither the name of University, Intel Corporation, or their respective\r
- * contributors may be used to endorse or promote products derived from\r
- * this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS,\r
- * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- */\r
-\r
-/*\r
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies, and that\r
- * the name of Digital Equipment Corporation not be used in advertising or\r
- * publicity pertaining to distribution of the document or software without\r
- * specific, written prior permission.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT\r
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- */\r
-\r
-/*\r
- * Portions Copyright (c) 1996 by Internet Software Consortium.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- */\r
-\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";\r
-static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $";\r
-static char rcsid[] = "$Id: res_mkquery.c,v 1.1.1.1 2003/11/19 01:51:37 kyu3 Exp $";\r
-#endif /* LIBC_SCCS and not lint */\r
-\r
-#include <sys/types.h>\r
-#include <sys/param.h>\r
-#include <netinet/in.h>\r
-#include <arpa/nameser.h>\r
-#include <netdb.h>\r
-#include <resolv.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-\r
-#include "res_config.h"\r
-\r
-/*\r
- * Form all types of queries.\r
- * Returns the size of the result or -1.\r
- */\r
-int\r
-res_mkquery(\r
- int op, /* opcode of query */\r
- const char *dname, /* domain name */\r
- int class, /* class of query */\r
- int type, /* type of query */\r
- const u_char *data, /* resource record data */\r
- int datalen, /* length of data */\r
- const u_char *newrr_in, /* new rr for modify or append */\r
- u_char *buf, /* buffer to put query */\r
- int buflen /* size of buffer */\r
- )\r
-{\r
- register HEADER *hp;\r
- register u_char *cp;\r
- register int n;\r
- u_char *dnptrs[20], **dpp, **lastdnptr;\r
-\r
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {\r
- h_errno = NETDB_INTERNAL;\r
- return (-1);\r
- }\r
-#ifdef DEBUG\r
- if (_res.options & RES_DEBUG)\r
- printf(";; res_mkquery(%d, %s, %d, %d)\n",\r
- op, dname, class, type);\r
-#endif\r
- /*\r
- * Initialize header fields.\r
- */\r
- if ((buf == NULL) || (buflen < HFIXEDSZ))\r
- return (-1);\r
- memset(buf, 0, HFIXEDSZ);\r
- hp = (HEADER *) buf;\r
- hp->id = htons(++_res.id);\r
- hp->opcode = op;\r
- hp->rd = (_res.options & RES_RECURSE) != 0;\r
- hp->rcode = NOERROR;\r
- cp = buf + HFIXEDSZ;\r
- buflen -= HFIXEDSZ;\r
- dpp = dnptrs;\r
- *dpp++ = buf;\r
- *dpp++ = NULL;\r
- lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];\r
- /*\r
- * perform opcode specific processing\r
- */\r
- switch (op) {\r
- case QUERY: /*FALLTHROUGH*/\r
- case NS_NOTIFY_OP:\r
- if ((buflen -= QFIXEDSZ) < 0)\r
- return (-1);\r
- if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)\r
- return (-1);\r
- cp += n;\r
- buflen -= n;\r
- __putshort((u_int16_t)type, cp);\r
- cp += INT16SZ;\r
- __putshort((u_int16_t)class, cp);\r
- cp += INT16SZ;\r
- hp->qdcount = htons(1);\r
- if (op == QUERY || data == NULL)\r
- break;\r
- /*\r
- * Make an additional record for completion domain.\r
- */\r
- buflen -= RRFIXEDSZ;\r
- n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);\r
- if (n < 0)\r
- return (-1);\r
- cp += n;\r
- buflen -= n;\r
- __putshort(T_NULL, cp);\r
- cp += INT16SZ;\r
- __putshort((u_int16_t)class, cp);\r
- cp += INT16SZ;\r
- __putlong(0, cp);\r
- cp += INT32SZ;\r
- __putshort(0, cp);\r
- cp += INT16SZ;\r
- hp->arcount = htons(1);\r
- break;\r
-\r
- case IQUERY:\r
- /*\r
- * Initialize answer section\r
- */\r
- if (buflen < 1 + RRFIXEDSZ + datalen)\r
- return (-1);\r
- *cp++ = '\0'; /* no domain name */\r
- __putshort((u_int16_t)type, cp);\r
- cp += INT16SZ;\r
- __putshort((u_int16_t)class, cp);\r
- cp += INT16SZ;\r
- __putlong(0, cp);\r
- cp += INT32SZ;\r
- __putshort((u_int16_t)datalen, cp);\r
- cp += INT16SZ;\r
- if (datalen) {\r
- memcpy(cp, data, datalen);\r
- cp += datalen;\r
- }\r
- hp->ancount = htons(1);\r
- break;\r
-\r
- default:\r
- return (-1);\r
- }\r
- return ((int)(cp - buf));\r
-}\r