Files
epics-base/src/ca/net_convert.h
1995-02-13 03:32:27 +00:00

93 lines
2.4 KiB
C

/*
* $Id$
*
* N E T _ C O N V E R T . H
* MACROS for rapid conversion between HOST data formats and those used
* by the IOCs (NETWORK).
*
*
* joh 09-13-90 force MIT sign to zero if exponent is zero
* to prevent a reseved operand fault.
*
* joh 03-16-94 Added double fp
* joh 11-02-94 Moved all fp cvrt to functions in
* convert.c
*
*
*/
#ifdef CA_LITTLE_ENDIAN
# ifndef ntohs
# define ntohs(SHORT)\
( ((SHORT) & 0x00ff) << 8 | ((SHORT) & 0xff00) >> 8 )
# endif
# ifndef htons
# define htons(SHORT)\
( ((SHORT) & 0x00ff) << 8 | ((SHORT) & 0xff00) >> 8 )
# endif
#else
# ifndef ntohs
# define ntohs(SHORT) (SHORT)
# endif
# ifndef htons
# define htons(SHORT) (SHORT)
# endif
#endif
#ifdef CA_LITTLE_ENDIAN
# ifndef ntohl
# define ntohl(LONG)\
(\
((LONG) & 0xff000000) >> 24 |\
((LONG) & 0x000000ff) << 24 |\
((LONG) & 0x0000ff00) << 8 |\
((LONG) & 0x00ff0000) >> 8\
)
# endif
# ifndef htonl
# define htonl(LONG)\
(\
((LONG) & 0x000000ff) << 24 |\
((LONG) & 0xff000000) >> 24 |\
((LONG) & 0x00ff0000) >> 8 |\
((LONG) & 0x0000ff00) << 8\
)
# endif
# else
# ifndef ntohl
# define ntohl(LONG) (LONG)
# endif
# ifndef htonl
# define htonl(LONG) (LONG)
# endif
#endif
#if defined(CA_FLOAT_IEEE) && !defined(CA_LITTLE_ENDIAN)
# define htond(IEEEhost, IEEEnet) \
(*(double *)(IEEEnet) = *(double *)(IEEEhost))
# define ntohd(IEEEnet, IEEEhost) \
(*(double *)(IEEEhost) = *(double *)(IEEEnet))
# define htonf(IEEEhost, IEEEnet) \
(*(float *)(IEEEnet) = *(float *)(IEEEhost))
# define ntohf(IEEEnet, IEEEhost) \
(*(float *)(IEEEhost) = *(float *)(IEEEnet))
#elif defined(CA_FLOAT_IEEE) && defined(CA_LITTLE_ENDIAN)
# define ntohf(NET,HOST) \
{*((u_long *)(HOST)) = ntohl(*((u_long *)(NET )));}
# define htonf(HOST,NET) \
{*((u_long *)(NET) ) = htonl(*((u_long *)(HOST)));}
# define ntohd(NET,HOST) \
{ ((u_long *)(HOST))[1] = ntohl(((u_long *)(NET))[0]) ; \
((u_long *)(HOST))[0] = ntohl(((u_long *)(NET))[1]) ;}
# define htond(HOST,NET) \
{ ((u_long *)(NET))[1] = htonl(((u_long *)(HOST))[0]) ; \
((u_long *)(NET))[0] = htonl(((u_long *)(HOST))[1]) ;}
#else
void htond(double *pHost, double *pNet);
void ntohd(double *pNet, double *pHost);
void htonf(float *pHost, float *pNet);
void ntohf(float *pNet, float *pHost);
#endif