How do I interface with pf in a C/C++ application?

I'd like to write a simple GUI C/C++ application (a simple interface) where the user can perform a few pf operations and also receive pf feedback (instead of using the pfctl command). I was hoping to get some guidance in regards to where to get started. The man pf (8) suggests the use of the man ioctl (2) interface . I can see a bunch of constants that start with "DIOC". A quick example or a tutorial on how to get started developing with pf would be more than appreciated. Thanks.

If you do not get what you need from here:
https://www.freebsd.org/cgi/man.cgi?query=pf\(4\)&sektion=

And here - This is an example of coding for it:
Landon Fuller

Then consider using system() calls with pfctl. The reason I say this is that the ioctl interface is very complex, the pfctl direct interface is not that bad.

1 Like

Landon Fuller's blog seems to have exactly what I was looking for. That's great. I'll start there. Thank you so much Jim. You're a life-saver. I'm trying to stay shell-independent. So, all the pfctl(8) won't work for me. I was looking for a C or C++ API instead. If I figure out how he uses one of the constants from the pf(8) man I think I can try to tweak it a bit to implement other ones as well.