LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-14-2006, 04:03 PM   #1
jroberts5477
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
How programatically in C do I get/set the default route or gateway address of eth0


I am trying to write code in C to get and set the default route or gateway address on a specific piece of hardware. I have tried many different things, but nothing seems to work. The closest way that looks close to me is using RTNetlink, however I'm not sure if that even works. When I use RTNetlink, I get a gateway address to return, however it is always 0.0.0.0. Any help would be great.
 
Old 09-15-2006, 09:26 AM   #2
fuzzyash
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Fedora Core 4
Posts: 184

Rep: Reputation: 30
To find out what the current address is you could use "/sbin/ifconfig eth0" & write something to filter out the IP number. This will "get" the address for you but what do you mean by :
Quote:
set the default route or gateway address on a specific piece of hardware.
What do you want to "set"? What do you mean by setting it on a specific piece of hardware?

If you can use bash instead of C you can use the following line to get the current IP of eth0 :
Code:
/sbin/ifconfig eth0 | /bin/awk /eth0/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'
It does exactly what I mentioned above in that it filters the IP out from the command "/sbin/ifconfig eth0"
 
Old 09-15-2006, 01:11 PM   #3
jroberts5477
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
I have multiple network adapters and for eth0 I want to programmatically set the gateway address for that interface. I can set the IP address, Subnet Mask, and broadcast address with ioctl(), but do not know how to, in C code, find and set the gateway.

Last edited by jroberts5477; 09-15-2006 at 01:56 PM.
 
  


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
eth0 and eth0:1. Default gateway is not working Fillys6 Linux - Networking 1 12-21-2005 09:33 AM
How do I set the ip address for eth0, eth1 and the default gateway? abefroman SUSE / openSUSE 5 05-19-2005 04:15 AM
dhclient not setting default gateway - no WAN route kadissie Linux - Networking 2 03-10-2005 04:55 AM
default route without a gateway scylla Linux - Networking 1 10-21-2004 01:40 AM
finding gateway address on eth0 MHouse Linux - Newbie 9 03-05-2004 06:35 AM

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

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