Changeset 12f041d for lib/proxy.c


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.

File:
1 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) {
Note: See TracChangeset for help on using the changeset viewer.