]> git.tdb.fi Git - libs/net.git/blob - source/sockaddr.h
6e4025d298cc46d0fc16719dcebf1cdad334514a
[libs/net.git] / source / sockaddr.h
1 #ifndef MSP_NET_SOCKADDR_H_
2 #define MSP_NET_SOCKADDR_H_
3
4 #include <string>
5 #ifndef WIN32
6 #include <sys/socket.h>
7 #endif
8 #include "constants.h"
9
10 namespace Msp {
11 namespace Net {
12
13 class SockAddr
14 {
15 protected:
16         SockAddr() { }
17 public:
18         virtual ~SockAddr() { }
19
20         static SockAddr *create(const sockaddr &sa) { return create(reinterpret_cast<const sockaddr_storage &>(sa)); }
21         static SockAddr *create(const sockaddr_storage &);
22
23         virtual SockAddr *copy() const = 0;
24
25         virtual Family get_family() const = 0;
26         virtual std::string str() const = 0;
27
28         /**
29         Fills the given struct sockaddr with information from this SockAddr.
30
31         @return  Number of bytes used
32         */
33         virtual unsigned fill_sockaddr(sockaddr &) const = 0;
34         virtual unsigned fill_sockaddr(sockaddr_storage &) const;
35 };
36
37 } // namespace Net
38 } // namespace Msp
39
40 #endif