49 lines
862 B
C++
49 lines
862 B
C++
|
#include <cstring>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <netdb.h>
|
||
|
|
||
|
namespace net
|
||
|
{
|
||
|
|
||
|
class TCPServer
|
||
|
{
|
||
|
private:
|
||
|
int status;
|
||
|
struct addrinfo hints;
|
||
|
struct addrinfo *servinfo; // Points to results
|
||
|
|
||
|
public:
|
||
|
TCPServer(TCPServer&) = delete;
|
||
|
~TCPServer()
|
||
|
{
|
||
|
this->stop();
|
||
|
}
|
||
|
|
||
|
void init()
|
||
|
{
|
||
|
memset(&hints, 0, sizeof hints);
|
||
|
hints.ai_family = AF_INET;
|
||
|
hints.ai_socktype = SOCK_STREAM;
|
||
|
hints.ai_flags = AI_PASSIVE;
|
||
|
if(!is_valid_struct(&hints, &servinfo))
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool is_valid_struct(addrinfo hints, addrinfo servinfo)
|
||
|
{
|
||
|
uint8_t result = getaddrinfo(NULL, "1337", &hints, &servinfo);
|
||
|
return
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void stop()
|
||
|
{
|
||
|
// Maybe more. Threading stuff?
|
||
|
freeaddrinfo(servinfo);
|
||
|
}
|
||
|
};
|
||
|
} // End net namespace
|