From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stas Sergeev Subject: Re: checking IPX route Date: Thu, 08 Aug 2002 02:22:58 +0400 Sender: linux-msdos-owner@vger.kernel.org Message-ID: <3D519DC2.2060707@yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040208090300050002010400" Return-path: List-Id: To: linux-msdos@vger.kernel.org This is a multi-part message in MIME format. --------------040208090300050002010400 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit 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. --------------040208090300050002010400 Content-Type: text/plain; name="ipx_proc.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ipx_proc.diff" --- 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); } --------------040208090300050002010400--