What's the best way to bind socket to specific interface?
===

I have an embedded application, running on a linux based modem, that sends data via SSL socket to a specific url. The modem is set up to send data via ethernet (eth0). However, if the ethernet connection is unavailable, it needs to switch to wireless (ppp0) as a backup. I tried SO_BINDTODEVICE but it did not work, I believe because of permission issues. What works, but is complicated and prone to errors, is to reconfigure the modem on the fly by disabling the eth0 port (with an AT command) which forces the socket connections to be made through the wireless port. Then, I periodically check if eth0 is back up by reconfiguring the modem, checking the connection and then reconfigure back to ppp0 if it is not. Its clumsy and the device's AT server is unreliable.

Is there a better way? 

One idea would be to have two urls on our remote server. One for ethernet socket and one for wireless. Thus, you could set up the routing tables accordingly. if the connection to the ethernet url is not successful, try the other url which will be routed to the ppp0 interface. 

Good idea or not? Any other ideas?