]> git.tdb.fi Git - libs/net.git/blobdiff - source/sockaddr.cpp
Don't close socket on Communicator error
[libs/net.git] / source / sockaddr.cpp
index c3ae2db3091d06730b183a6ad51f886808b1fad9..f6123ca38c685e9b3631593bdd9e89b4de248587 100644 (file)
@@ -1,26 +1,29 @@
-/* $Id$
-
-This file is part of libmspnet
-Copyright © 2008  Mikkosoft Productions, Mikko Rasa
-Distributed under the LGPL
-*/
-
-#include <msp/core/except.h>
+#include <stdexcept>
 #include "inet.h"
+#include "inet6.h"
+
+using namespace std;
 
 namespace Msp {
 namespace Net {
 
-SockAddr *SockAddr::create(sockaddr &sa)
+SockAddr *SockAddr::create(const sockaddr_storage &sa)
 {
-       switch(sa.sa_family)
+       switch(sa.ss_family)
        {
        case AF_INET:
-               return new InetAddr(reinterpret_cast<sockaddr_in &>(sa));
+               return new InetAddr(reinterpret_cast<const sockaddr_in &>(sa));
+       case AF_INET6:
+               return new Inet6Addr(reinterpret_cast<const sockaddr_in6 &>(sa));
        default:
-               throw InvalidParameterValue("Unknown address family");
+               throw invalid_argument("SockAddr::create");
        }
 }
 
+unsigned SockAddr::fill_sockaddr(sockaddr_storage &sa) const
+{
+       return fill_sockaddr(reinterpret_cast<sockaddr &>(sa));
+}
+
 } // namespace Net
 } // namespace Msp