Home | History | Annotate | Download | only in iptables
      1 /*
      2  * Author: Paul.Russell (at) rustcorp.com.au and mneuling (at) radlogic.com.au
      3  *
      4  * Based on the ipchains code by Paul Russell and Michael Neuling
      5  *
      6  * (C) 2000-2002 by the netfilter coreteam <coreteam (at) netfilter.org>:
      7  * 		    Paul 'Rusty' Russell <rusty (at) rustcorp.com.au>
      8  * 		    Marc Boucher <marc+nf (at) mbsi.ca>
      9  * 		    James Morris <jmorris (at) intercode.com.au>
     10  * 		    Harald Welte <laforge (at) gnumonks.org>
     11  * 		    Jozsef Kadlecsik <kadlec (at) blackhole.kfki.hu>
     12  *
     13  *	iptables -- IP firewall administration for kernels with
     14  *	firewall table (aimed for the 2.3 kernels)
     15  *
     16  *	See the accompanying manual page iptables(8) for information
     17  *	about proper usage of this program.
     18  *
     19  *	This program is free software; you can redistribute it and/or modify
     20  *	it under the terms of the GNU General Public License as published by
     21  *	the Free Software Foundation; either version 2 of the License, or
     22  *	(at your option) any later version.
     23  *
     24  *	This program is distributed in the hope that it will be useful,
     25  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
     26  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27  *	GNU General Public License for more details.
     28  *
     29  *	You should have received a copy of the GNU General Public License
     30  *	along with this program; if not, write to the Free Software
     31  *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     32  */
     33 
     34 #include <stdio.h>
     35 #include <stdlib.h>
     36 #include <errno.h>
     37 #include <string.h>
     38 #include <iptables.h>
     39 #include "iptables-multi.h"
     40 
     41 #ifdef IPTABLES_MULTI
     42 int
     43 iptables_main(int argc, char *argv[])
     44 #else
     45 int
     46 main(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