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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <libzonecfg.h>
37 #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
38 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
42 * -t prints "shared" vs. "exclusive"
45 main(int argc
, char *argv
[])
48 char zonename
[ZONENAME_MAX
];
51 boolean_t stacktype
= B_FALSE
;
53 (void) setlocale(LC_ALL
, "");
54 (void) textdomain(TEXT_DOMAIN
);
57 while ((arg
= getopt(argc
, argv
, "t")) != EOF
) {
70 if (zone_getattr(zoneid
, ZONE_ATTR_FLAGS
, &flags
,
71 sizeof (flags
)) < 0) {
72 perror("could not determine zone IP type");
75 if (flags
& ZF_NET_EXCL
)
76 (void) puts("exclusive");
78 (void) puts("shared");
82 if (getzonenamebyid(zoneid
, zonename
, sizeof (zonename
)) < 0) {
83 (void) fputs(gettext("could not determine zone name\n"),
89 * The use of dlopen here is a bit ugly, but it allows zonename to
90 * function properly before /usr is mounted. On such a system, scratch
91 * zones don't exist, so no translation is necessary.
93 if (dlopen("libzonecfg.so.1", RTLD_NOW
| RTLD_GLOBAL
) != NULL
&&
94 zonecfg_is_scratch(zonename
) &&
95 (fp
= zonecfg_open_scratch("", B_FALSE
)) != NULL
) {
96 (void) zonecfg_reverse_scratch(fp
, zonename
, zonename
,
97 sizeof (zonename
), NULL
, 0);
98 zonecfg_close_scratch(fp
);
100 (void) puts(zonename
);