zonename.c (108322fb) zonename.c (f4b3ec61)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21/*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <locale.h>
32#include <libintl.h>
33#include <zone.h>
34#include <libzonecfg.h>
35#include <dlfcn.h>
23 * Use is subject to license terms.
24 */
25
26#pragma ident "%Z%%M% %I% %E% SMI"
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <locale.h>
31#include <libintl.h>
32#include <zone.h>
33#include <libzonecfg.h>
34#include <dlfcn.h>
35#include <sys/zone.h>
36
37#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
38#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
39#endif
40
36
37#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
38#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
39#endif
40
41/*
42 * -t prints "shared" vs. "exclusive"
43 */
41int
44int
42main(void)
45main(int argc, char *argv[])
43{
46{
47 zoneid_t zoneid;
44 char zonename[ZONENAME_MAX];
45 FILE *fp;
48 char zonename[ZONENAME_MAX];
49 FILE *fp;
50 int arg;
51 boolean_t stacktype = B_FALSE;
46
47 (void) setlocale(LC_ALL, "");
48 (void) textdomain(TEXT_DOMAIN);
49
52
53 (void) setlocale(LC_ALL, "");
54 (void) textdomain(TEXT_DOMAIN);
55
50 if (getzonenamebyid(getzoneid(), zonename, sizeof (zonename)) < 0) {
56 opterr = 0;
57 while ((arg = getopt(argc, argv, "t")) != EOF) {
58 switch (arg) {
59 case 't':
60 stacktype = B_TRUE;
61 break;
62 }
63 }
64
65 zoneid = getzoneid();
66
67 if (stacktype) {
68 ushort_t flags;
69
70 if (zone_getattr(zoneid, ZONE_ATTR_FLAGS, &flags,
71 sizeof (flags)) < 0) {
72 perror("could not determine zone IP type");
73 exit(1);
74 }
75 if (flags & ZF_NET_EXCL)
76 (void) puts("exclusive");
77 else
78 (void) puts("shared");
79 return (0);
80 }
81
82 if (getzonenamebyid(zoneid, zonename, sizeof (zonename)) < 0) {
51 (void) fputs(gettext("could not determine zone name\n"),
52 stderr);
53 return (1);
54 }
55
56 /*
57 * The use of dlopen here is a bit ugly, but it allows zonename to
58 * function properly before /usr is mounted. On such a system, scratch

--- 12 unchanged lines hidden ---
83 (void) fputs(gettext("could not determine zone name\n"),
84 stderr);
85 return (1);
86 }
87
88 /*
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

--- 12 unchanged lines hidden ---