Changeset 829:9ed47cfb4d44 in roaraudio for libroar/socket.c
- Timestamp:
- 09/25/08 04:56:33 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/socket.c
r759 r829 594 594 595 595 int roar_socket_open_proxy (int mode, int type, char * host, int port, char * proxy_type) { 596 int proxy_port ;596 int proxy_port = -1; 597 597 char proxy_host[ROAR_SOCKET_MAX_HOSTNAMELEN]; 598 char * proxy_addr ;598 char * proxy_addr = NULL; 599 599 int i; 600 int fh ;600 int fh = -1; 601 601 602 602 // TODO: change this so we support listen() proxys (ssh -R) … … 604 604 return -1; 605 605 606 if ( !str cmp(proxy_type, "socks4a") ) { // for TOR, the only supported type at the moment606 if ( !strncmp(proxy_type, "socks", 5) ) { 607 607 proxy_addr = getenv("socks_proxy"); 608 608 … … 625 625 return -1; 626 626 } 627 627 } 628 629 if ( !strcmp(proxy_type, "socks4a") ) { // for TOR, the only supported type at the moment 628 630 if ( roar_socket_open_socks4a(mode, fh, host, port) == -1 ) { 631 close(fh); 632 return -1; 633 } 634 635 return fh; 636 } else if ( !strcmp(proxy_type, "socks4d") ) { // DECnet 637 if ( roar_socket_open_socks4d(mode, fh, host, port) == -1 ) { 638 close(fh); 639 return -1; 640 } 641 642 return fh; 643 } else if ( !strcmp(proxy_type, "socks4") ) { // good old SOCKS4 644 if ( roar_socket_open_socks4(mode, fh, host, port) == -1 ) { 629 645 close(fh); 630 646 return -1; … … 639 655 // protocoll dependet proxy code: 640 656 657 int roar_socket_open_socks4 (int mode, int fh, char * host, int port) { 658 struct hostent * he; 659 660 if ( (he = gethostbyname(host)) == NULL ) { 661 ROAR_ERR("roar_socket_open_socks4(*): Can\'t resolve host name '%s'", host); 662 return -1; 663 } 664 665 return roar_socket_open_socks4x(mode, fh, he->h_addr, port, NULL, 0); 666 } 667 641 668 int roar_socket_open_socks4a(int mode, int fh, char * host, int port) { 669 return roar_socket_open_socks4x(mode, fh, "\0\0\0\1", port, host, strlen(host)+1); 670 } 671 672 int roar_socket_open_socks4d(int mode, int fh, char * host, int port) { 673 size_t len = strlen(host)+1; 674 char * dp; 675 676 if ( port == 0 ) { 677 if ( (dp = strstr(host, "::")) == NULL ) 678 return -1; 679 680 len--; 681 *dp = 0; 682 memmove(dp+1, dp+2, len - (dp-host) - 1); 683 } 684 685 return roar_socket_open_socks4x(mode, fh, "\0\2\0\0", port, host, len); 686 } 687 688 int roar_socket_open_socks4x(int mode, int fh, char host[4], int port, char * app, size_t app_len) { 642 689 char buf[9]; 643 int len;644 690 645 691 buf[0] = 0x04; 646 692 buf[1] = mode == MODE_CONNECT ? 0x01 : 0x02; 647 693 *((uint16_t*)&buf[2]) = htons(port); 648 buf[4] = 0x00; 649 buf[5] = 0x00; 650 buf[6] = 0x00; 651 buf[7] = 0x01; 694 memcpy(buf+4, host, 4); 652 695 buf[8] = 0x00; 653 696 … … 655 698 return -1; 656 699 657 len = strlen(host); 658 659 if ( write(fh, host, len) != len ) 660 return -1; 661 662 if ( write(fh, "\0", 1) != 1 ) 663 return -1; 700 if ( app_len > 0 ) 701 if ( write(fh, app, app_len) != app_len ) 702 return -1; 664 703 665 704 if ( read(fh, buf, 8) != 8 )
Note: See TracChangeset
for help on using the changeset viewer.