/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#ifndef UDP4ADDR_H
#define UDP4ADDR_H

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

#include "Addr.h"

namespace Blinker {

/// UDP v4 address
class Udp4Addr: public Addr
{
public:
  /// constructor
  Udp4Addr();

  /// virtual destructor
  virtual ~Udp4Addr();

public:
  /// comparison
  //@{
  int compare(const Udp4Addr &that) const;
  bool operator==(const Udp4Addr &that) const;
  bool operator!=(const Udp4Addr &that) const;
  bool operator<(const Udp4Addr &that) const;
  bool operator>(const Udp4Addr &that) const;
  bool operator<=(const Udp4Addr &that) const;
  bool operator>=(const Udp4Addr &that) const;
  //@}

  /// return address family
  virtual int getFamily() const;

  /// return port (use this function only if absolutely necessary)
  virtual int getPort() const;

  /// set port (use this function only if absolutely necessary)
  virtual void setPort(int port);

  /**
   * @brief parse from string format
   * @param[in] str string format
   * @return if parsing was successful
   */
  virtual bool fromStr(const std::string &str);

  /**
   * @brief convert to string format
   * @return string format
   */
  virtual std::string toStr() const;
protected:
  struct sockaddr_in m_addr;

friend class Udp4Sock;
}; // class Udp4Addr

} // namespace Blinker

#endif // #ifndef UDP4ADDR_H

