]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/sockaddr.cpp
Prepare for assimilating msphttp
[libs/net.git] / source / net / sockaddr.cpp
diff --git a/source/net/sockaddr.cpp b/source/net/sockaddr.cpp
new file mode 100644 (file)
index 0000000..9b41f81
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdexcept>
+#include "inet.h"
+#include "inet6.h"
+#include "sockaddr_private.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Net {
+
+SockAddr *SockAddr::new_from_sys(const SysAddr &sa)
+{
+       switch(sa.addr.ss_family)
+       {
+       case AF_INET:
+               return new InetAddr(sa);
+       case AF_INET6:
+               return new Inet6Addr(sa);
+       default:
+               throw invalid_argument("SockAddr::create");
+       }
+}
+
+SockAddr::SysAddr::SysAddr():
+       size(sizeof(sockaddr_storage))
+{
+       addr.ss_family = AF_UNSPEC;
+}
+
+} // namespace Net
+} // namespace Msp