iptables-1.3.2-20050720
[iptables.git] / iptables-save.c
index 90163b5..6c7267e 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <dlfcn.h>
 #include <time.h>
+#include <netdb.h>
 #include "libiptc/libiptc.h"
 #include "iptables.h"
 
@@ -75,6 +76,7 @@ static const struct pprot chain_protos[] = {
        { "icmp", IPPROTO_ICMP },
        { "esp", IPPROTO_ESP },
        { "ah", IPPROTO_AH },
+       { "sctp", IPPROTO_SCTP },
 };
 
 static void print_proto(u_int16_t proto, int invert)
@@ -83,6 +85,12 @@ static void print_proto(u_int16_t proto, int invert)
                unsigned int i;
                const char *invertstr = invert ? "! " : "";
 
+               struct protoent *pent = getprotobynumber(proto);
+               if (pent) {
+                       printf("-p %s%s ", invertstr, pent->p_name);
+                       return;
+               }
+
                for (i = 0; i < sizeof(chain_protos)/sizeof(struct pprot); i++)
                        if (chain_protos[i].num == proto) {
                                printf("-p %s%s ",
@@ -111,7 +119,7 @@ static int print_match(const struct ipt_entry_match *e,
                        const struct ipt_ip *ip)
 {
        struct iptables_match *match
-               = find_match(e->u.user.name, TRY_LOAD);
+               = find_match(e->u.user.name, TRY_LOAD, NULL);
 
        if (match) {
                printf("-m %s ", e->u.user.name);
@@ -157,7 +165,7 @@ static void print_rule(const struct ipt_entry *e,
 
        /* print counters */
        if (counters)
-               printf("[%llu:%llu] ", e->counters.pcnt, e->counters.bcnt);
+               printf("[%llu:%llu] ", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt);
 
        /* print chain name */
        printf("-A %s ", chain);
@@ -276,7 +284,7 @@ static int do_output(const char *tablename)
                                struct ipt_counters count;
                                printf("%s ",
                                       iptc_get_policy(chain, &count, &h));
-                               printf("[%llu:%llu]\n", count.pcnt, count.bcnt);
+                               printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
                        } else {
                                printf("- [0:0]\n");
                        }
@@ -313,7 +321,13 @@ static int do_output(const char *tablename)
  * :Chain name POLICY packets bytes
  * rule
  */
-int main(int argc, char *argv[])
+#ifdef IPTABLES_MULTI
+int
+iptables_save_main(int argc, char *argv[])
+#else
+int
+main(int argc, char *argv[])
+#endif
 {
        const char *tablename = NULL;
        int c;
@@ -321,6 +335,10 @@ int main(int argc, char *argv[])
        program_name = "iptables-save";
        program_version = IPTABLES_VERSION;
 
+       lib_dir = getenv("IPTABLES_LIB_DIR");
+       if (!lib_dir)
+               lib_dir = IPT_LIB_DIR;
+
 #ifdef NO_SHARED_LIBS
        init_extensions();
 #endif