diff options
author | zfl9 <zfl9.com@gmail.com> | 2020-03-04 21:08:11 +0800 |
---|---|---|
committer | zfl9 <zfl9.com@gmail.com> | 2020-03-04 21:08:11 +0800 |
commit | a9080d8962cc7d30528618b7822d27c10b54bc67 (patch) | |
tree | 2e084eaae5a36702e1dae53f0b3cb84a1f8daf5a | |
parent | use libev instead of libuv (diff) | |
download | dns2tcp-a9080d8962cc7d30528618b7822d27c10b54bc67.tar.gz dns2tcp-a9080d8962cc7d30528618b7822d27c10b54bc67.tar.bz2 dns2tcp-a9080d8962cc7d30528618b7822d27c10b54bc67.zip |
use libev instead of libuv
-rw-r--r-- | dnsudp2tcp.c | 50 | ||||
-rwxr-xr-x | test | bin | 0 -> 67328 bytes |
2 files changed, 32 insertions, 18 deletions
diff --git a/dnsudp2tcp.c b/dnsudp2tcp.c index d64cbec..974e97d 100644 --- a/dnsudp2tcp.c +++ b/dnsudp2tcp.c @@ -56,9 +56,10 @@ typedef struct { } tcpwatcher_t; enum { - OPT_REUSE_PORT = 1 << 0, - OPT_QUICK_ACK = 1 << 1, - OPT_FAST_OPEN = 1 << 2, + OPT_IPV6_V6ONLY = 1 << 0, + OPT_REUSE_PORT = 1 << 1, + OPT_QUICK_ACK = 1 << 2, + OPT_FAST_OPEN = 1 << 3, }; static bool g_verbose = false; @@ -110,16 +111,17 @@ static void parse_sock_addr6(const skaddr6_t *addr, char *ipstr, portno_t *portn } static void print_command_help(void) { - printf("usage: dns2tcp <-L listen> <-R remote> [-s syncnt] [-rafvVh]\n" - " -L <ip#port> udp listen address, this is required\n" - " -R <ip#port> tcp remote address, this is required\n" - " -s <syncnt> set TCP_SYNCNT(max) for remote socket\n" - " -r enable SO_REUSEPORT for listen socket\n" - " -a enable TCP_QUICKACK for remote socket\n" - " -f enable TCP_FASTOPEN for remote socket\n" - " -v print verbose log, default: <disabled>\n" - " -V print version number of dns2tcp and exit\n" - " -h print help information of dns2tcp and exit\n" + printf("usage: dns2tcp <-L listen> <-R remote> [-s syncnt] [-6rafvVh]\n" + " -L <ip#port> udp listen address, this is required\n" + " -R <ip#port> tcp remote address, this is required\n" + " -s <syncnt> set TCP_SYNCNT(max) for remote socket\n" + " -6 enable IPV6_V6ONLY for listen socket\n" + " -r enable SO_REUSEPORT for listen socket\n" + " -a enable TCP_QUICKACK for remote socket\n" + " -f enable TCP_FASTOPEN for remote socket\n" + " -v print verbose log, default: <disabled>\n" + " -V print version number of dns2tcp and exit\n" + " -h print help information of dns2tcp and exit\n" "bug report: https://github.com/zfl9/dns2tcp. email: zfl9.com@gmail.com\n" ); } @@ -186,7 +188,7 @@ static void parse_command_args(int argc, char *argv[]) { opterr = 0; int shortopt = -1; - const char *optstr = "L:R:s:rafvVh"; + const char *optstr = "L:R:s:6rafvVh"; while ((shortopt = getopt(argc, argv, optstr)) != -1) { switch (shortopt) { case 'L': @@ -210,6 +212,9 @@ static void parse_command_args(int argc, char *argv[]) { goto PRINT_HELP_AND_EXIT; } break; + case '6': + g_options |= OPT_IPV6_V6ONLY; + break; case 'r': g_options |= OPT_REUSE_PORT; break; @@ -263,12 +268,21 @@ int main(int argc, char *argv[]) { LOGINF("[main] udp listen addr: %s#%hu", g_listen_ipstr, g_listen_portno); LOGINF("[main] tcp remote addr: %s#%hu", g_remote_ipstr, g_remote_portno); - if (g_syn_maxcnt) LOGINF("[main] enable TCP_SYNCNT:%hhu feature", g_syn_maxcnt); - if (g_options & OPT_REUSE_PORT) LOGINF("[main] enable SO_REUSEPORT feature"); - if (g_options & OPT_QUICK_ACK) LOGINF("[main] enable TCP_QUICKACK feature"); - if (g_options & OPT_FAST_OPEN) LOGINF("[main] enable TCP_FASTOPEN feature"); + if (g_syn_maxcnt) LOGINF("[main] enable TCP_SYNCNT:%hhu sockopt", g_syn_maxcnt); + if (g_options & OPT_IPV6_V6ONLY) LOGINF("[main] enable IPV6_V6ONLY sockopt"); + if (g_options & OPT_REUSE_PORT) LOGINF("[main] enable SO_REUSEPORT sockopt"); + if (g_options & OPT_QUICK_ACK) LOGINF("[main] enable TCP_QUICKACK sockopt"); + if (g_options & OPT_FAST_OPEN) LOGINF("[main] enable TCP_FASTOPEN sockopt"); IF_VERBOSE LOGINF("[main] verbose mode, affect performance"); + g_event_loop = ev_default_loop(0); + + int udp_sfd = socket(g_listen_skaddr.sin6_family, SOCK_DGRAM, 0); + if (udp_sfd < 0) { + LOGERR("[main] create udp socket failed: (%d) %s", errno, strerror(errno)); + return errno; + } + // TODO return 0; Binary files differ |