X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/b303b5847edac33b6b85de2fd420b8dbf6c219fd..808702d218ba5999dbc8cef769a79d1fb9be1e63:/tripe.c diff --git a/tripe.c b/tripe.c index 9e225659..0ba169b2 100644 --- a/tripe.c +++ b/tripe.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tripe.c,v 1.9 2003/04/15 14:11:09 mdw Exp $ + * $Id$ * * Main program * @@ -26,38 +26,6 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: tripe.c,v $ - * Revision 1.9 2003/04/15 14:11:09 mdw - * Rationalize the behaviour of the `-G' and `-U' options. - * - * Revision 1.8 2002/01/13 17:28:29 mdw - * Don't turn tracing on if tracing is turned off (!). - * - * Revision 1.7 2002/01/13 17:14:05 mdw - * Don't include the tracing option in the help if not compiled in. - * - * Revision 1.6 2001/06/19 22:08:37 mdw - * Moved buffers to peer.c. - * - * Revision 1.5 2001/02/16 21:43:12 mdw - * Provide a more helpful usage message. - * - * Revision 1.4 2001/02/16 21:41:31 mdw - * Add a new buffer. - * - * Revision 1.3 2001/02/04 17:10:40 mdw - * Remove a debugging @abort@ call. - * - * Revision 1.2 2001/02/03 22:33:00 mdw - * Stuff more randomness into the pool in the interval timer. - * - * Revision 1.1 2001/02/03 20:26:37 mdw - * Initial checkin. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "tripe.h" @@ -87,7 +55,7 @@ void interval(struct timeval *tv, void *v) { struct timeval tvv; T( trace(T_PEER, "peer: interval timer"); ) - rand_seed(RAND_GLOBAL, HASHSZ); + rand_seed(RAND_GLOBAL, MAXHASHSZ); p_interval(); tvv = *tv; tvv.tv_sec += T_INTERVAL; @@ -106,9 +74,9 @@ void interval(struct timeval *tv, void *v) static void usage(FILE *fp) { - pquis(fp, "Usage: $ [-D] [-d dir] [-p port] [-U user] [-G group]\n\ - [-k priv-keyring] [-K pub-keyring] [-t key-tag]\n\ - [-a socket] [-T trace-opts]\n"); + pquis(fp, "Usage: $ [-D] [-d DIR] [-b ADDR] [-p PORT]\n\ + [-U USER] [-G GROUP] [-a SOCKET] [-T TRACE-OPTS]\n\ + [-k PRIV-KEYRING] [-K PUB-KEYRING] [-t KEY-TAG]\n"); } static void version(FILE *fp) @@ -129,10 +97,11 @@ Options:\n\ -u, --usage Display pointless usage message.\n\ \n\ -D, --daemon Run in the background.\n\ --d, --directory=DIR Switch to directory DIR (default $TRIPEDIR).\n\ +-d, --directory=DIR Switch to directory DIR [default " CONFIGDIR "].\n\ +-b, --bind-address=ADDR Bind UDP socket to this IP ADDR.\n\ -p, --port=PORT Select UDP port to listen to.\n\ --u, --setuid=USER Set uid to USER after initialization.\n\ --g, --setgid=GROUP Set gid to GROUP after initialization.\n\ +-U, --setuid=USER Set uid to USER after initialization.\n\ +-G, --setgid=GROUP Set gid to GROUP after initialization.\n\ -k, --priv-keyring=FILE Get private key from FILE.\n\ -K, --pub-keyring=FILE Get public keys from FILE.\n\ -t, --tag=KEYTAG Use private key labelled TAG.\n\ @@ -147,10 +116,11 @@ int main(int argc, char *argv[]) { const char *kr_priv = "keyring", *kr_pub = "keyring.pub"; const char *tag_priv = "tripe-dh"; - const char *csock = "tripesock"; - const char *dir = "/var/lib/tripe"; + const char *csock = SOCKETDIR "/tripesock"; + const char *dir = CONFIGDIR; const char *p; unsigned port = 0; + struct in_addr baddr = { INADDR_ANY }; unsigned f = 0; uid_t u = -1; gid_t g = -1; @@ -175,6 +145,7 @@ int main(int argc, char *argv[]) { "setuid", OPTF_ARGREQ, 0, 'U' }, { "gid", OPTF_ARGREQ, 0, 'G' }, { "setgid", OPTF_ARGREQ, 0, 'G' }, + { "bind-address", OPTF_ARGREQ, 0, 'b' }, { "port", OPTF_ARGREQ, 0, 'p' }, { "directory", OPTF_ARGREQ, 0, 'd' }, { "priv-keyring", OPTF_ARGREQ, 0, 'k' }, @@ -185,10 +156,11 @@ int main(int argc, char *argv[]) { "trace", OPTF_ARGREQ, 0, 'T' }, #endif + { "tunnel", 0, 0, '0' }, { 0, 0, 0, 0 } }; - int i = mdwopt(argc, argv, "hvu DU:G: p:d:k:K:t:a:" T("T:"), + int i = mdwopt(argc, argv, "hvuDU:G:b:p:d:k:K:t:a:" T("T:"), opts, 0, 0, 0); if (i < 0) break; @@ -232,7 +204,13 @@ int main(int argc, char *argv[]) die(EXIT_FAILURE, "group `%s' not found", optarg); g = gr->gr_gid; } break; - + + case 'b': { + struct hostent *h = gethostbyname(optarg); + if (!h) + die(EXIT_FAILURE, "unknown host name `%s'", optarg); + memcpy(&baddr, h->h_addr, sizeof(struct in_addr)); + } break; case 'p': { char *p; unsigned long i = strtoul(optarg, &p, 0); @@ -267,6 +245,11 @@ int main(int argc, char *argv[]) trace_level(tr_flags); break; #endif + case '0': { + static const char *tun[] = { "notdef", "unet", "bsd", "linux" }; + puts(tun[TUN_TYPE]); + exit(0); + } break; default: f |= f_bogus; break; @@ -286,10 +269,10 @@ int main(int argc, char *argv[]) sel_init(&sel); sig_init(&sel); rand_noisesrc(RAND_GLOBAL, &noise_source); - rand_seed(RAND_GLOBAL, RMD160_HASHSZ); + rand_seed(RAND_GLOBAL, MAXHASHSZ); signal(SIGPIPE, SIG_IGN); tun_init(); - p_init(port); + p_init(baddr, port); if (!(f & f_daemon)) a_create(STDIN_FILENO, STDOUT_FILENO); if (g != (gid_t)-1) {