?
Solved

gcc system call to get gateway address?

Posted on 1998-12-09
2
Medium Priority
?
352 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 100 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

770 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