30 lines
761 B
C++
30 lines
761 B
C++
|
#pragma once
|
||
|
#include <cstdint>
|
||
|
#include <string>
|
||
|
#include <netinet/in.h>
|
||
|
#include <sys/socket.h>
|
||
|
namespace tinyrpc {
|
||
|
|
||
|
class NetAddress {
|
||
|
|
||
|
public:
|
||
|
NetAddress() = delete;
|
||
|
NetAddress(const std::string ip, uint16_t port);
|
||
|
NetAddress(uint16_t port);
|
||
|
NetAddress(const sockaddr_in* addr);
|
||
|
std::string toString() const;
|
||
|
const sockaddr* getSockaddr() const {
|
||
|
return reinterpret_cast<const sockaddr*>(&m_addr_in);
|
||
|
}
|
||
|
socklen_t getSockLen() const {return sizeof m_addr_in;}
|
||
|
~NetAddress();
|
||
|
|
||
|
|
||
|
static bool checkIpString(const std::string& ip);
|
||
|
private:
|
||
|
std::string m_ip{"None"};
|
||
|
uint16_t m_port{};
|
||
|
sockaddr_in m_addr_in{};
|
||
|
};
|
||
|
|
||
|
}
|