peerplays-fc/include/fc/ip.hpp

52 lines
1.4 KiB
C++
Raw Normal View History

2012-09-08 21:37:25 +00:00
#ifndef _FC_IP_HPP_
#define _FC_IP_HPP_
#include <fc/string.hpp>
namespace fc {
namespace ip {
class address {
public:
address( uint32_t _ip = 0 );
address( const fc::string& s );
address& operator=( const fc::string& s );
operator fc::string()const;
2012-09-09 03:46:19 +00:00
operator uint32_t()const;
2012-09-08 21:37:25 +00:00
2012-09-09 03:46:19 +00:00
friend bool operator==( const address& a, const address& b );
2012-09-08 21:37:25 +00:00
private:
uint32_t _ip;
};
class endpoint {
public:
endpoint();
endpoint( const address& i, uint16_t p = 0);
/** Converts "IP:PORT" to an endpoint */
static endpoint from_string( const string& s );
/** returns "IP:PORT" */
operator string()const;
void set_port(uint16_t p ) { _port = p; }
2012-09-08 21:37:25 +00:00
uint16_t port()const;
const address& get_address()const;
2012-09-09 03:46:19 +00:00
friend bool operator==( const endpoint& a, const endpoint& b );
2012-09-08 21:37:25 +00:00
private:
address _ip;
2012-09-25 21:45:28 +00:00
/**
* The compiler pads endpoint to a full 8 bytes, so while
* a port number is limited in range to 16 bits, we specify
* a full 32 bits so that memcmp can be used with sizeof(),
* otherwise 2 bytes will be 'random' and you do not know
* where they are stored.
*/
uint32_t _port;
2012-09-08 21:37:25 +00:00
};
}
}
#endif // _FC_ENDPOINT_HPP_