LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-11-2010, 04:20 PM   #1
harry-c
LQ Newbie
 
Registered: Dec 2010
Location: Brisbane, Australia
Distribution: Fedora, Ubunu, uCLniux
Posts: 2

Rep: Reputation: 0
How to check if Kernel has a route to a particular IP address


Hi,

I'm working on a userspace application that needs to find if the kernel has a route configured for a particular destination address, and what port it would be routed from. I'm hoping there is a simple kernel call that will do this for me, but haven't been able to find it yet :-)

I don't want to actually send a packet to do this, just query the kernel if where it *would* send the packet if I did.

The only method I've come up with is to get the kernel routing table through rtnetlink then check each entry to see if it matches my destination address. I guess this will work (after one or two tries to get the logic right ;-) ) but I'd rather do a single call if there is one.

Thanks in advance
 
Old 12-13-2010, 01:00 AM   #2
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
Yes there is a simple kernel call but that requires a parameter. That parameter values can be enabled/disables in "/etc/sysctl.conf"


File: /etc/sysctl.conf

net.ipv4.ip_forward = 0 // Value Zero denotes disableing

or

net.ipv4.ip_forward = 1 // Value One denotes enabling


sysctl -p /etc/sysctl.conf // Enable the changes made in sysctl.conf

Thanks,
 
Old 12-13-2010, 06:02 PM   #3
harry-c
LQ Newbie
 
Registered: Dec 2010
Location: Brisbane, Australia
Distribution: Fedora, Ubunu, uCLniux
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks prodev, but this isn't exactly what I'm looking for. I want to ask the kernel if it has a route to a particular address, not if routing/forwarding is enabled.

One approach that I'm following up is using connect() syscall to connect to a UDP port. This should fail with EHOSTUNREACH if there is no route to the destination IP address.
 
  


Reply



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
Add route to 1 IP Address through second network card mattttux Linux - Networking 1 09-08-2010 05:31 AM
How do I route internet traffic over my second IP address? FireRaven Linux - Networking 9 03-09-2010 02:04 PM
How to check source route vino87 Linux - Networking 0 06-29-2009 12:43 AM
Route to NAT'd address doublejoon Linux - Networking 1 01-18-2006 12:29 PM
dhcp no ip address and netmask dont match route address pengy666 Linux - Wireless Networking 1 05-08-2005 09:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:13 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