]> git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/getconntracktable.c
Merge branch 'ddns' into next
[ipfire-2.x.git] / src / misc-progs / getconntracktable.c
1 /* IPFire helper program - getconntracktable
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * The kernel's connection tracking table is not readable by
7 * non-root users. So this helper will just read and output it.
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "setuid.h"
13
14 int main(void) {
15 if (!(initsetuid()))
16 exit(1);
17
18 FILE *fp = fopen("/proc/net/nf_conntrack", "r");
19 if (fp == NULL) {
20 exit(1);
21 }
22
23 /* Read content line by line and write it to stdout. */
24 char linebuf[STRING_SIZE];
25 while (fgets(linebuf, STRING_SIZE, fp)) {
26 printf("%s", linebuf);
27 }
28
29 fclose(fp);
30 return 0;
31 }