Changeset 12f041d for lib


Ignore:
Timestamp:
2015-10-21T13:14:17Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
b0da3b8
Parents:
3314ced
Message:

socks4a proxy support (like socks4 with remote DNS)

Fixes trac ticket 995 https://bugs.bitlbee.org/bitlbee/ticket/995

This is slightly pointless for the suggested use case (tor), since with
socks5 we already send a hostname instead of an IP address.

Either way, it was easy to implement, so I hope it helps.

Location:
lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lib/proxy.c

    r3314ced r12f041d  
    294294        socklen_t len;
    295295        int error = ETIMEDOUT;
     296        gboolean is_socks4a = (proxytype == PROXY_SOCKS4A);
    296297
    297298        if (phb->inpa > 0) {
     
    304305        sock_make_blocking(source);
    305306
    306         /* XXX does socks4 not support host name lookups by the proxy? */
    307         if (!(hp = gethostbyname(phb->host))) {
     307        if (!is_socks4a && !(hp = gethostbyname(phb->host))) {
    308308                return phb_close(phb);
    309309        }
     
    313313        packet[2] = phb->port >> 8;
    314314        packet[3] = phb->port & 0xff;
    315         packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
    316         packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
    317         packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
    318         packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
     315        if (is_socks4a) {
     316                packet[4] = 0;
     317                packet[5] = 0;
     318                packet[6] = 0;
     319                packet[7] = 1;
     320        } else {
     321                packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
     322                packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
     323                packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
     324                packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
     325        }
    319326        packet[8] = 0;
    320327        if (write(source, packet, 9) != 9) {
    321328                return phb_close(phb);
     329        }
     330
     331        if (is_socks4a) {
     332                size_t host_len = strlen(phb->host) + 1; /* include the \0 */
     333
     334                if (write(source, phb->host, host_len) != host_len) {
     335                        return phb_close(phb);
     336                }
    322337        }
    323338
     
    506521        } else if (proxytype == PROXY_HTTP) {
    507522                return proxy_connect_http(host, port, phb);
    508         } else if (proxytype == PROXY_SOCKS4) {
     523        } else if (proxytype == PROXY_SOCKS4 || proxytype == PROXY_SOCKS4A) {
    509524                return proxy_connect_socks4(host, port, phb);
    510525        } else if (proxytype == PROXY_SOCKS5) {
  • lib/proxy.h

    r3314ced r12f041d  
    4040#define PROXY_SOCKS4 2
    4141#define PROXY_SOCKS5 3
     42#define PROXY_SOCKS4A 4
    4243
    4344extern char proxyhost[128];
  • lib/url.c

    r3314ced r12f041d  
    4848                } else if (g_strncasecmp(set_url, "socks5", i - set_url) == 0) {
    4949                        url->proto = PROTO_SOCKS5;
     50                } else if (g_strncasecmp(set_url, "socks4a", i - set_url) == 0) {
     51                        url->proto = PROTO_SOCKS4A;
    5052                } else {
    5153                        return 0;
  • lib/url.h

    r3314ced r12f041d  
    3030#define PROTO_SOCKS4    3
    3131#define PROTO_SOCKS5    4
     32#define PROTO_SOCKS4A   5
    3233#define PROTO_DEFAULT   PROTO_HTTP
    3334
Note: See TracChangeset for help on using the changeset viewer.