1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

added gai_strerror to resolv_addr() checks

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@237 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-09-10 12:22:21 +00:00
parent 262a7de013
commit d22a3da9ea
5 changed files with 33 additions and 27 deletions

View file

@ -147,7 +147,7 @@ int config_parse_node(config_setting_t *cfg, struct node **nodes)
{
struct node *node;
const char *remote, *local;
int ret;
/* Allocate memory */
node = (struct node *) malloc(sizeof(struct node));
@ -167,12 +167,15 @@ int config_parse_node(config_setting_t *cfg, struct node **nodes)
if (!config_setting_lookup_string(cfg, "local", &local))
cerror(cfg, "Missing local address for node '%s'", node->name);
ret = resolve_addr(local, &node->local, AI_PASSIVE);
if (ret)
cerror(cfg, "Failed to resolve local address '%s' of node '%s': %s",
local, node->name, gai_strerror(ret));
if (resolve_addr(local, &node->local, AI_PASSIVE))
cerror(cfg, "Failed to resolve local address '%s' of node '%s'", local, node->name);
if (resolve_addr(remote, &node->remote, 0))
cerror(cfg, "Failed to resolve remote address '%s' of node '%s'", remote, node->name);
ret = resolve_addr(remote, &node->remote, 0);
if (ret)
cerror(cfg, "Failed to resolve remote address '%s' of node '%s': %s",
remote, node->name, gai_strerror(ret));
config_setting_t *cfg_netem = config_setting_get_member(cfg, "netem");
if (cfg_netem) {

View file

@ -11,10 +11,10 @@
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "config.h"
#include "utils.h"
@ -54,8 +54,9 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa_quit, NULL);
/* Resolve addresses */
if (resolve_addr(argv[1], &n.local, 0))
error("Failed to resolve local address: %s", argv[1]);
int ret = resolve_addr(argv[1], &n.local, 0);
if (ret)
error("Failed to resolve local address '%s': %s", argv[1], gai_strerror(ret));
node_connect(&n);

View file

@ -56,16 +56,18 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa_quit, NULL);
/* Resolve addresses */
if (resolve_addr(argv[1], &n.remote, 0))
error("Failed to resolve remote address: %s", argv[1]);
int ret = resolve_addr(argv[1], &n.remote, 0);
if (ret)
error("Failed to resolve remote address '%s': %s", argv[1], gai_strerror(ret));
if (argc == 3) {
if (resolve_addr(argv[2], &n.local, AI_PASSIVE))
error("Failed to resolve local address: %s", argv[2]);
ret = resolve_addr(argv[2], &n.local, AI_PASSIVE);
if (ret)
error("Failed to resolve local address '%s': %s", argv[2], gai_strerror(ret));
}
else {
n.local.sin_family = AF_INET;
n.local.sin_addr.s_addr = INADDR_ANY;
n.local.sin_addr.s_addr = INADDR_ANY; /* all local interfaces */
n.local.sin_port = 0; /* random port */
}

View file

@ -12,6 +12,7 @@
#include <string.h>
#include <limits.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "config.h"
#include "msg.h"
@ -59,11 +60,13 @@ int main(int argc, char *argv[])
sigaction(SIGINT, &sa_quit, NULL);
/* Resolve addresses */
if (resolve_addr(argv[2], &n.local, 0))
error("Failed to resolve local address: %s", argv[2]);
int ret = resolve_addr(argv[2], &n.local, AI_PASSIVE);
if (ret)
error("Failed to resolve local address '%s': %s", argv[1], gai_strerror(ret));
if (resolve_addr(argv[3], &n.remote, 0))
error("Failed to resolve remote address: %s", argv[3]);
ret = resolve_addr(argv[3], &n.remote, 0);
if (ret)
error("Failed to resolve remote address '%s': %s", argv[1], gai_strerror(ret));
node_connect(&n);

View file

@ -51,8 +51,6 @@ void print(enum log_level lvl, const char *fmt, ...)
int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags)
{
int ret;
/* Split string */
char *tmp = strdup(addr);
char *node = strtok(tmp, ":");
@ -73,16 +71,15 @@ int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags)
.ai_protocol = 0
};
ret = getaddrinfo(node, service, &hint, &result);
if (ret)
error("Failed to lookup address '%s': %s", addr, gai_strerror(ret));
memcpy(sa, result->ai_addr, result->ai_addrlen);
int ret = getaddrinfo(node, service, &hint, &result);
if (!ret) {
memcpy(sa, result->ai_addr, result->ai_addrlen);
freeaddrinfo(result);
}
free(tmp);
freeaddrinfo(result);
return 0;
return ret;
}
cpu_set_t to_cpu_set(int set)