2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A
2N/A/*
2N/A * Adr memory based encoding
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <bsm/audit.h>
2N/A#include <bsm/libbsm.h>
2N/A#include <bsm/audit_record.h>
2N/A
2N/Avoid
2N/Aadr_start(adr_t *adr, char *p)
2N/A{
2N/A adr->adr_stream = p;
2N/A adr->adr_now = p;
2N/A}
2N/A
2N/Aint
2N/Aadr_count(adr_t *adr)
2N/A{
2N/A return (((intptr_t)adr->adr_now) - ((intptr_t)adr->adr_stream));
2N/A}
2N/A
2N/A
2N/A/*
2N/A * adr_char - pull out characters
2N/A */
2N/Avoid
2N/Aadr_char(adr_t *adr, char *cp, int count)
2N/A{
2N/A while (count-- > 0)
2N/A *adr->adr_now++ = *cp++;
2N/A}
2N/A
2N/A/*
2N/A * adr_short - pull out shorts
2N/A */
2N/Avoid
2N/Aadr_short(adr_t *adr, short *sp, int count)
2N/A{
2N/A
2N/A for (; count-- > 0; sp++) {
2N/A *adr->adr_now++ = (char)((*sp >> 8) & 0x00ff);
2N/A *adr->adr_now++ = (char)(*sp & 0x00ff);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * adr_ushort - pull out ushorts
2N/A */
2N/Avoid
2N/Aadr_ushort(adr_t *adr, ushort_t *sp, int count)
2N/A{
2N/A
2N/A for (; count-- > 0; sp++) {
2N/A *adr->adr_now++ = (char)((*sp >> 8) & 0x00ff);
2N/A *adr->adr_now++ = (char)(*sp & 0x00ff);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * adr_int32 - pull out uint32
2N/A */
2N/A#pragma weak adr_long = adr_int32
2N/Avoid
2N/Aadr_long(adr_t *adr, int32_t *lp, int count);
2N/Avoid
2N/Aadr_int32(adr_t *adr, int32_t *lp, int count)
2N/A{
2N/A int i; /* index for counting */
2N/A uint32_t l; /* value for shifting */
2N/A
2N/A for (; count-- > 0; lp++) {
2N/A for (i = 0, l = *(uint32_t *)lp; i < 4; i++) {
2N/A *adr->adr_now++ =
2N/A (char)((uint32_t)(l & 0xff000000) >> 24);
2N/A l <<= 8;
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * adr_uid
2N/A */
2N/A
2N/Avoid
2N/Aadr_uid(adr_t *adr, uid_t *up, int count)
2N/A{
2N/A int i; /* index for counting */
2N/A uid_t l; /* value for shifting */
2N/A
2N/A for (; count-- > 0; up++) {
2N/A for (i = 0, l = *(uint32_t *)up; i < 4; i++) {
2N/A *adr->adr_now++ =
2N/A (char)((uint32_t)(l & 0xff000000) >> 24);
2N/A l <<= 8;
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * adr_int64 - pull out uint64_t
2N/A */
2N/Avoid
2N/Aadr_int64(adr_t *adr, int64_t *lp, int count)
2N/A{
2N/A int i; /* index for counting */
2N/A uint64_t l; /* value for shifting */
2N/A
2N/A for (; count-- > 0; lp++) {
2N/A for (i = 0, l = *(uint64_t *)lp; i < 8; i++) {
2N/A *adr->adr_now++ = (char)
2N/A ((uint64_t)(l & 0xff00000000000000ULL) >> 56);
2N/A l <<= 8;
2N/A }
2N/A }
2N/A}