]> git.tdb.fi Git - libs/net.git/blob - source/inet.h
Style update: reorder class members
[libs/net.git] / source / inet.h
1 #ifndef MSP_NET_INET_H_
2 #define MSP_NET_INET_H_
3
4 #ifdef WIN32
5 #include <winsock2.h>
6 #else
7 #include <netinet/in.h>
8 #endif
9 #include "sockaddr.h"
10
11 namespace Msp {
12 namespace Net {
13
14 /**
15 Address class for IPv4 sockets.
16 */
17 class InetAddr: public SockAddr
18 {
19 private:
20 #ifdef WIN32
21         typedef u_long in_addr_t;
22         typedef u_short in_port_t;
23 #endif
24
25         in_addr_t addr;
26         in_port_t port;
27
28 public:
29         InetAddr();
30         InetAddr(const sockaddr_in &);
31         InetAddr(in_addr_t, in_port_t);
32
33         virtual InetAddr *copy() const { return new InetAddr(*this); }
34
35         Family get_family() const { return INET; }
36         in_addr_t get_addr() const { return ntohl(addr); }
37         in_port_t get_port() const { return ntohs(port); }
38         std::string str() const;
39         virtual unsigned fill_sockaddr(sockaddr &) const;
40 };
41
42 } // namespace Net
43 } // namespace Msp
44
45 #endif