I am trying to modify iperf to support another protocol (UDT). The UDT API is written such that it mirrors the standard BSD calls:
socket(...);
bind(...);
listen(...);
What I need to do then, is conditionally link with the UDT library so that these calls in iperf will use the UDT code instead of the socket interface to the TCP stack. Can this be done? I could always just load the library and have another conditional path using the UDT:: namespace but there would 1) be a lot of duplication from the TCP path and 2) be a lot of changes where maybe there need be none. Please let me know if I'm not being clear, any suggestions of how to achieve this dynamic linking is appreciated.
Edit:
Using the dlopen() family mentioned below, I could have the following program flow:
Parse cmd line params -> if UDT is requested, load library libudt -> get and store handles to all the UDT BSD functions (bind, listen, etc)
At this point I have function pointers stored with all my UDT functions. Let's say I'm storing them all in a struct called udt_calls. Now, I have a problem with the existing code which just makes calls like:
bind(...)
rather than:
udt_calls->bind(...)
Is there a clean way I can globally override any BSD call throughout the program with my now loaded function pointers in my udt_calls struct?