?
Solved

How host can detect its nearer router?

Posted on 2004-09-10
7
Medium Priority
?
198 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
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.

 

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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 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