info: add a function to initialise the config
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Dec 2015 14:48:43 +0000 (15:48 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 3 Dec 2015 11:00:08 +0000 (12:00 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info/info_types.h

index 6a30ee7..b5a83ac 100644 (file)
@@ -43,6 +43,8 @@
 #define _OLSRD_LIB_INFO_INFO_TYPES_H_
 
 #include <stdbool.h>
+#include <assert.h>
+#include <netinet/in.h>
 
 #include "common/autobuf.h"
 
@@ -118,4 +120,22 @@ typedef struct {
   { .name = "allowlocalhost", .set_plugin_parameter = &set_plugin_boolean, .data = &config.allow_localhost }, \
   { .name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data = &config.ipv6_only }
 
+static INLINE void info_plugin_config_init(info_plugin_config_t *config, unsigned short port) {
+  assert(config);
+
+  if (olsr_cnf->ip_version == AF_INET) {
+    config->accept_ip.v4.s_addr = htonl(INADDR_LOOPBACK);
+    config->listen_ip.v4.s_addr = htonl(INADDR_ANY);
+  } else {
+    config->accept_ip.v6 = in6addr_loopback;
+    config->listen_ip.v6 = in6addr_any;
+  }
+
+  config->ipc_port = port;
+  config->nompr = 0;
+  config->http_headers = true;
+  config->allow_localhost = false;
+  config->ipv6_only = false;
+}
+
 #endif /* _OLSRD_LIB_INFO_INFO_TYPES_H_ */