diff options
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/opentracker.c b/opentracker.c index 9c76f7f..bd8f5ca 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -36,7 +36,7 @@ struct http_data { | |||
36 | io_batch iob; | 36 | io_batch iob; |
37 | char* hdrbuf; | 37 | char* hdrbuf; |
38 | int hlen; | 38 | int hlen; |
39 | char ip[16]; | 39 | unsigned long ip; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | int header_complete(struct http_data* r) | 42 | int header_complete(struct http_data* r) |
@@ -141,7 +141,7 @@ e400: | |||
141 | case 8: | 141 | case 8: |
142 | if( byte_diff(data,8,"announce")) | 142 | if( byte_diff(data,8,"announce")) |
143 | goto e404; | 143 | goto e404; |
144 | byte_copy( &peer.ip, 4, h->ip ); | 144 | peer.ip = h->ip; |
145 | peer.port_flags = 6881 << 16; | 145 | peer.port_flags = 6881 << 16; |
146 | numwant = 50; | 146 | numwant = 50; |
147 | compact = 1; | 147 | compact = 1; |
@@ -193,14 +193,14 @@ e400: | |||
193 | 193 | ||
194 | /* Scanned whole query string */ | 194 | /* Scanned whole query string */ |
195 | if( !hash || ( compact == 0 ) ) goto e404; | 195 | if( !hash || ( compact == 0 ) ) goto e404; |
196 | printf("ALLFINE\n"); | 196 | |
197 | torrent = add_peer_to_torrent( hash, &peer ); | 197 | torrent = add_peer_to_torrent( hash, &peer ); |
198 | if( !torrent ) { | 198 | if( !torrent ) { |
199 | e500: | 199 | e500: |
200 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); | 200 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); |
201 | goto bailout; | 201 | goto bailout; |
202 | } | 202 | } |
203 | reply = malloc( numwant*6+10 ); | 203 | reply = malloc( numwant*6+24 ); |
204 | if( reply ) | 204 | if( reply ) |
205 | reply_size = return_peers_for_torrent( torrent, numwant, reply ); | 205 | reply_size = return_peers_for_torrent( torrent, numwant, reply ); |
206 | if( !reply || ( reply_size < 0 ) ) { | 206 | if( !reply || ( reply_size < 0 ) ) { |
@@ -214,13 +214,11 @@ e404: | |||
214 | goto bailout; | 214 | goto bailout; |
215 | } | 215 | } |
216 | c=h->hdrbuf=(char*)malloc(500); | 216 | c=h->hdrbuf=(char*)malloc(500); |
217 | c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); | 217 | c+=fmt_str(c,"HTTP/1.1 200 OK\r\nContent-Type: text/plain"); |
218 | c+=fmt_str(c,"\r\nContent-Length: "); | 218 | c+=fmt_str(c,"\r\nContent-Length: "); |
219 | /* ANSWER SIZE*/ | 219 | c+=fmt_ulonglong(c, reply_size ); |
220 | c+=fmt_ulonglong(c, 100 ); | ||
221 | c+=fmt_str(c,"\r\nLast-Modified: "); | 220 | c+=fmt_str(c,"\r\nLast-Modified: "); |
222 | /* MODIFY DATE | 221 | c+=fmt_httpdate(c,time(0)); |
223 | c+=fmt_httpdate(c,s.st_mtime); */ | ||
224 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); | 222 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); |
225 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); | 223 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); |
226 | if( reply && reply_size ) iob_addbuf(&h->iob,reply, reply_size ); | 224 | if( reply && reply_size ) iob_addbuf(&h->iob,reply, reply_size ); |
@@ -240,13 +238,13 @@ void graceful( int s ) { | |||
240 | 238 | ||
241 | int main() | 239 | int main() |
242 | { | 240 | { |
243 | int s=socket_tcp6(); | 241 | int s=socket_tcp4(); |
244 | uint32 scope_id; | 242 | uint32 scope_id; |
245 | char ip[16]; | 243 | unsigned long ip; |
246 | uint16 port; | 244 | uint16 port; |
247 | 245 | ||
248 | if (socket_bind6_reuse(s,V6any,6969,0)==-1) | 246 | if (socket_bind4_reuse(s,NULL,6969)==-1) |
249 | panic("socket_bind6_reuse"); | 247 | panic("socket_bind4_reuse"); |
250 | 248 | ||
251 | if (socket_listen(s,16)==-1) | 249 | if (socket_listen(s,16)==-1) |
252 | panic("socket_listen"); | 250 | panic("socket_listen"); |
@@ -270,7 +268,7 @@ int main() | |||
270 | if (i==s) // ist es der serversocket? | 268 | if (i==s) // ist es der serversocket? |
271 | { | 269 | { |
272 | int n; | 270 | int n; |
273 | while ((n=socket_accept6(s,ip,&port,&scope_id))!=-1) | 271 | while ((n=socket_accept4(s,(void*)&ip,&port))!=-1) |
274 | { | 272 | { |
275 | if (io_fd(n)) | 273 | if (io_fd(n)) |
276 | { | 274 | { |
@@ -280,7 +278,7 @@ int main() | |||
280 | if (h) | 278 | if (h) |
281 | { | 279 | { |
282 | byte_zero(h,sizeof(struct http_data)); | 280 | byte_zero(h,sizeof(struct http_data)); |
283 | byte_copy(h->ip,sizeof(ip),ip); | 281 | h->ip=ip; |
284 | io_setcookie(n,h); | 282 | io_setcookie(n,h); |
285 | } else | 283 | } else |
286 | io_close(n); | 284 | io_close(n); |
@@ -291,7 +289,7 @@ int main() | |||
291 | if (errno==EAGAIN) | 289 | if (errno==EAGAIN) |
292 | io_eagain(s); | 290 | io_eagain(s); |
293 | else | 291 | else |
294 | carp("socket_accept6"); | 292 | carp("socket_accept4"); |
295 | } | 293 | } |
296 | else | 294 | else |
297 | { | 295 | { |