Solved

gcc system call to get gateway address?

Posted on 1998-12-09
2
336 Views
Last Modified: 2008-02-01
We are using  gethostname() and getdomainname() that are
part of gcc with our Red Hat Linux 5.1 installation.  We
would like to find a  get gateway address  function.  What
system function can we call to get  gateway address?
0
Comment
Question by:amw23
2 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 1254973
Do you know the name of gateway system?
If not try experimenting with 'ping', and try find out the routing of a package. Lookfor a change in the addresses you receive from ping.
(use ping in verbose mode/show systems/...)
0
 
LVL 1

Accepted Solution

by:
mlonnrot earned 50 total points
ID: 1254974
There is no system call for this. I also don't think there's a portable way of doing it. Use popen() to run a UNIX command that returns the default router. For example:

f1 = popen("netstat -r | awk '/^default/{print $2}', "r");
fgets(defRoute, sizeof(defRoute)-1, f1)

Problem with this approach is that netstat truncates long hostnames, so you may end up with garbage. Most systems include options for the route command, i.e. "route get default". Put that in the popen() but you need root privs to run it.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now