forked from keithw/datagrump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.hh
43 lines (33 loc) · 1.01 KB
/
address.hh
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
#ifndef ADDRESS_HH
#define ADDRESS_HH
#include <sys/socket.h>
#include <netinet/in.h>
#include <string>
#include <string.h>
namespace Network {
/* Datagram address class. Wraps sockaddr_in */
class Address {
private:
struct sockaddr_in sockaddr_;
public:
/* Construct from IP address and port number */
Address( const std::string ip, const std::string port );
/* Construct from sockaddr_in */
Address( const struct sockaddr_in s_sockaddr ) : sockaddr_( s_sockaddr ) {}
/* Get underlying sockaddr_in */
const struct sockaddr_in & sockaddr( void ) const { return sockaddr_; }
/* Render address to string */
const std::string str( void ) const;
/* Get underlying IP address */
std::string ip( void ) const;
/* Get underlying port number */
uint16_t port( void ) const;
/* Compare two addresses */
bool operator==( const Address & other ) const
{
return (0 ==
memcmp( &sockaddr_, &other.sockaddr_, sizeof( sockaddr_ )));
}
};
}
#endif