From 39231f62c0a3dfe5c8a0eaa8763a1fe9652e18b8 Mon Sep 17 00:00:00 2001 From: Munkyu Im Date: Wed, 24 Jun 2015 11:00:33 +0900 Subject: [PATCH] check-net: replace exit() to return with value Change-Id: I56be60617b51c846e0fe90893343584d1f22d26a Signed-off-by: Munkyu Im --- tizen/src/util/check_net.c | 9 +++++---- tizen/src/util/check_net.h | 4 ++-- tizen/src/util/check_net_darwin.c | 8 ++++++-- tizen/src/util/check_net_linux.c | 8 ++++++-- tizen/src/util/check_net_win32.c | 19 ++++++++++--------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tizen/src/util/check_net.c b/tizen/src/util/check_net.c index aae1a18c96..6c6b02abba 100644 --- a/tizen/src/util/check_net.c +++ b/tizen/src/util/check_net.c @@ -86,22 +86,23 @@ inline void remove_string(char *src, char *dst, const char *toremove) dst[j] = '\0'; } -void main(int argc, char *argv[]) +int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, " Usage: check-net --proxy\n"); fprintf(stderr, " check-net --interface-all\n"); fprintf(stderr, " check-net --bridge\n"); fprintf(stderr, " check-net --host-ip\n"); - return; + return 1; } if (strcmp(argv[1], ARG_PROXY) == 0) { get_host_proxy_os(); } else if (strcmp(argv[1], ARG_INTERFACE_ALL) == 0) { - get_host_interface_all_os(); + return get_host_interface_all_os(); } else if (strcmp(argv[1], ARG_BRIDGE) == 0) { - get_host_bridge_os(); + return get_host_bridge_os(); } else if (strcmp(argv[1], ARG_HOST_IP) == 0) { get_host_ip_os(); } + return 0; } diff --git a/tizen/src/util/check_net.h b/tizen/src/util/check_net.h index e519408a6e..06945f420b 100644 --- a/tizen/src/util/check_net.h +++ b/tizen/src/util/check_net.h @@ -71,8 +71,8 @@ extern const char *pac_tempfile; void get_host_proxy_os(void); -void get_host_interface_all_os(void); -void get_host_bridge_os(void); +int get_host_interface_all_os(void); +int get_host_bridge_os(void); void download_url(char *); size_t write_data(void *, size_t, size_t, FILE *); diff --git a/tizen/src/util/check_net_darwin.c b/tizen/src/util/check_net_darwin.c index 81193d6f12..cdc0b1a0a9 100644 --- a/tizen/src/util/check_net_darwin.c +++ b/tizen/src/util/check_net_darwin.c @@ -196,21 +196,25 @@ void get_host_proxy_os(void) } } -void get_host_interface_all_os(void) +int get_host_interface_all_os(void) { if (access(PATH_IFCONFIG, F_OK) != -1) { system("/sbin/ifconfig -a"); + return 0; } else { fprintf(stderr, "ifconfig does not exist!\n"); + return 1; } } -void get_host_bridge_os(void) +int get_host_bridge_os(void) { if (access(PATH_IFCONFIG, F_OK) != -1) { system("/sbin/ifconfig bridge1"); + return 0; } else { fprintf(stderr, "ifconfig does not exist!\n"); + return 1; } } diff --git a/tizen/src/util/check_net_linux.c b/tizen/src/util/check_net_linux.c index 5ad1a0e4aa..dc5545b3ea 100644 --- a/tizen/src/util/check_net_linux.c +++ b/tizen/src/util/check_net_linux.c @@ -240,21 +240,25 @@ void get_host_proxy_os(void) pclose(output); } -void get_host_interface_all_os(void) +int get_host_interface_all_os(void) { if (access(PATH_IFCONFIG, F_OK) != -1) { system("/sbin/ifconfig -a"); + return 0; } else { fprintf(stderr, "ifconfig does not exist!\n"); + return 1; } } -void get_host_bridge_os(void) +int get_host_bridge_os(void) { if (access(PATH_IFCONFIG, F_OK) != -1) { system("/sbin/ifconfig bridge1"); + return 0; } else { fprintf(stderr, "ifconfig does not exist!\n"); + return 1; } } diff --git a/tizen/src/util/check_net_win32.c b/tizen/src/util/check_net_win32.c index cc64c73c8d..0570ae3f85 100644 --- a/tizen/src/util/check_net_win32.c +++ b/tizen/src/util/check_net_win32.c @@ -262,7 +262,7 @@ static print_interface(PIP_ADAPTER_INFO pAdapter, PIP_ADAPTER_ADDRESSES pAddress fprintf(stdout, "\n"); } -static void get_host_interface(int value) +static int get_host_interface(int value) { PIP_ADAPTER_ADDRESSES pAddresses = NULL; PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL; @@ -283,7 +283,7 @@ static void get_host_interface(int value) pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen); if (pAddresses == NULL) { fprintf(stderr, "Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n"); - return; + return 1; } dwRetAddressVal = GetAdaptersAddresses(AF_INET, flags, NULL, pAddresses, &outBufLen); @@ -304,14 +304,14 @@ static void get_host_interface(int value) pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO)); if (pAdapterInfo == NULL) { fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n"); - return; + return 1; } if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { FREE(pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(ulOutBufLen); if (pAdapterInfo == NULL) { fprintf(stderr, "Error allocating memory needed to call GetAdaptersinfo\n"); - return; + return 1; } } dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); @@ -334,20 +334,21 @@ static void get_host_interface(int value) } } else { fprintf(stderr, "GetAdaptersInfo failed with error: %d\n", dwRetVal); - return; + return 1; } if (pAdapterInfo) FREE(pAdapterInfo); + return 0; } -void get_host_interface_all_os(void) +int get_host_interface_all_os(void) { - get_host_interface(ALL_INTERFACE); + return get_host_interface(ALL_INTERFACE); } -void get_host_bridge_os(void) +int get_host_bridge_os(void) { - get_host_interface(BRIDGE_ONLY); + return get_host_interface(BRIDGE_ONLY); } void get_host_ip_os(void) -- 2.34.1