4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include <arpa/nameser.h>
42 * Private resolver of target and type with arguments:
43 * klooukp [ target [ RR_type ] ]
45 * Utitilizes DNS lookups to discover domain and realm information. This CLI
46 * is used primarily by kdcmgr(8) and kclient(8).
51 main(int argc
, char **argv
)
53 unsigned char answer
[NS_MAXMSG
], *ansp
= NULL
, *end
, a
, b
, c
, d
;
54 int len
= 0, anslen
, hostlen
, nq
, na
, type
, class;
55 int ttl __unused
, priority __unused
, weight __unused
, port
, size
;
56 char name
[NS_MAXDNAME
], *cp
, *typestr
= NULL
;
57 char nbuf
[INET6_ADDRSTRLEN
];
58 struct __res_state stat
;
69 if (gethostname(name
, MAXHOSTNAMELEN
) != 0)
72 (void) strncpy(name
, (char *)argv
[1], NS_MAXDNAME
);
88 (void) sscanf(name
, "%hhd.%hhd.%hhd.%hhd",
90 (void) sprintf(name
, "%d.%d.%d.%d.in-addr.arpa",
102 (void) memset(&stat
, 0, sizeof (stat
));
104 if (res_ninit(&stat
) == -1)
107 anslen
= sizeof (answer
);
108 len
= res_nsearch(&stat
, name
, C_IN
, rr_type
, answer
, anslen
);
110 if (len
< sizeof (HEADER
)) {
119 h
= (HEADER
*)answer
;
120 nq
= ntohs(h
->qdcount
);
121 na
= ntohs(h
->ancount
);
124 if (nq
!= 1 || na
< 1) {
129 hostlen
= sizeof (name
);
130 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
136 ansp
+= len
+ QFIXEDSZ
;
143 while (na
-- > 0 && ansp
< end
) {
145 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
149 ansp
+= len
; /* name */
150 NS_GET16(type
, ansp
); /* type */
151 NS_GET16(class, ansp
); /* class */
152 NS_GET32(ttl
, ansp
); /* ttl */
153 NS_GET16(size
, ansp
); /* size */
155 if ((ansp
+ size
) > end
) {
160 NS_GET16(priority
, ansp
);
161 NS_GET16(weight
, ansp
);
162 NS_GET16(port
, ansp
);
163 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
168 for (cp
= name
; *cp
; cp
++) {
171 (void) printf("%s %d\n", name
, port
);
172 } else if (typestr
&& *typestr
== 'I') {
173 (void) inet_ntop(AF_INET
, (void *)ansp
, nbuf
,
176 (void) printf("%s\n", nbuf
);
177 } else if (type
== T_PTR
) {
178 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
185 if (type
== rr_type
&& class == C_IN
) {
187 if (type
!= T_SRV
&& !(typestr
&& *typestr
== 'I'))
197 for (cp
= name
; *cp
; cp
++) {
201 if (type
!= T_SRV
&& !(typestr
&& *typestr
== 'I'))
202 (void) printf("%s\n", name
);