Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

cabal_netbase.h

00001 /*
00002    CABAL PROTOCOL
00003    CAched BAlanced LAN
00004 
00005    Abstract base class for basic services.
00006 
00007    $Id: cabal_netbase.h,v 1.4 2004/03/29 02:15:52 jonnymind Exp $
00008 ---------------------------------------------
00009    Begin      :
00010    Author     : Giancarlo Niccolai
00011 
00012    Last modified because:
00013 
00014 */
00015 
00016 #ifndef CABAL_NETBASE_H
00017 #define CABAL_NETBASE_H
00018 
00019 #include <string>
00020 #include <list>
00021 #include <cabal_defs.h>
00022 
00023 namespace Cabal {
00024 
00025 typedef std::list<std::string> StringList;
00026 typedef StringList::iterator StringListIter;
00027 typedef StringList::const_iterator StringListConstIter;
00028 
00038 typedef struct net_interface_entry 
00039 {
00040    std::string name;
00041    std::string ipaddr;
00042    std::string netmask;
00043 } NET_INTERFACE;
00044 
00047 class NetBase
00048 {
00049 public:
00050 
00051    static bool init()   throw(InitError);
00052    static bool exit()   throw(DataIncompleteError);
00053    
00055    static RawSocket createTCPSocket();
00056    static RawSocket createUDPSocket();
00057    
00059    static int closeSocket( RawSocket s );
00060    
00064    static bool bind( const RawSocket s, const SockAddrInet &addr );
00066    static bool connect( const RawSocket s, const SockAddrInet &addr );
00067    
00069    static bool listen( const RawSocket m_skCom, const int incomingMax );
00070    
00074    static RawSocket accept( const RawSocket s, SockAddrInet *in );
00075    
00077    static void initSockAddr( SockAddrInet &attr );
00078    static void initSockAddr( SockAddrInet &attr, const char *ip );
00079    static void initSockAddr( SockAddrInet &attr, const char *ip, const NetPort port );
00080    static void initSockAddr( SockAddrInet &attr, const NetAddr data, const NetPort port );
00081    
00083    static bool SockAddrIsZero( const SockAddrInet &addr );
00084    static bool SockAddrIsSame( const SockAddrInet &addr, const SockAddrInet &addr1 );
00085    static void SockAddrSetPort( SockAddrInet &attr, NetPort port );
00086    static NetPort SockAddrGetPort( const SockAddrInet &attr );
00087    
00089    static bool getHostList(
00090       const std::string &name,
00091       std::string &real_name,
00092       char *real_ip,
00093       NetAddr *other_addrs, int na_count );
00094       
00108    static bool addrToString( const SockAddrInet &addr, char *dest );
00114    static bool addrToString( const NetAddr addr, char *dest );
00115    
00126    static bool stringToAddr( const char *source, SockAddrInet &addr );
00127    
00129    static bool isAddressString( const char *source );
00130    
00132    static int errorCode();
00133 
00135    static void resetError();
00136    
00138    static std::string errorDescription( const int osCode );
00139    
00141    static RawSocket dup( RawSocket s );
00142    
00144    static bool inProgress();
00146    static bool errorAgain();
00148    static bool errorAgain(const int error);
00150    static bool errorPipe();
00151  
00153    static void setNonBlocking( RawSocket s );
00154    
00156    static void setBlocking( RawSocket s );
00157    
00161    static void setTCPDefaults( const RawSocket s );
00162 
00164    static bool validSocket( const RawSocket s );
00166    static void invalidate( RawSocket &s );
00167   
00169    static int getSocketOption( const RawSocket s, const int level, int &iErrval );
00170    
00172    static int send( const RawSocket s, const void *buffer, const int len, const int params );
00173 
00175    static int recv( const RawSocket s, void *buffer, const int len, const int params );
00176    
00178    static int sendto(const RawSocket s, const void *buffer, const int len, const int params,
00179             const SockAddrInet *remote, const int remsize );
00180             
00182    static int recvfrom(const RawSocket s, void *buffer, const int len, const int params,
00183             SockAddrInet *remote, int *remsize );
00184    
00186    static void shutdown( const RawSocket s );
00187    
00188    
00192    static void sleep ( const int msecs );
00193    
00195    static NetPort hostToNetPort( const NetPort data );
00196    static NetAddr hostToNetAddr( const NetAddr data );
00197    static NetPort netToHostPort( const NetPort data );
00198    static NetAddr netToHostAddr( const NetAddr data );
00199 
00203    static MSECS timeOfDay();
00204 };
00205 
00206 }
00207 
00208 #endif
00209 
00210 /* end of cabal_netbase.h */

Generated on Sat Apr 10 17:41:48 2004 for Cabal by doxygen 1.3.5