From d1ddd2627b5bd5ba8d16a834ff5b9289d2e51c9a Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 21 Aug 2002 16:33:00 +0000 Subject: [PATCH] converted inlines to ordinary functions --- src/cas/generic/caNetAddr.h | 229 ++++++------------------------------ 1 file changed, 34 insertions(+), 195 deletions(-) diff --git a/src/cas/generic/caNetAddr.h b/src/cas/generic/caNetAddr.h index 87a502f6f..e83e6fad2 100644 --- a/src/cas/generic/caNetAddr.h +++ b/src/cas/generic/caNetAddr.h @@ -13,222 +13,61 @@ // special cas specific network address class so: // 1) we dont drag BSD socket headers into // the server tool -// 2) we are able to use other networking services +// 2) we are not prevented from using other networking services // besides sockets in the future // -// get() will assert fail if the init flag has not been -// set -// #ifndef caNetAddrH #define caNetAddrH +#include + #ifdef caNetAddrSock -#include "osiSock.h" +# ifdef epicsExportSharedSymbols +# define epicsExportSharedSymbols_caNetAddrH +# undef epicsExportSharedSymbols +# endif +# include "osiSock.h" +# ifdef epicsExportSharedSymbols_caNetAddrH +# define epicsExportSharedSymbols +# endif #endif -#include "epicsAssert.h" #include "shareLib.h" -class verifyCANetAddr { -public: - inline void checkSize(); -}; - class epicsShareClass caNetAddr { - friend class verifyCANetAddr; public: - enum caNetAddrType {casnaUDF, casnaInet}; + void clear (); + caNetAddr (); + bool isValid () const; + bool operator == ( const caNetAddr & rhs ) const; + bool operator != ( const caNetAddr & rhs) const; + caNetAddr operator = ( const caNetAddr & naIn ); + void stringConvert ( char *pString, unsigned stringLength ) const; + void selfTest (); - // - // clear() - // - inline void clear () - { - this->type = casnaUDF; - } - - // - // caNetAddr() - // - inline caNetAddr () - { - this->clear(); - } - - inline bool isInet () const - { - return this->type == casnaInet; - } - - inline bool isValid () const - { - return this->type != casnaUDF; - } - - inline bool operator == (const caNetAddr &rhs) const // X aCC 361 - { - if (this->type != rhs.type) { - return false; - } -# ifdef caNetAddrSock - if (this->type==casnaInet) { - return (this->addr.ip.sin_addr.s_addr == rhs.addr.ip.sin_addr.s_addr) && - (this->addr.ip.sin_port == rhs.addr.ip.sin_port); - } -# endif - else { - return false; - } - } - - inline bool operator != (const caNetAddr &rhs) const - { - return ! this->operator == (rhs); - } - - // - // This is specified so that compilers will not use one of - // the following assignment operators after converting to a - // sockaddr_in or a sockaddr first. - // - // caNetAddr caNetAddr::operator =(const struct sockaddr_in&) - // caNetAddr caNetAddr::operator =(const struct sockaddr&) - // - inline caNetAddr operator = (const caNetAddr &naIn) - { - this->addr = naIn.addr; - this->type = naIn.type; - return *this; - } - - // - // convert to the string equivalent of the address - // - void stringConvert (char *pString, unsigned stringLength) const; - - // - // conditionally drag BSD socket headers into the server - // and server tool - // - // to use this #define caNetAddrSock - // -# ifdef caNetAddrSock - inline void setSockIP (unsigned long inaIn, unsigned short portIn) - { - this->type = casnaInet; - this->addr.ip.sin_family = AF_INET; - this->addr.ip.sin_addr.s_addr = inaIn; - this->addr.ip.sin_port = portIn; - } - - inline void setSockIP (const struct sockaddr_in &sockIPIn) - { - this->type = casnaInet; - assert (sockIPIn.sin_family == AF_INET); - this->addr.ip = sockIPIn; - } - - inline void setSock (const struct sockaddr &sock) - { - assert (sock.sa_family == AF_INET); - this->type = casnaInet; - const struct sockaddr_in *psip = - reinterpret_cast (&sock); - this->addr.ip = *psip; - } - - inline caNetAddr (const struct sockaddr_in &sockIPIn) - { - this->setSockIP (sockIPIn); - } - - inline caNetAddr operator = (const struct sockaddr_in &sockIPIn) - { - this->setSockIP (sockIPIn); - return *this; - } - - inline caNetAddr operator = (const struct sockaddr &sockIn) - { - this->setSock (sockIn); - return *this; - } - - inline struct sockaddr_in getSockIP() const - { - assert (this->type==casnaInet); - return this->addr.ip; - } - - inline struct sockaddr getSock() const - { - struct sockaddr sa; - assert (this->type==casnaInet); - struct sockaddr_in *psain = - reinterpret_cast (&sa); - *psain = this->addr.ip; - - return sa; - } - - inline operator sockaddr_in () const - { - return this->getSockIP(); - } - - inline operator sockaddr () const - { - return this->getSock(); - } - - # endif // caNetAddrSock + // support for socket addresses + // (other address formats may be supported in the future) + bool isInet () const; + void setSockIP ( unsigned long inaIn, unsigned short portIn ); + void setSockIP ( const struct sockaddr_in & sockIPIn ); + void setSock ( const struct sockaddr & sock ); + caNetAddr ( const struct sockaddr_in & sockIPIn ); + caNetAddr operator = ( const struct sockaddr & sockIn ); + caNetAddr operator = ( const struct sockaddr_in & sockIPIn ); + struct sockaddr getSock() const; + struct sockaddr_in getSockIP() const; + operator struct sockaddr () const; + operator struct sockaddr_in () const; private: + enum caNetAddrType { casnaUDF, casnaInet } type; union { + unsigned char pad[16]; # ifdef caNetAddrSock struct sockaddr_in ip; # endif - // - // this must be as big or bigger - // than the largest field - // - // see checkDummySize() above - // - unsigned char dummy[16]; } addr; - - caNetAddrType type; }; -inline void verifyCANetAddr::checkSize() -{ - // - // temp used because brain dead - // ms compiler does not allow - // use of scope res operator - // - caNetAddr t; - size_t ds = sizeof (t.addr.dummy); - size_t as = sizeof (t.addr); - assert (ds==as); -} - -// -// caNetAddr::stringConvert () -// -inline void caNetAddr::stringConvert (char *pString, unsigned stringLength) const -{ -# ifdef caNetAddrSock - if (this->type==casnaInet) { - ipAddrToA (&this->addr.ip, pString, stringLength); - return; - } -# endif - if (stringLength) { - strncpy (pString, "", stringLength); - pString[stringLength-1] = '\n'; - } -} - #endif // caNetAddrH