Solved

gcc system call to get gateway address?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

813 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

17 Experts available now in Live!

Get 1:1 Help Now