]> git.tdb.fi Git - libs/net.git/blob - source/inet.h
Drop Id tags and copyright notices
[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         Family      get_family() const { return INET; }
34         in_addr_t   get_addr() const { return ntohl(addr); }
35         in_port_t   get_port() const { return ntohs(port); }
36         std::string str() const;
37         virtual unsigned fill_sockaddr(sockaddr &) const;
38         virtual InetAddr *copy() const { return new InetAddr(*this); }
39 };
40
41 } // namespace Net
42 } // namespace Msp
43
44 #endif