2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
37 * Permission to use, copy, modify, and distribute this software for any
38 * purpose with or without fee is hereby granted, provided that the above
39 * copyright notice and this permission notice appear in all copies, and that
40 * the name of Digital Equipment Corporation not be used in advertising or
41 * publicity pertaining to distribution of the document or software without
42 * specific, written prior permission.
44 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
47 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
57 * Permission to use, copy, modify, and distribute this software for any
58 * purpose with or without fee is hereby granted, provided that the above
59 * copyright notice and this permission notice appear in all copies.
61 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
62 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
63 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
64 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
65 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
66 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
67 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
71 /* Original copyright ISC as above.
72 * Code modified specifically for ircd use from the following orginal files
85 #include "ircd_reslib.h"
86 #include "ircd_defs.h"
88 #include "ircd_string.h"
89 #include "ircd_addrinfo.h"
97 #define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */
98 #define DNS_LABELTYPE_BITSTRING 0x41
103 struct irc_ssaddr irc_nsaddr_list[IRCD_MAXNS];
105 char irc_domain[HOSTLEN + 1];
107 static const char digitvalue[256] = {
108 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
109 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
110 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
111 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
112 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
113 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
114 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
115 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
116 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
117 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
118 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
119 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
120 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
121 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
123 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
126 static int parse_resvconf(void);
127 static void add_nameserver(char *arg);
129 static const char digits[] = "0123456789";
130 static int labellen(const unsigned char *lp);
131 static int special(int ch);
132 static int printable(int ch);
133 static int irc_decode_bitstring(const char **cpp, char *dn, const char *eom);
134 static int irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz,
135 const unsigned char **dnptrs, const unsigned char **lastdnptr);
136 static int irc_dn_find(const unsigned char *, const unsigned char *, const unsigned char * const *,
137 const unsigned char * const *);
138 static int irc_encode_bitsring(const char **, const char *, unsigned char **, unsigned char **,
140 static int mklower(int ch);
146 return(parse_resvconf());
152 * output - -1 if failure 0 if success
153 * side effects - fills in irc_nsaddr_list
164 /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps
165 * for cygwin support etc. this hardcodes it to unix for now -db
167 if ((file = fbopen("/etc/resolv.conf", "r")) == NULL)
170 while (fbgets(input, MAXLINE, file) != NULL)
172 /* blow away any newline */
173 if ((p = strpbrk(input, "\r\n")) != NULL)
176 /* Ignore comment lines immediately */
181 /* skip until something thats not a space is seen */
184 /* if at this point, have a '\0' then continue */
188 /* skip until a space is found */
192 continue; /* no arguments?.. ignore this line */
193 /* blow away the space character */
196 /* skip these spaces that are before the argument */
199 /* Now arg should be right where p is pointing */
201 if ((p = strpbrk(arg, " \t")) != NULL)
202 *p = '\0'; /* take the first word */
204 if (strcasecmp(opt, "domain") == 0)
205 ircd_strncpy(irc_domain, arg, HOSTLEN);
206 else if (strcasecmp(opt, "nameserver") == 0)
216 * input - either an IPV4 address in dotted quad
217 * or an IPV6 address in : format
219 * side effects - entry in irc_nsaddr_list is filled in as needed
222 add_nameserver(char *arg)
224 struct addrinfo hints, *res;
225 /* Done max number of nameservers? */
226 if ((irc_nscount + 1) >= IRCD_MAXNS)
229 memset(&hints, 0, sizeof(hints));
230 hints.ai_family = PF_UNSPEC;
231 hints.ai_socktype = SOCK_DGRAM;
232 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
234 if (irc_getaddrinfo(arg, "domain", &hints, &res))
240 memcpy(&irc_nsaddr_list[irc_nscount].ss, res->ai_addr, res->ai_addrlen);
241 irc_nsaddr_list[irc_nscount].ss_len = res->ai_addrlen;
243 irc_freeaddrinfo(res);
247 * Expand compressed domain name 'comp_dn' to full domain name.
248 * 'msg' is a pointer to the begining of the message,
249 * 'eomorig' points to the first location after the message,
250 * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
251 * Return size of compressed name or -1 if there was an error.
254 irc_dn_expand(const unsigned char *msg, const unsigned char *eom,
255 const unsigned char *src, char *dst, int dstsiz)
257 int n = irc_ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
259 if (n > 0 && dst[0] == '.')
265 * irc_ns_name_uncompress(msg, eom, src, dst, dstsiz)
266 * Expand compressed domain name to presentation format.
268 * Number of bytes read out of `src', or -1 (with errno set).
270 * Root domain returns as "." not "".
273 irc_ns_name_uncompress(const unsigned char *msg, const unsigned char *eom,
274 const unsigned char *src, char *dst, size_t dstsiz)
276 unsigned char tmp[NS_MAXCDNAME];
279 if ((n = irc_ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
281 if (irc_ns_name_ntop(tmp, dst, dstsiz) == -1)
286 * irc_ns_name_unpack(msg, eom, src, dst, dstsiz)
287 * Unpack a domain name from a message, source may be compressed.
289 * -1 if it fails, or consumed octets if it succeeds.
292 irc_ns_name_unpack(const unsigned char *msg, const unsigned char *eom,
293 const unsigned char *src, unsigned char *dst,
296 const unsigned char *srcp, *dstlim;
298 int n, len, checked, l;
304 dstlim = dst + dstsiz;
305 if (srcp < msg || srcp >= eom) {
309 /* Fetch next label in domain name. */
310 while ((n = *srcp++) != 0) {
311 /* Check for indirection. */
312 switch (n & NS_CMPRSFLGS) {
316 if ((l = labellen(srcp - 1)) < 0) {
320 if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
326 memcpy(dstp, srcp, l);
337 len = srcp - src + 1;
338 srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
339 if (srcp < msg || srcp >= eom) { /* Out of range. */
345 * Check for loops in the compressed name;
346 * if we've looked at the whole message,
347 * there must be a loop.
349 if (checked >= eom - msg) {
357 return (-1); /* flag error */
367 * irc_ns_name_ntop(src, dst, dstsiz)
368 * Convert an encoded domain name to printable ascii as per RFC1035.
370 * Number of bytes written to buffer, or -1 (with errno set)
372 * The root is returned as "."
373 * All other domains are returned in non absolute form
376 irc_ns_name_ntop(const char *src, char *dst, size_t dstsiz)
388 while ((n = *cp++) != 0) {
389 if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
390 /* Some kind of compression pointer. */
401 if ((l = labellen(cp - 1)) < 0) {
402 errno = EMSGSIZE; /* XXX */
409 if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) {
412 if (n != DNS_LABELTYPE_BITSTRING) {
413 /* XXX: labellen should reject this case */
417 if ((m = irc_decode_bitstring(&cp, dn, eom)) < 0)
425 for ((void)NULL; l > 0; l--) {
434 } else if (!printable(c)) {
440 *dn++ = digits[c / 100];
441 *dn++ = digits[(c % 100) / 10];
442 *dn++ = digits[c % 10];
468 * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
469 * Return the size of the compressed name or -1.
470 * 'length' is the size of the array pointed to by 'comp_dn'.
473 irc_dn_comp(const char *src, unsigned char *dst, int dstsiz,
474 unsigned char **dnptrs, unsigned char **lastdnptr)
476 return(irc_ns_name_compress(src, dst, (size_t)dstsiz,
477 (const unsigned char **)dnptrs,
478 (const unsigned char **)lastdnptr));
482 * Skip over a compressed domain name. Return the size or -1.
485 irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom) {
486 const unsigned char *saveptr = ptr;
488 if (irc_ns_name_skip(&ptr, eom) == -1)
490 return(ptr - saveptr);
494 * ns_name_skip(ptrptr, eom)
495 * Advance *ptrptr to skip over the compressed name it points at.
497 * 0 on success, -1 (with errno set) on failure.
500 irc_ns_name_skip(const unsigned char **ptrptr, const unsigned char *eom)
502 const unsigned char *cp;
508 while (cp < eom && (n = *cp++) != 0)
510 /* Check for indirection. */
511 switch (n & NS_CMPRSFLGS)
513 case 0: /* normal case, n == len */
516 case NS_TYPE_ELT: /* EDNS0 extended label */
517 if ((l = labellen(cp - 1)) < 0)
519 errno = EMSGSIZE; /* XXX */
525 case NS_CMPRSFLGS: /* indirection */
528 default: /* illegal type */
547 irc_ns_get16(const unsigned char *src)
551 IRC_NS_GET16(dst, src);
556 irc_ns_get32(const unsigned char *src)
560 IRC_NS_GET32(dst, src);
565 irc_ns_put16(unsigned int src, unsigned char *dst)
567 IRC_NS_PUT16(src, dst);
571 irc_ns_put32(unsigned long src, unsigned char *dst)
573 IRC_NS_PUT32(src, dst);
580 * Thinking in noninternationalized USASCII (per the DNS spec),
581 * is this characted special ("in need of quoting") ?
593 case 0x5C: /* '\\' */
596 /* Special modifiers in zone files. */
606 labellen(const unsigned char *lp)
609 unsigned char l = *lp;
611 if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS)
613 /* should be avoided by the caller */
617 if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT)
619 if (l == DNS_LABELTYPE_BITSTRING)
621 if ((bitlen = *(lp + 1)) == 0)
623 return((bitlen + 7 ) / 8 + 1);
626 return(-1); /* unknwon ELT */
635 * Thinking in noninternationalized USASCII (per the DNS spec),
636 * is this character visible and not a space when printed ?
643 return(ch > 0x20 && ch < 0x7f);
647 irc_decode_bitstring(const char **cpp, char *dn, const char *eom)
649 const char *cp = *cpp;
653 if ((blen = (*cp & 0xff)) == 0)
655 plen = (blen + 3) / 4;
656 plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
657 if (dn + plen >= eom)
661 dn += sprintf(dn, "\\[x");
662 for (b = blen; b > 7; b -= 8, cp++)
663 dn += sprintf(dn, "%02x", *cp & 0xff);
666 dn += sprintf(dn, "%02x", tc & (0xff << (8 - b)));
669 dn += sprintf(dn, "%1x",
670 ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
672 dn += sprintf(dn, "/%d]", blen);
679 * irc_ns_name_pton(src, dst, dstsiz)
680 * Convert a ascii string into an encoded domain name as per RFC1035.
683 * 1 if string was fully qualified
684 * 0 is string was not fully qualified
686 * Enforces label and domain length limits.
689 irc_ns_name_pton(const char *src, unsigned char *dst, size_t dstsiz)
691 unsigned char *label, *bp, *eom;
693 int c, n, escaped, e = 0;
701 while ((c = *src++) != 0) {
703 if (c == '[') { /* start a bit string label */
704 if ((cp = strchr(src, ']')) == NULL) {
705 errno = EINVAL; /* ??? */
708 if ((e = irc_encode_bitsring(&src,
719 if ((c = *src++) == 0)
727 else if ((cp = strchr(digits, c)) != NULL) {
728 n = (cp - digits) * 100;
729 if ((c = *src++) == 0 ||
730 (cp = strchr(digits, c)) == NULL) {
734 n += (cp - digits) * 10;
735 if ((c = *src++) == 0 ||
736 (cp = strchr(digits, c)) == NULL) {
748 } else if (c == '\\') {
751 } else if (c == '.') {
752 c = (bp - label - 1);
753 if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
762 /* Fully qualified ? */
771 if ((bp - dst) > NS_MAXCDNAME) {
777 if (c == 0 || *src == '.') {
788 *bp++ = (unsigned char)c;
790 c = (bp - label - 1);
791 if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
809 if ((bp - dst) > NS_MAXCDNAME)
819 * irc_ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
820 * Pack domain name 'domain' into 'comp_dn'.
822 * Size of the compressed name, or -1.
824 * 'dnptrs' is an array of pointers to previous compressed names.
825 * dnptrs[0] is a pointer to the beginning of the message. The array
827 * 'lastdnptr' is a pointer to the end of the array pointed to
830 * The list of pointers in dnptrs is updated for labels inserted into
831 * the message as we compress the name. If 'dnptr' is NULL, we don't
832 * try to compress names. If 'lastdnptr' is NULL, we don't update the
836 irc_ns_name_pack(const unsigned char *src, unsigned char *dst, int dstsiz,
837 const unsigned char **dnptrs, const unsigned char **lastdnptr)
840 const unsigned char **cpp, **lpp, *eob, *msg;
841 const unsigned char *srcp;
848 if (dnptrs != NULL) {
849 if ((msg = *dnptrs++) != NULL) {
850 for (cpp = dnptrs; *cpp != NULL; cpp++)
852 lpp = cpp; /* end of list to search */
857 /* make sure the domain we are about to add is legal */
863 if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
867 if ((l0 = labellen(srcp)) < 0) {
872 if (l > NS_MAXCDNAME) {
879 /* from here on we need to reset compression pointer array on error */
882 /* Look to see if we can use pointers. */
884 if (n != 0 && msg != NULL) {
885 l = irc_dn_find(srcp, msg, (const unsigned char * const *)dnptrs,
886 (const unsigned char * const *)lpp);
888 if (dstp + 1 >= eob) {
891 *dstp++ = (l >> 8) | NS_CMPRSFLGS;
895 /* Not found, save it. */
896 if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
897 (dstp - msg) < 0x4000 && first) {
903 /* copy label to buffer */
904 if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
905 /* Should not happen. */
909 if (dstp + 1 + n >= eob) {
912 memcpy(dstp, srcp, n + 1);
928 irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz,
929 const unsigned char **dnptrs, const unsigned char **lastdnptr)
931 unsigned char tmp[NS_MAXCDNAME];
933 if (irc_ns_name_pton(src, tmp, sizeof tmp) == -1)
935 return(irc_ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
939 irc_encode_bitsring(const char **bp, const char *end, unsigned char **labelp,
940 unsigned char **dst, const char *eom)
943 const char *cp = *bp;
945 const char *beg_blen;
946 char *end_blen = NULL;
947 int value = 0, count = 0, tbcount = 0, blen = 0;
949 beg_blen = end_blen = NULL;
951 /* a bitstring must contain at least 2 characters */
955 /* XXX: currently, only hex strings are supported */
958 if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */
961 for (tp = *dst + 1; cp < end && tp < eom; cp++) {
963 case ']': /* end of the bitstring */
965 if (beg_blen == NULL)
967 blen = (int)strtol(beg_blen, &end_blen, 10);
968 if (*end_blen != ']')
972 *tp++ = ((value << 4) & 0xff);
980 if (!isdigit(c&0xff))
982 if (beg_blen == NULL) {
985 /* blen never begings with 0 */
991 if (!isxdigit(c&0xff))
994 value += digitvalue[(int)c];
1008 if (cp >= end || tp >= eom)
1012 * bit length validation:
1013 * If a <length> is present, the number of digits in the <bit-data>
1014 * MUST be just sufficient to contain the number of bits specified
1015 * by the <length>. If there are insignificant bits in a final
1016 * hexadecimal or octal digit, they MUST be zero.
1017 * RFC 2673, Section 3.2.
1022 if (((blen + 3) & ~3) != tbcount)
1024 traillen = tbcount - blen; /* between 0 and 3 */
1025 if (((value << (8 - traillen)) & 0xff) != 0)
1033 /* encode the type and the significant bit fields */
1034 **labelp = DNS_LABELTYPE_BITSTRING;
1044 * dn_find(domain, msg, dnptrs, lastdnptr)
1045 * Search for the counted-label name in an array of compressed names.
1047 * offset from msg if found, or -1.
1049 * dnptrs is the pointer to the first name on the list,
1050 * not the pointer to the start of the message.
1053 irc_dn_find(const unsigned char *domain, const unsigned char *msg,
1054 const unsigned char * const *dnptrs,
1055 const unsigned char * const *lastdnptr)
1057 const unsigned char *dn, *cp, *sp;
1058 const unsigned char * const *cpp;
1061 for (cpp = dnptrs; cpp < lastdnptr; cpp++)
1065 * terminate search on:
1067 * compression pointer
1070 while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
1071 (sp - msg) < 0x4000) {
1074 while ((n = *cp++) != 0) {
1076 * check for indirection
1078 switch (n & NS_CMPRSFLGS) {
1079 case 0: /* normal case, n == len */
1080 n = labellen(cp - 1); /* XXX */
1085 for ((void)NULL; n > 0; n--)
1086 if (mklower(*dn++) !=
1089 /* Is next root for both ? */
1090 if (*dn == '\0' && *cp == '\0')
1095 case NS_CMPRSFLGS: /* indirection */
1096 cp = msg + (((n & 0x3f) << 8) | *cp);
1099 default: /* illegal type */
1113 * Thinking in noninternationalized USASCII (per the DNS spec),
1114 * convert this character to lower case if it's upper case.
1119 if (ch >= 0x41 && ch <= 0x5A)
1125 /* From resolv/mkquery.c */
1128 * Form all types of queries.
1129 * Returns the size of the result or -1.
1133 const char *dname, /* domain name */
1134 int class, int type, /* class and type of query */
1135 unsigned char *buf, /* buffer to put query */
1136 int buflen) /* size of buffer */
1141 unsigned char *dnptrs[20], **dpp, **lastdnptr;
1144 * Initialize header fields.
1146 if ((buf == NULL) || (buflen < HFIXEDSZ))
1148 memset(buf, 0, HFIXEDSZ);
1149 hp = (HEADER *) buf;
1153 hp->rd = 1; /* recurse */
1154 hp->rcode = NO_ERRORS;
1155 cp = buf + HFIXEDSZ;
1160 lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
1162 if ((buflen -= QFIXEDSZ) < 0)
1164 if ((n = irc_dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
1169 IRC_NS_PUT16(type, cp);
1170 IRC_NS_PUT16(class, cp);
1171 hp->qdcount = htons(1);