summaryrefslogtreecommitdiff
path: root/i/simulotron/src/socket/address.hh
diff options
context:
space:
mode:
Diffstat (limited to 'i/simulotron/src/socket/address.hh')
-rw-r--r--i/simulotron/src/socket/address.hh76
1 files changed, 76 insertions, 0 deletions
diff --git a/i/simulotron/src/socket/address.hh b/i/simulotron/src/socket/address.hh
new file mode 100644
index 0000000..53fca07
--- /dev/null
+++ b/i/simulotron/src/socket/address.hh
@@ -0,0 +1,76 @@
+#ifndef address_hh
+#define address_hh
+// address.hh
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Dufour Jérémy
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// Contact :
+// Web: %WEB%
+// Email: <dufourj@efrei.fr>
+// }}}
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <string>
+#include <ostream>
+
+/// S'occupe de gérer les adresses.
+class Address {
+ /// La structure sockaddr_in de type réseau/AF_INET.
+ sockaddr_in sa_;
+ /// Le nom d'hôte de l'adresse.
+ std::string host_;
+ /// Le numéro de port de l'adresse.
+ int port_;
+
+ public:
+ /// Constructeur par défaut.
+ Address (void);
+ /// Constructeur pour le serveur. (port seulement)
+ Address (const int port);
+ /// Constructeur avec hôte et port.
+ Address (const std::string &host, const int port);
+ /// Constructeur à partir de la structure d'adresse.
+ Address (const sockaddr *sa, socklen_t sl);
+ /// Geter sockaddr.
+ const sockaddr *getSockaddr (void) const { return
+ reinterpret_cast<const sockaddr *> (&sa_); }
+ /// Geter hôte.
+ const std::string &getHost (void) const { return host_; }
+ /// Geter port.
+ const int getPort (void) const { return port_; }
+
+ private:
+ /// Résolution adresse vers hôte/port
+ void resolv (void);
+ /// Résolution hôte/port vers adresse
+ void unresolv (void);
+
+};
+
+/// Surcharge de l'opérateur << pour l'affichage.
+inline std::ostream &
+operator<< (std::ostream &s, const Address &a)
+{
+ return s << a.getHost () << ':' << a.getPort ();
+}
+
+#endif // address_hh