-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInetAddress.h
More file actions
29 lines (22 loc) · 804 Bytes
/
Copy pathInetAddress.h
File metadata and controls
29 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef _NET_INETADDRESS_H_
#define _NET_INETADDRESS_H_
#include <netinet/in.h>
#include <string>
class InetAddress
{
public:
explicit InetAddress(uint16_t port);
InetAddress(const std::string& ip, uint16_t port);
InetAddress(const struct sockaddr_in& addr)
: m_addr(addr){}
std::string toIp() const;
std::string toIpPort() const;
std::string toHostPort() const {return toIpPort();}
const struct sockaddr_in& getSockAddrInet() const {return m_addr;}
void setSockAddrInet(const struct sockaddr_in& addr) {m_addr = addr;}
uint32_t ipNetEndian() const { return m_addr.sin_addr.s_addr; }
uint16_t portNetEndian() const { return m_addr.sin_port; }
private:
struct sockaddr_in m_addr;
};
#endif