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

📄 warnetaddress.h

📁 ftpserver very good sample
💻 H
字号:
/**    The net address is a generic way to handle network   addresses. It's purpose is to make the transition to   IPv6 as painless as possible.*/#ifndef WAR_NET_ADDRESS_H#define WAR_NET_ADDRESS_H/* SYSTEM INCLUDES */#if defined(HAVE_WINSOCK) && !defined(WAR_WINSOCK2_H_INCLUDED)#   define WAR_WINSOCK2_H_INCLUDED#   include <winsock2.h>#endif#if defined(HAVE_NETDB_H) && !defined(WAR_NETDB_H_INCLUDED)#   define WAR_NETDB_H_INCLUDED#   include <netdb.h>#endif#ifdef HAVE_SOCKET_H#   ifndef WAR_SOCKET_H_INCLUDED#       define WAR_SOCKET_H_INCLUDED#       include <socket.h>#   endif#elif defined(HAVE_SYS_SOCKET_H)#   ifndef WAR_SYS_SOCKET_H_INCLUDED#       define WAR_SYS_SOCKET_H_INCLUDED#       include <sys/socket.h>#   endif#endif#ifdef HAVE_NETINET_IN_H#   ifndef WAR_NETINET_IN_H_INCLUDED#       define WAR_NETINET_IN_H_INCLUDED#       include <netinet/in.h>#   endif#endif#if defined(HAVE_ARPA_INET_H) && !defined(WAR_ARPA_INET_H_INCLUDED)#   define WAR_ARPA_INET_H_INCLUDED#   include <arpa/inet.h>#endif#ifndef WAR_LIST_INCLUDED#   define WAR_LIST_INCLUDED#   include <list>#endif/* PROJECT INCLUDES */#ifndef WAR_TYPES_H#   include "WarTypes.h"#endif#ifndef WAR_EXCEPTION_H#   include "WarException.h"#endif#ifndef WAR_COLLECTOR_H#   include "WarCollector.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********/// Portable macros for in_addr bits// NB: If un*x, #include <netinet/in.h> (or whatever...)#ifndef in_addr_b1///#   define WAR_IN_ADDR_B1(a) ((int)*(unsigned char *)&a.s_addr)///#   define WAR_IN_ADDR_B2(a) ((int)*((unsigned char *)&a.s_addr + 1))///#   define WAR_IN_ADDR_B3(a) ((int)*((unsigned char *)&a.s_addr + 2))///#   define WAR_IN_ADDR_B4(a) ((int)*((unsigned char *)&a.s_addr + 3))#endif/****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarNetAddress {public:    // LIFECYCLE    typedef std::list<WarNetAddress> list_t;    /**    * Default constructor.    */    WarNetAddress(void);    /**    * Constructor    */    WarNetAddress(const std::string& from)        throw(WarException);        /**    * Copy constructor.    *    * @param from The value to copy to this object.    */    WarNetAddress(const WarNetAddress& from);        /**    * Destructor.    */    ~WarNetAddress(void);        // OPERATORS    /// Resolv hostname | dotted_ip [: port | protocol_name]    WarNetAddress& operator = (war_ccstr_t from)         throw(WarException);        ///    WarNetAddress& operator = (const std::string& from)         throw(WarException);    bool operator == (const WarNetAddress& from) const;    bool operator < (const WarNetAddress& from) const;        /**    * Assignment operator.    *    * @param from THe value to assign to this object.    *    * @return A reference to this object.    */    WarNetAddress& operator=(const WarNetAddress& from) throw(WarException);        // OPERATIONS      void Reset();    void SetPort(war_port_t newPort);    /** Resolves a hostname, using a reverse DMS lookup.      *      * @param doWaitForResult If true, the function      *     will not returend until the name is resolved.      *     If false, the reverse DNS lookup is scheduled,      *     and the function returns at once.      *      * @exception WarException on error, or if the name can      *     not be resolved and doWaitForResult is true.      */    void Resolv(bool doWaitForResult = false)        throw(WarException);    // ACCESS    /** Assigns the value from a sockaddr. If paddr is      * NULL, the internal value is cleared      */    void AssignSockaddr(const struct sockaddr *paddr,         size_t length)         throw(WarException);    /// Get the port-number    war_port_t GetPort() const throw(WarException);     ///    const struct sockaddr& GetSockAddr() const         throw(WarException);        ///    const struct sockaddr_in& GetSockAddrIn() const         throw(WarException);    ///    const in_addr& GetInAddr() const         throw(WarException);    /// Get the family type (from struct sockaddr)    int GetFamily() const throw(WarException);    ///    size_t GetSockAddrLength() const;    std::string GetServiceName() const;    // INQUIRY    std::string Explain() const;    bool IsEmpty() const;    const std::string GetDomainname() const    {        return mDomainname;    }    /// Get "a.b.c.d" type IP address    const std::string GetDottedStr() const;    protected:    void UpdateDomainname();private:    struct sockaddr mAddr;    std::string mDomainname; // Resolved domain name    bool mIsResolved;};/* INLINE METHODS */template <class classT>WarCollector<classT> operator << (WarCollector<classT>& o,                                   const WarNetAddress& v){    o << v.Explain();    return o;}/* EXTERNAL REFERENCES */typedef std::list<WarNetAddress> war_netaddr_list_t;/** Returns a list of WarNetAddress that match  * the server:service pair. Normally, only  * one entry will be returned - but if a name  * is defined with serveral IP addresse, or a   * service on several ports, the list wil be  * a matrix of servers:ports  *  * @exception WarException if no name isfound, or  * if an error occurs  */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_NET_ADDRESS_H_ */

⌨️ 快捷键说明

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