forked from truvorskameikin/udp-discovery-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip_port.hpp
51 lines (39 loc) · 863 Bytes
/
ip_port.hpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __DISCOVERY_IP_PORT_H_
#define __DISCOVERY_IP_PORT_H_
#include <string>
namespace udpdiscovery {
class IpPort {
public:
IpPort() : ip_(0), port_(0) {
}
IpPort(unsigned int ip, int port) : ip_(ip), port_(port) {
}
void set_ip(unsigned int ip) {
ip_ = ip;
}
unsigned int ip() const {
return ip_;
}
void set_port(int port) {
port_ = port;
}
int port() const {
return port_;
}
bool operator==(const IpPort& rhv) const {
return ip_ == rhv.ip_ && port_ == rhv.port_;
}
bool operator<(const IpPort& rhv) const {
if (ip_ < rhv.ip_)
return true;
else if (ip_ > rhv.ip_)
return false;
return port_ < rhv.port_;
}
private:
unsigned int ip_;
int port_;
};
std::string IpToString(unsigned int ip);
};
#endif