tethering: remove redundant source when copying ip address.
authorKitae Kim <kt920.kim@samsung.com>
Thu, 7 Aug 2014 05:02:00 +0000 (14:02 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 7 Aug 2014 05:02:00 +0000 (14:02 +0900)
Change-Id: I895fef95e6a7d1f993220f07cea06bdbb00d7b90
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/ecs/ecs_tethering.c
tizen/src/tethering/common.c

index 9825e1c4ae733ca0892a9406216fa16aaa481d2c..b4d488361ad4a786f9f01470d3a9ef00132e11e1 100644 (file)
@@ -238,7 +238,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 3a23a0188ae4c6e9713b07e2131dbe9d1a6ed583..9796a079c8ebd88eeea25f928318814576aa1826 100644 (file)
@@ -61,6 +61,7 @@ MULTI_DEBUG_CHANNEL(tizen, 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;
@@ -607,21 +608,14 @@ 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));
-    }
-
-    INFO("server ip address: %s, port: %d\n", serveraddr, port);
-    ret = inet_aton(serveraddr, &addr.sin_addr);
+    INFO("server ip address: %s, port: %d\n", ipaddress, port);
+    ret = inet_aton(ipaddress, &addr.sin_addr);
 
     if (ret == 0) {
         ERR("inet_aton failure\n");
@@ -773,6 +767,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) {
@@ -782,20 +777,18 @@ 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);
+        ipaddress = loopback;
+    }
+
+    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;