Example #1
0
static void
silcpurple_ftp_send(PurpleXfer *x)
{
    SilcPurpleXfer xfer = x->data;
    const char *name;
    char *local_ip = NULL, *remote_ip = NULL;
    gboolean local = TRUE;

    name = purple_xfer_get_local_filename(x);

    /* Do the same magic what we do with key agreement (see silcpurple_buddy.c)
       to see if we are behind NAT. */
    if (silc_net_check_local_by_sock(xfer->sg->conn->sock->sock,
                                     NULL, &local_ip)) {
        /* Check if the IP is private */
        if (silcpurple_ip_is_private(local_ip)) {
            local = FALSE;
            /* Local IP is private, resolve the remote server IP to see whether
               we are talking to Internet or just on LAN. */
            if (silc_net_check_host_by_sock(xfer->sg->conn->sock->sock, NULL,
                                            &remote_ip))
                if (silcpurple_ip_is_private(remote_ip))
                    /* We assume we are in LAN.  Let's provide the connection point. */
                    local = TRUE;
        }
    }

    if (local && !local_ip)
        local_ip = silc_net_localip();

    /* Send the file */
    silc_client_file_send(xfer->sg->client, xfer->sg->conn,
                          silcpurple_ftp_monitor, xfer,
                          local_ip, 0, !local, xfer->client_entry,
                          name, &xfer->session_id);

    silc_free(local_ip);
    silc_free(remote_ip);
}
Example #2
0
File: buddy.c Project: dylex/pidgin
static void
silcpurple_buddy_keyagr_do(PurpleConnection *gc, const char *name,
			 gboolean force_local)
{
	SilcPurple sg = gc->proto_data;
	SilcClientEntry *clients;
	SilcUInt32 clients_count;
	char *local_ip = NULL, *remote_ip = NULL;
	gboolean local = TRUE;
	char *nickname;
	SilcPurpleKeyAgr a;

	if (!sg->conn || !name)
		return;

	if (!silc_parse_userfqdn(name, &nickname, NULL))
		return;

	/* Find client entry */
	clients = silc_client_get_clients_local(sg->client, sg->conn, nickname, name,
						&clients_count);
	if (!clients) {
		/* Resolve unknown user */
		SilcPurpleResolve r = silc_calloc(1, sizeof(*r));
		if (!r)
			return;
		r->nick = g_strdup(name);
		r->gc = gc;
		silc_client_get_clients(sg->client, sg->conn, nickname, NULL,
					silcpurple_buddy_keyagr_resolved, r);
		silc_free(nickname);
		return;
	}

	/* Resolve the local IP from the outgoing socket connection.  We resolve
	   it to check whether we have a private range IP address or public IP
	   address.  If we have public then we will assume that we are not behind
	   NAT and will provide automatically the point of connection to the
	   agreement.  If we have private range address we assume that we are
	   behind NAT and we let the responder provide the point of connection.

	   The algorithm also checks the remote IP address of server connection.
	   If it is private range address and we have private range address we
	   assume that we are chatting in LAN and will provide the point of
	   connection.

	   Naturally this algorithm does not always get things right. */

	if (silc_net_check_local_by_sock(sg->conn->sock->sock, NULL, &local_ip)) {
		/* Check if the IP is private */
		if (!force_local && silcpurple_ip_is_private(local_ip)) {
			local = FALSE;

			/* Local IP is private, resolve the remote server IP to see whether
			   we are talking to Internet or just on LAN. */
			if (silc_net_check_host_by_sock(sg->conn->sock->sock, NULL,
							&remote_ip))
				if (silcpurple_ip_is_private(remote_ip))
					/* We assume we are in LAN.  Let's provide
					   the connection point. */
					local = TRUE;
		}
	}

	if (force_local)
		local = TRUE;

	if (local && !local_ip)
		local_ip = silc_net_localip();

	a = silc_calloc(1, sizeof(*a));
	if (!a)
		return;
	a->responder = local;

	/* Send the key agreement request */
	silc_client_send_key_agreement(sg->client, sg->conn, clients[0],
				       local ? local_ip : NULL, NULL, 0, 60,
				       silcpurple_buddy_keyagr_cb, a);

	silc_free(local_ip);
	silc_free(remote_ip);
	silc_free(clients);
}