Mac OS X doesn't really have namespaces like Linux, but if you want to block networking, it looks like you can use `sandbox_init()` to get a similar effect. See the man page for a description.
There are two built-in profiles that seem to support a use case similar to what you describe: `kSBXProfileNoInternet`, where TCP/IP networking is prohibited; and `kSBXProfileNoNetwork`, where all sockets-based networking is prohibited. (While the latter might be closer to what Linux network namespace is doing here, the former might be enough for your needs.)
Please note that this function is documented as _deprecated_ , and those who wish to sandbox an application should look into the App Sandbox feature, so you might want to take a look at that as well. I don't know that App Sandbox would use the same mechanism (code that you run from a platform `#ifdef`), that's why I suggested `sandbox_init()` first.