Do we have API call similar to getbestinterface windows API call ?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Do we have API call similar to getbestinterface windows API call ?
Hello,
GetBestInterface function returns the index of the interface that has the best route to the specified host address. This is windows API call. But I am looking for similar API call in linux. I am aware of "ip route get" command which I guess does similar job.Correct me If I am wrong.
Instead of command I am more interested in some API call.
Thanks jpollard for your reply. I totally agree with you. But I have different scenario where I want to know the route for the destination host.
Let me explain you.
I have two interfaces on my system (ETH1 and ETH2). ETH1 is connected to a public network having x.x.x.x as valid IP address and ETH2 is connected to some different isolated network having y.y.y.y as IP address.
I have C++ application which will generate some files. This application has to sends a notification message including source IP (either x.x.x.x or y.y.y.y) address to the destination host. Destination host has to connect to the IP address given in the notification message to fetch the generated files. SO the destination host can be on ETH1 or ETH2. My application is not aware of this and it knows only the destination address. Here we are not suppose to send the files directly to the destination but we have to inform the destination to establish a connection and fetch the files. So in this case I want to know the interface name (ETH1 or ETH2) along with the IP address (x.x.x.x or y.y.y.y) so that my application will include this IP address in notification message and send it to the destination host. In windows I use to use getbestinterface API call. Now I have to port my application on LINUX and I am not aware of any such API in LINUX.
Once the packet leaves your system, you have no control over how it reaches the destination.
The ONLY way you can control that is by having TWO separate networks.
Thus if you want to use a particular network, then you use the destination address that is ON that network.
You can SPECIFY which interface to use (as in Windows)... but guess what - you ether get a "cannot connect to network" OR the routing layer will redirect it to the other interface.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.