--- /dev/null
+/*
+ * 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 defines macros and declares functions get Internet reachability.
+ *
+ * @file inm-reacher.h
+ * @author Jiung Yu (jiung.yu@samsung.com)
+ * @version 0.1
+ */
+
+#ifndef __INM_REACHER_H__
+#define __INM_REACHER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ INM_REACHER_ERROR_NONE = 0,
+ INM_REACHER_ERROR_NOT_INITIALIZED,
+ INM_REACHER_ERROR_INVALID_PARAM,
+ INM_REACHER_ERROR_OPERATION_FAILED,
+ INM_REACHER_ERROR_IN_PROGRESS,
+ INM_REACHER_ERROR_URL_NOT_EXIST,
+ INM_REACHER_ERROR_URL_NOT_FOUND,
+ INM_REACHER_ERROR_DNS_NOT_RESOLVED,
+ INM_REACHER_ERROR_TIMEOUT,
+ INM_REACHER_ERROR_CURL,
+
+} inm_reacher_error_e;
+
+typedef enum {
+ INM_REACHER_CHECK_DEFAULT_URLS,
+ INM_REACHER_CHECK_USER_URLS,
+}inm_reacher_check_type_e;
+
+int inm_reacher_init(void);
+int inm_reacher_deinit(void);
+
+
+typedef void (*reacher_callback) (
+ inm_reacher_error_e err,
+ gboolean found,
+ const char *url,
+ gpointer user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INM_REACHER_H__ */
--- /dev/null
+#include <string.h>
+#include <unistd.h>
+
+#include <errno.h>
+
+#include <curl/curl.h>
+#include <curl/multi.h>
+
+#include <glib.h>
+
+#include <linux/if.h>
+
+#include "inm-manager-log.h"
+#include "inm-reacher.h"
+#include "inm-util.h"
+
+#define SHOW_VERBOSE 0
+
+#define RET_ERR_IF_NOT_INIT()\
+ do {\
+ if (!g_reacher) {\
+ __INM_FUNC_EXIT__;\
+ return INM_REACHER_ERROR_NOT_INITIALIZED;\
+ }\
+ } while (0)
+#define RET_ERR_IF_INVALID_PARAM(param)\
+ do {\
+ if (!(param)) {\
+ __INM_FUNC_EXIT__;\
+ return INM_REACHER_ERROR_INVALID_PARAM;\
+ }\
+ } while (0)
+
+/* Information associated with a specific easy handle */
+typedef struct {
+ CURLM *p_mh;
+ CURL *p_eh;
+ char *url;
+ gboolean found;
+ double resolved_time;
+ double total_time;
+ double download_byte;
+ double speed;
+ char error[CURL_ERROR_SIZE];
+} conn_info_s;
+
+/* Information associated with a specific socket */
+typedef struct {
+ curl_socket_t sockfd;
+ CURL *p_eh;
+ int action;
+ long timeout;
+ GIOChannel *ch;
+ guint source_id;
+} sock_data_s;
+
+/* Global information, common to all connections */
+typedef struct {
+ CURLM *p_mh;
+ GSList *user_added_url;
+
+ guint timer_source_id;
+ int active_connection;
+ gboolean running;
+ conn_info_s *current_conn;
+ sock_data_s *current_sock;
+
+ GSList *current;
+ int current_index;
+
+ inm_reacher_check_type_e type;
+ gboolean once;
+ reacher_callback cb;
+ gpointer cb_user_data;
+} reacher_data_s;
+
+reacher_data_s *g_reacher;
+
+static const char *default_urls[] = {
+ "http://www.microsoft.com",
+ "http://www.opensource.org",
+ "http://www.google.com",
+ "http://www.yahoo.com",
+ "http://www.ibm.com",
+ "http://www.mysql.com",
+ "http://www.oracle.com",
+ "http://www.ripe.net",
+ "http://www.iana.org",
+ "http://www.amazon.com",
+ "http://www.netcraft.com",
+ "http://www.heise.de",
+ "http://www.chip.de",
+ "http://www.ca.com",
+ "http://www.cnet.com",
+ "http://www.news.com",
+ "http://www.cnn.com",
+ "http://www.wikipedia.org",
+ "http://www.dell.com",
+ "http://www.hp.com",
+ "http://www.cert.org",
+ "http://www.mit.edu",
+ "http://www.nist.gov",
+ "http://www.ebay.com",
+ "http://www.playstation.com",
+ "http://www.uefa.com",
+ "http://www.ieee.org",
+ "http://www.apple.com",
+ "http://www.symantec.com",
+ "http://www.zdnet.com",
+ "http://www.fujitsu.com",
+ "http://www.supermicro.com",
+ "http://www.hotmail.com",
+ "http://www.ecma.com",
+ "http://www.bbc.co.uk",
+ "http://news.google.com",
+ "http://www.foxnews.com",
+ "http://www.msn.com",
+ "http://www.wired.com",
+ "http://www.sky.com",
+ "http://www.usatoday.com",
+ "http://www.cbs.com",
+ "http://www.nbc.com",
+ "http://slashdot.org",
+ "http://www.techweb.com",
+ "http://www.newslink.org",
+ "http://www.un.org",
+};
+
+#define URL_CNT sizeof(default_urls)/sizeof(char *)
+
+int inm_reacher_init(void)
+{
+ gint ret = INM_REACHER_ERROR_NONE;
+
+ __INM_FUNC_ENTER__;
+
+ if (g_reacher) {
+ __INM_FUNC_EXIT__;
+ return INM_REACHER_ERROR_NONE;
+ }
+
+ g_reacher = g_try_malloc0(sizeof(reacher_data_s));
+ if (!g_reacher) {
+ __INM_FUNC_EXIT__;
+ return INM_REACHER_ERROR_OPERATION_FAILED;
+ }
+
+ __INM_FUNC_EXIT__;
+ return ret;
+}
+
+int inm_reacher_deinit(void)
+{
+ gint ret = INM_REACHER_ERROR_NONE;
+
+ __INM_FUNC_ENTER__;
+
+ RET_ERR_IF_NOT_INIT();
+
+ g_slist_free_full(g_reacher->user_added_url, g_free);
+ g_reacher->user_added_url = NULL;
+
+ g_reacher->active_connection = 0;
+ g_reacher->cb = NULL;
+ g_reacher->cb_user_data = NULL;
+ g_reacher->current = NULL;
+ g_reacher->current_index = 0;
+ g_reacher->running = FALSE;
+
+ __INM_FUNC_EXIT__;
+ return ret;
+}