]> git.tdb.fi Git - libs/net.git/blob - source/sockaddr.cpp
Add IPv6 support
[libs/net.git] / source / sockaddr.cpp
1 /* $Id$
2
3 This file is part of libmspnet
4 Copyright © 2008, 2011  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #include <msp/core/except.h>
9 #include "inet.h"
10 #include "inet6.h"
11
12 namespace Msp {
13 namespace Net {
14
15 unsigned SockAddr::fill_sockaddr(sockaddr_storage &sa) const
16 {
17         return fill_sockaddr(reinterpret_cast<sockaddr &>(sa));
18 }
19
20 SockAddr *SockAddr::create(const sockaddr_storage &sa)
21 {
22         switch(sa.ss_family)
23         {
24         case AF_INET:
25                 return new InetAddr(reinterpret_cast<const sockaddr_in &>(sa));
26         case AF_INET6:
27                 return new Inet6Addr(reinterpret_cast<const sockaddr_in6 &>(sa));
28         default:
29                 throw InvalidParameterValue("Unknown address family");
30         }
31 }
32
33 } // namespace Net
34 } // namespace Msp