• 欢迎浏览“String me = Creater\忠实的资深Linux玩家;”,请文明浏览,理性发言,有侵犯你的权益请邮件我(creater@vip.qq.com).
  • 把任何的失败都当作一次尝试,不要自卑;把所有的成功都想成是一种幸运,不要自傲。
  •    5年前 (2013-06-10)  Socket library |   6 条评论  9 
    文章评分 0 次,平均分 0.0

    这个类实际上就是套接口地址结构的封装,正如手册所说:
    This class and its subclasses is intended to be used as replacement
    for the internal data type 'ipaddr_t' and various implementations of
    IPv6 addressing found throughout the library.
    'ipaddr_t' is an IPv4 address in network byte order.
    'port_t' is the portnumber in host byte order.
    'struct in6_addr' is an IPv6 address.
    'struct in_addr' is an IPv4 address.
    该类以及其子类用于替换套接字结构,由于该类是抽象基类,所以一般都是从该类进行派生。实际上有两种套接字结构,即是PV4,IPV6两种结构,对应于SocketAddress的派生类Ipv4Address与Ipv6Address。
    代码中就是对套接字结构相关字段的设置,可以通过主机名或者ip地址获取套接字结构。

    class SocketAddress
    {
    public:
    	virtual ~SocketAddress() {}
    
    	/** Get a pointer to the address struct. */
    	virtual operator struct sockaddr *() = 0;
    
    	/** Get length of address struct. */
    	virtual operator socklen_t() = 0;
    
    	/** Compare two addresses. */
    	virtual bool operator==(SocketAddress&) = 0;
    
    	/** Set port number.
    		\param port Port number in host byte order */
    	virtual void SetPort(port_t port) = 0;
    
    	/** Get port number.
    		\return Port number in host byte order. */
    	virtual port_t GetPort() = 0;
    
    	/** Set socket address.
    		\param sa Pointer to either 'struct sockaddr_in' or 'struct sockaddr_in6'. */
    	virtual void SetAddress(struct sockaddr *sa) = 0;
    
    	/** Convert address to text. */
    	virtual std::string Convert(bool include_port) = 0;
    
    	/** Reverse lookup of address. */
    	virtual std::string Reverse() = 0;
    
    	/** Get address family. */
    	virtual int GetFamily() = 0;
    
    	/** Address structure is valid. */
    	virtual bool IsValid() = 0;
    
    	/** Get a copy of this SocketAddress object. */
    	virtual std::auto_ptr<SocketAddress> GetCopy() = 0;
    };
    
     

    除特别注明外,本站所有文章均为String me = "Creater\忠实的资深Linux玩家";原创,转载请注明出处来自http://unix8.net/home.php/1467.html

    关于

    发表评论

    暂无评论

    切换注册

    登录

    忘记密码 ?

    切换登录

    注册

    扫一扫二维码分享