#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <assert.h>
#include "common.h"
#include "render_remote.h"
#include "remote_node.h"
int remote_node_init (struct remote_node *node_info, const char *hostname, const char *portname) {
// zero out the struct
memset(node_info, 0, sizeof(*node_info));
// XXX: currently, this is hardcoded to one, but should be automagically discovered
node_info->parallel_renders = 1;
// lookup the host:port
portname = portname ? portname : RENDER_PORT_NAME;
// XXX: stat it and look for a PF_UNIX socket!
// PF_INET
struct addrinfo hints, *results, *result;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG; // attempt to get a working address as the first result
int err = getaddrinfo(hostname, portname, &hints, &results);
if (err != 0) {
error("getaddrinfo: [%s].%s: %s", hostname, portname, gai_strerror(err));
return -1;
}
assert(results != NULL); // we expect at least one result
// XXX: only use the first result, discard the rest.
result = results;
memcpy(&node_info->addr, result->ai_addr, result->ai_addrlen);
freeaddrinfo(results);
// success!
node_info->valid = 1;
return 0;
}