I have not written any network namespace aware programs, but as no one else has stepped up I'll try to get things moving for you.
First off, when asking programming questions it is always helpful to others to mention the language you are using, and the OS and/or distro you are working with. Different languages will have differing support functions and libs available which will affect the replies you may receive - especially true of networking applications. Early on, different distros offered differing support for network namespaces, or none at all, but I am not sure how that may have changed in the past few years.
Looking for online help I found plenty of resources available, some of which may surely have the answer you want. One of the best I think after a quick browse was thie OpenStack article:
Network Namespaces. Use your search engine of choice to find others.
Finally, if you do not receive useful replies in the Programming forum, you might want to have your question moved to the Netowrking forum. If you want to have it moved simply click the Report button at bottom of your post and ask a moderator to do that for you.
Good luck!