1 /* $OpenBSD: res_mkquery.c,v 1.5 2013/04/01 20:22:27 eric Exp $ */
3 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/types.h>
19 #include <netinet/in.h>
20 #include <arpa/nameser.h> /* for MAXDNAME */
27 #include "asr_private.h"
29 /* This function is apparently needed by some ports. */
31 res_mkquery(int op
, const char *dname
, int class, int type
,
32 const unsigned char *data
, int datalen
, const unsigned char *newrr
,
33 unsigned char *buf
, int buflen
)
41 /* we currently only support QUERY */
42 if (op
!= QUERY
|| data
)
45 if (dname
[0] == '\0' || dname
[strlen(dname
) - 1] != '.') {
46 if (strlcpy(fqdn
, dname
, sizeof(fqdn
)) >= sizeof(fqdn
) ||
47 strlcat(fqdn
, ".", sizeof(fqdn
)) >= sizeof(fqdn
))
52 if (dname_from_fqdn(dname
, dn
, sizeof(dn
)) == -1)
55 ac
= asr_use_resolver(NULL
);
57 memset(&h
, 0, sizeof h
);
58 h
.id
= res_randomid();
59 if (ac
->ac_options
& RES_RECURSE
)
63 pack_init(&p
, buf
, buflen
);
65 pack_query(&p
, type
, class, dn
);
76 * This function is not documented, but used by sendmail.
77 * Put here because it uses asr_private.h too.
80 res_querydomain(const char *name
,
87 char fqdn
[MAXDNAME
], ndom
[MAXDNAME
];
90 /* we really want domain to end with a dot for now */
91 if (domain
&& ((n
= strlen(domain
)) == 0 || domain
[n
- 1 ] != '.')) {
92 if (strlcpy(ndom
, domain
, sizeof(ndom
)) >= sizeof(ndom
) ||
93 strlcat(ndom
, ".", sizeof(ndom
)) >= sizeof(ndom
)) {
94 h_errno
= NETDB_INTERNAL
;
101 if (asr_make_fqdn(name
, domain
, fqdn
, sizeof fqdn
) == 0) {
102 h_errno
= NETDB_INTERNAL
;
107 return (res_query(fqdn
, class, type
, answer
, anslen
));