You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libUDPTCPNetwork/network.cc

49 lines
996 B

#include "UDPTCPNetwork.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
using namespace std;
char dnsip[NET_HOSTLEN];
//
// convert host and port to sockaddr_in6
//
int dns_filladdr (string host, string port, int ai_family,
struct sockaddr_storage *sAddr) {
struct addrinfo hints, *res;
int err;
bzero (&hints, sizeof (struct addrinfo));
hints.ai_family = ai_family;
hints.ai_socktype = SOCK_DGRAM;
if ((err = getaddrinfo (host.c_str(), port.c_str(), &hints, &res)) < 0) {
fprintf (stdout, "dns_filladdr (getaddrinfo):%s\n", gai_strerror (err));
return -1;
}
memcpy (sAddr, res->ai_addr, res->ai_addrlen);
freeaddrinfo (res);
return 1;
};
//
// convert int to char*
//
char* itoa(char* buffer, int number, int size) {
snprintf (buffer, size, "%d", number);
return buffer;
}