3 * $Id: fw.c,v 1.1 1999/07/01 08:56:23 mdw Exp $
5 * Port forwarding thingy
7 * (c) 1999 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the `fw' port forwarder.
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1999/07/01 08:56:23 mdw
37 /*----- Header files ------------------------------------------------------*/
50 #include <mLib/mdwopt.h>
51 #include <mLib/quis.h>
52 #include <mLib/report.h>
62 /*----- Static variables --------------------------------------------------*/
64 sel_state
*sel
; /* Multiplexor for nonblocking I/O */
66 /*----- Main code ---------------------------------------------------------*/
68 /* --- Standard GNU help options --- */
70 static void version(FILE *fp
)
72 fprintf(fp
, "%s version " VERSION
"\n", QUIS
);
75 static void usage(FILE *fp
)
77 fprintf(stderr
, "Usage: %s [-d] [-f file] [config statements...]\n",
81 static void help(FILE *fp
)
87 A fairly full-featured port-forwarder. Options available are:\n\
89 -h, --help Display this help message.\n\
90 -v, --version Display the program's version number.\n\
91 -u, --usage Display a terse usage summary.\n\
93 -f, --file=FILE Read configuration from a file.\n\
94 -d, --dump Dump the configuration to standard output.\n\
96 Configuration may be supplied in one or more configuration files, or on\n\
97 the command line (or both). If no `-f' option is present, and no\n\
98 configuration is given on the command line, the standard input stream is\n\
101 Configuration is free-form. Comments begin with a `#' character and\n\
102 continue to the end of the line. When reading from the command line,\n\
103 each argument is considered a separate line. See the manual page for the\n\
110 * Arguments: @int argc@ = number of command line arguments
111 * @char *argv[]@ = vector of argument strings
115 * Use: Simple port-forwarding server.
118 int main(int argc
, char *argv
[])
130 /* --- Initialize things --- */
138 /* --- Parse command line options --- */
141 static struct option opts
[] = {
143 /* --- Standard GNU help options --- */
145 { "help", 0, 0, 'h' },
146 { "version", 0, 0, 'v' },
147 { "usage", 0, 0, 'u' },
149 /* --- Other useful arguments --- */
151 { "file", OPTF_ARGREQ
, 0, 'f' },
152 { "dump", 0, 0, 'd' },
153 { "fork", 0, 0, 'b' },
154 { "background", 0, 0, 'b' },
156 /* --- Magic terminator --- */
160 int i
= mdwopt(argc
, argv
, "hvu f:db", opts
, 0, 0, 0);
180 if ((fp
= fopen(optarg
, "r")) == 0)
181 die(1, "couldn't open file `%s': %s", optarg
, strerror(errno
));
182 scan_fileinit(&ctx
, fp
, optarg
);
204 /* --- Deal with the remaining arguments --- */
206 if (optind
== argc
) {
209 else if (isatty(STDIN_FILENO
)) {
210 moan("no configuration given and stdin is a terminal.");
211 moan("type `%s --help' for usage information.", QUIS
);
215 scan_fileinit(&ctx
, stdin
, "<stdin>");
220 scan_argvinit(&ctx
, argv
+ optind
);
224 /* --- Dump out the state --- */
228 fputs("global acl:\n", stdout
);
230 for (s
= sel
->files
; s
; s
= s
->next
)
231 listener_dump((listener
*)s
, stdout
);
235 /* --- Fork into the background --- */
242 die(1, "couldn't fork: %s", strerror(errno
));
246 close(0); close(1); close(2);
254 /* --- Let rip --- */
256 openlog(QUIS
, 0, LOG_DAEMON
);
262 /*----- That's all, folks -------------------------------------------------*/