17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*f4b3ec61Sdh155122 * Common Development and Distribution License (the "License").
6*f4b3ec61Sdh155122 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*f4b3ec61Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <locale.h>
317c478bd9Sstevel@tonic-gate #include <libintl.h>
327c478bd9Sstevel@tonic-gate #include <zone.h>
33108322fbScarlsonj #include <libzonecfg.h>
34108322fbScarlsonj #include <dlfcn.h>
35*f4b3ec61Sdh155122 #include <sys/zone.h>
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
387c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate
41*f4b3ec61Sdh155122 /*
42*f4b3ec61Sdh155122 * -t prints "shared" vs. "exclusive"
43*f4b3ec61Sdh155122 */
447c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])45*f4b3ec61Sdh155122 main(int argc, char *argv[])
467c478bd9Sstevel@tonic-gate {
47*f4b3ec61Sdh155122 zoneid_t zoneid;
487c478bd9Sstevel@tonic-gate char zonename[ZONENAME_MAX];
49108322fbScarlsonj FILE *fp;
50*f4b3ec61Sdh155122 int arg;
51*f4b3ec61Sdh155122 boolean_t stacktype = B_FALSE;
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
547c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
557c478bd9Sstevel@tonic-gate
56*f4b3ec61Sdh155122 opterr = 0;
57*f4b3ec61Sdh155122 while ((arg = getopt(argc, argv, "t")) != EOF) {
58*f4b3ec61Sdh155122 switch (arg) {
59*f4b3ec61Sdh155122 case 't':
60*f4b3ec61Sdh155122 stacktype = B_TRUE;
61*f4b3ec61Sdh155122 break;
62*f4b3ec61Sdh155122 }
63*f4b3ec61Sdh155122 }
64*f4b3ec61Sdh155122
65*f4b3ec61Sdh155122 zoneid = getzoneid();
66*f4b3ec61Sdh155122
67*f4b3ec61Sdh155122 if (stacktype) {
68*f4b3ec61Sdh155122 ushort_t flags;
69*f4b3ec61Sdh155122
70*f4b3ec61Sdh155122 if (zone_getattr(zoneid, ZONE_ATTR_FLAGS, &flags,
71*f4b3ec61Sdh155122 sizeof (flags)) < 0) {
72*f4b3ec61Sdh155122 perror("could not determine zone IP type");
73*f4b3ec61Sdh155122 exit(1);
74*f4b3ec61Sdh155122 }
75*f4b3ec61Sdh155122 if (flags & ZF_NET_EXCL)
76*f4b3ec61Sdh155122 (void) puts("exclusive");
77*f4b3ec61Sdh155122 else
78*f4b3ec61Sdh155122 (void) puts("shared");
79*f4b3ec61Sdh155122 return (0);
80*f4b3ec61Sdh155122 }
81*f4b3ec61Sdh155122
82*f4b3ec61Sdh155122 if (getzonenamebyid(zoneid, zonename, sizeof (zonename)) < 0) {
837c478bd9Sstevel@tonic-gate (void) fputs(gettext("could not determine zone name\n"),
847c478bd9Sstevel@tonic-gate stderr);
857c478bd9Sstevel@tonic-gate return (1);
867c478bd9Sstevel@tonic-gate }
87108322fbScarlsonj
88108322fbScarlsonj /*
89108322fbScarlsonj * The use of dlopen here is a bit ugly, but it allows zonename to
90108322fbScarlsonj * function properly before /usr is mounted. On such a system, scratch
91108322fbScarlsonj * zones don't exist, so no translation is necessary.
92108322fbScarlsonj */
93108322fbScarlsonj if (dlopen("libzonecfg.so.1", RTLD_NOW | RTLD_GLOBAL) != NULL &&
94108322fbScarlsonj zonecfg_is_scratch(zonename) &&
95108322fbScarlsonj (fp = zonecfg_open_scratch("", B_FALSE)) != NULL) {
96108322fbScarlsonj (void) zonecfg_reverse_scratch(fp, zonename, zonename,
97108322fbScarlsonj sizeof (zonename), NULL, 0);
98108322fbScarlsonj zonecfg_close_scratch(fp);
99108322fbScarlsonj }
1007c478bd9Sstevel@tonic-gate (void) puts(zonename);
1017c478bd9Sstevel@tonic-gate return (0);
1027c478bd9Sstevel@tonic-gate }
103