+ return EXIT_SUCCESS;
+}
+
+static void displayroutes(void)
+{
+ char buff[256];
+ int nl = 0 ;
+ struct in_addr dest;
+ struct in_addr gw;
+ struct in_addr mask;
+ int flgs, ref, use, metric;
+ char flags[4];
+ unsigned long int d,g,m;
+
+ char sdest[16], sgw[16];
+
+
+ FILE *fp = xfopen("/proc/net/route", "r");
+
+ while( fgets(buff, sizeof(buff), fp) != NULL ) {
+ if(nl) {
+ int ifl = 0;
+ while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0')
+ ifl++;
+ buff[ifl]=0; /* interface */
+ if(sscanf(buff+ifl+1, "%lx%lx%d%d%d%d%lx",
+ &d, &g, &flgs, &ref, &use, &metric, &m)!=7) {
+ error_msg_and_die( "Unsuported kernel route format\n");
+ }
+ if(nl==1) {
+ printf("Kernel IP routing table\n"
+"Destination Gateway Genmask Flags Metric Ref Use Iface\n");
+ }
+
+
+ ifl = 0; /* parse flags */
+ if(flgs&1)
+ flags[ifl++]='U';
+ if(flgs&2)
+ flags[ifl++]='G';
+ if(flgs&4)
+ flags[ifl++]='H';
+ flags[ifl]=0;
+ dest.s_addr = d;
+ gw.s_addr = g;
+ mask.s_addr = m;
+ strcpy(sdest, (dest.s_addr==0 ? "default" :
+ inet_ntoa(dest)));
+ strcpy(sgw, (gw.s_addr==0 ? "*" :
+ inet_ntoa(gw)));
+ printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n",
+ sdest, sgw,
+ inet_ntoa(mask),
+ flags, metric, ref, use, buff);
+ }
+ nl++;
+ }