Trusted Solaris Developer's Guide

Binary and Hexadecimal Label Translation

There are two types of binary to hexadecimal routines: regular and reentrant. Both types of routines return a pointer to a string that contains the result of the translation or NULL if the label being translated is not a binary label.

Binary and Hexadecimal Label Translation Routines

This example converts a binary CMW label to hexadecimal and back again. Converting a sensitivity label is similar.

#include <tsol/label.h>
#include <stdio.h>

main()
{
	int retval;
	bclabel_t hcmwlabel, hexcmw;
	char *string;

	getcmwplabel(&hcmwlabel);
	if((string = bcltoh(&hcmwlabel)) != NULL)
		printf("Hex string = %s\n", string);

	retval = htobcl(string, &hexcmw);
	printf("Return Value = %d\n", retval);
}

The first printf statements print the binary CMW label in the following hexadecimal format:

Hex string = ADMIN_LOW [0xsensitivity label value]

The second printf statement prints the following where non-zero indicates a successful translation:


Return Value = 1

Reentrant Binary and Hexadecimal Label Translation Routines

The reentrant (MT-SAFE) routine bcltoh_r(3TSOL) requires the allocation and freeing of memory for a variable of the specified type. This example allocates memory, translates the binary CMW label to hexadecimal, and frees the memory at the end. Converting a sensitivity label to hexadecimal and back is a similar process.

#include <tsol/label.h>
#include <stdio.h>

main()
{
	int retval;
	bclabel_t hcmwlabel, hexcmw;
	char *string, *hex;

	getcmwplabel(&hcmwlabel);
	hex = h_alloc(SUN_CMW_ID);
	if((string = bcltoh_r(&hcmwlabel, hex)) != NULL)
		printf("Hex string = %s\n", string);

	retval = htobcl(string, &hexcmw);
	printf("Return Value = %d\n", retval);
	h_free(hex);
}

The printf statement prints the binary clearance in the following hexadecimal format:


Hex string =0x00000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000[0x00040c0000000000000000000000
000000000000000000000003ffffffffffff0000]

Return Value = 1