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 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 * hextoalabel - Convert an internal label to its human readable
42 #include <sys/param.h>
44 #include <tsol/label.h>
46 #if !defined(TEXT_DOMAIN)
47 #define TEXT_DOMAIN "SYS_TEST"
48 #endif /* !defined(TEXT_DOMAIN) */
51 label_error(const char *hex
, const int err
)
53 if (errno
== EINVAL
) {
56 (void) fprintf(stderr
,
57 gettext("hextoalabel: bad string %s\n"), hex
);
60 (void) fprintf(stderr
,
61 gettext("hextoalabel: bad previous label\n"));
64 (void) fprintf(stderr
,
65 gettext("hextoalabel: parsing error found in "
66 "\"%s\" at position %d\n"), hex
, err
);
70 perror("hextoalabel");
77 main(int argc
, char **argv
)
79 int cflg
= 0; /* true if Clearance only */
80 int errflg
= 0; /* true if arg error */
81 m_label_t
*label
= NULL
;
82 char hex
[PIPE_BUF
]; /* internal label */
83 char *ascii
= NULL
; /* human readable label to print */
84 int err
= 0; /* label error */
87 (void) setlocale(LC_ALL
, "");
88 (void) textdomain(TEXT_DOMAIN
);
91 while ((c
= getopt(argc
, argv
, "c")) != EOF
) {
104 if (errflg
|| argc
> 2) {
106 (void) fprintf(stderr
,
107 gettext("usage: %s [-c] [hexadecimal label]\n"), argv
[0]);
113 /* use label on command line */
115 (void) strlcpy(hex
, argv
[optind
], sizeof (hex
));
117 /* read label from standard input */
119 if ((c
= read(STDIN_FILENO
, hex
, sizeof (hex
))) <= 0) {
121 perror(gettext("reading hexadecimal label"));
127 * replace '\n' or (end of buffer) with end of string.
132 * flush any remaining input past the size of the buffer.
134 (void) ioctl(STDIN_FILENO
, I_FLUSH
, FLUSHR
);
138 if (str_to_label(hex
, &label
, USER_CLEAR
, L_NO_CORRECTION
,
140 label_error(hex
, err
);
142 if (label_to_str(label
, &ascii
, M_LABEL
, DEF_NAMES
) != 0) {
143 perror("label_to_str");
146 (void) printf("%s\n", ascii
);
150 if (str_to_label(hex
, &label
, MAC_LABEL
, L_NO_CORRECTION
,
152 label_error(hex
, err
);
154 if (label_to_str(label
, &ascii
, M_LABEL
, DEF_NAMES
) != 0) {
155 perror("label_to_str");
158 (void) printf("%s\n", ascii
);
163 return (0); /* really exit(0); */