23 #include "ClientInterface.h"
25 int ClientInterface::getLengthCl(
string header,
int size)
27 int totsize = header[size-1] & 0xff;
28 for (
int var = 0; var < size-1; var++)
30 totsize |= ((header[var] & 0xff) << (size-1-var)*8);
35 void* ClientInterface::get_in_addr(
struct sockaddr *sa)
37 if (sa->sa_family == AF_INET) {
38 return &(((
struct sockaddr_in*)sa)->sin_addr);
40 return &(((
struct sockaddr_in6*)sa)->sin6_addr);
43 int ClientInterface::create_tcp_socket()
46 if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
47 perror(
"Can't create TCP socket");
52 char* ClientInterface::get_ip(
char *host)
56 char *ip = (
char *)malloc(iplen+1);
57 memset(ip, 0, iplen+1);
58 if((hent = gethostbyname(host)) == NULL)
60 perror(
"Can't get IP");
63 if(inet_ntop(AF_INET, (
void *)hent->h_addr_list[0], ip, iplen) == NULL)
65 perror(
"Can't resolve host");
71 bool ClientInterface::isConnected(
int fd) {
73 if (recv(fd, &c, 1, MSG_DONTWAIT | MSG_PEEK) == 0) {