int main(int argc, char **argv) { struct evdns_base *dns; struct event_base *base; struct bufferevent *bev; struct url *socks, *host; int s4; base = event_base_new(); dns = evdns_base_new(base, 1); log_set_file(NULL); log_set_min_level(LOG_DEBUG); if (argc >= 3) { socks = url_tokenize(argv[2]); s4 = !evutil_ascii_strcasecmp("socks4", socks->scheme); if (conn_set_socks_server(socks->host, socks->port, s4? SOCKS_4 : SOCKS_4a) < 0) return 0; } host = url_connect_tokenize(argv[1]); bev = bufferevent_socket_new(base, -1, BEV_OPT_CLOSE_ON_FREE); conn_connect_bufferevent(bev, dns, AF_INET, host->host, host->port, do_connect, NULL); event_base_dispatch(base); return 0; }
static void set_socks_server(const char *socks) { struct url *url; enum socks_ver socksv; url = url_tokenize(socks); if (!url || !url->scheme) { log_error("shim: bad socks server, %s", socks); exit(1); } if (url->port < 0) url->port = 1080; if (!evutil_ascii_strcasecmp(url->scheme, "socks4")) socksv = SOCKS_4; else if (!evutil_ascii_strcasecmp(url->scheme, "socks4a")) socksv = SOCKS_4a; else { log_error("shim: unknown socks version, %s", url->scheme); exit(1); } if (conn_set_socks_server(url->host, url->port, socksv) < 0) exit(1); url_free(url); }
int main(int argc, char **argv) { struct url *url; url = url_tokenize(argv[1]); if (!url) { printf("bad url!\n"); return 0; } printf("%s, %s, %d, %s\n", url->scheme, url->host, url->port, url->path); url_free(url); return 0; }