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