updates.
[silc.git] / lib / silcclient / client_keyagr.c
index c68a432fd3b3405f48faed5b7756ca4f001938b1..20bb4b347e417ab92a8ed31fb7b6e1176ee99325 100644 (file)
@@ -295,7 +295,8 @@ SILC_TASK_CALLBACK(silc_client_key_agreement_timeout)
 void silc_client_send_key_agreement(SilcClient client,
                                    SilcClientConnection conn,
                                    SilcClientEntry client_entry,
-                                   char *hostname,
+                                   const char *hostname,
+                                   const char *bindhost,
                                    int port,
                                    uint32 timeout_secs,
                                    SilcKeyAgreementCallback completion,
@@ -310,18 +311,26 @@ void silc_client_send_key_agreement(SilcClient client,
   if (client_entry->ke)
     return;
 
-  /* Create the listener if hostname and port was provided */
+  /* Create the listener if hostname and port was provided.
+   * also, use bindhost if it was specified.
+   */
+   
   if (hostname) {
     ke = silc_calloc(1, sizeof(*ke));
-    ke->fd = silc_net_create_server(port, hostname);
+    
+    if (bindhost)
+      ke->fd = silc_net_create_server(port, bindhost);
+    else
+      ke->fd = silc_net_create_server(port, hostname);
 
     if (ke->fd < 0) {
       client->ops->say(client, conn, SILC_CLIENT_MESSAGE_ERROR, 
                       "Cannot create listener on %s on port %d: %s", 
-                      hostname, port, strerror(errno));
+                      (bindhost) ? bindhost:hostname, port, strerror(errno));
       completion(client, conn, client_entry, SILC_KEY_AGREEMENT_FAILURE,
                 NULL, context);
       silc_free(ke);
+
       return;
     }
 
@@ -343,9 +352,9 @@ void silc_client_send_key_agreement(SilcClient client,
        will not start the key exchange protocol within the specified 
        timeout. */
     ke->timeout = silc_schedule_task_add(client->schedule, 0, 
-                                    silc_client_key_agreement_timeout,
-                                    (void *)ke, timeout_secs, 0, 
-                                    SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
+                                        silc_client_key_agreement_timeout,
+                                        (void *)ke, timeout_secs, 0, 
+                                        SILC_TASK_TIMEOUT, SILC_TASK_PRI_LOW);
   }
 
   /* Encode the key agreement payload */
@@ -357,7 +366,8 @@ void silc_client_send_key_agreement(SilcClient client,
   silc_client_packet_send(client, sock, SILC_PACKET_KEY_AGREEMENT,
                          client_entry->id, SILC_ID_CLIENT, NULL, NULL,
                          buffer->data, buffer->len, FALSE);
-  silc_free(buffer);
+  silc_buffer_free(buffer);
+
 }
 
 static int 
@@ -366,17 +376,17 @@ silc_client_connect_to_client_internal(SilcClientInternalConnectContext *ctx)
   int sock;
 
   /* Create connection to server asynchronously */
-  sock = silc_net_create_connection_async(ctx->port, ctx->host);
+  sock = silc_net_create_connection_async(NULL, ctx->port, ctx->host);
   if (sock < 0)
     return -1;
 
   /* Register task that will receive the async connect and will
      read the result. */
   ctx->task = silc_schedule_task_add(ctx->client->schedule, sock, 
-                                silc_client_perform_key_agreement_start,
-                                (void *)ctx, 0, 0, 
-                                SILC_TASK_FD,
-                                SILC_TASK_PRI_NORMAL);
+                                    silc_client_perform_key_agreement_start,
+                                    (void *)ctx, 0, 0, 
+                                    SILC_TASK_FD,
+                                    SILC_TASK_PRI_NORMAL);
   silc_schedule_set_listen_fd(ctx->client->schedule, sock, SILC_TASK_WRITE);
 
   ctx->sock = sock;