generated from AfonsoCMSousa/CPP-Template
43 lines
873 B
C++
43 lines
873 B
C++
#ifndef NET_HPP
|
|
#define NET_HPP
|
|
|
|
#include <arpa/inet.h>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
#include <unistd.h>
|
|
|
|
#include "server_structs.h"
|
|
|
|
using namespace std;
|
|
|
|
class Socket {
|
|
private:
|
|
// Socket file descriptor
|
|
int sock;
|
|
struct sockaddr_in server_addr;
|
|
struct sockaddr_un server_addr_unix;
|
|
|
|
// Socket Data
|
|
api_packet packet_data;
|
|
|
|
public:
|
|
Socket();
|
|
~Socket();
|
|
|
|
void connect_server(const char *ip, uint16_t port);
|
|
void connect_unix(const char *ip, uint16_t port);
|
|
void send_server();
|
|
void send_unix();
|
|
void send_server(const api_packet &data);
|
|
void send_server(const void *data, size_t len);
|
|
void send_unix(const api_packet &data);
|
|
void set_packet(const api_packet &data);
|
|
api_packet create_packet(uint8_t tracker_id);
|
|
api_packet get_packet();
|
|
};
|
|
|
|
#endif // NET_HPP
|