summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/CMakeLists.txt2
-rw-r--r--src/lib/irm.c97
-rw-r--r--src/lib/sockets.c94
3 files changed, 193 insertions, 0 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 9a6f1946..2e0d6b6b 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -9,6 +9,8 @@ set(SOURCE_FILES
bitmap.c
cdap.c
du_buff.c
+ irm.c
+ sockets.c
)
add_library(ouroboros SHARED ${SOURCE_FILES})
diff --git a/src/lib/irm.c b/src/lib/irm.c
new file mode 100644
index 00000000..da229d3e
--- /dev/null
+++ b/src/lib/irm.c
@@ -0,0 +1,97 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * The API to instruct the IRM
+ *
+ * Sander Vrijders <[email protected]>
+ *
+ * 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 "libouroboros-irm"
+
+#include <ouroboros/irm.h>
+#include <ouroboros/common.h>
+#include <ouroboros/logs.h>
+#include <ouroboros/sockets.h>
+
+int irm_create_ipcp(rina_name_t name,
+ char * ipcp_type)
+{
+ int sockfd;
+ struct irm_msg_sock msg;
+
+ if (!ipcp_type)
+ return -1;
+
+ sockfd = client_socket_open(IRM_SOCK_PATH);
+ if (sockfd < 0)
+ return -1;
+
+ msg.code = IRM_CREATE_IPCP;
+ msg.irm_msg.create_ipcp.name = name;
+ msg.irm_msg.create_ipcp.ipcp_type = ipcp_type;
+
+ write(sockfd, &msg, sizeof(msg));
+ close(sockfd);
+
+ return 0;
+}
+
+int irm_destroy_ipcp(int ipcp_id)
+{
+
+ return 0;
+}
+
+int irm_bootstrap_ipcp(int ipcp_id,
+ struct dif_info info)
+{
+
+ return 0;
+}
+
+int irm_enroll_ipcp(int ipcp_id,
+ char * dif_name)
+{
+
+ return 0;
+}
+
+int irm_reg_ipcp(int ipcp_id,
+ char ** difs)
+{
+
+ return 0;
+}
+
+int irm_unreg_ipcp(int ipcp_id,
+ char ** difs)
+{
+
+ return 0;
+}
+
+char ** irm_list_ipcps()
+{
+
+ return 0;
+}
+
+char ** irm_list_ipcp_types()
+{
+
+ return 0;
+}
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
new file mode 100644
index 00000000..8917f55a
--- /dev/null
+++ b/src/lib/sockets.c
@@ -0,0 +1,94 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * The sockets layer to communicate between daemons
+ *
+ * Sander Vrijders <[email protected]>
+ *
+ * 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 "libouroboros-sockets"
+
+#include <ouroboros/logs.h>
+#include <ouroboros/common.h>
+#include <ouroboros/sockets.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+#include <string.h>
+
+int client_socket_open(char * file_name)
+{
+ int sockfd;
+ struct sockaddr_un serv_addr;
+
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ LOG_ERR("Failed to open socket");
+ return -1;
+ }
+
+ serv_addr.sun_family = AF_UNIX;
+ sprintf(serv_addr.sun_path, file_name);
+
+ if (connect(sockfd,
+ (struct sockaddr *) &serv_addr,
+ sizeof(serv_addr))) {
+ LOG_ERR("Failed to connect to server");
+ return -1;
+ }
+
+ return sockfd;
+}
+
+int server_socket_open(char * file_name)
+{
+ int sockfd;
+ struct sockaddr_un serv_addr;
+ struct stat sb;
+
+ if (!stat(file_name, &sb)) {
+ /* File exists */
+ if (unlink(file_name)) {
+ LOG_ERR("Failed to unlink filename: %s",
+ strerror(errno));
+ return -1;
+ }
+ }
+
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0) {
+ LOG_ERR("Failed to open socket");
+ return -1;
+ }
+
+ serv_addr.sun_family = AF_UNIX;
+ sprintf(serv_addr.sun_path, file_name);
+
+ if (bind(sockfd,
+ (struct sockaddr *) &serv_addr,
+ sizeof(serv_addr))) {
+ LOG_ERR("Failed to bind socket");
+ return -1;
+ }
+
+ if (listen(sockfd, 0)) {
+ LOG_ERR("Failed to listen to socket");
+ return -1;
+ }
+
+ return sockfd;
+}