Mercurial > pidgin.yaz
comparison src/stun.c @ 11371:6e02e20e3a58
[gaim-migrate @ 13596]
Replace // comments with /* */.
Set debugging category to "stun" instead of "simple".
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 30 Aug 2005 10:41:24 +0000 |
parents | e1840eb860e7 |
children | e1ab173ef3b5 |
comparison
equal
deleted
inserted
replaced
11370:2c3fb4a0f785 | 11371:6e02e20e3a58 |
---|---|
115 struct sockaddr_in *sinptr; | 115 struct sockaddr_in *sinptr; |
116 | 116 |
117 len = recv(source, buffer, 1024, 0); | 117 len = recv(source, buffer, 1024, 0); |
118 | 118 |
119 hdr = (struct stun_header*)buffer; | 119 hdr = (struct stun_header*)buffer; |
120 if(hdr->transid[0]!=packet->transid[0] || hdr->transid[1]!=packet->transid[1] || hdr->transid[2]!=packet->transid[2] || hdr->transid[3]!=packet->transid[3]) { // wrong transaction | 120 if(hdr->transid[0]!=packet->transid[0] || hdr->transid[1]!=packet->transid[1] || hdr->transid[2]!=packet->transid[2] || hdr->transid[3]!=packet->transid[3]) { /* wrong transaction */ |
121 gaim_debug_info("simple", "got wrong transid\n"); | 121 gaim_debug_info("stun", "got wrong transid\n"); |
122 return; | 122 return; |
123 } | 123 } |
124 if(test==1) { | 124 if(test==1) { |
125 tmp = buffer + sizeof(struct stun_header); | 125 tmp = buffer + sizeof(struct stun_header); |
126 while(buffer+len > tmp) { | 126 while(buffer+len > tmp) { |
130 memcpy(&in.s_addr, tmp+sizeof(struct stun_attrib)+2+2, 4); | 130 memcpy(&in.s_addr, tmp+sizeof(struct stun_attrib)+2+2, 4); |
131 strcpy(nattype.publicip, inet_ntoa(in)); | 131 strcpy(nattype.publicip, inet_ntoa(in)); |
132 } | 132 } |
133 tmp += sizeof(struct stun_attrib) + attrib->len; | 133 tmp += sizeof(struct stun_attrib) + attrib->len; |
134 } | 134 } |
135 gaim_debug_info("simple", "got public ip %s\n",nattype.publicip); | 135 gaim_debug_info("stun", "got public ip %s\n", nattype.publicip); |
136 nattype.status = 2; | 136 nattype.status = 2; |
137 nattype.type = 1; | 137 nattype.type = 1; |
138 | 138 |
139 // is it a NAT? | 139 /* is it a NAT? */ |
140 | 140 |
141 ifc.ifc_len = sizeof(buffer); | 141 ifc.ifc_len = sizeof(buffer); |
142 ifc.ifc_req = (struct ifreq *) buffer; | 142 ifc.ifc_req = (struct ifreq *) buffer; |
143 ioctl(source, SIOCGIFCONF, &ifc); | 143 ioctl(source, SIOCGIFCONF, &ifc); |
144 | 144 |
147 ifr = (struct ifreq *) tmp; | 147 ifr = (struct ifreq *) tmp; |
148 | 148 |
149 tmp += sizeof(struct ifreq); | 149 tmp += sizeof(struct ifreq); |
150 | 150 |
151 if(ifr->ifr_addr.sa_family == AF_INET) { | 151 if(ifr->ifr_addr.sa_family == AF_INET) { |
152 // we only care about ipv4 interfaces | 152 /* we only care about ipv4 interfaces */ |
153 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; | 153 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; |
154 if(sinptr->sin_addr.s_addr == in.s_addr) { | 154 if(sinptr->sin_addr.s_addr == in.s_addr) { |
155 // no NAT | 155 /* no NAT */ |
156 gaim_debug_info("simple","no nat"); | 156 gaim_debug_info("stun", "no nat"); |
157 nattype.type = 0; | 157 nattype.type = 0; |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 gaim_timeout_remove(timeout); | 161 gaim_timeout_remove(timeout); |
182 nattype.status = 0; | 182 nattype.status = 0; |
183 if(cb) cb(&nattype); | 183 if(cb) cb(&nattype); |
184 return &nattype; | 184 return &nattype; |
185 } | 185 } |
186 | 186 |
187 if(nattype.status == 1) { // currently discovering | 187 if(nattype.status == 1) { /* currently discovering */ |
188 if(cb) callbacks = g_slist_append(callbacks, cb); | 188 if(cb) callbacks = g_slist_append(callbacks, cb); |
189 return NULL; | 189 return NULL; |
190 } | 190 } |
191 if(nattype.status != -1) { // already discovered | 191 if(nattype.status != -1) { /* already discovered */ |
192 if(cb) cb(&nattype); | 192 if(cb) cb(&nattype); |
193 return &nattype; | 193 return &nattype; |
194 } | 194 } |
195 if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | 195 if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
196 nattype.status = 0; | 196 nattype.status = 0; |