#ifndef INCLUDED_BOBCAT_INETADDRESS_
#define INCLUDED_BOBCAT_INETADDRESS_

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

/*
    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;                                      // .f

            // replaces the formerly available getAddress() member.
        std::string dottedDecimalAddress() const;
        sockaddr const *sockaddrPtr() const;                        // 1.f
        sockaddr_in const *sockaddr_inPtr() const;                  // 1.f
        size_t size() const;                                        //  .f

    protected:
        InetAddress(std::string const &host, uint16_t port);
        explicit InetAddress(uint16_t port);                    // 1.f
        explicit InetAddress(sockaddr_in const &address);       // 2.f

        sockaddr *sockaddrPtr();                                // 2.f
        sockaddr_in *sockaddr_inPtr();                          // 2.f

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

inline InetAddress::InetAddress(uint16_t port)
{
    init(INADDR_ANY, port);
}
inline InetAddress::InetAddress(sockaddr_in const &address)       
:
    d_address(address)
{}
inline uint16_t InetAddress::port() const
{
    return ntohs(d_address.sin_port);
}
inline size_t InetAddress::size() const
{
    return sizeof(d_address);
}
inline sockaddr_in const *InetAddress::sockaddr_inPtr() const
{
    return &d_address;
}
inline sockaddr_in *InetAddress::sockaddr_inPtr()
{
    return &d_address;
}
inline sockaddr const *InetAddress::sockaddrPtr() const
{
    return reinterpret_cast<sockaddr const *>(&d_address);
}
inline sockaddr *InetAddress::sockaddrPtr() 
{
    return reinterpret_cast<sockaddr *>(&d_address);
}

} // FBB

#endif
