Have you ever encountered a piece of software that didn't include a feature to allow it to be bound to a specific IP? Or connect to a remote server (IP) via a specific interface or source IP?
Unfortunately this is far to common, either with Open Source software or even more common with Proprietary or closed source software. Fortunately this can be resolved without requiring modification to the software by using a LD_PRELOAD'ed shim.
How does this work?
The shim intercepts calls to common networking functions (i.e bind, connect) and replaces s_addr with the desired IP. Say the software has the following code in it before listening to a socket.
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
It would become as if the call was:
name.sin_addr.s_addr = in_addr("1.2.3.4");
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
Cool so how do I do this?
A tutorial for utilizing a shim made by Daniel Ryde can be found in the X4B Knowledgebase
Questions / Conclusion?
Cool or what? Got any questions, ask away
Unfortunately this is far to common, either with Open Source software or even more common with Proprietary or closed source software. Fortunately this can be resolved without requiring modification to the software by using a LD_PRELOAD'ed shim.
How does this work?
The shim intercepts calls to common networking functions (i.e bind, connect) and replaces s_addr with the desired IP. Say the software has the following code in it before listening to a socket.
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
It would become as if the call was:
name.sin_addr.s_addr = in_addr("1.2.3.4");
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
Cool so how do I do this?
A tutorial for utilizing a shim made by Daniel Ryde can be found in the X4B Knowledgebase
Questions / Conclusion?
Cool or what? Got any questions, ask away