You can use `Netlink`. From the wiki,
> Netlink was designed for and is used to transfer miscellaneous networking information between the Linux kernel space and user space processes. Networking utilities such as iproute2 use Netlink to communicate with the Linux kernel from user space. Netlink consists of a standard socket-based interface for user space processes and an internal kernel API for kernel modules. It is designed to be a more flexible successor to ioctl. Originally, Netlink used the AF_NETLINK socket family.
My personal preference would be bash scripts for such tasks since I can specify the `iptables` rules/routing in my script itself. If you are using programming language like C, you can probably invoke `system` and then use the return value in your program to do something.
There is one API named **haxwithaxe** available from here