LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-20-2015, 12:32 PM   #1
asif darvajkar
LQ Newbie
 
Registered: Aug 2015
Posts: 2

Rep: Reputation: Disabled
Smile 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.


Sorry if I am not clear.

Thanks,
 
Old 08-20-2015, 01:14 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I don't believe it is needed. Opening a connection to the target should have the kernel pick the best interface to use by default.
 
Old 08-21-2015, 01:41 PM   #3
asif darvajkar
LQ Newbie
 
Registered: Aug 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile

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.

I hope it is clear.
 
Old 08-21-2015, 02:40 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Then you don't understand how the network works.

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ptrace call API in attached process, how to set %rip? JunDai Programming 2 02-07-2013 05:11 AM
[SOLVED] Difference between Library API and System Call API ram619 Linux - Kernel 8 12-27-2012 02:40 AM
difference between system call and api vinaytp Linux - Newbie 3 05-06-2009 09:47 AM
How to check for return value from a API call in C language kushalkoolwal Programming 5 08-19-2008 04:55 PM
Shell Script call API treotan Programming 1 08-22-2005 10:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration