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 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 #include <arpa/nameser.h>
41 * Private resolver of target and type with arguments:
42 * klooukp [ target [ RR_type ] ]
44 * Utitilizes DNS lookups to discover domain and realm information. This CLI
45 * is used primarily by kdcmgr(1M) and kclient(1M).
50 main(int argc
, char **argv
)
52 unsigned char answer
[NS_MAXMSG
], *ansp
= NULL
, *end
, a
, b
, c
, d
;
53 int len
= 0, anslen
, hostlen
, nq
, na
, type
, class;
54 int ttl
, priority
, weight
, port
, size
;
55 char name
[NS_MAXDNAME
], *cp
, *typestr
= NULL
;
56 char nbuf
[INET6_ADDRSTRLEN
];
57 struct __res_state stat
;
66 if (gethostname(name
, MAXHOSTNAMELEN
) != 0)
69 (void) strncpy(name
, (char *)argv
[1], NS_MAXDNAME
);
85 (void) sscanf(name
, "%d.%d.%d.%d",
87 (void) sprintf(name
, "%d.%d.%d.%d.in-addr.arpa",
99 (void) memset(&stat
, 0, sizeof (stat
));
101 if (res_ninit(&stat
) == -1)
104 anslen
= sizeof (answer
);
105 len
= res_nsearch(&stat
, name
, C_IN
, rr_type
, answer
, anslen
);
107 if (len
< sizeof (HEADER
)) {
116 h
= (HEADER
*)answer
;
117 nq
= ntohs(h
->qdcount
);
118 na
= ntohs(h
->ancount
);
121 if (nq
!= 1 || na
< 1) {
126 hostlen
= sizeof (name
);
127 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
133 ansp
+= len
+ QFIXEDSZ
;
140 while (na
-- > 0 && ansp
< end
) {
142 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
146 ansp
+= len
; /* name */
147 NS_GET16(type
, ansp
); /* type */
148 NS_GET16(class, ansp
); /* class */
149 NS_GET32(ttl
, ansp
); /* ttl */
150 NS_GET16(size
, ansp
); /* size */
152 if ((ansp
+ size
) > end
) {
157 NS_GET16(priority
, ansp
);
158 NS_GET16(weight
, ansp
);
159 NS_GET16(port
, ansp
);
160 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
165 for (cp
= name
; *cp
; cp
++) {
168 (void) printf("%s %d\n", name
, port
);
169 } else if (typestr
&& *typestr
== 'I') {
170 (void) inet_ntop(AF_INET
, (void *)ansp
, nbuf
,
173 (void) printf("%s\n", nbuf
);
174 } else if (type
== T_PTR
) {
175 len
= dn_expand(answer
, end
, ansp
, name
, hostlen
);
182 if (type
== rr_type
&& class == C_IN
) {
184 if (type
!= T_SRV
&& !(typestr
&& *typestr
== 'I'))
194 for (cp
= name
; *cp
; cp
++) {
198 if (type
!= T_SRV
&& !(typestr
&& *typestr
== 'I'))
199 (void) printf("%s\n", name
);