iptables-standalone.c revision e37d45ce390c2f5a7f1e64742b9100ecef0def54
1824c19963e0263366047787b024a992afc2b1c54Howard Hinnant/*
2824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * Author: Paul.Russell@rustcorp.com.au and mneuling@radlogic.com.au
3824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
4824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * Based on the ipchains code by Paul Russell and Michael Neuling
5824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
6824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * (C) 2000-2002 by the netfilter coreteam <coreteam@netfilter.org>:
7824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * 		    Paul 'Rusty' Russell <rusty@rustcorp.com.au>
8824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * 		    Marc Boucher <marc+nf@mbsi.ca>
9824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * 		    James Morris <jmorris@intercode.com.au>
10824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * 		    Harald Welte <laforge@gnumonks.org>
11824c19963e0263366047787b024a992afc2b1c54Howard Hinnant * 		    Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
12824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
13824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	iptables -- IP firewall administration for kernels with
14824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	firewall table (aimed for the 2.3 kernels)
15824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
16824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	See the accompanying manual page iptables(8) for information
17824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	about proper usage of this program.
185e57142c5902c3f73a6fdcb8cab55e88ffb43a56Howard Hinnant *
19824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	This program is free software; you can redistribute it and/or modify
20824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	it under the terms of the GNU General Public License as published by
21824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	the Free Software Foundation; either version 2 of the License, or
22824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	(at your option) any later version.
23824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
24824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	This program is distributed in the hope that it will be useful,
25824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	but WITHOUT ANY WARRANTY; without even the implied warranty of
26824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
275e57142c5902c3f73a6fdcb8cab55e88ffb43a56Howard Hinnant *	GNU General Public License for more details.
28824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *
29824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	You should have received a copy of the GNU General Public License
30824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	along with this program; if not, write to the Free Software
31824c19963e0263366047787b024a992afc2b1c54Howard Hinnant *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32824c19963e0263366047787b024a992afc2b1c54Howard Hinnant */
33824c19963e0263366047787b024a992afc2b1c54Howard Hinnant
34824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include <stdio.h>
35824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include <stdlib.h>
36824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include <errno.h>
37824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include <string.h>
38824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include <iptables.h>
39824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#include "iptables-multi.h"
40824c19963e0263366047787b024a992afc2b1c54Howard Hinnant
41824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#ifdef IPTABLES_MULTI
42824c19963e0263366047787b024a992afc2b1c54Howard Hinnantint
43824c19963e0263366047787b024a992afc2b1c54Howard Hinnantiptables_main(int argc, char *argv[])
44824c19963e0263366047787b024a992afc2b1c54Howard Hinnant#else
45int
46main(int argc, char *argv[])
47#endif
48{
49	int ret;
50	char *table = "filter";
51	struct iptc_handle *handle = NULL;
52
53	iptables_globals.program_name = "iptables";
54	ret = xtables_init_all(&iptables_globals, NFPROTO_IPV4);
55	if (ret < 0) {
56		fprintf(stderr, "%s/%s Failed to initialize xtables\n",
57				iptables_globals.program_name,
58				iptables_globals.program_version);
59				exit(1);
60	}
61#if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
62	init_extensions();
63	init_extensions4();
64#endif
65
66	ret = do_command4(argc, argv, &table, &handle);
67	if (ret) {
68		ret = iptc_commit(handle);
69		iptc_free(handle);
70	}
71
72	if (!ret) {
73		if (errno == EINVAL) {
74			fprintf(stderr, "iptables: %s. "
75					"Run `dmesg' for more information.\n",
76				iptc_strerror(errno));
77		} else {
78			fprintf(stderr, "iptables: %s.\n",
79				iptc_strerror(errno));
80		}
81		if (errno == EAGAIN) {
82			exit(RESOURCE_PROBLEM);
83		}
84	}
85
86	exit(!ret);
87}
88