annotate src/stun.c @ 11225:46facec74fc1

[gaim-migrate @ 13361] added STUN API to detect a NAT and the public ip committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Wed, 10 Aug 2005 21:16:37 +0000
parents
children 67f874fadb57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11225
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
1 /**
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
2 * @file stun.c STUN (RFC3489) Implementation
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
3 * @ingroup core
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
4 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
5 * gaim
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
6 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
9 * source distribution.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
10 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
14 * (at your option) any later version.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
15 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
19 * GNU General Public License for more details.
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
20 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
24 *
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
25 * TODO: currently only detects if there is a NAT and not the type of NAT
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
26 */
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
27
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
28 #include <sys/socket.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
29 #include <ifaddrs.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
30 #include <net/if.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
31 #include <sys/ioctl.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
32 #include <resolv.h>
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
33
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
34 #include "internal.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
35
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
36 #include "debug.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
37 #include "account.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
38 #include "stun.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
39 #include "prefs.h"
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
40
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
41 struct stun_nattype nattype = {-1, 0, "\0"};
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
42
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
43 static gint transid[4];
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
44
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
45 static GSList *callbacks = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
46 static int fd = -1;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
47 gint incb = -1;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
48
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
49 static void do_callbacks() {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
50 while(callbacks) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
51 StunCallback cb = callbacks->data;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
52 cb(&nattype);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
53 callbacks = g_slist_remove(callbacks, cb);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
54 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
55 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
56
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
57 static void reply_cb(gpointer data, gint source, GaimInputCondition cond) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
58 char buffer[10240];
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
59 char *tmp;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
60 int len;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
61 struct in_addr in;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
62 struct stun_attrib *attrib;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
63 struct stun_header *hdr;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
64
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
65 len = recv(source, buffer, 10240, 0);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
66
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
67 hdr = (struct stun_header*)buffer;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
68 if(hdr->transid[0]!=transid[0] || hdr->transid[1]!=transid[1] || hdr->transid[2]!=transid[2] || hdr->transid[3]!=transid[3]) { // wrong transaction
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
69 gaim_debug_info("simple", "got wrong transid\n");
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
70 return;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
71 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
72
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
73 tmp = buffer + sizeof(struct stun_header);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
74 while(buffer+len > tmp) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
75
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
76 attrib = (struct stun_attrib*) tmp;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
77 if(attrib->type == htons(0x0001) && attrib->len == htons(8)) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
78 memcpy(&in.s_addr, tmp+sizeof(struct stun_attrib)+2+2, 4);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
79 strcpy(nattype.publicip, inet_ntoa(in));
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
80 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
81 tmp += sizeof(struct stun_attrib) + attrib->len;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
82 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
83 gaim_debug_info("simple", "got public ip %s\n",nattype.publicip);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
84 nattype.status = 2;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
85 nattype.type = 1;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
86
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
87 // is it a NAT?
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
88 struct ifconf ifc;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
89 struct ifreq *ifr;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
90 struct sockaddr_in *sinptr;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
91
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
92 ifc.ifc_len = sizeof(buffer);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
93 ifc.ifc_req = (struct ifreq *) buffer;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
94 ioctl(source, SIOCGIFCONF, &ifc);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
95
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
96 tmp = buffer;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
97 while(tmp < buffer + ifc.ifc_len) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
98 ifr = (struct ifreq *) tmp;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
99 len = sizeof(struct sockaddr);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
100
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
101 tmp += sizeof(ifr->ifr_name) + len;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
102
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
103 if(ifr->ifr_addr.sa_family == AF_INET) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
104 // we only care about ipv4 interfaces
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
105 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
106 if(sinptr->sin_addr.s_addr == in.s_addr) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
107 // no NAT
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
108 gaim_debug_info("simple","no nat");
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
109 nattype.type = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
110 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
111 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
112 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
113
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
114 do_callbacks();
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
115 gaim_input_remove(incb);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
116 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
117
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
118 struct stun_nattype *gaim_stun_discover(StunCallback cb) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
119 struct sockaddr_in addr;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
120 struct stun_header data;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
121 int ret = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
122
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
123 if(nattype.status == 1) { // currently discovering
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
124 callbacks = g_slist_append(callbacks, cb);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
125 return NULL;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
126 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
127 if(nattype.status == 2 || nattype.status == 0) { // already discovered
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
128 cb(&nattype);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
129 return &nattype;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
130 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
131
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
132 if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
133 nattype.status = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
134 cb(&nattype);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
135 return &nattype;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
136 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
137
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
138 addr.sin_family = AF_INET;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
139 addr.sin_port = htons(12108);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
140 addr.sin_addr.s_addr = INADDR_ANY;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
141 while( ((ret = bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) < 0 ) && ntohs(addr.sin_port) < 12208) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
142 addr.sin_port = htons(ntohs(addr.sin_port)+1);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
143 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
144 if( ret < 0 ) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
145 nattype.status = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
146 cb(&nattype);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
147 return &nattype;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
148 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
149 incb = gaim_input_add(fd, GAIM_INPUT_READ, reply_cb, NULL);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
150
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
151 char *ip = gaim_prefs_get_string("/core/network/stun_ip");
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
152 int port = gaim_prefs_get_int("/core/network/stun_port");
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
153
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
154 if(port == 0 || ip == NULL || ip[0] == '\0') return NULL;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
155
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
156 addr.sin_family = AF_INET;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
157 addr.sin_port = htons(port);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
158 addr.sin_addr.s_addr = inet_addr(ip);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
159
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
160 data.type = htons(0x0001);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
161 data.len = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
162 transid[0] = data.transid[0] = rand();
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
163 transid[1] = data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
164 transid[2] = data.transid[2] = rand();
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
165 transid[3] = data.transid[3] = rand();
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
166
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
167 if( sendto(fd, &data, sizeof(struct stun_header), 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < sizeof(struct stun_header)) {
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
168 nattype.status = 0;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
169 cb(&nattype);
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
170 return &nattype;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
171 }
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
172 return NULL;
46facec74fc1 [gaim-migrate @ 13361]
Thomas Butter <tbutter>
parents:
diff changeset
173 }