Solved

gcc system call to get gateway address?

Posted on 1998-12-09
2
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to declare a 2-dimensional version of strlen 4 227
distributed computing in Python 4 145
smtp c source code 7 105
Loading flat file data in tables 2 58
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

740 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