]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/constants.cpp
Prepare for assimilating msphttp
[libs/net.git] / source / net / constants.cpp
diff --git a/source/net/constants.cpp b/source/net/constants.cpp
new file mode 100644 (file)
index 0000000..e57897d
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdexcept>
+#ifdef WIN32
+#include <winsock2.h>
+#else
+#include <sys/socket.h>
+#endif
+#include "constants.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Net {
+
+int family_to_sys(Family f)
+{
+       switch(f)
+       {
+       case UNSPEC: return AF_UNSPEC;
+       case INET:   return AF_INET;
+       case INET6:  return AF_INET6;
+       case UNIX:   return AF_UNIX;
+       default: throw invalid_argument("family_to_sys");
+       }
+}
+
+Family family_from_sys(int f)
+{
+       switch(f)
+       {
+       case AF_UNSPEC: return UNSPEC;
+       case AF_INET:   return INET;
+       case AF_INET6:  return INET6;
+       case AF_UNIX:   return UNIX;
+       default: throw invalid_argument("family_from_sys");
+       }
+}
+
+} // namespace Net
+} // namespace Msp