add: relay/piface support

This commit is contained in:
Tobias Reisinger 2020-04-14 00:50:55 +02:00
parent fa6ceb2bf4
commit db64e4f820
34 changed files with 1259 additions and 313 deletions

View file

@ -5,33 +5,35 @@
#include <sys/socket.h>
#include <logger.h>
#include <helper.h>
#include <helpers.h>
int
helper_connect_server(char* host, char* port)
helper_connect_tcp_server(char* host, uint16_t port)
{
int s, status;
struct addrinfo hints, *res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET; //set IP Protocol flag (IPv4 or IPv6 - we don't care)
hints.ai_socktype = SOCK_STREAM; //set socket flag
char port_str[6];
sprintf(port_str, "%d", port);
if ((status = getaddrinfo(host, port, &hints, &res)) != 0) { //getaddrinfo() will evaluate the given address, using the hints-flags and port, and return an IP address and other server infos
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
exit(EXIT_FAILURE);
}
int s, status;
struct addrinfo hints, *res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET; //set IP Protocol flag (IPv4 or IPv6 - we don't care)
hints.ai_socktype = SOCK_STREAM; //set socket flag
//res got filled out by getaddrinfo() for us
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); //creating Socket
if ((status = getaddrinfo(host, port_str, &hints, &res)) != 0) { //getaddrinfo() will evaluate the given address, using the hints-flags and port, and return an IP address and other server infos
LOG_ERROR("getaddrinfo: %s\n", gai_strerror(status));
return -1;
}
if ((status = connect(s, res->ai_addr, res->ai_addrlen)) != 0) {
fprintf(stderr, "Keine Verbindung mit dem Netzwerk möglich.\n");
freeaddrinfo(res);
exit(EXIT_FAILURE);
}
//res got filled out by getaddrinfo() for us
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); //creating Socket
freeaddrinfo(res);
if ((status = connect(s, res->ai_addr, res->ai_addrlen)) != 0) {
LOG_ERROR("connect() failed");
freeaddrinfo(res);
return -1;
}
return s;
freeaddrinfo(res);
return s;
}