Dont fail in url_tokenize if input contains just a path.
[shim.git] / main.c
blob54c5421dc542807cbe57a1a4547063bbf3beac49
1 #include <netinet/in.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <event2/event.h>
5 #include <event2/dns.h>
6 #include <event2/util.h>
7 #include "proxy.h"
8 #include "conn.h"
9 #include "log.h"
10 #include "util.h"
12 int
13 main(int argc, char **argv)
15 struct sockaddr_in sin;
16 struct event_base *base;
17 struct evdns_base *dns;
19 base = event_base_new();
20 dns = evdns_base_new(base, 1);
21 log_set_min_level(LOG_DEBUG);
22 log_set_file(NULL);
24 if (argc >= 2) {
25 struct url *url;
26 enum socks_ver socksv;
28 url = url_tokenize(argv[1]);
29 if (!url) {
30 log_error("shim: bad socks server, %s", argv[1]);
31 return 0;
33 if (url->port < 0)
34 url->port = 1080;
36 if (!evutil_ascii_strcasecmp(url->scheme, "socks4"))
37 socksv = SOCKS_4;
38 else if (!evutil_ascii_strcasecmp(url->scheme, "socks4a"))
39 socksv = SOCKS_4a;
40 else {
41 log_error("shim: unknown socks version, %s",
42 url->scheme);
43 return 0;
46 if (conn_set_socks_server(url->host, url->port, socksv) < 0)
47 return 0;
49 url_free(url);
52 memset(&sin, 0, sizeof(sin));
53 sin.sin_family = AF_INET;
54 sin.sin_port = htons(8888);
56 proxy_init(base, dns, (struct sockaddr *)&sin, sizeof(sin));
58 event_base_dispatch(base);
60 return 0;