/* @(#)75    1.12  src/examples/common/util.c, examples.src, os2dce21.dss, 960602a.1 2/14/96 13:16:04 */
/*
 * COMPONENT_NAME:  examples.src
 *
 * FUNCTIONS:
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1992, 1994
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 */

/*********************************************************************
 *                                                                   *
 *  Functions :  get_local_host_net_addrs()                          *
 *               print_binding_handle()                              *
 *               print_exception()                                   *
 *                                                                   *
 *  Comments  :  Utility routines used by the example programs.      *
 *                                                                   *
 *********************************************************************/

#ifdef __BORLANDC__
#define _System _syscall
#define far
#include <dce/dce_error.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#undef random
#include <string.h>
#include <errno.h>
#include <dce/pthread_exc.h>
#include <dce/rpc.h>
#include <dce/rpcexc.h>
#ifdef IBMOS2
#include "types.h"
#include <netinet/in.h>
#else
#include <sys/types.h>
#endif
#include <sys/socket.h>
#include <sys/time.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include "util.h"

#define  BUFSIZE   1024
#ifdef IBMOS2
#define  size(p)   sizeof(p)
#else
#define  size(p)   max((p).sa_len, sizeof(p))
#endif


/*********************************************************************
 *   Function    :  get_local_host_net_addrs()                       *
 *********************************************************************
 *                                                                   *
 *   Description :  Obtains a socket descriptor, and uses it to      *
 *                  inspect the network interface configuration.     *
 *                  A complete list of ip addresses for the          *
 *                  internet network family is returned, except      *
 *                  for loopback addresses.                          *
 *                                                                   *
 *   Returns     :  0 (success) or appropriate error code.           *
 *                                                                   *
 *********************************************************************/

unsigned32 get_local_host_net_addrs( int  *count,
                                     char addrstrv[20][16] )
{
    struct ifconf       ifc;
    struct ifreq        ifreq, *ifr;
    struct sockaddr_in  if_addr;
    int    s, i, addr[4];
    char   buf[BUFSIZE], *cp, *cplim;

    *count = 0;

socket_again:

    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        if (errno == EINTR)
        {
            goto socket_again;
        }
        perror("socket() call");
        return(errno);
    }

    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;

ifconf_again:


#ifdef IBMOS2
#ifndef __IBMC__
    if (ioctl( s,
               SIOCGIFCONF,
               (char *)&ifc, 0 ) < 0)
#else
    if (ioctl( s,
               SIOCGIFCONF,
               (char *)&ifc, NULL ) < 0)
#endif
#else
    if (ioctl( s,
               SIOCGIFCONF,
               (char *)&ifc ) < 0)
#endif
    {
        if (errno == EINTR)
        {
            goto ifconf_again;
        }
        perror("ioctl() call");
        return(errno);
    }

    ifr = ifc.ifc_req;
    cplim = buf + ifc.ifc_len;

    for (cp = buf;
         cp < cplim;
         cp += sizeof(ifr->ifr_name) + size(ifr->ifr_addr))
    {
        ifr = (struct ifreq *)cp;
        ifreq = *ifr;

ifflags_again:
#ifdef IBMOS2
#ifndef __IBMC__
        if ( ioctl( s,
                    SIOCGIFFLAGS,
                    (char *)&ifreq, 0 ) < 0)
#else
        if ( ioctl( s,
                    SIOCGIFFLAGS,
                    (char *)&ifreq, NULL ) < 0)
#endif
#else
        if ( ioctl( s,
                    SIOCGIFFLAGS,
                    (char *)&ifreq ) < 0)
#endif
        {
            if (errno == EINTR)
            {
                goto ifflags_again;
            }
            perror("ioctl() call");
            return(errno);
        }

        if_addr = * (struct sockaddr_in *) &ifr->ifr_addr;

        /*
         * If this isn't an Internet-family address, ignore it.
         */
        if ((ifreq.ifr_flags & IFF_UP) &&
            !(ifreq.ifr_flags & IFF_LOOPBACK) &&
            (ifr->ifr_addr.sa_family == AF_INET))
        {
            (*count)++;
            for (i=0; i<4; i++)
            {
                addr[i] = if_addr.sin_addr.s_addr & 0x000000FF;
                if_addr.sin_addr.s_addr = if_addr.sin_addr.s_addr >> 8;
            }
            sprintf(&addrstrv[*count-1][0],
                    "%d.%d.%d.%d",
                    addr[3],
                    addr[2],
                    addr[1],
                    addr[0]);
        } /* end if */

    } /* end for */

    return(0);

} /* end get_local_host_net_addrs() */


/*********************************************************************
 *   Function    :  print_binding_handle()                           *
 *********************************************************************
 *                                                                   *
 *   Description :  Prints out the fields of a binding handle.       *
 *                                                                   *
 *   Returns     :  0 (success) or appropriate error code.           *
 *                                                                   *
 *********************************************************************/

unsigned32 print_binding_handle( rpc_binding_handle_t bh )
{
    unsigned32 status;
    char *string_binding;
    char *obj_uuid, *protseq, *netaddr, *endpoint, *netopts;

    rpc_binding_to_string_binding( bh,
                                   &string_binding,
                                   &status );

    CHECK_STATUS( "rpc_binding_to_string_binding()\n",
                  status,
                  RETURN );

    rpc_string_binding_parse( string_binding,
                              &obj_uuid,
                              &protseq,
                              &netaddr,
                              &endpoint,
                              &netopts,
                              &status );

    CHECK_STATUS( "rpc_string_binding_parse()\n",
                  status,
                  RETURN );

    PRINT("\n");
    PRINT("Binding Info:\n");
    PRINT("\tobject uuid       :%s\n",obj_uuid);
    PRINT("\tprotocol sequence :%s\n",protseq);
    PRINT("\tnetwork address   :%s\n",netaddr);
    PRINT("\tendpoint          :%s\n",endpoint);
    PRINT("\tnetwork options   :%s\n",netopts);
    PRINT("\n");

    rpc_string_free( &string_binding, &status );
    rpc_string_free( &obj_uuid, &status );
    rpc_string_free( &protseq, &status );
    rpc_string_free( &netaddr, &status );
    rpc_string_free( &endpoint, &status );
    rpc_string_free( &netopts, &status );
    return (status);

} /* end print_binding_handle() */


/*********************************************************************
 *   Function    :  print_exception()                                *
 *********************************************************************
 *                                                                   *
 *   Description :  Given an exception structure (raised thru the    *
 *                  exception handling mechanism), this routine      *
 *                  will examine the structure, and print out a      *
 *                  text string describing the exception.            *
 *                                                                   *
 *   Returns     :  Void function.                                   *
 *                                                                   *
 *********************************************************************/

void print_exception( EXCEPTION *e )
{
    char *estr = NULL;

#ifdef __BORLANDC__

    if (exc_matches(e,&rpc_x_assoc_grp_not_found))
        estr = "rpc_x_assoc_grp_not_found";
    else if (exc_matches(e,&rpc_x_cancel_timeout))
        estr = "rpc_x_cancel_timeout";
    else if (exc_matches(e,&rpc_x_coding_error))
        estr = "rpc_x_coding_error";
    else if (exc_matches(e,&rpc_x_comm_failure))
        estr = "rpc_x_comm_failure";
    else if (exc_matches(e,&rpc_x_context_id_not_found))
        estr = "rpc_x_context_id_not_found";
    else if (exc_matches(e,&rpc_x_endpoint_not_found))
        estr = "rpc_x_endpoint_not_found";
    else if (exc_matches(e,&rpc_x_in_args_too_big))
        estr = "rpc_x_in_args_too_big";
    else if (exc_matches(e,&rpc_x_invalid_binding))
        estr = "rpc_x_invalid_binding";
    else if (exc_matches(e,&rpc_x_invalid_bound))
        estr = "rpc_x_invalid_bound";
    else if (exc_matches(e,&rpc_x_invalid_call_opt))
        estr = "rpc_x_invalid_call_opt";
    else if (exc_matches(e,&rpc_x_invalid_naf_id))
        estr = "rpc_x_invalid_naf_id";
    else if (exc_matches(e,&rpc_x_invalid_rpc_protseq))
        estr = "rpc_x_invalid_rpc_protseq";
    else if (exc_matches(e,&rpc_x_invalid_tag))
        estr = "rpc_x_invalid_tag";
    else if (exc_matches(e,&rpc_x_invalid_timeout))
        estr = "rpc_x_invalid_timeout";
    else if (exc_matches(e,&rpc_x_manager_not_entered))
        estr = "rpc_x_manager_not_entered";
    else if (exc_matches(e,&rpc_x_max_descs_exceeded))
        estr = "rpc_x_max_descs_exceeded";
    else if (exc_matches(e,&rpc_x_no_fault))
        estr = "rpc_x_no_fault";
    else if (exc_matches(e,&rpc_x_no_memory))
        estr = "rpc_x_no_memory";
    else if (exc_matches(e,&rpc_x_not_rpc_tower))
        estr = "rpc_x_not_rpc_tower";
    else if (exc_matches(e,&rpc_x_object_not_found))
        estr = "rpc_x_object_not_found";
    else if (exc_matches(e,&rpc_x_op_rng_error))
        estr = "rpc_x_op_rng_error";
    else if (exc_matches(e,&rpc_x_protocol_error))
        estr = "rpc_x_protocol_error";
    else if (exc_matches(e,&rpc_x_protseq_not_supported))
        estr = "rpc_x_protseq_not_supported";
    else if (exc_matches(e,&rpc_x_rpcd_comm_failure))
        estr = "rpc_x_rpcd_comm_failure";
    else if (exc_matches(e,&rpc_x_server_too_busy))
        estr = "rpc_x_server_too_busy";
    else if (exc_matches(e,&rpc_x_unknown_if))
        estr = "rpc_x_unknown_if";
    else if (exc_matches(e,&rpc_x_unknown_error))
        estr = "rpc_x_unknown_error";
    else if (exc_matches(e,&rpc_x_unknown_mgr_type))
        estr = "rpc_x_unknown_mgr_type";
    else if (exc_matches(e,&rpc_x_unknown_reject))
        estr = "rpc_x_unknown_reject";
    else if (exc_matches(e,&rpc_x_unknown_remote_fault))
        estr = "rpc_x_unknown_remote_fault";
    else if (exc_matches(e,&rpc_x_unsupported_type))
        estr = "rpc_x_unsupported_type";
    else if (exc_matches(e,&rpc_x_who_are_you_failed))
        estr = "rpc_x_who_are_you_failed";
    else if (exc_matches(e,&rpc_x_wrong_boot_time))
        estr = "rpc_x_wrong_boot_time";
    else if (exc_matches(e,&rpc_x_wrong_kind_of_binding))
        estr = "rpc_x_wrong_kind_of_binding";
    else if (exc_matches(e,&rpc_x_access_control_info_inv))
        estr = "rpc_x_access_control_info_inv";
    else if (exc_matches(e,&rpc_x_assoc_grp_max_exceeded))
        estr = "rpc_x_assoc_grp_max_exceeded";
    else if (exc_matches(e,&rpc_x_assoc_shutdown))
        estr = "rpc_x_assoc_shutdown";
    else if (exc_matches(e,&rpc_x_cannot_accept))
        estr = "rpc_x_cannot_accept";
    else if (exc_matches(e,&rpc_x_cannot_connect))
        estr = "rpc_x_cannot_connect";
    else if (exc_matches(e,&rpc_x_cant_inq_socket))
        estr = "rpc_x_cant_inq_socket";

    if (estr == NULL)
    {
        if (exc_matches(e,&rpc_x_connect_closed_by_rem))
            estr = "rpc_x_connect_closed_by_rem";
        else if (exc_matches(e,&rpc_x_connect_no_resources))
            estr = "rpc_x_connect_no_resources";
        else if (exc_matches(e,&rpc_x_connect_rejected))
            estr = "rpc_x_connect_rejected";
        else if (exc_matches(e,&rpc_x_connect_timed_out))
            estr = "rpc_x_connect_timed_out";
        else if (exc_matches(e,&rpc_x_connection_aborted))
            estr = "rpc_x_connection_aborted";
        else if (exc_matches(e,&rpc_x_connection_closed))
            estr = "rpc_x_connection_closed";
        else if (exc_matches(e,&rpc_x_host_unreachable))
            estr = "rpc_x_host_unreachable";
        else if (exc_matches(e,&rpc_x_invalid_endpoint_format))
            estr = "rpc_x_invalid_endpoint_format";
        else if (exc_matches(e,&rpc_x_loc_connect_aborted))
            estr = "rpc_x_loc_connect_aborted";
        else if (exc_matches(e,&rpc_x_network_unreachable))
            estr = "rpc_x_network_unreachable";
        else if (exc_matches(e,&rpc_x_no_rem_endpoint))
            estr = "rpc_x_no_rem_endpoint";
        else if (exc_matches(e,&rpc_x_rem_host_crashed))
            estr = "rpc_x_rem_host_crashed";
        else if (exc_matches(e,&rpc_x_rem_host_down))
            estr = "rpc_x_rem_host_down";
        else if (exc_matches(e,&rpc_x_rem_network_shutdown))
            estr = "rpc_x_rem_network_shutdown";
        else if (exc_matches(e,&rpc_x_rpc_prot_version_mismatch))
            estr = "rpc_x_rpc_prot_version_mismatch";
        else if (exc_matches(e,&rpc_x_string_too_long))
            estr = "rpc_x_string_too_long";
        else if (exc_matches(e,&rpc_x_too_many_rem_connects))
            estr = "rpc_x_too_many_rem_connects";
        else if (exc_matches(e,&rpc_x_tsyntaxes_unsupported))
            estr = "rpc_x_tsyntaxes_unsupported";
        else if (exc_matches(e,&rpc_x_binding_vector_full))
            estr = "rpc_x_binding_vector_full";
        else if (exc_matches(e,&rpc_x_entry_not_found))
            estr = "rpc_x_entry_not_found";
        else if (exc_matches(e,&rpc_x_group_not_found))
            estr = "rpc_x_group_not_found";
        else if (exc_matches(e,&rpc_x_incomplete_name))
            estr = "rpc_x_incomplete_name";
        else if (exc_matches(e,&rpc_x_invalid_arg))
            estr = "rpc_x_invalid_arg";
        else if (exc_matches(e,&rpc_x_invalid_import_context))
            estr = "rpc_x_invalid_import_context";
        else if (exc_matches(e,&rpc_x_invalid_inquiry_context))
            estr = "rpc_x_invalid_inquiry_context";
        else if (exc_matches(e,&rpc_x_invalid_inquiry_type))
            estr = "rpc_x_invalid_inquiry_type";
        else if (exc_matches(e,&rpc_x_invalid_lookup_context))
            estr = "rpc_x_invalid_lookup_context";
        else if (exc_matches(e,&rpc_x_invalid_name_syntax))
            estr = "rpc_x_invalid_name_syntax";
        else if (exc_matches(e,&rpc_x_invalid_object))
            estr = "rpc_x_invalid_object";
        else if (exc_matches(e,&rpc_x_invalid_vers_option))
            estr = "rpc_x_invalid_vers_option";
        else if (exc_matches(e,&rpc_x_name_service_unavailable))
            estr = "rpc_x_name_service_unavailable";
        else if (exc_matches(e,&rpc_x_no_env_setup))
            estr = "rpc_x_no_env_setup";
        else if (exc_matches(e,&rpc_x_no_more_bindings))
            estr = "rpc_x_no_more_bindings";
        else if (exc_matches(e,&rpc_x_no_more_elements))
            estr = "rpc_x_no_more_elements";
        else if (exc_matches(e,&rpc_x_not_found))
            estr = "rpc_x_not_found";
        else if (exc_matches(e,&rpc_x_not_rpc_entry))
            estr = "rpc_x_not_rpc_entry";
        else if (exc_matches(e,&rpc_x_obj_uuid_not_found))
            estr = "rpc_x_obj_uuid_not_found";
        else if (exc_matches(e,&rpc_x_profile_not_found))
            estr = "rpc_x_profile_not_found";
        else if (exc_matches(e,&rpc_x_unsupported_name_syntax))
            estr = "rpc_x_unsupported_name_syntax";
        else if (exc_matches(e,&rpc_x_auth_bad_integrity))
            estr = "rpc_x_auth_bad_integrity";
        else if (exc_matches(e,&rpc_x_auth_badaddr))
            estr = "rpc_x_auth_badaddr";
    }

    if (estr == NULL)
    {
        if (exc_matches(e,&rpc_x_auth_baddirection))
            estr = "rpc_x_auth_baddirection";
        else if (exc_matches(e,&rpc_x_auth_badkeyver))
            estr = "rpc_x_auth_badkeyver";
        else if (exc_matches(e,&rpc_x_auth_badmatch))
            estr = "rpc_x_auth_badmatch";
        else if (exc_matches(e,&rpc_x_auth_badorder))
            estr = "rpc_x_auth_badorder";
        else if (exc_matches(e,&rpc_x_auth_badseq))
            estr = "rpc_x_auth_badseq";
        else if (exc_matches(e,&rpc_x_auth_badversion))
            estr = "rpc_x_auth_badversion";
        else if (exc_matches(e,&rpc_x_auth_field_toolong))
            estr = "rpc_x_auth_field_toolong";
        else if (exc_matches(e,&rpc_x_auth_inapp_cksum))
            estr = "rpc_x_auth_inapp_cksum";
        else if (exc_matches(e,&rpc_x_auth_method))
            estr = "rpc_x_auth_method";
        else if (exc_matches(e,&rpc_x_auth_msg_type))
            estr = "rpc_x_auth_msg_type";
        else if (exc_matches(e,&rpc_x_auth_modified))
            estr = "rpc_x_auth_modified";
        else if (exc_matches(e,&rpc_x_auth_mut_fail))
            estr = "rpc_x_auth_mut_fail";
        else if (exc_matches(e,&rpc_x_auth_nokey))
            estr = "rpc_x_auth_nokey";
        else if (exc_matches(e,&rpc_x_auth_not_us))
            estr = "rpc_x_auth_not_us";
        else if (exc_matches(e,&rpc_x_auth_repeat))
            estr = "rpc_x_auth_repeat";
        else if (exc_matches(e,&rpc_x_auth_skew))
            estr = "rpc_x_auth_skew";
        else if (exc_matches(e,&rpc_x_auth_tkt_expired))
            estr = "rpc_x_auth_tkt_expired";
        else if (exc_matches(e,&rpc_x_auth_tkt_nyv))
            estr = "rpc_x_auth_tkt_nyv";
        else if (exc_matches(e,&rpc_x_call_id_not_found))
            estr = "rpc_x_call_id_not_found";
        else if (exc_matches(e,&rpc_x_credentials_too_large))
            estr = "rpc_x_credentials_too_large";
        else if (exc_matches(e,&rpc_x_invalid_checksum))
            estr = "rpc_x_invalid_checksum";
        else if (exc_matches(e,&rpc_x_invalid_crc))
            estr = "rpc_x_invalid_crc";
        else if (exc_matches(e,&rpc_x_invalid_credentials))
            estr = "rpc_x_invalid_credentials";
        else if (exc_matches(e,&rpc_x_key_id_not_found))
            estr = "rpc_x_key_id_not_found";
        else if (exc_matches(e,&rpc_x_ss_char_trans_open_fail))
            estr = "rpc_x_ss_char_trans_open_fail";
        else if (exc_matches(e,&rpc_x_ss_char_trans_short_file))
            estr = "rpc_x_ss_char_trans_short_file";
        else if (exc_matches(e,&rpc_x_ss_context_damaged))
            estr = "rpc_x_ss_context_damaged";
        else if (exc_matches(e,&rpc_x_ss_context_mismatch))
            estr = "rpc_x_ss_context_mismatch";
        else if (exc_matches(e,&rpc_x_ss_in_null_context))
            estr = "rpc_x_ss_in_null_context";
        else if (exc_matches(e,&rpc_x_ss_pipe_closed))
            estr = "rpc_x_ss_pipe_closed";
        else if (exc_matches(e,&rpc_x_ss_pipe_comm_error))
            estr = "rpc_x_ss_pipe_comm_error";
        else if (exc_matches(e,&rpc_x_ss_pipe_discipline_error))
            estr = "rpc_x_ss_pipe_discipline_error";
        else if (exc_matches(e,&rpc_x_ss_pipe_empty))
            estr = "rpc_x_ss_pipe_empty";
        else if (exc_matches(e,&rpc_x_ss_pipe_memory))
            estr = "rpc_x_ss_pipe_memory";
        else if (exc_matches(e,&rpc_x_ss_pipe_order))
            estr = "rpc_x_ss_pipe_order";
        else if (exc_matches(e,&rpc_x_ss_remote_comm_failure))
            estr = "rpc_x_ss_remote_comm_failure";
        else if (exc_matches(e,&rpc_x_ss_remote_no_memory))
            estr = "rpc_x_ss_remote_no_memory";
        else if (exc_matches(e,&exc_e_uninitexc))
            estr = "exc_e_uninitexc";
        else if (exc_matches(e,&exc_e_illaddr))
            estr = "exc_e_illaddr";
        else if (exc_matches(e,&exc_e_exquota))
            estr = "exc_e_exquota";
        else if (exc_matches(e,&exc_e_insfmem))
            estr = "exc_e_insfmem";
    }

    if (estr == NULL)
    {
        if (exc_matches(e,&exc_e_nopriv))
            estr = "exc_e_nopriv";
        else if (exc_matches(e,&exc_e_illinstr))
            estr = "exc_e_illinstr";
        else if (exc_matches(e,&exc_e_resaddr))
            estr = "exc_e_resaddr";
        else if (exc_matches(e,&exc_e_privinst))
            estr = "exc_e_privinst";
        else if (exc_matches(e,&exc_e_resoper))
            estr = "exc_e_resoper";
        else if (exc_matches(e,&exc_e_SIGTRAP))
            estr = "exc_e_SIGTRAP";
        else if (exc_matches(e,&exc_e_SIGIOT))
            estr = "exc_e_SIGIOT";
        else if (exc_matches(e,&exc_e_SIGEMT))
            estr = "exc_e_SIGEMT";
        else if (exc_matches(e,&exc_e_aritherr))
            estr = "exc_e_aritherr";
        else if (exc_matches(e,&exc_e_SIGSYS))
            estr = "exc_e_SIGSYS";
        else if (exc_matches(e,&exc_e_SIGPIPE))
            estr = "exc_e_SIGPIPE";
        else if (exc_matches(e,&exc_e_excpu))
            estr = "exc_e_excpu";
        else if (exc_matches(e,&exc_e_exfilsiz))
            estr = "exc_e_exfilsiz";
        else if (exc_matches(e,&exc_e_intovf))
            estr = "exc_e_intovf";
        else if (exc_matches(e,&exc_e_intdiv))
            estr = "exc_e_intdiv";
        else if (exc_matches(e,&exc_e_fltovf))
            estr = "exc_e_fltovf";
        else if (exc_matches(e,&exc_e_fltdiv))
            estr = "exc_e_fltdiv";
        else if (exc_matches(e,&exc_e_fltund))
            estr = "exc_e_fltund";
        else if (exc_matches(e,&exc_e_decovf))
            estr = "exc_e_decovf";
        else if (exc_matches(e,&exc_e_subrng))
            estr = "exc_e_subrng";
        else if (exc_matches(e,&cma_e_alerted))
            estr = "cma_e_alerted";
        else if (exc_matches(e,&cma_e_assertion))
            estr = "cma_e_assertion";
        else if (exc_matches(e,&cma_e_badparam))
            estr = "cma_e_badparam";
        else if (exc_matches(e,&cma_e_bugcheck))
            estr = "cma_e_bugcheck";
        else if (exc_matches(e,&cma_e_exit_thread))
            estr = "cma_e_exit_thread";
        else if (exc_matches(e,&cma_e_existence))
            estr = "cma_e_existence";
        else if (exc_matches(e,&cma_e_in_use))
            estr = "cma_e_in_use";
        else if (exc_matches(e,&cma_e_use_error))
            estr = "cma_e_use_error";
        else if (exc_matches(e,&cma_e_wrongmutex))
            estr = "cma_e_wrongmutex";
        else if (exc_matches(e,&cma_e_stackovf))
            estr = "cma_e_stackovf";
        else if (exc_matches(e,&cma_e_nostackmem))
            estr = "cma_e_nostackmem";
        else if (exc_matches(e,&cma_e_notcmastack))
            estr = "cma_e_notcmastack";
        else if (exc_matches(e,&cma_e_unimp))
            estr = "cma_e_unimp";
        else if (exc_matches(e,&cma_e_inialrpro))
            estr = "cma_e_inialrpro";
        else if (exc_matches(e,&cma_e_defer_q_full))
            estr = "cma_e_defer_q_full";
        else if (exc_matches(e,&cma_e_signal_q_full))
            estr = "cma_e_signal_q_full";
        else if (exc_matches(e,&cma_e_alert_nesting))
            estr = "cma_e_alert_nesting";
        else
            estr = "Unknown exception";
    }
#else
    if (exc_matches(e,&rpc_x_assoc_grp_not_found))
        estr = "rpc_x_assoc_grp_not_found";
    else if (exc_matches(e,&rpc_x_cancel_timeout))
        estr = "rpc_x_cancel_timeout";
    else if (exc_matches(e,&rpc_x_coding_error))
        estr = "rpc_x_coding_error";
    else if (exc_matches(e,&rpc_x_comm_failure))
        estr = "rpc_x_comm_failure";
    else if (exc_matches(e,&rpc_x_context_id_not_found))
        estr = "rpc_x_context_id_not_found";
    else if (exc_matches(e,&rpc_x_endpoint_not_found))
        estr = "rpc_x_endpoint_not_found";
    else if (exc_matches(e,&rpc_x_in_args_too_big))
        estr = "rpc_x_in_args_too_big";
    else if (exc_matches(e,&rpc_x_invalid_binding))
        estr = "rpc_x_invalid_binding";
    else if (exc_matches(e,&rpc_x_invalid_bound))
        estr = "rpc_x_invalid_bound";
    else if (exc_matches(e,&rpc_x_invalid_call_opt))
        estr = "rpc_x_invalid_call_opt";
    else if (exc_matches(e,&rpc_x_invalid_naf_id))
        estr = "rpc_x_invalid_naf_id";
    else if (exc_matches(e,&rpc_x_invalid_rpc_protseq))
        estr = "rpc_x_invalid_rpc_protseq";
    else if (exc_matches(e,&rpc_x_invalid_tag))
        estr = "rpc_x_invalid_tag";
    else if (exc_matches(e,&rpc_x_invalid_timeout))
        estr = "rpc_x_invalid_timeout";
    else if (exc_matches(e,&rpc_x_manager_not_entered))
        estr = "rpc_x_manager_not_entered";
    else if (exc_matches(e,&rpc_x_max_descs_exceeded))
        estr = "rpc_x_max_descs_exceeded";
    else if (exc_matches(e,&rpc_x_no_fault))
        estr = "rpc_x_no_fault";
    else if (exc_matches(e,&rpc_x_no_memory))
        estr = "rpc_x_no_memory";
    else if (exc_matches(e,&rpc_x_not_rpc_tower))
        estr = "rpc_x_not_rpc_tower";
    else if (exc_matches(e,&rpc_x_object_not_found))
        estr = "rpc_x_object_not_found";
    else if (exc_matches(e,&rpc_x_op_rng_error))
        estr = "rpc_x_op_rng_error";
    else if (exc_matches(e,&rpc_x_protocol_error))
        estr = "rpc_x_protocol_error";
    else if (exc_matches(e,&rpc_x_protseq_not_supported))
        estr = "rpc_x_protseq_not_supported";
    else if (exc_matches(e,&rpc_x_rpcd_comm_failure))
        estr = "rpc_x_rpcd_comm_failure";
    else if (exc_matches(e,&rpc_x_server_too_busy))
        estr = "rpc_x_server_too_busy";
    else if (exc_matches(e,&rpc_x_unknown_if))
        estr = "rpc_x_unknown_if";
    else if (exc_matches(e,&rpc_x_unknown_error))
        estr = "rpc_x_unknown_error";
    else if (exc_matches(e,&rpc_x_unknown_mgr_type))
        estr = "rpc_x_unknown_mgr_type";
    else if (exc_matches(e,&rpc_x_unknown_reject))
        estr = "rpc_x_unknown_reject";
    else if (exc_matches(e,&rpc_x_unknown_remote_fault))
        estr = "rpc_x_unknown_remote_fault";
    else if (exc_matches(e,&rpc_x_unsupported_type))
        estr = "rpc_x_unsupported_type";
    else if (exc_matches(e,&rpc_x_who_are_you_failed))
        estr = "rpc_x_who_are_you_failed";
    else if (exc_matches(e,&rpc_x_wrong_boot_time))
        estr = "rpc_x_wrong_boot_time";
    else if (exc_matches(e,&rpc_x_wrong_kind_of_binding))
        estr = "rpc_x_wrong_kind_of_binding";
    else if (exc_matches(e,&rpc_x_access_control_info_inv))
        estr = "rpc_x_access_control_info_inv";
    else if (exc_matches(e,&rpc_x_assoc_grp_max_exceeded))
        estr = "rpc_x_assoc_grp_max_exceeded";
    else if (exc_matches(e,&rpc_x_assoc_shutdown))
        estr = "rpc_x_assoc_shutdown";
    else if (exc_matches(e,&rpc_x_cannot_accept))
        estr = "rpc_x_cannot_accept";
    else if (exc_matches(e,&rpc_x_cannot_connect))
        estr = "rpc_x_cannot_connect";
    else if (exc_matches(e,&rpc_x_cant_inq_socket))
        estr = "rpc_x_cant_inq_socket";
    else if (exc_matches(e,&rpc_x_connect_closed_by_rem))
        estr = "rpc_x_connect_closed_by_rem";
    else if (exc_matches(e,&rpc_x_connect_no_resources))
        estr = "rpc_x_connect_no_resources";
    else if (exc_matches(e,&rpc_x_connect_rejected))
        estr = "rpc_x_connect_rejected";
    else if (exc_matches(e,&rpc_x_connect_timed_out))
        estr = "rpc_x_connect_timed_out";
    else if (exc_matches(e,&rpc_x_connection_aborted))
        estr = "rpc_x_connection_aborted";
    else if (exc_matches(e,&rpc_x_connection_closed))
        estr = "rpc_x_connection_closed";
    else if (exc_matches(e,&rpc_x_host_unreachable))
        estr = "rpc_x_host_unreachable";
    else if (exc_matches(e,&rpc_x_invalid_endpoint_format))
        estr = "rpc_x_invalid_endpoint_format";
    else if (exc_matches(e,&rpc_x_loc_connect_aborted))
        estr = "rpc_x_loc_connect_aborted";
    else if (exc_matches(e,&rpc_x_network_unreachable))
        estr = "rpc_x_network_unreachable";
    else if (exc_matches(e,&rpc_x_no_rem_endpoint))
        estr = "rpc_x_no_rem_endpoint";
    else if (exc_matches(e,&rpc_x_rem_host_crashed))
        estr = "rpc_x_rem_host_crashed";
    else if (exc_matches(e,&rpc_x_rem_host_down))
        estr = "rpc_x_rem_host_down";
    else if (exc_matches(e,&rpc_x_rem_network_shutdown))
        estr = "rpc_x_rem_network_shutdown";
    else if (exc_matches(e,&rpc_x_rpc_prot_version_mismatch))
        estr = "rpc_x_rpc_prot_version_mismatch";
    else if (exc_matches(e,&rpc_x_string_too_long))
        estr = "rpc_x_string_too_long";
    else if (exc_matches(e,&rpc_x_too_many_rem_connects))
        estr = "rpc_x_too_many_rem_connects";
    else if (exc_matches(e,&rpc_x_tsyntaxes_unsupported))
        estr = "rpc_x_tsyntaxes_unsupported";
    else if (exc_matches(e,&rpc_x_binding_vector_full))
        estr = "rpc_x_binding_vector_full";
    else if (exc_matches(e,&rpc_x_entry_not_found))
        estr = "rpc_x_entry_not_found";
    else if (exc_matches(e,&rpc_x_group_not_found))
        estr = "rpc_x_group_not_found";
    else if (exc_matches(e,&rpc_x_incomplete_name))
        estr = "rpc_x_incomplete_name";
    else if (exc_matches(e,&rpc_x_invalid_arg))
        estr = "rpc_x_invalid_arg";
    else if (exc_matches(e,&rpc_x_invalid_import_context))
        estr = "rpc_x_invalid_import_context";
    else if (exc_matches(e,&rpc_x_invalid_inquiry_context))
        estr = "rpc_x_invalid_inquiry_context";
    else if (exc_matches(e,&rpc_x_invalid_inquiry_type))
        estr = "rpc_x_invalid_inquiry_type";
    else if (exc_matches(e,&rpc_x_invalid_lookup_context))
        estr = "rpc_x_invalid_lookup_context";
    else if (exc_matches(e,&rpc_x_invalid_name_syntax))
        estr = "rpc_x_invalid_name_syntax";
    else if (exc_matches(e,&rpc_x_invalid_object))
        estr = "rpc_x_invalid_object";
    else if (exc_matches(e,&rpc_x_invalid_vers_option))
        estr = "rpc_x_invalid_vers_option";
    else if (exc_matches(e,&rpc_x_name_service_unavailable))
        estr = "rpc_x_name_service_unavailable";
    else if (exc_matches(e,&rpc_x_no_env_setup))
        estr = "rpc_x_no_env_setup";
    else if (exc_matches(e,&rpc_x_no_more_bindings))
        estr = "rpc_x_no_more_bindings";
    else if (exc_matches(e,&rpc_x_no_more_elements))
        estr = "rpc_x_no_more_elements";
    else if (exc_matches(e,&rpc_x_not_found))
        estr = "rpc_x_not_found";
    else if (exc_matches(e,&rpc_x_not_rpc_entry))
        estr = "rpc_x_not_rpc_entry";
    else if (exc_matches(e,&rpc_x_obj_uuid_not_found))
        estr = "rpc_x_obj_uuid_not_found";
    else if (exc_matches(e,&rpc_x_profile_not_found))
        estr = "rpc_x_profile_not_found";
    else if (exc_matches(e,&rpc_x_unsupported_name_syntax))
        estr = "rpc_x_unsupported_name_syntax";
    else if (exc_matches(e,&rpc_x_auth_bad_integrity))
        estr = "rpc_x_auth_bad_integrity";
    else if (exc_matches(e,&rpc_x_auth_badaddr))
        estr = "rpc_x_auth_badaddr";
    else if (exc_matches(e,&rpc_x_auth_baddirection))
        estr = "rpc_x_auth_baddirection";
    else if (exc_matches(e,&rpc_x_auth_badkeyver))
        estr = "rpc_x_auth_badkeyver";
    else if (exc_matches(e,&rpc_x_auth_badmatch))
        estr = "rpc_x_auth_badmatch";
    else if (exc_matches(e,&rpc_x_auth_badorder))
        estr = "rpc_x_auth_badorder";
    else if (exc_matches(e,&rpc_x_auth_badseq))
        estr = "rpc_x_auth_badseq";
    else if (exc_matches(e,&rpc_x_auth_badversion))
        estr = "rpc_x_auth_badversion";
    else if (exc_matches(e,&rpc_x_auth_field_toolong))
        estr = "rpc_x_auth_field_toolong";
    else if (exc_matches(e,&rpc_x_auth_inapp_cksum))
        estr = "rpc_x_auth_inapp_cksum";
    else if (exc_matches(e,&rpc_x_auth_method))
        estr = "rpc_x_auth_method";
    else if (exc_matches(e,&rpc_x_auth_msg_type))
        estr = "rpc_x_auth_msg_type";
    else if (exc_matches(e,&rpc_x_auth_modified))
        estr = "rpc_x_auth_modified";
    else if (exc_matches(e,&rpc_x_auth_mut_fail))
        estr = "rpc_x_auth_mut_fail";
    else if (exc_matches(e,&rpc_x_auth_nokey))
        estr = "rpc_x_auth_nokey";
    else if (exc_matches(e,&rpc_x_auth_not_us))
        estr = "rpc_x_auth_not_us";
    else if (exc_matches(e,&rpc_x_auth_repeat))
        estr = "rpc_x_auth_repeat";
    else if (exc_matches(e,&rpc_x_auth_skew))
        estr = "rpc_x_auth_skew";
    else if (exc_matches(e,&rpc_x_auth_tkt_expired))
        estr = "rpc_x_auth_tkt_expired";
    else if (exc_matches(e,&rpc_x_auth_tkt_nyv))
        estr = "rpc_x_auth_tkt_nyv";
    else if (exc_matches(e,&rpc_x_call_id_not_found))
        estr = "rpc_x_call_id_not_found";
    else if (exc_matches(e,&rpc_x_credentials_too_large))
        estr = "rpc_x_credentials_too_large";
    else if (exc_matches(e,&rpc_x_invalid_checksum))
        estr = "rpc_x_invalid_checksum";
    else if (exc_matches(e,&rpc_x_invalid_crc))
        estr = "rpc_x_invalid_crc";
    else if (exc_matches(e,&rpc_x_invalid_credentials))
        estr = "rpc_x_invalid_credentials";
    else if (exc_matches(e,&rpc_x_key_id_not_found))
        estr = "rpc_x_key_id_not_found";
    else if (exc_matches(e,&rpc_x_ss_char_trans_open_fail))
        estr = "rpc_x_ss_char_trans_open_fail";
    else if (exc_matches(e,&rpc_x_ss_char_trans_short_file))
        estr = "rpc_x_ss_char_trans_short_file";
    else if (exc_matches(e,&rpc_x_ss_context_damaged))
        estr = "rpc_x_ss_context_damaged";
    else if (exc_matches(e,&rpc_x_ss_context_mismatch))
        estr = "rpc_x_ss_context_mismatch";
    else if (exc_matches(e,&rpc_x_ss_in_null_context))
        estr = "rpc_x_ss_in_null_context";
    else if (exc_matches(e,&rpc_x_ss_pipe_closed))
        estr = "rpc_x_ss_pipe_closed";
    else if (exc_matches(e,&rpc_x_ss_pipe_comm_error))
        estr = "rpc_x_ss_pipe_comm_error";
    else if (exc_matches(e,&rpc_x_ss_pipe_discipline_error))
        estr = "rpc_x_ss_pipe_discipline_error";
    else if (exc_matches(e,&rpc_x_ss_pipe_empty))
        estr = "rpc_x_ss_pipe_empty";
    else if (exc_matches(e,&rpc_x_ss_pipe_memory))
        estr = "rpc_x_ss_pipe_memory";
    else if (exc_matches(e,&rpc_x_ss_pipe_order))
        estr = "rpc_x_ss_pipe_order";
    else if (exc_matches(e,&rpc_x_ss_remote_comm_failure))
        estr = "rpc_x_ss_remote_comm_failure";
    else if (exc_matches(e,&rpc_x_ss_remote_no_memory))
        estr = "rpc_x_ss_remote_no_memory";
    else if (exc_matches(e,&exc_e_uninitexc))
        estr = "exc_e_uninitexc";
    else if (exc_matches(e,&exc_e_illaddr))
        estr = "exc_e_illaddr";
    else if (exc_matches(e,&exc_e_exquota))
        estr = "exc_e_exquota";
    else if (exc_matches(e,&exc_e_insfmem))
        estr = "exc_e_insfmem";
    else if (exc_matches(e,&exc_e_nopriv))
        estr = "exc_e_nopriv";
    else if (exc_matches(e,&exc_e_illinstr))
        estr = "exc_e_illinstr";
    else if (exc_matches(e,&exc_e_resaddr))
        estr = "exc_e_resaddr";
    else if (exc_matches(e,&exc_e_privinst))
        estr = "exc_e_privinst";
    else if (exc_matches(e,&exc_e_resoper))
        estr = "exc_e_resoper";
    else if (exc_matches(e,&exc_e_SIGTRAP))
        estr = "exc_e_SIGTRAP";
    else if (exc_matches(e,&exc_e_SIGIOT))
        estr = "exc_e_SIGIOT";
    else if (exc_matches(e,&exc_e_SIGEMT))
        estr = "exc_e_SIGEMT";
    else if (exc_matches(e,&exc_e_aritherr))
        estr = "exc_e_aritherr";
    else if (exc_matches(e,&exc_e_SIGSYS))
        estr = "exc_e_SIGSYS";
    else if (exc_matches(e,&exc_e_SIGPIPE))
        estr = "exc_e_SIGPIPE";
    else if (exc_matches(e,&exc_e_excpu))
        estr = "exc_e_excpu";
    else if (exc_matches(e,&exc_e_exfilsiz))
        estr = "exc_e_exfilsiz";
    else if (exc_matches(e,&exc_e_intovf))
        estr = "exc_e_intovf";
    else if (exc_matches(e,&exc_e_intdiv))
        estr = "exc_e_intdiv";
    else if (exc_matches(e,&exc_e_fltovf))
        estr = "exc_e_fltovf";
    else if (exc_matches(e,&exc_e_fltdiv))
        estr = "exc_e_fltdiv";
    else if (exc_matches(e,&exc_e_fltund))
        estr = "exc_e_fltund";
    else if (exc_matches(e,&exc_e_decovf))
        estr = "exc_e_decovf";
    else if (exc_matches(e,&exc_e_subrng))
        estr = "exc_e_subrng";
    else if (exc_matches(e,&cma_e_alerted))
        estr = "cma_e_alerted";
    else if (exc_matches(e,&cma_e_assertion))
        estr = "cma_e_assertion";
    else if (exc_matches(e,&cma_e_badparam))
        estr = "cma_e_badparam";
    else if (exc_matches(e,&cma_e_bugcheck))
        estr = "cma_e_bugcheck";
    else if (exc_matches(e,&cma_e_exit_thread))
        estr = "cma_e_exit_thread";
    else if (exc_matches(e,&cma_e_existence))
        estr = "cma_e_existence";
    else if (exc_matches(e,&cma_e_in_use))
        estr = "cma_e_in_use";
    else if (exc_matches(e,&cma_e_use_error))
        estr = "cma_e_use_error";
    else if (exc_matches(e,&cma_e_wrongmutex))
        estr = "cma_e_wrongmutex";
    else if (exc_matches(e,&cma_e_stackovf))
        estr = "cma_e_stackovf";
    else if (exc_matches(e,&cma_e_nostackmem))
        estr = "cma_e_nostackmem";
    else if (exc_matches(e,&cma_e_notcmastack))
        estr = "cma_e_notcmastack";
    else if (exc_matches(e,&cma_e_unimp))
        estr = "cma_e_unimp";
    else if (exc_matches(e,&cma_e_inialrpro))
        estr = "cma_e_inialrpro";
    else if (exc_matches(e,&cma_e_defer_q_full))
        estr = "cma_e_defer_q_full";
    else if (exc_matches(e,&cma_e_signal_q_full))
        estr = "cma_e_signal_q_full";
    else if (exc_matches(e,&cma_e_alert_nesting))
        estr = "cma_e_alert_nesting";
    else
        estr = "Unknown exception";
#endif

    PRINT("EXCEPTION RAISED: %s\n", estr);
    return;

} /* end print_exception() */

/* EOF util.c */

