#ifndef __pxx_sock_addr_hh__
#define __pxx_sock_addr_hh__

#include "pxx_common.hh"
#include "pxx_exception.hh"

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

namespace pxx
{

typedef enum {
  af_unix = AF_LOCAL,
  af_inet = AF_INET,
  af_inet6 = AF_INET6
} address_family_t ;

struct SockAddr
{

  address_family_t family ;
  struct sockaddr* addr ;
  socklen_t addrlen ;

  inline SockAddr (char const* _host, uint16_t _port) ;
  inline SockAddr (address_family_t _af, uint16_t _port = 0) ;
  inline SockAddr (char const* _file) ;
  inline ~SockAddr () ;

  class AF_NotSupported :
    public Exception
  {
  public:
    void print()
      { fprintf(stderr, "Address family not supported\n"); }
  };

  class HostNotFound :
    public Exception
  {
  public:
    void print()
      { fprintf(stderr, "The specified host is unknown\n"); }
  };

  class NoAddress :
    public Exception
  {
  public:
    void print()
      { fprintf(stderr, "The specified name has no IP address attached\n"); }
  };

  class ServerError :
    public Exception
  {
  public:
    void print()
      { fprintf(stderr, "Non-recoverable name server error occurred\n"); }
  };

  class TryAgain :
    public Exception
  {
  public:
    void print()
      { fprintf(stderr, "Temporary name server error occured\n"); }
  };

};

}

#endif // __pxx_sock_addr_hh__
