#ifndef _INCLUDED_BOBCAT_INETADDRESS_
#define _INCLUDED_BOBCAT_INETADDRESS_

#include <netinet/in.h>
#include <string>
#include <bobcat/errno>

/*
    int-info coming in or going out: host byte order
*/    
namespace FBB
{
    class InetAddress
    {
        sockaddr_in     d_address;  // address/port: network byte order
                                // sa_family_t  in_addr,    uint16_t
                                // sin_family,  sin_addr,   sin_port
        public:
            uint16_t port() const
            {
                return ntohs(d_address.sin_port);
            }

                // replaces the formerly available getAddress() member.
            std::string dottedDecimalAddress() const throw (Errno);

            sockaddr const *sockaddrPtr() const
            {
                return reinterpret_cast<sockaddr const *>(&d_address);
            }

            size_t size() const
            {
                return sizeof(d_address);
            }

        protected:
                                                            // 1.cc
            InetAddress(std::string const &host, uint16_t port) throw (Errno);

            InetAddress(uint16_t port)
            {
                init(INADDR_ANY, port);
            }

            InetAddress(sockaddr_in const &address)       
            :
                d_address(address)
            {}

            sockaddr *sockaddrPtr() 
            {
                return reinterpret_cast<sockaddr *>(&d_address);
            }

        private:
            void init(uint32_t addr, uint16_t port);    // host byte order !
    };
}

#endif
