Changeset 223 for tags/onioncat-0.1.7/src/ocatroute.c
- Timestamp:
- 06/21/08 14:11:41 (4 years ago)
- Location:
- tags/onioncat-0.1.7
- Files:
-
- 2 copied
-
. (copied) (copied from trunk)
-
src/ocatroute.c (copied) (copied from trunk/src/ocatroute.c) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tags/onioncat-0.1.7/src/ocatroute.c
r221 r223 287 287 288 288 289 #define HANDLE_HTTP 290 #ifdef HANDLE_HTTP 291 #define BSTRLEN 1024 292 293 int handle_http(const OcatPeer_t *peer) 294 { 295 time_t t; 296 char response[BSTRLEN], timestr[BSTRLEN]; 297 struct tm tm; 298 299 // simple check if packet could be an HTTP request 300 if (strncmp(peer->fragbuf, "GET ", 4)) 301 return 0; 302 303 t = time(NULL); 304 (void) localtime_r(&t, &tm); 305 strftime(timestr, BSTRLEN, "%a, %d %b %Y %H:%M:%S %z", &tm); 306 snprintf(response, BSTRLEN, 307 "HTTP/1.0 301 HTTP not possible\r\nLocation: %s\r\nDate: %s\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n" 308 "<html><body><h1>HTTP not possible!<br>OnionCat is running on this port at \"%s.onion\"</h1></body></html>\r\n", 309 OCAT_URL, timestr, onion_url_ 310 ); 311 log_msg(L_INFO, "request seems to be HTTP"); 312 if (send(peer->tcpfd, response, strlen(response), MSG_DONTWAIT) == -1) 313 log_msg(L_ERROR, "could not send html response"); 314 315 return 1; 316 } 317 #endif 318 319 289 320 void *socket_receiver(void *p) 290 321 { … … 405 436 if (!plen) 406 437 { 438 #ifdef HANDLE_HTTP 439 if (handle_http(peer)) 440 { 441 log_msg(L_NOTICE, "closing %d due to HTTP.", peer->tcpfd); 442 close(peer->tcpfd); 443 unlock_peer(peer); 444 lock_peers(); 445 delete_peer(peer); 446 unlock_peers(); 447 } 448 #endif 407 449 log_msg(L_DEBUG, "FRAGBUF RESET!"); 408 450 peer->fraglen = 0; … … 652 694 { 653 695 struct sockaddr_in in; 654 int fd, t ;696 int fd, t, len; 655 697 char buf[FRAME_SIZE], onion[ONION_NAME_SIZE]; 656 698 SocksHdr_t *shdr = (SocksHdr_t*) buf; … … 688 730 shdr->port = htons(ocat_dest_port_); 689 731 shdr->addr.s_addr = htonl(0x00000001); 690 strcpy(buf + sizeof(SocksHdr_t), "tor6"); 691 strcpy(buf + sizeof(SocksHdr_t) + 5, onion); 692 693 if (write(fd, shdr, sizeof(SocksHdr_t) + strlen(onion) + 6) != sizeof(SocksHdr_t) + strlen(onion) + 6) 732 /* 733 strlcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 734 strlcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, sizeof(onion)); 735 */ 736 memcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 737 memcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, strlen(onion) + 1); 738 len = sizeof(SocksHdr_t) + strlen(usrname_) + strlen(onion) + 2; 739 if (write(fd, shdr, len) != len) 694 740 // FIXME: there should be some additional error handling 695 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", sizeof(SocksHdr_t) + strlen(onion) + 6, fd);741 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", len, fd); 696 742 log_msg(L_DEBUG, "connect request sent"); 697 743
Note: See TracChangeset
for help on using the changeset viewer.
