pipe_pid = -1;
}
-bool
-fw3_has_table(bool ipv6, const char *table)
+static bool
+file_contains(const char *path, const char *str)
{
FILE *f;
-
char line[12];
bool seen = false;
- const char *path = ipv6
- ? "/proc/net/ip6_tables_names" : "/proc/net/ip_tables_names";
-
if (!(f = fopen(path, "r")))
return false;
while (fgets(line, sizeof(line), f))
{
- if (!strncmp(line, table, strlen(table)))
+ if (!strncmp(line, str, strlen(str)))
{
seen = true;
break;
}
bool
-fw3_has_target(const bool ipv6, const char *target)
+fw3_has_table(const bool ipv6, const char *table)
{
- FILE *f;
+ const char *path = ipv6
+ ? "/proc/net/ip6_tables_names" : "/proc/net/ip_tables_names";
- char line[12];
- bool seen = false;
+ return file_contains(path, table);
+}
+bool
+fw3_has_target(const bool ipv6, const char *target)
+{
const char *path = ipv6
? "/proc/net/ip6_tables_targets" : "/proc/net/ip_tables_targets";
- if (!(f = fopen(path, "r")))
- return false;
-
- while (fgets(line, sizeof(line), f))
- {
- if (!strcmp(line, target))
- {
- seen = true;
- break;
- }
- }
-
- fclose(f);
-
- return seen;
+ return file_contains(path, target);
}
bool
void info(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
-
#define warn_section(t, r, e, fmt, ...) \
do { \
if (e) \
void fw3_pr(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
-bool fw3_has_table(bool ipv6, const char *table);
+bool fw3_has_table(const bool ipv6, const char *table);
bool fw3_has_target(const bool ipv6, const char *target);