From 63633c57b1e2573890fa627dd63f7c79ee5777b8 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 25 Feb 2016 19:14:26 +0100 Subject: lib, irmd, tools: Support to create IPCPs Provides the initial support to create IPCPs via a command-line tool. It extends the socket layer with a message that is sent over a socket to the irmd when the irm_create_ipcp library function is called from a program. --- src/irmd/main.c | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'src/irmd') diff --git a/src/irmd/main.c b/src/irmd/main.c index b4e43534..d2aa6cd9 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -28,22 +28,44 @@ #include #include #include +#include #define BUF_SIZE 256 + +static void create_ipcp(rina_name_t * name, + char * ipcp_type) +{ + LOG_DBG("AP name is %s", name->ap_name); + LOG_DBG("AP instance id is %d", name->api_id); + LOG_DBG("AE name is %s", name->ae_name); + LOG_DBG("AE instance id is %d", name->aei_id); + + LOG_DBG("IPCP type is %s", ipcp_type); + + LOG_MISSING; +} + int main() { int sockfd; + uint8_t * buf; sockfd = server_socket_open(IRM_SOCK_PATH); if (sockfd < 0) return -1; + buf = malloc(sizeof(buf) * BUF_SIZE); + if (!buf) { + LOG_ERR("Cannot allocate memory"); + return -1; + } + while (true) { - int cli_sockfd; - struct irm_msg_sock msg; + int cli_sockfd; + struct irm_msg * msg; ssize_t count; - char buf[BUF_SIZE]; + buffer_t buffer; cli_sockfd = accept(sockfd, 0, 0); if (cli_sockfd < 0) { @@ -52,12 +74,28 @@ int main() count = read(cli_sockfd, buf, BUF_SIZE); if (count) { - msg = (struct struct irm_msg_sock) buf; - LOG_INFO("Got message code %d", buf.code); + buffer.size = count; + buffer.data = buf; + msg = deserialize_irm_msg(&buffer); + if (!msg) + continue; + + LOG_DBG("Got message code %d", msg->code); + switch (msg->code) { + case IRM_CREATE_IPCP: + create_ipcp(msg->msgs.create_ipcp.name, + msg->msgs.create_ipcp.ipcp_type); + break; + default: + LOG_ERR("Don't know that message code"); + break; + } } close(cli_sockfd); } + free(buf); + return 0; } -- cgit v1.2.3