Solved

How host can detect its nearer router?

Posted on 2004-09-10
7
191 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

14 Experts available now in Live!

Get 1:1 Help Now