Solved

How host can detect its nearer router?

Posted on 2004-09-10
7
190 Views
Last Modified: 2010-04-22
hello,
  I want to write a program that will communicate with adjecent router thro' C program. Can i use socket program or write a Linux kernel module to achieve it?
    what data structure can i use to find nearest router?
0
Comment
Question by:cranium2003
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 12026989
You won't easily be able "to find nearest router" unless said router is running a routing protocol like RIP, OSPF, etc., that broadcasts routing information. If you don't know what the IP of a local router is and the router isn't brodcasting routing information you'd have to try routing a packet through every local IP.
0
 

Author Comment

by:cranium2003
ID: 12130420
can it be possible through /proc/net/route on linux machine.
by reading a /proc/net/route file and sending my packet to each Gateway router
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12133566
Maybe I misunderstood what you are after. I took the question title"How host can detect its nearer router?" to mean that you want to wite a program that will search out adjacent routers. But your last comment seems to indicate otherwise.

What, eaxtly, are you wanting to do in this code?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:cranium2003
ID: 12180881
hi jleive,
       AS i told you already i want to write a program that will contact other routers and exchange my own data packet between two routers, these two routers are software made routers by making ip forwarding enabled. for that i ask that can i use /proc/net/route to check adjecent routers with ip address entry flag as gateway in /proc/net/route?
0
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
ID: 12181343
In that case, yes, picking up the gateway IP(s) from /proc/net/route will work.
0
 

Author Comment

by:cranium2003
ID: 12197810
hello jlevie,
                 but picking that file will give only ip address in hex form and route -r gives ip table in decimal form. i want it to be in decimal form when i open a file /pro/net/route and read it. how can i do it?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12201942
There are a number of ways of converting the hex value to decimal octets. One way might look like:

#include <stdio.h>
#include <string.h>

main()
{
  char in[] = "7D00A8C0";
  char ou[16];
  int ip[4];

  sprintf(ou, "0x%c%c.0x%c%c.0x%c%c.0x%c%c",
      in[6], in[7], in[4], in[5], in[2], in[3], in[0], in[1]);
  sscanf(ou, "%x.%x.%x.%x", &ip[0], &ip[1], &ip[2], &ip[3]);
  printf("%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]);
  exit(0);
}
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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

22 Experts available now in Live!

Get 1:1 Help Now