tethering: remove redundant source when copying ip address. 05/25505/2
authorKitae Kim <kt920.kim@samsung.com>
Wed, 6 Aug 2014 08:17:09 +0000 (17:17 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Wed, 6 Aug 2014 09:58:29 +0000 (18:58 +0900)
Change-Id: I528aa0886cccf746ca928390da930bf07ec5bccc
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/ecs/ecs_tethering.c
tizen/src/tethering/common.c

index f6828d37849a4312db142f1dea10dce48b372a39..2e4682d9d9c4e215b21259f9513b5be05ab83aa4 100644 (file)
@@ -245,7 +245,6 @@ bool msgproc_tethering_req(ECS_Client* ccli, ECS__TetheringReq* msg)
             // get ip address and port
             if (msg->data.data && msg->data.len > 0) {
                 const gchar *data = (const gchar *)msg->data.data;
-                // gchar **server_addr = NULL;
                 gchar *ip_address = NULL;
                 guint64 port = 0;
 
index 6e11e765d5aa6ad59f528b288498b2d4c1629ab6..709e5e726b1dc31d303b407c86d1e0319e35a32b 100644 (file)
@@ -60,6 +60,7 @@ DECLARE_DEBUG_CHANNEL(app_tethering);
 #endif
 
 #define SEND_BUF_MAX_SIZE 4096
+static const char *loopback="127.0.0.1";
 
 typedef struct tethering_recv_buf {
     uint32_t len;
@@ -549,22 +550,14 @@ static void tethering_io_handler(void *opaque)
 static int start_tethering_socket(const char *ipaddress, int port)
 {
     struct sockaddr_in addr;
-
-    gchar serveraddr[32] = { 0, };
     int sock = -1;
     int ret = 0;
 
     addr.sin_family = AF_INET;
     addr.sin_port = htons(port); // i.e. 1234
 
-    if (ipaddress == NULL) {
-        g_strlcpy(serveraddr, "127.0.0.1", sizeof(serveraddr));
-    } else {
-        g_strlcpy(serveraddr, ipaddress, sizeof(serveraddr));
-    }
-
-    LOG_INFO("server ip address: %s, port: %d\n", serveraddr, port);
-    ret = inet_aton(serveraddr, &addr.sin_addr);
+    LOG_INFO("server ip address: %s, port: %d\n", ipaddress, port);
+    ret = inet_aton(ipaddress, &addr.sin_addr);
 
     if (ret == 0) {
         LOG_SEVERE("inet_aton failure\n");
@@ -722,6 +715,7 @@ static void *initialize_tethering_socket(void *opaque);
 int connect_tethering_app(const char *ipaddress, int port)
 {
     TetheringState *client = NULL;
+    int ipaddr_len = 0;
 
     client = g_malloc0(sizeof(TetheringState));
     if (!client) {
@@ -731,23 +725,21 @@ int connect_tethering_app(const char *ipaddress, int port)
     client->port = port;
 
     if (ipaddress) {
-        int ipaddr_len = 0;
-
         ipaddr_len = strlen(ipaddress);
-
-        client->ipaddress = g_malloc0(ipaddr_len + 1);
-        if (!client->ipaddress) {
-            g_free(client);
-            return -1;
-        }
-
-        g_strlcpy(client->ipaddress, ipaddress, ipaddr_len);
     } else {
-        client->ipaddress = NULL;
+        // ipaddr_len = strlen(LOOPBACK);
+        ipaddr_len = strlen(loopback);
+        ipaddress = loopback;
     }
 
-    tethering_client = client;
+    client->ipaddress = g_malloc0(ipaddr_len + 1);
+    if (!client->ipaddress) {
+        g_free(client);
+        return -1;
+    }
+    g_strlcpy(client->ipaddress, ipaddress, ipaddr_len + 1);
 
+    tethering_client = client;
     qemu_mutex_init(&tethering_client->mutex);
 
     qemu_thread_create(&tethering_client->thread, "tethering-io-thread",