diff options
author | Dimitri Staessens <dimitri.staessens@intec.ugent.be> | 2016-02-26 14:50:00 +0100 |
---|---|---|
committer | Dimitri Staessens <dimitri.staessens@intec.ugent.be> | 2016-02-26 14:50:00 +0100 |
commit | 90740422f230ad064972c0f5b45b6c7f7190efb4 (patch) | |
tree | ae91f8cd49c8844e6ee53f7da957e88fd15c4cb7 /src/irmd/main.c | |
parent | 62eba345ce0ab3fb58e6998261da20bbc2f5cc3a (diff) | |
parent | 7b6fc640c7d31ff8979194813b0fa0e7b4f24bde (diff) | |
download | ouroboros-90740422f230ad064972c0f5b45b6c7f7190efb4.tar.gz ouroboros-90740422f230ad064972c0f5b45b6c7f7190efb4.zip |
Merge branch 'be' of bitbucket.org:ouroboros-rina/ouroboros into be-pci
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 97 |
1 files changed, 95 insertions, 2 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index 8ab071e0..137b2b61 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1,10 +1,103 @@ -#define OUROBOROS_PREFIX "irm" +/* + * Ouroboros - Copyright (C) 2016 + * + * The IPC Resource Manager + * + * Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "irmd" #include <ouroboros/logs.h> +#include <ouroboros/common.h> +#include <ouroboros/sockets.h> +#include <ouroboros/irm.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdlib.h> +#include <errno.h> + +#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() { - LOG_DBG("Test of the IRM"); + 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 == NULL) { + LOG_ERR("Cannot allocate memory"); + return -ENOMEM; + } + + while (true) { + int cli_sockfd; + struct irm_msg * msg; + ssize_t count; + buffer_t buffer; + + cli_sockfd = accept(sockfd, 0, 0); + if (cli_sockfd < 0) { + LOG_ERR("Cannot accept new connection"); + continue; + } + + count = read(cli_sockfd, buf, BUF_SIZE); + if (count) { + buffer.size = count; + buffer.data = buf; + msg = deserialize_irm_msg(&buffer); + if (msg == NULL) + 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; } |