forked from augcampos/asterisk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPAddress.h
More file actions
94 lines (76 loc) · 2.08 KB
/
IPAddress.h
File metadata and controls
94 lines (76 loc) · 2.08 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* IPAddress.h
*
* Created on: 29 de Jun de 2011
* Author: augcampos
*/
#ifndef IPADDRESS_H_
#define IPADDRESS_H_
#include <string>
#include <sstream>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <iostream>
#include <boost/thread.hpp>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <netdb.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#endif
namespace asteriskcpp {
class IPAddress {
private:
int ip;
std::string host;
unsigned short port;
static boost::mutex mut;
public:
IPAddress();
IPAddress(unsigned short port);
IPAddress(int ip, unsigned short port);
IPAddress(const std::string& host, unsigned short port);
IPAddress(const IPAddress& ipAddress);
~IPAddress();
void setHost(const std::string& host);
void setIP(int ip);
void setPort(unsigned short port);
std::string getHost() const;
int getIP() const;
unsigned short getPort() const;
operator const bool() {
return (ip != 0);
}
//not a full comparison (args ignored)
friend inline bool operator !=(const IPAddress& a, const IPAddress& b) {
return (a.ip != b.ip || a.port != b.port);
}
friend inline bool operator ==(const IPAddress& a, const IPAddress& b) {
return (a.ip == b.ip && a.port == b.port);
}
friend std::ostream& operator<<(std::ostream& os, IPAddress& o) {
os << o.host << ":" << o.port;
return (os);
}
friend std::ostream& operator<<(std::ostream& os, const IPAddress& o) {
os << o.host << ":" << o.port;
return (os);
}
private:
void resolveAddr();
void toStringAddr();
void getLocalIP();
};
#ifdef _WIN32
class InitWSA {
public:
InitWSA();
~InitWSA();
};
#endif
}
#endif /* IPADDRESS_H_ */