Solved

gcc system call to get gateway address?

Posted on 1998-12-09
2
344 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is my core dump file in Ubuntu? 12 454
C#, VS15, StructLayout 1 135
Digital Output does not have continuity to ground? 3 100
Super Scope, DHCP 5 91
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.

861 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