bref
API 2014 of the Zia HTTP server.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
/Users/giersc_v/projets/zia/api/include/bref/IpAddress.h
Go to the documentation of this file.
00001 
00010 #ifndef BREF_API_IPADDRESS_H_
00011 #define BREF_API_IPADDRESS_H_
00012 
00013 #include <stdint.h>
00014 
00015 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
00016 # include <WinSock2.h>
00017 #endif
00018 
00019 namespace bref {
00020 
00021 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
00022 typedef SOCKET SocketType;
00023 #else
00024 typedef int SocketType;
00025 #endif
00026 
00030 union IPv4Address
00031 {
00032   unsigned char bytes[4];
00033   uint32_t      host;
00034 }; // union 'IPv4Address'
00035 
00039 union IPv6Address {
00040   struct {
00041     union {
00042       unsigned char networkBytes[8];
00043       uint64_t      network;
00044     };
00045     union {
00046       unsigned char hostBytes[8];
00047       uint64_t      host;
00048     };
00049   };
00050   unsigned char     bytes[16];
00051 }; // union 'IPv6Address'
00052 
00056 class IpAddress {
00057 public:
00058   IpAddress();
00062   IpAddress(const char * host);
00063   ~IpAddress();
00064 
00068   bool isV4() const;
00072   bool isV6() const;
00076   bool isV4Compatible() const;
00077 
00081   const IPv4Address & getV4() const;
00085   const IPv6Address & getV6() const;
00086 
00087 protected:
00088   enum { IPv4, IPv6, IPerror } ipAddressStatus_;
00089   union {
00090     IPv4Address v4_[4];
00091     IPv6Address v6_;
00092   } ipAddress_;
00093 }; // class 'IpAddress'
00094 
00095 } // namespace 'bref'
00096 
00097 #endif // BREF_API_IPADDRESS_H_