summaryrefslogtreecommitdiff
path: root/comm/Address.h
diff options
context:
space:
mode:
authorchatty1993-04-07 11:50:31 +0000
committerchatty1993-04-07 11:50:31 +0000
commitba066c34dde204aa192d03a23a81356374d93731 (patch)
tree39391f6235d2cf8a59a0634ac5ea430cdd21f5d4 /comm/Address.h
parent05ab076e1c2a9ca16472f9a6b47b8d22914b3783 (diff)
downloadivy-league-ba066c34dde204aa192d03a23a81356374d93731.zip
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.gz
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.bz2
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.xz
Initial revision
Diffstat (limited to 'comm/Address.h')
-rw-r--r--comm/Address.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/comm/Address.h b/comm/Address.h
new file mode 100644
index 0000000..b220339
--- /dev/null
+++ b/comm/Address.h
@@ -0,0 +1,118 @@
+/*
+ * The Unix Channel
+ *
+ * by Michel Beaudouin-Lafon
+ *
+ * Copyright 1990-1993
+ * Laboratoire de Recherche en Informatique (LRI)
+ *
+ * Addresses
+ *
+ * $Id$
+ * $CurLog$
+ */
+
+#ifndef Address_H_
+#define Address_H_
+
+#include "cplus_bugs.h"
+#include "global.h"
+#include "ccu/SmartPointer.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#ifdef UNIX_SOCK
+#include <sys/un.h>
+#endif
+
+#ifndef AF_UNIX
+#define AF_UNIX AF_UNSPEC
+#endif
+
+
+typedef struct sockaddr SockAddr;
+
+/* this union is useful for adresses returned by system calls */
+
+typedef union {
+ struct sockaddr sa; // default
+#ifdef UNIX_SOCK
+ struct sockaddr_un su; // unix
+#endif
+ struct sockaddr_in si; // inet
+} GEN_ADDR;
+
+
+class UchAddress : public CcuSmartData {
+protected:
+ bool Valid;
+
+public:
+ UchAddress ();
+ ~UchAddress ();
+
+ bool IsValid () const { return Valid; }
+virtual int Family (); // AF_UNSPEC, AF_UNIX, AF_INET
+virtual int Length ();
+virtual SockAddr* GetSockAddr ();
+virtual char* StrRepr (char* buf);
+
+static UchAddress* Decode (GEN_ADDR*, int);
+};
+
+PointerClass (pUchAddress, UchAddress)
+
+class UchInetAddress : public UchAddress {
+protected:
+ struct sockaddr_in Addr;
+
+public:
+ UchInetAddress ();
+ UchInetAddress (lword, sword = 0); // hostid, port#
+ UchInetAddress (const char*, sword = 0); // hostname, port#
+ ~UchInetAddress ();
+
+ int Family ();
+ int Length ();
+ SockAddr* GetSockAddr ();
+inline sword Port () { return Addr.sin_port; }
+inline lword Host () { return Addr.sin_addr.s_addr; }
+ char* StrRepr (char* buf);
+
+static lword LoopBack ();
+};
+
+#ifndef INADDR_LOOPBACK
+#define INADDR_LOOPBACK (INET_ADDR::LoopBack ())
+#endif
+
+#define ANYADDR ((lword) INADDR_ANY)
+#define LOOPBACK ((lword) INADDR_LOOPBACK)
+#define BROADCAST ((lword) INADDR_BROADCAST)
+
+
+
+#ifdef UNIX_SOCK
+
+class UchUnixAddress : public UchAddress {
+protected:
+ struct sockaddr_un Addr;
+
+public:
+ UchUnixAddress ();
+ UchUnixAddress (const char*);
+ ~UchUnixAddress ();
+
+ int Family ();
+ int Length ();
+ SockAddr* GetSockAddr ();
+ char* StrRepr (char* buf);
+};
+
+#endif /* UNIX_ADDR */
+
+
+#endif /* Address_H_ */
+