|
10321
|
1 /*
|
|
|
2 * gaim - Rendezvous Protocol Plugin
|
|
|
3 *
|
|
|
4 * Gaim is the legal property of its developers, whose names are too numerous
|
|
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
|
6 * source distribution.
|
|
|
7 *
|
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
|
11 * (at your option) any later version.
|
|
|
12 *
|
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 * GNU General Public License for more details.
|
|
|
17 *
|
|
|
18 * You should have received a copy of the GNU General Public License
|
|
|
19 * along with this program; if not, write to the Free Software
|
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
21 */
|
|
|
22 #include "internal.h"
|
|
|
23
|
|
|
24 #include "connection.h"
|
|
|
25 #include "network.h"
|
|
|
26
|
|
|
27 #include "direct.h"
|
|
|
28 #include "rendezvous.h"
|
|
|
29
|
|
|
30 /*
|
|
|
31 gchar *
|
|
|
32 gaim_network_convert_ipv4_to_string(void *ip)
|
|
|
33 {
|
|
|
34 gchar *ret;
|
|
|
35 unsigned char *ipv4 = (unsigned char *)ip;
|
|
|
36
|
|
|
37 ret = g_strdup_printf("::ffff:%02hhx%02hhx:%02hhx%02hhx", ipv4[0], ipv4[1], ipv4[2], ipv4[3]);
|
|
|
38
|
|
|
39 return ret;
|
|
|
40 }
|
|
|
41
|
|
|
42 gchar *
|
|
|
43 gaim_network_convert_ipv6_to_string(void *ip)
|
|
|
44 {
|
|
|
45 gchar *ret;
|
|
|
46
|
|
|
47 //ret = g_strdup_printf("%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx:%02hhx%02hhx", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]);
|
|
|
48 ret = g_malloc0(INET6_ADDRSTRLEN + 1);
|
|
|
49 inet_ntop(AF_INET6, ip, ret, sizeof(ret));
|
|
|
50
|
|
|
51 return ret;
|
|
|
52 }
|
|
|
53 */
|
|
|
54
|
|
|
55 static gboolean rendezvous_find_buddy_by_ip(gpointer key, gpointer value, gpointer user_data)
|
|
|
56 {
|
|
|
57 RendezvousBuddy *rb = value;
|
|
|
58
|
|
|
59 printf("looking at ip=%s\n", rb->ip);
|
|
|
60 if ((rb->ip != NULL) && !strcasecmp(rb->ip, user_data))
|
|
|
61 return TRUE;
|
|
|
62
|
|
|
63 return FALSE;
|
|
|
64 }
|
|
|
65
|
|
|
66 void rendezvous_direct_acceptconnection(gpointer data, gint source, GaimInputCondition condition)
|
|
|
67 {
|
|
|
68 GaimConnection *gc = (GaimConnection *)data;
|
|
|
69 RendezvousData *rd = gc->proto_data;
|
|
|
70 int fd;
|
|
|
71 struct sockaddr_in6 addr;
|
|
|
72 socklen_t addrlen = sizeof(addr);
|
|
|
73 gchar *ip;
|
|
|
74 RendezvousBuddy *rb;
|
|
|
75
|
|
|
76 fd = accept(rd->listener, (struct sockaddr *)&addr, &addrlen);
|
|
|
77 if (fd == -1) {
|
|
|
78 gaim_debug_warning("rendezvous", "accept: %s\n", strerror(errno));
|
|
|
79 return;
|
|
|
80 }
|
|
|
81 /*
|
|
|
82 printf("\nsa_family=%d\n\n", ((struct sockaddr *)&addr)->sa_family);
|
|
|
83 if (((struct sockaddr *)&addr)->sa_family == AF_INET)
|
|
|
84 ip = gaim_network_convert_ipv4_to_string((unsigned char *)&ip);
|
|
|
85 else if (((struct sockaddr *)&addr)->sa_family == AF_INET6)
|
|
|
86 ip = gaim_network_convert_ipv6_to_string((unsigned char *)&(addr.sin6_addr));
|
|
|
87 printf("\nip=%s\n", ip);
|
|
|
88
|
|
|
89 rb = g_hash_table_find(rd->buddies, rendezvous_find_buddy_by_ip, ip);
|
|
|
90 g_free(ip);
|
|
|
91 */
|
|
|
92 if (rb == NULL) {
|
|
|
93 /* We don't want to talk to people that don't advertise themselves */
|
|
|
94 printf("\ndid not find rb\n\n");
|
|
|
95 close(fd);
|
|
|
96 return;
|
|
|
97 }
|
|
|
98 printf("\nip belongs to=%s\n\n", rb->aim);
|
|
|
99
|
|
|
100 rb->fd = fd;
|
|
|
101
|
|
|
102 }
|