Add initial code for icmp ping 91/191791/1
authorYu <jiung.yu@samsung.com>
Tue, 23 Oct 2018 06:01:06 +0000 (15:01 +0900)
committerYu <jiung.yu@samsung.com>
Tue, 23 Oct 2018 06:11:49 +0000 (15:11 +0900)
Change-Id: I374d63ac1a1181b2a724f9418113a9c486163ac0
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
include/inm-icmp-ping.h [new file with mode: 0644]
src/inm-icmp-ping.c [new file with mode: 0644]

diff --git a/include/inm-icmp-ping.h b/include/inm-icmp-ping.h
new file mode 100644 (file)
index 0000000..e385edc
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Network Monitoring Module
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+
+ * This file declares functions for ARPing.
+ *
+ * @file        inm-icmp-ping.h
+ * @author      Jiung Yu (jiung.yu@samsung.com)
+ * @version     0.1
+ */
+#ifndef __INM_ICMP_PING_H__
+#define __INM_ICMP_PING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+       INM_ICMP_PING_ERROR_NONE = 0,
+       INM_ICMP_PING_ERROR_NOT_INITIALIZED,
+       INM_ICMP_PING_ERROR_INVALID_PARAM,
+       INM_ICMP_PING_ERROR_OPERATION_FAILED,
+       INM_ICMP_PING_ERROR_IN_PROGRESS,
+
+} inm_icmp_ping_error_e;
+
+typedef void (*icmp_ping_callback) (gboolean found, gchar *ip, gpointer user_data);
+
+int inm_icmp_ping_init();
+int inm_icmp_ping_deinit();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INM_ICMP_H__ */
+
diff --git a/src/inm-icmp-ping.c b/src/inm-icmp-ping.c
new file mode 100644 (file)
index 0000000..9fe388a
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Network Monitoring Module
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * This file implements ICMP functions.
+ *
+ * @file        inm-icmp.c
+ * @author      Jiung Yu (jiung.yu@samsung.com)
+ * @version     0.1
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <errno.h>
+
+#include <glib.h>
+
+#include "inm-manager-log.h"
+#include "inm-util.h"
+#include "inm-icmp-ping.h"
+
+typedef struct {
+       gboolean in_progress;
+
+       guint user_timeout;
+       guint interval;
+       gint count;
+       gint received;
+
+       guint icmp_user_timer_source_id;
+       guint icmp_interval_timer_source_id;
+
+       gchar *target_ip;
+
+       icmp_ping_callback cb;
+       gpointer cb_user_data;
+} icmp_ping_data_s;
+
+GData *icmp_ping_dl;
+gboolean icmp_ping_init;
+
+#define DEFAULT_INTERVAL 1
+#define DEFAULT_TIMEOUT 0
+#define DEFAULT_COUNT 10
+
+#define RET_ERR_IF_NOT_INIT()\
+       do {\
+               if (!icmp_ping_init) {\
+                       __INM_FUNC_EXIT__;\
+                       return INM_ICMP_ERROR_NOT_INITIALIZED;\
+               }\
+       } while (0)
+#define RET_ERR_IF_DATA_NOT_FOUND(ping_data)\
+       do {\
+               if (!(ping_data)) {\
+                       INM_LOGI("ping_data not found");\
+                       __INM_FUNC_EXIT__;\
+                       return INM_ICMP_ERROR_OPERATION_FAILED;\
+               }\
+       } while (0)
+
+int inm_icmp_ping_init()
+{
+       gint ret = INM_ICMP_PING_ERROR_NONE;
+
+       __INM_FUNC_ENTER__;
+
+       icmp_ping_init = TRUE;
+       g_datalist_init(&(icmp_ping_dl));
+
+       __INM_FUNC_EXIT__;
+       return ret;
+}
+
+int inm_icmp_ping_deinit()
+{
+       gint ret = INM_ICMP_PING_ERROR_NONE;
+
+       __INM_FUNC_ENTER__;
+
+       if (!icmp_ping_init)
+               return INM_ICMP_PING_ERROR_NOT_INITIALIZED;
+
+       icmp_ping_init = FALSE;
+       g_datalist_clear(&(icmp_ping_dl));
+
+       __INM_FUNC_EXIT__;
+       return ret;
+}