X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/cd2d678ee93ee3cab0c4f0df959489c27e9a8ad5..24898e7eadbac98ac25abbecdb813ceacabefa76:/server/tripe.c diff --git a/server/tripe.c b/server/tripe.c index fb1d3375..637400a5 100644 --- a/server/tripe.c +++ b/server/tripe.c @@ -163,6 +163,21 @@ int lp_run(void) return (0); } +/*----- Tunnel table ------------------------------------------------------*/ + +static const tunnel_ops *tunnels[] = { +#ifdef TUN_LINUX + &tun_linux, +#endif +#ifdef TUN_BSD + &tun_bsd, +#endif +#ifdef TUN_UNET + &tun_unet, +#endif + &tun_slip, +}; + /*----- Main code ---------------------------------------------------------*/ /* --- @main@ --- * @@ -229,6 +244,7 @@ int main(int argc, char *argv[]) const char *p; const char *bindhost = 0, *bindsvc = STR(TRIPE_PORT); struct addrinfo aihint = { 0 }, *ailist; + const tunnel_ops *dflt = 0; unsigned f = 0; int i; int err; @@ -247,7 +263,6 @@ int main(int argc, char *argv[]) dir = p; if ((p = getenv("TRIPESOCK")) != 0) csock = p; - tun_default = tunnels[0]; aihint.ai_family = AF_UNSPEC; for (;;) { @@ -323,13 +338,11 @@ int main(int argc, char *argv[]) break; case 'n': { int i; - for (i = 0;; i++) { - if (!tunnels[i]) - die(EXIT_FAILURE, "unknown tunnel `%s'", optarg); + for (i = 0; i < N(tunnels); i++) if (mystrieq(optarg, tunnels[i]->name)) - break; - } - tun_default = tunnels[i]; + { dflt = tunnels[i]; goto found_tun; } + die(EXIT_FAILURE, "unknown tunnel `%s'", optarg); + found_tun:; } break; case 'd': dir = optarg; @@ -359,7 +372,7 @@ int main(int argc, char *argv[]) #endif case '0': { int i; - for (i = 0; tunnels[i]; i++) + for (i = 0; i < N(tunnels); i++) puts(tunnels[i]->name); exit(0); } break; @@ -406,8 +419,9 @@ int main(int argc, char *argv[]) } p_init(); - for (i = 0; tunnels[i]; i++) - tunnels[i]->init(); + for (i = 0; i < N(tunnels); i++) + p_addtun(tunnels[i]); + if (dflt) p_setdflttun(dflt); p_bind(ailist); freeaddrinfo(ailist); for (i = 0; tunnels[i]; i++) {