iptables-standalone.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Author: Paul.Russell@rustcorp.com.au and mneuling@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@netfilter.org>:
  7. * Paul 'Rusty' Russell <rusty@rustcorp.com.au>
  8. * Marc Boucher <marc+nf@mbsi.ca>
  9. * James Morris <jmorris@intercode.com.au>
  10. * Harald Welte <laforge@gnumonks.org>
  11. * Jozsef Kadlecsik <kadlec@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. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <errno.h>
  36. #include <string.h>
  37. #include <iptables.h>
  38. #include "iptables-multi.h"
  39. int
  40. iptables_main(int argc, char *argv[])
  41. {
  42. int ret;
  43. char *table = "filter";
  44. struct xtc_handle *handle = NULL;
  45. iptables_globals.program_name = "iptables";
  46. ret = xtables_init_all(&iptables_globals, NFPROTO_IPV4);
  47. if (ret < 0) {
  48. fprintf(stderr, "%s/%s Failed to initialize xtables\n",
  49. iptables_globals.program_name,
  50. iptables_globals.program_version);
  51. exit(1);
  52. }
  53. #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
  54. init_extensions();
  55. init_extensions4();
  56. #endif
  57. ret = do_command4(argc, argv, &table, &handle);
  58. if (ret) {
  59. ret = iptc_commit(handle);
  60. iptc_free(handle);
  61. }
  62. if (!ret) {
  63. if (errno == EINVAL) {
  64. fprintf(stderr, "iptables: %s. "
  65. "Run `dmesg' for more information.\n",
  66. iptc_strerror(errno));
  67. } else {
  68. fprintf(stderr, "iptables: %s.\n",
  69. iptc_strerror(errno));
  70. }
  71. if (errno == EAGAIN) {
  72. exit(RESOURCE_PROBLEM);
  73. }
  74. }
  75. exit(!ret);
  76. }