2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/arch/dos/ipx.c,v $
18 * $Date: 2001-10-19 09:01:56 $
20 * Routines for IPX communications.
22 * $Log: not supported by cvs2svn $
23 * Revision 1.2 2001/01/29 13:35:08 bradleyb
24 * Fixed build system, minor fixes
26 * Revision 1.1.1.1 2001/01/19 03:30:15 bradleyb
29 * Revision 1.1.1.1 1999/06/14 21:58:22 donut
30 * Import of d1x 1.37 source.
32 * Revision 2.10 1995/03/29 17:27:55 john
33 * Added code to not duplicate broadcasts.
35 * Revision 2.9 1995/03/29 15:32:07 john
38 * Revision 2.8 1995/03/29 15:07:31 john
39 * Added network support.
41 * Revision 2.7 1995/03/29 11:22:27 john
42 * Added broadcasting over a net.
44 * Revision 2.6 1995/03/28 20:05:03 john
45 * Took away alternate server stuff.
47 * Revision 2.5 1995/03/23 19:14:29 john
48 * Added better MAX_USERS message.
50 * Revision 2.4 1995/03/23 19:00:02 john
51 * Added user list capabitly.
53 * Revision 2.3 1995/03/23 12:27:05 john
54 * Move IPX into bios lib.
56 * Revision 2.2 1995/03/22 19:08:15 john
57 * Added code to fix sending packets over router... now
58 * we just need to make broadcasts go over router!!
60 * Revision 2.1 1995/03/21 08:40:16 john
61 * Ifdef'd out the NETWORK code.
63 * Revision 2.0 1995/02/27 11:30:45 john
64 * New version 2.0, which has no anonymous unions, builds with
65 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
67 * Revision 1.31 1995/02/16 17:35:03 john
68 * Added code to allow dynamic socket changing.
70 * Revision 1.30 1995/02/01 21:03:45 john
73 * Revision 1.29 1995/01/22 14:31:05 john
76 * Revision 1.28 1995/01/22 14:29:26 john
77 * Added code to bypass broadcast messages.
79 * Revision 1.27 1995/01/03 13:46:16 john
80 * Added code that should make ipx work over different servers,
81 * but ifdef'd it out with SHAREWARE in ipx.c. I haven't tested
82 * this, and I hope it doesn't introduce net bugs.
84 * Revision 1.26 1994/12/14 11:54:37 rob
85 * Reduce # of ipx packets.
87 * Revision 1.25 1994/12/11 00:43:28 john
88 * Locked down DOS ipx buffers... probably not necessary, tho.
90 * Revision 1.24 1994/12/08 15:49:58 rob
91 * Bumped up the # of ipx packets.
93 * Revision 1.23 1994/12/04 15:23:54 rob
94 * Reduced packet # constants.
96 * Revision 1.22 1994/11/27 23:12:39 matt
97 * Made changes for new mprintf calling convention
99 * Revision 1.21 1994/11/19 15:15:19 mike
100 * remove unused code and data
102 * Revision 1.20 1994/11/10 11:06:07 rob
103 * Raised number of ipx packets to 64 and buffers to 128 (for 8-way games)
104 * Removed (commented out) all the spx support stuff.
106 * Revision 1.19 1994/11/07 17:50:12 rob
107 * Bumped up max_packets and ipx_num_packets to double their previous
110 * Revision 1.18 1994/11/07 15:39:01 rob
111 * Removed temporary hacked ipx_send_object function.
112 * Replaced with a more general thing.
114 * Revision 1.17 1994/11/05 16:08:40 rob
115 * Made a change necessary for object syncing on rejoin.
117 * Revision 1.16 1994/11/01 15:57:12 rob
118 * Added support for SPX sockets for critical messages.
120 * Revision 1.15 1994/10/31 19:21:01 rob
121 * Added a routine for sending objects via ipx. Its a hack and shoukld
122 * be replaced by something more general time permitting.
124 * Revision 1.14 1994/10/20 14:57:42 john
127 * Revision 1.13 1994/10/20 11:22:45 john
128 * Tweaked the number of waiting packets. Added code to print
129 * total packets missed, and to limit the packet send rate to
130 * 10 packets per second unless firing.
132 * Revision 1.12 1994/10/03 20:50:11 john
133 * Started adding sound pause functions.
135 * Revision 1.11 1994/09/15 08:54:24 mike
136 * comment out a mprintf.
138 * Revision 1.10 1994/09/12 19:38:20 john
139 * Made some stuff that prints to the DOS screen go to the
140 * mono instead, since it really is debugging info.
142 * Revision 1.9 1994/09/07 13:32:03 john
143 * Made ipx_close explicitly close the socket we were using,
144 * because it seems that VLM's don't automatically close them
145 * like the older NETX stuff did (Going from Novell 3.11 driver
148 * Revision 1.8 1994/09/06 19:29:20 john
149 * Added trial version of rejoin function.
151 * Revision 1.7 1994/08/09 19:31:50 john
152 * Networking changes.
154 * Revision 1.6 1994/08/05 16:11:41 john
155 * Psuedo working version of networking.
157 * Revision 1.5 1994/08/04 19:17:21 john
158 * Inbetween version of network stuff.
160 * Revision 1.4 1994/07/29 16:08:57 john
161 * *** empty log message ***
163 * Revision 1.3 1994/07/25 12:33:31 john
164 * Network "pinging" in.
166 * Revision 1.2 1994/07/20 15:58:28 john
167 * First installment of ipx stuff.
169 * Revision 1.1 1994/07/19 15:42:00 john
180 static char rcsid[] = "$Id: ipx.c,v 1.3 2001-10-19 09:01:56 bradleyb Exp $";
184 #define _BORLAND_DOS_REGS 1
202 typedef unsigned char BYTE;
203 typedef unsigned short WORD;
204 typedef unsigned long DWORD;
206 typedef struct local_address {
208 } __pack__ local_address;
210 typedef struct net_address {
212 local_address node_id;
214 } __pack__ net_address;
216 typedef struct ipx_header {
219 BYTE transport_control;
221 net_address destination;
223 } __pack__ ipx_header;
225 typedef struct ecb_header {
229 BYTE completion_code;
231 BYTE ipx_reserved[14];
233 local_address immediate_address;
235 WORD fragment_pointer[2];
237 } __pack__ ecb_header;
239 typedef struct packet_data {
241 byte data[IPX_MAX_DATA_SIZE];
242 } __pack__ packet_data;
244 typedef struct ipx_packet {
248 } __pack__ ipx_packet;
250 typedef struct user_address {
254 } __pack__ user_address;
257 int Ipx_num_users = 0;
258 user_address Ipx_users[MAX_USERS];
260 #define MAX_NETWORKS 64
261 int Ipx_num_networks = 0;
262 uint Ipx_networks[MAX_NETWORKS];
264 int ipx_packetnum = 0;
266 #define MAX_PACKETS 64
268 static packet_data packet_buffers[MAX_PACKETS];
269 static short packet_free_list[MAX_PACKETS];
270 static int num_packets = 0;
271 static int largest_packet_index = 0;
272 static short packet_size[MAX_PACKETS];
275 ubyte ipx_installed=0;
276 WORD ipx_vector_segment;
277 WORD ipx_vector_offset;
278 ubyte ipx_socket_life = 0; // 0=closed at prog termination, 0xff=closed when requested.
279 DWORD ipx_network = 0;
280 local_address ipx_my_node;
281 WORD ipx_num_packets=32; // 32 Ipx packets
282 ipx_packet * packets;
284 ushort ipx_packets_selector;
286 ecb_header * last_ecb=NULL;
289 void got_new_packet( ecb_header * ecb );
290 void ipx_listen_for_packet(ecb_header * ecb );
292 void free_packet( int id )
294 packet_buffers[id].packetnum = -1;
295 packet_free_list[ --num_packets ] = id;
296 if (largest_packet_index==id)
297 while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 ));
300 int ipx_get_packet_data( ubyte * data )
302 int i, n, best, best_id, size;
304 for (i=1; i<ipx_num_packets; i++ ) {
305 if ( !packets[i].ecb.in_use ) {
306 got_new_packet( &packets[i].ecb );
307 packets[i].ecb.in_use = 0;
308 ipx_listen_for_packet(&packets[i].ecb);
316 for (i=0; i<=largest_packet_index; i++ ) {
317 if ( packet_buffers[i].packetnum > -1 ) {
319 if ( best == -1 || (packet_buffers[i].packetnum<best) ) {
320 best = packet_buffers[i].packetnum;
326 //mprintf( (0, "Best id = %d, pn = %d, last_ecb = %x, len=%x, ne = %d\n", best_id, best, last_ecb, lastlen, neterrors ));
327 //mprintf( (1, "<%d> ", neterrors ));
329 if ( best_id < 0 ) return 0;
331 size = packet_size[best_id];
332 memcpy( data, packet_buffers[best_id].data, size );
333 free_packet(best_id);
339 unsigned int swap_short( unsigned int short )
340 #pragma aux swap_short parm [eax] = "xchg al,ah";
342 static inline unsigned int swap_short( unsigned int sshort ) {
344 asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort));
349 void got_new_packet( ecb_header * ecb )
353 unsigned short datasize;
357 p = (ipx_packet *)ecb;
359 if ( p->ecb.in_use ) { neterrors++; return; }
360 if ( p->ecb.completion_code ) { neterrors++; return; }
362 // Error( "Recieve error %d for completion code", p->ecb.completion_code );
364 if ( memcmp( &p->ipx.source.node_id, &ipx_my_node, 6 ) ) {
365 datasize=swap_short(p->ipx.length);
367 datasize -= sizeof(ipx_header);
368 // Find slot to put packet in...
369 if ( datasize > 0 && datasize <= sizeof(packet_data) ) {
370 if ( num_packets >= MAX_PACKETS ) {
371 //printf( 1, "IPX: Packet buffer overrun!!!\n" );
375 id = packet_free_list[ num_packets++ ];
376 if (id > largest_packet_index ) largest_packet_index = id;
377 packet_size[id] = datasize-sizeof(int);
378 packet_buffers[id].packetnum = p->pd.packetnum;
379 if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; }
380 memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] );
387 //ipx_listen_for_packet(&p->ecb);
390 ubyte * ipx_get_my_local_address()
392 return ipx_my_node.address;
395 ubyte * ipx_get_my_server_address()
397 return (ubyte *)&ipx_network;
400 void ipx_listen_for_packet(ecb_header * ecb )
402 dpmi_real_regs rregs;
404 memset(&rregs,0,sizeof(dpmi_real_regs));
405 rregs.ebx = 4; // Listen For Packet function
406 rregs.esi = DPMI_real_offset(ecb);
407 rregs.es = DPMI_real_segment(ecb);
408 dpmi_real_int386x( 0x7A, &rregs );
411 void ipx_cancel_listen_for_packet(ecb_header * ecb )
413 dpmi_real_regs rregs;
414 memset(&rregs,0,sizeof(dpmi_real_regs));
415 rregs.ebx = 6; // IPX Cancel event
416 rregs.esi = DPMI_real_offset(ecb);
417 rregs.es = DPMI_real_segment(ecb);
418 dpmi_real_int386x( 0x7A, &rregs );
422 void ipx_send_packet(ecb_header * ecb )
424 dpmi_real_regs rregs;
425 memset(&rregs,0,sizeof(dpmi_real_regs));
426 rregs.ebx = 3; // Send Packet function
427 rregs.esi = DPMI_real_offset(ecb);
428 rregs.es = DPMI_real_segment(ecb);
429 dpmi_real_int386x( 0x7A, &rregs );
435 ubyte local_target[6];
436 } __pack__ net_xlat_info;
438 void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target )
440 net_xlat_info * info;
441 dpmi_real_regs rregs;
443 // Get dos memory for call...
444 info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) );
445 assert( info != NULL );
446 memcpy( info->network, server, 4 );
447 memcpy( info->node, node, 6 );
449 memset(&rregs,0,sizeof(dpmi_real_regs));
451 rregs.ebx = 2; // Get Local Target
452 rregs.es = DPMI_real_segment(info);
453 rregs.esi = DPMI_real_offset(info->network);
454 rregs.edi = DPMI_real_offset(info->local_target);
456 dpmi_real_int386x( 0x7A, &rregs );
458 // Save the local target...
459 memcpy( local_target, info->local_target, 6 );
464 dpmi_real_regs rregs;
465 if ( ipx_installed ) {
466 // When using VLM's instead of NETX, the sockets don't
467 // seem to automatically get closed, so we must explicitly
468 // close them at program termination.
470 memset(&rregs,0,sizeof(dpmi_real_regs));
471 rregs.edx = ipx_socket;
472 rregs.ebx = 1; // Close socket
473 dpmi_real_int386x( 0x7A, &rregs );
478 //---------------------------------------------------------------
479 // Initializes all IPX internals.
480 // If socket_number==0, then opens next available socket.
481 // Returns: 0 if successful.
482 // -1 if socket already open.
483 // -2 if socket table full.
484 // -3 if IPX not installed.
485 // -4 if couldn't allocate low dos memory
486 // -5 if error with getting internetwork address
488 int ipx_init( int socket_number, int show_address )
490 dpmi_real_regs rregs;
491 ubyte *ipx_real_buffer;
498 // init packet buffers.
499 for (i=0; i<MAX_PACKETS; i++ ) {
500 packet_buffers[i].packetnum = -1;
501 packet_free_list[i] = i;
504 largest_packet_index = 0;
506 // Get the IPX vector
507 memset(&rregs,0,sizeof(dpmi_real_regs));
508 rregs.eax=0x00007a00;
509 dpmi_real_int386x( 0x2f, &rregs );
511 if ( (rregs.eax & 0xFF) != 0xFF ) {
514 ipx_vector_offset = rregs.edi & 0xFFFF;
515 ipx_vector_segment = rregs.es;
516 //printf( "IPX entry point at %.4x:%.4x\n", ipx_vector_segment, ipx_vector_offset );
518 // Open a socket for IPX
520 memset(&rregs,0,sizeof(dpmi_real_regs));
521 swab( (char *)&socket_number,(char *)&ipx_socket, 2 );
522 rregs.edx = ipx_socket;
523 rregs.eax = ipx_socket_life;
524 rregs.ebx = 0; // Open socket
525 dpmi_real_int386x( 0x7A, &rregs );
527 ipx_socket = rregs.edx & 0xFFFF;
529 if ( rregs.eax & 0xFF ) {
530 //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
536 // Find our internetwork address
537 ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block
538 if ( ipx_real_buffer == NULL ) {
539 //printf( "Error allocation realmode memory\n" );
543 memset(&rregs,0,sizeof(dpmi_real_regs));
544 rregs.ebx = 9; // Get internetwork address
545 rregs.esi = DPMI_real_offset(ipx_real_buffer);
546 rregs.es = DPMI_real_segment(ipx_real_buffer);
547 dpmi_real_int386x( 0x7A, &rregs );
549 if ( rregs.eax & 0xFF ) {
550 //printf( "Error getting internetwork address!\n" );
554 memcpy( &ipx_network, ipx_real_buffer, 4 );
555 memcpy( &ipx_my_node, &ipx_real_buffer[4], 6 );
557 Ipx_num_networks = 0;
558 memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 );
560 if ( show_address ) {
561 printf( "My IPX addresss is " );
562 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
563 printf( "%02X%02X%02X%02X%02X%02X\n", ipx_real_buffer[4],ipx_real_buffer[5],ipx_real_buffer[6],ipx_real_buffer[7],ipx_real_buffer[8],ipx_real_buffer[9] );
567 packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector );
568 if ( packets == NULL ) {
569 //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets );
572 #if 0 /* adb: not needed, fails with cwsdpmi */
573 if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) {
574 //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets );
578 memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets );
580 for (i=1; i<ipx_num_packets; i++ ) {
581 packets[i].ecb.in_use = 0x1d;
582 //packets[i].ecb.in_use = 0;
583 packets[i].ecb.socket_id = ipx_socket;
584 packets[i].ecb.fragment_count = 1;
585 packets[i].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[i].ipx);
586 packets[i].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[i].ipx);
587 packets[i].ecb.fragment_size = sizeof(ipx_packet)-sizeof(ecb_header); //-sizeof(ecb_header);
589 ipx_listen_for_packet(&packets[i].ecb);
592 packets[0].ecb.socket_id = ipx_socket;
593 packets[0].ecb.fragment_count = 1;
594 packets[0].ecb.fragment_pointer[0] = DPMI_real_offset(&packets[0].ipx);
595 packets[0].ecb.fragment_pointer[1] = DPMI_real_segment(&packets[0].ipx);
596 packets[0].ipx.packet_type = 4; // IPX packet
597 packets[0].ipx.destination.socket_id = ipx_socket;
598 // memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
599 memset( packets[0].ipx.destination.network_id, 0, 4 );
604 void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address )
606 assert(ipx_installed);
608 if ( datasize >= IPX_MAX_DATA_SIZE ) {
609 printf( "Data too big\n" );
610 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
613 //end this section replacement - VR
616 // Make sure no one is already sending something
617 while( packets[0].ecb.in_use )
621 if (packets[0].ecb.completion_code) {
622 // printf( "Send error %d for completion code\n", packets[0].ecb.completion_code );
623 //added/replaced on 11/8/98 by Victor Rachels to stop crappage
626 //end this section replacement - VR
630 // Fill in destination address
631 if ( memcmp( network, &ipx_network, 4 ) )
632 memcpy( packets[0].ipx.destination.network_id, network, 4 );
634 memset( packets[0].ipx.destination.network_id, 0, 4 );
635 memcpy( packets[0].ipx.destination.node_id.address, address, 6 );
636 memcpy( packets[0].ecb.immediate_address.address, immediate_address, 6 );
637 packets[0].pd.packetnum = ipx_packetnum++;
639 // Fill in data to send
640 packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize;
642 assert( datasize > 1 );
643 assert( packets[0].ecb.fragment_size <= 576 );
645 memcpy( packets[0].pd.data, data, datasize );
648 ipx_send_packet( &packets[0].ecb );
652 void ipx_send_broadcast_packet_data( ubyte * data, int datasize )
655 ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
656 ubyte local_address[6];
658 // Set to all networks besides mine
659 for (i=0; i<Ipx_num_networks; i++ ) {
660 if ( memcmp( &Ipx_networks[i], &ipx_network, 4 ) ) {
661 ipx_get_local_target( (ubyte *)&Ipx_networks[i], broadcast, local_address );
662 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, local_address );
664 ipx_send_packet_data( data, datasize, (ubyte *)&Ipx_networks[i], broadcast, broadcast );
668 //OLDipx_send_packet_data( data, datasize, (ubyte *)&ipx_network, broadcast, broadcast );
670 // Send directly to all users not on my network or in the network list.
671 for (i=0; i<Ipx_num_users; i++ ) {
672 if ( memcmp( Ipx_users[i].network, &ipx_network, 4 ) ) {
673 for (j=0; j<Ipx_num_networks; j++ ) {
674 if (!memcmp( Ipx_users[i].network, &Ipx_networks[j], 4 ))
677 ipx_send_packet_data( data, datasize, Ipx_users[i].network, Ipx_users[i].node, Ipx_users[i].address );
684 // Sends a non-localized packet... needs 4 byte server, 6 byte address
685 void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * server, ubyte *address )
687 ubyte local_address[6];
689 if ( (*(uint *)server) != 0 ) {
690 ipx_get_local_target( server, address, local_address );
691 ipx_send_packet_data( data, datasize, server, address, local_address );
693 // Old method, no server info.
694 ipx_send_packet_data( data, datasize, server, address, address );
698 int ipx_change_default_socket( ushort socket_number )
702 dpmi_real_regs rregs;
704 if ( !ipx_installed ) return -3;
707 memset(&rregs,0,sizeof(dpmi_real_regs));
708 swab( (char *)&socket_number,(char *)&new_ipx_socket, 2 );
709 rregs.edx = new_ipx_socket;
710 rregs.eax = ipx_socket_life;
711 rregs.ebx = 0; // Open socket
712 dpmi_real_int386x( 0x7A, &rregs );
714 new_ipx_socket = rregs.edx & 0xFFFF;
716 if ( rregs.eax & 0xFF ) {
717 //printf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET ));
721 for (i=1; i<ipx_num_packets; i++ ) {
722 ipx_cancel_listen_for_packet(&packets[i].ecb);
725 // Close existing socket...
726 memset(&rregs,0,sizeof(dpmi_real_regs));
727 rregs.edx = ipx_socket;
728 rregs.ebx = 1; // Close socket
729 dpmi_real_int386x( 0x7A, &rregs );
731 ipx_socket = new_ipx_socket;
733 // Repost all listen requests on the new socket...
734 for (i=1; i<ipx_num_packets; i++ ) {
735 packets[i].ecb.in_use = 0;
736 packets[i].ecb.socket_id = ipx_socket;
737 ipx_listen_for_packet(&packets[i].ecb);
740 packets[0].ecb.socket_id = ipx_socket;
741 packets[0].ipx.destination.socket_id = ipx_socket;
744 // init packet buffers.
745 for (i=0; i<MAX_PACKETS; i++ ) {
746 packet_buffers[i].packetnum = -1;
747 packet_free_list[i] = i;
750 largest_packet_index = 0;
755 void ipx_read_user_file(char * filename)
759 char temp_line[132], *p1;
762 if (!filename) return;
766 fp = fopen( filename, "rt" );
769 printf( "Broadcast Users:\n" );
771 while (fgets(temp_line, 132, fp)) {
773 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
774 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
775 n = sscanf( temp_line, "%2x%2x%2x%2x/%2x%2x%2x%2x%2x%2x",(unsigned int *)&tmp.network[0],(unsigned int *) &tmp.network[1],(unsigned int *) &tmp.network[2],(unsigned int *) &tmp.network[3],(unsigned int *) &tmp.node[0],(unsigned int *) &tmp.node[1],(unsigned int *) &tmp.node[2],(unsigned int *)&tmp.node[3],(unsigned int *) &tmp.node[4],(unsigned int *) &tmp.node[5] );
776 if ( n != 10 ) continue;
777 if ( Ipx_num_users < MAX_USERS ) {
778 ubyte * ipx_real_buffer = (ubyte *)&tmp;
779 ipx_get_local_target( tmp.network, tmp.node, tmp.address );
780 Ipx_users[Ipx_num_users++] = tmp;
781 printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] );
782 printf( "%02X%02X%02X%02X%02X%02X\n", ipx_real_buffer[4],ipx_real_buffer[5],ipx_real_buffer[6],ipx_real_buffer[7],ipx_real_buffer[8],ipx_real_buffer[9] );
784 printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS );
793 void ipx_read_network_file(char * filename)
797 char temp_line[132], *p1;
800 if (!filename) return;
802 fp = fopen( filename, "rt" );
805 printf( "Using Networks:\n" );
806 for (i=0; i<Ipx_num_networks; i++ ) {
807 ubyte * n1 = (ubyte *)&Ipx_networks[i];
808 printf("* %02x%02x%02x%02x\n", n1[0], n1[1], n1[2], n1[3] );
811 while (fgets(temp_line, 132, fp)) {
813 p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0';
814 p1 = strchr(temp_line,';'); if (p1) *p1 = '\0';
815 n = sscanf( temp_line, "%2x%2x%2x%2x",(unsigned int *) &tmp.network[0],(unsigned int *) &tmp.network[1],(unsigned int *) &tmp.network[2],(unsigned int *) &tmp.network[3] );
816 if ( n != 4 ) continue;
817 if ( Ipx_num_networks < MAX_NETWORKS ) {
819 for (j=0; j<Ipx_num_networks; j++ )
820 if ( !memcmp( &Ipx_networks[j], tmp.network, 4 ) )
822 if ( j >= Ipx_num_networks ) {
823 memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 );
824 printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] );
827 printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS );
836 //---typedef struct rip_entry {
842 //---typedef struct rip_packet {
843 //--- ushort operation; //1=request, 2=response
844 //--- rip_entry rip[50];
848 //---void ipx_find_all_servers()
851 //--- rip_packet * rp;
852 //--- assert(ipx_installed);
854 //--- ipx_change_default_socket( 0x0453 );
855 //--- // ipx_change_default_socket( 0x5304 );
857 //--- // Make sure no one is already sending something
858 //--- while( packets[0].ecb.in_use )
862 //--- if (packets[0].ecb.completion_code) {
863 //--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code );
867 //--- rp = (rip_packet *)&packets[0].pd;
869 //--- // Fill in destination address
871 //--- char mzero1[] = {0,0,0,1};
872 //--- char mzero[] = {0,0,0,0,0,1};
873 //--- char immediate[6];
874 //--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 );
875 //--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 );
877 //--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
878 //--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
880 //--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 );
881 //--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 );
882 //--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 );
883 //--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 );
884 //--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 );
885 //--- //mzero1[3] = 1;
886 //--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 );
887 //--- //mzero[5] = 1;
888 //--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 );
889 //--- //ipx_get_local_target( mzero1, mzero, immediate );
890 //--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 );
891 //--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 );
892 //--- //mzero[5] = 0;
895 //--- packets[0].ipx.packet_type = 1; // RIP packet
897 //--- // Fill in data to send
898 //--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet);
899 //--- assert( packets[0].ecb.fragment_size <= 576 );
901 //--- rp->operation = 0; // Request
902 //--- for (i=0;i<50; i++) {
903 //--- rp->rip[i].network = 0xFFFFFFFF;
904 //--- rp->rip[i].nhops = 0;
905 //--- rp->rip[i].nticks = 0;
909 //--- ipx_send_packet( &packets[0].ecb );
911 //--- for (i=0;i<50; i++) {
912 //--- if ( rp->rip[i].network != 0xFFFFFFFF )
913 //--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks );