Linux MS DOS discussions
 help / color / mirror / Atom feed
* checking IPX route
@ 2002-08-07 12:43 Grigory Batalov
  0 siblings, 0 replies; 4+ messages in thread
From: Grigory Batalov @ 2002-08-07 12:43 UTC (permalink / raw)
  To: linux-msdos

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

  As Stas Sergeev said, we need to check presence of IPX route
 before trying to add it. Here is my version of such checking.
 Patch applies after Stas' last ipx_root.diff .

-- 
 Grigory Batalov.




[-- Attachment #2: dosemu-1.1.3-ipx_route.patch --]
[-- Type: text/plain, Size: 4469 bytes --]

diff -ruN dosemu-1.1.3.orig/src/base/misc/utilities.c dosemu-1.1.3/src/base/misc/utilities.c
--- dosemu-1.1.3.orig/src/base/misc/utilities.c	Wed Aug  7 15:50:56 2002
+++ dosemu-1.1.3/src/base/misc/utilities.c	Wed Aug  7 15:52:35 2002
@@ -22,6 +22,7 @@
 #include "Linux/vt.h"
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <netinet/in.h>
 
 #include "emu.h"
 #include "machcompat.h"
@@ -354,6 +355,34 @@
 {
   procbufptr = procbuf; proclastpos = 0;
 }
+
+int check_proc_ipx_route(unsigned long targetNet, unsigned long network, unsigned char node[])
+{ char buf[13];
+
+  snprintf(buf,9,"%08lX",(unsigned long)htonl(targetNet));
+  buf[8]='\0';
+
+  while (strncmp(procbufptr,buf,8) != 0)
+     { while (*procbufptr != '\n' && *procbufptr != 0)
+          procbufptr++;
+       if (*procbufptr == 0)
+         return 0;
+       procbufptr++;
+      }
+
+  snprintf(buf,9,"%08lX",(unsigned long)htonl(network));
+  buf[8]='\0';
+  if (strncmp(procbufptr+11,buf,8) != 0)
+     return 0;
+
+  snprintf(buf,13,"%02X%02X%02X%02X%02X%02X",node[0],node[1],
+                             node[2],node[3],node[4],node[5]);
+  buf[12]='\0';
+  if (strncmp(procbufptr+24,buf,12) != 0)
+     return 0;
+
+  return 1;
+ }
 
 char *get_proc_string_by_key(char *key)
 {
diff -ruN dosemu-1.1.3.orig/src/dosext/net/net/ipxglt.c dosemu-1.1.3/src/dosext/net/net/ipxglt.c
--- dosemu-1.1.3.orig/src/dosext/net/net/ipxglt.c	Wed Aug  7 15:51:54 2002
+++ dosemu-1.1.3/src/dosext/net/net/ipxglt.c	Wed Aug  7 15:52:35 2002
@@ -34,6 +34,8 @@
 #include "emu.h"
 #include "dosemu_select.h"
 
+#include "utilities.h"
+
 #define FALSE   0
 #define TRUE    1
 #define TIMEOUT 250000
@@ -220,20 +222,32 @@
         
                 *hops = htons(RipResponse.Hops);
                 *ticks = htons(RipResponse.Ticks);
-                retCode = AddRoute( network, ipxs.sipx_network,
-                        ipxs.sipx_node );
-                if( retCode < 0 ) {
-                        n_printf("IPX: Failure %d adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
+
+		open_proc_scan("/proc/net/ipx_route");
+		if (check_proc_ipx_route(network,ipxs.sipx_network,ipxs.sipx_node))
+		   { n_printf("IPX: Route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x> exists\n",
+                        (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
+                        ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
+                        ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
+		    }
+		else
+		   { retCode = AddRoute( network, ipxs.sipx_network, ipxs.sipx_node );
+                     if (retCode < 0 )
+		          { n_printf("IPX: Failure %d adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 retCode,
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                } else {
-                        n_printf("IPX: Success adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
+			    n_printf("IPX: Try manually add this route or use RIP daemon like ipxripd\n");
+			   }
+		     else
+		          { n_printf("IPX: Success adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                }
+			   }
+		    }
+		close_proc_scan();
         } else {
                 printf("IPX: Error %d in GetLocalTarget main packet send/receive loop\n", retCode);
         }
diff -ruN dosemu-1.1.3.orig/src/include/utilities.h dosemu-1.1.3/src/include/utilities.h
--- dosemu-1.1.3.orig/src/include/utilities.h	Tue Mar 19 00:58:13 2002
+++ dosemu-1.1.3/src/include/utilities.h	Wed Aug  7 15:52:35 2002
@@ -26,6 +26,8 @@
 char *get_proc_string_by_key(char *key);
 void advance_proc_bufferptr(void);
 void reset_proc_bufferptr(void);
+int check_proc_ipx_route(unsigned long targetNet,unsigned long network,
+	unsigned char node[]);
 int get_proc_intvalue_by_key(char *key);
 int integer_sqrt(int x);
 int exists_dir(char *name);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checking IPX route
@ 2002-08-07 20:32 Stas Sergeev
  0 siblings, 0 replies; 4+ messages in thread
From: Stas Sergeev @ 2002-08-07 20:32 UTC (permalink / raw)
  To: linux-msdos

[-- Attachment #1: Type: text/plain, Size: 384 bytes --]

Hello.

Grigory Batalov wrote:
> we need to check presence of IPX route
> before trying to add it. Here is my version of such checking.
Hmm, any reasons for implementing
this in utilities.c?
I'd better implement it in ipxglt.c instead.
The attached patch is completely untested,
please check if it works. I think I have
completely preserved the logic of your patch,
but who knows...


[-- Attachment #2: ipx_proc.diff --]
[-- Type: text/plain, Size: 3859 bytes --]

--- src/dosext/net/net/ipxglt.c	Fri Aug  2 18:31:46 2002
+++ src/dosext/net/net/ipxglt.c	Thu Aug  8 00:19:14 2002
@@ -33,6 +33,7 @@
 
 #include "emu.h"
 #include "dosemu_select.h"
+#include "utilities.h"
 
 #define FALSE   0
 #define TRUE    1
@@ -55,14 +56,16 @@
 	struct sockaddr_ipx	*st = (struct sockaddr_ipx *)&rt.rt_dst;
 	struct sockaddr_ipx	*sr = (struct sockaddr_ipx *)&rt.rt_gateway;
 	int sock;
-	int i;
 	
+	if (!can_do_root_stuff) {
+		error("IPX: Cannot add route, root privs required!\n");
+		return -2;
+	}
+
 	rt.rt_flags = RTF_GATEWAY;
 	st->sipx_network = targetNet;
         sr->sipx_network = network;
-	for( i=0; i<6; i++ ) {
-		sr->sipx_node[i] = node[i];
-	}	
+	memcpy(sr->sipx_node, node, 6);
 	sr->sipx_family = st->sipx_family = AF_IPX;
 	
 	enter_priv_on();
@@ -85,6 +88,31 @@
         return(0);
 }
 
+int CheckRouteExist(unsigned long targetNet, unsigned network,
+        unsigned char node[])
+{
+char buf_targ[9], buf_net[9], buf_node[13], proc_net[9], proc_node[13], *proc_str;
+
+	sprintf(buf_targ, "%08lX", (unsigned long)htonl(targetNet));
+	sprintf(buf_net, "%08lX", (unsigned long)htonl(network));
+	sprintf(buf_node, "%02X%02X%02X%02X%02X%02X", node[0], node[1],
+                     node[2], node[3], node[4], node[5]);
+
+	open_proc_scan("/proc/net/ipx_route");
+	proc_str = get_proc_string_by_key(buf_targ);
+	close_proc_scan();
+
+	if (!proc_str)
+		return 0;
+
+	sscanf(proc_str, "%s %s", proc_net, proc_node);
+
+	if (strcmp(buf_net, proc_net) || strcmp(buf_node, proc_node))
+		return 0;
+
+	return 1;
+}
+
 /* network must be passed in in network order (that is, high-low) */
 /* returns 0 on success, less than 0 on failure */
 int IPXGetLocalTarget( unsigned long network, int *hops, int *ticks )
@@ -220,20 +248,27 @@
         
                 *hops = htons(RipResponse.Hops);
                 *ticks = htons(RipResponse.Ticks);
-                retCode = AddRoute( network, ipxs.sipx_network,
+		if (CheckRouteExist(network, ipxs.sipx_network, ipxs.sipx_node)) {
+		   n_printf("IPX: Route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x> already exists\n",
+                     (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
+                     ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
+                     ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
+		} else {
+                  retCode = AddRoute( network, ipxs.sipx_network,
                         ipxs.sipx_node );
-                if( retCode < 0 ) {
-                        n_printf("IPX: Failure %d adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
-                                retCode,
+                  if( retCode < 0 ) {
+                        error("IPX: Failure adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                } else {
+			error("IPX: Try manually add this route with ipx_route command\nor use RIP daemon like ipxripd\n");
+                  } else {
                         n_printf("IPX: Success adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                }
+                  }
+		}
         } else {
                 printf("IPX: Error %d in GetLocalTarget main packet send/receive loop\n", retCode);
         }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checking IPX route
@ 2002-08-07 22:22 Stas Sergeev
  2002-08-08  4:53 ` Grigory Batalov
  0 siblings, 1 reply; 4+ messages in thread
From: Stas Sergeev @ 2002-08-07 22:22 UTC (permalink / raw)
  To: linux-msdos

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

Hello.

> The attached patch is completely untested,
> please check if it works. I think I have
> completely preserved the logic of your patch,
> but who knows...
Yes, it is still completely untested but
contains one bug less than the previous one:)
Grigory, please see if this one works.

[-- Attachment #2: ipx_proc.diff --]
[-- Type: text/plain, Size: 3887 bytes --]

--- src/dosext/net/net/ipxglt.c	Fri Aug  2 18:31:46 2002
+++ src/dosext/net/net/ipxglt.c	Thu Aug  8 00:19:14 2002
@@ -33,6 +33,7 @@
 
 #include "emu.h"
 #include "dosemu_select.h"
+#include "utilities.h"
 
 #define FALSE   0
 #define TRUE    1
@@ -55,14 +56,16 @@
 	struct sockaddr_ipx	*st = (struct sockaddr_ipx *)&rt.rt_dst;
 	struct sockaddr_ipx	*sr = (struct sockaddr_ipx *)&rt.rt_gateway;
 	int sock;
-	int i;
 	
+	if (!can_do_root_stuff) {
+		error("IPX: Cannot add route, root privs required!\n");
+		return -2;
+	}
+
 	rt.rt_flags = RTF_GATEWAY;
 	st->sipx_network = targetNet;
         sr->sipx_network = network;
-	for( i=0; i<6; i++ ) {
-		sr->sipx_node[i] = node[i];
-	}	
+	memcpy(sr->sipx_node, node, 6);
 	sr->sipx_family = st->sipx_family = AF_IPX;
 	
 	enter_priv_on();
@@ -85,6 +88,33 @@
         return(0);
 }
 
+int CheckRouteExist(unsigned long targetNet, unsigned network,
+        unsigned char node[])
+{
+char buf_targ[9], buf_net[9], buf_node[13], proc_net[9], proc_node[13], *proc_str;
+
+	sprintf(buf_targ, "%08lX", (unsigned long)htonl(targetNet));
+	sprintf(buf_net, "%08lX", (unsigned long)htonl(network));
+	sprintf(buf_node, "%02X%02X%02X%02X%02X%02X", node[0], node[1],
+                     node[2], node[3], node[4], node[5]);
+
+	open_proc_scan("/proc/net/ipx_route");
+	proc_str = get_proc_string_by_key(buf_targ);
+
+	if (!proc_str) {
+		close_proc_scan();
+		return 0;
+	}
+
+	sscanf(proc_str, "%s %s", proc_net, proc_node);
+	close_proc_scan();
+
+	if (strcmp(buf_net, proc_net) || strcmp(buf_node, proc_node))
+		return 0;
+
+	return 1;
+}
+
 /* network must be passed in in network order (that is, high-low) */
 /* returns 0 on success, less than 0 on failure */
 int IPXGetLocalTarget( unsigned long network, int *hops, int *ticks )
@@ -220,20 +250,27 @@
         
                 *hops = htons(RipResponse.Hops);
                 *ticks = htons(RipResponse.Ticks);
-                retCode = AddRoute( network, ipxs.sipx_network,
+		if (CheckRouteExist(network, ipxs.sipx_network, ipxs.sipx_node)) {
+		   n_printf("IPX: Route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x> already exists\n",
+                     (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
+                     ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
+                     ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
+		} else {
+                  retCode = AddRoute( network, ipxs.sipx_network,
                         ipxs.sipx_node );
-                if( retCode < 0 ) {
-                        n_printf("IPX: Failure %d adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
-                                retCode,
+                  if( retCode < 0 ) {
+                        error("IPX: Failure adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                } else {
+			error("IPX: Try manually add this route with ipx_route command\nor use RIP daemon like ipxripd\n");
+                  } else {
                         n_printf("IPX: Success adding route <%08lx through %08lx:%02x%02x%02x%02x%02x%02x>\n",
                                 (unsigned long int)htonl(network), (unsigned long int)htonl(ipxs.sipx_network),
                                 ipxs.sipx_node[0],ipxs.sipx_node[1],ipxs.sipx_node[2],
                                 ipxs.sipx_node[3],ipxs.sipx_node[4],ipxs.sipx_node[5] );
-                }
+                  }
+		}
         } else {
                 printf("IPX: Error %d in GetLocalTarget main packet send/receive loop\n", retCode);
         }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: checking IPX route
  2002-08-07 22:22 checking IPX route Stas Sergeev
@ 2002-08-08  4:53 ` Grigory Batalov
  0 siblings, 0 replies; 4+ messages in thread
From: Grigory Batalov @ 2002-08-08  4:53 UTC (permalink / raw)
  To: linux-msdos

On Thu, 08 Aug 2002 00:32:40 +0400
Stas Sergeev <stssppnn@yahoo.com> wrote:

> Hmm, any reasons for implementing
> this in utilities.c?

 I was confused that /proc/net/ipx_route hasn't delimiters =).

On Thu, 08 Aug 2002 02:22:58 +0400
Stas Sergeev <stssppnn@yahoo.com> wrote:

> > The attached patch is completely untested,
> > please check if it works. I think I have
> > completely preserved the logic of your patch,
> > but who knows...
> Yes, it is still completely untested but
> contains one bug less than the previous one:)
> Grigory, please see if this one works.

  Yes, it works as supposed.

--
Grigory Batalov.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-08  4:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-07 22:22 checking IPX route Stas Sergeev
2002-08-08  4:53 ` Grigory Batalov
  -- strict thread matches above, loose matches on Subject: below --
2002-08-07 20:32 Stas Sergeev
2002-08-07 12:43 Grigory Batalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox