generated from AfonsoCMSousa/CPP-Template
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
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 "log.h"
|
|
#include "server_structs.h"
|
|
|
|
using namespace std;
|
|
|
|
class Socket {
|
|
private:
|
|
// Socket file descriptor
|
|
int sock_server;
|
|
int sock_unix;
|
|
struct sockaddr_in server_addr;
|
|
struct sockaddr_un server_addr_unix;
|
|
|
|
// Server port for input (listening)
|
|
int server_port_input;
|
|
char buffer[1024];
|
|
|
|
// Socket Data
|
|
api_packet packet_data;
|
|
|
|
public:
|
|
Socket();
|
|
~Socket();
|
|
|
|
void connect_server(const char *ip, uint16_t port);
|
|
void bind_server(const char *ip, uint16_t port);
|
|
void send_server();
|
|
void send_server(const api_packet &data);
|
|
void send_server(const void *data, size_t len);
|
|
ssize_t receive_server(void *buffer, size_t len);
|
|
|
|
void connect_unix(const char *ip, uint16_t port);
|
|
void send_unix();
|
|
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
|