/* * (c) Copyright, Real-Time Innovations, 2005-2024. * All rights reserved. * * No duplications, whole or partial, manual or electronic, may be made * without express written permission. Any such copies, or * revisions thereof, must display this notice unaltered. * This code contains trade secrets of Real-Time Innovations, Inc. */ #ifndef osapi_host_h #define osapi_host_h #include "osapi/osapi_type.h" #include "osapi/osapi_dll.h" #ifdef __cplusplus extern "C" { #endif /** @internal \file \brief host (AKA node) utility */ /** @internal \defgroup RTIOsapiHostClass RTIOsapiHost * \ingroup RTIOsapiModule * * \brief OS independent encapsulation of a node, or a host, on which * 1 or more processes run */ /** @internal \ingroup RTIOsapiHostClass * @brief host id, which is unique for the host. Host ID is generated based on * the first NIC up * * @note this method internally generates exceptions, * therefore the caller does not need to log an exception. */ extern RTIOsapiDllExport RTI_UINT32 RTIOsapiHost_getId(void); #define RTI_OSAPI_HOSTID_LEN (16) #define RTI_OSAPI_HOSTID_UNKNOWN \ { \ { \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ } \ } struct RTIOsapiHostId { RTI_UINT8 value[RTI_OSAPI_HOSTID_LEN]; }; /** @internal \ingroup RTIOsapiHostClass * @brief host id, which is unique for the host. * Host ID is generated based on the first NIC, no matter if it is up or not. * * This method returns a 128 bit host id. * * @note this method internally generates exceptions, * therefore the caller does not need to log an exception. */ extern RTIOsapiDllExport void RTIOsapiHost_getUniqueId( struct RTIOsapiHostId *hostId); /** @internal \ingroup RTIOsapiHostClass * @brief Checks if a host id is unknown */ extern RTIOsapiDllExport RTIBool RTIOsapiHost_isUnknown(struct RTIOsapiHostId *hostId); /* 64bit MAC address of host */ #define RTIHOST_HWADDR_LEN (8) #define RTIHOSTWADDR_UNKNOWN \ { \ { \ 0, 0, 0, 0, 0, 0, 0, 0 \ } \ } struct RTIHostHWAddr { RTI_UINT8 hwAddr[RTIHOST_HWADDR_LEN]; }; /** @internal \ingroup RTIOsapiHostClass * @brief retrieve the host hw addr, which is the MAC address of the first * interface found. The returned structure will contain either a 48bit or * 64bit MAC address. 48bit addresses will occupy the first 6 bytes of the * hwAddr member of the structure, and the last 2 bytes will be zero. 48bit * MAC addresses will not be converted to the EUI-64 format. * * @param hwAddrOut \b out. Will return all zeros on failure for hwAddr member. * * @note this method internally generates exceptions, * therefore the caller does not need to log an exception. */ extern RTIOsapiDllExport void RTIOsapiHost_getHWAddress( struct RTIHostHWAddr *hwAddrOut); /** @internal \ingroup RTIOsapiHostClass * @brief retrieve the hostname. * * @param hostname \b out. Will return a null terminated hostname in the array * name * @param len. The length of the array name. * * @return On error, -1 is returned. */ extern RTIOsapiDllExport int RTIOsapiHost_getHostName(char *name, int len); struct RTINtpTime; /** @internal \ingroup RTIOsapiHostClass * @pre the this submodule's internal singleton must be initialized through * RTIOsapiHost_getId. * * @brief using the hostId as the seed, generate a "random" time in range * [timeMinIn, timeMaxIn]. */ extern RTIOsapiDllExport void RTIOsapiHost_generateRandomTime( struct RTINtpTime *randomTimeOut, const struct RTINtpTime *timeMinIn, const struct RTINtpTime *timeMaxIn); /* 12-byte UUID */ #define GUIDPREFIX_UNKNOWN \ { \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ } typedef unsigned int RTIOsapiGuidPrefix[3]; /** @internal \ingroup RTIOsapiHostClass * @brief obtain a Universally Unique ID. * * @param uuid_out \b out. Will return a 12-byte unique ID */ extern RTIOsapiDllExport void RTIOsapiHost_generate_uuid( RTIOsapiGuidPrefix *uuid_out); #ifdef __cplusplus } /* extern "C" */ #endif #include "osapi/osapi_host_impl.h" #endif /* osapi_host_h */