Last active
May 25, 2018 16:11
-
-
Save sbz/11148971 to your computer and use it in GitHub Desktop.
pf: ioctl get rules call debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/cdefs.h> | |
#include <sys/types.h> | |
#include <sys/ioctl.h> | |
#ifdef __FreeBSD__ | |
#include <sys/endian.h> | |
#endif | |
#include <net/if.h> | |
#include <net/pfvar.h> | |
#include <err.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
static void | |
breakpoint(void) { | |
asm volatile("int $3"); | |
} | |
int | |
main(void) { | |
int dev; | |
int rc; | |
char *pf_device = "/dev/pf"; | |
struct pfioc_rule pr; | |
dev = open(pf_device, O_RDONLY); | |
if (dev == -1) | |
errx(1, "open: can't open device %s", pf_device); | |
memset(&pr, 0, sizeof(pr)); | |
if (ioctl(dev, DIOCGETRULES, &pr)) { | |
errx(1, "ioctl: DIOCGETRULES"); | |
} | |
#ifdef NDEBUG | |
breakpoint(); | |
#endif | |
printf("%x\n", pr); | |
printf("GETRULES: %lu\n", DIOCGETRULES); | |
return 0; | |
} |
Author
sbz
commented
Apr 21, 2014
- Compile it with:
- Run debugger in privilege mode because /dev/pf is owned by root:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment