⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkaddress.h

📁 symbian平台S60_2nd_FP2_SC rtp实现
💻 H
字号:
#ifndef NETWORKADDRESS_HXX_
#define NETWORKADDRESS_HXX_


#include "vtypes.h"
#include "RtpTools.h"

#define IPV4_LENGTH 4

/** Class which implements a network address.  includes functionality
 * to look up network addresses from hostnames or ip addresses as
 * strings.
 */
class NetworkAddress;
bool operator < ( NetworkAddress & xAddress,
						const NetworkAddress & yAddress );
bool operator == ( NetworkAddress & xAddress,
						 const NetworkAddress & yAddress );
bool operator != ( NetworkAddress & xAddress,
						 const NetworkAddress & yAddress );

class NetworkAddress
{
   public:
      /// default constructor. The host is initially set to localhost.
      NetworkAddress ( int port = -1 );

      /** The host hostName can be in the same form as passed to
       * setHostName()
       */
      NetworkAddress ( const TDesC8& hostName, int port = -1 );

	  void setHostName ( const TDesC8& theAddress );
	  
      /// get hostname in the form "lab1.vovida.com"
      TDesC8& getHostName () ;

      /// get IP address as a string in the form "192.168.4.5"
      TDesC8& getIpName () ;

      /** return the IP4 address packed as an unsigned int, in
       * network byte order.
       */
      u_int32_t getIp4Address () ;

      /** return the address in a sockaddr.  This value is assigned
       * @param socka    returned address
       */
      void getSockAddr(struct sockaddr & socka) ;

      /// compare two IP addresses
      friend bool operator < ( NetworkAddress & xAddress,
                               NetworkAddress & yAddress );

      /// compare two IP addresses
      friend bool operator == ( NetworkAddress & xAddress,
                                NetworkAddress & yAddress );

      /// compare two IP addresses
      friend bool operator != ( NetworkAddress & xAddress,
                                NetworkAddress & yAddress );

      /// copy constructor
      NetworkAddress(  NetworkAddress& x);

      /// assignment operator =
      NetworkAddress& operator=( NetworkAddress& x );


      /// Mutexes the gethostbyname(), return 0 when successful
      int getHostByName(const char* hostName,
                               struct hostent* hEnt,
                               char* buf,
                               int buflen,
                               int* thrErrno);

      /// calls unix gethostname()
      TDesC8& getLocalHostName();
      
      /// value if host lookup failed
       int getHostLookupFailed;
      /// value if host lookup succeeded
        
	   int getHostLookupOK;
   public:
	  TInetAddr Address;
	  void SetInetAddr();

   private:
      /// Check if parameter is a valid IP address
      bool is_valid_ip_addr (const TDesC8& ip_addr) ;
	  
      void initIpAddress() ;
    
      unsigned char ipAddress[IPV4_LENGTH];  // it's in network byte order
	  int iPort;
      TBuf8<256> rawHostName;
	  TBuf8<256> hostName;
      bool ipAddressSet;

	private:
		// 远程主机地址
		char remoteHost[32];
		// 远程主机端口
		int remotePort;
		// 本地端口
		int localPort;
	public:
		void GetRemoteHost(char *ahost)
		{
			if( ahost!=NULL)
			strcpy( ahost, remoteHost);
		}
		void SetRemoteHost( char * ahost)
		{
			if( ahost !=NULL)
				strcpy(remoteHost , ahost);
		}
		int  GetremotePort() {return remotePort ;}
		void SetremotePort( int aport) {remotePort = aport ;}

		int GetlocalPort(){return localPort ;}
		void SetlocalPort( int aport) {localPort = aport;}
};


// NETWORKADDRESS_HXX_
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -