Solved

How host can detect its nearer router?

Posted on 2004-09-10
7
193 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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